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