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