LCOV - code coverage report
Current view: top level - atrace/utrace/util - trace_driver_api.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.9 % 27 24
Test Date: 2026-08-12 11:04:46 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 "trace_driver_api.h"
      12              : #include "ascend_hal.h"
      13              : #include "adiag_print.h"
      14              : #include "adiag_utils.h"
      15              : #include "trace_load_library.h"
      16              : 
      17              : #define DRIVER_FUNCTION_NUM 2U
      18              : #define DRIVER_LIBRARY_NAME "libascend_hal.so"
      19              : 
      20              : STATIC ArgPtr g_libHandle = NULL;
      21              : STATIC SymbolInfo g_drvFuncInfo[DRIVER_FUNCTION_NUM] = {
      22              :     { "drvGetPlatformInfo", NULL },
      23              :     { "drvGetDevNum", NULL },
      24              : };
      25              : 
      26         1890 : TraStatus TraceDriverInit(void)
      27              : {
      28         1890 :     g_libHandle = TraceOpenLibrary(DRIVER_LIBRARY_NAME);
      29         1890 :     if (g_libHandle == NULL) {
      30              :         // on the general server (pure cpu) scene the driver library is absent, this is expected
      31              :         // and should not report an error, otherwise it pollutes the disk log on a normal startup.
      32            0 :         ADIAG_WAR("dlopen library %s failed, treat as pure cpu env, strerr=%s.",
      33              :             DRIVER_LIBRARY_NAME, strerror(AdiagGetErrorCode()));
      34            0 :         return TRACE_FAILURE;
      35              :     }
      36              : 
      37         1890 :     TraStatus ret = TraceLoadFunc(g_libHandle, g_drvFuncInfo, DRIVER_FUNCTION_NUM);
      38         1890 :     ADIAG_CHK_EXPR_ACTION(ret != TRACE_SUCCESS, return TRACE_FAILURE, "load function symbol failed, ret=%d.", ret);
      39              : 
      40         1890 :     return TRACE_SUCCESS;
      41              : }
      42              : 
      43         1880 : void TraceDriverExit(void)
      44              : {
      45         1880 :     if (g_libHandle == NULL) {
      46            0 :         return;
      47              :     }
      48         1880 :     if (TraceCloseLibrary(g_libHandle) != TRACE_SUCCESS) {
      49           20 :         ADIAG_WAR("can not dlclose library %s, strerr=%s.", DRIVER_LIBRARY_NAME, strerror(AdiagGetErrorCode()));
      50              :     }
      51              : }
      52              : 
      53              : typedef drvError_t (*DrvGetPlatformInfo)(uint32_t *);
      54         1890 : TraStatus TraceDrvGetPlatformInfo(uint32_t *info)
      55              : {
      56         1890 :     DrvGetPlatformInfo func = (DrvGetPlatformInfo)g_drvFuncInfo[0].handle;
      57         1890 :     ADIAG_CHK_EXPR_ACTION(func == NULL, return TRACE_FAILURE, "can not find function\"%s\".", g_drvFuncInfo[0].symbol);
      58              : 
      59         1890 :     drvError_t drvErr = func(info);
      60         1890 :     ADIAG_CHK_EXPR_ACTION(drvErr != DRV_ERROR_NONE, return TRACE_FAILURE,
      61              :         "get platform info failed, drvErr=%d.", (int32_t)drvErr);
      62              : 
      63         1890 :     return TRACE_SUCCESS;
      64              : }
      65              : 
      66              : typedef drvError_t (*DrvGetDevNum)(uint32_t *);
      67         1890 : TraStatus TraceDrvGetDevNum(uint32_t *num)
      68              : {
      69         1890 :     DrvGetDevNum func = (DrvGetDevNum)g_drvFuncInfo[1].handle;
      70         1890 :     ADIAG_CHK_EXPR_ACTION(func == NULL, return TRACE_FAILURE, "can not find function\"%s\".", g_drvFuncInfo[1].symbol);
      71              : 
      72         1890 :     drvError_t drvErr = func(num);
      73              : 
      74         1890 :     if (drvErr == DRV_ERROR_NOT_SUPPORT) {
      75           20 :         return TRACE_FAILURE;
      76              :     }
      77         1870 :     ADIAG_CHK_EXPR_ACTION(drvErr != DRV_ERROR_NONE, return TRACE_FAILURE,
      78              :         "get device num failed, drvErr=%d.", (int32_t)drvErr);
      79              : 
      80         1870 :     return TRACE_SUCCESS;
      81              : }
        

Generated by: LCOV version 2.0-1