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