Skip to content

Commit

Permalink
Remove duplicated common test util functions (#22981)
Browse files Browse the repository at this point in the history
### Details:
 - *item1*
 - *...*

### Tickets:
 - *ticket-id*
  • Loading branch information
riverlijunjie authored Feb 21, 2024
1 parent fa43c7b commit 65f1fe9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,18 @@ TEST_P(CompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinaries) {
auto execNet = core->compile_model(function, targetDevice, configuration);
execNet = {};
// Check that directory with cached kernels exists after loading network
ASSERT_TRUE(ov::test::utils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist";
ASSERT_TRUE(ov::util::directory_exists(cache_path)) << "Directory with cached kernels doesn't exist";
// Check that folder contains cache files and remove them
for (auto& ext : m_extList) {
// Check that folder contains cache files and remove them
ASSERT_GT(ov::test::utils::removeFilesWithExt(cache_path, ext), 0);
}
// Remove directory and check that it doesn't exist anymore
ASSERT_EQ(ov::test::utils::removeDir(cache_path), 0);
ASSERT_FALSE(ov::test::utils::directoryExists(cache_path));
ASSERT_FALSE(ov::util::directory_exists(cache_path));
} catch (std::exception& ex) {
// Cleanup in case of any exception
if (ov::test::utils::directoryExists(cache_path)) {
if (ov::util::directory_exists(cache_path)) {
for (auto& ext : m_extList) {
// Check that folder contains cache files and remove them
ASSERT_GT(ov::test::utils::removeFilesWithExt(cache_path, ext), 0);
Expand All @@ -752,7 +752,7 @@ TEST_P(CompiledKernelsCacheTest, TwoNetworksWithSameModelCreatesSameCache) {
}

// Check that directory with cached kernels exists after loading network
ASSERT_TRUE(ov::test::utils::directoryExists(cache_path)) << "Directory with cached kernels doesn't exist";
ASSERT_TRUE(ov::util::directory_exists(cache_path)) << "Directory with cached kernels doesn't exist";
// Load 2nd CNNNetwork
auto execNet2 = core->compile_model(function, targetDevice, configuration);
execNet2 = {};
Expand All @@ -767,10 +767,10 @@ TEST_P(CompiledKernelsCacheTest, TwoNetworksWithSameModelCreatesSameCache) {

// Remove directory and check that it doesn't exist anymore
ASSERT_EQ(ov::test::utils::removeDir(cache_path), 0);
ASSERT_FALSE(ov::test::utils::directoryExists(cache_path));
ASSERT_FALSE(ov::util::directory_exists(cache_path));
} catch (std::exception& ex) {
// Cleanup in case of any exception
if (ov::test::utils::directoryExists(cache_path)) {
if (ov::util::directory_exists(cache_path)) {
for (auto& ext : m_extList) {
// Check that folder contains cache files and remove them
ASSERT_GE(ov::test::utils::removeFilesWithExt(cache_path, ext), 0);
Expand All @@ -796,18 +796,18 @@ TEST_P(CompiledKernelsCacheTest, CanCreateCacheDirAndDumpBinariesUnicodePath) {
auto execNet = core->compile_model(function, targetDevice, configuration);
execNet = {};
// Check that directory with cached kernels exists after loading network
ASSERT_TRUE(ov::test::utils::directoryExists(cache_path_w)) << "Directory with cached kernels doesn't exist";
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
for (auto& ext : m_extList) {
// Check that folder contains cache files and remove them
ASSERT_GT(ov::test::utils::removeFilesWithExt(cache_path_w, ov::test::utils::stringToWString(ext)), 0);
}
// Remove directory and check that it doesn't exist anymore
ASSERT_EQ(ov::test::utils::removeDir(cache_path_w), 0);
ASSERT_FALSE(ov::test::utils::directoryExists(cache_path_w));
ASSERT_FALSE(ov::util::directory_exists(cache_path_w));
} catch (std::exception& ex) {
// Cleanup in case of any exception
if (ov::test::utils::directoryExists(cache_path_w)) {
if (ov::util::directory_exists(cache_path_w)) {
for (auto& ext : m_extList) {
// Check that folder contains cache files and remove them
ASSERT_GT(ov::test::utils::removeFilesWithExt(cache_path_w, ov::test::utils::stringToWString(ext)), 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,6 @@ inline int removeDir(const std::string& path) {
return rmdir(path.c_str());
}

inline bool directoryExists(const std::string& path) {
struct stat sb;

if (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
return true;
}

return false;
}

inline int createDirectory(const std::string& dirPath) {
#ifdef _WIN32
return _mkdir(dirPath.c_str());
Expand All @@ -154,24 +144,6 @@ inline int createDirectory(const std::string& dirPath) {
#endif
}

inline int createDirectoryRecursive(const std::string& dirPath) {
std::string copyDirPath = dirPath;
std::vector<std::string> nested_dir_names;
while (!directoryExists(copyDirPath)) {
auto pos = copyDirPath.rfind(FileSeparator);
nested_dir_names.push_back(copyDirPath.substr(pos, copyDirPath.length() - pos));
copyDirPath = copyDirPath.substr(0, pos);
}
while (!nested_dir_names.empty()) {
copyDirPath = copyDirPath + nested_dir_names.back();
if (createDirectory(copyDirPath) != 0) {
return -1;
}
nested_dir_names.pop_back();
}
return 0;
}

inline std::vector<std::string> splitStringByDelimiter(std::string paths, const std::string& delimiter = ",") {
size_t delimiterPos;
std::vector<std::string> splitPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,6 @@ inline int removeDir(std::wstring path) {
return result;
}

inline bool directoryExists(const std::wstring& path) {
# ifdef _WIN32
struct _stat64i32 sb;
if (_wstat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
return true;
}
# else
struct stat sb;
if (stat(ov::util::wstring_to_string(path).c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
return true;
}
# endif

return false;
}

extern const std::vector<std::wstring> test_unicode_postfix_vector;

} // namespace utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ void ApiSummary::saveReport() {
}
filename += ov::test::utils::REPORT_EXTENSION;

if (!ov::test::utils::directoryExists(outputFolder)) {
ov::test::utils::createDirectoryRecursive(outputFolder);
if (!ov::util::directory_exists(outputFolder)) {
ov::util::create_directory_recursive(outputFolder);
}

std::string outputFilePath = outputFolder + std::string(ov::test::utils::FileSeparator) + filename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ void OpSummary::saveReport() {
}
filename += ov::test::utils::REPORT_EXTENSION;

if (!ov::test::utils::directoryExists(outputFolder)) {
ov::test::utils::createDirectoryRecursive(outputFolder);
if (!ov::util::directory_exists(outputFolder)) {
ov::util::create_directory_recursive(outputFolder);
}

std::string outputFilePath = outputFolder + std::string(ov::test::utils::FileSeparator) + filename;
Expand Down

0 comments on commit 65f1fe9

Please sign in to comment.