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

Generated by: LCOV version 2.0-1