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