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 ModTest : public testing::Test {};
24
25 struct ModModel1 {
26 const std::vector<int32_t> tensor_shape = {3};
27 int64_t input0Value[3] = {10, 20, 30};
28 int64_t input1Value[1] = {3};
29 int64_t outputValue[3] = {0};
30
31 OHNNOperandTest input0 = {OH_NN_INT64, OH_NN_TENSOR, tensor_shape, input0Value, 3*sizeof(int64_t)};
32 OHNNOperandTest input1 = {OH_NN_INT64, OH_NN_TENSOR, tensor_shape, input1Value, 3*sizeof(int64_t)};
33 OHNNOperandTest output = {OH_NN_INT64, OH_NN_TENSOR, tensor_shape, outputValue, 3*sizeof(int64_t)};
34 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_MOD,
35 .operands = {input0, input1, output},
36 .paramIndices = {},
37 .inputIndices = {0, 1},
38 .outputIndices = {2}};
39 };
40
41 struct ModModel2 {
42 const std::vector<int32_t> tensor_shape = {3};
43 bool input0Value[1] = {true};
44 int64_t input1Value[3] = {2, 3, 4};
45 int64_t outputValue[3] = {0};
46
47 OHNNOperandTest input0 = {OH_NN_BOOL, OH_NN_TENSOR, {1}, input0Value, sizeof(int64_t)};
48 OHNNOperandTest input1 = {OH_NN_INT64, OH_NN_TENSOR, tensor_shape, input1Value, 3*sizeof(int64_t)};
49 OHNNOperandTest output = {OH_NN_INT64, OH_NN_TENSOR, tensor_shape, outputValue, 3*sizeof(int64_t)};
50 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_MOD,
51 .operands = {input0, input1, output},
52 .paramIndices = {},
53 .inputIndices = {0, 1},
54 .outputIndices = {2}};
55 };
56
57 struct ModModel3 {
58 const std::vector<int32_t> tensor_shape = {1};
59 bool input0Value[1] = {true};
60 bool input1Value[1] = {true};
61 int64_t* outputValue = {};
62
63 OHNNOperandTest input0 = {OH_NN_BOOL, OH_NN_TENSOR, tensor_shape, input0Value, sizeof(int64_t)};
64 OHNNOperandTest input1 = {OH_NN_BOOL, OH_NN_TENSOR, tensor_shape, input1Value, sizeof(int64_t)};
65 OHNNOperandTest output = {OH_NN_INT64, OH_NN_TENSOR, tensor_shape, outputValue, sizeof(int64_t)};
66 OHNNGraphArgs graphArgs = {.operationType = OH_NN_OPS_MOD,
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_Mod_Build_01
75 * @tc.desc: ModModel1模型build测试
76 * @tc.type: FUNC
77 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_01, Function | MediumTest | Level1)78 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_01, Function | MediumTest | Level1)
79 {
80 OH_NNModel *model = OH_NNModel_Construct();
81 EXPECT_NE(nullptr, model);
82
83 ModModel1 modModel;
84 OHNNGraphArgs graphArgs = modModel.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_Mod_Build_02
104 * @tc.desc: ModModel2模型build测试
105 * @tc.type: FUNC
106 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_02, Function | MediumTest | Level1)107 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_02, Function | MediumTest | Level1)
108 {
109 OH_NNModel *model = OH_NNModel_Construct();
110 EXPECT_NE(nullptr, model);
111
112 ModModel2 modModel;
113 OHNNGraphArgs graphArgs = modModel.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_Mod_Build_03
133 * @tc.desc: ModModel3模型build测试
134 * @tc.type: FUNC
135 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_03, Function | MediumTest | Level1)136 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_03, Function | MediumTest | Level1)
137 {
138 OH_NNModel *model = OH_NNModel_Construct();
139 EXPECT_NE(nullptr, model);
140
141 ModModel3 modModel;
142 OHNNGraphArgs graphArgs = modModel.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_Mod_Build_04
162 * @tc.desc: ModModel1模型输入Tensor+1进行build测试
163 * @tc.type: FUNC
164 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_04, Function | MediumTest | Level2)165 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_04, Function | MediumTest | Level2)
166 {
167 OH_NNModel *model = OH_NNModel_Construct();
168 EXPECT_NE(nullptr, model);
169
170 ModModel2 modModel;
171 OHNNGraphArgs graphArgs = modModel.graphArgs;
172 graphArgs.operands = {modModel.input0, modModel.input1, modModel.input1, modModel.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_Mod_Build_05
182 * @tc.desc: ModModel1模型输出Tensor+1进行build测试
183 * @tc.type: FUNC
184 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_05, Function | MediumTest | Level2)185 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_05, Function | MediumTest | Level2)
186 {
187 OH_NNModel *model = OH_NNModel_Construct();
188 EXPECT_NE(nullptr, model);
189
190 ModModel2 modModel;
191 OHNNGraphArgs graphArgs = modModel.graphArgs;
192 graphArgs.operands = {modModel.input0, modModel.input1, modModel.output, modModel.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_Mod_Build_06
202 * @tc.desc: ModModel1模型传入非法参数进行build测试
203 * @tc.type: FUNC
204 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_06, Function | MediumTest | Level2)205 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Build_06, Function | MediumTest | Level2)
206 {
207 OH_NNModel *model = OH_NNModel_Construct();
208 EXPECT_NE(nullptr, model);
209
210 ModModel2 modModel;
211 OHNNGraphArgs graphArgs = modModel.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 = {modModel.input0, modModel.input1, modModel.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_Mod_Model_Finish_01
224 * @tc.desc: 模型构图,未添加操作数
225 * @tc.type: FUNC
226 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_Finish_01, Function | MediumTest | Level2)227 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_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_Mod_Model_Finish_02
240 * @tc.desc: 模型构图,未设置输入输出
241 * @tc.type: FUNC
242 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_Finish_02, Function | MediumTest | Level2)243 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_Finish_02, Function | MediumTest | Level2)
244 {
245 OH_NNModel *model = OH_NNModel_Construct();
246 EXPECT_NE(nullptr, model);
247
248 ModModel1 modModel;
249 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_Finish_03
258 * @tc.desc: 模型构图,设置输入输出,构图成功
259 * @tc.type: FUNC
260 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_Finish_03, Function | MediumTest | Level1)261 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_Finish_03, Function | MediumTest | Level1)
262 {
263 OH_NNModel *model = OH_NNModel_Construct();
264 EXPECT_NE(nullptr, model);
265
266 ModModel1 modModel;
267 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SetOperandValue_01
275 * @tc.desc: 设置操作数值,操作数不存在
276 * @tc.type: FUNC
277 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SetOperandValue_01, Function | MediumTest | Level2)278 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SetOperandValue_01, Function | MediumTest | Level2)
279 {
280 OH_NNModel *model = OH_NNModel_Construct();
281 EXPECT_NE(nullptr, model);
282
283 ModModel1 modModel;
284 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SetOperandValue_02
311 * @tc.desc: 设置操作数值,buufer为nullptr
312 * @tc.type: FUNC
313 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SetOperandValue_02, Function | MediumTest | Level2)314 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SetOperandValue_02, Function | MediumTest | Level2)
315 {
316 OH_NNModel *model = OH_NNModel_Construct();
317 EXPECT_NE(nullptr, model);
318
319 ModModel1 modModel;
320 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SetOperandValue_03
346 * @tc.desc: 设置操作数值,length为0
347 * @tc.type: FUNC
348 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SetOperandValue_03, Function | MediumTest | Level2)349 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SetOperandValue_03, Function | MediumTest | Level2)
350 {
351 OH_NNModel *model = OH_NNModel_Construct();
352 EXPECT_NE(nullptr, model);
353
354 ModModel1 modModel;
355 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SpecifyInputsAndOutputs_01
381 * @tc.desc: 设置输入输出,inputIndices为nullptr
382 * @tc.type: FUNC
383 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_01, Function | MediumTest | Level2)384 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_01, Function | MediumTest | Level2)
385 {
386 OH_NNModel *model = OH_NNModel_Construct();
387 EXPECT_NE(nullptr, model);
388
389 ModModel1 modModel;
390 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SpecifyInputsAndOutputs_02
404 * @tc.desc: 设置输入输出,inputindices中data为nullptr
405 * @tc.type: FUNC
406 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_02, Function | MediumTest | Level2)407 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_02, Function | MediumTest | Level2)
408 {
409 OH_NNModel *model = OH_NNModel_Construct();
410 EXPECT_NE(nullptr, model);
411
412 ModModel1 modModel;
413 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SpecifyInputsAndOutputs_03
428 * @tc.desc: 设置输入输出,inputindices中data对应序号不存在
429 * @tc.type: FUNC
430 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_03, Function | MediumTest | Level2)431 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_03, Function | MediumTest | Level2)
432 {
433 OH_NNModel *model = OH_NNModel_Construct();
434 EXPECT_NE(nullptr, model);
435
436 ModModel1 modModel;
437 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SpecifyInputsAndOutputs_04
452 * @tc.desc: 设置输入输出,inputindices中size为0
453 * @tc.type: FUNC
454 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_04, Function | MediumTest | Level2)455 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_04, Function | MediumTest | Level2)
456 {
457 OH_NNModel *model = OH_NNModel_Construct();
458 EXPECT_NE(nullptr, model);
459
460 ModModel1 modModel;
461 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SpecifyInputsAndOutputs_05
476 * @tc.desc: 设置输入输出,outputindices为nullptr
477 * @tc.type: FUNC
478 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_05, Function | MediumTest | Level2)479 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_05, Function | MediumTest | Level2)
480 {
481 OH_NNModel *model = OH_NNModel_Construct();
482 EXPECT_NE(nullptr, model);
483
484 ModModel1 modModel;
485 OHNNGraphArgs graphArgs = modModel.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_Mod_Model_SpecifyInputsAndOutputs_06
499 * @tc.desc: 设置输入输出,outputindices中data为nullptr
500 * @tc.type: FUNC
501 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_06, Function | MediumTest | Level2)502 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_06, Function | MediumTest | Level2)
503 {
504 OH_NNModel *model = OH_NNModel_Construct();
505 EXPECT_NE(nullptr, model);
506
507 ModModel1 modModel;
508 OHNNGraphArgs graphArgs = modModel.graphArgs;
509 graphArgs.specifyIO = false;
510 graphArgs.build = false;
511 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
512
513 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
514 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
515 outputIndices.data = nullptr;
516 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
517
518 Free(model, nullptr, nullptr);
519 }
520
521 /**
522 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_07
523 * @tc.desc: 设置输入输出,outputindices中data对应序号不存在
524 * @tc.type: FUNC
525 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_07, Function | MediumTest | Level2)526 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_07, Function | MediumTest | Level2)
527 {
528 OH_NNModel *model = OH_NNModel_Construct();
529 EXPECT_NE(nullptr, model);
530
531 ModModel1 modModel;
532 OHNNGraphArgs graphArgs = modModel.graphArgs;
533 graphArgs.specifyIO = false;
534 graphArgs.build = false;
535 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
536
537 graphArgs.outputIndices = {100000};
538 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
539 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
540 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
541
542 Free(model, nullptr, nullptr);
543 }
544
545 /**
546 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_08
547 * @tc.desc: 设置输入输出,outputindices中size为0
548 * @tc.type: FUNC
549 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_08, Function | MediumTest | Level2)550 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_SpecifyInputsAndOutputs_08, Function | MediumTest | Level2)
551 {
552 OH_NNModel *model = OH_NNModel_Construct();
553 EXPECT_NE(nullptr, model);
554
555 ModModel1 modModel;
556 OHNNGraphArgs graphArgs = modModel.graphArgs;
557 graphArgs.specifyIO = false;
558 graphArgs.build = false;
559 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
560
561 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
562 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
563 outputIndices.size = 0;
564 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
565
566 Free(model, nullptr, nullptr);
567 }
568
569 /**
570 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_01
571 * @tc.desc: 添加算子,paramindices为nullptr
572 * @tc.type: FUNC
573 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_01, Function | MediumTest | Level2)574 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_01, Function | MediumTest | Level2)
575 {
576 OH_NNModel *model = OH_NNModel_Construct();
577 EXPECT_NE(nullptr, model);
578
579 ModModel1 modModel;
580 OHNNGraphArgs graphArgs = modModel.graphArgs;
581 graphArgs.addOperation = false;
582 graphArgs.specifyIO = false;
583 graphArgs.build = false;
584 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
585
586 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
587 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
588 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
589 nullptr, &inputIndices, &outputIndices));
590
591 Free(model, nullptr, nullptr);
592 }
593
594 /**
595 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_02
596 * @tc.desc: 添加算子,paramindices中data为nullptr
597 * @tc.type: FUNC
598 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_02, Function | MediumTest | Level2)599 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_02, Function | MediumTest | Level2)
600 {
601 OH_NNModel *model = OH_NNModel_Construct();
602 EXPECT_NE(nullptr, model);
603
604 ModModel1 modModel;
605 OHNNGraphArgs graphArgs = modModel.graphArgs;
606 graphArgs.addOperation = false;
607 graphArgs.specifyIO = false;
608 graphArgs.build = false;
609 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
610
611 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
612 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
613 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
614 paramIndices.data = nullptr;
615 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
616 ¶mIndices, &inputIndices, &outputIndices));
617
618 Free(model, nullptr, nullptr);
619 }
620
621 /**
622 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_03
623 * @tc.desc: 添加算子,paramindices中data对应序号不存在
624 * @tc.type: FUNC
625 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_03, Function | MediumTest | Level2)626 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_03, Function | MediumTest | Level2)
627 {
628 OH_NNModel *model = OH_NNModel_Construct();
629 EXPECT_NE(nullptr, model);
630
631 ModModel1 modModel;
632 OHNNGraphArgs graphArgs = modModel.graphArgs;
633 graphArgs.addOperation = false;
634 graphArgs.specifyIO = false;
635 graphArgs.build = false;
636 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
637
638 graphArgs.paramIndices = {100000};
639 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
640 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
641 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
642 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
643 ¶mIndices, &inputIndices, &outputIndices));
644
645 Free(model, nullptr, nullptr);
646 }
647
648 /**
649 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_04
650 * @tc.desc: 添加算子,paramindices中size为0
651 * @tc.type: FUNC
652 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_04, Function | MediumTest | Level2)653 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_04, Function | MediumTest | Level2)
654 {
655 OH_NNModel *model = OH_NNModel_Construct();
656 EXPECT_NE(nullptr, model);
657
658 ModModel1 modModel;
659 OHNNGraphArgs graphArgs = modModel.graphArgs;
660 graphArgs.addOperation = false;
661 graphArgs.specifyIO = false;
662 graphArgs.build = false;
663 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
664
665 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
666 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
667 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
668 paramIndices.size = 0;
669 EXPECT_EQ(OH_NN_SUCCESS, OH_NNModel_AddOperation(model, graphArgs.operationType,
670 ¶mIndices, &inputIndices, &outputIndices));
671
672 Free(model, nullptr, nullptr);
673 }
674
675 /**
676 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_05
677 * @tc.desc: 添加算子,inputindices为nullptr
678 * @tc.type: FUNC
679 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_05, Function | MediumTest | Level2)680 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_05, Function | MediumTest | Level2)
681 {
682 OH_NNModel *model = OH_NNModel_Construct();
683 EXPECT_NE(nullptr, model);
684
685 ModModel1 modModel;
686 OHNNGraphArgs graphArgs = modModel.graphArgs;
687 graphArgs.addOperation = false;
688 graphArgs.specifyIO = false;
689 graphArgs.build = false;
690 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
691
692 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
693 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
694 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
695 ¶mIndices, nullptr, &outputIndices));
696
697 Free(model, nullptr, nullptr);
698 }
699
700 /**
701 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_06
702 * @tc.desc: 添加算子,inputindices中data为nullptr
703 * @tc.type: FUNC
704 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_06, Function | MediumTest | Level2)705 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_06, Function | MediumTest | Level2)
706 {
707 OH_NNModel *model = OH_NNModel_Construct();
708 EXPECT_NE(nullptr, model);
709
710 ModModel1 modModel;
711 OHNNGraphArgs graphArgs = modModel.graphArgs;
712 graphArgs.addOperation = false;
713 graphArgs.specifyIO = false;
714 graphArgs.build = false;
715 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
716
717 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
718 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
719 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
720 inputIndices.data = nullptr;
721 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
722 ¶mIndices, &inputIndices, &outputIndices));
723
724 Free(model, nullptr, nullptr);
725 }
726
727 /**
728 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_07
729 * @tc.desc: 添加算子,inputindices中data对应序号不存在
730 * @tc.type: FUNC
731 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_07, Function | MediumTest | Level2)732 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_07, Function | MediumTest | Level2)
733 {
734 OH_NNModel *model = OH_NNModel_Construct();
735 EXPECT_NE(nullptr, model);
736
737 ModModel1 modModel;
738 OHNNGraphArgs graphArgs = modModel.graphArgs;
739 graphArgs.addOperation = false;
740 graphArgs.specifyIO = false;
741 graphArgs.build = false;
742 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
743
744 graphArgs.inputIndices = {100000};
745 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
746 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
747 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
748 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
749 ¶mIndices, &inputIndices, &outputIndices));
750
751 Free(model, nullptr, nullptr);
752 }
753
754 /**
755 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_08
756 * @tc.desc: 添加算子,inputindices中size为0
757 * @tc.type: FUNC
758 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_08, Function | MediumTest | Level2)759 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_08, Function | MediumTest | Level2)
760 {
761 OH_NNModel *model = OH_NNModel_Construct();
762 EXPECT_NE(nullptr, model);
763
764 ModModel1 modModel;
765 OHNNGraphArgs graphArgs = modModel.graphArgs;
766 graphArgs.addOperation = false;
767 graphArgs.specifyIO = false;
768 graphArgs.build = false;
769 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
770
771 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
772 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
773 auto outputIndices = TransformUInt32Array(graphArgs.outputIndices);
774 inputIndices.size = 0;
775 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(model, graphArgs.operationType,
776 ¶mIndices, &inputIndices, &outputIndices));
777
778 Free(model, nullptr, nullptr);
779 }
780
781 /**
782 * @tc.number : SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_09
783 * @tc.desc: 添加算子,outputindices为nullptr
784 * @tc.type: FUNC
785 */
HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_09, Function | MediumTest | Level2)786 HWTEST_F(ModTest, SUB_AI_NNRt_Func_North_Mod_Model_AddOperation_09, Function | MediumTest | Level2)
787 {
788 OH_NNModel *model = OH_NNModel_Construct();
789 EXPECT_NE(nullptr, model);
790
791 ModModel1 modModel;
792 OHNNGraphArgs graphArgs = modModel.graphArgs;
793 graphArgs.addOperation = false;
794 graphArgs.specifyIO = false;
795 graphArgs.build = false;
796 EXPECT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
797
798 auto paramIndices = TransformUInt32Array(graphArgs.paramIndices);
799 auto inputIndices = TransformUInt32Array(graphArgs.inputIndices);
800 EXPECT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddOperation(nullptr, graphArgs.operationType,
801 ¶mIndices, &inputIndices, nullptr));
802
803 Free(model, nullptr, nullptr);
804 }