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