Skip to content

Commit

Permalink
Update algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
riverlijunjie committed Feb 5, 2024
1 parent dc775af commit a07beb7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
16 changes: 7 additions & 9 deletions src/inference/src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ namespace ov {
std::string find_plugins_xml(const std::string& xml_file) {
std::string xml_file_name = xml_file;
if (xml_file_name.empty()) {
// Default plugin xml file name.
// Default plugin xml file name, will search in OV folder.
xml_file_name = "plugins.xml";
} else {
// 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());
}

// If the xml file exists, will use it; else will search it only in ov folder.
if (ov::util::file_exists(xml_file_name)) {
// User can set any path for plugins xml file but need guarantee security issue if apply file path out of OV
// folder.
// If the xml file exists or file path contains file separator, return file path;
// Else search it in OV folder with no restriction on file name and extension.
if (ov::util::file_exists(xml_file_name) ||
xml_file_name.find(util::FileTraits<char>().file_separator) != xml_file_name.npos) {
return xml_file_name;
}
}
Expand Down
24 changes: 21 additions & 3 deletions src/inference/tests/functional/ov_core_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,25 @@ TEST(CoreBaseTest, LoadPluginXML) {
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadPluginInvalidXML) {
TEST(CoreBaseTest, LoadPluginDifferentXMLExtension) {
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));
EXPECT_NO_THROW(ov::Core core(xml_file_name));
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadAbsoluteOVPathPluginXML) {
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_path));
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadAbsolutePathPluginXML) {
TEST(CoreBaseTest, LoadAbsoluteCWPathPluginXML) {
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;
Expand All @@ -60,4 +69,13 @@ TEST(CoreBaseTest, LoadAbsolutePathPluginXML) {
remove_plugin_xml(xml_file_path);
}

TEST(CoreBaseTest, LoadRelativeCWPathPluginXML) {
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_name));
remove_plugin_xml(xml_file_path);
}

#endif

0 comments on commit a07beb7

Please sign in to comment.