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