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