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