From ea48786bc67a3284ff9f514945edff7ffba4d72a Mon Sep 17 00:00:00 2001 From: Vitaliy Urusovskij Date: Fri, 27 Jan 2023 09:54:43 +0400 Subject: [PATCH] Fix "(un)register_plugin(s)" C and Py tests (#15291) * Fix "(un)register_plugin(s)" tests * Remove test skips on Debian after tests are fixed --- .ci/azure/linux_debian.yml | 10 +--- src/bindings/c/tests/ie_c_api_test.cpp | 48 +++------------ .../python/tests/test_runtime/test_core.py | 51 ++++++++-------- .../python/tests/test_utils/test_utils.py | 25 +------- .../test_inference_engine/test_IECore.py | 60 ++++++++++--------- .../src/os/lin/lin_shared_object_loader.cpp | 2 +- 6 files changed, 69 insertions(+), 127 deletions(-) diff --git a/.ci/azure/linux_debian.yml b/.ci/azure/linux_debian.yml index f472f6e247a758..1a4bceafd7254b 100644 --- a/.ci/azure/linux_debian.yml +++ b/.ci/azure/linux_debian.yml @@ -225,10 +225,7 @@ jobs: # Skip test_onnx/test_zoo_models and test_onnx/test_backend due to long execution time - script: | - # TODO (vurusovs): revert skip of test_core.py::test_register_plugin*, - # test should be fixed python3 -m pytest -s $(INSTALL_TEST_DIR)/pyngraph \ - -k 'not test_register_plugin' \ --junitxml=$(INSTALL_TEST_DIR)/TEST-Pyngraph.xml \ --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_zoo_models.py \ --ignore=$(INSTALL_TEST_DIR)/pyngraph/tests/test_onnx/test_backend.py @@ -246,10 +243,7 @@ jobs: export OV_FRONTEND_PATH=$(PYTHON_WHEEL_INSTALL_DIR)/openvino/libs:$(INSTALL_TEST_DIR) # For python imports to import pybind_mock_frontend export PYTHONPATH=$(INSTALL_TEST_DIR):$PYTHONPATH - # TODO (vurusovs): revert skip of test_core.py::test_register_plugin*, - # test should be fixed python3 -m pytest -s $(INSTALL_TEST_DIR)/pyopenvino \ - -k 'not test_register_plugin' \ --junitxml=$(INSTALL_TEST_DIR)/TEST-Pyngraph.xml \ --ignore=$(INSTALL_TEST_DIR)/pyopenvino/tests/test_utils/test_utils.py \ --ignore=$(INSTALL_TEST_DIR)/pyopenvino/tests/test_onnx/test_zoo_models.py \ @@ -355,9 +349,7 @@ jobs: displayName: 'CPU FuncTests' - script: | - # TODO (vurusovs): revert skip of ie_core_*register_plugin*, - # tests should be fixed - $(INSTALL_TEST_DIR)/InferenceEngineCAPITests --gtest_filter=-*register_plugin* --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-InferenceEngineCAPITests.xml + $(INSTALL_TEST_DIR)/InferenceEngineCAPITests --gtest_output=xml:$(INSTALL_TEST_DIR)/TEST-InferenceEngineCAPITests.xml env: DATA_PATH: $(MODELS_PATH) MODELS_PATH: $(MODELS_PATH) diff --git a/src/bindings/c/tests/ie_c_api_test.cpp b/src/bindings/c/tests/ie_c_api_test.cpp index 9a0f24c98667b9..0fa0fb8176b63a 100644 --- a/src/bindings/c/tests/ie_c_api_test.cpp +++ b/src/bindings/c/tests/ie_c_api_test.cpp @@ -127,21 +127,10 @@ TEST(ie_core_register_plugin, registerPlugin) { IE_ASSERT_OK(ie_core_create("", &core)); ASSERT_NE(nullptr, core); - ie_network_t *network = nullptr; - IE_EXPECT_OK(ie_core_read_network(core, xml, bin, &network)); - EXPECT_NE(nullptr, network); - - const char *plugin_name = "openvino_intel_cpu_plugin"; + const char *plugin_name = "test_plugin"; const char *device_name = "BLA"; IE_EXPECT_OK(ie_core_register_plugin(core, plugin_name, device_name)); - ie_config_t config = {nullptr, nullptr, nullptr}; - ie_executable_network_t *exe_network = nullptr; - IE_EXPECT_OK(ie_core_load_network(core, network, device_name, &config, &exe_network)); - EXPECT_NE(nullptr, exe_network); - - ie_exec_network_free(&exe_network); - ie_network_free(&network); ie_core_free(&core); } @@ -150,43 +139,24 @@ TEST(ie_core_register_plugins, registerPlugins) { IE_ASSERT_OK(ie_core_create("", &core)); ASSERT_NE(nullptr, core); - ie_network_t *network = nullptr; - IE_EXPECT_OK(ie_core_read_network(core, xml, bin, &network)); - EXPECT_NE(nullptr, network); - IE_EXPECT_OK(ie_core_register_plugins(core, plugins_xml)); - ie_config_t config = {nullptr, nullptr, nullptr}; - const char *device_name = "CUSTOM"; - ie_executable_network_t *exe_network = nullptr; - IE_EXPECT_OK(ie_core_load_network(core, network, device_name, &config, &exe_network)); - EXPECT_NE(nullptr, exe_network); - - ie_exec_network_free(&exe_network); - ie_network_free(&network); ie_core_free(&core); } -TEST(ie_core_unregister_plugin, unregisterPlugin) { +TEST(ie_core_unload_plugin, unloadPlugin) { ie_core_t *core = nullptr; - IE_ASSERT_OK(ie_core_create(plugins_xml, &core)); + IE_ASSERT_OK(ie_core_create("", &core)); ASSERT_NE(nullptr, core); - ie_network_t *network = nullptr; - IE_EXPECT_OK(ie_core_read_network(core, xml, bin, &network)); - EXPECT_NE(nullptr, network); - - ie_config_t config = {nullptr, nullptr, nullptr}; - const char *device_name = "CUSTOM"; - ie_executable_network_t *exe_network = nullptr; - IE_EXPECT_OK(ie_core_load_network(core, network, device_name, &config, &exe_network)); - EXPECT_NE(nullptr, exe_network); - - ie_exec_network_free(&exe_network); - ie_network_free(&network); - + const char *device_name = "CPU"; + ie_core_versions_t versions = {0}; + // Trigger plugin loading + IE_EXPECT_OK(ie_core_get_versions(core, device_name, &versions)); + // Unload plugin IE_EXPECT_OK(ie_core_unregister_plugin(core, device_name)); + ie_core_versions_free(&versions); ie_core_free(&core); } diff --git a/src/bindings/python/tests/test_runtime/test_core.py b/src/bindings/python/tests/test_runtime/test_core.py index 3233cb1422f414..b0ef8dbf60b833 100644 --- a/src/bindings/python/tests/test_runtime/test_core.py +++ b/src/bindings/python/tests/test_runtime/test_core.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import pytest +import sys import numpy as np import os from pathlib import Path @@ -28,7 +29,6 @@ generate_image, generate_relu_compiled_model, get_relu_model, - generate_lib_name, plugins_path, ) @@ -257,43 +257,40 @@ def test_query_model(device): @pytest.mark.dynamic_library() -def test_register_plugin(device): +def test_register_plugin(): + device = "TEST_DEVICE" + lib_name = "test_plugin" + full_lib_name = lib_name + ".dll" if sys.platform == "win32" else "lib" + lib_name + ".so" + core = Core() - full_device_name = core.get_property(device, "FULL_DEVICE_NAME") - lib_name = generate_lib_name(device, full_device_name) - core.register_plugin(lib_name, "BLA") - model = core.read_model(model=test_net_xml, weights=test_net_bin) - compiled_model = core.compile_model(model, "BLA") - assert isinstance(compiled_model, CompiledModel), "Cannot load the network to the registered plugin with name 'BLA'" + core.register_plugin(lib_name, device) + with pytest.raises(RuntimeError) as e: + core.get_versions(device) + assert f"Cannot load library '{full_lib_name}'" in str(e.value) @pytest.mark.dynamic_library() -def test_register_plugins(device): +def test_register_plugins(): + device = "TEST_DEVICE" + lib_name = "test_plugin" + full_lib_name = lib_name + ".dll" if sys.platform == "win32" else "lib" + lib_name + ".so" + plugins_xml = plugins_path(device, full_lib_name) + core = Core() - full_device_name = core.get_property(device, "FULL_DEVICE_NAME") - plugins_xml = plugins_path(device, full_device_name) core.register_plugins(plugins_xml) - model = core.read_model(model=test_net_xml, weights=test_net_bin) - compiled_model = core.compile_model(model, "CUSTOM") os.remove(plugins_xml) - assert isinstance(compiled_model, CompiledModel), ( - "Cannot load the network to " - "the registered plugin with name 'CUSTOM' " - "registered in the XML file" - ) + + with pytest.raises(RuntimeError) as e: + core.get_versions(device) + assert f"Cannot load library '{full_lib_name}'" in str(e.value) -@pytest.mark.skip(reason="Need to figure out if it's expected behaviour (fails with C++ API as well") -def test_unregister_plugin(device): +def test_unload_plugin(device): core = Core() + # Trigger plugin loading + core.get_versions(device) + # Unload plugin core.unload_plugin(device) - model = core.read_model(model=test_net_xml, weights=test_net_bin) - with pytest.raises(RuntimeError) as e: - core.load_network(model, device) - assert ( - f"Device with '{device}' name is not registered in the OpenVINO Runtime" - in str(e.value) - ) @pytest.mark.template_plugin() diff --git a/src/bindings/python/tests/test_utils/test_utils.py b/src/bindings/python/tests/test_utils/test_utils.py index 69ee3ba72ce04d..7bc35a79fa5f30 100644 --- a/src/bindings/python/tests/test_utils/test_utils.py +++ b/src/bindings/python/tests/test_utils/test_utils.py @@ -10,7 +10,6 @@ import pytest from pathlib import Path -from platform import processor import openvino import openvino.runtime.opset8 as ops @@ -28,30 +27,10 @@ def test_compare_models(): print("openvino.test_utils.compare_models is not available") # noqa: T201 -def generate_lib_name(device, full_device_name): - lib_name = "" - arch = processor() - if arch == "x86_64" or "Intel" in full_device_name or device in ["GNA", "VPUX"]: - lib_name = "openvino_intel_" + device.lower() + "_plugin" - elif arch != "x86_64" and device == "CPU": - lib_name = "openvino_arm_cpu_plugin" - elif device in ["HETERO", "MULTI", "AUTO"]: - lib_name = "openvino_" + device.lower() + "_plugin" - return lib_name - - -def plugins_path(device, full_device_name): - lib_name = generate_lib_name(device, full_device_name) - full_lib_name = "" - - if sys.platform == "win32": - full_lib_name = lib_name + ".dll" - else: - full_lib_name = "lib" + lib_name + ".so" - +def plugins_path(device, lib_path): plugin_xml = f""" - + """ diff --git a/src/bindings/python/tests_compatibility/test_inference_engine/test_IECore.py b/src/bindings/python/tests_compatibility/test_inference_engine/test_IECore.py index b0449985e914e5..5d614009334eeb 100644 --- a/src/bindings/python/tests_compatibility/test_inference_engine/test_IECore.py +++ b/src/bindings/python/tests_compatibility/test_inference_engine/test_IECore.py @@ -85,45 +85,49 @@ def test_query_network(device): @pytest.mark.dynamic_library -@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test") def test_register_plugin(): - ie = IECore() - if ie.get_metric("CPU", "FULL_DEVICE_NAME") == "arm_compute::NEON": - pytest.skip("Can't run on ARM plugin due-to openvino_intel_cpu_plugin specific test") - ie.register_plugin("openvino_intel_cpu_plugin", "BLA") - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - exec_net = ie.load_network(net, "BLA") - assert isinstance(exec_net, ExecutableNetwork), "Cannot load the network to the registered plugin with name 'BLA'" + device = "TEST_DEVICE" + lib_name = "test_plugin" + full_lib_name = lib_name + ".dll" if sys.platform == "win32" else "lib" + lib_name + ".so" + ie = IECore() + ie.register_plugin(lib_name, device) + with pytest.raises(RuntimeError) as e: + ie.get_versions(device) + assert f"Cannot load library '{full_lib_name}'" in str(e.value) @pytest.mark.dynamic_library -@pytest.mark.skipif(os.environ.get("TEST_DEVICE", "CPU") != "CPU", reason="Device dependent test") def test_register_plugins(): + device = "TEST_DEVICE" + lib_name = "test_plugin" + full_lib_name = lib_name + ".dll" if sys.platform == "win32" else "lib" + lib_name + ".so" + plugins_xml_path = os.path.join(os.getcwd(), "plugin_path.xml") + + plugin_xml = f""" + + + + + """ + + with open(plugins_xml_path, "w") as f: + f.write(plugin_xml) + ie = IECore() - if ie.get_metric("CPU", "FULL_DEVICE_NAME") == "arm_compute::NEON": - pytest.skip("Can't run on ARM plugin due-to openvino_intel_cpu_plugin specific test") - if platform == "linux" or platform == "linux2": - ie.register_plugins(plugins_xml) - elif platform == "darwin": - ie.register_plugins(plugins_osx_xml) - elif platform == "win32": - ie.register_plugins(plugins_win_xml) + ie.register_plugins(plugins_xml_path) + os.remove(plugins_xml_path) - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - exec_net = ie.load_network(net, "CUSTOM") - assert isinstance(exec_net, - ExecutableNetwork), "Cannot load the network to the registered plugin with name 'CUSTOM' " \ - "registred in the XML file" + with pytest.raises(RuntimeError) as e: + ie.get_versions(device) + assert f"Cannot load library '{full_lib_name}'" in str(e.value) -@pytest.mark.skip(reason="Need to figure out if it's expected behaviour (fails with C++ API as well") -def test_unregister_plugin(device): +def test_unload_plugin(device): ie = IECore() + # Trigger plugin loading + ie.get_versions(device) + # Unload plugin ie.unregister_plugin(device) - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - with pytest.raises(RuntimeError) as e: - ie.load_network(net, device) - assert f"Device with '{device}' name is not registered in the OpenVINO Runtime" in str(e.value) def test_available_devices(device): diff --git a/src/common/util/src/os/lin/lin_shared_object_loader.cpp b/src/common/util/src/os/lin/lin_shared_object_loader.cpp index 4d9cba447f0903..ad97072c6d63db 100644 --- a/src/common/util/src/os/lin/lin_shared_object_loader.cpp +++ b/src/common/util/src/os/lin/lin_shared_object_loader.cpp @@ -26,7 +26,7 @@ std::shared_ptr load_shared_object(const char* path) { }}; if (!shared_object) { std::stringstream ss; - ss << "Cannot load library '" << path; + ss << "Cannot load library '" << path << "'"; if (auto error = dlerror()) { ss << ": " << error; }