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