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