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