LCOV - code coverage report
Current view: top level - src/platform - platform_infos_utils.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.0 % 50 48
Test Date: 2026-07-28 10:52:27 Functions: 100.0 % 7 7

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : #include "platform_infos_utils.h"
      11              : #include "platform_log.h"
      12              : #include "platform_infos_impl.h"
      13              : 
      14              : namespace fe {
      15              : std::mutex plt_info_mutex;
      16              : std::mutex opt_info_mutex;
      17              : 
      18            1 : PlatformInfosUtils::PlatformInfosUtils() {}
      19              : 
      20            1 : PlatformInfosUtils::~PlatformInfosUtils() {}
      21              : 
      22           24 : PlatformInfosUtils& PlatformInfosUtils::GetInstance()
      23              : {
      24           24 :     static PlatformInfosUtils platform_info_utils;
      25           24 :     return platform_info_utils;
      26              : }
      27              : 
      28           23 : void PlatformInfosUtils::Clone(PlatFormInfos& dest_platform_infos, const PlatFormInfos& platform_infos) const
      29              : {
      30           23 :     std::lock_guard<std::mutex> lock_guard(plt_info_mutex);
      31           23 :     PF_LOGD("Using platFormInfos Clone function.");
      32           23 :     if (&dest_platform_infos != &platform_infos) {
      33           23 :         dest_platform_infos.core_num_ = platform_infos.core_num_;
      34           23 :         if (platform_infos.platform_infos_impl_) {
      35           19 :             PF_MAKE_SHARED(
      36              :                 dest_platform_infos.platform_infos_impl_ =
      37              :                     std::make_shared<PlatFormInfosImpl>(*platform_infos.platform_infos_impl_),
      38              :                 return);
      39              :         }
      40              :     }
      41           23 : }
      42              : 
      43          539 : void PlatformInfosUtils::Trim(std::string& str)
      44              : {
      45          539 :     if (str.empty()) {
      46            2 :         return;
      47              :     }
      48          537 :     size_t start_pos = str.find_first_not_of(" \t");
      49          537 :     size_t end_pos = str.find_last_not_of(" \t");
      50          537 :     if (start_pos == std::string::npos || start_pos > end_pos) {
      51            2 :         str.clear();
      52            2 :         return;
      53              :     }
      54          535 :     str = str.substr(start_pos, end_pos - start_pos + 1);
      55              : }
      56              : 
      57          186 : void PlatformInfosUtils::Split(const std::string& str, char pattern, std::vector<std::string>& res_vec)
      58              : {
      59          186 :     if (str.empty()) {
      60            1 :         return;
      61              :     }
      62              : 
      63          185 :     std::string str_and_pattern = str + pattern;
      64          185 :     size_t pos = str_and_pattern.find(pattern);
      65          185 :     size_t size = str_and_pattern.size();
      66          993 :     while (pos != std::string::npos) {
      67          808 :         std::string sub_str = str_and_pattern.substr(0, pos);
      68          808 :         res_vec.push_back(sub_str);
      69          808 :         str_and_pattern = str_and_pattern.substr(pos + 1, size);
      70          808 :         pos = str_and_pattern.find(pattern);
      71          808 :     }
      72          185 :     return;
      73          185 : }
      74              : 
      75          302 : std::string RealSoFilePath(const std::string& path)
      76              : {
      77          302 :     if (path.empty()) {
      78            2 :         PF_LOGE("Path string is NULL.");
      79            4 :         return "";
      80              :     }
      81              : 
      82          300 :     if (path.size() >= PATH_MAX) {
      83            0 :         PF_LOGE("File path '%s' is too long!", path.c_str());
      84            0 :         return "";
      85              :     }
      86              : 
      87          300 :     char resolved_path[PATH_MAX] = {0};
      88          300 :     std::string res = "";
      89              : 
      90          300 :     if (realpath(path.c_str(), resolved_path) != nullptr) {
      91          298 :         res = resolved_path;
      92              :     } else {
      93            2 :         PF_LOGE("Path '%s' does not exist.", path.c_str());
      94              :     }
      95          300 :     return res;
      96          300 : }
      97              : } // namespace fe
        

Generated by: LCOV version 2.0-1