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