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