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