• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vector>
17 #include <string>
18 #include <iostream>
19 #include <limits>
20 #include "nncore_utils.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::NeuralNetworkRuntime::Test;
24 class ErfTest : public testing::Test {};
25 
26 struct ErfModel1 {
27     const std::vector<int32_t> tensor_shape = {4};
28     float inputValue[4] = {0, -1, 1, 10};
29     float outputValue[4] = {0};
30     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 4*sizeof(float)};
31     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 4*sizeof(float)};
32     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_ERF,
33                                .operands = {input, output},
34                                .paramIndices = {},
35                                .inputIndices = {0},
36                                .outputIndices = {1}};
37 };
38 
39 struct ErfModel2 {
40     const std::vector<int32_t> tensor_shape = {};
41     float* inputValue = {};
42     float* outputValue = {};
43 
44     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 0*sizeof(float)};
45     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 0*sizeof(float)};
46     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_ERF,
47                                .operands = {input, output},
48                                .paramIndices = {},
49                                .inputIndices = {0},
50                                .outputIndices = {1}};
51 };
52 
53 struct ErfModel3 {
54     const std::vector<int32_t> tensor_shape = {5};
55     float inputValue[5] = {std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::infinity(),
56                            -std::numeric_limits<float>::infinity(), 1.0e20f, -1.0e20f};
57     float outputValue[5] = {0};
58 
59     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 5*sizeof(float)};
60     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 5*sizeof(float)};
61     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_ERF,
62                                .operands = {input, output},
63                                .paramIndices = {},
64                                .inputIndices = {0},
65                                .outputIndices = {1}};
66 };
67 
68 /**
69  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Build_01
70  * @tc.desc: ErfModel1模型build测试
71  * @tc.type: FUNC
72  */
73 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Build_01, Function | MediumTest | Level1)
74 {
75     OH_NNModel *model = OH_NNModel_Construct();
76     EXPECT_NE(nullptr, model);
77 
78     ErfModel1 erfModel;
79     OHNNGraphArgs graphArgs = erfModel.graphArgs;
80     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
81 
82     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
83     EXPECT_NE(nullptr, compilation);
84 
85     OHNNCompileParam compileParam{
86         .performanceMode = OH_NN_PERFORMANCE_HIGH,
87         .priority = OH_NN_PRIORITY_HIGH,
88     };
89     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
90 
91     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
92     EXPECT_NE(nullptr, executor);
93 
94     Free(model, compilation, executor);
95 }
96 
97 /**
98  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Build_02
99  * @tc.desc: ErfModel2模型build测试
100  * @tc.type: FUNC
101  */
102 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Build_02, Function | MediumTest | Level1)
103 {
104     OH_NNModel *model = OH_NNModel_Construct();
105     EXPECT_NE(nullptr, model);
106 
107     ErfModel2 erfModel;
108     OHNNGraphArgs graphArgs = erfModel.graphArgs;
109     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
110 
111     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
112     EXPECT_NE(nullptr, compilation);
113 
114     OHNNCompileParam compileParam{
115         .performanceMode = OH_NN_PERFORMANCE_HIGH,
116         .priority = OH_NN_PRIORITY_HIGH,
117     };
118     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
119 
120     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
121     EXPECT_NE(nullptr, executor);
122 
123     Free(model, compilation, executor);
124 }
125 
126 /**
127  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Build_03
128  * @tc.desc: ErfModel3模型build测试
129  * @tc.type: FUNC
130  */
131 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Build_03, Function | MediumTest | Level1)
132 {
133     OH_NNModel *model = OH_NNModel_Construct();
134     EXPECT_NE(nullptr, model);
135 
136     ErfModel3 erfModel;
137     OHNNGraphArgs graphArgs = erfModel.graphArgs;
138     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
139 
140     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
141     EXPECT_NE(nullptr, compilation);
142 
143     OHNNCompileParam compileParam{
144         .performanceMode = OH_NN_PERFORMANCE_HIGH,
145         .priority = OH_NN_PRIORITY_HIGH,
146     };
147     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
148 
149     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
150     EXPECT_NE(nullptr, executor);
151 
152     Free(model, compilation, executor);
153 }
154 
155 /**
156  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Build_04
157  * @tc.desc: ErfModel1模型输入Tensor+1进行build测试
158  * @tc.type: FUNC
159  */
160 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Build_04, Function | MediumTest | Level2)
161 {
162     OH_NNModel *model = OH_NNModel_Construct();
163     EXPECT_NE(nullptr, model);
164 
165     ErfModel1 erfModel;
166     OHNNGraphArgs graphArgs = erfModel.graphArgs;
167     graphArgs.operands = {erfModel.input, erfModel.input, erfModel.output};
168     graphArgs.inputIndices = {0, 1};
169     graphArgs.outputIndices = {2};
170     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
171 
172     Free(model, nullptr, nullptr);
173 }
174 
175 /**
176  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Build_05
177  * @tc.desc: ErfModel1模型输出Tensor+1进行build测试
178  * @tc.type: FUNC
179  */
180 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Build_05, Function | MediumTest | Level2)
181 {
182     OH_NNModel *model = OH_NNModel_Construct();
183     EXPECT_NE(nullptr, model);
184 
185     ErfModel1 erfModel;
186     OHNNGraphArgs graphArgs = erfModel.graphArgs;
187     graphArgs.operands = {erfModel.input, erfModel.output, erfModel.output};
188     graphArgs.inputIndices = {0};
189     graphArgs.outputIndices = {1, 2};
190     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
191 
192     Free(model, nullptr, nullptr);
193 }
194 
195 /**
196  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Build_06
197  * @tc.desc: ErfModel1模型传入非法参数进行build测试
198  * @tc.type: FUNC
199  */
200 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Build_06, Function | MediumTest | Level2)
201 {
202     OH_NNModel *model = OH_NNModel_Construct();
203     EXPECT_NE(nullptr, model);
204 
205     ErfModel1 erfModel;
206     OHNNGraphArgs graphArgs = erfModel.graphArgs;
207 
208     int8_t activationValue = OH_NN_FUSED_NONE;
209     OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)};
210     graphArgs.operands = {erfModel.input, erfModel.output, activation};
211     graphArgs.paramIndices = {2};
212     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
213 
214     Free(model, nullptr, nullptr);
215 }
216 
217 /**
218  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_Finish_01
219  * @tc.desc: 模型构图,未添加操作数
220  * @tc.type: FUNC
221  */
222 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_Finish_01, Function | MediumTest | Level2)
223 {
224     OH_NNModel *model = OH_NNModel_Construct();
225     EXPECT_NE(nullptr, model);
226 
227     OHNNGraphArgs graphArgs;
228     EXPECT_EQ(OH_NN_INVALID_PARAMETER, SingleModelBuildEndStep(model, graphArgs));
229 
230     Free(model, nullptr, nullptr);
231 }
232 
233 /**
234  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_Finish_02
235  * @tc.desc: 模型构图,未设置输入输出
236  * @tc.type: FUNC
237  */
238 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_Finish_02, Function | MediumTest | Level2)
239 {
240     OH_NNModel *model = OH_NNModel_Construct();
241     EXPECT_NE(nullptr, model);
242 
243     ErfModel1 erfModel;
244     OHNNGraphArgs graphArgs = erfModel.graphArgs;
245     graphArgs.specifyIO = false;
246     EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs));
247 
248     Free(model, nullptr, nullptr);
249 }
250 
251 /**
252  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_Finish_03
253  * @tc.desc: 模型构图,设置输入输出,构图成功
254  * @tc.type: FUNC
255  */
256 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_Finish_03, Function | MediumTest | Level1)
257 {
258     OH_NNModel *model = OH_NNModel_Construct();
259     EXPECT_NE(nullptr, model);
260 
261     ErfModel1 erfModel;
262     OHNNGraphArgs graphArgs = erfModel.graphArgs;
263     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
264 
265     Free(model, nullptr, nullptr);
266 }
267 
268 /**
269  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SetOperandValue_01
270  * @tc.desc: 设置操作数值,操作数不存在
271  * @tc.type: FUNC
272  */
273 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SetOperandValue_01, Function | MediumTest | Level2)
274 {
275     OH_NNModel *model = OH_NNModel_Construct();
276     EXPECT_NE(nullptr, model);
277 
278     ErfModel1 erfModel;
279     OHNNGraphArgs graphArgs = erfModel.graphArgs;
280 
281     NN_TensorDesc* tensorDesc = nullptr;
282     std::vector<NN_TensorDesc*> tensorDescVec;
283 
284     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
285         const OHNNOperandTest &operandTem = graphArgs.operands[i];
286         tensorDesc = createTensorDesc(operandTem.shape.data(),
287                                       (uint32_t) operandTem.shape.size(),
288                                       operandTem.dataType, operandTem.format);
289         tensorDescVec.emplace_back(tensorDesc);
290         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
291         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
292 
293         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
294             graphArgs.paramIndices.end()) {
295             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(
296                 model, 1000+i, operandTem.data, operandTem.length));
297         }
298     }
299 
300     FreeTensorDescVec(tensorDescVec);
301     Free(model, nullptr, nullptr);
302 }
303 
304 /**
305  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SetOperandValue_02
306  * @tc.desc: 设置操作数值,buufer为nullptr
307  * @tc.type: FUNC
308  */
309 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SetOperandValue_02, Function | MediumTest | Level2)
310 {
311     OH_NNModel *model = OH_NNModel_Construct();
312     EXPECT_NE(nullptr, model);
313 
314     ErfModel1 erfModel;
315     OHNNGraphArgs graphArgs = erfModel.graphArgs;
316 
317     NN_TensorDesc* tensorDesc = nullptr;
318     std::vector<NN_TensorDesc*> tensorDescVec;
319 
320     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
321         const OHNNOperandTest &operandTem = graphArgs.operands[i];
322         tensorDesc = createTensorDesc(operandTem.shape.data(),
323                                       (uint32_t) operandTem.shape.size(),
324                                       operandTem.dataType, operandTem.format);
325         tensorDescVec.emplace_back(tensorDesc);
326         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
327         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
328 
329         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
330             graphArgs.paramIndices.end()) {
331             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, i, nullptr, operandTem.length));
332         }
333     }
334 
335     FreeTensorDescVec(tensorDescVec);
336     Free(model, nullptr, nullptr);
337 }
338 
339 /**
340  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SetOperandValue_03
341  * @tc.desc: 设置操作数值,length为0
342  * @tc.type: FUNC
343  */
344 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SetOperandValue_03, Function | MediumTest | Level2)
345 {
346     OH_NNModel *model = OH_NNModel_Construct();
347     EXPECT_NE(nullptr, model);
348 
349     ErfModel1 erfModel;
350     OHNNGraphArgs graphArgs = erfModel.graphArgs;
351 
352     NN_TensorDesc* tensorDesc = nullptr;
353     std::vector<NN_TensorDesc*> tensorDescVec;
354 
355     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
356         const OHNNOperandTest &operandTem = graphArgs.operands[i];
357         tensorDesc = createTensorDesc(operandTem.shape.data(),
358                                       (uint32_t) operandTem.shape.size(),
359                                       operandTem.dataType, operandTem.format);
360         tensorDescVec.emplace_back(tensorDesc);
361         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
362         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
363 
364         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
365             graphArgs.paramIndices.end()) {
366             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000+i, operandTem.data, 0));
367         }
368     }
369 
370     FreeTensorDescVec(tensorDescVec);
371     Free(model, nullptr, nullptr);
372 }
373 
374 /**
375  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_01
376  * @tc.desc: 设置输入输出,inputIndices为nullptr
377  * @tc.type: FUNC
378  */
379 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_01, Function | MediumTest | Level2)
380 {
381     OH_NNModel *model = OH_NNModel_Construct();
382     EXPECT_NE(nullptr, model);
383 
384     ErfModel1 erfModel;
385     OHNNGraphArgs graphArgs = erfModel.graphArgs;
386     graphArgs.specifyIO = false;
387     graphArgs.build = false;
388     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
389 
390     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
391     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
392     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices));
393 
394     Free(model, nullptr, nullptr);
395 }
396 
397 /**
398  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_02
399  * @tc.desc: 设置输入输出,inputindices中data为nullptr
400  * @tc.type: FUNC
401  */
402 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_02, Function | MediumTest | Level2)
403 {
404     OH_NNModel *model = OH_NNModel_Construct();
405     EXPECT_NE(nullptr, model);
406 
407     ErfModel1 erfModel;
408     OHNNGraphArgs graphArgs = erfModel.graphArgs;
409     graphArgs.specifyIO = false;
410     graphArgs.build = false;
411     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
412 
413     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
414     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
415     inputIndices.data = nullptr;
416     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
417 
418     Free(model, nullptr, nullptr);
419 }
420 
421 /**
422  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_03
423  * @tc.desc: 设置输入输出,inputindices中data对应序号不存在
424  * @tc.type: FUNC
425  */
426 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_03, Function | MediumTest | Level2)
427 {
428     OH_NNModel *model = OH_NNModel_Construct();
429     EXPECT_NE(nullptr, model);
430 
431     ErfModel1 erfModel;
432     OHNNGraphArgs graphArgs = erfModel.graphArgs;
433     graphArgs.specifyIO = false;
434     graphArgs.build = false;
435     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
436 
437     graphArgs.inputIndices = {100000};
438     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
439     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
440     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
441 
442     Free(model, nullptr, nullptr);
443 }
444 
445 /**
446  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_04
447  * @tc.desc: 设置输入输出,inputindices中size为0
448  * @tc.type: FUNC
449  */
450 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_04, Function | MediumTest | Level2)
451 {
452     OH_NNModel *model = OH_NNModel_Construct();
453     EXPECT_NE(nullptr, model);
454 
455     ErfModel1 erfModel;
456     OHNNGraphArgs graphArgs = erfModel.graphArgs;
457     graphArgs.specifyIO = false;
458     graphArgs.build = false;
459     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
460 
461     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
462     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
463     inputIndices.size = 0;
464     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
465 
466     Free(model, nullptr, nullptr);
467 }
468 
469 /**
470  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_05
471  * @tc.desc: 设置输入输出,outputindices为nullptr
472  * @tc.type: FUNC
473  */
474 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_05, Function | MediumTest | Level2)
475 {
476     OH_NNModel *model = OH_NNModel_Construct();
477     EXPECT_NE(nullptr, model);
478 
479     ErfModel1 erfModel;
480     OHNNGraphArgs graphArgs = erfModel.graphArgs;
481     graphArgs.specifyIO = false;
482     graphArgs.build = false;
483     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
484 
485     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
486     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
487     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr));
488 
489     Free(model, nullptr, nullptr);
490 }
491 
492 /**
493  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_06
494  * @tc.desc: 设置输入输出,outputindices中data为nullptr
495  * @tc.type: FUNC
496  */
497 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_06, Function | MediumTest | Level2)
498 {
499     OH_NNModel *model = OH_NNModel_Construct();
500     EXPECT_NE(nullptr, model);
501 
502     ErfModel1 erfModel;
503     OHNNGraphArgs graphArgs = erfModel.graphArgs;
504     graphArgs.specifyIO = false;
505     graphArgs.build = false;
506     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
507 
508     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
509     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
510     outputIndices.data = nullptr;
511     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
512 
513     Free(model, nullptr, nullptr);
514 }
515 
516 /**
517  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_07
518  * @tc.desc: 设置输入输出,outputindices中data对应序号不存在
519  * @tc.type: FUNC
520  */
521 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_07, Function | MediumTest | Level2)
522 {
523     OH_NNModel *model = OH_NNModel_Construct();
524     EXPECT_NE(nullptr, model);
525 
526     ErfModel1 erfModel;
527     OHNNGraphArgs graphArgs = erfModel.graphArgs;
528     graphArgs.specifyIO = false;
529     graphArgs.build = false;
530     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
531 
532     graphArgs.outputIndices = {100000};
533     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
534     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
535     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
536 
537     Free(model, nullptr, nullptr);
538 }
539 
540 /**
541  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_08
542  * @tc.desc: 设置输入输出,outputindices中size为0
543  * @tc.type: FUNC
544  */
545 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_SpecifyInputsAndOutputs_08, Function | MediumTest | Level2)
546 {
547     OH_NNModel *model = OH_NNModel_Construct();
548     EXPECT_NE(nullptr, model);
549 
550     ErfModel1 erfModel;
551     OHNNGraphArgs graphArgs = erfModel.graphArgs;
552     graphArgs.specifyIO = false;
553     graphArgs.build = false;
554     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
555 
556     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
557     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
558     outputIndices.size = 0;
559     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
560 
561     Free(model, nullptr, nullptr);
562 }
563 
564 /**
565  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_01
566  * @tc.desc: 添加算子,paramindices为nullptr
567  * @tc.type: FUNC
568  */
569 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_01, Function | MediumTest | Level2)
570 {
571     OH_NNModel *model = OH_NNModel_Construct();
572     EXPECT_NE(nullptr, model);
573 
574     ErfModel1 erfModel;
575     OHNNGraphArgs graphArgs = erfModel.graphArgs;
576     graphArgs.addOperation = false;
577     graphArgs.specifyIO = false;
578     graphArgs.build = false;
579     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
580 
581     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
582     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
583     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
584                                                                nullptr, &inputIndices, &outputIndices));
585 
586     Free(model, nullptr, nullptr);
587 }
588 
589 /**
590  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_02
591  * @tc.desc: 添加算子,paramindices中data为nullptr
592  * @tc.type: FUNC
593  */
594 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_02, Function | MediumTest | Level2)
595 {
596     OH_NNModel *model = OH_NNModel_Construct();
597     EXPECT_NE(nullptr, model);
598 
599     ErfModel1 erfModel;
600     OHNNGraphArgs graphArgs = erfModel.graphArgs;
601     graphArgs.addOperation = false;
602     graphArgs.specifyIO = false;
603     graphArgs.build = false;
604     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
605 
606     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
607     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
608     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
609     paramIndices.data = nullptr;
610     EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
611                                                      &paramIndices, &inputIndices, &outputIndices));
612 
613     Free(model, nullptr, nullptr);
614 }
615 
616 /**
617  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_03
618  * @tc.desc: 添加算子,paramindices中data对应序号不存在
619  * @tc.type: FUNC
620  */
621 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_03, Function | MediumTest | Level2)
622 {
623     OH_NNModel *model = OH_NNModel_Construct();
624     EXPECT_NE(nullptr, model);
625 
626     ErfModel1 erfModel;
627     OHNNGraphArgs graphArgs = erfModel.graphArgs;
628     graphArgs.addOperation = false;
629     graphArgs.specifyIO = false;
630     graphArgs.build = false;
631     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
632 
633     graphArgs.paramIndices = {100000};
634     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
635     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
636     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
637     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
638                                                                &paramIndices, &inputIndices, &outputIndices));
639 
640     Free(model, nullptr, nullptr);
641 }
642 
643 /**
644  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_04
645  * @tc.desc: 添加算子,paramindices中size为0
646  * @tc.type: FUNC
647  */
648 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_04, Function | MediumTest | Level2)
649 {
650     OH_NNModel *model = OH_NNModel_Construct();
651     EXPECT_NE(nullptr, model);
652 
653     ErfModel1 erfModel;
654     OHNNGraphArgs graphArgs = erfModel.graphArgs;
655     graphArgs.addOperation = false;
656     graphArgs.specifyIO = false;
657     graphArgs.build = false;
658     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
659 
660     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
661     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
662     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
663     paramIndices.size = 0;
664     EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
665                                                      &paramIndices, &inputIndices, &outputIndices));
666 
667     Free(model, nullptr, nullptr);
668 }
669 
670 /**
671  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_05
672  * @tc.desc: 添加算子,inputindices为nullptr
673  * @tc.type: FUNC
674  */
675 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_05, Function | MediumTest | Level2)
676 {
677     OH_NNModel *model = OH_NNModel_Construct();
678     EXPECT_NE(nullptr, model);
679 
680     ErfModel1 erfModel;
681     OHNNGraphArgs graphArgs = erfModel.graphArgs;
682     graphArgs.addOperation = false;
683     graphArgs.specifyIO = false;
684     graphArgs.build = false;
685     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
686 
687     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
688     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
689     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
690                                                                &paramIndices, nullptr, &outputIndices));
691 
692     Free(model, nullptr, nullptr);
693 }
694 
695 /**
696  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_06
697  * @tc.desc: 添加算子,inputindices中data为nullptr
698  * @tc.type: FUNC
699  */
700 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_06, Function | MediumTest | Level2)
701 {
702     OH_NNModel *model = OH_NNModel_Construct();
703     EXPECT_NE(nullptr, model);
704 
705     ErfModel1 erfModel;
706     OHNNGraphArgs graphArgs = erfModel.graphArgs;
707     graphArgs.addOperation = false;
708     graphArgs.specifyIO = false;
709     graphArgs.build = false;
710     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
711 
712     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
713     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
714     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
715     inputIndices.data = nullptr;
716     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
717                                                                &paramIndices, &inputIndices, &outputIndices));
718 
719     Free(model, nullptr, nullptr);
720 }
721 
722 /**
723  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_07
724  * @tc.desc: 添加算子,inputindices中data对应序号不存在
725  * @tc.type: FUNC
726  */
727 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_07, Function | MediumTest | Level2)
728 {
729     OH_NNModel *model = OH_NNModel_Construct();
730     EXPECT_NE(nullptr, model);
731 
732     ErfModel1 erfModel;
733     OHNNGraphArgs graphArgs = erfModel.graphArgs;
734     graphArgs.addOperation = false;
735     graphArgs.specifyIO = false;
736     graphArgs.build = false;
737     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
738 
739     graphArgs.inputIndices = {100000};
740     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
741     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
742     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
743     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
744                                                                &paramIndices, &inputIndices, &outputIndices));
745 
746     Free(model, nullptr, nullptr);
747 }
748 
749 /**
750  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_08
751  * @tc.desc: 添加算子,inputindices中size为0
752  * @tc.type: FUNC
753  */
754 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_08, Function | MediumTest | Level2)
755 {
756     OH_NNModel *model = OH_NNModel_Construct();
757     EXPECT_NE(nullptr, model);
758 
759     ErfModel1 erfModel;
760     OHNNGraphArgs graphArgs = erfModel.graphArgs;
761     graphArgs.addOperation = false;
762     graphArgs.specifyIO = false;
763     graphArgs.build = false;
764     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
765 
766     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
767     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
768     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
769     inputIndices.size = 0;
770     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
771                                                                &paramIndices, &inputIndices, &outputIndices));
772 
773     Free(model, nullptr, nullptr);
774 }
775 
776 /**
777  * @tc.number : SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_09
778  * @tc.desc: 添加算子,outputindices为nullptr
779  * @tc.type: FUNC
780  */
781 HWTEST_F(ErfTest, SUB_AI_NNRt_Func_North_Erf_Model_AddOperation_09, Function | MediumTest | Level2)
782 {
783     OH_NNModel *model = OH_NNModel_Construct();
784     EXPECT_NE(nullptr, model);
785 
786     ErfModel1 erfModel;
787     OHNNGraphArgs graphArgs = erfModel.graphArgs;
788     graphArgs.addOperation = false;
789     graphArgs.specifyIO = false;
790     graphArgs.build = false;
791     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
792 
793     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
794     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
795     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType,
796                                                                &paramIndices, &inputIndices, nullptr));
797 
798     Free(model, nullptr, nullptr);
799 }