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