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