已合并
消除platform manager相对路径 #736
handong12138创建于 3月10日
消除platform manager相对路径 #736
已合并
共 7 个文件变更+81-117
| @@ -73,10 +73,6 @@ class PlatformInfoManager { | |||
| 73 | 73 | ||
| 74 | uint32_t LoadConfigFile(std::string real_path); | 74 | uint32_t LoadConfigFile(std::string real_path); |
| 75 | 75 | ||
| 76 | - std::string RealPath(const std::string &path); | ||
| 77 | - | ||
| 78 | - std::string GetSoFilePath(); | ||
| 79 | - | ||
| 80 | void ParseVersion(std::map<std::string, std::string> &version_map, | 76 | void ParseVersion(std::map<std::string, std::string> &version_map, |
| 81 | std::string &soc_version, | 77 | std::string &soc_version, |
| 82 | PlatformInfo &platform_info_temp); | 78 | PlatformInfo &platform_info_temp); |
| @@ -10,21 +10,17 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | - | ||
| 14 | 13 | ||
| 15 | 14 | ||
| 16 | 15 | ||
| 17 | - | ||
| 18 | 16 | ||
| 19 | 17 | ||
| 20 | - | ||
| 21 | 18 | ||
| 22 | 19 | ||
| 23 | 20 | ||
| 24 | namespace fe { | 21 | namespace fe { |
| 25 | namespace { | 22 | namespace { |
| 26 | const std::string FIXPIPE_CONFIG_KEY = "Intrinsic_fix_pipe_"; | 23 | const std::string FIXPIPE_CONFIG_KEY = "Intrinsic_fix_pipe_"; |
| 27 | -const std::string PLATFORM_RELATIVE_PATH = "../data/platform_config"; | ||
| 28 | const std::string INI_FILE_SUFFIX = "ini"; | 24 | const std::string INI_FILE_SUFFIX = "ini"; |
| 29 | const std::string STR_SOC_VERSION = "SoC_version"; | 25 | const std::string STR_SOC_VERSION = "SoC_version"; |
| 30 | const std::string STR_AIC_VERSION = "AIC_version"; | 26 | const std::string STR_AIC_VERSION = "AIC_version"; |
| @@ -930,55 +926,13 @@ uint32_t PlatformInfoManager::ParsePlatformInfo(std::map<std::string, std::map<s | |||
| 930 | return PLATFORM_SUCCESS; | 926 | return PLATFORM_SUCCESS; |
| 931 | } | 927 | } |
| 932 | 928 | ||
| 933 | -std::string PlatformInfoManager::RealPath(const std::string &path) { | ||
| 934 | - if (path.empty()) { | ||
| 935 | - PF_LOGE("Path string is NULL."); | ||
| 936 | - return ""; | ||
| 937 | - } | ||
| 938 | - | ||
| 939 | - if (path.size() >= PATH_MAX) { | ||
| 940 | - PF_LOGE("File path '%s' is too long!", path.c_str()); | ||
| 941 | - return ""; | ||
| 942 | - } | ||
| 943 | - | ||
| 944 | - char resoved_path[PATH_MAX] = {0}; | ||
| 945 | - std::string res = ""; | ||
| 946 | - | ||
| 947 | - if (realpath(path.c_str(), resoved_path) != nullptr) { | ||
| 948 | - res = resoved_path; | ||
| 949 | - } else { | ||
| 950 | - PF_LOGE("Path '%s' does not exist.", path.c_str()); | ||
| 951 | - } | ||
| 952 | - return res; | ||
| 953 | -} | ||
| 954 | - | ||
| 955 | -std::string PlatformInfoManager::GetSoFilePath() { | ||
| 956 | - Dl_info dl_info; | ||
| 957 | - std::string real_file_path = ""; | ||
| 958 | - PlatformInfoManager &(*instance_ptr)() = &PlatformInfoManager::Instance; | ||
| 959 | - if (dladdr(reinterpret_cast<void *>(instance_ptr), &dl_info) == 0) { | ||
| 960 | - PF_LOGE("Failed to read the so file path."); | ||
| 961 | - return real_file_path; | ||
| 962 | - } else { | ||
| 963 | - std::string so_path = dl_info.dli_fname; | ||
| 964 | - if (so_path.empty()) { | ||
| 965 | - PF_LOGE("The so file path is empty."); | ||
| 966 | - return real_file_path; | ||
| 967 | - } | ||
| 968 | - real_file_path = RealPath(so_path); | ||
| 969 | - size_t pos = real_file_path.rfind('/'); | ||
| 970 | - real_file_path = real_file_path.substr(0, pos + 1); | ||
| 971 | - } | ||
| 972 | - return real_file_path; | ||
| 973 | -} | ||
| 974 | - | ||
| 975 | __attribute__((visibility("default"))) uint32_t PlatformInfoManager::InitializePlatformInfo() { | 929 | __attribute__((visibility("default"))) uint32_t PlatformInfoManager::InitializePlatformInfo() { |
| 976 | // add lock | 930 | // add lock |
| 977 | std::lock_guard<std::mutex> lock_guard(pc_lock_); | 931 | std::lock_guard<std::mutex> lock_guard(pc_lock_); |
| 978 | if (init_flag_) { | 932 | if (init_flag_) { |
| 979 | return PLATFORM_SUCCESS; | 933 | return PLATFORM_SUCCESS; |
| 980 | } | 934 | } |
| 981 | - std::string cfg_file_real_path = RealPath(GetSoFilePath() + PLATFORM_RELATIVE_PATH); | 935 | + std::string cfg_file_real_path = fe::GetConfigFilePath<PlatformInfoManager>(); |
| 982 | if (cfg_file_real_path.empty()) { | 936 | if (cfg_file_real_path.empty()) { |
| 983 | PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); | 937 | PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); |
| 984 | return PLATFORM_FAILED; | 938 | return PLATFORM_FAILED; |
| @@ -1199,7 +1153,7 @@ uint32_t PlatformInfoManager::InitRuntimePlatformInfos(const std::string &SoCVer | |||
| 1199 | return PLATFORM_SUCCESS; | 1153 | return PLATFORM_SUCCESS; |
| 1200 | } | 1154 | } |
| 1201 | 1155 | ||
| 1202 | - std::string cfg_file_real_path = RealPath(GetSoFilePath() + PLATFORM_RELATIVE_PATH); | 1156 | + std::string cfg_file_real_path = fe::GetConfigFilePath<PlatformInfoManager>(); |
| 1203 | if (cfg_file_real_path.empty()) { | 1157 | if (cfg_file_real_path.empty()) { |
| 1204 | PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); | 1158 | PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); |
| 1205 | return PLATFORM_FAILED; | 1159 | return PLATFORM_FAILED; |
| @@ -65,4 +65,26 @@ void PlatformInfosUtils::Split(const std::string &str, char pattern, std::vector | |||
| 65 | } | 65 | } |
| 66 | return; | 66 | return; |
| 67 | } | 67 | } |
| 68 | + | ||
| 69 | +std::string RealSoFilePath(const std::string &path) { | ||
| 70 | + if (path.empty()) { | ||
| 71 | + PF_LOGE("Path string is NULL."); | ||
| 72 | + return ""; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + if (path.size() >= PATH_MAX) { | ||
| 76 | + PF_LOGE("File path '%s' is too long!", path.c_str()); | ||
| 77 | + return ""; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + char resoved_path[PATH_MAX] = {0}; | ||
| 81 | + std::string res = ""; | ||
| 82 | + | ||
| 83 | + if (realpath(path.c_str(), resoved_path) != nullptr) { | ||
| 84 | + res = resoved_path; | ||
| 85 | + } else { | ||
| 86 | + PF_LOGE("Path '%s' does not exist.", path.c_str()); | ||
| 87 | + } | ||
| 88 | + return res; | ||
| 89 | +} | ||
| 68 | } // namespace fe | 90 | } // namespace fe |
| @@ -12,10 +12,14 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 16 | + | ||
| 15 | 17 | ||
| 18 | + | ||
| 16 | 19 | ||
| 17 | namespace fe { | 20 | namespace fe { |
| 18 | extern std::mutex plt_mutex; | 21 | extern std::mutex plt_mutex; |
| 22 | +const std::string PLATFORM_RELATIVE_PATH = "data/platform_config"; | ||
| 19 | 23 | ||
| 20 | class PlatformInfosUtils { | 24 | class PlatformInfosUtils { |
| 21 | public: | 25 | public: |
| @@ -32,6 +36,45 @@ class PlatformInfosUtils { | |||
| 32 | PlatformInfosUtils(); | 36 | PlatformInfosUtils(); |
| 33 | ~PlatformInfosUtils(); | 37 | ~PlatformInfosUtils(); |
| 34 | }; | 38 | }; |
| 39 | + | ||
| 40 | +std::string RealSoFilePath(const std::string &path); | ||
| 41 | + | ||
| 42 | +template <typename ManagerType> | ||
| 43 | +std::string GetSoFilePath() { | ||
| 44 | + Dl_info dl_info; | ||
| 45 | + std::string real_file_path = ""; | ||
| 46 | + ManagerType &(*instance_ptr)() = &ManagerType::Instance; | ||
| 47 | + if (dladdr(reinterpret_cast<void *>(instance_ptr), &dl_info) == 0) { | ||
| 48 | + PF_LOGE("Failed to read the so file path."); | ||
| 49 | + return real_file_path; | ||
| 50 | + } else { | ||
| 51 | + std::string so_path = dl_info.dli_fname; | ||
| 52 | + if (so_path.empty()) { | ||
| 53 | + PF_LOGE("The so file path is empty."); | ||
| 54 | + return real_file_path; | ||
| 55 | + } | ||
| 56 | + real_file_path = RealSoFilePath(so_path); | ||
| 57 | + size_t pos = real_file_path.rfind('/'); | ||
| 58 | + real_file_path = real_file_path.substr(0, pos + 1); | ||
| 59 | + } | ||
| 60 | + return real_file_path; | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +template <typename ManagerType> | ||
| 64 | +std::string GetConfigFilePath() { | ||
| 65 | + std::string so_file_path = GetSoFilePath<ManagerType>(); | ||
| 66 | + while (!so_file_path.empty() && so_file_path.back() == '/') { | ||
| 67 | + so_file_path.pop_back(); | ||
| 68 | + } | ||
| 69 | + size_t pos = so_file_path.find_last_of("/\\"); | ||
| 70 | + if (pos == std::string::npos) { | ||
| 71 | + return ""; | ||
| 72 | + } | ||
| 73 | + so_file_path = so_file_path.substr(0, pos + 1); | ||
| 74 | + PF_LOGI("Current so file path is [%s].", so_file_path.c_str()); | ||
| 75 | + | ||
| 76 | + return RealSoFilePath(so_file_path + PLATFORM_RELATIVE_PATH); | ||
| 77 | +} | ||
| 35 | } // namespace fe | 78 | } // namespace fe |
| 36 | 79 | ||
| 37 | 80 | ||
| @@ -10,12 +10,9 @@ | |||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | - | ||
| 14 | 13 | ||
| 15 | 14 | ||
| 16 | - | ||
| 17 | 15 | ||
| 18 | - | ||
| 19 | 16 | ||
| 20 | 17 | ||
| 21 | 18 | ||
| @@ -24,7 +21,6 @@ extern "C" { | |||
| 24 | 21 | ||
| 25 | 22 | ||
| 26 | const std::string FIXPIPE_CONFIG_KEY = "Intrinsic_fix_pipe_"; | 23 | const std::string FIXPIPE_CONFIG_KEY = "Intrinsic_fix_pipe_"; |
| 27 | -const std::string PLATFORM_RELATIVE_PATH = "data/platform_config"; | ||
| 28 | const std::string INI_FILE_SUFFIX = ".ini"; | 24 | const std::string INI_FILE_SUFFIX = ".ini"; |
| 29 | 25 | ||
| 30 | const std::string STR_AI_CORE_INTRINSIC_DTYPE_MAP = "AICoreintrinsicDtypeMap"; | 26 | const std::string STR_AI_CORE_INTRINSIC_DTYPE_MAP = "AICoreintrinsicDtypeMap"; |
| @@ -213,65 +209,8 @@ uint32_t PlatformManagerV2::ParsePlatformInfo(std::map<std::string, std::map<std | |||
| 213 | return PLATFORM_SUCCESS; | 209 | return PLATFORM_SUCCESS; |
| 214 | } | 210 | } |
| 215 | 211 | ||
| 216 | -std::string PlatformManagerV2::RealPath(const std::string &path) { | ||
| 217 | - if (path.empty()) { | ||
| 218 | - PF_LOGE("Path string is NULL."); | ||
| 219 | - return ""; | ||
| 220 | - } | ||
| 221 | - | ||
| 222 | - if (path.size() >= PATH_MAX) { | ||
| 223 | - PF_LOGE("File path '%s' is too long!", path.c_str()); | ||
| 224 | - return ""; | ||
| 225 | - } | ||
| 226 | - | ||
| 227 | - char resoved_path[PATH_MAX] = {0}; | ||
| 228 | - std::string res = ""; | ||
| 229 | - | ||
| 230 | - if (realpath(path.c_str(), resoved_path) != nullptr) { | ||
| 231 | - res = resoved_path; | ||
| 232 | - } else { | ||
| 233 | - PF_LOGE("Path '%s' does not exist.", path.c_str()); | ||
| 234 | - } | ||
| 235 | - return res; | ||
| 236 | -} | ||
| 237 | - | ||
| 238 | -std::string PlatformManagerV2::GetSoFilePath() { | ||
| 239 | - Dl_info dl_info; | ||
| 240 | - std::string real_file_path = ""; | ||
| 241 | - PlatformManagerV2 &(*instance_ptr)() = &PlatformManagerV2::Instance; | ||
| 242 | - if (dladdr(reinterpret_cast<void *>(instance_ptr), &dl_info) == 0) { | ||
| 243 | - PF_LOGE("Failed to read the so file path."); | ||
| 244 | - return real_file_path; | ||
| 245 | - } else { | ||
| 246 | - std::string so_path = dl_info.dli_fname; | ||
| 247 | - if (so_path.empty()) { | ||
| 248 | - PF_LOGE("The so file path is empty."); | ||
| 249 | - return real_file_path; | ||
| 250 | - } | ||
| 251 | - real_file_path = RealPath(so_path); | ||
| 252 | - size_t pos = real_file_path.rfind('/'); | ||
| 253 | - real_file_path = real_file_path.substr(0, pos + 1); | ||
| 254 | - } | ||
| 255 | - return real_file_path; | ||
| 256 | -} | ||
| 257 | - | ||
| 258 | -std::string PlatformManagerV2::GetConfigFilePath() { | ||
| 259 | - std::string so_file_path = GetSoFilePath(); | ||
| 260 | - while (!so_file_path.empty() && so_file_path.back() == '/') { | ||
| 261 | - so_file_path.pop_back(); | ||
| 262 | - } | ||
| 263 | - size_t pos = so_file_path.find_last_of("/\\"); | ||
| 264 | - if (pos == std::string::npos) { | ||
| 265 | - return ""; | ||
| 266 | - } | ||
| 267 | - so_file_path = so_file_path.substr(0, pos + 1); | ||
| 268 | - PF_LOGI("Current so file path is [%s].", so_file_path.c_str()); | ||
| 269 | - | ||
| 270 | - return RealPath(so_file_path + PLATFORM_RELATIVE_PATH); | ||
| 271 | -} | ||
| 272 | - | ||
| 273 | uint32_t PlatformManagerV2::InitPlatformInfos(const std::string &soc_version) { | 212 | uint32_t PlatformManagerV2::InitPlatformInfos(const std::string &soc_version) { |
| 274 | - std::string cfg_file_real_path = GetConfigFilePath(); | 213 | + std::string cfg_file_real_path = fe::GetConfigFilePath<PlatformManagerV2>(); |
| 275 | if (cfg_file_real_path.empty()) { | 214 | if (cfg_file_real_path.empty()) { |
| 276 | PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); | 215 | PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); |
| 277 | return PLATFORM_FAILED; | 216 | return PLATFORM_FAILED; |
| @@ -44,9 +44,6 @@ class PlatformManagerV2 { | |||
| 44 | fe::PlatFormInfos &platform_info_temp); | 44 | fe::PlatFormInfos &platform_info_temp); |
| 45 | uint32_t ParsePlatformInfo(std::map<std::string, std::map<std::string, std::string>> &content_info_map, | 45 | uint32_t ParsePlatformInfo(std::map<std::string, std::map<std::string, std::string>> &content_info_map, |
| 46 | fe::PlatFormInfos &platform_info_temp); | 46 | fe::PlatFormInfos &platform_info_temp); |
| 47 | - std::string RealPath(const std::string &path); | ||
| 48 | - std::string GetSoFilePath(); | ||
| 49 | - std::string GetConfigFilePath(); | ||
| 50 | uint32_t InitPlatformInfos(const std::string &soc_version); | 47 | uint32_t InitPlatformInfos(const std::string &soc_version); |
| 51 | int32_t GetPlatformInfos(const std::string &soc_version, fe::PlatFormInfos &platform_info); | 48 | int32_t GetPlatformInfos(const std::string &soc_version, fe::PlatFormInfos &platform_info); |
| 52 | 49 | ||
| @@ -66,4 +66,17 @@ TEST_F(PlatformManagerV2UTest, platform_instance_Trim) { | |||
| 66 | EXPECT_EQ(strNg, ""); | 66 | EXPECT_EQ(strNg, ""); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | +TEST_F(PlatformManagerV2UTest, platform_instance_RealPath1) { | ||
| 70 | + std::string path = ""; | ||
| 71 | + string res = ""; | ||
| 72 | + res = fe::RealSoFilePath(path); | ||
| 73 | + EXPECT_EQ(res, ""); | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +TEST_F(PlatformManagerV2UTest, platform_instance_RealPath2) { | ||
| 77 | + std::string path = "test1"; | ||
| 78 | + string res = ""; | ||
| 79 | + res = fe::RealSoFilePath(path); | ||
| 80 | + EXPECT_EQ(res, ""); | ||
| 81 | +} | ||
| 69 | } | 82 | } |