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