From dc775af840728dd0f7eb83c228734fa4eccd99b2 Mon Sep 17 00:00:00 2001 From: "River.Li" Date: Wed, 31 Jan 2024 22:59:40 +0800 Subject: [PATCH] Check extension name and add test cases --- src/inference/src/core.cpp | 14 ++--- .../tests/functional/ov_core_test.cpp | 63 +++++++++++++++++++ 2 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 src/inference/tests/functional/ov_core_test.cpp diff --git a/src/inference/src/core.cpp b/src/inference/src/core.cpp index b730f9fdeee14f..5868a188add814 100644 --- a/src/inference/src/core.cpp +++ b/src/inference/src/core.cpp @@ -22,15 +22,15 @@ std::string find_plugins_xml(const std::string& xml_file) { // Default plugin xml file name. xml_file_name = "plugins.xml"; } else { - // Exclude relative path - const auto relative_path_symbol = std::string("..") + util::FileTraits().file_separator; - if (xml_file_name.find(relative_path_symbol) != xml_file_name.npos) { - OPENVINO_THROW("Unsupport plugin xml file relative path: ", xml_file_name.c_str()); + // Check plugin xml extension name. + if (!ov::util::ends_with(xml_file_name, "xml") && !ov::util::ends_with(xml_file_name, "XML")) { + OPENVINO_THROW("Unsupport plugin xml file with non-xml extension name(.xml or .XML): ", + xml_file_name.c_str()); } - // Check plugin xml extension name - if (!ov::util::ends_with(xml_file_name, "xml") && !ov::util::ends_with(xml_file_name, "XML")) { - OPENVINO_THROW("Unsupport plugin xml file with non-xml extension name: ", xml_file_name.c_str()); + // If the xml file exists, will use it; else will search it only in ov folder. + if (ov::util::file_exists(xml_file_name)) { + return xml_file_name; } } const auto ov_library_path = ov::util::get_ov_lib_path(); diff --git a/src/inference/tests/functional/ov_core_test.cpp b/src/inference/tests/functional/ov_core_test.cpp new file mode 100644 index 00000000000000..88057e8da475c8 --- /dev/null +++ b/src/inference/tests/functional/ov_core_test.cpp @@ -0,0 +1,63 @@ +// Copyright (C) 2018-2024 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include + +#include + +#include "common_test_utils/common_utils.hpp" +#include "common_test_utils/file_utils.hpp" +#include "openvino/runtime/core.hpp" +#include "openvino/util/file_util.hpp" + +#ifndef OPENVINO_STATIC_LIBRARY + +static void create_plugin_xml(const std::string& file_name) { + std::ofstream file(file_name); + + file << "::file_separator; + file << ov::util::FileTraits::library_prefix(); + file << "mock_engine"; + file << OV_BUILD_POSTFIX; + file << ov::util::FileTraits::dot_symbol; + file << ov::util::FileTraits::library_ext(); + file << "\" name=\"1\">"; + file.flush(); + file.close(); +} + +static void remove_plugin_xml(const std::string& file_name) { + ov::test::utils::removeFile(file_name); +} + +TEST(CoreBaseTest, LoadPluginXML) { + std::string xml_file_name = "test_plugin.xml"; + std::string xml_file_path = + ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits::file_separator + xml_file_name; + create_plugin_xml(xml_file_path); + EXPECT_NO_THROW(ov::Core core(xml_file_name)); + remove_plugin_xml(xml_file_path); +} + +TEST(CoreBaseTest, LoadPluginInvalidXML) { + std::string xml_file_name = "test_plugin.test"; + std::string xml_file_path = + ov::test::utils::getOpenvinoLibDirectory() + ov::util::FileTraits::file_separator + xml_file_name; + create_plugin_xml(xml_file_path); + EXPECT_ANY_THROW(ov::Core core(xml_file_name)); + remove_plugin_xml(xml_file_path); +} + +TEST(CoreBaseTest, LoadAbsolutePathPluginXML) { + std::string xml_file_name = "test_plugin.xml"; + std::string xml_file_path = + ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits::file_separator + xml_file_name; + create_plugin_xml(xml_file_path); + EXPECT_NO_THROW(ov::Core core(xml_file_path)); + remove_plugin_xml(xml_file_path); +} + +#endif \ No newline at end of file