[apiConformance] Move related to core tests from api to ov_inference_functional_tests (#18349)

This commit is contained in:
Sofya Balandina 2023-07-19 10:01:26 +01:00 committed by GitHub
parent d08b424935
commit 8ac00677a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 350 additions and 78 deletions

View File

@ -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 <class T>
std::function<T> make_std_function(const std::shared_ptr<void> so, const std::string& functionName) {
std::function<T> ptr(reinterpret_cast<T*>(ov::util::get_symbol(so, functionName.c_str())));
return ptr;
}
} // namespace
class MockPlugin : public ov::IPlugin {
std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties,
const ov::SoPtr<ov::IRemoteContext>& 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<ov::streams::Num>();
}
OPENVINO_NOT_IMPLEMENTED;
}
ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override {
if (name == ov::supported_properties) {
std::vector<ov::PropertyName> 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<ov::IRemoteContext> create_context(const ov::AnyMap& remote_properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remote_properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model, const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
private:
int32_t num_streams{0};
};
using TestParam = std::tuple<ov::AnyMap, ov::AnyMap>;
class GetPropertyTest : public ::testing::TestWithParam<TestParam> {
public:
@ -100,11 +25,11 @@ public:
}
void reg_plugin(ov::Core& core, std::shared_ptr<ov::IPlugin>& 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<void(ov::IPlugin*)> injectProxyEngine =
make_std_function<void(ov::IPlugin*)>(m_so, "InjectPlugin");
CommonTestUtils::make_std_function<void(ov::IPlugin*)>(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<TestParam>& obj)
}
TEST_P(GetPropertyTest, canGenerateCorrectPropertyList) {
auto plugin = std::make_shared<MockPlugin>();
auto plugin = std::make_shared<CommonTestUtils::MockPlugin>();
std::shared_ptr<ov::IPlugin> 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>(), 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<bool>());
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<bool>());
EXPECT_TRUE(value);
}
TEST(PropertyTest, GetUnsupportedPropertyCoreThrow) {
ov::Core core;
// Unsupported property test
ASSERT_THROW(core.get_property("unsupported_property"), ov::Exception);
}

View File

@ -0,0 +1,180 @@
#include <gtest/gtest.h>
#include <string>
#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 <iostream>
# define GTEST_COUT std::cerr << "[ ] [ INFO ] "
# include <codecvt>
# include <functional_test_utils/skip_tests_config.hpp>
# include "openvino/pass/manager.hpp"
#endif
#ifndef OPENVINO_STATIC_LIBRARY
inline void mockPlugin(ov::Core& core, std::shared_ptr<ov::IPlugin>& plugin, std::shared_ptr<void>& 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<void(ov::IPlugin*)> injectProxyEngine =
CommonTestUtils::make_std_function<void(ov::IPlugin*)>(m_so, "InjectPlugin");
injectProxyEngine(plugin.get());
}
TEST(RegisterPluginTests, registerNewPluginNoThrows) {
ov::Core core;
auto plugin = std::make_shared<CommonTestUtils::MockPlugin>();
std::shared_ptr<ov::IPlugin> base_plugin = plugin;
std::shared_ptr<void> 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<CommonTestUtils::MockPlugin>();
std::shared_ptr<ov::IPlugin> base_plugin = plugin;
std::shared_ptr<void> 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 << "<ie><plugins><plugin name=\"mock\" location=\"";
stream << ov::util::make_plugin_library_name(CommonTestUtils::getExecutableDirectory(),
std::string("mock_engine") + IE_BUILD_POSTFIX);
stream << "\"></plugin></plugins></ie>";
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{"<ie><plugins><plugin location=\"libmock_engine.so\"></plugin></plugins></ie>"};
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<std::string> 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<std::string> 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<std::string> 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

View File

@ -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<ov::PropertyName> 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

View File

@ -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 <direct.h>
#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 <class T>
std::function<T> make_std_function(const std::shared_ptr<void> so, const std::string& functionName) {
std::function<T> ptr(reinterpret_cast<T*>(ov::util::get_symbol(so, functionName.c_str())));
return ptr;
}
} // namespace
class MockPlugin : public ov::IPlugin {
std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> compile_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties,
const ov::SoPtr<ov::IRemoteContext>& 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<ov::streams::Num>();
}
OPENVINO_NOT_IMPLEMENTED;
}
ov::Any get_property(const std::string& name, const ov::AnyMap& arguments) const override {
if (name == ov::supported_properties) {
std::vector<ov::PropertyName> 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<ov::IRemoteContext> create_context(const ov::AnyMap& remote_properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
ov::SoPtr<ov::IRemoteContext> get_default_context(const ov::AnyMap& remote_properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model, const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
std::shared_ptr<ov::ICompiledModel> import_model(std::istream& model,
const ov::SoPtr<ov::IRemoteContext>& context,
const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
ov::SupportedOpsMap query_model(const std::shared_ptr<const ov::Model>& model,
const ov::AnyMap& properties) const override {
OPENVINO_NOT_IMPLEMENTED;
}
private:
int32_t num_streams{0};
};
} // namespace CommonTestUtils