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