• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vector>
17 #include <string>
18 #include <iostream>
19 #include "nncore_utils.h"
20 
21 using namespace testing::ext;
22 using namespace OHOS::NeuralNetworkRuntime::Test;
23 class SwishTest : public testing::Test {};
24 
25 struct SwishModel1 {
26     const std::vector<int32_t> tensor_shape = {3, 3};
27     float inputValue[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
28     float outputValue[3][3] = {0};
29 
30     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 9*sizeof(float)};
31     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 9*sizeof(float)};
32     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SWISH,
33                                .operands = {input, output},
34                                .paramIndices = {},
35                                .inputIndices = {0},
36                                .outputIndices = {1}};
37 };
38 
39 struct SwishModel2 {
40     const std::vector<int32_t> tensor_shape = {2, 3};
41     float inputValue[2][3] = {{-1, 0, 1}, {2, -2, 3}};
42     float outputValue[2][3] = {0};
43 
44     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 6*sizeof(float)};
45     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 6*sizeof(float)};
46     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SWISH,
47                                .operands = {input, output},
48                                .paramIndices = {},
49                                .inputIndices = {0},
50                                .outputIndices = {1}};
51 };
52 
53 struct SwishModel3 {
54     const std::vector<int32_t> tensor_shape = {2, 3};
55     float inputValue[2][2] = {{0, 0}, {0, 0}};
56     float outputValue[2][2] = {0};
57 
58     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 4*sizeof(float)};
59     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 4*sizeof(float)};
60     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SWISH,
61                                .operands = {input, output},
62                                .paramIndices = {},
63                                .inputIndices = {0},
64                                .outputIndices = {1}};
65 };
66 
67 /**
68  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Build_01
69  * @tc.desc: SwishModel1模型build测试
70  * @tc.type: FUNC
71  */
72 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Build_01, Function | MediumTest | Level1)
73 {
74     OH_NNModel *model = OH_NNModel_Construct();
75     EXPECT_NE(nullptr, model);
76 
77     SwishModel1 swishModel;
78     OHNNGraphArgs graphArgs = swishModel.graphArgs;
79     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
80 
81     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
82     EXPECT_NE(nullptr, compilation);
83 
84     OHNNCompileParam compileParam{
85         .performanceMode = OH_NN_PERFORMANCE_HIGH,
86         .priority = OH_NN_PRIORITY_HIGH,
87     };
88     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
89 
90     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
91     EXPECT_NE(nullptr, executor);
92 
93     Free(model, compilation, executor);
94 }
95 
96 /**
97  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Build_02
98  * @tc.desc: SwishModel2模型build测试
99  * @tc.type: FUNC
100  */
101 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Build_02, Function | MediumTest | Level1)
102 {
103     OH_NNModel *model = OH_NNModel_Construct();
104     EXPECT_NE(nullptr, model);
105 
106     SwishModel2 swishModel;
107     OHNNGraphArgs graphArgs = swishModel.graphArgs;
108     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
109 
110     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
111     EXPECT_NE(nullptr, compilation);
112 
113     OHNNCompileParam compileParam{
114         .performanceMode = OH_NN_PERFORMANCE_HIGH,
115         .priority = OH_NN_PRIORITY_HIGH,
116     };
117     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
118 
119     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
120     EXPECT_NE(nullptr, executor);
121 
122     Free(model, compilation, executor);
123 }
124 
125 /**
126  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Build_03
127  * @tc.desc: SwishModel2模型build测试
128  * @tc.type: FUNC
129  */
130 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Build_03, Function | MediumTest | Level1)
131 {
132     OH_NNModel *model = OH_NNModel_Construct();
133     EXPECT_NE(nullptr, model);
134 
135     SwishModel3 swishModel;
136     OHNNGraphArgs graphArgs = swishModel.graphArgs;
137     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
138 
139     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
140     EXPECT_NE(nullptr, compilation);
141 
142     OHNNCompileParam compileParam{
143         .performanceMode = OH_NN_PERFORMANCE_HIGH,
144         .priority = OH_NN_PRIORITY_HIGH,
145     };
146     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
147 
148     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
149     EXPECT_NE(nullptr, executor);
150 
151     Free(model, compilation, executor);
152 }
153 
154 /**
155  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Build_04
156  * @tc.desc: SwishModel1模型输入Tensor+1进行build测试
157  * @tc.type: FUNC
158  */
159 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Build_04, Function | MediumTest | Level2)
160 {
161     OH_NNModel *model = OH_NNModel_Construct();
162     EXPECT_NE(nullptr, model);
163 
164     SwishModel1 swishModel;
165     OHNNGraphArgs graphArgs = swishModel.graphArgs;
166     graphArgs.operands = {swishModel.input, swishModel.input, swishModel.output};
167     graphArgs.inputIndices = {0, 1};
168     graphArgs.outputIndices = {2};
169     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
170 
171     Free(model, nullptr, nullptr);
172 }
173 
174 /**
175  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Build_05
176  * @tc.desc: SwishModel1模型输出Tensor+1进行build测试
177  * @tc.type: FUNC
178  */
179 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Build_05, Function | MediumTest | Level2)
180 {
181     OH_NNModel *model = OH_NNModel_Construct();
182     EXPECT_NE(nullptr, model);
183 
184     SwishModel1 swishModel;
185     OHNNGraphArgs graphArgs = swishModel.graphArgs;
186     graphArgs.operands = {swishModel.input, swishModel.output, swishModel.output};
187     graphArgs.inputIndices = {0};
188     graphArgs.outputIndices = {1, 2};
189     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
190 
191     Free(model, nullptr, nullptr);
192 }
193 
194 /**
195  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Build_06
196  * @tc.desc: SwishModel1模型传入非法参数进行build测试
197  * @tc.type: FUNC
198  */
199 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Build_06, Function | MediumTest | Level2)
200 {
201     OH_NNModel *model = OH_NNModel_Construct();
202     EXPECT_NE(nullptr, model);
203 
204     SwishModel1 swishModel;
205     OHNNGraphArgs graphArgs = swishModel.graphArgs;
206 
207     int8_t activationValue = OH_NN_FUSED_NONE;
208     OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)};
209     graphArgs.operands = {swishModel.input, swishModel.output, activation};
210     graphArgs.paramIndices = {2};
211     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
212 
213     Free(model, nullptr, nullptr);
214 }
215 
216 /**
217  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_Finish_01
218  * @tc.desc: 模型构图,未添加操作数
219  * @tc.type: FUNC
220  */
221 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_Finish_01, Function | MediumTest | Level2)
222 {
223     OH_NNModel *model = OH_NNModel_Construct();
224     EXPECT_NE(nullptr, model);
225 
226     OHNNGraphArgs graphArgs;
227     EXPECT_EQ(OH_NN_INVALID_PARAMETER, SingleModelBuildEndStep(model, graphArgs));
228 
229     Free(model, nullptr, nullptr);
230 }
231 
232 /**
233  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_Finish_02
234  * @tc.desc: 模型构图,未设置输入输出
235  * @tc.type: FUNC
236  */
237 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_Finish_02, Function | MediumTest | Level2)
238 {
239     OH_NNModel *model = OH_NNModel_Construct();
240     EXPECT_NE(nullptr, model);
241 
242     SwishModel1 swishModel;
243     OHNNGraphArgs graphArgs = swishModel.graphArgs;
244     graphArgs.specifyIO = false;
245     EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs));
246 
247     Free(model, nullptr, nullptr);
248 }
249 
250 /**
251  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_Finish_03
252  * @tc.desc: 模型构图,设置输入输出,构图成功
253  * @tc.type: FUNC
254  */
255 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_Finish_03, Function | MediumTest | Level1)
256 {
257     OH_NNModel *model = OH_NNModel_Construct();
258     EXPECT_NE(nullptr, model);
259 
260     SwishModel1 swishModel;
261     OHNNGraphArgs graphArgs = swishModel.graphArgs;
262     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
263 
264     Free(model, nullptr, nullptr);
265 }
266 
267 /**
268  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SetOperandValue_01
269  * @tc.desc: 设置操作数值,操作数不存在
270  * @tc.type: FUNC
271  */
272 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SetOperandValue_01, Function | MediumTest | Level2)
273 {
274     OH_NNModel *model = OH_NNModel_Construct();
275     EXPECT_NE(nullptr, model);
276 
277     SwishModel1 swishModel;
278     OHNNGraphArgs graphArgs = swishModel.graphArgs;
279 
280     NN_TensorDesc* tensorDesc = nullptr;
281     std::vector<NN_TensorDesc*> tensorDescVec;
282 
283     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
284         const OHNNOperandTest &operandTem = graphArgs.operands[i];
285         tensorDesc = createTensorDesc(operandTem.shape.data(),
286                                       (uint32_t) operandTem.shape.size(),
287                                       operandTem.dataType, operandTem.format);
288         tensorDescVec.emplace_back(tensorDesc);
289         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
290         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
291 
292         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
293             graphArgs.paramIndices.end()) {
294             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(
295                 model, 1000+i, operandTem.data, operandTem.length));
296         }
297     }
298 
299     FreeTensorDescVec(tensorDescVec);
300     Free(model, nullptr, nullptr);
301 }
302 
303 /**
304  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SetOperandValue_02
305  * @tc.desc: 设置操作数值,buufer为nullptr
306  * @tc.type: FUNC
307  */
308 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SetOperandValue_02, Function | MediumTest | Level2)
309 {
310     OH_NNModel *model = OH_NNModel_Construct();
311     EXPECT_NE(nullptr, model);
312 
313     SwishModel1 swishModel;
314     OHNNGraphArgs graphArgs = swishModel.graphArgs;
315 
316     NN_TensorDesc* tensorDesc = nullptr;
317     std::vector<NN_TensorDesc*> tensorDescVec;
318 
319     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
320         const OHNNOperandTest &operandTem = graphArgs.operands[i];
321         tensorDesc = createTensorDesc(operandTem.shape.data(),
322                                       (uint32_t) operandTem.shape.size(),
323                                       operandTem.dataType, operandTem.format);
324         tensorDescVec.emplace_back(tensorDesc);
325         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
326         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
327 
328         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
329             graphArgs.paramIndices.end()) {
330             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, i, nullptr, operandTem.length));
331         }
332     }
333 
334     FreeTensorDescVec(tensorDescVec);
335     Free(model, nullptr, nullptr);
336 }
337 
338 /**
339  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SetOperandValue_03
340  * @tc.desc: 设置操作数值,length为0
341  * @tc.type: FUNC
342  */
343 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SetOperandValue_03, Function | MediumTest | Level2)
344 {
345     OH_NNModel *model = OH_NNModel_Construct();
346     EXPECT_NE(nullptr, model);
347 
348     SwishModel1 swishModel;
349     OHNNGraphArgs graphArgs = swishModel.graphArgs;
350 
351     NN_TensorDesc* tensorDesc = nullptr;
352     std::vector<NN_TensorDesc*> tensorDescVec;
353 
354     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
355         const OHNNOperandTest &operandTem = graphArgs.operands[i];
356         tensorDesc = createTensorDesc(operandTem.shape.data(),
357                                       (uint32_t) operandTem.shape.size(),
358                                       operandTem.dataType, operandTem.format);
359         tensorDescVec.emplace_back(tensorDesc);
360         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
361         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
362 
363         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
364             graphArgs.paramIndices.end()) {
365             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000+i, operandTem.data, 0));
366         }
367     }
368 
369     FreeTensorDescVec(tensorDescVec);
370     Free(model, nullptr, nullptr);
371 }
372 
373 /**
374  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_01
375  * @tc.desc: 设置输入输出,inputIndices为nullptr
376  * @tc.type: FUNC
377  */
378 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_01, Function | MediumTest | Level2)
379 {
380     OH_NNModel *model = OH_NNModel_Construct();
381     EXPECT_NE(nullptr, model);
382 
383     SwishModel1 swishModel;
384     OHNNGraphArgs graphArgs = swishModel.graphArgs;
385     graphArgs.specifyIO = false;
386     graphArgs.build = false;
387     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
388 
389     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
390     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
391     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices));
392 
393     Free(model, nullptr, nullptr);
394 }
395 
396 /**
397  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_02
398  * @tc.desc: 设置输入输出,inputindices中data为nullptr
399  * @tc.type: FUNC
400  */
401 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_02, Function | MediumTest | Level2)
402 {
403     OH_NNModel *model = OH_NNModel_Construct();
404     EXPECT_NE(nullptr, model);
405 
406     SwishModel1 swishModel;
407     OHNNGraphArgs graphArgs = swishModel.graphArgs;
408     graphArgs.specifyIO = false;
409     graphArgs.build = false;
410     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
411 
412     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
413     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
414     inputIndices.data = nullptr;
415     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
416 
417     Free(model, nullptr, nullptr);
418 }
419 
420 /**
421  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_03
422  * @tc.desc: 设置输入输出,inputindices中data对应序号不存在
423  * @tc.type: FUNC
424  */
425 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_03, Function | MediumTest | Level2)
426 {
427     OH_NNModel *model = OH_NNModel_Construct();
428     EXPECT_NE(nullptr, model);
429 
430     SwishModel1 swishModel;
431     OHNNGraphArgs graphArgs = swishModel.graphArgs;
432     graphArgs.specifyIO = false;
433     graphArgs.build = false;
434     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
435 
436     graphArgs.inputIndices = {100000};
437     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
438     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
439     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
440 
441     Free(model, nullptr, nullptr);
442 }
443 
444 /**
445  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_04
446  * @tc.desc: 设置输入输出,inputindices中size为0
447  * @tc.type: FUNC
448  */
449 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_04, Function | MediumTest | Level2)
450 {
451     OH_NNModel *model = OH_NNModel_Construct();
452     EXPECT_NE(nullptr, model);
453 
454     SwishModel1 swishModel;
455     OHNNGraphArgs graphArgs = swishModel.graphArgs;
456     graphArgs.specifyIO = false;
457     graphArgs.build = false;
458     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
459 
460     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
461     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
462     inputIndices.size = 0;
463     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
464 
465     Free(model, nullptr, nullptr);
466 }
467 
468 /**
469  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_05
470  * @tc.desc: 设置输入输出,outputindices为nullptr
471  * @tc.type: FUNC
472  */
473 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_05, Function | MediumTest | Level2)
474 {
475     OH_NNModel *model = OH_NNModel_Construct();
476     EXPECT_NE(nullptr, model);
477 
478     SwishModel1 swishModel;
479     OHNNGraphArgs graphArgs = swishModel.graphArgs;
480     graphArgs.specifyIO = false;
481     graphArgs.build = false;
482     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
483 
484     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
485     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
486     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr));
487 
488     Free(model, nullptr, nullptr);
489 }
490 
491 /**
492  * @tc.number : SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_06
493  * @tc.desc: 设置输入输出,outputindices中data为nullptr
494  * @tc.type: FUNC
495  */
496 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_06, Function | MediumTest | Level2)
497 {
498     OH_NNModel *model = OH_NNModel_Construct();
499     EXPECT_NE(nullptr, model);
500 
501     SwishModel1 swishModel;
502     OHNNGraphArgs graphArgs = swishModel.graphArgs;
503     graphArgs.addOperation = false;
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_Swish_Model_SpecifyInputsAndOutputs_07
518  * @tc.desc: 设置输入输出,outputindices中data对应序号不存在
519  * @tc.type: FUNC
520  */
521 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_07, Function | MediumTest | Level2)
522 {
523     OH_NNModel *model = OH_NNModel_Construct();
524     EXPECT_NE(nullptr, model);
525 
526     SwishModel1 swishModel;
527     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_SpecifyInputsAndOutputs_08
542  * @tc.desc: 设置输入输出,outputindices中size为0
543  * @tc.type: FUNC
544  */
545 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_SpecifyInputsAndOutputs_08, Function | MediumTest | Level2)
546 {
547     OH_NNModel *model = OH_NNModel_Construct();
548     EXPECT_NE(nullptr, model);
549 
550     SwishModel1 swishModel;
551     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_01
566  * @tc.desc: 添加算子,paramindices为nullptr
567  * @tc.type: FUNC
568  */
569 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_01, Function | MediumTest | Level2)
570 {
571     OH_NNModel *model = OH_NNModel_Construct();
572     EXPECT_NE(nullptr, model);
573 
574     SwishModel1 swishModel;
575     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_02
591  * @tc.desc: 添加算子,paramindices中data为nullptr
592  * @tc.type: FUNC
593  */
594 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_02, Function | MediumTest | Level1)
595 {
596     OH_NNModel *model = OH_NNModel_Construct();
597     EXPECT_NE(nullptr, model);
598 
599     SwishModel1 swishModel;
600     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_03
618  * @tc.desc: 添加算子,paramindices中data对应序号不存在
619  * @tc.type: FUNC
620  */
621 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_03, Function | MediumTest | Level2)
622 {
623     OH_NNModel *model = OH_NNModel_Construct();
624     EXPECT_NE(nullptr, model);
625 
626     SwishModel1 swishModel;
627     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_04
645  * @tc.desc: 添加算子,paramindices中size为0
646  * @tc.type: FUNC
647  */
648 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_04, Function | MediumTest | Level1)
649 {
650     OH_NNModel *model = OH_NNModel_Construct();
651     EXPECT_NE(nullptr, model);
652 
653     SwishModel1 swishModel;
654     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_05
672  * @tc.desc: 添加算子,inputindices为nullptr
673  * @tc.type: FUNC
674  */
675 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_05, Function | MediumTest | Level2)
676 {
677     OH_NNModel *model = OH_NNModel_Construct();
678     EXPECT_NE(nullptr, model);
679 
680     SwishModel1 swishModel;
681     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_06
697  * @tc.desc: 添加算子,inputindices中data为nullptr
698  * @tc.type: FUNC
699  */
700 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_06, Function | MediumTest | Level2)
701 {
702     OH_NNModel *model = OH_NNModel_Construct();
703     EXPECT_NE(nullptr, model);
704 
705     SwishModel1 swishModel;
706     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_07
724  * @tc.desc: 添加算子,inputindices中data对应序号不存在
725  * @tc.type: FUNC
726  */
727 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_07, Function | MediumTest | Level2)
728 {
729     OH_NNModel *model = OH_NNModel_Construct();
730     EXPECT_NE(nullptr, model);
731 
732     SwishModel1 swishModel;
733     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_08
751  * @tc.desc: 添加算子,inputindices中size为0
752  * @tc.type: FUNC
753  */
754 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_08, Function | MediumTest | Level2)
755 {
756     OH_NNModel *model = OH_NNModel_Construct();
757     EXPECT_NE(nullptr, model);
758 
759     SwishModel1 swishModel;
760     OHNNGraphArgs graphArgs = swishModel.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_Swish_Model_AddOperation_09
778  * @tc.desc: 添加算子,outputindices为nullptr
779  * @tc.type: FUNC
780  */
781 HWTEST_F(SwishTest, SUB_AI_NNRt_Func_North_Swish_Model_AddOperation_09, Function | MediumTest | Level2)
782 {
783     OH_NNModel *model = OH_NNModel_Construct();
784     EXPECT_NE(nullptr, model);
785 
786     SwishModel1 swishModel;
787     OHNNGraphArgs graphArgs = swishModel.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 }