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