From b4faeebc84e65dc9e418caf8bb44e143bfcf8246 Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Thu, 12 Jan 2023 14:45:36 +0400 Subject: [PATCH] Align `RegisterPluginsInRegistry()` with `RegisterPluginByName()` (#15026) * Align `RegisterPluginsInRegistry()` with `RegisterPluginByName()` * Add gmock dependency to commonTestUtils If use macros like OV_EXPECT_THROW, it requires target to be linked with `gmock`. So add the dependency directly to commonTestUtils * Add `ThrowOnRegisterPlugin(s)Twice` tests * ClangFormat --- src/inference/src/ie_core.cpp | 7 +++- src/inference/tests/unit/core.cpp | 39 +++++++++++++++++++ .../common_test_utils/CMakeLists.txt | 1 + .../common_test_utils/test_assertions.hpp | 1 + 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 src/inference/tests/unit/core.cpp diff --git a/src/inference/src/ie_core.cpp b/src/inference/src/ie_core.cpp index 15b04736e9c..015fead455b 100644 --- a/src/inference/src/ie_core.cpp +++ b/src/inference/src/ie_core.cpp @@ -587,12 +587,15 @@ public: FOREACH_CHILD (pluginNode, devicesNode, "plugin") { std::string deviceName = GetStrAttr(pluginNode, "name"); - ov::util::FilePath pluginPath = getPluginPath(GetStrAttr(pluginNode, "location")); - + if (pluginRegistry.find(deviceName) != pluginRegistry.end()) { + IE_THROW() << "Device with \"" << deviceName << "\" is already registered in the OpenVINO Runtime"; + } if (deviceName.find('.') != std::string::npos) { IE_THROW() << "Device name must not contain dot '.' symbol"; } + ov::util::FilePath pluginPath = getPluginPath(GetStrAttr(pluginNode, "location")); + // check properties auto propertiesNode = pluginNode.child("properties"); ov::AnyMap config; diff --git a/src/inference/tests/unit/core.cpp b/src/inference/tests/unit/core.cpp new file mode 100644 index 00000000000..6dd8f9a410c --- /dev/null +++ b/src/inference/tests/unit/core.cpp @@ -0,0 +1,39 @@ +// Copyright (C) 2023 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/runtime/core.hpp" + +#include + +#include + +#include "common_test_utils/file_utils.hpp" +#include "common_test_utils/test_assertions.hpp" +#include "openvino/util/file_util.hpp" + +TEST(CoreTests, ThrowOnRegisterPluginTwice) { + ov::Core core; + core.register_plugin("test_plugin", "TEST_DEVICE"); + OV_EXPECT_THROW(core.register_plugin("test_plugin", "TEST_DEVICE"), + ov::Exception, + ::testing::HasSubstr("Device with \"TEST_DEVICE\" is already registered in the OpenVINO Runtime")); +} + +TEST(CoreTests, ThrowOnRegisterPluginsTwice) { + ov::Core core; + + auto getPluginXml = [&]() -> std::string { + std::string pluginsXML = "test_plugins.xml"; + std::ofstream file(pluginsXML); + file << ""; + file.flush(); + file.close(); + return pluginsXML; + }; + + core.register_plugins(getPluginXml()); + OV_EXPECT_THROW(core.register_plugins(getPluginXml()), + ov::Exception, + ::testing::HasSubstr("Device with \"TEST_DEVICE\" is already registered in the OpenVINO Runtime")); +} \ No newline at end of file diff --git a/src/tests/ie_test_utils/common_test_utils/CMakeLists.txt b/src/tests/ie_test_utils/common_test_utils/CMakeLists.txt index a90b6801314..c383f016bdf 100644 --- a/src/tests/ie_test_utils/common_test_utils/CMakeLists.txt +++ b/src/tests/ie_test_utils/common_test_utils/CMakeLists.txt @@ -18,6 +18,7 @@ function(add_common_utils ADD_TARGET_NAME) PUBLIC gtest gtest_main + gmock ngraphFunctions openvino::runtime openvino::runtime::dev diff --git a/src/tests/ie_test_utils/common_test_utils/test_assertions.hpp b/src/tests/ie_test_utils/common_test_utils/test_assertions.hpp index ed6e912e3e2..34ff34b0c1e 100644 --- a/src/tests/ie_test_utils/common_test_utils/test_assertions.hpp +++ b/src/tests/ie_test_utils/common_test_utils/test_assertions.hpp @@ -5,6 +5,7 @@ #pragma once #include +#include #include