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