From 35e163aea039cb61c724a30747a62c1758a027cb Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Wed, 8 Oct 2025 14:09:50 +0000 Subject: [PATCH 1/7] Add test for ov::util::create_directory_recursive Signed-off-by: Raasz, Pawel --- .../tests/file_util_test.cpp | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp b/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp index 545c988101ab73..0eba0254e05d1d 100644 --- a/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp +++ b/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp @@ -2,18 +2,20 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "openvino/util/file_util.hpp" - #include #include #include #include #include +#include #include +#include "common_test_utils/common_utils.hpp" +#include "common_test_utils/file_utils.hpp" #include "openvino/core/visibility.hpp" #include "openvino/util/file_path.hpp" +#include "openvino/util/file_util.hpp" namespace ov::test { using std::string; @@ -633,4 +635,51 @@ TEST_F(FileUtilTest, androidWithCutFileSizeTest) { EXPECT_EQ(ov::util::file_size(ov::util::Path("android_test_file_20.txt!_to_cut.jar")), 20); } #endif + +using StringPathVariantP = std::variant; + +class FileUtilTestP : public FileUtilTest, public ::testing::WithParamInterface { +protected: + std::filesystem::path get_path_param() const { + return std::visit( + [](auto&& p) { + return std::filesystem::path(p); + }, + GetParam()); + } +}; + +INSTANTIATE_TEST_SUITE_P(string_paths, + FileUtilTestP, + testing::Values("test_encoder/test_encoder.encrypted/", + "test_encoder/test_encoder.encrypted")); +INSTANTIATE_TEST_SUITE_P(u16_paths, + FileUtilTestP, + testing::Values(u"test_encoder/dot.folder", u"test_encoder/dot.folder/")); + +INSTANTIATE_TEST_SUITE_P(u32_paths, + FileUtilTestP, + testing::Values(U"test_encoder/dot.folder", U"test_encoder/dot.folder/")); + +INSTANTIATE_TEST_SUITE_P(wstring_paths, + FileUtilTestP, + testing::Values(L"test_encoder/test_encoder.encrypted", + L"test_encoder/test_encoder.encrypted/")); + +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT +INSTANTIATE_TEST_SUITE_P( + unicode_paths, + FileUtilTestP, + testing::Values("这是.folder", L"这是_folder", L"这是_folder/", u"这是_folder/", U"这是_folder/")); +#endif + +TEST_P(FileUtilTestP, create_directories) { + const auto path = std::filesystem::path(utils::generateTestFilePrefix()) / get_path_param(); + + ov::util::create_directory_recursive(path); + + EXPECT_TRUE(utils::fileExists(path)); + EXPECT_EQ(utils::removeDir(path.string()), 0); + EXPECT_FALSE(utils::fileExists(path)); +} } // namespace ov::test From 9cc5f508109ae8f39063596b385a82820bbdc374 Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Wed, 8 Oct 2025 15:22:46 +0000 Subject: [PATCH 2/7] Fix using test utils Signed-off-by: Raasz, Pawel --- .../test_utils/common_test_utils/tests/file_util_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp b/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp index 0eba0254e05d1d..8292f6eab8abca 100644 --- a/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp +++ b/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp @@ -678,8 +678,8 @@ TEST_P(FileUtilTestP, create_directories) { ov::util::create_directory_recursive(path); - EXPECT_TRUE(utils::fileExists(path)); + EXPECT_TRUE(utils::fileExists(path.string())); EXPECT_EQ(utils::removeDir(path.string()), 0); - EXPECT_FALSE(utils::fileExists(path)); + EXPECT_FALSE(utils::fileExists(path.string())); } } // namespace ov::test From ac260fa24b8a007a1ea0293d5aeeb775db209e87 Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Fri, 10 Oct 2025 08:19:59 +0000 Subject: [PATCH 3/7] Update test to check created path is same as given literals Signed-off-by: Raasz, Pawel --- .../util/include/openvino/util/file_util.hpp | 24 +++++++++++++++++-- .../include/common_test_utils/file_utils.hpp | 6 +++++ .../common_test_utils/src/file_utils.cpp | 19 +++++++++++++++ .../tests/file_util_test.cpp | 21 +++++++++------- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index 506197cd98649a..268bfe145e4c8b 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -346,8 +346,28 @@ inline std::basic_string make_path(const std::basic_string& folder, const return folder + ov::util::FileTraits::file_separator + file; } -inline ov::util::Path make_path(const wchar_t* file) { - return {std::wstring(file)}; +/** + * @brief Creates std::filesystem::path provided by source. + * + * The purpose of this function is to hide platform specific issue with path creation like on Windows create from + * literal std::string with unicode characters can lead to different path name than expected. + * + * @param source Source to create path. Supported types are same as for std::filesystem::path constructor. + * @return std::filesystem::path object. + */ +template +constexpr std::filesystem::path make_path(const Source& source) { + if constexpr (std::is_same_v, wchar_t*>) { + return {std::wstring(source)}; + } +#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) + else if constexpr (std::is_same_v) { + return {ov::util::string_to_wstring(source)}; + } +#endif + else { + return {source}; + } } } // namespace util diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp index 817e91f94bc355..49e577adb2dca8 100644 --- a/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp +++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/file_utils.hpp @@ -6,9 +6,11 @@ #include +#include #include #include #include +#include #include #include "common_test_utils/common_utils.hpp" @@ -259,6 +261,10 @@ class MockPlugin : public ov::IPlugin { int32_t num_streams{0}; }; +using StringPathVariant = std::variant; + +std::filesystem::path to_fs_path(const StringPathVariant& param); + } // namespace utils } // namespace test } // namespace ov diff --git a/src/tests/test_utils/common_test_utils/src/file_utils.cpp b/src/tests/test_utils/common_test_utils/src/file_utils.cpp index edf6ecb8a241a5..d6da3ca8f8ed80 100644 --- a/src/tests/test_utils/common_test_utils/src/file_utils.cpp +++ b/src/tests/test_utils/common_test_utils/src/file_utils.cpp @@ -21,6 +21,7 @@ # include #endif +#include "openvino/util/variant_visitor.hpp" namespace ov { namespace test { namespace utils { @@ -231,6 +232,24 @@ std::string getRelativePath(const std::string& from, const std::string& to) { return output; } +std::filesystem::path to_fs_path(const StringPathVariant& param) { + return std::visit(ov::util::VariantVisitor{ +#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) // && defined(_WIN32) + [](const std::string& p) { + if (std::any_of(p.begin(), p.end(), [](unsigned char c) { + return c > 127; + })) { + return std::filesystem::path(ov::util::string_to_wstring(p)); + } else { + return std::filesystem::path(p); + } + }, +#endif + [](const auto& p) { + return std::filesystem::path(p); + }}, + param); +} } // namespace utils } // namespace test } // namespace ov diff --git a/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp b/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp index 8292f6eab8abca..1119318f06027b 100644 --- a/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp +++ b/src/tests/test_utils/common_test_utils/tests/file_util_test.cpp @@ -636,14 +636,13 @@ TEST_F(FileUtilTest, androidWithCutFileSizeTest) { } #endif -using StringPathVariantP = std::variant; - -class FileUtilTestP : public FileUtilTest, public ::testing::WithParamInterface { +class FileUtilTestP : public FileUtilTest, public ::testing::WithParamInterface { protected: std::filesystem::path get_path_param() const { return std::visit( - [](auto&& p) { - return std::filesystem::path(p); + [](const auto& p) { + // Use OV util to hide some platform details with path creation + return ov::util::make_path(p); }, GetParam()); } @@ -674,12 +673,16 @@ INSTANTIATE_TEST_SUITE_P( #endif TEST_P(FileUtilTestP, create_directories) { - const auto path = std::filesystem::path(utils::generateTestFilePrefix()) / get_path_param(); + const auto test_dir = utils::generateTestFilePrefix(); + const auto path = std::filesystem::path(test_dir) / get_path_param(); + const auto exp_path = std::filesystem::path(test_dir) / utils::to_fs_path(GetParam()); ov::util::create_directory_recursive(path); - EXPECT_TRUE(utils::fileExists(path.string())); - EXPECT_EQ(utils::removeDir(path.string()), 0); - EXPECT_FALSE(utils::fileExists(path.string())); + EXPECT_EQ(path, exp_path); + ASSERT_TRUE(std::filesystem::exists(path)); + ASSERT_TRUE(std::filesystem::exists(exp_path)); + + std::filesystem::remove_all(test_dir); } } // namespace ov::test From d48089c00f1009cf573df9878d922e6f17116973 Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Fri, 10 Oct 2025 09:10:55 +0000 Subject: [PATCH 4/7] Remove constexpr from `make_path` function Signed-off-by: Raasz, Pawel --- src/common/util/include/openvino/util/file_util.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index 268bfe145e4c8b..7a8375f199ec13 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -356,7 +356,7 @@ inline std::basic_string make_path(const std::basic_string& folder, const * @return std::filesystem::path object. */ template -constexpr std::filesystem::path make_path(const Source& source) { +std::filesystem::path make_path(const Source& source) { if constexpr (std::is_same_v, wchar_t*>) { return {std::wstring(source)}; } From c1b16a29e56ebab649e9c716ddb1dc76a314b76a Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Fri, 10 Oct 2025 10:13:16 +0000 Subject: [PATCH 5/7] Update make_path util Signed-off-by: Raasz, Pawel --- src/common/util/include/openvino/util/file_util.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/common/util/include/openvino/util/file_util.hpp b/src/common/util/include/openvino/util/file_util.hpp index 7a8375f199ec13..6eee9c3da0c102 100644 --- a/src/common/util/include/openvino/util/file_util.hpp +++ b/src/common/util/include/openvino/util/file_util.hpp @@ -359,13 +359,10 @@ template std::filesystem::path make_path(const Source& source) { if constexpr (std::is_same_v, wchar_t*>) { return {std::wstring(source)}; - } -#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) - else if constexpr (std::is_same_v) { + } else if constexpr (std::is_same_v && + std::is_same_v) { return {ov::util::string_to_wstring(source)}; - } -#endif - else { + } else { return {source}; } } From 510f6a059f9fca1502e34946e84086963d26237c Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Fri, 10 Oct 2025 10:13:31 +0000 Subject: [PATCH 6/7] Use make_path in core_impl Signed-off-by: Raasz, Pawel --- src/inference/src/dev/core_impl.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/inference/src/dev/core_impl.cpp b/src/inference/src/dev/core_impl.cpp index 56e918714f7610..86843b71c79fcc 100644 --- a/src/inference/src/dev/core_impl.cpp +++ b/src/inference/src/dev/core_impl.cpp @@ -1781,14 +1781,7 @@ ov::CoreConfig::CacheConfig ov::CoreConfig::get_cache_config_for_device(const ov ov::CoreConfig::CacheConfig ov::CoreConfig::CacheConfig::create(const std::string& dir) { CacheConfig cache_config{dir, nullptr}; if (!dir.empty()) { - if constexpr (std::is_same_v) { - // if path native type is same as wstring type (e.g. Windows) convert to wstring - // in case of string has unicode without conversion wrong created dir may have incorrect name - // should be removed if cache_dir will path instead of string - ov::util::create_directory_recursive(ov::util::string_to_wstring(dir)); - } else { - ov::util::create_directory_recursive(dir); - } + ov::util::create_directory_recursive(ov::util::make_path(dir)); cache_config._cacheManager = std::make_shared(dir); } return cache_config; From c17e82ecd52fc4f3f370db2b95132d4a68181772 Mon Sep 17 00:00:00 2001 From: "Raasz, Pawel" Date: Fri, 10 Oct 2025 11:41:34 +0000 Subject: [PATCH 7/7] Uncomment test code Signed-off-by: Raasz, Pawel --- src/tests/test_utils/common_test_utils/src/file_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/test_utils/common_test_utils/src/file_utils.cpp b/src/tests/test_utils/common_test_utils/src/file_utils.cpp index d6da3ca8f8ed80..4e3ef07f44af8c 100644 --- a/src/tests/test_utils/common_test_utils/src/file_utils.cpp +++ b/src/tests/test_utils/common_test_utils/src/file_utils.cpp @@ -234,7 +234,7 @@ std::string getRelativePath(const std::string& from, const std::string& to) { std::filesystem::path to_fs_path(const StringPathVariant& param) { return std::visit(ov::util::VariantVisitor{ -#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) // && defined(_WIN32) +#if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) [](const std::string& p) { if (std::any_of(p.begin(), p.end(), [](unsigned char c) { return c > 127;