Skip to content

Commit

Permalink
[UNICODE] solve windows unicode inconsistent issue (openvinotoolkit#2…
Browse files Browse the repository at this point in the history
…3100)

### Details:
 - solve windows unicode inconsistent issue
 - add more test case

### Tickets:
 - Closes openvinotoolkit#23072
 - CVS-128116
  • Loading branch information
riverlijunjie authored Feb 27, 2024
1 parent b711ed0 commit 976298c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/common/util/src/file_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::codecvt_utf8<wchar_t>> wstring_decoder;
Expand All @@ -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<int>(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<std::codecvt_utf8<wchar_t>> wstring_encoder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,6 @@ std::vector<std::string> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ std::vector<std::string> 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).*)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ using compileModelLoadFromFileParams = std::tuple<
class CompileModelLoadFromFileTestBase : public testing::WithParamInterface<compileModelLoadFromFileParams>,
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<compileModelLoadFromFileParams> obj);

void SetUp() override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>()(test_name);
std::stringstream ss;
ss << std::this_thread::get_id();
std::string cache_path = ov::test::utils::getCurrentWorkingDir() + ov::util::FileTraits<char>::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<char>::file_separator + m_modelName);
std::wstring model_bin_path_w =
ov::util::string_to_wstring(cache_path_mb + ov::util::FileTraits<char>::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<compileModelCacheRuntimePropertiesParams> obj) {
auto param = obj.param;
Expand Down

0 comments on commit 976298c

Please sign in to comment.