• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include <cmath>
16 #include <cstdio>
17 #include <vector>
18 #include <thread>
19 
20 #include "nnrt_utils.h"
21 #include "model.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::NeuralNetworkRuntime::Test;
25 using namespace OHOS::HDI::Nnrt::V1_0;
26 
27 namespace {
28 
29 class ModelTest : public testing::Test {
30 protected:
31     AddModel addModel;
32     OHNNGraphArgs graphArgs = addModel.graphArgs;
33     OHNNCompileParam compileParam;
34 };
35 
BuildAddTopKGraph(OH_NNModel * model)36 void BuildAddTopKGraph(OH_NNModel *model)
37 {
38     AddTopKModel addTopKModel;
39     OHNNGraphArgsMulti graphArgsMulti = addTopKModel.graphArgs;
40     ASSERT_EQ(OH_NN_SUCCESS, BuildMultiOpGraph(model, graphArgsMulti));
41 }
42 
BuildModel(OH_NNModel * model,const OHNNGraphArgs & graphArgs)43 void BuildModel(OH_NNModel *model, const OHNNGraphArgs &graphArgs)
44 {
45     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
46 }
47 
48 } // namespace
49 
50 /**
51  * @tc.number : SUB_AI_NNRt_Func_North_Model_CreateModel_0100
52  * @tc.name   : 创建模型实例,指针校验
53  * @tc.desc   : [C- SOFTWARE -0200]
54  */
55 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_CreateModel_0100, Function | MediumTest | Level0)
56 {
57     OH_NNModel *model = OH_NNModel_Construct();
58     ASSERT_NE(nullptr, model);
59 }
60 
61 /**
62  * @tc.number : SUB_AI_NNRt_Func_North_Model_CreateModel_0200
63  * @tc.name   : 创建多个模型实例,指针校验
64  * @tc.desc   : [C- SOFTWARE -0200]
65  */
66 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_CreateModel_0200, Function | MediumTest | Level2)
67 {
68     OH_NNModel *model_first = OH_NNModel_Construct();
69     ASSERT_NE(nullptr, model_first);
70 
71     OH_NNModel *model_second = OH_NNModel_Construct();
72     ASSERT_NE(nullptr, model_second);
73 
74     OH_NNModel *model_third = OH_NNModel_Construct();
75     ASSERT_NE(nullptr, model_third);
76 
77     ASSERT_NE(model_first, model_second);
78     ASSERT_NE(model_first, model_third);
79     ASSERT_NE(model_second, model_third);
80     Free(model_first);
81     Free(model_second);
82     Free(model_third);
83 }
84 
85 /**
86  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperand_0100
87  * @tc.name   : 添加操作数值,model为nullptr
88  * @tc.desc   : [C- SOFTWARE -0200]
89  */
90 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperand_0100, Function | MediumTest | Level3)
91 {
92     int32_t dimensions[3]{3, 2, 2};
93     OH_NN_Tensor operand{OH_NN_FLOAT32, 3, dimensions, nullptr, OH_NN_TENSOR};
94     OH_NN_ReturnCode ret = OH_NNModel_AddTensor(nullptr, &operand);
95     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
96 }
97 
98 /**
99  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperand_0200
100  * @tc.name   : 添加操作数,operand为nullptr
101  * @tc.desc   : [C- SOFTWARE -0200]
102  */
103 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperand_0200, Function | MediumTest | Level3)
104 {
105     OH_NNModel *model = OH_NNModel_Construct();
106     ASSERT_NE(nullptr, model);
107 
108     OH_NN_ReturnCode ret = OH_NNModel_AddTensor(model, nullptr);
109     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
110     Free(model);
111 }
112 
113 /**
114  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperand_0300
115  * @tc.name   : 添加操作数,operand中dataType为100000
116  * @tc.desc   : [C- SOFTWARE -0200]
117  */
118 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperand_0300, Function | MediumTest | Level3)
119 {
120     OH_NNModel *model = OH_NNModel_Construct();
121     ASSERT_NE(nullptr, model);
122 
123     int32_t dimensions[3]{3, 2, 2};
124 
125     OH_NN_Tensor operand{static_cast<OH_NN_DataType>(100000), 3, dimensions, nullptr, OH_NN_TENSOR};
126     OH_NN_ReturnCode ret = OH_NNModel_AddTensor(model, &operand);
127     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
128     Free(model);
129 }
130 
131 /**
132  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperand_0400
133  * @tc.name   : 添加操作数,operand中type为100000
134  * @tc.desc   : [C- SOFTWARE -0200]
135  */
136 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperand_0400, Function | MediumTest | Level3)
137 {
138     OH_NNModel *model = OH_NNModel_Construct();
139     ASSERT_NE(nullptr, model);
140 
141     int32_t dimensions[3]{3, 2, 2};
142 
143     OH_NN_Tensor operand{OH_NN_FLOAT32, 3, dimensions, nullptr, static_cast<OH_NN_TensorType>(100000)};
144     OH_NN_ReturnCode ret = OH_NNModel_AddTensor(model, &operand);
145     EXPECT_EQ(OH_NN_INVALID_PARAMETER, ret);
146     Free(model);
147 }
148 
149 /**
150  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetOperandValue_0100
151  * @tc.name   : 设置操作数值,model为nullptr
152  * @tc.desc   : [C- SOFTWARE -0200]
153  */
154 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetOperandValue_0100, Function | MediumTest | Level3)
155 {
156     OH_NNModel *model = OH_NNModel_Construct();
157     ASSERT_NE(nullptr, model);
158 
159     int8_t activationValue{0};
160     int32_t dimensions[3]{3, 2, 2};
161     OH_NN_Tensor operand{OH_NN_FLOAT32, 3, dimensions, nullptr, OH_NN_TENSOR};
162     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensor(model, &operand));
163 
164     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
165               OH_NNModel_SetTensorData(nullptr, 1, (void *)&activationValue, sizeof(int8_t)));
166     Free(model);
167 }
168 
169 /**
170  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetOperandValue_0200
171  * @tc.name   : 设置操作数值,操作数不存在
172  * @tc.desc   : [C- SOFTWARE -0200]
173  */
174 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetOperandValue_0200, Function | MediumTest | Level3)
175 {
176     OH_NNModel *model = OH_NNModel_Construct();
177     ASSERT_NE(nullptr, model);
178 
179     int8_t activationValue{0};
180     int32_t dimensions[3]{3, 2, 2};
181     OH_NN_Tensor operand{OH_NN_FLOAT32, 3, dimensions, nullptr, OH_NN_TENSOR};
182     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensor(model, &operand));
183 
184     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
185               OH_NNModel_SetTensorData(model, 1000, (void *)&activationValue, sizeof(int8_t)));
186     Free(model);
187 }
188 
189 /**
190  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetOperandValue_0300
191  * @tc.name   : 设置操作数值,buffer为nullptr
192  * @tc.desc   : [C- SOFTWARE -0200]
193  */
194 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetOperandValue_0300, Function | MediumTest | Level3)
195 {
196     OH_NNModel *model = OH_NNModel_Construct();
197     ASSERT_NE(nullptr, model);
198 
199     int32_t dimensions[3]{3, 2, 2};
200     OH_NN_Tensor operand{OH_NN_FLOAT32, 3, dimensions, nullptr, OH_NN_TENSOR};
201     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensor(model, &operand));
202 
203     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1, nullptr, sizeof(int8_t)));
204     Free(model);
205 }
206 
207 /**
208  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetOperandValue_0400
209  * @tc.name   : 设置操作数值,length为0
210  * @tc.desc   : [C- SOFTWARE -0200]
211  */
212 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetOperandValue_0400, Function | MediumTest | Level3)
213 {
214     OH_NNModel *model = OH_NNModel_Construct();
215     ASSERT_NE(nullptr, model);
216 
217     int8_t activationValue{0};
218     int32_t dimensions[3]{3, 2, 2};
219     OH_NN_Tensor operand{OH_NN_FLOAT32, 3, dimensions, nullptr, OH_NN_TENSOR};
220     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensor(model, &operand));
221 
222     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1, (void *)&activationValue, 0));
223     Free(model);
224 }
225 
226 /**
227  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0100
228  * @tc.name   : 添加算子,model为nullptr
229  * @tc.desc   : [C- SOFTWARE -0200]
230  */
231 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0100, Function | MediumTest | Level3)
232 {
233     OH_NNModel *model = OH_NNModel_Construct();
234     ASSERT_NE(nullptr, model);
235     graphArgs.specifyIO = false;
236     graphArgs.build = false;
237     graphArgs.addOperation = false;
238     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
239     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
240                                    graphArgs.paramIndices.size()};
241     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
242                                    graphArgs.inputIndices.size()};
243     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
244                                     graphArgs.outputIndices.size()};
245     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
246               OH_NNModel_AddOperation(nullptr, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
247     Free(model);
248 }
249 
250 /**
251  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0200
252  * @tc.name   : 添加算子,paramIndices为nullptr
253  * @tc.desc   : [C- SOFTWARE -0200]
254  */
255 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0200, Function | MediumTest | Level3)
256 {
257     OH_NNModel *model = OH_NNModel_Construct();
258     ASSERT_NE(nullptr, model);
259     graphArgs.specifyIO = false;
260     graphArgs.build = false;
261     graphArgs.addOperation = false;
262     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
263 
264     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
265                                    graphArgs.inputIndices.size()};
266     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
267                                     graphArgs.outputIndices.size()};
268     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
269               OH_NNModel_AddOperation(model, graphArgs.operationType, nullptr, &inputIndices, &outputIndices));
270     Free(model);
271 }
272 
273 /**
274  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0300
275  * @tc.name   : 添加算子,paramIndices中data为nullptr
276  * @tc.desc   : [C- SOFTWARE -0200]
277  */
278 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0300, Function | MediumTest | Level3)
279 {
280     OH_NNModel *model = OH_NNModel_Construct();
281     ASSERT_NE(nullptr, model);
282     graphArgs.specifyIO = false;
283     graphArgs.build = false;
284     graphArgs.addOperation = false;
285     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
286     OH_NN_UInt32Array paramIndices{nullptr, graphArgs.paramIndices.size()};
287     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
288                                    graphArgs.inputIndices.size()};
289     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
290                                     graphArgs.outputIndices.size()};
291     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
292               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
293     Free(model);
294 }
295 
296 /**
297  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0400
298  * @tc.name   : 添加算子,paramIndices中data对应序号不存在
299  * @tc.desc   : [C- SOFTWARE -0200]
300  */
301 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0400, Function | MediumTest | Level3)
302 {
303     OH_NNModel *model = OH_NNModel_Construct();
304     ASSERT_NE(nullptr, model);
305     graphArgs.specifyIO = false;
306     graphArgs.build = false;
307     graphArgs.addOperation = false;
308     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
309     uint32_t paramIndicesValue{10};
310     OH_NN_UInt32Array paramIndices{&paramIndicesValue, graphArgs.paramIndices.size()};
311     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
312                                    graphArgs.inputIndices.size()};
313     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
314                                     graphArgs.outputIndices.size()};
315     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
316               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
317     Free(model);
318 }
319 
320 /**
321  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0500
322  * @tc.name   : 添加算子,paramIndices中size为0
323  * @tc.desc   : [C- SOFTWARE -0200]
324  */
325 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0500, Function | MediumTest | Level3)
326 {
327     OH_NNModel *model = OH_NNModel_Construct();
328     ASSERT_NE(nullptr, model);
329     graphArgs.specifyIO = false;
330     graphArgs.build = false;
331     graphArgs.addOperation = false;
332     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
333     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()), 0};
334     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
335                                    graphArgs.inputIndices.size()};
336     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
337                                     graphArgs.outputIndices.size()};
338     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
339               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
340     Free(model);
341 }
342 
343 /**
344  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0600
345  * @tc.name   : 添加算子,inputIndices为nullptr
346  * @tc.desc   : [C- SOFTWARE -0200]
347  */
348 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0600, Function | MediumTest | Level3)
349 {
350     OH_NNModel *model = OH_NNModel_Construct();
351     ASSERT_NE(nullptr, model);
352     graphArgs.specifyIO = false;
353     graphArgs.build = false;
354     graphArgs.addOperation = false;
355     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
356     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
357                                    graphArgs.paramIndices.size()};
358     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
359                                     graphArgs.outputIndices.size()};
360     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
361               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, nullptr, &outputIndices));
362     Free(model);
363 }
364 
365 /**
366  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0700
367  * @tc.name   : 添加算子,inputIndices中data为nullptr
368  * @tc.desc   : [C- SOFTWARE -0200]
369  */
370 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0700, Function | MediumTest | Level3)
371 {
372     OH_NNModel *model = OH_NNModel_Construct();
373     ASSERT_NE(nullptr, model);
374     graphArgs.specifyIO = false;
375     graphArgs.build = false;
376     graphArgs.addOperation = false;
377     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
378     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
379                                    graphArgs.paramIndices.size()};
380     OH_NN_UInt32Array inputIndices{nullptr, graphArgs.inputIndices.size()};
381     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
382                                     graphArgs.outputIndices.size()};
383     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
384               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
385     Free(model);
386 }
387 
388 /**
389  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0800
390  * @tc.name   : 添加算子,inputIndices中data对应序号不存在
391  * @tc.desc   : [C- SOFTWARE -0200]
392  */
393 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0800, Function | MediumTest | Level3)
394 {
395     OH_NNModel *model = OH_NNModel_Construct();
396     ASSERT_NE(nullptr, model);
397     graphArgs.specifyIO = false;
398     graphArgs.build = false;
399     graphArgs.addOperation = false;
400     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
401     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
402                                    graphArgs.paramIndices.size()};
403     uint32_t inputIndicesValue{10};
404     OH_NN_UInt32Array inputIndices{&inputIndicesValue, graphArgs.inputIndices.size()};
405     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
406                                     graphArgs.outputIndices.size()};
407     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
408               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
409     Free(model);
410 }
411 
412 /**
413  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_0900
414  * @tc.name   : 添加算子,inputIndices中size为0
415  * @tc.desc   : [C- SOFTWARE -0200]
416  */
417 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_0900, Function | MediumTest | Level3)
418 {
419     OH_NNModel *model = OH_NNModel_Construct();
420     ASSERT_NE(nullptr, model);
421     graphArgs.specifyIO = false;
422     graphArgs.build = false;
423     graphArgs.addOperation = false;
424     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
425     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
426                                    graphArgs.paramIndices.size()};
427     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()), 0};
428     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
429                                     graphArgs.outputIndices.size()};
430     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
431               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
432     Free(model);
433 }
434 
435 /**
436  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_1000
437  * @tc.name   : 添加算子,outputIndices为nullptr
438  * @tc.desc   : [C- SOFTWARE -0200]
439  */
440 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_1000, Function | MediumTest | Level3)
441 {
442     OH_NNModel *model = OH_NNModel_Construct();
443     ASSERT_NE(nullptr, model);
444     graphArgs.specifyIO = false;
445     graphArgs.build = false;
446     graphArgs.addOperation = false;
447     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
448     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
449                                    graphArgs.paramIndices.size()};
450     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()), 0};
451     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
452               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, nullptr));
453     Free(model);
454 }
455 
456 /**
457  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_1100
458  * @tc.name   : 添加算子,outputIndices中data为nullptr
459  * @tc.desc   : [C- SOFTWARE -0200]
460  */
461 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_1100, Function | MediumTest | Level3)
462 {
463     OH_NNModel *model = OH_NNModel_Construct();
464     ASSERT_NE(nullptr, model);
465     graphArgs.specifyIO = false;
466     graphArgs.build = false;
467     graphArgs.addOperation = false;
468     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
469     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
470                                    graphArgs.paramIndices.size()};
471     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
472                                    graphArgs.inputIndices.size()};
473     OH_NN_UInt32Array outputIndices{nullptr, graphArgs.outputIndices.size()};
474     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
475               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
476     Free(model);
477 }
478 
479 /**
480  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_1200
481  * @tc.name   : 添加算子,outputIndices中data对应序号不存在
482  * @tc.desc   : [C- SOFTWARE -0200]
483  */
484 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_1200, Function | MediumTest | Level3)
485 {
486     OH_NNModel *model = OH_NNModel_Construct();
487     ASSERT_NE(nullptr, model);
488     graphArgs.specifyIO = false;
489     graphArgs.build = false;
490     graphArgs.addOperation = false;
491     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
492     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
493                                    graphArgs.paramIndices.size()};
494     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
495                                    graphArgs.inputIndices.size()};
496     uint32_t outputIndicesValue{10};
497     OH_NN_UInt32Array outputIndices{&outputIndicesValue, graphArgs.outputIndices.size()};
498     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
499               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
500     Free(model);
501 }
502 
503 /**
504  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddOperation_1300
505  * @tc.name   : 添加算子,outputIndices中size为0
506  * @tc.desc   : [C- SOFTWARE -0200]
507  */
508 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddOperation_1300, Function | MediumTest | Level3)
509 {
510     OH_NNModel *model = OH_NNModel_Construct();
511     ASSERT_NE(nullptr, model);
512     graphArgs.specifyIO = false;
513     graphArgs.build = false;
514     graphArgs.addOperation = false;
515     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
516     OH_NN_UInt32Array paramIndices{const_cast<uint32_t *>(graphArgs.paramIndices.data()),
517                                    graphArgs.paramIndices.size()};
518     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
519                                    graphArgs.inputIndices.size()};
520     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()), 0};
521     ASSERT_EQ(OH_NN_INVALID_PARAMETER,
522               OH_NNModel_AddOperation(model, graphArgs.operationType, &paramIndices, &inputIndices, &outputIndices));
523     Free(model);
524 }
525 
526 /**
527  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0100
528  * @tc.name   : 设置输入输出,model为nullptr
529  * @tc.desc   : [C- SOFTWARE -0200]
530  */
531 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0100, Function | MediumTest | Level3)
532 {
533     OH_NNModel *model = OH_NNModel_Construct();
534     ASSERT_NE(nullptr, model);
535     graphArgs.specifyIO = false;
536     graphArgs.build = false;
537     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
538 
539     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
540                                    graphArgs.inputIndices.size()};
541     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
542                                     graphArgs.outputIndices.size()};
543     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(nullptr, &inputIndices, &outputIndices));
544     Free(model);
545 }
546 
547 /**
548  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0200
549  * @tc.name   : 设置输入输出,inputIndices为nullptr
550  * @tc.desc   : [C- SOFTWARE -0200]
551  */
552 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0200, Function | MediumTest | Level3)
553 {
554     OH_NNModel *model = OH_NNModel_Construct();
555     ASSERT_NE(nullptr, model);
556     graphArgs.specifyIO = false;
557     graphArgs.build = false;
558     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
559     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
560                                     graphArgs.outputIndices.size()};
561     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, nullptr, &outputIndices));
562     Free(model);
563 }
564 
565 /**
566  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0300
567  * @tc.name   : 设置输入输出,inputIndices中data为nullptr
568  * @tc.desc   : [C- SOFTWARE -0200]
569  */
570 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0300, Function | MediumTest | Level3)
571 {
572     OH_NNModel *model = OH_NNModel_Construct();
573     ASSERT_NE(nullptr, model);
574     graphArgs.specifyIO = false;
575     graphArgs.build = false;
576     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
577     OH_NN_UInt32Array inputIndices{nullptr, 2};
578     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
579                                     graphArgs.outputIndices.size()};
580     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
581     Free(model);
582 }
583 
584 /**
585  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0400
586  * @tc.name   : 设置输入输出,inputIndices中data对应序号不存在
587  * @tc.desc   : [C- SOFTWARE -0200]
588  */
589 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0400, Function | MediumTest | Level3)
590 {
591     OH_NNModel *model = OH_NNModel_Construct();
592     ASSERT_NE(nullptr, model);
593     graphArgs.specifyIO = false;
594     graphArgs.build = false;
595     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
596     uint32_t modelInputIndicesValue{5};
597     OH_NN_UInt32Array inputIndices{&modelInputIndicesValue, 1};
598 
599     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
600                                     graphArgs.outputIndices.size()};
601     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
602     Free(model);
603 }
604 
605 /**
606  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0500
607  * @tc.name   : 设置输入输出,inputIndices中size为0
608  * @tc.desc   : [C- SOFTWARE -0200]
609  */
610 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0500, Function | MediumTest | Level3)
611 {
612     OH_NNModel *model = OH_NNModel_Construct();
613     ASSERT_NE(nullptr, model);
614     graphArgs.specifyIO = false;
615     graphArgs.build = false;
616     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
617     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()), 0};
618     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()),
619                                     graphArgs.outputIndices.size()};
620 
621     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
622     Free(model);
623 }
624 
625 /**
626  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0600
627  * @tc.name   : 设置输入输出,outputIndices为空指针
628  * @tc.desc   : [C- SOFTWARE -0200]
629  */
630 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0600, Function | MediumTest | Level3)
631 {
632     OH_NNModel *model = OH_NNModel_Construct();
633     ASSERT_NE(nullptr, model);
634     graphArgs.specifyIO = false;
635     graphArgs.build = false;
636     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
637 
638     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
639                                    graphArgs.inputIndices.size()};
640     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, nullptr));
641     Free(model);
642 }
643 
644 /**
645  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0700
646  * @tc.name   : 设置输入输出,outputIndices中data为nullptr
647  * @tc.desc   : [C- SOFTWARE -0200]
648  */
649 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0700, Function | MediumTest | Level3)
650 {
651     OH_NNModel *model = OH_NNModel_Construct();
652     ASSERT_NE(nullptr, model);
653     graphArgs.specifyIO = false;
654     graphArgs.build = false;
655     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
656 
657     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
658                                    graphArgs.inputIndices.size()};
659     OH_NN_UInt32Array outputIndices{nullptr, 1};
660     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
661     Free(model);
662 }
663 
664 /**
665  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0800
666  * @tc.name   : 设置输入输出,outputIndices中data对应序号不存在
667  * @tc.desc   : [C- SOFTWARE -0200]
668  */
669 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0800, Function | MediumTest | Level3)
670 {
671     OH_NNModel *model = OH_NNModel_Construct();
672     ASSERT_NE(nullptr, model);
673     graphArgs.specifyIO = false;
674     graphArgs.build = false;
675     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
676 
677     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
678                                    graphArgs.inputIndices.size()};
679     uint32_t modelOutputIndicesValue{5};
680     OH_NN_UInt32Array outputIndices{&modelOutputIndicesValue, 1};
681     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
682     Free(model);
683 }
684 
685 /**
686  * @tc.number : SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0900
687  * @tc.name   : 设置输入输出,outputIndices中size为0
688  * @tc.desc   : [C- SOFTWARE -0200]
689  */
690 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SpecifyInputsAndOutputs_0900, Function | MediumTest | Level3)
691 {
692     OH_NNModel *model = OH_NNModel_Construct();
693     ASSERT_NE(nullptr, model);
694     graphArgs.specifyIO = false;
695     graphArgs.build = false;
696     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
697 
698     OH_NN_UInt32Array inputIndices{const_cast<uint32_t *>(graphArgs.inputIndices.data()),
699                                    graphArgs.inputIndices.size()};
700     OH_NN_UInt32Array outputIndices{const_cast<uint32_t *>(graphArgs.outputIndices.data()), 0};
701     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SpecifyInputsAndOutputs(model, &inputIndices, &outputIndices));
702     Free(model);
703 }
704 
705 /**
706  * @tc.number : SUB_AI_NNRt_Func_North_Model_Finish_0100
707  * @tc.name   : 模型构图,model为空指针
708  * @tc.desc   : [C- SOFTWARE -0200]
709  */
710 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_Finish_0100, Function | MediumTest | Level3)
711 {
712     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_Finish(nullptr));
713 }
714 
715 /**
716  * @tc.number : SUB_AI_NNRt_Func_North_Model_Finish_0200
717  * @tc.name   : 模型构图,未添加操作数
718  * @tc.desc   : [C- SOFTWARE -0200]
719  */
720 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_Finish_0200, Function | MediumTest | Level3)
721 {
722     OH_NNModel *model = OH_NNModel_Construct();
723     ASSERT_NE(nullptr, model);
724     ASSERT_EQ(OH_NN_OPERATION_FORBIDDEN, OH_NNModel_Finish(model));
725     Free(model);
726 }
727 
728 /**
729  * @tc.number : SUB_AI_NNRt_Func_North_Model_Finish_0300
730  * @tc.name   : 模型构图,未设置输入输出
731  * @tc.desc   : [C- SOFTWARE -0200]
732  */
733 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_Finish_0300, Function | MediumTest | Level3)
734 {
735     OH_NNModel *model = OH_NNModel_Construct();
736     ASSERT_NE(nullptr, model);
737     graphArgs.specifyIO = false;
738     ASSERT_EQ(OH_NN_OPERATION_FORBIDDEN, BuildSingleOpGraph(model, graphArgs));
739     Free(model);
740 }
741 
742 /**
743  * @tc.number : SUB_AI_NNRt_Func_North_Model_Finish_0400
744  * @tc.name   : 模型构图,设置输入输出,构图成功
745  * @tc.desc   : [C- SOFTWARE -0200]
746  */
747 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_Finish_0400, Function | MediumTest | Level1)
748 {
749     OH_NNModel *model = OH_NNModel_Construct();
750     ASSERT_NE(nullptr, model);
751     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
752     Free(model);
753 }
754 
755 /**
756  * @tc.number : SUB_AI_NNRt_Func_North_Model_Destroy_0100
757  * @tc.name   : 释放模型,model为nullptr
758  * @tc.desc   : [C- SOFTWARE -0200]
759  */
760 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_Destroy_0100, Function | MediumTest | Level3)
761 {
762     OH_NNModel *model = nullptr;
763     ASSERT_NO_THROW(OH_NNModel_Destroy(&model));
764 }
765 
766 /**
767  * @tc.number : SUB_AI_NNRt_Func_North_Model_Destroy_0200
768  * @tc.name   : 释放模型,model未构图
769  * @tc.desc   : [C- SOFTWARE -0200]
770  */
771 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_Destroy_0200, Function | MediumTest | Level3)
772 {
773     OH_NNModel *model = OH_NNModel_Construct();
774     ASSERT_NE(nullptr, model);
775     graphArgs.build = false;
776     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
777     OH_NNModel_Destroy(&model);
778     ASSERT_EQ(nullptr, model);
779 }
780 
781 /**
782  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0100
783  * @tc.name   : 查询算子支持,model为空指针
784  * @tc.desc   : [C- SOFTWARE -0200]
785  */
786 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0100, Function | MediumTest | Level3)
787 {
788     const size_t *devicesID{nullptr};
789     const bool *isSupported{nullptr};
790     uint32_t opCount{0};
791     uint32_t devicesCount{0};
792     ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
793     size_t targetDevice = devicesID[0];
794     OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(nullptr, targetDevice, &isSupported, &opCount);
795     ASSERT_EQ(OH_NN_INVALID_PARAMETER, ret);
796 }
797 
798 /**
799  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0200
800  * @tc.name   : 查询算子支持,deviceID不存在
801  * @tc.desc   : [C- SOFTWARE -0200]
802  */
803 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0200, Function | MediumTest | Level3)
804 {
805     OH_NNModel *model = OH_NNModel_Construct();
806     ASSERT_NE(nullptr, model);
807     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
808 
809     size_t targetDevice{100000};
810     const bool *isSupported{nullptr};
811     uint32_t opCount{0};
812     ASSERT_EQ(OH_NN_FAILED, OH_NNModel_GetAvailableOperations(model, targetDevice, &isSupported, &opCount));
813 
814     Free(model);
815 }
816 
817 /**
818  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0300
819  * @tc.name   : 查询算子支持,*isSupported为nullptr
820  * @tc.desc   : [C- SOFTWARE -0200]
821  */
822 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0300, Function | MediumTest | Level3)
823 {
824     OH_NNModel *model = OH_NNModel_Construct();
825     ASSERT_NE(nullptr, model);
826     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
827 
828     const size_t *devicesID{nullptr};
829     uint32_t opCount{0};
830     uint32_t devicesCount{0};
831     ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
832     size_t targetDevice = devicesID[0];
833 
834     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_GetAvailableOperations(model, targetDevice, nullptr, &opCount));
835 
836     Free(model);
837 }
838 
839 /**
840  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0400
841  * @tc.name   : 查询算子支持,**isSupported非nullptr
842  * @tc.desc   : [C- SOFTWARE -0200]
843  */
844 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0400, Function | MediumTest | Level3)
845 {
846     OH_NNModel *model = OH_NNModel_Construct();
847     ASSERT_NE(nullptr, model);
848     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
849 
850     const size_t *devicesID{nullptr};
851     const bool isSupported = true;
852     const bool *realSupported = &isSupported;
853     uint32_t opCount{0};
854     uint32_t devicesCount{0};
855     ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
856     size_t targetDevice = devicesID[0];
857     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_GetAvailableOperations(model, targetDevice,
858     &realSupported, &opCount));
859     Free(model);
860 }
861 
862 /**
863  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0500
864  * @tc.name   : 查询算子支持,*opCount为nullptr
865  * @tc.desc   : [C- SOFTWARE -0200]
866  */
867 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0500, Function | MediumTest | Level3)
868 {
869     OH_NNModel *model = OH_NNModel_Construct();
870     ASSERT_NE(nullptr, model);
871     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
872 
873     const size_t *devicesID{nullptr};
874     const bool *isSupported{nullptr};
875     uint32_t devicesCount{0};
876     ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
877     size_t targetDevice = devicesID[0];
878     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_GetAvailableOperations(model, targetDevice,
879     &isSupported, nullptr));
880     Free(model);
881 }
882 
883 /**
884  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0600
885  * @tc.name   : 查询算子支持,model未完成构图
886  * @tc.desc   : [C- SOFTWARE -0200]
887  */
888 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0600, Function | MediumTest | Level3)
889 {
890     OH_NNModel *model = OH_NNModel_Construct();
891     ASSERT_NE(nullptr, model);
892     graphArgs.build = false;
893     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
894 
895     const size_t *devicesID{nullptr};
896     const bool *isSupported{nullptr};
897     uint32_t opCount{0};
898     uint32_t devicesCount{0};
899     ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
900     size_t targetDevice = devicesID[0];
901     ASSERT_EQ(OH_NN_OPERATION_FORBIDDEN, OH_NNModel_GetAvailableOperations(model, targetDevice,
902     &isSupported, &opCount));
903     Free(model);
904 }
905 
906 /**
907  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0700
908  * @tc.name   : 查询算子支持,算子均支持
909  * @tc.desc   : [C- SOFTWARE -0200]
910  */
911 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0700, Function | MediumTest | Level1)
912 {
913     OHOS::sptr<V1_0::MockIDevice> device = V1_0::MockIDevice::GetInstance();
914     std::vector<bool> isSupported{true, true};
915     device->SetOperationsSupported(isSupported);
916     OH_NNModel *model = OH_NNModel_Construct();
917     ASSERT_NE(nullptr, model);
918     BuildAddTopKGraph(model);
919 
920     const size_t *devicesID{nullptr};
921     const bool *realSupported{nullptr};
922     uint32_t opCount;
923     uint32_t devicesCount;
924     ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
925     size_t targetDevice = devicesID[0];
926     OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, targetDevice, &realSupported, &opCount);
927     ASSERT_EQ(OH_NN_SUCCESS, ret);
928     for (int i = 0; i < opCount; i++) {
929         EXPECT_EQ(realSupported[i], isSupported[i]);
930     }
931     Free(model);
932 }
933 
934 /**
935  * @tc.number : SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0800
936  * @tc.name   : 查询算子支持,算子部分支持
937  * @tc.desc   : [C- SOFTWARE -0200]
938  */
939 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_GetSupportedOperation_0800, Function | MediumTest | Level2)
940 {
941     OHOS::sptr<V1_0::MockIDevice> device = V1_0::MockIDevice::GetInstance();
942     std::vector<bool> isSupported{true, false};
943     device->SetOperationsSupported(isSupported);
944     OH_NNModel *model = OH_NNModel_Construct();
945     ASSERT_NE(nullptr, model);
946     BuildAddTopKGraph(model);
947 
948     const size_t *devicesID{nullptr};
949     const bool *realSupported{nullptr};
950     uint32_t opCount;
951     uint32_t devicesCount;
952     ASSERT_EQ(OH_NN_SUCCESS, OH_NNDevice_GetAllDevicesID(&devicesID, &devicesCount));
953     size_t targetDevice = devicesID[0];
954 
955     OH_NN_ReturnCode ret = OH_NNModel_GetAvailableOperations(model, targetDevice, &realSupported, &opCount);
956     ASSERT_EQ(OH_NN_SUCCESS, ret);
957     for (int i = 0; i < opCount; i++) {
958         EXPECT_EQ(realSupported[i], isSupported[i]);
959     }
960     Free(model);
961     device->SetOperationsSupported({true});
962 }
963 
964 /**
965  * @tc.number : SUB_AI_NNR_Func_North_Model_Combine_0100
966  * @tc.name   : 不同model,多线程并发在线构图,构图成功
967  * @tc.desc   : [C- SOFTWARE -0200]
968  */
969 HWTEST_F(ModelTest, SUB_AI_NNR_Func_North_Model_Combine_0100, Function | MediumTest | Level2)
970 {
971     OH_NNModel *model1 = OH_NNModel_Construct();
972     ASSERT_NE(nullptr, model1);
973     OH_NNModel *model2 = OH_NNModel_Construct();
974     ASSERT_NE(nullptr, model2);
975     std::thread th1(BuildModel, model1, graphArgs);
976     std::thread th2(BuildModel, model2, graphArgs);
977     th1.join();
978     th2.join();
979     Free(model1);
980     Free(model2);
981 }
982 
983 /**
984  * @tc.number : SUB_AI_NNR_Func_North_Model_Combine_0200
985  * @tc.name   : 多模型构图,模型构图过程中释放其他模型
986  * @tc.desc   : [C- SOFTWARE -0200]
987  */
988 HWTEST_F(ModelTest, SUB_AI_NNR_Func_North_Model_Combine_0200, Function | MediumTest | Level1)
989 {
990     OH_NNModel *model1 = OH_NNModel_Construct();
991     ASSERT_NE(nullptr, model1);
992     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model1, graphArgs));
993 
994     OH_NNModel *model2 = OH_NNModel_Construct();
995     ASSERT_NE(nullptr, model2);
996 
997     std::thread th1(BuildModel, model2, graphArgs);
998     std::thread th2(OH_NNModel_Destroy, &model1);
999     th1.join();
1000     th2.join();
1001     ASSERT_EQ(nullptr, model1);
1002     Free(model2);
1003 }
1004