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