LCOV - code coverage report
Current view: top level - aicpu_kernel - load_platform_info.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.3 % 31 28
Test Date: 2026-07-28 10:54:05 Functions: 75.0 % 4 3

            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 "load_platform_info.h"
      12              : #include "utils/aicpu_kernel_log.h"
      13              : #include "utils/aicpu_kernel_status.h"
      14              : #include "type_def.h"
      15              : 
      16              : namespace {
      17              : struct LoadPlatformInfosArgs {
      18              :   uint64_t args{0UL};
      19              :   uint64_t args_size{0UL};
      20              : };
      21              : }
      22              : 
      23              : extern "C" {
      24            1 : __attribute__((visibility("default"))) uint32_t LoadCustPlatform(void *args) {
      25            1 :   KERNEL_LOG_INFO("Begin loading the custom platform");
      26            1 :   auto load_args = PtrToPtr<void, LoadPlatformInfosArgs>(args);
      27            1 :   const uint64_t input_info = load_args->args;
      28            1 :   const uint32_t info_len = static_cast<uint32_t>(load_args->args_size);
      29            1 :   return aicpu::PlatformRebuild::GetInstance().ProcessPlatformInfoMsg(input_info, info_len);
      30              : }
      31              : 
      32            0 : __attribute__((visibility("default"))) int32_t AicpuExtendKernelsLoadPlatformInfo(const uint64_t input_info,
      33              :   const uint32_t info_len) {
      34            0 :   KERNEL_LOG_INFO("Begin loading the custom platform with the extension package kernel.");
      35            0 :   return aicpu::PlatformRebuild::GetInstance().ProcessPlatformInfoMsg(input_info, info_len);
      36              : }
      37              : }
      38              : 
      39              : namespace aicpu {
      40            5 : PlatformRebuild &PlatformRebuild::GetInstance() {
      41              :   static PlatformRebuild instance;
      42            5 :   return instance;
      43              : }
      44              : 
      45            5 : int32_t PlatformRebuild::ProcessPlatformInfoMsg(const uint64_t info_args,
      46              :                                                 const uint32_t info_len) {
      47            5 :   if (info_len != static_cast<uint32_t>(sizeof(PlatformInfoArgs))) {
      48            1 :     KERNEL_LOG_ERROR("The length of args is invalid, input:%u, base:%zu", info_len,
      49              :                      sizeof(PlatformInfoArgs));
      50            1 :     return KERNEL_STATUS_PARAM_INVALID;
      51              :   }
      52            4 :   const PlatformInfoArgs *const platform_args = PtrToPtr<void, PlatformInfoArgs>(ValueToPtr(info_args));
      53            4 :   KERNEL_CHECK_NULLPTR(platform_args, KERNEL_STATUS_PARAM_INVALID, "info args nullptr");
      54            4 :   if ((platform_args->input_data_info == 0UL) || (platform_args->input_data_len == 0UL) ||
      55            3 :       (platform_args->platform_instance == 0UL)) {
      56            1 :     KERNEL_LOG_ERROR(
      57              :         "input args is invalid: input_data_info:0x%x, input_data_len:%llu, platform_instance:0x%x",
      58              :         platform_args->input_data_info, platform_args->input_data_len, platform_args->platform_instance);
      59            1 :     return KERNEL_STATUS_PARAM_INVALID;
      60              :   }
      61              : 
      62            3 :   KERNEL_LOG_INFO("input param: input_data_info:0x%x, input_data_len:%llu, platform_instance:0x%x",
      63              :                   platform_args->input_data_info, platform_args->input_data_len,
      64              :                   platform_args->platform_instance);
      65            3 :   fe::PlatFormInfos *platform_infos = PtrToPtr<void, fe::PlatFormInfos>(ValueToPtr(platform_args->platform_instance));
      66            3 :   KERNEL_CHECK_NULLPTR(platform_infos, KERNEL_STATUS_PARAM_INVALID, "platform instance nullptr");
      67            3 :   char *input_data_info = PtrToPtr<void, char>(ValueToPtr(platform_args->input_data_info));
      68            3 :   KERNEL_CHECK_FALSE(platform_infos->Init(), KERNEL_STATUS_INNER_ERROR, "Fe platformInfo init failed");
      69            3 :   if (!(platform_infos->LoadFromBuffer(input_data_info, platform_args->input_data_len))) {
      70            1 :     KERNEL_LOG_ERROR("Deserialization failed");
      71            1 :     return KERNEL_STATUS_INNER_ERROR;
      72              :   }
      73            2 :   KERNEL_LOG_INFO("The platform info has been loaded successfully.");
      74            2 :   return KERNEL_STATUS_OK;
      75              : }
      76              : }  // namespace aicpu
        

Generated by: LCOV version 2.0-1