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