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