1 /* 2 * Copyright (c) 2024 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 16 #include <vector> 17 #include <string> 18 #include <iostream> 19 #include "nncore_utils.h" 20 21 using namespace testing::ext; 22 using namespace OHOS::NeuralNetworkRuntime::Test; 23 class DetectionPostProcessTest : public testing::Test {}; 24 25 struct DetectionPostProcessModel1 { 26 const std::vector<int32_t> bbox_shape = {1, 16}; 27 const std::vector<int32_t> scores_shape = {1, 4}; 28 const std::vector<int32_t> anchors_shape = {1, 2, 8}; 29 const std::vector<int32_t> output_shape = {2, 8}; 30 31 int64_t inputSizeValue[1] = {45}; 32 std::vector<float> scaleValue = {10, 10, 5, 5}; 33 float nmsIoUThresholdValue[1] = {0.5}; 34 float nmsScoreThresholdValue[1] = {0.4}; 35 int64_t maxDetectionsValue[1] = {5}; 36 int64_t detectionsPerClassValue[1] = {2}; 37 int64_t maxClassesPerDetectionValue[1] = {1}; 38 int64_t numClassesValue[1] = {5}; 39 bool useRegularNmsValue[1] = {false}; 40 bool outQuantizedValue[1] = {false}; 41 42 float bboxValue[1][16] = {1}; 43 float scoresValue[1][4] = {1}; 44 float anchorsValue[1][2][8] = {1}; 45 46 float bboxesValue[1][16] = {0}; 47 float classesValue[1][4] = {0}; 48 float confidencesValue[1][16] = {0}; 49 float numDetectionsValue[1][16] = {0}; 50 51 OHNNOperandTest bbox = {OH_NN_FLOAT32, OH_NN_TENSOR, bbox_shape, bboxValue, 16*sizeof(float)}; 52 OHNNOperandTest scores = {OH_NN_FLOAT32, OH_NN_TENSOR, scores_shape, scoresValue, 4*sizeof(float)}; 53 OHNNOperandTest anchors = {OH_NN_FLOAT32, OH_NN_TENSOR, anchors_shape, anchorsValue, 16*sizeof(float)}; 54 55 OHNNOperandTest bboxes = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, bboxesValue, 16*sizeof(float)}; 56 OHNNOperandTest classes = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, classesValue, 16*sizeof(float)}; 57 OHNNOperandTest confidences = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, confidencesValue, 16*sizeof(float)}; 58 OHNNOperandTest numDetections = {OH_NN_FLOAT32, OH_NN_TENSOR, output_shape, numDetectionsValue, 16*sizeof(float)}; 59 60 OHNNOperandTest inputSize = {OH_NN_INT64, OH_NN_DETECTION_POST_PROCESS_INPUT_SIZE, {1}, 61 inputSizeValue, sizeof(int64_t)}; 62 OHNNOperandTest scale = {OH_NN_FLOAT32, OH_NN_DETECTION_POST_PROCESS_SCALE, {4}, &scaleValue, 4*sizeof(float)}; 63 OHNNOperandTest nmsIoUThreshold = {OH_NN_FLOAT32, OH_NN_DETECTION_POST_PROCESS_NMS_IOU_THRESHOLD, {1}, 64 nmsIoUThresholdValue, sizeof(float)}; 65 OHNNOperandTest nmsScoreThreshold = {OH_NN_FLOAT32, OH_NN_DETECTION_POST_PROCESS_NMS_SCORE_THRESHOLD, {1}, 66 nmsScoreThresholdValue, sizeof(float)}; 67 OHNNOperandTest maxDetections = {OH_NN_INT64, OH_NN_DETECTION_POST_PROCESS_MAX_DETECTIONS, {1}, 68 maxDetectionsValue, sizeof(int64_t)}; 69 OHNNOperandTest detectionsPerClass = {OH_NN_INT64, OH_NN_DETECTION_POST_PROCESS_DETECTIONS_PER_CLASS, {1}, 70 detectionsPerClassValue, sizeof(int64_t)}; 71 OHNNOperandTest maxClassesPerDetection = {OH_NN_INT64, OH_NN_DETECTION_POST_PROCESS_MAX_CLASSES_PER_DETECTION, {1}, 72 maxClassesPerDetectionValue, sizeof(int64_t)}; 73 OHNNOperandTest numClasses = {OH_NN_INT64, OH_NN_DETECTION_POST_PROCESS_NUM_CLASSES, {1}, 74 numClassesValue, sizeof(int64_t)}; 75 OHNNOperandTest useRegularNms = {OH_NN_BOOL, OH_NN_DETECTION_POST_PROCESS_USE_REGULAR_NMS, {1}, 76 useRegularNmsValue, sizeof(bool)}; 77 OHNNOperandTest outQuantized = {OH_NN_BOOL, OH_NN_DETECTION_POST_PROCESS_OUT_QUANTIZED, {1}, 78 outQuantizedValue, sizeof(bool)}; 79 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_DETECTION_POST_PROCESS, 80 .operands = {bbox, scores, anchors, bboxes, classes, confidences, numDetections, 81 inputSize, scale, nmsIoUThreshold, nmsScoreThreshold, maxDetections, 82 detectionsPerClass, maxClassesPerDetection, numClasses, useRegularNms, 83 outQuantized}, 84 .paramIndices = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, 85 .inputIndices = {0, 1, 2}, 86 .outputIndices = {3, 4, 5, 6}}; 87 }; 88 89 /** 90 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_01 91 * @tc.desc: DetectionPostProcessModel1模型build测试 92 * @tc.type: FUNC 93 */ 94 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_01, 95 Function | MediumTest | Level1) 96 { 97 OH_NNModel *model = OH_NNModel_Construct(); 98 EXPECT_NE(nullptr, model); 99 100 DetectionPostProcessModel1 dppModel; 101 OHNNGraphArgs graphArgs = dppModel.graphArgs; 102 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 103 104 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 105 EXPECT_NE(nullptr, compilation); 106 107 OHNNCompileParam compileParam{ 108 .performanceMode = OH_NN_PERFORMANCE_HIGH, 109 .priority = OH_NN_PRIORITY_HIGH, 110 }; 111 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 112 113 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 114 EXPECT_NE(nullptr, executor); 115 116 Free(model, compilation, executor); 117 } 118 119 /** 120 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_02 121 * @tc.desc: DetectionPostProcessModel1模型输入Tensor+1进行build测试 122 * @tc.type: FUNC 123 */ 124 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_02, 125 Function | MediumTest | Level2) 126 { 127 OH_NNModel *model = OH_NNModel_Construct(); 128 EXPECT_NE(nullptr, model); 129 130 DetectionPostProcessModel1 dppModel; 131 OHNNGraphArgs graphArgs = dppModel.graphArgs; 132 graphArgs.operands = {dppModel.bbox, dppModel.bbox, dppModel.scores, dppModel.anchors, dppModel.bboxes, 133 dppModel.classes, dppModel.confidences, dppModel.numDetections, dppModel.inputSize, 134 dppModel.scale, dppModel.nmsIoUThreshold, dppModel.nmsScoreThreshold, dppModel.maxDetections, 135 dppModel.detectionsPerClass, dppModel.maxClassesPerDetection, dppModel.numClasses, 136 dppModel.useRegularNms, dppModel.outQuantized}; 137 graphArgs.inputIndices = {0, 1, 2, 3}; 138 graphArgs.outputIndices = {4, 5, 6, 7}; 139 graphArgs.paramIndices = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; 140 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 141 142 Free(model, nullptr, nullptr); 143 } 144 145 /** 146 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_03 147 * @tc.desc: DetectionPostProcessModel1模型输出Tensor+1进行build测试 148 * @tc.type: FUNC 149 */ 150 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_03, 151 Function | MediumTest | Level2) 152 { 153 OH_NNModel *model = OH_NNModel_Construct(); 154 EXPECT_NE(nullptr, model); 155 156 DetectionPostProcessModel1 dppModel; 157 OHNNGraphArgs graphArgs = dppModel.graphArgs; 158 graphArgs.operands = {dppModel.bbox, dppModel.scores, dppModel.anchors, dppModel.bboxes, dppModel.bboxes, 159 dppModel.classes, dppModel.confidences, dppModel.numDetections, dppModel.inputSize, 160 dppModel.scale, dppModel.nmsIoUThreshold, dppModel.nmsScoreThreshold, dppModel.maxDetections, 161 dppModel.detectionsPerClass, dppModel.maxClassesPerDetection, dppModel.numClasses, 162 dppModel.useRegularNms, dppModel.outQuantized}; 163 graphArgs.inputIndices = {0, 1, 2}; 164 graphArgs.outputIndices = {3, 4, 5, 6, 7}; 165 graphArgs.paramIndices = {8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; 166 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 167 168 Free(model, nullptr, nullptr); 169 } 170 171 /** 172 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_04 173 * @tc.desc: DetectionPostProcessModel1模型传入非法参数进行build测试 174 * @tc.type: FUNC 175 */ 176 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Build_04, 177 Function | MediumTest | Level2) 178 { 179 OH_NNModel *model = OH_NNModel_Construct(); 180 EXPECT_NE(nullptr, model); 181 182 DetectionPostProcessModel1 dppModel; 183 OHNNGraphArgs graphArgs = dppModel.graphArgs; 184 185 int8_t activationValue = OH_NN_FUSED_NONE; 186 OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)}; 187 graphArgs.operands = {dppModel.bbox, dppModel.scores, dppModel.anchors, dppModel.bboxes, dppModel.classes, 188 dppModel.confidences, dppModel.numDetections, dppModel.inputSize, dppModel.scale, 189 dppModel.nmsIoUThreshold, dppModel.nmsScoreThreshold, dppModel.maxDetections, 190 dppModel.detectionsPerClass, dppModel.maxClassesPerDetection, dppModel.numClasses, 191 dppModel.useRegularNms, dppModel.outQuantized, activation}; 192 graphArgs.paramIndices = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; 193 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 194 195 Free(model, nullptr, nullptr); 196 } 197 198 /** 199 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_Finish_01 200 * @tc.desc: 模型构图,未添加操作数 201 * @tc.type: FUNC 202 */ 203 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_Finish_01, 204 Function | MediumTest | Level2) 205 { 206 OH_NNModel *model = OH_NNModel_Construct(); 207 EXPECT_NE(nullptr, model); 208 209 OHNNGraphArgs graphArgs; 210 EXPECT_EQ(OH_NN_INVALID_PARAMETER, SingleModelBuildEndStep(model, graphArgs)); 211 212 Free(model, nullptr, nullptr); 213 } 214 215 /** 216 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_Finish_02 217 * @tc.desc: 模型构图,未设置输入输出 218 * @tc.type: FUNC 219 */ 220 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_Finish_02, 221 Function | MediumTest | Level2) 222 { 223 OH_NNModel *model = OH_NNModel_Construct(); 224 EXPECT_NE(nullptr, model); 225 226 DetectionPostProcessModel1 dppModel; 227 OHNNGraphArgs graphArgs = dppModel.graphArgs; 228 graphArgs.specifyIO = false; 229 EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs)); 230 231 Free(model, nullptr, nullptr); 232 } 233 234 /** 235 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_Finish_03 236 * @tc.desc: 模型构图,设置输入输出,构图成功 237 * @tc.type: FUNC 238 */ 239 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_Finish_03, 240 Function | MediumTest | Level1) 241 { 242 OH_NNModel *model = OH_NNModel_Construct(); 243 EXPECT_NE(nullptr, model); 244 245 DetectionPostProcessModel1 dppModel; 246 OHNNGraphArgs graphArgs = dppModel.graphArgs; 247 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 248 249 Free(model, nullptr, nullptr); 250 } 251 252 /** 253 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SetOperandValue_01 254 * @tc.desc: 设置操作数值,操作数不存在 255 * @tc.type: FUNC 256 */ 257 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SetOperandValue_01, 258 Function | MediumTest | Level2) 259 { 260 OH_NNModel *model = OH_NNModel_Construct(); 261 EXPECT_NE(nullptr, model); 262 263 DetectionPostProcessModel1 dppModel; 264 OHNNGraphArgs graphArgs = dppModel.graphArgs; 265 266 NN_TensorDesc* tensorDesc = nullptr; 267 std::vector<NN_TensorDesc*> tensorDescVec; 268 269 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 270 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 271 tensorDesc = createTensorDesc(operandTem.shape.data(), 272 (uint32_t) operandTem.shape.size(), 273 operandTem.dataType, operandTem.format); 274 tensorDescVec.emplace_back(tensorDesc); 275 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 276 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 277 278 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 279 graphArgs.paramIndices.end()) { 280 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData( 281 model, 1000+i, operandTem.data, operandTem.length)); 282 } 283 } 284 285 FreeTensorDescVec(tensorDescVec); 286 Free(model, nullptr, nullptr); 287 } 288 289 /** 290 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SetOperandValue_02 291 * @tc.desc: 设置操作数值,buufer为nullptr 292 * @tc.type: FUNC 293 */ 294 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SetOperandValue_02, 295 Function | MediumTest | Level2) 296 { 297 OH_NNModel *model = OH_NNModel_Construct(); 298 EXPECT_NE(nullptr, model); 299 300 DetectionPostProcessModel1 dppModel; 301 OHNNGraphArgs graphArgs = dppModel.graphArgs; 302 303 NN_TensorDesc* tensorDesc = nullptr; 304 std::vector<NN_TensorDesc*> tensorDescVec; 305 306 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 307 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 308 tensorDesc = createTensorDesc(operandTem.shape.data(), 309 (uint32_t) operandTem.shape.size(), 310 operandTem.dataType, operandTem.format); 311 tensorDescVec.emplace_back(tensorDesc); 312 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 313 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 314 315 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 316 graphArgs.paramIndices.end()) { 317 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, i, nullptr, operandTem.length)); 318 } 319 } 320 321 FreeTensorDescVec(tensorDescVec); 322 Free(model, nullptr, nullptr); 323 } 324 325 /** 326 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SetOperandValue_03 327 * @tc.desc: 设置操作数值,length为0 328 * @tc.type: FUNC 329 */ 330 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SetOperandValue_03, 331 Function | MediumTest | Level2) 332 { 333 OH_NNModel *model = OH_NNModel_Construct(); 334 EXPECT_NE(nullptr, model); 335 336 DetectionPostProcessModel1 dppModel; 337 OHNNGraphArgs graphArgs = dppModel.graphArgs; 338 339 NN_TensorDesc* tensorDesc = nullptr; 340 std::vector<NN_TensorDesc*> tensorDescVec; 341 342 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 343 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 344 tensorDesc = createTensorDesc(operandTem.shape.data(), 345 (uint32_t) operandTem.shape.size(), 346 operandTem.dataType, operandTem.format); 347 tensorDescVec.emplace_back(tensorDesc); 348 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 349 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 350 351 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 352 graphArgs.paramIndices.end()) { 353 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000+i, operandTem.data, 0)); 354 } 355 } 356 357 FreeTensorDescVec(tensorDescVec); 358 Free(model, nullptr, nullptr); 359 } 360 361 /** 362 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_01 363 * @tc.desc: 设置输入输出,inputIndices为nullptr 364 * @tc.type: FUNC 365 */ 366 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_01, 367 Function | MediumTest | Level2) 368 { 369 OH_NNModel *model = OH_NNModel_Construct(); 370 EXPECT_NE(nullptr, model); 371 372 DetectionPostProcessModel1 dppModel; 373 OHNNGraphArgs graphArgs = dppModel.graphArgs; 374 graphArgs.specifyIO = false; 375 graphArgs.build = false; 376 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 377 378 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 379 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 380 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices)); 381 382 Free(model, nullptr, nullptr); 383 } 384 385 /** 386 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_02 387 * @tc.desc: 设置输入输出,inputindices中data为nullptr 388 * @tc.type: FUNC 389 */ 390 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_02, 391 Function | MediumTest | Level2) 392 { 393 OH_NNModel *model = OH_NNModel_Construct(); 394 EXPECT_NE(nullptr, model); 395 396 DetectionPostProcessModel1 dppModel; 397 OHNNGraphArgs graphArgs = dppModel.graphArgs; 398 graphArgs.specifyIO = false; 399 graphArgs.build = false; 400 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 401 402 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 403 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 404 inputIndices.data = nullptr; 405 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 406 407 Free(model, nullptr, nullptr); 408 } 409 410 /** 411 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_03 412 * @tc.desc: 设置输入输出,inputindices中data对应序号不存在 413 * @tc.type: FUNC 414 */ 415 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_03, 416 Function | MediumTest | Level2) 417 { 418 OH_NNModel *model = OH_NNModel_Construct(); 419 EXPECT_NE(nullptr, model); 420 421 DetectionPostProcessModel1 dppModel; 422 OHNNGraphArgs graphArgs = dppModel.graphArgs; 423 graphArgs.specifyIO = false; 424 graphArgs.build = false; 425 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 426 427 graphArgs.inputIndices = {100000}; 428 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 429 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 430 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 431 432 Free(model, nullptr, nullptr); 433 } 434 435 /** 436 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_04 437 * @tc.desc: 设置输入输出,inputindices中size为0 438 * @tc.type: FUNC 439 */ 440 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_04, 441 Function | MediumTest | Level2) 442 { 443 OH_NNModel *model = OH_NNModel_Construct(); 444 EXPECT_NE(nullptr, model); 445 446 DetectionPostProcessModel1 dppModel; 447 OHNNGraphArgs graphArgs = dppModel.graphArgs; 448 graphArgs.specifyIO = false; 449 graphArgs.build = false; 450 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 451 452 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 453 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 454 inputIndices.size = 0; 455 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 456 457 Free(model, nullptr, nullptr); 458 } 459 460 /** 461 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_05 462 * @tc.desc: 设置输入输出,outputindices为nullptr 463 * @tc.type: FUNC 464 */ 465 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_05, 466 Function | MediumTest | Level2) 467 { 468 OH_NNModel *model = OH_NNModel_Construct(); 469 EXPECT_NE(nullptr, model); 470 471 DetectionPostProcessModel1 dppModel; 472 OHNNGraphArgs graphArgs = dppModel.graphArgs; 473 graphArgs.specifyIO = false; 474 graphArgs.build = false; 475 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 476 477 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 478 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 479 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr)); 480 481 Free(model, nullptr, nullptr); 482 } 483 484 /** 485 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_06 486 * @tc.desc: 设置输入输出,outputindices中data为nullptr 487 * @tc.type: FUNC 488 */ 489 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_06, 490 Function | MediumTest | Level2) 491 { 492 OH_NNModel *model = OH_NNModel_Construct(); 493 EXPECT_NE(nullptr, model); 494 495 DetectionPostProcessModel1 dppModel; 496 OHNNGraphArgs graphArgs = dppModel.graphArgs; 497 graphArgs.specifyIO = false; 498 graphArgs.build = false; 499 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 500 501 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 502 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 503 outputIndices.data = nullptr; 504 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 505 506 Free(model, nullptr, nullptr); 507 } 508 509 /** 510 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_07 511 * @tc.desc: 设置输入输出,outputindices中data对应序号不存在 512 * @tc.type: FUNC 513 */ 514 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_07, 515 Function | MediumTest | Level2) 516 { 517 OH_NNModel *model = OH_NNModel_Construct(); 518 EXPECT_NE(nullptr, model); 519 520 DetectionPostProcessModel1 dppModel; 521 OHNNGraphArgs graphArgs = dppModel.graphArgs; 522 graphArgs.specifyIO = false; 523 graphArgs.build = false; 524 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 525 526 graphArgs.outputIndices = {100000}; 527 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 528 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 529 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 530 531 Free(model, nullptr, nullptr); 532 } 533 534 /** 535 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_08 536 * @tc.desc: 设置输入输出,outputindices中size为0 537 * @tc.type: FUNC 538 */ 539 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_SpecifyInputsAndOutputs_08, 540 Function | MediumTest | Level2) 541 { 542 OH_NNModel *model = OH_NNModel_Construct(); 543 EXPECT_NE(nullptr, model); 544 545 DetectionPostProcessModel1 dppModel; 546 OHNNGraphArgs graphArgs = dppModel.graphArgs; 547 graphArgs.specifyIO = false; 548 graphArgs.build = false; 549 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 550 551 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 552 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 553 outputIndices.size = 0; 554 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 555 556 Free(model, nullptr, nullptr); 557 } 558 559 /** 560 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_01 561 * @tc.desc: 添加算子,paramindices为nullptr 562 * @tc.type: FUNC 563 */ 564 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_01, 565 Function | MediumTest | Level2) 566 { 567 OH_NNModel *model = OH_NNModel_Construct(); 568 EXPECT_NE(nullptr, model); 569 570 DetectionPostProcessModel1 dppModel; 571 OHNNGraphArgs graphArgs = dppModel.graphArgs; 572 graphArgs.addOperation = false; 573 graphArgs.specifyIO = false; 574 graphArgs.build = false; 575 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 576 577 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 578 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 579 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 580 nullptr, &inputIndices, &outputIndices)); 581 582 Free(model, nullptr, nullptr); 583 } 584 585 /** 586 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_02 587 * @tc.desc: 添加算子,paramindices中data为nullptr 588 * @tc.type: FUNC 589 */ 590 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_02, 591 Function | MediumTest | Level2) 592 { 593 OH_NNModel *model = OH_NNModel_Construct(); 594 EXPECT_NE(nullptr, model); 595 596 DetectionPostProcessModel1 dppModel; 597 OHNNGraphArgs graphArgs = dppModel.graphArgs; 598 graphArgs.addOperation = false; 599 graphArgs.specifyIO = false; 600 graphArgs.build = false; 601 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 602 603 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 604 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 605 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 606 paramIndices.data = nullptr; 607 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 608 ¶mIndices, &inputIndices, &outputIndices)); 609 610 Free(model, nullptr, nullptr); 611 } 612 613 /** 614 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_03 615 * @tc.desc: 添加算子,paramindices中data对应序号不存在 616 * @tc.type: FUNC 617 */ 618 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_03, 619 Function | MediumTest | Level2) 620 { 621 OH_NNModel *model = OH_NNModel_Construct(); 622 EXPECT_NE(nullptr, model); 623 624 DetectionPostProcessModel1 dppModel; 625 OHNNGraphArgs graphArgs = dppModel.graphArgs; 626 graphArgs.addOperation = false; 627 graphArgs.specifyIO = false; 628 graphArgs.build = false; 629 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 630 631 graphArgs.paramIndices = {100000}; 632 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 633 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 634 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 635 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 636 ¶mIndices, &inputIndices, &outputIndices)); 637 638 Free(model, nullptr, nullptr); 639 } 640 641 /** 642 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_04 643 * @tc.desc: 添加算子,paramindices中size为0 644 * @tc.type: FUNC 645 */ 646 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_04, 647 Function | MediumTest | Level2) 648 { 649 OH_NNModel *model = OH_NNModel_Construct(); 650 EXPECT_NE(nullptr, model); 651 652 DetectionPostProcessModel1 dppModel; 653 OHNNGraphArgs graphArgs = dppModel.graphArgs; 654 graphArgs.addOperation = false; 655 graphArgs.specifyIO = false; 656 graphArgs.build = false; 657 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 658 659 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 660 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 661 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 662 paramIndices.size = 0; 663 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 664 ¶mIndices, &inputIndices, &outputIndices)); 665 666 Free(model, nullptr, nullptr); 667 } 668 669 /** 670 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_05 671 * @tc.desc: 添加算子,inputindices为nullptr 672 * @tc.type: FUNC 673 */ 674 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_05, 675 Function | MediumTest | Level2) 676 { 677 OH_NNModel *model = OH_NNModel_Construct(); 678 EXPECT_NE(nullptr, model); 679 680 DetectionPostProcessModel1 dppModel; 681 OHNNGraphArgs graphArgs = dppModel.graphArgs; 682 graphArgs.addOperation = false; 683 graphArgs.specifyIO = false; 684 graphArgs.build = false; 685 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 686 687 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 688 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 689 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 690 ¶mIndices, nullptr, &outputIndices)); 691 692 Free(model, nullptr, nullptr); 693 } 694 695 /** 696 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_06 697 * @tc.desc: 添加算子,inputindices中data为nullptr 698 * @tc.type: FUNC 699 */ 700 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_06, 701 Function | MediumTest | Level2) 702 { 703 OH_NNModel *model = OH_NNModel_Construct(); 704 EXPECT_NE(nullptr, model); 705 706 DetectionPostProcessModel1 dppModel; 707 OHNNGraphArgs graphArgs = dppModel.graphArgs; 708 graphArgs.addOperation = false; 709 graphArgs.specifyIO = false; 710 graphArgs.build = false; 711 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 712 713 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 714 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 715 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 716 inputIndices.data = nullptr; 717 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 718 ¶mIndices, &inputIndices, &outputIndices)); 719 720 Free(model, nullptr, nullptr); 721 } 722 723 /** 724 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_07 725 * @tc.desc: 添加算子,inputindices中data对应序号不存在 726 * @tc.type: FUNC 727 */ 728 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_07, 729 Function | MediumTest | Level2) 730 { 731 OH_NNModel *model = OH_NNModel_Construct(); 732 EXPECT_NE(nullptr, model); 733 734 DetectionPostProcessModel1 dppModel; 735 OHNNGraphArgs graphArgs = dppModel.graphArgs; 736 graphArgs.addOperation = false; 737 graphArgs.specifyIO = false; 738 graphArgs.build = false; 739 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 740 741 graphArgs.inputIndices = {100000}; 742 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 743 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 744 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 745 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 746 ¶mIndices, &inputIndices, &outputIndices)); 747 748 Free(model, nullptr, nullptr); 749 } 750 751 /** 752 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_08 753 * @tc.desc: 添加算子,inputindices中size为0 754 * @tc.type: FUNC 755 */ 756 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_08, 757 Function | MediumTest | Level2) 758 { 759 OH_NNModel *model = OH_NNModel_Construct(); 760 EXPECT_NE(nullptr, model); 761 762 DetectionPostProcessModel1 dppModel; 763 OHNNGraphArgs graphArgs = dppModel.graphArgs; 764 graphArgs.addOperation = false; 765 graphArgs.specifyIO = false; 766 graphArgs.build = false; 767 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 768 769 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 770 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 771 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 772 inputIndices.size = 0; 773 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 774 ¶mIndices, &inputIndices, &outputIndices)); 775 776 Free(model, nullptr, nullptr); 777 } 778 779 /** 780 * @tc.number : SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_09 781 * @tc.desc: 添加算子,outputindices为nullptr 782 * @tc.type: FUNC 783 */ 784 HWTEST_F(DetectionPostProcessTest, SUB_AI_NNRt_Func_North_DetectionPostProcess_Model_AddOperation_09, 785 Function | MediumTest | Level2) 786 { 787 OH_NNModel *model = OH_NNModel_Construct(); 788 EXPECT_NE(nullptr, model); 789 790 DetectionPostProcessModel1 dppModel; 791 OHNNGraphArgs graphArgs = dppModel.graphArgs; 792 graphArgs.addOperation = false; 793 graphArgs.specifyIO = false; 794 graphArgs.build = false; 795 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 796 797 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 798 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 799 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType, 800 ¶mIndices, &inputIndices, nullptr)); 801 802 Free(model, nullptr, nullptr); 803 }