• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "nncore_utils.h"
21 
22 using namespace testing::ext;
23 using namespace OHOS::NeuralNetworkRuntime::Test;
24 using namespace OHOS::HDI::Nnrt::V2_0;
25 
26 namespace {
27 
28 class ModelTest : public testing::Test {
29 protected:
30     AddModel addModel;
31     OHNNGraphArgs graphArgs = addModel.graphArgs;
32 };
33 
BuildAddTopKGraph(OH_NNModel * model)34 void BuildAddTopKGraph(OH_NNModel *model)
35 {
36     AddTopKModel addTopKModel;
37     OHNNGraphArgsMulti graphArgsMulti = addTopKModel.graphArgs;
38     ASSERT_EQ(OH_NN_SUCCESS, BuildMultiOpGraph(model, graphArgsMulti));
39 }
40 
BuildModel(OH_NNModel * model,const OHNNGraphArgs & graphArgs)41 void BuildModel(OH_NNModel *model, const OHNNGraphArgs &graphArgs)
42 {
43     ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model, graphArgs));
44 }
45 
46 } // namespace
47 
48 /**
49  * @tc.number : SUB_AI_NNRt_Func_North_Model_CreateQuantParam_0100
50  * @tc.desc: 创建量化参数
51  * @tc.type: FUNC
52  */
53 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_CreateQuantParam_0100, Function | MediumTest | Level0)
54 {
55     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
56     ASSERT_NE(nullptr, quantParam);
57 }
58 
59 /**
60  * @tc.number : SUB_AI_NNRt_Func_North_Model_DestroyQuantParam_0100
61  * @tc.desc: 释放量化参数,*quantParam为空
62  * @tc.type: FUNC
63  */
64 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_DestroyQuantParam_0100, Function | MediumTest | Level0)
65 {
66     NN_QuantParam* quantParam = nullptr;
67     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNQuantParam_Destroy(&quantParam));
68 }
69 
70 /**
71  * @tc.number : SUB_AI_NNRt_Func_North_Model_DestroyQuantParam_0200
72  * @tc.desc: 释放量化参数,quantParam为空
73  * @tc.type: FUNC
74  */
75 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_DestroyQuantParam_0200, Function | MediumTest | Level0)
76 {
77     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNQuantParam_Destroy(nullptr));
78 }
79 
80 /**
81  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0100
82  * @tc.desc: 设置量化参数,参数为空,返回失败
83  * @tc.type: FUNC
84  */
85 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0100, Function | MediumTest | Level0)
86 {
87     double scales = 0.2;
88     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNQuantParam_SetScales(nullptr, &scales, 1));
89 }
90 
91 /**
92  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0200
93  * @tc.desc: 设置量化参数,参数合法,count=1,参数的channel=1,调用成功
94  * @tc.type: FUNC
95  */
96 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0200, Function | MediumTest | Level0)
97 {
98     OH_NNModel *model = OH_NNModel_Construct();
99     ASSERT_NE(nullptr, model);
100     int32_t inputDims[4] = {1, 1, 2, 3};
101     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
102     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
103     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
104     double scales = 0.2;
105     int32_t zeroPoints = 0;
106     uint32_t numBits = 8;
107     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetScales(quantParam, &scales, 1));
108     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetZeroPoints(quantParam, &zeroPoints, 1));
109     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetNumBits(quantParam, &numBits, 1));
110     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorQuantParams(model, 0, quantParam));
111     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
112     OH_NNModel_Destroy(&model);
113 }
114 
115 /**
116  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0300
117  * @tc.desc: 设置量化参数,count=1,channel=2,Per-Layer模式,设置成功
118  * @tc.type: FUNC
119  */
120 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0300, Function | MediumTest | Level0)
121 {
122     OH_NNModel *model = OH_NNModel_Construct();
123     ASSERT_NE(nullptr, model);
124     int32_t inputDims[4] = {1, 2, 2, 3};
125     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
126     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
127     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
128     double scales = 0.2;
129     int32_t zeroPoints = 0;
130     uint32_t numBits = 8;
131     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetScales(quantParam, &scales, 1));
132     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetZeroPoints(quantParam, &zeroPoints, 1));
133     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetNumBits(quantParam, &numBits, 1));
134     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorQuantParams(model, 0, quantParam));
135     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
136     OH_NNModel_Destroy(&model);
137 }
138 
139 /**
140  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0400
141  * @tc.desc: 设置量化参数,参数合法,count=2,参数的channel=1,调用失败
142  * @tc.type: FUNC
143  */
144 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0400, Function | MediumTest | Level0)
145 {
146     OH_NNModel *model = OH_NNModel_Construct();
147     ASSERT_NE(nullptr, model);
148     int32_t inputDims[4] = {1, 1, 2, 3};
149     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
150     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
151     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
152     double scales = 0.2;
153     int32_t zeroPoints = 0;
154     uint32_t numBits = 8;
155     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetScales(quantParam, &scales, 2));
156     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetZeroPoints(quantParam, &zeroPoints, 2));
157     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetNumBits(quantParam, &numBits, 2));
158     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorQuantParams(model, 0, quantParam));
159     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
160     OH_NNModel_Destroy(&model);
161 }
162 
163 /**
164  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0500
165  * @tc.desc: 设置量化参数,参数合法,参数count不一致,调用失败
166  * @tc.type: FUNC
167  */
168 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0500, Function | MediumTest | Level0)
169 {
170     OH_NNModel *model = OH_NNModel_Construct();
171     ASSERT_NE(nullptr, model);
172     int32_t inputDims[4] = {1, 1, 2, 3};
173     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
174     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
175     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
176     double scales = 0.2;
177     int32_t zeroPoints = 0;
178     uint32_t numBits = 8;
179     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetScales(quantParam, &scales, 1));
180     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetZeroPoints(quantParam, &zeroPoints, 2));
181     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetNumBits(quantParam, &numBits, 1));
182     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorQuantParams(model, 0, quantParam));
183     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
184     OH_NNModel_Destroy(&model);
185 }
186 
187 /**
188  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0600
189  * @tc.desc: 设置量化参数,参数合法,不设置zeroPoints,调用失败
190  * @tc.type: FUNC
191  */
192 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0600, Function | MediumTest | Level0)
193 {
194     OH_NNModel *model = OH_NNModel_Construct();
195     ASSERT_NE(nullptr, model);
196     int32_t inputDims[4] = {1, 1, 2, 3};
197     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
198     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
199     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
200     double scales = 0.2;
201     uint32_t numBits = 8;
202     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetScales(quantParam, &scales, 1));
203     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetNumBits(quantParam, &numBits, 1));
204     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorQuantParams(model, 0, quantParam));
205     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
206     OH_NNModel_Destroy(&model);
207 }
208 
209 /**
210  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0700
211  * @tc.desc: 设置量化参数,参数合法,不设置numBits,调用失败
212  * @tc.type: FUNC
213  */
214 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0700, Function | MediumTest | Level0)
215 {
216     OH_NNModel *model = OH_NNModel_Construct();
217     ASSERT_NE(nullptr, model);
218     int32_t inputDims[4] = {1, 1, 2, 3};
219     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
220     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
221     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
222     double scales = 0.2;
223     int32_t zeroPoints = 0;
224     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetScales(quantParam, &scales, 1));
225     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetZeroPoints(quantParam, &zeroPoints, 1));
226     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorQuantParams(model, 0, quantParam));
227     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
228     OH_NNModel_Destroy(&model);
229 }
230 
231 /**
232  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0800
233  * @tc.desc: 设置量化参数,参数合法,不设置scales,调用失败
234  * @tc.type: FUNC
235  */
236 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0800, Function | MediumTest | Level0)
237 {
238     OH_NNModel *model = OH_NNModel_Construct();
239     ASSERT_NE(nullptr, model);
240     int32_t inputDims[4] = {1, 1, 2, 3};
241     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
242     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
243     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
244     int32_t zeroPoints = 0;
245     uint32_t numBits = 8;
246     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetZeroPoints(quantParam, &zeroPoints, 1));
247     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetNumBits(quantParam, &numBits, 1));
248     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorQuantParams(model, 0, quantParam));
249     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
250     OH_NNModel_Destroy(&model);
251 }
252 
253 /**
254  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetQuantParam_0900
255  * @tc.desc: 设置量化参数,参数合法,tensor下标等于当前tensor个数,返回失败
256  * @tc.type: FUNC
257  */
258 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetQuantParam_0900, Function | MediumTest | Level0)
259 {
260     OH_NNModel *model = OH_NNModel_Construct();
261     ASSERT_NE(nullptr, model);
262     int32_t inputDims[4] = {1, 1, 2, 3};
263     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
264     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
265     NN_QuantParam* quantParam = OH_NNQuantParam_Create();
266     double scales = 0.2;
267     int32_t zeroPoints = 0;
268     uint32_t numBits = 8;
269     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetScales(quantParam, &scales, 1));
270     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetZeroPoints(quantParam, &zeroPoints, 1));
271     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_SetNumBits(quantParam, &numBits, 1));
272     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorQuantParams(model, 1, quantParam));
273     ASSERT_EQ(OH_NN_SUCCESS, OH_NNQuantParam_Destroy(&quantParam));
274     OH_NNModel_Destroy(&model);
275 }
276 
277 /**
278  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddTensorToModel_0100
279  * @tc.desc: 添加tensor到模型,model为空
280  * @tc.type: FUNC
281  */
282 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddTensorToModel_0100, Function | MediumTest | Level0)
283 {
284     int32_t inputDims[4] = {1, 1, 2, 3};
285     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
286     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddTensorToModel(nullptr, tensorDesc));
287 }
288 
289 /**
290  * @tc.number : SUB_AI_NNRt_Func_North_Model_AddTensorToModel_0200
291  * @tc.desc: 添加tensor到模型,tensorDesc为空
292  * @tc.type: FUNC
293  */
294 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_AddTensorToModel_0200, Function | MediumTest | Level0)
295 {
296     OH_NNModel *model = OH_NNModel_Construct();
297     ASSERT_NE(nullptr, model);
298     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_AddTensorToModel(model, nullptr));
299     OH_NNModel_Destroy(&model);
300 }
301 
302 /**
303  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetTensorData_0100
304  * @tc.desc: 设置操作数值,model为nullptr
305  * @tc.type: FUNC
306  */
307 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetTensorData_0100, Function | MediumTest | Level0)
308 {
309     int8_t activationValue{0};
310     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(nullptr, 0, (void *)&activationValue, sizeof(int8_t)));
311 }
312 
313 /**
314  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetTensorData_0200
315  * @tc.desc: 设置操作数值,databuffer为nullptr
316  * @tc.type: FUNC
317  */
318 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetTensorData_0200, Function | MediumTest | Level0)
319 {
320     OH_NNModel *model = OH_NNModel_Construct();
321     ASSERT_NE(nullptr, model);
322     int32_t inputDims[4] = {1, 1, 2, 3};
323     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
324     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
325     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 0, nullptr, sizeof(int8_t)));
326     OH_NNModel_Destroy(&model);
327 }
328 
329 /**
330  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetTensorData_0300
331  * @tc.desc: 设置操作数值,length = 0
332  * @tc.type: FUNC
333  */
334 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetTensorData_0300, Function | MediumTest | Level0)
335 {
336     OH_NNModel *model = OH_NNModel_Construct();
337     ASSERT_NE(nullptr, model);
338     int32_t inputDims[4] = {1, 1, 2, 3};
339     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
340     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
341     int8_t activationValue{0};
342     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 0, (void *)&activationValue, 0));
343     OH_NNModel_Destroy(&model);
344 }
345 
346 /**
347  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetTensorData_0400
348  * @tc.desc: 设置操作数值,index大于tensor个数
349  * @tc.type: FUNC
350  */
351 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetTensorData_0400, Function | MediumTest | Level0)
352 {
353     OH_NNModel *model = OH_NNModel_Construct();
354     ASSERT_NE(nullptr, model);
355     int32_t inputDims[4] = {1, 1, 2, 3};
356     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
357     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
358     int8_t activationValue{0};
359     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorData(model, 1000, (void *)&activationValue, sizeof(int8_t)));
360     OH_NNModel_Destroy(&model);
361 }
362 
363 /**
364  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetTensorType_0100
365  * @tc.desc: 设置tensortype,model为nullptr
366  * @tc.type: FUNC
367  */
368 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetTensorType_0100, Function | MediumTest | Level0)
369 {
370     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorType(nullptr, 0, OH_NN_TENSOR));
371 }
372 
373 /**
374  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetTensorType_0200
375  * @tc.desc: 设置tensortype,index大于tensor个数
376  * @tc.type: FUNC
377  */
378 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetTensorType_0200, Function | MediumTest | Level0)
379 {
380     OH_NNModel *model = OH_NNModel_Construct();
381     ASSERT_NE(nullptr, model);
382     int32_t inputDims[4] = {1, 1, 2, 3};
383     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
384     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
385     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNModel_SetTensorType(model, 1000, OH_NN_TENSOR));
386     OH_NNModel_Destroy(&model);
387 }
388 
389 /**
390  * @tc.number : SUB_AI_NNRt_Func_North_Model_SetTensorType_0300
391  * @tc.desc: 设置tensortype,遍历设置tensorType
392  * @tc.type: FUNC
393  */
394 HWTEST_F(ModelTest, SUB_AI_NNRt_Func_North_Model_SetTensorType_0300, Function | MediumTest | Level0)
395 {
396     OH_NNModel *model = OH_NNModel_Construct();
397     ASSERT_NE(nullptr, model);
398     int32_t inputDims[4] = {1, 1, 2, 3};
399     NN_TensorDesc* tensorDesc = createTensorDesc(inputDims, 4, OH_NN_FLOAT32, OH_NN_FORMAT_NCHW);
400     ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_AddTensorToModel(model, tensorDesc));
401     for (int tensorType = 0; tensorType < 77; tensorType++) {
402         ASSERT_EQ(OH_NN_SUCCESS, OH_NNModel_SetTensorType(model, 0, static_cast<OH_NN_TensorType>(tensorType)));
403     }
404     OH_NNModel_Destroy(&model);
405 }
406