• 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 <vector>
16 #include <string>
17 
18 #include "nncore_utils.h"
19 
20 using namespace testing::ext;
21 using namespace OHOS::NeuralNetworkRuntime::Test;
22 using namespace OHOS::HDI::Nnrt::V2_0;
23 class TensorDescTest : public testing::Test {};
24 
25 
26 /**
27  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescCreate_0100
28  * @tc.desc: 创建TensorDesc
29  * @tc.type: FUNC
30  */
31 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescCreate_0100, Function | MediumTest | Level1)
32 {
33     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
34     ASSERT_NE(nullptr, tensorDesc);
35     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
36 }
37 
38 /**
39  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescDestroy_0100
40  * @tc.desc: 销毁TensorDesc,TensorDesc为空
41  * @tc.type: FUNC
42  */
43 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescDestroy_0100, Function | MediumTest | Level1)
44 {
45     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_Destroy(nullptr));
46 }
47 
48 /**
49  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescDestroy_0200
50  * @tc.desc: 销毁TensorDesc,*TensorDesc为空
51  * @tc.type: FUNC
52  */
53 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescDestroy_0200, Function | MediumTest | Level1)
54 {
55     NN_TensorDesc* tensorDesc = nullptr;
56     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_Destroy(&tensorDesc));
57 }
58 
59 /**
60  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescDestroy_0300
61  * @tc.desc: 销毁TensorDesc
62  * @tc.type: FUNC
63  */
64 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescDestroy_0300, Function | MediumTest | Level1)
65 {
66     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
67     ASSERT_NE(nullptr, tensorDesc);
68     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
69 }
70 
71 /**
72  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetDataType_0100
73  * @tc.desc: 设置TensorDesc数据类型,TensorDesc为空
74  * @tc.type: FUNC
75  */
76 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetDataType_0100, Function | MediumTest | Level1)
77 {
78     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetDataType(nullptr, OH_NN_UNKNOWN));
79 }
80 
81 /**
82  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetDataType_0200
83  * @tc.desc: 设置TensorDesc数据类型,遍历DataType
84  * @tc.type: FUNC
85  */
86 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetDataType_0200, Function | MediumTest | Level1)
87 {
88     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
89     ASSERT_NE(nullptr, tensorDesc);
90     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetDataType(tensorDesc, OH_NN_UNKNOWN));
91     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetDataType(tensorDesc, OH_NN_FLOAT64));
92     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetDataType(tensorDesc, OH_NN_BOOL));
93     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
94 }
95 
96 /**
97  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetDataType_0300
98  * @tc.desc: 设置TensorDesc数据类型,DataType不合法
99  * @tc.type: FUNC
100  */
101 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetDataType_0300, Function | MediumTest | Level1)
102 {
103     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
104     ASSERT_NE(nullptr, tensorDesc);
105     int dataType = static_cast<int>(OH_NN_FLOAT64)+1;
106     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetDataType(tensorDesc, static_cast<OH_NN_DataType>(dataType)));
107     dataType = static_cast<int>(OH_NN_UNKNOWN)-1;
108     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetDataType(tensorDesc, static_cast<OH_NN_DataType>(dataType)));
109     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
110 }
111 
112 /**
113  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetDataType_0100
114  * @tc.desc: 获取TensorDesc数据类型,TensorDesc为空
115  * @tc.type: FUNC
116  */
117 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetDataType_0100, Function | MediumTest | Level1)
118 {
119     OH_NN_DataType dataType;
120     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetDataType(nullptr, &dataType));
121 }
122 
123 /**
124  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetDataType_0200
125  * @tc.desc: 获取TensorDesc数据类型,未设置DataType
126  * @tc.type: FUNC
127  */
128 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetDataType_0200, Function | MediumTest | Level1)
129 {
130     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
131     ASSERT_NE(nullptr, tensorDesc);
132     OH_NN_DataType dataType = OH_NN_UNKNOWN;
133     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetDataType(tensorDesc, &dataType));
134     ASSERT_EQ(OH_NN_UNKNOWN, dataType);
135     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
136 }
137 
138 /**
139  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetShape_0100
140  * @tc.desc: 设置TensorDescShape,TensorDesc为空
141  * @tc.type: FUNC
142  */
143 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetShape_0100, Function | MediumTest | Level1)
144 {
145     int32_t inputDims[4] = {1, 2, 2, 3};
146     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetShape(nullptr, inputDims, 4));
147 }
148 
149 /**
150  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetShape_0200
151  * @tc.desc: 设置TensorDescShape,shape为空
152  * @tc.type: FUNC
153  */
154 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetShape_0200, Function | MediumTest | Level1)
155 {
156     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
157     ASSERT_NE(nullptr, tensorDesc);
158     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetShape(tensorDesc, nullptr, 0));
159     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
160 }
161 
162 /**
163  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetShape_0100
164  * @tc.desc: 获取TensorDescShape,TensorDesc为空
165  * @tc.type: FUNC
166  */
167 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetShape_0100, Function | MediumTest | Level1)
168 {
169     size_t shapeLength = 0;
170     int32_t* shape = nullptr;
171     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetShape(nullptr, &shape, &shapeLength));
172 }
173 
174 /**
175  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetShape_0200
176  * @tc.desc: 获取TensorDescShape,未设置shape
177  * @tc.type: FUNC
178  */
179 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetShape_0200, Function | MediumTest | Level1)
180 {
181     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
182     ASSERT_NE(nullptr, tensorDesc);
183     size_t shapeLength = 0;
184     int32_t* shape = nullptr;
185     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetShape(tensorDesc, &shape, &shapeLength));
186     ASSERT_EQ(nullptr, shape);
187     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
188 }
189 
190 /**
191  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetShape_0300
192  * @tc.desc: 获取TensorDescShape,合法设置返回成功
193  * @tc.type: FUNC
194  */
195 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetShape_0300, Function | MediumTest | Level1)
196 {
197     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
198     ASSERT_NE(nullptr, tensorDesc);
199     int32_t inputDims[4] = {1, 2, 2, 3};
200     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetShape(tensorDesc, inputDims, 4));
201     size_t shapeLength = 0;
202     int32_t* shape = nullptr;
203     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetShape(tensorDesc, &shape, &shapeLength));
204     ASSERT_EQ(*inputDims, *shape);
205     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
206 }
207 
208 /**
209  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetFormat_0100
210  * @tc.desc: 设置TensorDescFormat,TensorDesc为空
211  * @tc.type: FUNC
212  */
213 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetFormat_0100, Function | MediumTest | Level1)
214 {
215     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetFormat(nullptr, OH_NN_FORMAT_NONE));
216 }
217 
218 /**
219  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetFormat_0200
220  * @tc.desc: 设置TensorDescFormat,遍历设置format
221  * @tc.type: FUNC
222  */
223 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetFormat_0200, Function | MediumTest | Level1)
224 {
225     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
226     ASSERT_NE(nullptr, tensorDesc);
227     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetFormat(tensorDesc, OH_NN_FORMAT_NONE));
228     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetFormat(tensorDesc, OH_NN_FORMAT_NCHW));
229     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetFormat(tensorDesc, OH_NN_FORMAT_NHWC));
230     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetFormat(tensorDesc, OH_NN_FORMAT_ND));
231     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
232 }
233 
234 /**
235  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetFormat_0100
236  * @tc.desc: 获取TensorDescFormat,TensorDesc为空
237  * @tc.type: FUNC
238  */
239 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetFormat_0100, Function | MediumTest | Level1)
240 {
241     OH_NN_Format format = OH_NN_FORMAT_NONE;
242     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetFormat(nullptr, &format));
243 }
244 
245 /**
246  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetFormat_0200
247  * @tc.desc: 获取TensorDescFormat,未设置Format
248  * @tc.type: FUNC
249  */
250 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetFormat_0200, Function | MediumTest | Level1)
251 {
252     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
253     ASSERT_NE(nullptr, tensorDesc);
254     OH_NN_Format format = OH_NN_FORMAT_NONE;
255     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetFormat(tensorDesc, &format));
256     ASSERT_EQ(OH_NN_FORMAT_NONE, format);
257     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
258 }
259 
260 /**
261  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetFormat_0300
262  * @tc.desc: 获取TensorDescFormat,合法获取,返回成功
263  * @tc.type: FUNC
264  */
265 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetFormat_0300, Function | MediumTest | Level1)
266 {
267     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
268     ASSERT_NE(nullptr, tensorDesc);
269     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetFormat(tensorDesc, OH_NN_FORMAT_NCHW));
270     OH_NN_Format format = OH_NN_FORMAT_NONE;
271     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetFormat(tensorDesc, &format));
272     ASSERT_EQ(OH_NN_FORMAT_NCHW, format);
273     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
274 }
275 
276 /**
277  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetElementCount_0100
278  * @tc.desc: 获取TensorDescElementCount,TensorDesc为空
279  * @tc.type: FUNC
280  */
281 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetElementCount_0100, Function | MediumTest | Level1)
282 {
283     size_t elementCount = 0;
284     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetElementCount(nullptr, &elementCount));
285 }
286 
287 /**
288  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetElementCount_0200
289  * @tc.desc: 获取TensorDescElementCount,合理设置返回正确
290  * @tc.type: FUNC
291  */
292 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetElementCount_0200, Function | MediumTest | Level1)
293 {
294     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
295     ASSERT_NE(nullptr, tensorDesc);
296     int32_t inputDims[4] = {1, 2, 2, 3};
297     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetShape(tensorDesc, inputDims, 4));
298     size_t elementCount = 0;
299     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetElementCount(tensorDesc, &elementCount));
300     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
301 }
302 
303 /**
304  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetElementCount_0300
305  * @tc.desc: 获取TensorDescElementCount,不设置,返回错误
306  * @tc.type: FUNC
307  */
308 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetElementCount_0300, Function | MediumTest | Level1)
309 {
310     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
311     ASSERT_NE(nullptr, tensorDesc);
312     size_t elementCount = 0;
313     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetElementCount(tensorDesc, &elementCount));
314     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
315 }
316 
317 /**
318  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetByteSize_0100
319  * @tc.desc: 获取TensorDescByteSize,TensorDesc为空
320  * @tc.type: FUNC
321  */
322 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetByteSize_0100, Function | MediumTest | Level1)
323 {
324     size_t byteSize = 0;
325     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetByteSize(nullptr, &byteSize));
326 }
327 
328 /**
329  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetByteSize_0200
330  * @tc.desc: 获取TensorDescByteSize,合理设置返回正确
331  * @tc.type: FUNC
332  */
333 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetByteSize_0200, Function | MediumTest | Level1)
334 {
335     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
336     ASSERT_NE(nullptr, tensorDesc);
337     int32_t inputDims[4] = {1, 2, 2, 3};
338     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetDataType(tensorDesc, OH_NN_FLOAT32));
339     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetShape(tensorDesc, inputDims, 4));
340     size_t byteSize = 0;
341     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetByteSize(tensorDesc, &byteSize));
342     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
343 }
344 
345 /**
346  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetByteSize_0300
347  * @tc.desc: 获取TensorDescByteSize,不设置,返回错误
348  * @tc.type: FUNC
349  */
350 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetByteSize_0300, Function | MediumTest | Level1)
351 {
352     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
353     ASSERT_NE(nullptr, tensorDesc);
354     size_t byteSize = 0;
355     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetByteSize(tensorDesc, &byteSize));
356     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
357 }
358 
359 /**
360  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetName_0100
361  * @tc.desc: 设置TensorDescName,TensorDesc为空
362  * @tc.type: FUNC
363  */
364 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetName_0100, Function | MediumTest | Level1)
365 {
366     const char* name = "tensorDesc";
367     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetName(nullptr, name));
368 }
369 
370 /**
371  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescSetName_0200
372  * @tc.desc: 设置TensorDescName,name为空
373  * @tc.type: FUNC
374  */
375 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescSetName_0200, Function | MediumTest | Level1)
376 {
377     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
378     ASSERT_NE(nullptr, tensorDesc);
379     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_SetName(tensorDesc, nullptr));
380     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
381 }
382 
383 /**
384  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetName_0100
385  * @tc.desc: 获取TensorDescName,TensorDesc为空
386  * @tc.type: FUNC
387  */
388 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetName_0100, Function | MediumTest | Level1)
389 {
390     const char* name = nullptr;
391     ASSERT_EQ(OH_NN_INVALID_PARAMETER, OH_NNTensorDesc_GetName(nullptr, &name));
392 }
393 
394 /**
395  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetName_0200
396  * @tc.desc: 获取TensorDescName,合理设置返回正确
397  * @tc.type: FUNC
398  */
399 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetName_0200, Function | MediumTest | Level1)
400 {
401     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
402     ASSERT_NE(nullptr, tensorDesc);
403     const char* nameIn = "tensorDesc";
404     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_SetName(tensorDesc, nameIn));
405     const char* nameOut = nullptr;
406     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetName(tensorDesc, &nameOut));
407     ASSERT_EQ(*nameIn, *nameOut);
408     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
409 }
410 
411 /**
412  * @tc.name: SUB_AI_NNRt_Core_Func_North_TensorDescGetName_0300
413  * @tc.desc: 获取TensorDescName,不设置,返回错误
414  * @tc.type: FUNC
415  */
416 HWTEST_F(TensorDescTest, SUB_AI_NNRt_Core_Func_North_TensorDescGetName_0300, Function | MediumTest | Level1)
417 {
418     NN_TensorDesc* tensorDesc = OH_NNTensorDesc_Create();
419     ASSERT_NE(nullptr, tensorDesc);
420     const char* nameOut = nullptr;
421     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_GetName(tensorDesc, &nameOut));
422     std::string name(nameOut);
423     std::string empty("");
424     ASSERT_EQ(empty, name);
425     ASSERT_EQ(OH_NN_SUCCESS, OH_NNTensorDesc_Destroy(&tensorDesc));
426 }
427 
428