From 976298c41725ef7618e06a260b3f50f38e7d7a35 Mon Sep 17 00:00:00 2001 From: River Li Date: Tue, 27 Feb 2024 20:32:16 +0800 Subject: [PATCH] [UNICODE] solve windows unicode inconsistent issue (#23100) ### Details: - solve windows unicode inconsistent issue - add more test case ### Tickets: - Closes https://github.com/openvinotoolkit/openvino/issues/23072 - CVS-128116 --- src/common/util/src/file_util.cpp | 8 +-- .../behavior/ov_plugin/caching_tests.cpp | 4 ++ .../skip_tests_config.cpp | 4 -- .../skip_tests_config.cpp | 3 - .../behavior/ov_plugin/caching_tests.hpp | 2 +- .../src/behavior/ov_plugin/caching_tests.cpp | 55 +++++++++++++++++++ 6 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/common/util/src/file_util.cpp b/src/common/util/src/file_util.cpp index 8beebf295928b1..b845c7b9737e98 100644 --- a/src/common/util/src/file_util.cpp +++ b/src/common/util/src/file_util.cpp @@ -340,9 +340,9 @@ void ov::util::convert_path_win_style(std::string& path) { std::string ov::util::wstring_to_string(const std::wstring& wstr) { # ifdef _WIN32 - int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); + int size_needed = WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); std::string strTo(size_needed, 0); - WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); + WideCharToMultiByte(CP_ACP, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); return strTo; # else std::wstring_convert> wstring_decoder; @@ -354,9 +354,9 @@ std::wstring ov::util::string_to_wstring(const std::string& string) { const char* str = string.c_str(); # ifdef _WIN32 int strSize = static_cast(std::strlen(str)); - int size_needed = MultiByteToWideChar(CP_UTF8, 0, str, strSize, NULL, 0); + int size_needed = MultiByteToWideChar(CP_ACP, 0, str, strSize, NULL, 0); std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, str, strSize, &wstrTo[0], size_needed); + MultiByteToWideChar(CP_ACP, 0, str, strSize, &wstrTo[0], size_needed); return wstrTo; # else std::wstring_convert> wstring_encoder; diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp index da54ed76e2dada..4275074c69e8cb 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/ov_plugin/caching_tests.cpp @@ -144,6 +144,10 @@ namespace { CompileModelLoadFromMemoryTestBase, ::testing::Combine(::testing::ValuesIn(TestCpuTargets), ::testing::ValuesIn(CpuConfigs)), CompileModelLoadFromMemoryTestBase::getTestCaseName); + INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_CPU, + CompileModelLoadFromFileTestBase, + ::testing::Combine(::testing::ValuesIn(TestCpuTargets), ::testing::ValuesIn(CpuConfigs)), + CompileModelLoadFromMemoryTestBase::getTestCaseName); INSTANTIATE_TEST_SUITE_P(smoke_CachingSupportCase_CPU, CompileModelCacheRuntimePropertiesTestBase, ::testing::Combine(::testing::ValuesIn(TestCpuTargets), ::testing::ValuesIn(CpuConfigs)), diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp index 4a643a42ce6324..8f0c39e50fef5d 100644 --- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp @@ -300,10 +300,6 @@ std::vector disabledTestPatterns() { retVector.emplace_back(R"(smoke_Snippets.*)"); #endif -#if defined(_WIN32) - retVector.emplace_back(R"(.*LoadNetworkCompiledKernelsCacheTest.*CanCreateCacheDirAndDumpBinariesUnicodePath.*)"); -#endif - if (!ov::with_cpu_x86_avx512_core()) { // on platforms which do not support bfloat16, we are disabling bf16 tests since there are no bf16 primitives, // tests are useless on such platforms diff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp index 9508397faf53b2..27764e3070e976 100644 --- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp +++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp @@ -62,9 +62,6 @@ std::vector disabledTestPatterns() { R"(.*CachingSupportCase.*LoadNetworkCacheTestBase.*CompareWithRefImpl.*)", // Issue: 119648 R"(.*smoke_LPT/InterpolateTransformation.*)", -#if defined(_WIN32) - R"(.*KernelCachingSupportCase.*CanCreateCacheDirAndDumpBinariesUnicodePath.*)", -#endif R"(.*CachingSupportCase.*GPU.*CompileModelCacheTestBase.*CompareWithRefImpl.*)", // unsupported metrics R"(.*nightly_HeteroAutoBatchOVGetMetricPropsTest.*OVGetMetricPropsTest.*(FULL_DEVICE_NAME_with_DEVICE_ID|AVAILABLE_DEVICES|DEVICE_UUID|OPTIMIZATION_CAPABILITIES|MAX_BATCH_SIZE|DEVICE_GOPS|DEVICE_TYPE|RANGE_FOR_ASYNC_INFER_REQUESTS|RANGE_FOR_STREAMS).*)", diff --git a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp index 5e91f3f8e8db73..70ba11c7665cd0 100644 --- a/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp +++ b/src/tests/functional/plugin/shared/include/behavior/ov_plugin/caching_tests.hpp @@ -64,11 +64,11 @@ using compileModelLoadFromFileParams = std::tuple< class CompileModelLoadFromFileTestBase : public testing::WithParamInterface, virtual public SubgraphBaseTest, virtual public OVPluginTestBase { +public: std::string m_cacheFolderName; std::string m_modelName; std::string m_weightsName; -public: static std::string getTestCaseName(testing::TestParamInfo obj); void SetUp() override; diff --git a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp index bcdb866a8658e0..66d46dcccbba9a 100644 --- a/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp +++ b/src/tests/functional/plugin/shared/src/behavior/ov_plugin/caching_tests.cpp @@ -333,6 +333,61 @@ TEST_P(CompileModelLoadFromFileTestBase, CanLoadFromFileWithoutException) { run(); } +#ifdef OPENVINO_ENABLE_UNICODE_PATH_SUPPORT +TEST_P(CompileModelLoadFromFileTestBase, CanCreateCacheDirAndDumpBinariesUnicodePath) { + std::string test_name = ::testing::UnitTest::GetInstance()->current_test_info()->name(); + auto hash = std::hash()(test_name); + std::stringstream ss; + ss << std::this_thread::get_id(); + std::string cache_path = ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits::file_separator + + "compiledModel_" + std::to_string(hash) + "_" + ss.str() + "_" + GetTimestamp() + "_cache"; + std::wstring postfix = L"_" + ov::test::utils::test_unicode_postfix_vector[0]; + std::wstring cache_path_w = ov::util::string_to_wstring(cache_path) + postfix; + auto cache_path_mb = ov::util::wstring_to_string(cache_path_w); + std::wstring model_xml_path_w = + ov::util::string_to_wstring(cache_path_mb + ov::util::FileTraits::file_separator + m_modelName); + std::wstring model_bin_path_w = + ov::util::string_to_wstring(cache_path_mb + ov::util::FileTraits::file_separator + m_weightsName); + + try { + ov::test::utils::createDirectory(cache_path_mb); + + // Copy IR files into unicode folder for read_model test + ov::test::utils::copyFile(m_modelName, model_xml_path_w); + ov::test::utils::copyFile(m_weightsName, model_bin_path_w); + + // Set unicode folder as cache_dir + core->set_property(ov::cache_dir(cache_path_mb)); + // Read model from unicode folder + auto model = core->read_model(ov::util::wstring_to_string(model_xml_path_w)); + + // Load model to target plugins + auto compiled_model = core->compile_model(model, targetDevice, configuration); + compiled_model = {}; + model = {}; + // Check that directory with cached model exists after loading network + ASSERT_TRUE(ov::util::directory_exists(cache_path_w)) << "Directory with cached kernels doesn't exist"; + // Check that folder contains cache files and remove them + ASSERT_GT(ov::test::utils::removeFilesWithExt(cache_path_w, ov::util::string_to_wstring("blob")), 0); + ov::test::utils::removeFile(model_xml_path_w); + ov::test::utils::removeFile(model_bin_path_w); + // Remove directory and check that it doesn't exist anymore + ov::test::utils::removeDir(cache_path_w); + ASSERT_FALSE(ov::util::directory_exists(cache_path_w)); + } catch (std::exception& ex) { + // Cleanup in case of any exception + if (ov::util::directory_exists(cache_path_w)) { + // Check that folder contains cache files and remove them + ASSERT_GT(ov::test::utils::removeFilesWithExt(cache_path_w, ov::util::string_to_wstring("blob")), 0); + ov::test::utils::removeFile(model_xml_path_w); + ov::test::utils::removeFile(model_bin_path_w); + ov::test::utils::removeDir(cache_path_w); + } + FAIL() << ex.what() << std::endl; + } +} +#endif + std::string CompileModelCacheRuntimePropertiesTestBase::getTestCaseName( testing::TestParamInfo obj) { auto param = obj.param;