LCOV - code coverage report
Current view: top level - pub_facility/env_manager - env_internal_api.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.0 % 25 22
Test Date: 2026-07-28 10:52:48 Functions: 100.0 % 4 4

            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              : 
      11              : #include "env_internal_api.h"
      12              : 
      13              : namespace tsd {
      14         1336 : void GetEnvFromMmSys(mmEnvId id, const char* envName, std::string& envValue)
      15              : {
      16         1336 :     constexpr size_t envValueMaxLen = 1024UL * 1024UL;
      17              :     try {
      18         1336 :         const char* envPath = nullptr;
      19         1336 :         envPath = (&mmSysGetEnv != nullptr) ? mmSysGetEnv(id) : getenv(envName);
      20         1336 :         if ((envPath == nullptr) || (strnlen(envPath, envValueMaxLen) >= envValueMaxLen)) {
      21         1235 :             TSD_WARN("Get env[%s] failed", envName);
      22         1235 :             return;
      23              :         }
      24          101 :         envValue = envPath;
      25            0 :     } catch (std::exception& e) {
      26            0 :         TSD_ERROR("get env failed:[%s]", e.what());
      27            0 :     }
      28              : }
      29              : 
      30           74 : bool GetFlagFromMmSys(mmEnvId id, const char_t* const envStr, const char_t* const envValue)
      31              : {
      32           74 :     std::string isFlag;
      33           74 :     GetEnvFromMmSys(id, envStr, isFlag);
      34           74 :     if (!isFlag.empty()) {
      35           41 :         if (isFlag == envValue) {
      36           21 :             return true;
      37              :         }
      38              :     }
      39           53 :     return false;
      40           74 : }
      41              : 
      42           17 : bool IsFpgaMmSysEnv()
      43              : {
      44           17 :     const bool isFpga = GetFlagFromMmSys(MM_ENV_DATAMASTER_RUN_MODE, "DATAMASTER_RUN_MODE", "1");
      45           17 :     return isFpga;
      46              : }
      47              : 
      48           41 : bool IsAsanMmSysEnv()
      49              : {
      50           41 :     const bool isAsan = GetFlagFromMmSys(MM_ENV_ASAN_RUN_MODE, "ASAN_RUN_MODE", "1");
      51           41 :     return isAsan;
      52              : }
      53              : } // namespace tsd
        

Generated by: LCOV version 2.0-1