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