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 SelectTest : public testing::Test {}; 24 25 struct SelectModel1 { 26 const std::vector<int32_t> tensor_shape = {1}; 27 bool input0Value[1] = {true}; 28 float input1Value[1] = {1}; 29 float input2Value[1] = {4}; 30 float outputValue[1] = {0}; 31 32 OHNNOperandTest input0 = {OH_NN_BOOL, OH_NN_TENSOR, tensor_shape, input0Value, sizeof(bool)}; 33 OHNNOperandTest input1 = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, input1Value, sizeof(float)}; 34 OHNNOperandTest input2 = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, input2Value, sizeof(float)}; 35 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, sizeof(float)}; 36 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SELECT, 37 .operands = {input0, input1, input2, output}, 38 .paramIndices = {}, 39 .inputIndices = {0, 1, 2}, 40 .outputIndices = {3}}; 41 }; 42 43 struct SelectModel2 { 44 const std::vector<int32_t> tensor_shape = {3}; 45 bool input0Value[3] = {true, false, false}; 46 float input1Value[3] = {1, 2, 3}; 47 float input2Value[3] = {4, 5, 6}; 48 float outputValue[3] = {0}; 49 50 OHNNOperandTest input0 = {OH_NN_BOOL, OH_NN_TENSOR, tensor_shape, input0Value, 3*sizeof(bool)}; 51 OHNNOperandTest input1 = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, input1Value, 3*sizeof(float)}; 52 OHNNOperandTest input2 = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, input2Value, 3*sizeof(float)}; 53 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 3*sizeof(float)}; 54 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SELECT, 55 .operands = {input0, input1, input2, output}, 56 .paramIndices = {}, 57 .inputIndices = {0, 1, 2}, 58 .outputIndices = {3}}; 59 }; 60 61 struct SelectModel3 { 62 const std::vector<int32_t> input0_shape = {2}; 63 const std::vector<int32_t> input_shape = {3}; 64 bool input0Value[2] = {true, false}; 65 float input1Value[3] = {1, 2, 3}; 66 float input2Value[3] = {4, 5, 6}; 67 float outputValue[3] = {0}; 68 69 OHNNOperandTest input0 = {OH_NN_BOOL, OH_NN_TENSOR, input0_shape, input0Value, 2*sizeof(bool)}; 70 OHNNOperandTest input1 = {OH_NN_FLOAT32, OH_NN_TENSOR, input_shape, input1Value, 3*sizeof(float)}; 71 OHNNOperandTest input2 = {OH_NN_FLOAT32, OH_NN_TENSOR, input_shape, input2Value, 3*sizeof(float)}; 72 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, input_shape, outputValue, 3*sizeof(float)}; 73 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SELECT, 74 .operands = {input0, input1, input2, output}, 75 .paramIndices = {}, 76 .inputIndices = {0, 1, 2}, 77 .outputIndices = {3}}; 78 }; 79 80 struct SelectModel4 { 81 const std::vector<int32_t> input0_shape = {2}; 82 const std::vector<int32_t> input1_shape = {3}; 83 const std::vector<int32_t> input2_shape = {4}; 84 bool input0Value[2] = {true, false}; 85 float input1Value[3] = {1, 2, 3}; 86 float input2Value[4] = {4, 5, 6, 7}; 87 float outputValue[3] = {0}; 88 89 OHNNOperandTest input0 = {OH_NN_BOOL, OH_NN_TENSOR, input0_shape, input0Value, 2*sizeof(bool)}; 90 OHNNOperandTest input1 = {OH_NN_FLOAT32, OH_NN_TENSOR, input1_shape, input1Value, 3*sizeof(float)}; 91 OHNNOperandTest input2 = {OH_NN_FLOAT32, OH_NN_TENSOR, input2_shape, input2Value, 4*sizeof(float)}; 92 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, input1_shape, outputValue, 3*sizeof(float)}; 93 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SELECT, 94 .operands = {input0, input1, input2, output}, 95 .paramIndices = {}, 96 .inputIndices = {0, 1, 2}, 97 .outputIndices = {3}}; 98 }; 99 100 struct SelectModel5 { 101 const std::vector<int32_t> tensor_shape = {1}; 102 bool* input0Value = {}; 103 float* input1Value = {}; 104 float* outputValue = {}; 105 106 OHNNOperandTest input0 = {OH_NN_BOOL, OH_NN_TENSOR, tensor_shape, input0Value, sizeof(bool)}; 107 OHNNOperandTest input1 = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, input1Value, sizeof(float)}; 108 OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, sizeof(float)}; 109 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SELECT, 110 .operands = {input0, input1, input1, output}, 111 .paramIndices = {}, 112 .inputIndices = {0, 1, 2}, 113 .outputIndices = {3}}; 114 }; 115 116 /** 117 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_01 118 * @tc.desc: SelectModel1模型build测试 119 * @tc.type: FUNC 120 */ 121 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_01, Function | MediumTest | Level1) 122 { 123 OH_NNModel *model = OH_NNModel_Construct(); 124 EXPECT_NE(nullptr, model); 125 126 SelectModel1 selectModel; 127 OHNNGraphArgs graphArgs = selectModel.graphArgs; 128 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 129 130 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 131 EXPECT_NE(nullptr, compilation); 132 133 OHNNCompileParam compileParam{ 134 .performanceMode = OH_NN_PERFORMANCE_HIGH, 135 .priority = OH_NN_PRIORITY_HIGH, 136 }; 137 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 138 139 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 140 EXPECT_NE(nullptr, executor); 141 142 Free(model, compilation, executor); 143 } 144 145 /** 146 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_02 147 * @tc.desc: SelectModel2模型build测试 148 * @tc.type: FUNC 149 */ 150 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_02, Function | MediumTest | Level1) 151 { 152 OH_NNModel *model = OH_NNModel_Construct(); 153 EXPECT_NE(nullptr, model); 154 155 SelectModel2 selectModel; 156 OHNNGraphArgs graphArgs = selectModel.graphArgs; 157 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 158 159 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 160 EXPECT_NE(nullptr, compilation); 161 162 OHNNCompileParam compileParam{ 163 .performanceMode = OH_NN_PERFORMANCE_HIGH, 164 .priority = OH_NN_PRIORITY_HIGH, 165 }; 166 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 167 168 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 169 EXPECT_NE(nullptr, executor); 170 171 Free(model, compilation, executor); 172 } 173 174 /** 175 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_03 176 * @tc.desc: SelectModel3模型build测试 177 * @tc.type: FUNC 178 */ 179 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_03, Function | MediumTest | Level1) 180 { 181 OH_NNModel *model = OH_NNModel_Construct(); 182 EXPECT_NE(nullptr, model); 183 184 SelectModel3 selectModel; 185 OHNNGraphArgs graphArgs = selectModel.graphArgs; 186 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 187 188 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 189 EXPECT_NE(nullptr, compilation); 190 191 OHNNCompileParam compileParam{ 192 .performanceMode = OH_NN_PERFORMANCE_HIGH, 193 .priority = OH_NN_PRIORITY_HIGH, 194 }; 195 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 196 197 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 198 EXPECT_NE(nullptr, executor); 199 200 Free(model, compilation, executor); 201 } 202 203 /** 204 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_04 205 * @tc.desc: SelectModel4模型build测试 206 * @tc.type: FUNC 207 */ 208 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_04, Function | MediumTest | Level1) 209 { 210 OH_NNModel *model = OH_NNModel_Construct(); 211 EXPECT_NE(nullptr, model); 212 213 SelectModel4 selectModel; 214 OHNNGraphArgs graphArgs = selectModel.graphArgs; 215 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 216 217 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 218 EXPECT_NE(nullptr, compilation); 219 220 OHNNCompileParam compileParam{ 221 .performanceMode = OH_NN_PERFORMANCE_HIGH, 222 .priority = OH_NN_PRIORITY_HIGH, 223 }; 224 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 225 226 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 227 EXPECT_NE(nullptr, executor); 228 229 Free(model, compilation, executor); 230 } 231 232 /** 233 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_05 234 * @tc.desc: SelectModel5模型build测试 235 * @tc.type: FUNC 236 */ 237 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_05, Function | MediumTest | Level1) 238 { 239 OH_NNModel *model = OH_NNModel_Construct(); 240 EXPECT_NE(nullptr, model); 241 242 SelectModel5 selectModel; 243 OHNNGraphArgs graphArgs = selectModel.graphArgs; 244 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 245 246 OH_NNCompilation *compilation = OH_NNCompilation_Construct(model); 247 EXPECT_NE(nullptr, compilation); 248 249 OHNNCompileParam compileParam{ 250 .performanceMode = OH_NN_PERFORMANCE_HIGH, 251 .priority = OH_NN_PRIORITY_HIGH, 252 }; 253 EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam)); 254 255 OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation); 256 EXPECT_NE(nullptr, executor); 257 258 Free(model, compilation, executor); 259 } 260 261 /** 262 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_06 263 * @tc.desc: SelectModel1模型输入Tensor+1进行build测试 264 * @tc.type: FUNC 265 */ 266 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_06, Function | MediumTest | Level2) 267 { 268 OH_NNModel *model = OH_NNModel_Construct(); 269 EXPECT_NE(nullptr, model); 270 271 SelectModel1 selectModel; 272 OHNNGraphArgs graphArgs = selectModel.graphArgs; 273 graphArgs.operands = {selectModel.input0, selectModel.input1, selectModel.input2, 274 selectModel.input2, selectModel.output}; 275 graphArgs.inputIndices = {0, 1, 2, 3}; 276 graphArgs.outputIndices = {4}; 277 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 278 279 Free(model, nullptr, nullptr); 280 } 281 282 /** 283 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_07 284 * @tc.desc: SelectModel1模型输出Tensor+1进行build测试 285 * @tc.type: FUNC 286 */ 287 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_07, Function | MediumTest | Level2) 288 { 289 OH_NNModel *model = OH_NNModel_Construct(); 290 EXPECT_NE(nullptr, model); 291 292 SelectModel1 selectModel; 293 OHNNGraphArgs graphArgs = selectModel.graphArgs; 294 graphArgs.operands = {selectModel.input0, selectModel.input1, selectModel.input2, 295 selectModel.output, selectModel.output}; 296 graphArgs.inputIndices = {0, 1, 2}; 297 graphArgs.outputIndices = {3, 4}; 298 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 299 300 Free(model, nullptr, nullptr); 301 } 302 303 /** 304 * @tc.number : SUB_AI_NNRt_Func_North_Select_Build_08 305 * @tc.desc: SelectModel1模型传入非法参数进行build测试 306 * @tc.type: FUNC 307 */ 308 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Build_08, Function | MediumTest | Level2) 309 { 310 OH_NNModel *model = OH_NNModel_Construct(); 311 EXPECT_NE(nullptr, model); 312 313 SelectModel1 selectModel; 314 OHNNGraphArgs graphArgs = selectModel.graphArgs; 315 316 int8_t activationValue = OH_NN_FUSED_NONE; 317 OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)}; 318 graphArgs.operands = {selectModel.input0, selectModel.input1, selectModel.input2, selectModel.output, activation}; 319 graphArgs.paramIndices = {4}; 320 EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs)); 321 322 Free(model, nullptr, nullptr); 323 } 324 325 /** 326 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_Finish_01 327 * @tc.desc: 模型构图,未添加操作数 328 * @tc.type: FUNC 329 */ 330 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_Finish_01, Function | MediumTest | Level2) 331 { 332 OH_NNModel *model = OH_NNModel_Construct(); 333 EXPECT_NE(nullptr, model); 334 335 OHNNGraphArgs graphArgs; 336 EXPECT_EQ(OH_NN_INVALID_PARAMETER, SingleModelBuildEndStep(model, graphArgs)); 337 338 Free(model, nullptr, nullptr); 339 } 340 341 /** 342 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_Finish_02 343 * @tc.desc: 模型构图,未设置输入输出 344 * @tc.type: FUNC 345 */ 346 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_Finish_02, Function | MediumTest | Level2) 347 { 348 OH_NNModel *model = OH_NNModel_Construct(); 349 EXPECT_NE(nullptr, model); 350 351 SelectModel1 selectModel; 352 OHNNGraphArgs graphArgs = selectModel.graphArgs; 353 graphArgs.specifyIO = false; 354 EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs)); 355 356 Free(model, nullptr, nullptr); 357 } 358 359 /** 360 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_Finish_03 361 * @tc.desc: 模型构图,设置输入输出,构图成功 362 * @tc.type: FUNC 363 */ 364 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_Finish_03, Function | MediumTest | Level1) 365 { 366 OH_NNModel *model = OH_NNModel_Construct(); 367 EXPECT_NE(nullptr, model); 368 369 SelectModel1 selectModel; 370 OHNNGraphArgs graphArgs = selectModel.graphArgs; 371 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 372 373 Free(model, nullptr, nullptr); 374 } 375 376 /** 377 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SetOperandValue_01 378 * @tc.desc: 设置操作数值,操作数不存在 379 * @tc.type: FUNC 380 */ 381 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SetOperandValue_01, Function | MediumTest | Level2) 382 { 383 OH_NNModel *model = OH_NNModel_Construct(); 384 EXPECT_NE(nullptr, model); 385 386 SelectModel1 selectModel; 387 OHNNGraphArgs graphArgs = selectModel.graphArgs; 388 389 NN_TensorDesc* tensorDesc = nullptr; 390 std::vector<NN_TensorDesc*> tensorDescVec; 391 392 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 393 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 394 tensorDesc = createTensorDesc(operandTem.shape.data(), 395 (uint32_t) operandTem.shape.size(), 396 operandTem.dataType, operandTem.format); 397 tensorDescVec.emplace_back(tensorDesc); 398 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 399 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 400 401 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 402 graphArgs.paramIndices.end()) { 403 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData( 404 model, 1000+i, operandTem.data, operandTem.length)); 405 } 406 } 407 408 FreeTensorDescVec(tensorDescVec); 409 Free(model, nullptr, nullptr); 410 } 411 412 /** 413 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SetOperandValue_02 414 * @tc.desc: 设置操作数值,buufer为nullptr 415 * @tc.type: FUNC 416 */ 417 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SetOperandValue_02, Function | MediumTest | Level2) 418 { 419 OH_NNModel *model = OH_NNModel_Construct(); 420 EXPECT_NE(nullptr, model); 421 422 SelectModel1 selectModel; 423 OHNNGraphArgs graphArgs = selectModel.graphArgs; 424 425 NN_TensorDesc* tensorDesc = nullptr; 426 std::vector<NN_TensorDesc*> tensorDescVec; 427 428 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 429 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 430 tensorDesc = createTensorDesc(operandTem.shape.data(), 431 (uint32_t) operandTem.shape.size(), 432 operandTem.dataType, operandTem.format); 433 tensorDescVec.emplace_back(tensorDesc); 434 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 435 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 436 437 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 438 graphArgs.paramIndices.end()) { 439 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, i, nullptr, operandTem.length)); 440 } 441 } 442 443 FreeTensorDescVec(tensorDescVec); 444 Free(model, nullptr, nullptr); 445 } 446 447 /** 448 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SetOperandValue_03 449 * @tc.desc: 设置操作数值,length为0 450 * @tc.type: FUNC 451 */ 452 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SetOperandValue_03, Function | MediumTest | Level2) 453 { 454 OH_NNModel *model = OH_NNModel_Construct(); 455 EXPECT_NE(nullptr, model); 456 457 SelectModel1 selectModel; 458 OHNNGraphArgs graphArgs = selectModel.graphArgs; 459 460 NN_TensorDesc* tensorDesc = nullptr; 461 std::vector<NN_TensorDesc*> tensorDescVec; 462 463 for (size_t i = 0; i < graphArgs.operands.size(); i++) { 464 const OHNNOperandTest &operandTem = graphArgs.operands[i]; 465 tensorDesc = createTensorDesc(operandTem.shape.data(), 466 (uint32_t) operandTem.shape.size(), 467 operandTem.dataType, operandTem.format); 468 tensorDescVec.emplace_back(tensorDesc); 469 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc)); 470 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type)); 471 472 if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) != 473 graphArgs.paramIndices.end()) { 474 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000+i, operandTem.data, 0)); 475 } 476 } 477 478 FreeTensorDescVec(tensorDescVec); 479 Free(model, nullptr, nullptr); 480 } 481 482 /** 483 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_01 484 * @tc.desc: 设置输入输出,inputIndices为nullptr 485 * @tc.type: FUNC 486 */ 487 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_01, Function | MediumTest | Level2) 488 { 489 OH_NNModel *model = OH_NNModel_Construct(); 490 EXPECT_NE(nullptr, model); 491 492 SelectModel1 selectModel; 493 OHNNGraphArgs graphArgs = selectModel.graphArgs; 494 graphArgs.specifyIO = false; 495 graphArgs.build = false; 496 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 497 498 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 499 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 500 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices)); 501 502 Free(model, nullptr, nullptr); 503 } 504 505 /** 506 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_02 507 * @tc.desc: 设置输入输出,inputindices中data为nullptr 508 * @tc.type: FUNC 509 */ 510 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_02, Function | MediumTest | Level2) 511 { 512 OH_NNModel *model = OH_NNModel_Construct(); 513 EXPECT_NE(nullptr, model); 514 515 SelectModel1 selectModel; 516 OHNNGraphArgs graphArgs = selectModel.graphArgs; 517 graphArgs.specifyIO = false; 518 graphArgs.build = false; 519 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 520 521 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 522 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 523 inputIndices.data = nullptr; 524 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 525 526 Free(model, nullptr, nullptr); 527 } 528 529 /** 530 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_03 531 * @tc.desc: 设置输入输出,inputindices中data对应序号不存在 532 * @tc.type: FUNC 533 */ 534 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_03, Function | MediumTest | Level2) 535 { 536 OH_NNModel *model = OH_NNModel_Construct(); 537 EXPECT_NE(nullptr, model); 538 539 SelectModel1 selectModel; 540 OHNNGraphArgs graphArgs = selectModel.graphArgs; 541 graphArgs.specifyIO = false; 542 graphArgs.build = false; 543 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 544 545 graphArgs.inputIndices = {100000}; 546 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 547 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 548 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 549 550 Free(model, nullptr, nullptr); 551 } 552 553 /** 554 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_04 555 * @tc.desc: 设置输入输出,inputindices中size为0 556 * @tc.type: FUNC 557 */ 558 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_04, Function | MediumTest | Level2) 559 { 560 OH_NNModel *model = OH_NNModel_Construct(); 561 EXPECT_NE(nullptr, model); 562 563 SelectModel1 selectModel; 564 OHNNGraphArgs graphArgs = selectModel.graphArgs; 565 graphArgs.specifyIO = false; 566 graphArgs.build = false; 567 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 568 569 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 570 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 571 inputIndices.size = 0; 572 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 573 574 Free(model, nullptr, nullptr); 575 } 576 577 /** 578 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_05 579 * @tc.desc: 设置输入输出,outputindices为nullptr 580 * @tc.type: FUNC 581 */ 582 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_05, Function | MediumTest | Level2) 583 { 584 OH_NNModel *model = OH_NNModel_Construct(); 585 EXPECT_NE(nullptr, model); 586 587 SelectModel1 selectModel; 588 OHNNGraphArgs graphArgs = selectModel.graphArgs; 589 graphArgs.specifyIO = false; 590 graphArgs.build = false; 591 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 592 593 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 594 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 595 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr)); 596 597 Free(model, nullptr, nullptr); 598 } 599 600 /** 601 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_06 602 * @tc.desc: 设置输入输出,outputindices中data为nullptr 603 * @tc.type: FUNC 604 */ 605 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_06, Function | MediumTest | Level2) 606 { 607 OH_NNModel *model = OH_NNModel_Construct(); 608 EXPECT_NE(nullptr, model); 609 610 SelectModel1 selectModel; 611 OHNNGraphArgs graphArgs = selectModel.graphArgs; 612 graphArgs.specifyIO = false; 613 graphArgs.build = false; 614 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 615 616 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 617 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 618 outputIndices.data = nullptr; 619 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 620 621 Free(model, nullptr, nullptr); 622 } 623 624 /** 625 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_07 626 * @tc.desc: 设置输入输出,outputindices中data对应序号不存在 627 * @tc.type: FUNC 628 */ 629 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_07, Function | MediumTest | Level2) 630 { 631 OH_NNModel *model = OH_NNModel_Construct(); 632 EXPECT_NE(nullptr, model); 633 634 SelectModel1 selectModel; 635 OHNNGraphArgs graphArgs = selectModel.graphArgs; 636 graphArgs.specifyIO = false; 637 graphArgs.build = false; 638 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 639 640 graphArgs.outputIndices = {100000}; 641 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 642 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 643 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 644 645 Free(model, nullptr, nullptr); 646 } 647 648 /** 649 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_08 650 * @tc.desc: 设置输入输出,outputindices中size为0 651 * @tc.type: FUNC 652 */ 653 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_SpecifyInputsAndOutputs_08, Function | MediumTest | Level2) 654 { 655 OH_NNModel *model = OH_NNModel_Construct(); 656 EXPECT_NE(nullptr, model); 657 658 SelectModel1 selectModel; 659 OHNNGraphArgs graphArgs = selectModel.graphArgs; 660 graphArgs.specifyIO = false; 661 graphArgs.build = false; 662 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 663 664 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 665 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 666 outputIndices.size = 0; 667 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices)); 668 669 Free(model, nullptr, nullptr); 670 } 671 672 /** 673 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_01 674 * @tc.desc: 添加算子,paramindices为nullptr 675 * @tc.type: FUNC 676 */ 677 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_01, Function | MediumTest | Level2) 678 { 679 OH_NNModel *model = OH_NNModel_Construct(); 680 EXPECT_NE(nullptr, model); 681 682 SelectModel1 selectModel; 683 OHNNGraphArgs graphArgs = selectModel.graphArgs; 684 graphArgs.addOperation = false; 685 graphArgs.specifyIO = false; 686 graphArgs.build = false; 687 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 688 689 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 690 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 691 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 692 nullptr, &inputIndices, &outputIndices)); 693 694 Free(model, nullptr, nullptr); 695 } 696 697 /** 698 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_02 699 * @tc.desc: 添加算子,paramindices中data为nullptr 700 * @tc.type: FUNC 701 */ 702 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_02, Function | MediumTest | Level2) 703 { 704 OH_NNModel *model = OH_NNModel_Construct(); 705 EXPECT_NE(nullptr, model); 706 707 SelectModel1 selectModel; 708 OHNNGraphArgs graphArgs = selectModel.graphArgs; 709 graphArgs.addOperation = false; 710 graphArgs.specifyIO = false; 711 graphArgs.build = false; 712 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 713 714 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 715 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 716 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 717 paramIndices.data = nullptr; 718 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType, 719 ¶mIndices, &inputIndices, &outputIndices)); 720 721 Free(model, nullptr, nullptr); 722 } 723 724 /** 725 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_03 726 * @tc.desc: 添加算子,paramindices中data对应序号不存在 727 * @tc.type: FUNC 728 */ 729 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_03, Function | MediumTest | Level2) 730 { 731 OH_NNModel *model = OH_NNModel_Construct(); 732 EXPECT_NE(nullptr, model); 733 734 SelectModel1 selectModel; 735 OHNNGraphArgs graphArgs = selectModel.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.paramIndices = {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_Select_Model_AddOperation_04 753 * @tc.desc: 添加算子,paramindices中size为0 754 * @tc.type: FUNC 755 */ 756 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_04, Function | MediumTest | Level2) 757 { 758 OH_NNModel *model = OH_NNModel_Construct(); 759 EXPECT_NE(nullptr, model); 760 761 SelectModel1 selectModel; 762 OHNNGraphArgs graphArgs = selectModel.graphArgs; 763 graphArgs.addOperation = false; 764 graphArgs.specifyIO = false; 765 graphArgs.build = false; 766 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 767 768 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 769 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 770 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 771 paramIndices.size = 0; 772 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType, 773 ¶mIndices, &inputIndices, &outputIndices)); 774 775 Free(model, nullptr, nullptr); 776 } 777 778 /** 779 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_05 780 * @tc.desc: 添加算子,inputindices为nullptr 781 * @tc.type: FUNC 782 */ 783 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_05, Function | MediumTest | Level2) 784 { 785 OH_NNModel *model = OH_NNModel_Construct(); 786 EXPECT_NE(nullptr, model); 787 788 SelectModel1 selectModel; 789 OHNNGraphArgs graphArgs = selectModel.graphArgs; 790 graphArgs.addOperation = false; 791 graphArgs.specifyIO = false; 792 graphArgs.build = false; 793 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 794 795 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 796 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 797 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 798 ¶mIndices, nullptr, &outputIndices)); 799 800 Free(model, nullptr, nullptr); 801 } 802 803 /** 804 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_06 805 * @tc.desc: 添加算子,inputindices中data为nullptr 806 * @tc.type: FUNC 807 */ 808 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_06, Function | MediumTest | Level2) 809 { 810 OH_NNModel *model = OH_NNModel_Construct(); 811 EXPECT_NE(nullptr, model); 812 813 SelectModel1 selectModel; 814 OHNNGraphArgs graphArgs = selectModel.graphArgs; 815 graphArgs.addOperation = false; 816 graphArgs.specifyIO = false; 817 graphArgs.build = false; 818 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 819 820 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 821 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 822 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 823 inputIndices.data = nullptr; 824 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 825 ¶mIndices, &inputIndices, &outputIndices)); 826 827 Free(model, nullptr, nullptr); 828 } 829 830 /** 831 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_07 832 * @tc.desc: 添加算子,inputindices中data对应序号不存在 833 * @tc.type: FUNC 834 */ 835 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_07, Function | MediumTest | Level2) 836 { 837 OH_NNModel *model = OH_NNModel_Construct(); 838 EXPECT_NE(nullptr, model); 839 840 SelectModel1 selectModel; 841 OHNNGraphArgs graphArgs = selectModel.graphArgs; 842 graphArgs.addOperation = false; 843 graphArgs.specifyIO = false; 844 graphArgs.build = false; 845 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 846 847 graphArgs.inputIndices = {100000}; 848 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 849 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 850 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 851 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 852 ¶mIndices, &inputIndices, &outputIndices)); 853 854 Free(model, nullptr, nullptr); 855 } 856 857 /** 858 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_08 859 * @tc.desc: 添加算子,inputindices中size为0 860 * @tc.type: FUNC 861 */ 862 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_08, Function | MediumTest | Level2) 863 { 864 OH_NNModel *model = OH_NNModel_Construct(); 865 EXPECT_NE(nullptr, model); 866 867 SelectModel1 selectModel; 868 OHNNGraphArgs graphArgs = selectModel.graphArgs; 869 graphArgs.addOperation = false; 870 graphArgs.specifyIO = false; 871 graphArgs.build = false; 872 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 873 874 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 875 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 876 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices); 877 inputIndices.size = 0; 878 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType, 879 ¶mIndices, &inputIndices, &outputIndices)); 880 881 Free(model, nullptr, nullptr); 882 } 883 884 /** 885 * @tc.number : SUB_AI_NNRt_Func_North_Select_Model_AddOperation_09 886 * @tc.desc: 添加算子,outputindices为nullptr 887 * @tc.type: FUNC 888 */ 889 HWTEST_F(SelectTest, SUB_AI_NNRt_Func_North_Select_Model_AddOperation_09, Function | MediumTest | Level2) 890 { 891 OH_NNModel *model = OH_NNModel_Construct(); 892 EXPECT_NE(nullptr, model); 893 894 SelectModel1 selectModel; 895 OHNNGraphArgs graphArgs = selectModel.graphArgs; 896 graphArgs.addOperation = false; 897 graphArgs.specifyIO = false; 898 graphArgs.build = false; 899 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs)); 900 901 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices); 902 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices); 903 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType, 904 ¶mIndices, &inputIndices, nullptr)); 905 906 Free(model, nullptr, nullptr); 907 }