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