Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

Improve sync in Core::register_plugins and tests (#30175)

Oleg Pipikinc4dad488746c
diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp
index cc77ff88d4b..04e9e96909e 100644
--- a/src/inference/src/dev/core_impl.cpp
+++ b/src/inference/src/dev/core_impl.cpp
@@ -577,8 +577,6 @@ void ov::CoreImpl::register_compile_time_plugins() {
}
void ov::CoreImpl::register_plugins_in_registry(const std::string& xml_config_file, const bool& by_abs_path) {
- std::lock_guard<std::mutex> lock(get_mutex());
-
using namespace ov::util;
auto parse_result = pugixml::parse_xml(xml_config_file.c_str());
if (!parse_result.error_msg.empty()) {
@@ -590,6 +588,8 @@ void ov::CoreImpl::register_plugins_in_registry(const std::string& xml_config_fi
pugi::xml_node ieNode = xmlDoc.document_element();
pugi::xml_node devicesNode = ieNode.child("plugins");
+ std::lock_guard<std::mutex> lock(get_mutex());
+
FOREACH_CHILD (pluginNode, devicesNode, "plugin") {
std::string deviceName = pugixml::get_str_attr(pluginNode, "name");
if (pluginRegistry.find(deviceName) != pluginRegistry.end()) {
diff --git a/src/inference/tests/functional/ov_core_threading.cpp b/src/inference/tests/functional/ov_core_threading.cpp
index 9ef2f6884f4..a8e11007613 100644
--- a/src/inference/tests/functional/ov_core_threading.cpp
+++ b/src/inference/tests/functional/ov_core_threading.cpp
@@ -90,12 +90,12 @@ TEST_F(CoreThreadingTests, SetConfigPluginDoesNotExist) {
TEST_F(CoreThreadingTests, RegisterPlugin) {
ov::Core core;
std::atomic<int> index{0};
+ auto plugin_path = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
+ std::string("mock_engine") + OV_BUILD_POSTFIX);
runParallel(
[&]() {
const std::string deviceName = std::to_string(index++);
- core.register_plugin(ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
- std::string("mock_engine") + OV_BUILD_POSTFIX),
- deviceName);
+ core.register_plugin(plugin_path, deviceName);
core.get_versions(deviceName);
core.unload_plugin(deviceName);
},
@@ -107,20 +107,16 @@ TEST_F(CoreThreadingTests, RegisterPlugins) {
ov::Core core;
std::atomic<unsigned int> index{0};
auto file_prefix = ov::test::utils::generateTestFilePrefix();
+ auto plugin_path = ov::util::make_plugin_library_name(ov::test::utils::getExecutableDirectory(),
+ std::string("mock_engine") + OV_BUILD_POSTFIX);
- auto getPluginXml = [&]() -> std::tuple<std::string, std::string> {
+ auto getPluginXml = [&]() -> std::tuple<std::filesystem::path, std::string> {
std::string indexStr = std::to_string(index++);
- std::string pluginsXML = file_prefix + indexStr + ".xml";
+ std::filesystem::path pluginsXML = file_prefix + indexStr + ".xml";
std::ofstream file(pluginsXML);
file << "<ie><plugins><plugin location=\"";
- file << ov::test::utils::getExecutableDirectory();
- file << ov::util::FileTraits<char>::file_separator;
- file << ov::util::FileTraits<char>::library_prefix();
- file << "mock_engine";
- file << OV_BUILD_POSTFIX;
- file << ov::util::FileTraits<char>::dot_symbol;
- file << ov::util::FileTraits<char>::library_ext();
+ file << plugin_path;
file << "\" name=\"";
file << indexStr;
file << "\"></plugin></plugins></ie>";
@@ -132,11 +128,11 @@ TEST_F(CoreThreadingTests, RegisterPlugins) {
runParallel(
[&]() {
- std::string fileName, deviceName;
- std::tie(fileName, deviceName) = getPluginXml();
- core.register_plugins(fileName);
+ const auto& [fileName, deviceName] = getPluginXml();
+ core.register_plugins(fileName.string());
core.get_versions(deviceName);
- ASSERT_EQ(0, std::remove(fileName.c_str()));
+ core.unload_plugin(deviceName);
+ std::filesystem::remove(fileName);
},
1000);
}