Skip to content

Commit

Permalink
Fix "(un)register_plugin(s)" C and Py tests (openvinotoolkit#15291)
Browse files Browse the repository at this point in the history
* Fix "(un)register_plugin(s)" tests

* Remove test skips on Debian after tests are fixed
  • Loading branch information
vurusovs authored Jan 27, 2023
1 parent 369bce2 commit ea48786
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 127 deletions.
10 changes: 1 addition & 9 deletions .ci/azure/linux_debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down
48 changes: 9 additions & 39 deletions src/bindings/c/tests/ie_c_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
51 changes: 24 additions & 27 deletions src/bindings/python/tests/test_runtime/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

import pytest
import sys
import numpy as np
import os
from pathlib import Path
Expand All @@ -28,7 +29,6 @@
generate_image,
generate_relu_compiled_model,
get_relu_model,
generate_lib_name,
plugins_path,
)

Expand Down Expand Up @@ -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()
Expand Down
25 changes: 2 additions & 23 deletions src/bindings/python/tests/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import pytest

from pathlib import Path
from platform import processor

import openvino
import openvino.runtime.opset8 as ops
Expand All @@ -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"""<ie>
<plugins>
<plugin location="{full_lib_name}" name="CUSTOM">
<plugin location="{lib_path}" name="{device}">
</plugin>
</plugins>
</ie>"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"""<ie>
<plugins>
<plugin location="{full_lib_name}" name="{device}">
</plugin>
</plugins>
</ie>"""

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):
Expand Down
2 changes: 1 addition & 1 deletion src/common/util/src/os/lin/lin_shared_object_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ std::shared_ptr<void> 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;
}
Expand Down

0 comments on commit ea48786

Please sign in to comment.