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