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