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