Removed testdata repo usage (#19890)
This commit is contained in:
1 parent
11016a9357
commit
0b8237f508
34 files changed
+63
-451
No files matched your search
@@ -13,9 +13,6 @@ file (GLOB HELPERS_INCLUDES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
|
||||
)
|
||||
|
||||
## Enable Models multiple search paths
|
||||
message("configuring file: ${CMAKE_CURRENT_BINARY_DIR}/test_model_repo.h")
|
||||
|
||||
function(add_helpers target_name)
|
||||
add_library(${target_name} STATIC ${HELPERS_SRC})
|
||||
|
||||
@@ -37,8 +34,3 @@ add_helpers(${TARGET_NAME}_s USE_STATIC_IE)
|
||||
|
||||
target_link_libraries(${TARGET_NAME}_s PUBLIC common_test_utils_s
|
||||
PRIVATE inference_engine_legacy_s)
|
||||
|
||||
if (ENABLE_DATA)
|
||||
add_dependencies(${TARGET_NAME} data)
|
||||
add_dependencies(${TARGET_NAME}_s data)
|
||||
endif()
|
||||
@@ -1,150 +0,0 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
//
|
||||
// Created by user on 19.10.18.
|
||||
//
|
||||
|
||||
#include "helpers/test_model_repo.hpp"
|
||||
#include "test_model_path.hpp"
|
||||
|
||||
#ifndef _WIN32
|
||||
# include <libgen.h>
|
||||
# include <dirent.h>
|
||||
#else
|
||||
# include <samples/os/windows/w_dirent.h>
|
||||
#endif
|
||||
|
||||
#include <utility>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <gtest/gtest.h>
|
||||
#include <fstream>
|
||||
|
||||
#ifndef _WIN32
|
||||
static std::string getDirname(std::string filePath) {
|
||||
std::vector<char> input(filePath.begin(), filePath.end());
|
||||
input.push_back(0);
|
||||
return dirname(&*input.begin());
|
||||
}
|
||||
#else
|
||||
static std::string getDirname(std::string filePath) {
|
||||
char dirname[_MAX_DIR] = {};
|
||||
char drive[_MAX_DRIVE] = {};
|
||||
_splitpath(filePath.c_str(), drive, dirname, nullptr, nullptr); // preserve drive letter if possible
|
||||
return std::string(drive) + dirname;
|
||||
}
|
||||
#endif
|
||||
|
||||
static std::string get_models_path() {
|
||||
const char* models_path = TestDataHelpers::get_model_path_non_fatal();
|
||||
|
||||
if (nullptr == models_path) {
|
||||
::testing::AssertionFailure() << "MODELS_PATH not defined";
|
||||
}
|
||||
|
||||
return std::string(models_path);
|
||||
}
|
||||
|
||||
static bool exist(const std::string& name) {
|
||||
std::ifstream file(name);
|
||||
if(!file) // If the file was not found, then file is 0, i.e. !file=1 or true.
|
||||
return false; // The file was not found.
|
||||
else // If the file was found, then file is non-0.
|
||||
return true; // The file was found.
|
||||
}
|
||||
|
||||
static std::vector<std::string> getModelsDirs() {
|
||||
auto repo_list = get_model_repo();
|
||||
int last_delimiter = 0;
|
||||
std::vector<std::string> folders;
|
||||
for(;;) {
|
||||
auto folderDelimiter = repo_list.find(':', last_delimiter);
|
||||
if (folderDelimiter == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
auto nextDelimiter = repo_list.find(';', last_delimiter);
|
||||
folders.push_back(repo_list.substr(last_delimiter, folderDelimiter - last_delimiter));
|
||||
|
||||
if (nextDelimiter == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
|
||||
last_delimiter = nextDelimiter + 1;
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
|
||||
ModelsPath::operator std::string() const {
|
||||
std::vector<std::string> absModelsPath;
|
||||
for (auto & path : getModelsDirs()) {
|
||||
std::string b = get_models_path();
|
||||
const auto absPath = get_models_path() + kPathSeparator + path + _rel_path.str();
|
||||
absModelsPath.push_back(absPath);
|
||||
if (exist(absPath)) {
|
||||
return absPath;
|
||||
}
|
||||
//checking models for precision encoded in folder name
|
||||
auto dirname = getDirname(absPath);
|
||||
std::vector<std::pair<std::string, std::string>> stdprecisions = {
|
||||
{"_fp32", "FP32"},
|
||||
{"_q78", "_Q78"},
|
||||
{"_fp16", "FP16"},
|
||||
{"_i16", "I16"}
|
||||
};
|
||||
|
||||
if (dirname.size() == absPath.size())
|
||||
continue;
|
||||
|
||||
auto filename = absPath.substr(dirname.size() + 1);
|
||||
|
||||
for (auto &precision : stdprecisions) {
|
||||
auto havePrecision = filename.find(precision.first);
|
||||
if (havePrecision == std::string::npos) continue;
|
||||
|
||||
auto newName = filename.replace(havePrecision, precision.first.size(), "");
|
||||
newName = dirname + kPathSeparator + precision.second + kPathSeparator + newName;
|
||||
|
||||
if (exist(newName)) {
|
||||
return newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// checking dirname
|
||||
auto getModelsDirname = [](std::string path) -> std::string {
|
||||
std::string dir = getDirname(path);
|
||||
|
||||
struct stat sb;
|
||||
if (stat(dir.c_str(), &sb) != 0 || !S_ISDIR(sb.st_mode)) {
|
||||
return "";
|
||||
}
|
||||
return dir;
|
||||
};
|
||||
|
||||
for (auto & path : absModelsPath) {
|
||||
std::string publicDir = getModelsDirname(path);
|
||||
|
||||
if (!publicDir.empty()) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
std::stringstream errorMsg;
|
||||
errorMsg<< "path to model invalid, models found at: \n";
|
||||
|
||||
for (auto & path : absModelsPath) {
|
||||
errorMsg << path <<"\n";
|
||||
}
|
||||
errorMsg << "also searched by parent directory names: \n";
|
||||
for (auto & path : absModelsPath) {
|
||||
errorMsg << getDirname(path) << "\n";
|
||||
}
|
||||
|
||||
std::cout << errorMsg.str();
|
||||
::testing::AssertionFailure() << errorMsg.str();
|
||||
|
||||
// doesn't matter what to return here
|
||||
return "";
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sstream>
|
||||
|
||||
static const char kPathSeparator =
|
||||
#if defined _WIN32 || defined __CYGWIN__
|
||||
'\\';
|
||||
#else
|
||||
'/';
|
||||
#endif
|
||||
|
||||
class ModelsPath {
|
||||
std::stringstream _rel_path;
|
||||
mutable std::string _abs_path;
|
||||
|
||||
public:
|
||||
|
||||
ModelsPath() = default;
|
||||
|
||||
ModelsPath(const ModelsPath & that) {
|
||||
_rel_path << that._rel_path.str();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ModelsPath operator + (const T & relative_path) const {
|
||||
ModelsPath newPath(*this);
|
||||
newPath += relative_path;
|
||||
return newPath;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ModelsPath & operator += (const T & relative_path) {
|
||||
_rel_path << relative_path;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
ModelsPath & operator << (const T & serializable) {
|
||||
_rel_path << serializable;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string str() const {
|
||||
return this->operator std::string();
|
||||
}
|
||||
|
||||
const char * c_str() const {
|
||||
_abs_path = this->operator std::string ();
|
||||
return _abs_path.c_str();
|
||||
}
|
||||
|
||||
operator std::string() const;
|
||||
};
|
||||
|
||||
inline std::ostream & operator << (std::ostream &os, const ModelsPath & path) {
|
||||
os << path.str();
|
||||
return os;
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <ie_input_info.hpp>
|
||||
|
||||
#include "helpers/test_model_repo.hpp"
|
||||
#include "test_model_path.hpp"
|
||||
#include <tests_file_utils.hpp>
|
||||
#include <chrono>
|
||||
|
||||
|
||||
@@ -25,7 +25,3 @@ addIeTargetTest(
|
||||
target_compile_definitions(${TARGET_NAME}
|
||||
PUBLIC ${ARGV}
|
||||
GNA_DATA_PATH=\"${CMAKE_CURRENT_SOURCE_DIR}/data\")
|
||||
|
||||
if (ENABLE_DATA)
|
||||
add_dependencies(${TARGET_NAME} data)
|
||||
endif()
|
||||
@@ -4,14 +4,14 @@
|
||||
|
||||
#include "test_model_repo.hpp"
|
||||
|
||||
std::string get_model_repo() {
|
||||
return "models:";
|
||||
};
|
||||
|
||||
const char* TestDataHelpers::get_model_path_non_fatal() noexcept {
|
||||
return TestDataHelpers::get_model_path_non_fatal_default();
|
||||
}
|
||||
|
||||
std::string TestDataHelpers::get_data_path() {
|
||||
return TestDataHelpers::get_data_path_default();
|
||||
if (const auto env_var = std::getenv("GNA_DATA_PATH")) {
|
||||
return env_var;
|
||||
}
|
||||
|
||||
#ifdef GNA_DATA_PATH
|
||||
return GNA_DATA_PATH;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
@@ -5,35 +5,8 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
std::string get_model_repo();
|
||||
|
||||
namespace TestDataHelpers {
|
||||
|
||||
const char* get_model_path_non_fatal() noexcept;
|
||||
|
||||
std::string get_data_path();
|
||||
|
||||
inline const char* get_model_path_non_fatal_default() noexcept {
|
||||
if (const auto env_var = std::getenv("MODELS_PATH")) {
|
||||
return env_var;
|
||||
}
|
||||
|
||||
#ifdef MODELS_PATH
|
||||
return MODELS_PATH;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
inline std::string get_data_path_default() {
|
||||
if (const auto env_var = std::getenv("GNA_DATA_PATH")) {
|
||||
return env_var;
|
||||
}
|
||||
|
||||
#ifdef GNA_DATA_PATH
|
||||
return GNA_DATA_PATH;
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
} // namespace TestDataHelpers
|
||||
Reference in new issue
Block a user