• 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 SquareTest : public testing::Test {};
24 
25 struct SquareModel1 {
26     const std::vector<int32_t> tensor_shape = {5};
27     float inputValue[5] = {1, 0, 3, -4, -5};
28     float outputValue[5] = {0};
29 
30     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 5*sizeof(float)};
31     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 5*sizeof(float)};
32     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SQUARE,
33                                .operands = {input, output},
34                                .paramIndices = {},
35                                .inputIndices = {0},
36                                .outputIndices = {1}};
37 };
38 
39 
40 struct SquareModel2 {
41     const std::vector<int32_t> tensor_shape = {};
42     float* inputValue = {};
43     float* outputValue = {};
44 
45     OHNNOperandTest input = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, inputValue, 0*sizeof(float)};
46     OHNNOperandTest output = {OH_NN_FLOAT32, OH_NN_TENSOR, tensor_shape, outputValue, 0*sizeof(float)};
47     OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_SQUARE,
48                                .operands = {input, output},
49                                .paramIndices = {},
50                                .inputIndices = {0},
51                                .outputIndices = {1}};
52 };
53 
54 /**
55  * @tc.number : SUB_AI_NNRt_Func_North_Square_Build_01
56  * @tc.desc: SquareModel1模型build测试
57  * @tc.type: FUNC
58  */
59 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Build_01, Function | MediumTest | Level1)
60 {
61     OH_NNModel *model = OH_NNModel_Construct();
62     EXPECT_NE(nullptr, model);
63 
64     SquareModel1 squareModel;
65     OHNNGraphArgs graphArgs = squareModel.graphArgs;
66     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
67 
68     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
69     EXPECT_NE(nullptr, compilation);
70 
71     OHNNCompileParam compileParam{
72         .performanceMode = OH_NN_PERFORMANCE_HIGH,
73         .priority = OH_NN_PRIORITY_HIGH,
74     };
75     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
76 
77     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
78     EXPECT_NE(nullptr, executor);
79 
80     Free(model, compilation, executor);
81 }
82 
83 /**
84  * @tc.number : SUB_AI_NNRt_Func_North_Square_Build_02
85  * @tc.desc: SquareModel2模型build测试
86  * @tc.type: FUNC
87  */
88 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Build_02, Function | MediumTest | Level1)
89 {
90     OH_NNModel *model = OH_NNModel_Construct();
91     EXPECT_NE(nullptr, model);
92 
93     SquareModel2 squareModel;
94     OHNNGraphArgs graphArgs = squareModel.graphArgs;
95     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
96 
97     OH_NNCompilation *compilation = OH_NNCompilation_Construct(model);
98     EXPECT_NE(nullptr, compilation);
99 
100     OHNNCompileParam compileParam{
101         .performanceMode = OH_NN_PERFORMANCE_HIGH,
102         .priority = OH_NN_PRIORITY_HIGH,
103     };
104     EXPECT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation, compileParam));
105 
106     OH_NNExecutor *executor = OH_NNExecutor_Construct(compilation);
107     EXPECT_NE(nullptr, executor);
108 
109     Free(model, compilation, executor);
110 }
111 
112 /**
113  * @tc.number : SUB_AI_NNRt_Func_North_Square_Build_03
114  * @tc.desc: SquareModel1模型输入Tensor+1进行build测试
115  * @tc.type: FUNC
116  */
117 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Build_03, Function | MediumTest | Level2)
118 {
119     OH_NNModel *model = OH_NNModel_Construct();
120     EXPECT_NE(nullptr, model);
121 
122     SquareModel1 squareModel;
123     OHNNGraphArgs graphArgs = squareModel.graphArgs;
124     graphArgs.operands = {squareModel.input, squareModel.input, squareModel.output};
125     graphArgs.inputIndices = {0, 1};
126     graphArgs.outputIndices = {2};
127     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
128 
129     Free(model, nullptr, nullptr);
130 }
131 
132 /**
133  * @tc.number : SUB_AI_NNRt_Func_North_Square_Build_04
134  * @tc.desc: SquareModel1模型输出Tensor+1进行build测试
135  * @tc.type: FUNC
136  */
137 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Build_04, Function | MediumTest | Level2)
138 {
139     OH_NNModel *model = OH_NNModel_Construct();
140     EXPECT_NE(nullptr, model);
141 
142     SquareModel1 squareModel;
143     OHNNGraphArgs graphArgs = squareModel.graphArgs;
144     graphArgs.operands = {squareModel.input, squareModel.output, squareModel.output};
145     graphArgs.inputIndices = {0};
146     graphArgs.outputIndices = {1, 2};
147     EXPECT_EQ(OH_NN_INVALID_PARAMETER, BuildSingleOpGraph(model, graphArgs));
148 
149     Free(model, nullptr, nullptr);
150 }
151 
152 /**
153  * @tc.number : SUB_AI_NNRt_Func_North_Square_Build_05
154  * @tc.desc: SquareModel1模型传入非法参数进行build测试
155  * @tc.type: FUNC
156  */
157 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Build_05, Function | MediumTest | Level2)
158 {
159     OH_NNModel *model = OH_NNModel_Construct();
160     EXPECT_NE(nullptr, model);
161 
162     SquareModel1 squareModel;
163     OHNNGraphArgs graphArgs = squareModel.graphArgs;
164 
165     int8_t activationValue = OH_NN_FUSED_NONE;
166     OHNNOperandTest activation = {OH_NN_INT8, OH_NN_ADD_ACTIVATIONTYPE, {}, &activationValue, sizeof(int8_t)};
167     graphArgs.operands = {squareModel.input, squareModel.output, activation};
168     graphArgs.paramIndices = {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_Square_Model_Finish_01
176  * @tc.desc: 模型构图,未添加操作数
177  * @tc.type: FUNC
178  */
179 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_Finish_01, Function | MediumTest | Level2)
180 {
181     OH_NNModel *model = OH_NNModel_Construct();
182     EXPECT_NE(nullptr, model);
183 
184     OHNNGraphArgs graphArgs;
185     EXPECT_EQ(OH_NN_INVALID_PARAMETER, SingleModelBuildEndStep(model, graphArgs));
186 
187     Free(model, nullptr, nullptr);
188 }
189 
190 /**
191  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_Finish_02
192  * @tc.desc: 模型构图,未设置输入输出
193  * @tc.type: FUNC
194  */
195 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_Finish_02, Function | MediumTest | Level2)
196 {
197     OH_NNModel *model = OH_NNModel_Construct();
198     EXPECT_NE(nullptr, model);
199 
200     SquareModel1 squareModel;
201     OHNNGraphArgs graphArgs = squareModel.graphArgs;
202     graphArgs.specifyIO = false;
203     EXPECT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs));
204 
205     Free(model, nullptr, nullptr);
206 }
207 
208 /**
209  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_Finish_03
210  * @tc.desc: 模型构图,设置输入输出,构图成功
211  * @tc.type: FUNC
212  */
213 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_Finish_03, Function | MediumTest | Level1)
214 {
215     OH_NNModel *model = OH_NNModel_Construct();
216     EXPECT_NE(nullptr, model);
217 
218     SquareModel1 squareModel;
219     OHNNGraphArgs graphArgs = squareModel.graphArgs;
220     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
221 
222     Free(model, nullptr, nullptr);
223 }
224 
225 /**
226  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SetOperandValue_01
227  * @tc.desc: 设置操作数值,操作数不存在
228  * @tc.type: FUNC
229  */
230 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SetOperandValue_01, Function | MediumTest | Level2)
231 {
232     OH_NNModel *model = OH_NNModel_Construct();
233     EXPECT_NE(nullptr, model);
234 
235     SquareModel1 squareModel;
236     OHNNGraphArgs graphArgs = squareModel.graphArgs;
237 
238     NN_TensorDesc* tensorDesc = nullptr;
239     std::vector<NN_TensorDesc*> tensorDescVec;
240 
241     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
242         const OHNNOperandTest &operandTem = graphArgs.operands[i];
243         tensorDesc = createTensorDesc(operandTem.shape.data(),
244                                       (uint32_t) operandTem.shape.size(),
245                                       operandTem.dataType, operandTem.format);
246         tensorDescVec.emplace_back(tensorDesc);
247         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
248         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
249 
250         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
251             graphArgs.paramIndices.end()) {
252             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(
253                 model, 1000+i, operandTem.data, operandTem.length));
254         }
255     }
256 
257     FreeTensorDescVec(tensorDescVec);
258     Free(model, nullptr, nullptr);
259 }
260 
261 /**
262  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SetOperandValue_02
263  * @tc.desc: 设置操作数值,buufer为nullptr
264  * @tc.type: FUNC
265  */
266 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SetOperandValue_02, Function | MediumTest | Level2)
267 {
268     OH_NNModel *model = OH_NNModel_Construct();
269     EXPECT_NE(nullptr, model);
270 
271     SquareModel1 squareModel;
272     OHNNGraphArgs graphArgs = squareModel.graphArgs;
273 
274     NN_TensorDesc* tensorDesc = nullptr;
275     std::vector<NN_TensorDesc*> tensorDescVec;
276 
277     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
278         const OHNNOperandTest &operandTem = graphArgs.operands[i];
279         tensorDesc = createTensorDesc(operandTem.shape.data(),
280                                       (uint32_t) operandTem.shape.size(),
281                                       operandTem.dataType, operandTem.format);
282         tensorDescVec.emplace_back(tensorDesc);
283         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
284         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
285 
286         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
287             graphArgs.paramIndices.end()) {
288             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, i, nullptr, operandTem.length));
289         }
290     }
291 
292     FreeTensorDescVec(tensorDescVec);
293     Free(model, nullptr, nullptr);
294 }
295 
296 /**
297  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SetOperandValue_03
298  * @tc.desc: 设置操作数值,length为0
299  * @tc.type: FUNC
300  */
301 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SetOperandValue_03, Function | MediumTest | Level2)
302 {
303     OH_NNModel *model = OH_NNModel_Construct();
304     EXPECT_NE(nullptr, model);
305 
306     SquareModel1 squareModel;
307     OHNNGraphArgs graphArgs = squareModel.graphArgs;
308 
309     NN_TensorDesc* tensorDesc = nullptr;
310     std::vector<NN_TensorDesc*> tensorDescVec;
311 
312     for (size_t i = 0; i < graphArgs.operands.size(); i++) {
313         const OHNNOperandTest &operandTem = graphArgs.operands[i];
314         tensorDesc = createTensorDesc(operandTem.shape.data(),
315                                       (uint32_t) operandTem.shape.size(),
316                                       operandTem.dataType, operandTem.format);
317         tensorDescVec.emplace_back(tensorDesc);
318         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
319         EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, i, operandTem.type));
320 
321         if (std::find(graphArgs.paramIndices.begin(), graphArgs.paramIndices.end(), i) !=
322             graphArgs.paramIndices.end()) {
323             EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000+i, operandTem.data, 0));
324         }
325     }
326 
327     FreeTensorDescVec(tensorDescVec);
328     Free(model, nullptr, nullptr);
329 }
330 
331 /**
332  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_01
333  * @tc.desc: 设置输入输出,inputIndices为nullptr
334  * @tc.type: FUNC
335  */
336 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_01, Function | MediumTest | Level2)
337 {
338     OH_NNModel *model = OH_NNModel_Construct();
339     EXPECT_NE(nullptr, model);
340 
341     SquareModel1 squareModel;
342     OHNNGraphArgs graphArgs = squareModel.graphArgs;
343     graphArgs.specifyIO = false;
344     graphArgs.build = false;
345     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
346 
347     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
348     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
349     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices));
350 
351     Free(model, nullptr, nullptr);
352 }
353 
354 /**
355  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_02
356  * @tc.desc: 设置输入输出,inputindices中data为nullptr
357  * @tc.type: FUNC
358  */
359 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_02, Function | MediumTest | Level2)
360 {
361     OH_NNModel *model = OH_NNModel_Construct();
362     EXPECT_NE(nullptr, model);
363 
364     SquareModel1 squareModel;
365     OHNNGraphArgs graphArgs = squareModel.graphArgs;
366     graphArgs.specifyIO = false;
367     graphArgs.build = false;
368     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
369 
370     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
371     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
372     inputIndices.data = nullptr;
373     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
374 
375     Free(model, nullptr, nullptr);
376 }
377 
378 /**
379  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_03
380  * @tc.desc: 设置输入输出,inputindices中data对应序号不存在
381  * @tc.type: FUNC
382  */
383 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_03, Function | MediumTest | Level2)
384 {
385     OH_NNModel *model = OH_NNModel_Construct();
386     EXPECT_NE(nullptr, model);
387 
388     SquareModel1 squareModel;
389     OHNNGraphArgs graphArgs = squareModel.graphArgs;
390     graphArgs.specifyIO = false;
391     graphArgs.build = false;
392     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
393 
394     graphArgs.inputIndices = {100000};
395     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
396     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
397     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
398 
399     Free(model, nullptr, nullptr);
400 }
401 
402 /**
403  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_04
404  * @tc.desc: 设置输入输出,inputindices中size为0
405  * @tc.type: FUNC
406  */
407 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_04, Function | MediumTest | Level2)
408 {
409     OH_NNModel *model = OH_NNModel_Construct();
410     EXPECT_NE(nullptr, model);
411 
412     SquareModel1 squareModel;
413     OHNNGraphArgs graphArgs = squareModel.graphArgs;
414     graphArgs.specifyIO = false;
415     graphArgs.build = false;
416     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
417 
418     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
419     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
420     inputIndices.size = 0;
421     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
422 
423     Free(model, nullptr, nullptr);
424 }
425 
426 /**
427  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_05
428  * @tc.desc: 设置输入输出,outputindices为nullptr
429  * @tc.type: FUNC
430  */
431 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_05, Function | MediumTest | Level2)
432 {
433     OH_NNModel *model = OH_NNModel_Construct();
434     EXPECT_NE(nullptr, model);
435 
436     SquareModel1 squareModel;
437     OHNNGraphArgs graphArgs = squareModel.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, &inputIndices, nullptr));
445 
446     Free(model, nullptr, nullptr);
447 }
448 
449 /**
450  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_06
451  * @tc.desc: 设置输入输出,outputindices中data为nullptr
452  * @tc.type: FUNC
453  */
454 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_06, Function | MediumTest | Level2)
455 {
456     OH_NNModel *model = OH_NNModel_Construct();
457     EXPECT_NE(nullptr, model);
458 
459     SquareModel1 squareModel;
460     OHNNGraphArgs graphArgs = squareModel.graphArgs;
461     graphArgs.specifyIO = false;
462     graphArgs.build = false;
463     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
464 
465     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
466     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
467     outputIndices.data = nullptr;
468     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
469 
470     Free(model, nullptr, nullptr);
471 }
472 
473 /**
474  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_07
475  * @tc.desc: 设置输入输出,outputindices中data对应序号不存在
476  * @tc.type: FUNC
477  */
478 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_07, Function | MediumTest | Level2)
479 {
480     OH_NNModel *model = OH_NNModel_Construct();
481     EXPECT_NE(nullptr, model);
482 
483     SquareModel1 squareModel;
484     OHNNGraphArgs graphArgs = squareModel.graphArgs;
485     graphArgs.specifyIO = false;
486     graphArgs.build = false;
487     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
488 
489     graphArgs.outputIndices = {100000};
490     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
491     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
492     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
493 
494     Free(model, nullptr, nullptr);
495 }
496 
497 /**
498  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_08
499  * @tc.desc: 设置输入输出,outputindices中size为0
500  * @tc.type: FUNC
501  */
502 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_SpecifyInputsAndOutputs_08, Function | MediumTest | Level2)
503 {
504     OH_NNModel *model = OH_NNModel_Construct();
505     EXPECT_NE(nullptr, model);
506 
507     SquareModel1 squareModel;
508     OHNNGraphArgs graphArgs = squareModel.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.size = 0;
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_Square_Model_AddOperation_01
523  * @tc.desc: 添加算子,paramindices为nullptr
524  * @tc.type: FUNC
525  */
526 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_01, Function | MediumTest | Level2)
527 {
528     OH_NNModel *model = OH_NNModel_Construct();
529     EXPECT_NE(nullptr, model);
530 
531     SquareModel1 squareModel;
532     OHNNGraphArgs graphArgs = squareModel.graphArgs;
533     graphArgs.addOperation = false;
534     graphArgs.specifyIO = false;
535     graphArgs.build = false;
536     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
537 
538     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
539     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
540     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
541                                                                nullptr, &inputIndices, &outputIndices));
542 
543     Free(model, nullptr, nullptr);
544 }
545 
546 /**
547  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_02
548  * @tc.desc: 添加算子,paramindices中data为nullptr
549  * @tc.type: FUNC
550  */
551 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_02, Function | MediumTest | Level2)
552 {
553     OH_NNModel *model = OH_NNModel_Construct();
554     EXPECT_NE(nullptr, model);
555 
556     SquareModel1 squareModel;
557     OHNNGraphArgs graphArgs = squareModel.graphArgs;
558     graphArgs.addOperation = false;
559     graphArgs.specifyIO = false;
560     graphArgs.build = false;
561     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
562 
563     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
564     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
565     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
566     paramIndices.data = nullptr;
567     EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
568                                                      &paramIndices, &inputIndices, &outputIndices));
569 
570     Free(model, nullptr, nullptr);
571 }
572 
573 /**
574  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_03
575  * @tc.desc: 添加算子,paramindices中data对应序号不存在
576  * @tc.type: FUNC
577  */
578 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_03, Function | MediumTest | Level2)
579 {
580     OH_NNModel *model = OH_NNModel_Construct();
581     EXPECT_NE(nullptr, model);
582 
583     SquareModel1 squareModel;
584     OHNNGraphArgs graphArgs = squareModel.graphArgs;
585     graphArgs.addOperation = false;
586     graphArgs.specifyIO = false;
587     graphArgs.build = false;
588     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
589 
590     graphArgs.paramIndices = {100000};
591     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
592     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
593     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
594     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
595                                                                &paramIndices, &inputIndices, &outputIndices));
596 
597     Free(model, nullptr, nullptr);
598 }
599 
600 /**
601  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_04
602  * @tc.desc: 添加算子,paramindices中size为0
603  * @tc.type: FUNC
604  */
605 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_04, Function | MediumTest | Level2)
606 {
607     OH_NNModel *model = OH_NNModel_Construct();
608     EXPECT_NE(nullptr, model);
609 
610     SquareModel1 squareModel;
611     OHNNGraphArgs graphArgs = squareModel.graphArgs;
612     graphArgs.addOperation = false;
613     graphArgs.specifyIO = false;
614     graphArgs.build = false;
615     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
616 
617     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
618     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
619     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
620     paramIndices.size = 0;
621     EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
622                                                      &paramIndices, &inputIndices, &outputIndices));
623 
624     Free(model, nullptr, nullptr);
625 }
626 
627 /**
628  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_05
629  * @tc.desc: 添加算子,inputindices为nullptr
630  * @tc.type: FUNC
631  */
632 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_05, Function | MediumTest | Level2)
633 {
634     OH_NNModel *model = OH_NNModel_Construct();
635     EXPECT_NE(nullptr, model);
636 
637     SquareModel1 squareModel;
638     OHNNGraphArgs graphArgs = squareModel.graphArgs;
639     graphArgs.addOperation = false;
640     graphArgs.specifyIO = false;
641     graphArgs.build = false;
642     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
643 
644     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
645     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
646     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
647                                                                &paramIndices, nullptr, &outputIndices));
648 
649     Free(model, nullptr, nullptr);
650 }
651 
652 /**
653  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_06
654  * @tc.desc: 添加算子,inputindices中data为nullptr
655  * @tc.type: FUNC
656  */
657 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_06, Function | MediumTest | Level2)
658 {
659     OH_NNModel *model = OH_NNModel_Construct();
660     EXPECT_NE(nullptr, model);
661 
662     SquareModel1 squareModel;
663     OHNNGraphArgs graphArgs = squareModel.graphArgs;
664     graphArgs.addOperation = false;
665     graphArgs.specifyIO = false;
666     graphArgs.build = false;
667     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
668 
669     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
670     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
671     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
672     inputIndices.data = nullptr;
673     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
674                                                                &paramIndices, &inputIndices, &outputIndices));
675 
676     Free(model, nullptr, nullptr);
677 }
678 
679 /**
680  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_07
681  * @tc.desc: 添加算子,inputindices中data对应序号不存在
682  * @tc.type: FUNC
683  */
684 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_07, Function | MediumTest | Level2)
685 {
686     OH_NNModel *model = OH_NNModel_Construct();
687     EXPECT_NE(nullptr, model);
688 
689     SquareModel1 squareModel;
690     OHNNGraphArgs graphArgs = squareModel.graphArgs;
691     graphArgs.addOperation = false;
692     graphArgs.specifyIO = false;
693     graphArgs.build = false;
694     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
695 
696     graphArgs.inputIndices = {100000};
697     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
698     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
699     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
700     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
701                                                                &paramIndices, &inputIndices, &outputIndices));
702 
703     Free(model, nullptr, nullptr);
704 }
705 
706 /**
707  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_08
708  * @tc.desc: 添加算子,inputindices中size为0
709  * @tc.type: FUNC
710  */
711 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_08, Function | MediumTest | Level2)
712 {
713     OH_NNModel *model = OH_NNModel_Construct();
714     EXPECT_NE(nullptr, model);
715 
716     SquareModel1 squareModel;
717     OHNNGraphArgs graphArgs = squareModel.graphArgs;
718     graphArgs.addOperation = false;
719     graphArgs.specifyIO = false;
720     graphArgs.build = false;
721     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
722 
723     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
724     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
725     auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
726     inputIndices.size = 0;
727     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
728                                                                &paramIndices, &inputIndices, &outputIndices));
729 
730     Free(model, nullptr, nullptr);
731 }
732 
733 /**
734  * @tc.number : SUB_AI_NNRt_Func_North_Square_Model_AddOperation_09
735  * @tc.desc: 添加算子,outputindices为nullptr
736  * @tc.type: FUNC
737  */
738 HWTEST_F(SquareTest, SUB_AI_NNRt_Func_North_Square_Model_AddOperation_09, Function | MediumTest | Level2)
739 {
740     OH_NNModel *model = OH_NNModel_Construct();
741     EXPECT_NE(nullptr, model);
742 
743     SquareModel1 squareModel;
744     OHNNGraphArgs graphArgs = squareModel.graphArgs;
745     graphArgs.addOperation = false;
746     graphArgs.specifyIO = false;
747     graphArgs.build = false;
748     EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
749 
750     auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
751     auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
752     EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType,
753                                                                &paramIndices, &inputIndices, nullptr));
754 
755     Free(model, nullptr, nullptr);
756 }