LCOV - code coverage report
Current view: top level - aicpu_kernel/utils - aicpu_kernel_log.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-08-12 11:05:02 Functions: 100.0 % 1 1

            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              : #ifndef AICPU_KERNEL_UTILS_AICPU_KERNEL_LOG_H
      12              : #define AICPU_KERNEL_UTILS_AICPU_KERNEL_LOG_H
      13              : #include <sys/syscall.h>
      14              : #include <cstdint>
      15              : #include <unistd.h>
      16              : 
      17              : #include "log_weak.h"
      18              : 
      19              : namespace aicpu {
      20            9 : inline int64_t GetTid()
      21              : {
      22            9 :     thread_local static int64_t tid = syscall(__NR_gettid);
      23            9 :     return tid;
      24              : }
      25              : } // namespace aicpu
      26              : 
      27              : #ifdef RUN_TEST
      28              : const char KERNEL_MODULE[] = "AICPU";
      29              : #define KERNEL_LOG_DEBUG(fmt, ...) ((void)0)
      30              : #define KERNEL_LOG_INFO(fmt, ...) ((void)0)
      31              : #define KERNEL_LOG_WARN(fmt, ...)                                                                                      \
      32              :     printf(                                                                                                            \
      33              :         "[WARN] [%s][%s][%s:%d][tid:%ld]:" fmt "\n", KERNEL_MODULE, __FILE__, __FUNCTION__, __LINE__, aicpu::GetTid(), \
      34              :         ##__VA_ARGS__)
      35              : #define KERNEL_LOG_ERROR(fmt, ...)                                                                     \
      36              :     printf(                                                                                            \
      37              :         "[ERROR] [%s][%s][%s:%d][tid:%ld]:" fmt "\n", KERNEL_MODULE, __FILE__, __FUNCTION__, __LINE__, \
      38              :         aicpu::GetTid(), ##__VA_ARGS__)
      39              : #define KERNEL_LOG_EVENT(fmt, ...)                                                                     \
      40              :     printf(                                                                                            \
      41              :         "[EVENT] [%s][%s][%s:%d][tid:%ld]:" fmt "\n", KERNEL_MODULE, __FILE__, __FUNCTION__, __LINE__, \
      42              :         aicpu::GetTid(), ##__VA_ARGS__)
      43              : #else
      44              : #define KERNEL_LOG_DEBUG(fmt, ...)                                                                                \
      45              :     do {                                                                                                          \
      46              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                            \
      47              :             dlog_debug(                                                                                           \
      48              :                 AICPU, "[%s:%d][%s][tid:%ld]" fmt, __FILE__, __LINE__, __func__, aicpu::GetTid(), ##__VA_ARGS__); \
      49              :         }                                                                                                         \
      50              :     } while (0)
      51              : 
      52              : #define KERNEL_LOG_INFO(fmt, ...)                                                                                 \
      53              :     do {                                                                                                          \
      54              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                            \
      55              :             dlog_info(                                                                                            \
      56              :                 AICPU, "[%s:%d][%s][tid:%ld]" fmt, __FILE__, __LINE__, __func__, aicpu::GetTid(), ##__VA_ARGS__); \
      57              :         }                                                                                                         \
      58              :     } while (0)
      59              : 
      60              : #define KERNEL_LOG_WARN(fmt, ...)                                                                                 \
      61              :     do {                                                                                                          \
      62              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                            \
      63              :             dlog_warn(                                                                                            \
      64              :                 AICPU, "[%s:%d][%s][tid:%ld]" fmt, __FILE__, __LINE__, __func__, aicpu::GetTid(), ##__VA_ARGS__); \
      65              :         }                                                                                                         \
      66              :     } while (0)
      67              : 
      68              : #define KERNEL_LOG_ERROR(fmt, ...)                                                                                \
      69              :     do {                                                                                                          \
      70              :         if (&DlogRecord != nullptr) {                                                                             \
      71              :             dlog_error(                                                                                           \
      72              :                 AICPU, "[%s:%d][%s][tid:%ld]" fmt, __FILE__, __LINE__, __func__, aicpu::GetTid(), ##__VA_ARGS__); \
      73              :         }                                                                                                         \
      74              :     } while (0)
      75              : 
      76              : #define KERNEL_LOG_EVENT(fmt, ...)                                                                         \
      77              :     do {                                                                                                   \
      78              :         if ((&CheckLogLevel != nullptr) && (&DlogRecord != nullptr)) {                                     \
      79              :             dlog_info(                                                                                     \
      80              :                 static_cast<int32_t>(static_cast<uint32_t>(AICPU) | static_cast<uint32_t>(RUN_LOG_MASK)),  \
      81              :                 "[%s:%d][%s][tid:%ld]" fmt, __FILE__, __LINE__, __func__, aicpu::GetTid(), ##__VA_ARGS__); \
      82              :         }                                                                                                  \
      83              :     } while (0)
      84              : #endif
      85              : 
      86              : #define KERNEL_CHECK_NULLPTR_VOID(value, logText...) \
      87              :     if (value == nullptr) {                          \
      88              :         KERNEL_LOG_ERROR(logText);                   \
      89              :         return;                                      \
      90              :     }
      91              : 
      92              : #define KERNEL_CHECK_FALSE(condition, errorCode, logText...) \
      93              :     if (!(condition)) {                                      \
      94              :         KERNEL_LOG_ERROR(logText);                           \
      95              :         return errorCode;                                    \
      96              :     }
      97              : 
      98              : #define KERNEL_CHECK_NULLPTR(value, errorCode, logText...) \
      99              :     if (value == nullptr) {                                \
     100              :         KERNEL_LOG_ERROR(logText);                         \
     101              :         return errorCode;                                  \
     102              :     }
     103              : 
     104              : #define KERNEL_CHECK_ASSIGN_64S_MULTI(A, B, result, errorCode)                    \
     105              :     if ((A) != 0 && (B) != 0 && ((INT64_MAX) / (A)) <= (B)) {                     \
     106              :         KERNEL_LOG_ERROR("Integer reversed multiA: %ld * multiB: %ld", (A), (B)); \
     107              :         return errorCode;                                                         \
     108              :     }                                                                             \
     109              :     (result) = ((A) * (B));
     110              : 
     111              : #define KERNEL_CHECK_FALSE_RUN_INFO(condition, errorCode, logText...) \
     112              :     if (!(condition)) {                                               \
     113              :         KERNEL_LOG_EVENT(logText);                                    \
     114              :         return errorCode;                                             \
     115              :     }
     116              : 
     117              : #define KERNEL_CHECK_FALSE_VOID(condition, logText...) \
     118              :     if (!(condition)) {                                \
     119              :         KERNEL_LOG_ERROR(logText);                     \
     120              :         return;                                        \
     121              :     }
     122              : 
     123              : #define KERNEL_HANDLE_ERROR(expression, logText...) \
     124              :     {                                               \
     125              :         uint32_t ret = expression;                  \
     126              :         if (ret != 0U) {                            \
     127              :             KERNEL_LOG_ERROR(logText);              \
     128              :             return ret;                             \
     129              :         }                                           \
     130              :     }
     131              : 
     132              : #define KERNEL_CHECK_ERROR(expression) \
     133              :     do {                               \
     134              :         uint32_t ret = expression;     \
     135              :         if (ret != 0U) {               \
     136              :             return ret;                \
     137              :         }                              \
     138              :     } while (0)
     139              : 
     140              : #define KERNEL_CHECK_FALSE_EXEC(condition, execExpr...) \
     141              :     if (!(condition)) {                                 \
     142              :         execExpr;                                       \
     143              :     }
     144              : 
     145              : #define KERNEL_CHECK_RET(condition, errorCode) \
     146              :     do {                                       \
     147              :         if (condition) {                       \
     148              :             return errorCode;                  \
     149              :         }                                      \
     150              :     } while (0)
     151              : 
     152              : #endif // AICPU_KERNEL_UTILS_AICPU_KERNEL_LOG_H
        

Generated by: LCOV version 2.0-1