1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <cmath> 16 #include <cstdio> 17 #include <vector> 18 19 #include "nnrt_utils.h" 20 21 using namespace testing::ext; 22 using namespace OHOS::NeuralNetworkRuntime::Test; 23 24 class DeviceTest : public testing::Test {}; 25 26 /** 27 * @tc.number : SUB_AI_NNRtt_Func_North_Device_DeviceID_0100 28 * @tc.name : 获取设备ID,*allDevicesID为nullptr 29 * @tc.desc : [C- SOFTWARE -0200] 30 */ 31 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0100, Function | MediumTest | Level3) 32 { 33 uint32_t count{0}; 34 35 OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(nullptr, &count); 36 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); 37 } 38 39 /** 40 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceID_0200 41 * @tc.name : 获取设备ID,**allDevicesID非nullptr 42 * @tc.desc : [C- SOFTWARE -0200] 43 */ 44 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0200, Function | MediumTest | Level3) 45 { 46 const size_t allDeviceIds = 0; 47 const size_t *pAllDeviceIds = &allDeviceIds; 48 uint32_t count{0}; 49 50 OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(&pAllDeviceIds, &count); 51 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); 52 } 53 54 /** 55 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceID_0300 56 * @tc.name : 获取设备ID,获取设备ID,deviceCount为nullptr 57 * @tc.desc : [C- SOFTWARE -0200] 58 */ 59 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0300, Function | MediumTest | Level3) 60 { 61 const size_t *allDeviceIds = nullptr; 62 63 OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(&allDeviceIds, nullptr); 64 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); 65 } 66 67 /** 68 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceID_0400 69 * @tc.name : 获取设备ID,设备数量校验 70 * @tc.desc : [C- SOFTWARE -0200] 71 */ 72 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceID_0400, Function | MediumTest | Level2) 73 { 74 const size_t *allDeviceIds = nullptr; 75 uint32_t count{0}; 76 77 OH_NN_ReturnCode ret = OH_NNDevice_GetAllDevicesID(&allDeviceIds, &count); 78 EXPECT_EQ(OH_NN_SUCCESS, ret); 79 80 uint32_t expectCount = 1; 81 EXPECT_EQ(expectCount, count); 82 } 83 84 /** 85 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0100 86 * @tc.name : 获取硬件名称,deviceID不存在 87 * @tc.desc : [C- SOFTWARE -0200] 88 */ 89 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0100, Function | MediumTest | Level3) 90 { 91 const size_t deviceID{100000}; 92 const char *name = nullptr; 93 94 OH_NN_ReturnCode ret = OH_NNDevice_GetName(deviceID, &name); 95 EXPECT_EQ(OH_NN_FAILED, ret); 96 } 97 98 /** 99 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0200 100 * @tc.name : 获取硬件名称,*name为nullprt 101 * @tc.desc : [C- SOFTWARE -0200] 102 */ 103 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0200, Function | MediumTest | Level3) 104 { 105 const size_t *devicesID{nullptr}; 106 uint32_t devicesCount{0}; 107 ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount)); 108 size_t targetDevice = devicesID[0]; 109 110 OH_NN_ReturnCode ret = OH_NNDevice_GetName(targetDevice, nullptr); 111 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); 112 } 113 114 /** 115 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0300 116 * @tc.name : 获取硬件名称,**name非nullptr 117 * @tc.desc : [C- SOFTWARE -0200] 118 */ 119 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0300, Function | MediumTest | Level3) 120 { 121 const size_t *devicesID{nullptr}; 122 uint32_t devicesCount{0}; 123 ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount)); 124 size_t targetDevice = devicesID[0]; 125 126 const char *name = "name"; 127 128 OH_NN_ReturnCode ret = OH_NNDevice_GetName(targetDevice, &name); 129 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); 130 } 131 132 /** 133 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceName_0400 134 * @tc.name : 获取硬件名称, 结果校验 135 * @tc.desc : [C- SOFTWARE -0200] 136 */ 137 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceName_0400, Function | MediumTest | Level1) 138 { 139 const size_t *devicesID{nullptr}; 140 uint32_t devicesCount{0}; 141 ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount)); 142 size_t targetDevice = devicesID[0]; 143 144 const char *name = nullptr; 145 std::string m_deviceName{"Device-CPU_TestVendor"}; 146 147 OH_NN_ReturnCode ret = OH_NNDevice_GetName(targetDevice, &name); 148 EXPECT_EQ(OH_NN_SUCCESS, ret); 149 std::string sName(name); 150 EXPECT_EQ(m_deviceName, sName); 151 } 152 153 /** 154 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceType_0100 155 * @tc.name : 获取硬件类别,deviceType为nullprt 156 * @tc.desc : [C- SOFTWARE -0200] 157 */ 158 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceType_0100, Function | MediumTest | Level3) 159 { 160 const size_t *devicesID{nullptr}; 161 uint32_t devicesCount{0}; 162 ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount)); 163 size_t targetDevice = devicesID[0]; 164 165 OH_NN_ReturnCode ret = OH_NNDevice_GetType(targetDevice, nullptr); 166 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); 167 } 168 169 /** 170 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceType_0200 171 * @tc.name : 获取硬件类别,deviceID不存在 172 * @tc.desc : [C- SOFTWARE -0200] 173 */ 174 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceType_0200, Function | MediumTest | Level3) 175 { 176 const size_t deviceID{100000}; 177 OH_NN_DeviceType type{OH_NN_OTHERS}; 178 179 OH_NN_ReturnCode ret = OH_NNDevice_GetType(deviceID, &type); 180 EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret); 181 } 182 183 /** 184 * @tc.number : SUB_AI_NNRt_Func_North_Device_DeviceType_0300 185 * @tc.name :获取硬件类别,结果校验 186 * @tc.desc : [C- SOFTWARE -0200] 187 */ 188 HWTEST_F(DeviceTest, SUB_AI_NNRt_Func_North_Device_DeviceType_0300, Function | MediumTest | Level1) 189 { 190 const size_t *devicesID{nullptr}; 191 uint32_t devicesCount{0}; 192 ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount)); 193 size_t targetDevice = devicesID[0]; 194 195 OH_NN_DeviceType type{OH_NN_OTHERS}; 196 197 OH_NN_ReturnCode ret = OH_NNDevice_GetType(targetDevice, &type); 198 EXPECT_EQ(OH_NN_SUCCESS, ret); 199 }