Skip to content

Commit

Permalink
Check extension name and add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
riverlijunjie committed Jan 31, 2024
1 parent 816e99a commit dc775af
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/inference/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>().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();
Expand Down
63 changes: 63 additions & 0 deletions src/inference/tests/functional/ov_core_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#include <gtest/gtest.h>

#include <fstream>

#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 << "<ie><plugins><plugin location=\"";
file << ov::test::utils::getExecutableDirectory();
file << ov::util::FileTraits<char>::file_separator;
file << ov::util::FileTraits<char>::library_prefix();
file << "mock_engine";
file << OV_BUILD_POSTFIX;
file << ov::util::FileTraits<char>::dot_symbol;
file << ov::util::FileTraits<char>::library_ext();
file << "\" name=\"1\"></plugin></plugins></ie>";
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<char>::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<char>::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<char>::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

0 comments on commit dc775af

Please sign in to comment.