• 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 ReciprocalTest : public testing::Test {};
24 
25 struct ReciprocalModel1 {
26     const std::vector<int32_t> tensor_shape = {2, 2};
27     float inputValue[2][2] = {{1, 2}, {3, 4}};
28     float outputValue[2][2] = {0};
29 
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_RECIPROCAL,
33                                .operands = {input, output},
34                                .paramIndices = {},
35                                .inputIndices = {0},
36                                .outputIndices = {1}};
37 };
38 
39 struct ReciprocalModel2 {
40     const std::vector<int32_t> tensor_shape = {3};
41     float inputValue[3] = {-1, -2, -4};
42     float outputValue[3] = {0};
43 
44     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 3*sizeof(float)};
45     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 3*sizeof(float)};
46     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_RECIPROCAL,
47                                .operands = {input, output},
48                                .paramIndices = {},
49                                .inputIndices = {0},
50                                .outputIndices = {1}};
51 };
52 
53 struct ReciprocalModel3 {
54     const std::vector<int32_t> tensor_shape = {1};
55     bool inputValue[1] = {false};
56     float outputValue[1] = {0};
57 
58     OHNNOperandTest input = {OH_NN_BOOL, OH_NN_TENSOR, tensor_shape, inputValue, sizeof(bool)};
59     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, sizeof(float)};
60     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_RECIPROCAL,
61                                .operands = {input, output},
62                                .paramIndices = {},
63                                .inputIndices = {0},
64                                .outputIndices = {1}};
65 };
66 
67 /**
68  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Build_01
69  * @tc.desc: ReciprocalModel1模型build测试
70  * @tc.type: FUNC
71  */
72 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Build_01, Function | MediumTest | Level1)
73 {
74     OH_NNModel *model = OH_NNModel_Construct();
75     EXPECT_NE(nullptr, model);
76 
77     ReciprocalModel1 reciprocalModel;
78     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Build_02
98  * @tc.desc: ReciprocalModel2模型build测试
99  * @tc.type: FUNC
100  */
101 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Build_02, Function | MediumTest | Level1)
102 {
103     OH_NNModel *model = OH_NNModel_Construct();
104     EXPECT_NE(nullptr, model);
105 
106     ReciprocalModel2 reciprocalModel;
107     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Build_03
127  * @tc.desc: ReciprocalModel3模型build测试
128  * @tc.type: FUNC
129  */
130 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Build_03, Function | MediumTest | Level1)
131 {
132     OH_NNModel *model = OH_NNModel_Construct();
133     EXPECT_NE(nullptr, model);
134 
135     ReciprocalModel3 reciprocalModel;
136     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Build_04
156  * @tc.desc: ReciprocalModel1模型输入Tensor+1进行build测试
157  * @tc.type: FUNC
158  */
159 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Build_04, Function | MediumTest | Level2)
160 {
161     OH_NNModel *model = OH_NNModel_Construct();
162     EXPECT_NE(nullptr, model);
163 
164     ReciprocalModel1 reciprocalModel;
165     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
166     graphArgs.operands = {reciprocalModel.input, reciprocalModel.input, reciprocalModel.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_Reciprocal_Build_05
176  * @tc.desc: ReciprocalModel1模型输出Tensor+1进行build测试
177  * @tc.type: FUNC
178  */
179 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Build_05, Function | MediumTest | Level2)
180 {
181     OH_NNModel *model = OH_NNModel_Construct();
182     EXPECT_NE(nullptr, model);
183 
184     ReciprocalModel1 reciprocalModel;
185     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
186     graphArgs.operands = {reciprocalModel.input, reciprocalModel.output, reciprocalModel.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_Reciprocal_Build_06
196  * @tc.desc: ReciprocalModel1模型传入非法参数进行build测试
197  * @tc.type: FUNC
198  */
199 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Build_06, Function | MediumTest | Level2)
200 {
201     OH_NNModel *model = OH_NNModel_Construct();
202     EXPECT_NE(nullptr, model);
203 
204     ReciprocalModel1 reciprocalModel;
205     OHNNGraphArgs graphArgs = reciprocalModel.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 = {reciprocalModel.input, reciprocalModel.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_Reciprocal_Model_Finish_01
218  * @tc.desc: 模型构图,未添加操作数
219  * @tc.type: FUNC
220  */
221 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_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_Reciprocal_Model_Finish_02
234  * @tc.desc: 模型构图,未设置输入输出
235  * @tc.type: FUNC
236  */
237 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_Finish_02, Function | MediumTest | Level2)
238 {
239     OH_NNModel *model = OH_NNModel_Construct();
240     EXPECT_NE(nullptr, model);
241 
242     ReciprocalModel1 reciprocalModel;
243     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Model_Finish_03
252  * @tc.desc: 模型构图,设置输入输出,构图成功
253  * @tc.type: FUNC
254  */
255 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_Finish_03, Function | MediumTest | Level1)
256 {
257     OH_NNModel *model = OH_NNModel_Construct();
258     EXPECT_NE(nullptr, model);
259 
260     ReciprocalModel1 reciprocalModel;
261     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Model_SetOperandValue_01
269  * @tc.desc: 设置操作数值,操作数不存在
270  * @tc.type: FUNC
271  */
272 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SetOperandValue_01, Function | MediumTest | Level2)
273 {
274     OH_NNModel *model = OH_NNModel_Construct();
275     EXPECT_NE(nullptr, model);
276 
277     ReciprocalModel1 reciprocalModel;
278     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Model_SetOperandValue_02
305  * @tc.desc: 设置操作数值,buufer为nullptr
306  * @tc.type: FUNC
307  */
308 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SetOperandValue_02, Function | MediumTest | Level2)
309 {
310     OH_NNModel *model = OH_NNModel_Construct();
311     EXPECT_NE(nullptr, model);
312 
313     ReciprocalModel1 reciprocalModel;
314     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Model_SetOperandValue_03
340  * @tc.desc: 设置操作数值,length为0
341  * @tc.type: FUNC
342  */
343 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SetOperandValue_03, Function | MediumTest | Level2)
344 {
345     OH_NNModel *model = OH_NNModel_Construct();
346     EXPECT_NE(nullptr, model);
347 
348     ReciprocalModel1 reciprocalModel;
349     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Model_SpecifyInputsAndOutputs_01
375  * @tc.desc: 设置输入输出,inputIndices为nullptr
376  * @tc.type: FUNC
377  */
378 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_01,
379          Function | MediumTest | Level2)
380 {
381     OH_NNModel *model = OH_NNModel_Construct();
382     EXPECT_NE(nullptr, model);
383 
384     ReciprocalModel1 reciprocalModel;
385     OHNNGraphArgs graphArgs = reciprocalModel.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_Reciprocal_Model_SpecifyInputsAndOutputs_02
399  * @tc.desc: 设置输入输出,inputindices中data为nullptr
400  * @tc.type: FUNC
401  */
402 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_02,
403          Function | MediumTest | Level2)
404 {
405     OH_NNModel *model = OH_NNModel_Construct();
406     EXPECT_NE(nullptr, model);
407 
408     ReciprocalModel1 reciprocalModel;
409     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
410     graphArgs.specifyIO = false;
411     graphArgs.build = false;
412     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
413 
414     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
415     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
416     inputIndices.data = nullptr;
417     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
418 
419     Free(model, nullptr, nullptr);
420 }
421 
422 /**
423  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_03
424  * @tc.desc: 设置输入输出,inputindices中data对应序号不存在
425  * @tc.type: FUNC
426  */
427 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_03,
428          Function | MediumTest | Level2)
429 {
430     OH_NNModel *model = OH_NNModel_Construct();
431     EXPECT_NE(nullptr, model);
432 
433     ReciprocalModel1 reciprocalModel;
434     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
435     graphArgs.specifyIO = false;
436     graphArgs.build = false;
437     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
438 
439     graphArgs.inputIndices = {100000};
440     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
441     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
442     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
443 
444     Free(model, nullptr, nullptr);
445 }
446 
447 /**
448  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_04
449  * @tc.desc: 设置输入输出,inputindices中size为0
450  * @tc.type: FUNC
451  */
452 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_04,
453          Function | MediumTest | Level2)
454 {
455     OH_NNModel *model = OH_NNModel_Construct();
456     EXPECT_NE(nullptr, model);
457 
458     ReciprocalModel1 reciprocalModel;
459     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
460     graphArgs.specifyIO = false;
461     graphArgs.build = false;
462     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
463 
464     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
465     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
466     inputIndices.size = 0;
467     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
468 
469     Free(model, nullptr, nullptr);
470 }
471 
472 /**
473  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_05
474  * @tc.desc: 设置输入输出,outputindices为nullptr
475  * @tc.type: FUNC
476  */
477 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_05,
478          Function | MediumTest | Level2)
479 {
480     OH_NNModel *model = OH_NNModel_Construct();
481     EXPECT_NE(nullptr, model);
482 
483     ReciprocalModel1 reciprocalModel;
484     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
485     graphArgs.specifyIO = false;
486     graphArgs.build = false;
487     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
488 
489     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
490     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
491     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr));
492 
493     Free(model, nullptr, nullptr);
494 }
495 
496 /**
497  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_06
498  * @tc.desc: 设置输入输出,outputindices中data为nullptr
499  * @tc.type: FUNC
500  */
501 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_06,
502          Function | MediumTest | Level2)
503 {
504     OH_NNModel *model = OH_NNModel_Construct();
505     EXPECT_NE(nullptr, model);
506 
507     ReciprocalModel1 reciprocalModel;
508     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
509     graphArgs.specifyIO = false;
510     graphArgs.build = false;
511     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
512 
513     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
514     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
515     outputIndices.data = nullptr;
516     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
517 
518     Free(model, nullptr, nullptr);
519 }
520 
521 /**
522  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_07
523  * @tc.desc: 设置输入输出,outputindices中data对应序号不存在
524  * @tc.type: FUNC
525  */
526 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_07,
527          Function | MediumTest | Level2)
528 {
529     OH_NNModel *model = OH_NNModel_Construct();
530     EXPECT_NE(nullptr, model);
531 
532     ReciprocalModel1 reciprocalModel;
533     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
534     graphArgs.specifyIO = false;
535     graphArgs.build = false;
536     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
537 
538     graphArgs.outputIndices = {100000};
539     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
540     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
541     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
542 
543     Free(model, nullptr, nullptr);
544 }
545 
546 /**
547  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_08
548  * @tc.desc: 设置输入输出,outputindices中size为0
549  * @tc.type: FUNC
550  */
551 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_SpecifyInputsAndOutputs_08,
552          Function | MediumTest | Level2)
553 {
554     OH_NNModel *model = OH_NNModel_Construct();
555     EXPECT_NE(nullptr, model);
556 
557     ReciprocalModel1 reciprocalModel;
558     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
559     graphArgs.specifyIO = false;
560     graphArgs.build = false;
561     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
562 
563     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
564     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
565     outputIndices.size = 0;
566     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
567 
568     Free(model, nullptr, nullptr);
569 }
570 
571 /**
572  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_01
573  * @tc.desc: 添加算子,paramindices为nullptr
574  * @tc.type: FUNC
575  */
576 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_01, Function | MediumTest | Level2)
577 {
578     OH_NNModel *model = OH_NNModel_Construct();
579     EXPECT_NE(nullptr, model);
580 
581     ReciprocalModel1 reciprocalModel;
582     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
583     graphArgs.addOperation = false;
584     graphArgs.specifyIO = false;
585     graphArgs.build = false;
586     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
587 
588     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
589     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
590     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
591                                                                nullptr, &inputIndices, &outputIndices));
592 
593     Free(model, nullptr, nullptr);
594 }
595 
596 /**
597  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_02
598  * @tc.desc: 添加算子,paramindices中data为nullptr
599  * @tc.type: FUNC
600  */
601 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_02, Function | MediumTest | Level1)
602 {
603     OH_NNModel *model = OH_NNModel_Construct();
604     EXPECT_NE(nullptr, model);
605 
606     ReciprocalModel1 reciprocalModel;
607     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
608     graphArgs.addOperation = false;
609     graphArgs.specifyIO = false;
610     graphArgs.build = false;
611     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
612 
613     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
614     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
615     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
616     paramIndices.data = nullptr;
617     EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
618                                                      &paramIndices, &inputIndices, &outputIndices));
619 
620     Free(model, nullptr, nullptr);
621 }
622 
623 /**
624  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_03
625  * @tc.desc: 添加算子,paramindices中data对应序号不存在
626  * @tc.type: FUNC
627  */
628 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_03, Function | MediumTest | Level2)
629 {
630     OH_NNModel *model = OH_NNModel_Construct();
631     EXPECT_NE(nullptr, model);
632 
633     ReciprocalModel1 reciprocalModel;
634     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
635     graphArgs.addOperation = false;
636     graphArgs.specifyIO = false;
637     graphArgs.build = false;
638     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
639 
640     graphArgs.paramIndices = {100000};
641     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
642     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
643     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
644     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
645                                                                &paramIndices, &inputIndices, &outputIndices));
646 
647     Free(model, nullptr, nullptr);
648 }
649 
650 /**
651  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_04
652  * @tc.desc: 添加算子,paramindices中size为0
653  * @tc.type: FUNC
654  */
655 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_04, Function | MediumTest | Level1)
656 {
657     OH_NNModel *model = OH_NNModel_Construct();
658     EXPECT_NE(nullptr, model);
659 
660     ReciprocalModel1 reciprocalModel;
661     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
662     graphArgs.addOperation = false;
663     graphArgs.specifyIO = false;
664     graphArgs.build = false;
665     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
666 
667     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
668     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
669     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
670     paramIndices.size = 0;
671     EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
672                                                      &paramIndices, &inputIndices, &outputIndices));
673 
674     Free(model, nullptr, nullptr);
675 }
676 
677 /**
678  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_05
679  * @tc.desc: 添加算子,inputindices为nullptr
680  * @tc.type: FUNC
681  */
682 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_05, Function | MediumTest | Level2)
683 {
684     OH_NNModel *model = OH_NNModel_Construct();
685     EXPECT_NE(nullptr, model);
686 
687     ReciprocalModel1 reciprocalModel;
688     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
689     graphArgs.addOperation = false;
690     graphArgs.specifyIO = false;
691     graphArgs.build = false;
692     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
693 
694     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
695     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
696     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
697                                                                &paramIndices, nullptr, &outputIndices));
698 
699     Free(model, nullptr, nullptr);
700 }
701 
702 /**
703  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_06
704  * @tc.desc: 添加算子,inputindices中data为nullptr
705  * @tc.type: FUNC
706  */
707 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_06, Function | MediumTest | Level2)
708 {
709     OH_NNModel *model = OH_NNModel_Construct();
710     EXPECT_NE(nullptr, model);
711 
712     ReciprocalModel1 reciprocalModel;
713     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
714     graphArgs.addOperation = false;
715     graphArgs.specifyIO = false;
716     graphArgs.build = false;
717     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
718 
719     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
720     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
721     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
722     inputIndices.data = nullptr;
723     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
724                                                                &paramIndices, &inputIndices, &outputIndices));
725 
726     Free(model, nullptr, nullptr);
727 }
728 
729 /**
730  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_07
731  * @tc.desc: 添加算子,inputindices中data对应序号不存在
732  * @tc.type: FUNC
733  */
734 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_07, Function | MediumTest | Level2)
735 {
736     OH_NNModel *model = OH_NNModel_Construct();
737     EXPECT_NE(nullptr, model);
738 
739     ReciprocalModel1 reciprocalModel;
740     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
741     graphArgs.addOperation = false;
742     graphArgs.specifyIO = false;
743     graphArgs.build = false;
744     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
745 
746     graphArgs.inputIndices = {100000};
747     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
748     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
749     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
750     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
751                                                                &paramIndices, &inputIndices, &outputIndices));
752 
753     Free(model, nullptr, nullptr);
754 }
755 
756 /**
757  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_08
758  * @tc.desc: 添加算子,inputindices中size为0
759  * @tc.type: FUNC
760  */
761 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_08, Function | MediumTest | Level2)
762 {
763     OH_NNModel *model = OH_NNModel_Construct();
764     EXPECT_NE(nullptr, model);
765 
766     ReciprocalModel1 reciprocalModel;
767     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
768     graphArgs.addOperation = false;
769     graphArgs.specifyIO = false;
770     graphArgs.build = false;
771     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
772 
773     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
774     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
775     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
776     inputIndices.size = 0;
777     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
778                                                                &paramIndices, &inputIndices, &outputIndices));
779 
780     Free(model, nullptr, nullptr);
781 }
782 
783 /**
784  * @tc.number : SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_09
785  * @tc.desc: 添加算子,outputindices为nullptr
786  * @tc.type: FUNC
787  */
788 HWTEST_F(ReciprocalTest, SUB_AI_NNRt_Func_North_Reciprocal_Model_AddOperation_09, Function | MediumTest | Level2)
789 {
790     OH_NNModel *model = OH_NNModel_Construct();
791     EXPECT_NE(nullptr, model);
792 
793     ReciprocalModel1 reciprocalModel;
794     OHNNGraphArgs graphArgs = reciprocalModel.graphArgs;
795     graphArgs.addOperation = false;
796     graphArgs.specifyIO = false;
797     graphArgs.build = false;
798     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
799 
800     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
801     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
802     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType,
803                                                                &paramIndices, &inputIndices, nullptr));
804 
805     Free(model, nullptr, nullptr);
806 }