LCOV - code coverage report
Current view: top level - acl/aclrt_c/common - acl_rt.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 51 51
Test Date: 2026-07-28 10:53:01 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 <string.h>
      11              : #include "log_inner.h"
      12              : #include "runtime/rt.h"
      13              : #include "ge_executor_rt.h"
      14              : #include "mmpa_api.h"
      15              : #include "ref_obj.h"
      16              : #include "acl/acl.h"
      17              : 
      18              : #ifdef __cplusplus
      19              : extern "C" {
      20              : #endif
      21              : 
      22              : static RefObj gInitRefCount;
      23              : 
      24           13 : static inline bool PathIsLegal(const char* cfg)
      25              : {
      26           13 :     mmFileHandle* fd = mmOpenFile(cfg, FILE_READ);
      27           13 :     if (fd == NULL) {
      28           10 :         return false;
      29              :     }
      30            3 :     (void)mmSeekFile(fd, 0, MM_SEEK_FILE_END);
      31            3 :     bool isLegal = mmTellFile(fd) == 0 ? false : true;
      32            3 :     mmCloseFile(fd);
      33            3 :     return isLegal;
      34              : }
      35              : 
      36           15 : static void* InitHookFunc(RefObj* obj, const void* userData)
      37              : {
      38           15 :     const rtError_t rtErr = rtInit();
      39           15 :     if (rtErr != RT_ERROR_NONE) {
      40            1 :         ACL_LOG_INNER_ERROR("rt init fail, ret = %d", rtErr);
      41            1 :         return NULL;
      42              :     }
      43           14 :     Status ret = GeInitialize();
      44           14 :     if (ret != (Status)SUCCESS) {
      45            1 :         ACL_LOG_INNER_ERROR("ge init fail, ret = %d", ret);
      46            1 :         (void)rtDeinit();
      47            1 :         return NULL;
      48              :     }
      49           13 :     const char* configPath = (const char*)userData;
      50           13 :     if (PathIsLegal(configPath)) {
      51            3 :         ret = GeDbgInit(configPath);
      52            3 :         if (ret != (Status)SUCCESS) {
      53            1 :             (void)GeFinalize();
      54            1 :             (void)rtDeinit();
      55            1 :             return NULL;
      56              :         }
      57              :     }
      58           12 :     return obj;
      59              : }
      60              : 
      61           16 : aclError aclInit(const char* configPath)
      62              : {
      63           16 :     if (GetObjRefWithUserData(&gInitRefCount, configPath, InitHookFunc) == NULL) {
      64            3 :         ACL_LOG_ERROR("Add refCount err");
      65            3 :         return ACL_ERROR_INTERNAL_ERROR;
      66              :     }
      67           13 :     ACL_LOG_INFO("Increased refCount: %lu", (uint64_t)gInitRefCount.refCount);
      68           13 :     return ACL_SUCCESS;
      69              : }
      70              : 
      71           12 : static void DeinitHookFunc(RefObj* obj)
      72              : {
      73              :     (void)obj;
      74           12 :     (void)GeDbgDeInit();
      75           12 :     (void)GeFinalize();
      76           12 :     (void)rtDeinit();
      77           12 : }
      78           13 : aclError aclFinalize()
      79              : {
      80           13 :     ReleaseObjRef(&gInitRefCount, DeinitHookFunc);
      81           13 :     ACL_LOG_INFO("Decreased refCount: %lu", (uint64_t)gInitRefCount.refCount);
      82           13 :     return ACL_SUCCESS;
      83              : }
      84              : 
      85            2 : aclError aclrtGetVersion(int32_t* majorVersion, int32_t* minorVersion, int32_t* patchVersion)
      86              : {
      87            2 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(majorVersion);
      88            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(minorVersion);
      89            1 :     ACL_REQUIRES_NOT_NULL_WITH_INPUT_REPORT(patchVersion);
      90              :     // Acl version is (*majorVersion).(*minorVersion).(*patchVersion)
      91            1 :     *majorVersion = ACL_MAJOR_VERSION;
      92            1 :     *minorVersion = ACL_MINOR_VERSION;
      93            1 :     *patchVersion = ACL_PATCH_VERSION;
      94            1 :     ACL_LOG_INFO("acl version is %d.%d.%d", *majorVersion, *minorVersion, *patchVersion);
      95              : 
      96            1 :     return ACL_SUCCESS;
      97              : }
      98              : 
      99            2 : const char* aclGetRecentErrMsg() { return GetErrorMessage(); }
     100              : 
     101              : #ifdef __cplusplus
     102              : }
     103              : #endif
        

Generated by: LCOV version 2.0-1