From 8ac00677a9a5359adf7eff725a6315f4c4658cb2 Mon Sep 17 00:00:00 2001 From: Sofya Balandina Date: Wed, 19 Jul 2023 10:01:26 +0100 Subject: [PATCH] [apiConformance] Move related to core tests from api to ov_inference_functional_tests (#18349) --- .../get_supported_property_test.cpp | 110 ++++------- .../functional/ov_register_plugin_test.cpp | 180 ++++++++++++++++++ .../ov_plugin/core_integration_sw.hpp | 57 ++++++ .../include/common_test_utils/file_utils.hpp | 81 ++++++++ 4 files changed, 350 insertions(+), 78 deletions(-) create mode 100644 src/inference/tests/functional/ov_register_plugin_test.cpp diff --git a/src/inference/tests/functional/get_supported_property_test.cpp b/src/inference/tests/functional/get_supported_property_test.cpp index 10618f0256e..bc7a78beea9 100644 --- a/src/inference/tests/functional/get_supported_property_test.cpp +++ b/src/inference/tests/functional/get_supported_property_test.cpp @@ -14,81 +14,6 @@ #include "openvino/util/file_util.hpp" #include "openvino/util/shared_object.hpp" -namespace { -std::string get_mock_engine_path() { - std::string mockEngineName("mock_engine"); - return ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), - mockEngineName + IE_BUILD_POSTFIX); -} -template -std::function make_std_function(const std::shared_ptr so, const std::string& functionName) { - std::function ptr(reinterpret_cast(ov::util::get_symbol(so, functionName.c_str()))); - return ptr; -} - -} // namespace - -class MockPlugin : public ov::IPlugin { - std::shared_ptr compile_model(const std::shared_ptr& model, - const ov::AnyMap& properties) const override { - OPENVINO_NOT_IMPLEMENTED; - } - - std::shared_ptr compile_model(const std::shared_ptr& model, - const ov::AnyMap& properties, - const ov::SoPtr& context) const override { - OPENVINO_NOT_IMPLEMENTED; - } - - void set_property(const ov::AnyMap& properties) override { - for (auto&& it : properties) { - if (it.first == ov::num_streams.name()) - num_streams = it.second.as(); - } - OPENVINO_NOT_IMPLEMENTED; - } - - ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override { - if (name == ov::supported_properties) { - std::vector supportedProperties = { - ov::PropertyName(ov::supported_properties.name(), ov::PropertyMutability::RO), - ov::PropertyName(ov::num_streams.name(), ov::PropertyMutability::RW)}; - return decltype(ov::supported_properties)::value_type(supportedProperties); - } else if (name == ov::internal::supported_properties) { - return decltype(ov::internal::supported_properties)::value_type({}); - } else if (name == ov::num_streams.name()) { - return decltype(ov::num_streams)::value_type(num_streams); - } - return ""; - } - - ov::SoPtr create_context(const ov::AnyMap& remote_properties) const override { - OPENVINO_NOT_IMPLEMENTED; - } - - ov::SoPtr get_default_context(const ov::AnyMap& remote_properties) const override { - OPENVINO_NOT_IMPLEMENTED; - } - - std::shared_ptr import_model(std::istream& model, const ov::AnyMap& properties) const override { - OPENVINO_NOT_IMPLEMENTED; - } - - std::shared_ptr import_model(std::istream& model, - const ov::SoPtr& context, - const ov::AnyMap& properties) const override { - OPENVINO_NOT_IMPLEMENTED; - } - - ov::SupportedOpsMap query_model(const std::shared_ptr& model, - const ov::AnyMap& properties) const override { - OPENVINO_NOT_IMPLEMENTED; - } - -private: - int32_t num_streams{0}; -}; - using TestParam = std::tuple; class GetPropertyTest : public ::testing::TestWithParam { public: @@ -100,11 +25,11 @@ public: } void reg_plugin(ov::Core& core, std::shared_ptr& plugin) { - std::string libraryPath = get_mock_engine_path(); + std::string libraryPath = CommonTestUtils::get_mock_engine_path(); if (!m_so) m_so = ov::util::load_shared_object(libraryPath.c_str()); std::function injectProxyEngine = - make_std_function(m_so, "InjectPlugin"); + CommonTestUtils::make_std_function(m_so, "InjectPlugin"); injectProxyEngine(plugin.get()); core.register_plugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), @@ -143,7 +68,7 @@ static std::string getTestCaseName(const testing::TestParamInfo& obj) } TEST_P(GetPropertyTest, canGenerateCorrectPropertyList) { - auto plugin = std::make_shared(); + auto plugin = std::make_shared(); std::shared_ptr base_plugin = plugin; reg_plugin(core, base_plugin); core.get_property(m_plugin_name, ov::supported_properties); @@ -176,3 +101,32 @@ INSTANTIATE_TEST_SUITE_P(GetSupportedPropertyTest, GetPropertyTest, ::testing::ValuesIn(test_variants), getTestCaseName); + +TEST(PropertyTest, SetCacheDirPropertyCoreNoThrow) { + ov::Core core; + + // Cache_dir property test + ov::Any value; + ASSERT_NO_THROW(core.set_property(ov::cache_dir("./tmp_cache_dir"))); + ASSERT_NO_THROW(value = core.get_property(ov::cache_dir.name())); + EXPECT_EQ(value.as(), std::string("./tmp_cache_dir")); +} + +TEST(PropertyTest, SetTBBForceTerminatePropertyCoreNoThrow) { + ov::Core core; + + bool value = true; + ASSERT_NO_THROW(core.set_property(ov::force_tbb_terminate(false))); + ASSERT_NO_THROW(value = core.get_property(ov::force_tbb_terminate.name()).as()); + EXPECT_FALSE(value); + ASSERT_NO_THROW(core.set_property(ov::force_tbb_terminate(true))); + ASSERT_NO_THROW(value = core.get_property(ov::force_tbb_terminate.name()).as()); + EXPECT_TRUE(value); +} + +TEST(PropertyTest, GetUnsupportedPropertyCoreThrow) { + ov::Core core; + + // Unsupported property test + ASSERT_THROW(core.get_property("unsupported_property"), ov::Exception); +} diff --git a/src/inference/tests/functional/ov_register_plugin_test.cpp b/src/inference/tests/functional/ov_register_plugin_test.cpp new file mode 100644 index 00000000000..ffa8f5ea123 --- /dev/null +++ b/src/inference/tests/functional/ov_register_plugin_test.cpp @@ -0,0 +1,180 @@ +#include + +#include + +#include "common_test_utils/file_utils.hpp" +#include "common_test_utils/unicode_utils.hpp" +#include "openvino/openvino.hpp" +#include "openvino/runtime/iplugin.hpp" +#include "openvino/runtime/properties.hpp" +#include "openvino/util/file_util.hpp" +#include "openvino/util/shared_object.hpp" + +using namespace ::testing; +using namespace std; + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT +# include +# define GTEST_COUT std::cerr << "[ ] [ INFO ] " +# include +# include + +# include "openvino/pass/manager.hpp" +#endif + +#ifndef OPENVINO_STATIC_LIBRARY + +inline void mockPlugin(ov::Core& core, std::shared_ptr& plugin, std::shared_ptr& m_so) { + std::string libraryPath = CommonTestUtils::get_mock_engine_path(); + if (!m_so) + m_so = ov::util::load_shared_object(libraryPath.c_str()); + std::function injectProxyEngine = + CommonTestUtils::make_std_function(m_so, "InjectPlugin"); + + injectProxyEngine(plugin.get()); +} + +TEST(RegisterPluginTests, registerNewPluginNoThrows) { + ov::Core core; + auto plugin = std::make_shared(); + std::shared_ptr base_plugin = plugin; + std::shared_ptr m_so; + mockPlugin(core, base_plugin, m_so); + + std::string mock_plugin_name{"MOCK_HARDWARE"}; + ASSERT_NO_THROW( + core.register_plugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + std::string("mock_engine") + IE_BUILD_POSTFIX), + mock_plugin_name)); + ASSERT_NO_THROW(core.get_property(mock_plugin_name, ov::supported_properties)); + + core.unload_plugin(mock_plugin_name); +} + +TEST(RegisterPluginTests, registerExistingPluginThrows) { + ov::Core core; + auto plugin = std::make_shared(); + std::shared_ptr base_plugin = plugin; + std::shared_ptr m_so; + mockPlugin(core, base_plugin, m_so); + + std::string mock_plugin_name{"MOCK_HARDWARE"}; + ASSERT_NO_THROW( + core.register_plugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + std::string("mock_engine") + IE_BUILD_POSTFIX), + mock_plugin_name)); + ASSERT_THROW(core.register_plugin(ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + std::string("mock_engine") + IE_BUILD_POSTFIX), + mock_plugin_name), + ov::Exception); +} + +inline std::string getPluginFile() { + std::string filePostfix{"mock_engine_valid.xml"}; + std::string filename = CommonTestUtils::generateTestFilePrefix() + "_" + filePostfix; + std::ostringstream stream; + stream << ""; + CommonTestUtils::createFile(filename, stream.str()); + return filename; +} + +TEST(RegisterPluginTests, smoke_createMockEngineConfigNoThrows) { + const std::string filename = getPluginFile(); + ASSERT_NO_THROW(ov::Core core(filename)); + CommonTestUtils::removeFile(filename.c_str()); +} + +TEST(RegisterPluginTests, createMockEngineConfigThrows) { + std::string filename = CommonTestUtils::generateTestFilePrefix() + "_mock_engine.xml"; + std::string content{""}; + CommonTestUtils::createFile(filename, content); + ASSERT_THROW(ov::Core core(filename), ov::Exception); + CommonTestUtils::removeFile(filename.c_str()); +} + +TEST(RegisterPluginTests2, createNonExistingConfigThrows) { + ASSERT_THROW(ov::Core core("nonExistPlugins.xml"), ov::Exception); +} + +TEST(RegisterPluginTests2, registerNonExistingPluginFileThrows) { + ov::Core core; + ASSERT_THROW(core.register_plugins("nonExistPlugins.xml"), ov::Exception); +} + +TEST(RegisterPluginTests, unregisterNonExistingPluginThrows) { + ov::Core core; + ASSERT_THROW(core.unload_plugin("unkown_device"), ov::Exception); +} + +TEST(RegisterPluginTests, unregisterExistingPluginNoThrow) { + ov::Core core; + + // get registered devices + std::vector devices = core.get_available_devices(); + + for (auto&& deviceWithID : devices) { + // get_available_devices add to registered device DeviceID, we should remove it + std::string device = deviceWithID.substr(0, deviceWithID.find(".")); + // now, we can unregister device + ASSERT_NO_THROW(core.unload_plugin(device)) << "upload plugin fails: " << device; + } +} + +TEST(RegisterPluginTests, accessToUnregisteredPluginThrows) { + ov::Core core; + std::vector devices = core.get_available_devices(); + + for (auto&& device : devices) { + ASSERT_NO_THROW(core.get_versions(device)); + ASSERT_NO_THROW(core.unload_plugin(device)); + ASSERT_NO_THROW(core.set_property(device, ov::AnyMap{})); + ASSERT_NO_THROW(core.get_versions(device)); + ASSERT_NO_THROW(core.unload_plugin(device)); + } +} + +# ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT +TEST(RegisterPluginTests, registerPluginsXMLUnicodePath) { + const std::string pluginXML = getPluginFile(); + + for (std::size_t testIndex = 0; testIndex < CommonTestUtils::test_unicode_postfix_vector.size(); testIndex++) { + GTEST_COUT << testIndex; + std::wstring postfix = L"_" + CommonTestUtils::test_unicode_postfix_vector[testIndex]; + std::wstring pluginsXmlW = CommonTestUtils::addUnicodePostfixToPath(pluginXML, postfix); + + try { + bool is_copy_successfully; + is_copy_successfully = CommonTestUtils::copyFile(pluginXML, pluginsXmlW); + if (!is_copy_successfully) { + FAIL() << "Unable to copy from '" << pluginXML << "' to '" << ::ov::util::wstring_to_string(pluginsXmlW) + << "'"; + } + + GTEST_COUT << "Test " << testIndex << std::endl; + + ov::Core core; + + GTEST_COUT << "Core created " << testIndex << std::endl; + ASSERT_NO_THROW(core.register_plugins(::ov::util::wstring_to_string(pluginsXmlW))); + CommonTestUtils::removeFile(pluginsXmlW); + ASSERT_NO_THROW(core.get_versions("mock")); // from pluginXML + + std::vector devices = core.get_available_devices(); + ASSERT_NO_THROW(core.get_versions(devices.at(0))); + GTEST_COUT << "Plugin created " << testIndex << std::endl; + + GTEST_COUT << "OK" << std::endl; + } catch (const ov::Exception& e_next) { + CommonTestUtils::removeFile(pluginsXmlW); + std::remove(pluginXML.c_str()); + FAIL() << e_next.what(); + } + } + CommonTestUtils::removeFile(pluginXML); +} + +# endif // OPENVINO_ENABLE_UNICODE_PATH_SUPPORT +#endif // !OPENVINO_STATIC_LIBRARY diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration_sw.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration_sw.hpp index 8a2b57eaa68..cc1b993b848 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration_sw.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/core_integration_sw.hpp @@ -125,6 +125,63 @@ TEST_P(OVClassSeveralDevicesTestQueryModel, QueryModelActualSeveralDevicesNoThro OV_ASSERT_NO_THROW(ie.query_model(actualNetwork, multi_target_device)); } +TEST(OVClassBasicPropsTest, smoke_SetConfigHeteroThrows) { + ov::Core core; + OV_ASSERT_NO_THROW(core.set_property(CommonTestUtils::DEVICE_HETERO, ov::enable_profiling(true))); +} + +TEST(OVClassBasicPropsTest, smoke_SetConfigDevicePropertiesThrows) { + ov::Core core; + ASSERT_THROW(core.set_property("", ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::enable_profiling(true))), + ov::Exception); + ASSERT_THROW(core.set_property(CommonTestUtils::DEVICE_CPU, + ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::enable_profiling(true))), + ov::Exception); + ASSERT_THROW(core.set_property(CommonTestUtils::DEVICE_AUTO, + ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::enable_profiling(true))), + ov::Exception); + ASSERT_THROW(core.set_property(CommonTestUtils::DEVICE_AUTO, + ov::device::properties(CommonTestUtils::DEVICE_CPU, ov::num_streams(4))), + ov::Exception); +} + +TEST(OVClassBasicPropsTest, smoke_SetConfigAutoNoThrows) { + ov::Core core; + + // priority config test + ov::hint::Priority value; + OV_ASSERT_NO_THROW(core.set_property(CommonTestUtils::DEVICE_AUTO, ov::hint::model_priority(ov::hint::Priority::LOW))); + OV_ASSERT_NO_THROW(value = core.get_property(CommonTestUtils::DEVICE_AUTO, ov::hint::model_priority)); + EXPECT_EQ(value, ov::hint::Priority::LOW); + OV_ASSERT_NO_THROW(core.set_property(CommonTestUtils::DEVICE_AUTO, ov::hint::model_priority(ov::hint::Priority::MEDIUM))); + OV_ASSERT_NO_THROW(value = core.get_property(CommonTestUtils::DEVICE_AUTO, ov::hint::model_priority)); + EXPECT_EQ(value, ov::hint::Priority::MEDIUM); + OV_ASSERT_NO_THROW(core.set_property(CommonTestUtils::DEVICE_AUTO, ov::hint::model_priority(ov::hint::Priority::HIGH))); + OV_ASSERT_NO_THROW(value = core.get_property(CommonTestUtils::DEVICE_AUTO, ov::hint::model_priority)); + EXPECT_EQ(value, ov::hint::Priority::HIGH); +} + +TEST(OVClassBasicPropsTest, smoke_GetMetricSupportedMetricsHeteroNoThrow) { + ov::Core core; + std::string target_device = CommonTestUtils::DEVICE_HETERO; + + std::vector properties; + OV_ASSERT_NO_THROW(properties = core.get_property(target_device, ov::supported_properties)); + + std::cout << "Supported HETERO properties: " << std::endl; + for (auto&& str : properties) { + std::cout << str << " is_mutable: " << str.is_mutable() << std::endl; + } + + auto it = std::find(properties.begin(), properties.end(), ov::supported_properties); + ASSERT_NE(properties.end(), it); +} + +TEST_P(OVClassModelOptionalTestP, getVersionsNonEmpty) { + ov::Core core = createCoreWithTemplate(); + ASSERT_EQ(2, core.get_versions(CommonTestUtils::DEVICE_HETERO + std::string(":") + target_device).size()); +} + } // namespace behavior } // namespace test } // namespace ov \ No newline at end of file diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp index 92f55e77c32..492ae1bb180 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp @@ -14,6 +14,11 @@ #include "common_test_utils/w_dirent.h" #include "common_test_utils/common_utils.hpp" +#include "openvino/runtime/iplugin.hpp" +#include "openvino/util/file_util.hpp" +#include "openvino/util/shared_object.hpp" +#include "openvino/runtime/internal_properties.hpp" + #ifdef _WIN32 #include #define rmdir(dir) _rmdir(dir) @@ -277,4 +282,80 @@ std::string getExecutableDirectory(); std::string getCurrentWorkingDir(); std::string getRelativePath(const std::string& from, const std::string& to); +namespace { +inline std::string get_mock_engine_path() { + std::string mockEngineName("mock_engine"); + return ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(), + mockEngineName + IE_BUILD_POSTFIX); +} + +template +std::function make_std_function(const std::shared_ptr so, const std::string& functionName) { + std::function ptr(reinterpret_cast(ov::util::get_symbol(so, functionName.c_str()))); + return ptr; +} + +} // namespace + +class MockPlugin : public ov::IPlugin { + std::shared_ptr compile_model(const std::shared_ptr& model, + const ov::AnyMap& properties) const override { + OPENVINO_NOT_IMPLEMENTED; + } + + std::shared_ptr compile_model(const std::shared_ptr& model, + const ov::AnyMap& properties, + const ov::SoPtr& context) const override { + OPENVINO_NOT_IMPLEMENTED; + } + + void set_property(const ov::AnyMap& properties) override { + for (auto&& it : properties) { + if (it.first == ov::num_streams.name()) + num_streams = it.second.as(); + } + OPENVINO_NOT_IMPLEMENTED; + } + + ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override { + if (name == ov::supported_properties) { + std::vector supportedProperties = { + ov::PropertyName(ov::supported_properties.name(), ov::PropertyMutability::RO), + ov::PropertyName(ov::num_streams.name(), ov::PropertyMutability::RW)}; + return decltype(ov::supported_properties)::value_type(supportedProperties); + } else if (name == ov::internal::supported_properties) { + return decltype(ov::internal::supported_properties)::value_type({}); + } else if (name == ov::num_streams.name()) { + return decltype(ov::num_streams)::value_type(num_streams); + } + return ""; + } + + ov::SoPtr create_context(const ov::AnyMap& remote_properties) const override { + OPENVINO_NOT_IMPLEMENTED; + } + + ov::SoPtr get_default_context(const ov::AnyMap& remote_properties) const override { + OPENVINO_NOT_IMPLEMENTED; + } + + std::shared_ptr import_model(std::istream& model, const ov::AnyMap& properties) const override { + OPENVINO_NOT_IMPLEMENTED; + } + + std::shared_ptr import_model(std::istream& model, + const ov::SoPtr& context, + const ov::AnyMap& properties) const override { + OPENVINO_NOT_IMPLEMENTED; + } + + ov::SupportedOpsMap query_model(const std::shared_ptr& model, + const ov::AnyMap& properties) const override { + OPENVINO_NOT_IMPLEMENTED; + } + +private: + int32_t num_streams{0}; +}; + } // namespace CommonTestUtils