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