DeviceTest.cpp 6.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <cmath>
#include <cstdio>
#include <vector>

#include "nnrt_utils.h"

using namespace testing::ext;
using namespace OHOS::NeuralNetworkRuntime::Test;

class DeviceTest : public testing::Test {};

/**
 * @tc.number : SUB_AI_NNRtt_Func_North_Device_DeviceID_0100
 * @tc.name   : 获取设备ID,*allDevicesID为nullptr
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0100, Function | MediumTest | Level3)
{
    uint32_t count{0};

    OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(nullptr, &count);
    EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceID_0200
 * @tc.name   : 获取设备ID,**allDevicesID非nullptr
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0200, Function | MediumTest | Level3)
{
    const size_t allDeviceIds = 0;
    const size_t *pAllDeviceIds = &allDeviceIds;
    uint32_t count{0};

    OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(&pAllDeviceIds, &count);
    EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceID_0300
 * @tc.name   : 获取设备ID,获取设备ID,deviceCount为nullptr
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0300, Function | MediumTest | Level3)
{
    const size_t *allDeviceIds = nullptr;

    OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(&allDeviceIds, nullptr);
    EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceID_0400
 * @tc.name   : 获取设备ID,设备数量校验
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0400, Function | MediumTest | Level2)
{
    const size_t *allDeviceIds = nullptr;
    uint32_t count{0};

    OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(&allDeviceIds, &count);
    EXPECT_EQ(OH_NN_SUCCESS, ret);

    uint32_t expectCount = 1;
    EXPECT_EQ(expectCount, count);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0100
 * @tc.name   : 获取硬件名称,deviceID不存在
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0100, Function | MediumTest | Level3)
{
    const size_t deviceID{100000};
    const char *name = nullptr;

    OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, &name);
    EXPECT_EQ(OH_NN_FAILED, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0200
 * @tc.name   : 获取硬件名称,*name为nullprt
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0200, Function | MediumTest | Level3)
{
    const size_t *devicesID{nullptr};
    uint32_t devicesCount{0};
    ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
    size_t targetDevice = devicesID[0];

    OH_NN_ReturnCode ret = OH_NNDevice_GetName(targetDevice, nullptr);
    EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0300
 * @tc.name   : 获取硬件名称,**name非nullptr
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0300, Function | MediumTest | Level3)
{
    const size_t *devicesID{nullptr};
    uint32_t devicesCount{0};
    ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
    size_t targetDevice = devicesID[0];

    const char *name = "name";

    OH_NN_ReturnCode ret = OH_NNDevice_GetName(targetDevice, &name);
    EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0400
 * @tc.name   : 获取硬件名称, 结果校验
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0400, Function | MediumTest | Level1)
{
    const size_t *devicesID{nullptr};
    uint32_t devicesCount{0};
    ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
    size_t targetDevice = devicesID[0];

    const char *name = nullptr;
    std::string m_deviceName{"RK3568-CPU_Rockchip"};

    OH_NN_ReturnCode ret = OH_NNDevice_GetName(targetDevice, &name);
    EXPECT_EQ(OH_NN_SUCCESS, ret);
    std::string sName(name);
    EXPECT_EQ(m_deviceName, sName);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceType_0100
 * @tc.name   : 获取硬件类别,deviceType为nullprt
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceType_0100, Function | MediumTest | Level3)
{
    const size_t *devicesID{nullptr};
    uint32_t devicesCount{0};
    ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
    size_t targetDevice = devicesID[0];

    OH_NN_ReturnCode ret = OH_NNDevice_GetType(targetDevice, nullptr);
    EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceType_0200
 * @tc.name   : 获取硬件类别,deviceID不存在
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceType_0200, Function | MediumTest | Level3)
{
    const size_t deviceID{100000};
    OH_NN_DeviceType type{OH_NN_OTHERS};

    OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, &type);
    EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
}

/**
 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceType_0300
 * @tc.name   :获取硬件类别,结果校验
 * @tc.desc   : [C- SOFTWARE -0200]
 */
HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceType_0300, Function | MediumTest | Level1)
{
    const size_t *devicesID{nullptr};
    uint32_t devicesCount{0};
    ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
    size_t targetDevice = devicesID[0];

    OH_NN_DeviceType type{OH_NN_OTHERS};

    OH_NN_ReturnCode ret = OH_NNDevice_GetType(targetDevice, &type);
    EXPECT_EQ(OH_NN_SUCCESS, ret);
}