• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "hcs_config_test.h"
10 #include "device_resource_if.h"
11 #include "hdf_log.h"
12 
13 #define HDF_LOG_TAG hcs_config_test
14 
15 #define INDEX_NUM_ZERO 0
16 #define INDEX_NUM_ONE 1
17 #define INDEX_NUM_TWO 2
18 #define INDEX_NUM_THREE 3
19 #define INDEX_NUM_FOUR 4
20 #define INDEX_NUM_FIVE 5
21 #define INDEX_NUM_SIX 6
22 #define INDEX_NUM_SEVEN 7
23 #define TEST_DATA_ZERO 0
24 #define TEST_DATA_ONE 1
25 #define TEST_DATA_TWO 2
26 #define TEST_DATA_THREE 3
27 #define TEST_DATA_FOUR 4
28 #define TEST_DATA_FIVE 5
29 #define TEST_DATA_SIX 6
30 #define TEST_DATA_SEVEN 7
31 #define TEST_DATA_256 256
32 #define TEST_DATA_257 257
33 #define DATA_TYPE_NUM_U32 3
34 #define DATA_TYPE_NUM_U64 4
35 #define U8_DATA 1
36 #define U16_DATA_OFFSET 8
37 #define U16_DATA (1 << U16_DATA_OFFSET)
38 #define U32_DATA_OFFSET 16
39 #define U32_DATA (1 << U32_DATA_OFFSET)
40 #define U64_DATA 0x100000000
41 #define DEFAULT_UINT8_MAX 0xFF
42 #define DEFAULT_UINT16_MAX 0xFFFF
43 #define DEFAULT_UINT32_MAX 0xFFFFFFFF
44 #define DEFAULT_UINT64_MAX 0xFFFFFFFFFFFFFFFF
45 #define BOARDID_LENGTH 2
46 #define HW_AUDIO_INFO "hw,hw_audio_info"
47 #define HW_FINGERPRINT_INFO "hw,hw_fingerprint_info"
48 #define INVALID_STRING "NULL"
49 #define READ_U32_INDEX "read_u32_index"
50 #define DUAL_FINGERPRINT "dual_fingerprint"
51 #define BOARD_ID "board_id"
52 #define STRING_LIST_NAMES "string_list_names"
53 #define AUDIO_INFO "audio_info"
54 #define FINGERPRINT_INFO "fingerprint_info"
55 #define INVALID_NODE "fingerprint"
56 #define FINGER_INFO "finger_info"
57 #define STRING_ATTR_VALUE "default"
58 #define READ_FOUR_DATA_TYPE "read_four_data_type"
59 #define HW_DATA_TYPE_TEST "hw,data_type_test"
60 #define SMARTPA_NUM "smartpa_num"
61 #define READ_U64DATA "read_u64data"
62 #define VOICE_VOL_LEVEL "voice_vol_level"
63 #define SMARTPA_ADDR "smartpa_addr"
64 #define DATA_TEST_ARRAY_LENGTH 8
65 #define TEST_U8_ELEM_DATA  "test_u8_elem_data"
66 #define TEST_U16_ELEM_DATA "test_u16_elem_data"
67 static const struct DeviceResourceNode *g_testRoot = NULL;
68 static const struct DeviceResourceIface *g_devResInstance = NULL;
69 
TestGetRootNode(void)70 static bool TestGetRootNode(void)
71 {
72     g_devResInstance = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
73     if (g_devResInstance == NULL) {
74         HDF_LOGE("%s failed, DeviceResourceGetIfaceInstance is error", __func__);
75         return false;
76     }
77 
78     g_testRoot = g_devResInstance->GetRootNode();
79     if (g_testRoot == NULL) {
80         HDF_LOGE("%s failed, GetDmRootNode failed, line: %d\n", __FUNCTION__, __LINE__);
81         return false;
82     }
83     return true;
84 }
85 
HcsTestCreateDMHcsToTree(void)86 int HcsTestCreateDMHcsToTree(void)
87 {
88     if (!TestGetRootNode()) {
89         return HDF_FAILURE;
90     }
91     return HDF_SUCCESS;
92 }
93 
TestHcsGetNodeByMatchAttrSuccess(void)94 static bool TestHcsGetNodeByMatchAttrSuccess(void)
95 {
96     const struct DeviceResourceNode *fingerPrintNode = NULL;
97     const struct DeviceResourceNode *audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
98     if (audioNode == NULL) {
99         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d\n", __FUNCTION__, __LINE__);
100         return false;
101     }
102     fingerPrintNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_FINGERPRINT_INFO);
103     if (fingerPrintNode == NULL) {
104         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d\n", __FUNCTION__, __LINE__);
105         return false;
106     }
107     return true;
108 }
109 
HcsTestGetNodeByMatchAttrSuccess(void)110 int HcsTestGetNodeByMatchAttrSuccess(void)
111 {
112     if (!TestGetRootNode()) {
113         return HDF_FAILURE;
114     }
115     if (!TestHcsGetNodeByMatchAttrSuccess()) {
116         return HDF_FAILURE;
117     }
118     return HDF_SUCCESS;
119 }
120 
TestHcsGetNodeByMatchAttrFailed(void)121 static bool TestHcsGetNodeByMatchAttrFailed(void)
122 {
123     const struct DeviceResourceNode *nullNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, INVALID_STRING);
124     if (nullNode != NULL) {
125         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d\n", __FUNCTION__, __LINE__);
126         return false;
127     }
128     nullNode = g_devResInstance->GetNodeByMatchAttr(NULL, INVALID_STRING);
129     if (nullNode != NULL) {
130         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d\n", __FUNCTION__, __LINE__);
131         return false;
132     }
133     nullNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, NULL);
134     if (nullNode != NULL) {
135         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d\n", __FUNCTION__, __LINE__);
136         return false;
137     }
138     return true;
139 }
140 
HcsTestGetNodeByMatchAttrFail(void)141 int HcsTestGetNodeByMatchAttrFail(void)
142 {
143     if (!TestGetRootNode()) {
144         return HDF_FAILURE;
145     }
146     if (!TestHcsGetNodeByMatchAttrFailed()) {
147         return HDF_FAILURE;
148     }
149     return HDF_SUCCESS;
150 }
151 
TestHcsAttrGetBoolSuccess(void)152 static bool TestHcsAttrGetBoolSuccess(void)
153 {
154     const struct DeviceResourceNode *fingerNode = NULL;
155     const struct DeviceResourceNode *audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
156     bool primaryMic = g_devResInstance->GetBool(audioNode, "builtin_primary_mic_exist");
157     bool dualFinger = NULL;
158     if (!primaryMic) {
159         HDF_LOGE("%s failed, HcsGetBool failed, line: %d\n", __FUNCTION__, __LINE__);
160         return false;
161     }
162     fingerNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_FINGERPRINT_INFO);
163     if (fingerNode == NULL) {
164         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d\n", __FUNCTION__, __LINE__);
165         return false;
166     }
167     dualFinger = g_devResInstance->GetBool(fingerNode, DUAL_FINGERPRINT);
168     if (dualFinger) {
169         HDF_LOGE("%s failed, HcsGetBool failed, line: %d\n", __FUNCTION__, __LINE__);
170         return false;
171     }
172     return true;
173 }
174 
HcsTestGetBoolAttrValueSuccess(void)175 int HcsTestGetBoolAttrValueSuccess(void)
176 {
177     if (!TestGetRootNode()) {
178         return HDF_FAILURE;
179     }
180     if (!TestHcsAttrGetBoolSuccess()) {
181         return HDF_FAILURE;
182     }
183     return HDF_SUCCESS;
184 }
185 
TestHcsAttrGetBoolFailed(void)186 static bool TestHcsAttrGetBoolFailed(void)
187 {
188     const struct DeviceResourceNode *fingerNode = NULL;
189     const struct DeviceResourceNode *audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
190     bool testReadBool = NULL;
191     if (audioNode == NULL) {
192         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d", __FUNCTION__, __LINE__);
193         return false;
194     }
195     testReadBool = g_devResInstance->GetBool(audioNode, INVALID_STRING);
196     if (testReadBool) {
197         HDF_LOGE("%s failed, HcsGetBool failed, line: %d", __FUNCTION__, __LINE__);
198         return false;
199     }
200     fingerNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_FINGERPRINT_INFO);
201     if (fingerNode == NULL) {
202         HDF_LOGE("%s failed, HcsGetNodeByMatchAttr failed, line: %d", __FUNCTION__, __LINE__);
203         return false;
204     }
205     testReadBool = g_devResInstance->GetBool(fingerNode, INVALID_STRING);
206     if (testReadBool) {
207         HDF_LOGE("%s failed, HcsGetBool failed. line: %d", __FUNCTION__, __LINE__);
208         return false;
209     }
210     testReadBool = g_devResInstance->GetBool(NULL, INVALID_STRING);
211     if (testReadBool) {
212         HDF_LOGE("%s failed, HcsGetBool failed. line: %d", __FUNCTION__, __LINE__);
213         return false;
214     }
215     testReadBool = g_devResInstance->GetBool(fingerNode, NULL);
216     if (testReadBool) {
217         HDF_LOGE("%s failed, HcsGetBool failed. line: %d", __FUNCTION__, __LINE__);
218         return false;
219     }
220     return true;
221 }
222 
HcsTestGetBoolAttrValueFail(void)223 int HcsTestGetBoolAttrValueFail(void)
224 {
225     if (!TestGetRootNode()) {
226         return HDF_FAILURE;
227     }
228     if (!TestHcsAttrGetBoolFailed()) {
229         return HDF_FAILURE;
230     }
231     return HDF_SUCCESS;
232 }
233 
HcsTestGetUint8AttrValueSuccess(void)234 int HcsTestGetUint8AttrValueSuccess(void)
235 {
236     const struct DeviceResourceNode *audioNode = NULL;
237     uint8_t data;
238     int32_t ret;
239     if (!TestGetRootNode()) {
240         return HDF_FAILURE;
241     }
242     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
243     ret = g_devResInstance->GetUint8(audioNode, SMARTPA_NUM, &data, DEFAULT_UINT8_MAX);
244     if ((ret != HDF_SUCCESS) || (data != U8_DATA)) {
245         HDF_LOGE("%s failed, line: %d, ret = %d, data = %u", __FUNCTION__, __LINE__, ret, data);
246         return HDF_FAILURE;
247     }
248     return HDF_SUCCESS;
249 }
250 
HcsTestGetUint8AttrValueFail(void)251 int HcsTestGetUint8AttrValueFail(void)
252 {
253     const struct DeviceResourceNode *audioNode = NULL;
254     uint8_t data;
255     int32_t ret;
256     if (!TestGetRootNode()) {
257         return HDF_FAILURE;
258     }
259     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
260     ret = g_devResInstance->GetUint8(audioNode, INVALID_STRING, &data, DEFAULT_UINT8_MAX);
261     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT8_MAX)) {
262         return HDF_FAILURE;
263     }
264     ret = g_devResInstance->GetUint8(audioNode, READ_U64DATA, NULL, DEFAULT_UINT8_MAX);
265     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT8_MAX)) {
266         return HDF_FAILURE;
267     }
268     ret = g_devResInstance->GetUint8(audioNode, VOICE_VOL_LEVEL, &data, DEFAULT_UINT8_MAX);
269     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT8_MAX)) {
270         return HDF_FAILURE;
271     }
272     ret = g_devResInstance->GetUint8(audioNode, SMARTPA_ADDR, &data, DEFAULT_UINT8_MAX);
273     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT8_MAX)) {
274         return HDF_FAILURE;
275     }
276     ret = g_devResInstance->GetUint8(audioNode, READ_U64DATA, &data, DEFAULT_UINT8_MAX);
277     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT8_MAX)) {
278         return HDF_FAILURE;
279     }
280     return HDF_SUCCESS;
281 }
282 
HcsTestGetUint8ArrayElemSuccess(void)283 int HcsTestGetUint8ArrayElemSuccess(void)
284 {
285     const struct DeviceResourceNode *dataType = NULL;
286     uint8_t data[DATA_TEST_ARRAY_LENGTH] = { 0 };
287     // the test data is 0, 1, 2, 3, 4, 5, 6, 7.
288     const uint8_t testData[DATA_TEST_ARRAY_LENGTH] = { 0, 1, 2, 3, 4, 5, 6, 7 };
289     int32_t i;
290     int32_t count;
291     if (!TestGetRootNode()) {
292         return HDF_FAILURE;
293     }
294     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
295     count = g_devResInstance->GetElemNum(dataType, TEST_U8_ELEM_DATA);
296     if (count != DATA_TEST_ARRAY_LENGTH) {
297         return HDF_FAILURE;
298     }
299     for (i = 0; i < count; i++) {
300         int32_t ret = g_devResInstance->GetUint8ArrayElem(dataType, TEST_U8_ELEM_DATA, i, &data[i],
301             DEFAULT_UINT8_MAX);
302         if ((ret != HDF_SUCCESS) || (data[i] != testData[i])) {
303             HDF_LOGE("%s failed, line: %d, ret = %d, i = %u, data = %u", __FUNCTION__, __LINE__, ret, i, data[i]);
304             return HDF_FAILURE;
305         }
306     }
307     return HDF_SUCCESS;
308 }
309 
HcsTestGetUint8ArrayElemFail(void)310 int HcsTestGetUint8ArrayElemFail(void)
311 {
312     const struct DeviceResourceNode *dataType = NULL;
313     uint8_t data1[DATA_TYPE_NUM_U64] = { 0 };
314     uint8_t data;
315     int32_t i;
316     int32_t ret;
317     int32_t count;
318     if (!TestGetRootNode()) {
319         return HDF_FAILURE;
320     }
321     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
322     // the number of 8 is invalid value.
323     ret = g_devResInstance->GetUint8ArrayElem(dataType, TEST_U8_ELEM_DATA, 8, &data, DEFAULT_UINT8_MAX);
324     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT8_MAX)) {
325         HDF_LOGE("%s failed, line: %d, ret = %d, data = %x", __FUNCTION__, __LINE__, ret, data);
326         return HDF_FAILURE;
327     }
328     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
329     count = g_devResInstance->GetElemNum(dataType, READ_FOUR_DATA_TYPE);
330     if (count != DATA_TYPE_NUM_U64) {
331         return HDF_FAILURE;
332     }
333     for (i = 0; i < count; i++) {
334         ret = g_devResInstance->GetUint8ArrayElem(dataType, READ_FOUR_DATA_TYPE, i, &data1[i], DEFAULT_UINT8_MAX);
335     }
336     // the 0~3 represents the location in array.
337     if ((ret == HDF_SUCCESS) || (data1[INDEX_NUM_ZERO] != U8_DATA) || (data1[INDEX_NUM_ONE] != DEFAULT_UINT8_MAX) ||
338         (data1[INDEX_NUM_TWO] != DEFAULT_UINT8_MAX) || (data1[INDEX_NUM_THREE] != DEFAULT_UINT8_MAX)) {
339         HDF_LOGE("%s failed, line: %d, ret = %d, data = %x", __FUNCTION__, __LINE__, ret, data);
340         return HDF_FAILURE;
341     }
342     return HDF_SUCCESS;
343 }
344 
HcsTestGetUint8ArraySuccess(void)345 int HcsTestGetUint8ArraySuccess(void)
346 {
347     const struct DeviceResourceNode *dataType = NULL;
348     uint8_t data[DATA_TEST_ARRAY_LENGTH] = { 0 };
349     int32_t ret;
350     if (!TestGetRootNode()) {
351         return HDF_FAILURE;
352     }
353     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
354     ret = g_devResInstance->GetUint8Array(dataType, TEST_U8_ELEM_DATA, data, DATA_TEST_ARRAY_LENGTH,
355                                           DEFAULT_UINT8_MAX);
356     // the 0~7 represents the location in array or the value in hcs file.
357     if ((ret != HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != TEST_DATA_ZERO) || (data[INDEX_NUM_ONE] != TEST_DATA_ONE) ||
358         (data[INDEX_NUM_TWO] != TEST_DATA_TWO) || (data[INDEX_NUM_THREE] != TEST_DATA_THREE) ||
359         (data[INDEX_NUM_FOUR] != TEST_DATA_FOUR) ||
360         (data[INDEX_NUM_FIVE] != TEST_DATA_FIVE) || (data[INDEX_NUM_SIX] != TEST_DATA_SIX) ||
361         (data[INDEX_NUM_SEVEN] != TEST_DATA_SEVEN)) {
362         return HDF_FAILURE;
363     }
364     return HDF_SUCCESS;
365 }
366 
HcsTestGetUint8ArrayFail(void)367 int HcsTestGetUint8ArrayFail(void)
368 {
369     const struct DeviceResourceNode *dataType = NULL;
370     uint8_t data[DATA_TYPE_NUM_U64 + 1] = { 0 };
371     int32_t ret;
372     if (!TestGetRootNode()) {
373         return HDF_FAILURE;
374     }
375     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
376     ret = g_devResInstance->GetUint8Array(dataType, READ_FOUR_DATA_TYPE, data, 0, DEFAULT_UINT8_MAX);
377     // the 0, 1, 2 represents the location in array, the 0 of second param is default value.
378     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != TEST_DATA_ZERO) || (data[INDEX_NUM_ONE] != TEST_DATA_ZERO) ||
379         (data[INDEX_NUM_TWO] != TEST_DATA_ZERO)) {
380         return HDF_FAILURE;
381     }
382     ret = g_devResInstance->GetUint8Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64 + 1,
383         DEFAULT_UINT8_MAX);
384     // the 0, 1, 2, 3, 4 represents the location in array
385     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != U8_DATA) || (data[INDEX_NUM_ONE] != DEFAULT_UINT8_MAX) ||
386         (data[INDEX_NUM_TWO] != DEFAULT_UINT8_MAX) ||
387         (data[INDEX_NUM_THREE] != DEFAULT_UINT8_MAX) || (data[INDEX_NUM_FOUR] != DEFAULT_UINT8_MAX)) {
388         return HDF_FAILURE;
389     }
390     return HDF_SUCCESS;
391 }
392 
HcsTestGetUint16AttrValueSuccess(void)393 int HcsTestGetUint16AttrValueSuccess(void)
394 {
395     const struct DeviceResourceNode *audioNode = NULL;
396     uint16_t data;
397     int32_t ret;
398     if (!TestGetRootNode()) {
399         return HDF_FAILURE;
400     }
401     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
402     ret = g_devResInstance->GetUint16(audioNode, SMARTPA_NUM, &data, DEFAULT_UINT16_MAX);
403     if ((ret != HDF_SUCCESS) || (data != U8_DATA)) {
404         HDF_LOGE("%s failed, line: %d, ret = %d, data = %u", __FUNCTION__, __LINE__, ret, data);
405         return HDF_FAILURE;
406     }
407     ret = g_devResInstance->GetUint16(audioNode, VOICE_VOL_LEVEL, &data, DEFAULT_UINT16_MAX);
408     if ((ret != HDF_SUCCESS) || (data != U16_DATA)) {
409         HDF_LOGE("%s failed, line: %d, ret = %d, data = %u", __FUNCTION__, __LINE__, ret, data);
410         return HDF_FAILURE;
411     }
412     return HDF_SUCCESS;
413 }
414 
HcsTestGetUint16AttrValueFail(void)415 int HcsTestGetUint16AttrValueFail(void)
416 {
417     const struct DeviceResourceNode *audioNode = NULL;
418     uint16_t data;
419     int32_t ret;
420     if (!TestGetRootNode()) {
421         return HDF_FAILURE;
422     }
423     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
424     ret = g_devResInstance->GetUint16(audioNode, INVALID_STRING, &data, DEFAULT_UINT16_MAX);
425     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT16_MAX)) {
426         return HDF_FAILURE;
427     }
428     ret = g_devResInstance->GetUint16(audioNode, READ_U64DATA, NULL, DEFAULT_UINT16_MAX);
429     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT16_MAX)) {
430         return HDF_FAILURE;
431     }
432     ret = g_devResInstance->GetUint16(audioNode, SMARTPA_ADDR, &data, DEFAULT_UINT16_MAX);
433     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT16_MAX)) {
434         return HDF_FAILURE;
435     }
436     ret = g_devResInstance->GetUint16(audioNode, READ_U64DATA, &data, DEFAULT_UINT16_MAX);
437     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT16_MAX)) {
438         return HDF_FAILURE;
439     }
440     return HDF_SUCCESS;
441 }
442 
HcsTestGetUint16ArrayElemSuccess(void)443 int HcsTestGetUint16ArrayElemSuccess(void)
444 {
445     const struct DeviceResourceNode *dataType = NULL;
446     // the length of data is 8.
447     uint16_t data[DATA_TEST_ARRAY_LENGTH] = { 0 };
448     // the test data is 0, 1, 2, 3, 4, 5, 256, 257.
449     const uint16_t testData[DATA_TEST_ARRAY_LENGTH] = { TEST_DATA_ZERO, TEST_DATA_ONE, TEST_DATA_TWO, TEST_DATA_THREE,
450                                                         TEST_DATA_FOUR, TEST_DATA_FIVE, TEST_DATA_256, TEST_DATA_257 };
451     int32_t i;
452     int32_t count;
453     if (!TestGetRootNode()) {
454         return HDF_FAILURE;
455     }
456     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
457     count = g_devResInstance->GetElemNum(dataType, TEST_U16_ELEM_DATA);
458     if (count != DATA_TEST_ARRAY_LENGTH) {
459         return HDF_FAILURE;
460     }
461     for (i = 0; i < count; i++) {
462         int32_t ret = g_devResInstance->GetUint16ArrayElem(dataType, TEST_U16_ELEM_DATA, i, &data[i],
463             DEFAULT_UINT16_MAX);
464         if ((ret != HDF_SUCCESS) || (data[i] != testData[i])) {
465             return HDF_FAILURE;
466         }
467     }
468     return HDF_SUCCESS;
469 }
470 
HcsTestGetUint16ArrayElemFail(void)471 int HcsTestGetUint16ArrayElemFail(void)
472 {
473     const struct DeviceResourceNode *dataType = NULL;
474     uint16_t data1[DATA_TYPE_NUM_U64] = { 0 };
475     uint16_t data;
476     int32_t i;
477     int32_t ret;
478     int32_t count;
479     if (!TestGetRootNode()) {
480         return HDF_FAILURE;
481     }
482     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
483     ret = g_devResInstance->GetUint16ArrayElem(dataType, TEST_U16_ELEM_DATA, DATA_TEST_ARRAY_LENGTH, &data,
484         DEFAULT_UINT16_MAX);
485     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT16_MAX)) {
486         return HDF_FAILURE;
487     }
488     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
489     count = g_devResInstance->GetElemNum(dataType, READ_FOUR_DATA_TYPE);
490     if (count != DATA_TYPE_NUM_U64) {
491         return HDF_FAILURE;
492     }
493     for (i = 0; i < count; i++) {
494         ret = g_devResInstance->GetUint16ArrayElem(dataType, READ_FOUR_DATA_TYPE, i, &data1[i], DEFAULT_UINT16_MAX);
495     }
496     // the 0~3 represents the location in array.
497     if ((ret == HDF_SUCCESS) || (data1[INDEX_NUM_ZERO] != U8_DATA) || (data1[INDEX_NUM_ONE] != U16_DATA) ||
498         (data1[INDEX_NUM_TWO] != DEFAULT_UINT16_MAX) || (data1[INDEX_NUM_THREE] != DEFAULT_UINT16_MAX)) {
499         return HDF_FAILURE;
500     }
501     return HDF_SUCCESS;
502 }
503 
HcsTestGetUint16ArraySuccess(void)504 int HcsTestGetUint16ArraySuccess(void)
505 {
506     const struct DeviceResourceNode *dataType = NULL;
507     uint16_t data[DATA_TEST_ARRAY_LENGTH] = { 0 };
508     int32_t ret;
509     if (!TestGetRootNode()) {
510         return HDF_FAILURE;
511     }
512     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
513     ret = g_devResInstance->GetUint16Array(dataType, TEST_U16_ELEM_DATA, data, DATA_TEST_ARRAY_LENGTH,
514         DEFAULT_UINT16_MAX);
515     // the data[0~7] represents the location in array, the test data is 0, 1, 2, 3, 4, 5, 256, 257.
516     if ((ret != HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != TEST_DATA_ZERO) || (data[INDEX_NUM_ONE] != TEST_DATA_ONE) ||
517         (data[INDEX_NUM_TWO] != TEST_DATA_TWO) || (data[INDEX_NUM_THREE] != TEST_DATA_THREE) ||
518         (data[INDEX_NUM_FOUR] != TEST_DATA_FOUR) ||
519         (data[INDEX_NUM_FIVE] != TEST_DATA_FIVE) || (data[INDEX_NUM_SIX] != TEST_DATA_256) ||
520         (data[INDEX_NUM_SEVEN] != TEST_DATA_257)) {
521         return HDF_FAILURE;
522     }
523     return HDF_SUCCESS;
524 }
525 
HcsTestGetUint16ArrayFail(void)526 int HcsTestGetUint16ArrayFail(void)
527 {
528     const struct DeviceResourceNode *dataType = NULL;
529     uint16_t data[DATA_TYPE_NUM_U64 + 1] = { 0 };
530     int32_t ret;
531     if (!TestGetRootNode()) {
532         return HDF_FAILURE;
533     }
534     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
535     ret = g_devResInstance->GetUint16Array(dataType, READ_FOUR_DATA_TYPE, data, 0, DEFAULT_UINT16_MAX);
536     // the 0, 1, 2 represents the location in array, the 0 of second param is default value.
537     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != TEST_DATA_ZERO) || (data[INDEX_NUM_ONE] != TEST_DATA_ZERO) ||
538         (data[INDEX_NUM_TWO] != TEST_DATA_ZERO)) {
539         return HDF_FAILURE;
540     }
541     ret = g_devResInstance->GetUint16Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64 + 1,
542         DEFAULT_UINT16_MAX);
543     // the 0, 1, 2, 3, 4 represents the location in array
544     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != U8_DATA) || (data[INDEX_NUM_ONE] != U16_DATA) ||
545         (data[INDEX_NUM_TWO] != DEFAULT_UINT16_MAX) || (data[INDEX_NUM_THREE] != DEFAULT_UINT16_MAX) ||
546         (data[INDEX_NUM_FOUR] != DEFAULT_UINT16_MAX)) {
547         return HDF_FAILURE;
548     }
549     return HDF_SUCCESS;
550 }
551 
HcsTestGetUint32AttrValueSuccess(void)552 int HcsTestGetUint32AttrValueSuccess(void)
553 {
554     const struct DeviceResourceNode *audioNode = NULL;
555     uint32_t data;
556     int32_t ret;
557     if (!TestGetRootNode()) {
558         return HDF_FAILURE;
559     }
560     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
561     ret = g_devResInstance->GetUint32(audioNode, SMARTPA_NUM, &data, DEFAULT_UINT32_MAX);
562     if ((ret != HDF_SUCCESS) || (data != U8_DATA)) {
563         HDF_LOGE("%s failed, line: %d, ret = %d, data = %u", __FUNCTION__, __LINE__, ret, data);
564         return HDF_FAILURE;
565     }
566     ret = g_devResInstance->GetUint32(audioNode, VOICE_VOL_LEVEL, &data, DEFAULT_UINT32_MAX);
567     if ((ret != HDF_SUCCESS) || (data != U16_DATA)) {
568         HDF_LOGE("%s failed, line: %d", __FUNCTION__, __LINE__);
569         return HDF_FAILURE;
570     }
571     ret = g_devResInstance->GetUint32(audioNode, SMARTPA_ADDR, &data, DEFAULT_UINT32_MAX);
572     if ((ret != HDF_SUCCESS) || (data != U32_DATA)) {
573         HDF_LOGE("%s failed, line: %d", __FUNCTION__, __LINE__);
574         return HDF_FAILURE;
575     }
576     return HDF_SUCCESS;
577 }
578 
HcsTestGetUint32AttrValueFail(void)579 int HcsTestGetUint32AttrValueFail(void)
580 {
581     const struct DeviceResourceNode *audioNode = NULL;
582     uint32_t data;
583     int32_t ret;
584     if (!TestGetRootNode()) {
585         return HDF_FAILURE;
586     }
587     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
588     ret = g_devResInstance->GetUint32(audioNode, INVALID_STRING, &data, DEFAULT_UINT32_MAX);
589     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT32_MAX)) {
590         return HDF_FAILURE;
591     }
592     ret = g_devResInstance->GetUint32(audioNode, SMARTPA_ADDR, NULL, DEFAULT_UINT32_MAX);
593     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT32_MAX)) {
594         return HDF_FAILURE;
595     }
596     return HDF_SUCCESS;
597 }
598 
HcsTestGetUint32ArrayElemSuccess(void)599 int HcsTestGetUint32ArrayElemSuccess(void)
600 {
601     const struct DeviceResourceNode *fingerNode = NULL;
602     uint32_t data[DATA_TYPE_NUM_U32] = { 0 };
603     const uint32_t testData[DATA_TYPE_NUM_U32] = { U8_DATA, U16_DATA, U32_DATA };
604     int32_t i;
605     int32_t count;
606     if (!TestGetRootNode()) {
607         return HDF_FAILURE;
608     }
609     fingerNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_FINGERPRINT_INFO);
610     count = g_devResInstance->GetElemNum(fingerNode, READ_U32_INDEX);
611     if (count != DATA_TYPE_NUM_U32) {
612         return HDF_FAILURE;
613     }
614     for (i = 0; i < count; i++) {
615         int32_t ret = g_devResInstance->GetUint32ArrayElem(fingerNode, READ_U32_INDEX, i, &data[i],
616                                                            DEFAULT_UINT32_MAX);
617         if ((ret != HDF_SUCCESS) || (data[i] != testData[i])) {
618             return HDF_FAILURE;
619         }
620     }
621     return HDF_SUCCESS;
622 }
623 
HcsTestGetUint32ArrayElemFail(void)624 int HcsTestGetUint32ArrayElemFail(void)
625 {
626     const struct DeviceResourceNode *fingerNode = NULL;
627     uint32_t data;
628     int32_t ret;
629     if (!TestGetRootNode()) {
630         return HDF_FAILURE;
631     }
632     fingerNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_FINGERPRINT_INFO);
633     ret = g_devResInstance->GetUint32ArrayElem(fingerNode, READ_U32_INDEX, DATA_TYPE_NUM_U32, &data,
634         DEFAULT_UINT32_MAX);
635     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT32_MAX)) {
636         return HDF_FAILURE;
637     }
638     return HDF_SUCCESS;
639 }
640 
HcsTestGetUint32ArraySuccess(void)641 int HcsTestGetUint32ArraySuccess(void)
642 {
643     uint32_t data[BOARDID_LENGTH] = { 0 };
644     int32_t ret;
645     if (!TestGetRootNode()) {
646         return HDF_FAILURE;
647     }
648     ret = g_devResInstance->GetUint32Array(g_testRoot, BOARD_ID, data, BOARDID_LENGTH, DEFAULT_UINT32_MAX);
649     // the 0, 1 represents the location in array.
650     if ((ret != HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != U32_DATA) || (data[INDEX_NUM_ONE] != U16_DATA)) {
651         return HDF_FAILURE;
652     }
653     return HDF_SUCCESS;
654 }
655 
HcsTestGetUint32ArrayFail(void)656 int HcsTestGetUint32ArrayFail(void)
657 {
658     uint32_t data[DATA_TYPE_NUM_U32] = { 0 };
659     int32_t ret;
660     if (!TestGetRootNode()) {
661         return HDF_FAILURE;
662     }
663     ret = g_devResInstance->GetUint32Array(g_testRoot, BOARD_ID, data, 0, DEFAULT_UINT32_MAX);
664     // the 0, 1, 2 represents the location in array, the 0 of second param is default value.
665     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != TEST_DATA_ZERO) || (data[INDEX_NUM_ONE] != TEST_DATA_ZERO) ||
666         (data[INDEX_NUM_TWO] != TEST_DATA_ZERO)) {
667         return HDF_FAILURE;
668     }
669     ret = g_devResInstance->GetUint32Array(g_testRoot, BOARD_ID, data, DATA_TYPE_NUM_U32, DEFAULT_UINT32_MAX);
670     // the 0, 1, 2 represents the location in array
671     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != U32_DATA) || (data[INDEX_NUM_ONE] != U16_DATA) ||
672         (data[INDEX_NUM_TWO] != DEFAULT_UINT32_MAX)) {
673         return HDF_FAILURE;
674     }
675     return HDF_SUCCESS;
676 }
677 
HcsTestGetUint64AttrValueSuccess(void)678 int HcsTestGetUint64AttrValueSuccess(void)
679 {
680     const struct DeviceResourceNode *audioNode = NULL;
681     uint64_t data;
682     int32_t ret;
683     if (!TestGetRootNode()) {
684         return HDF_FAILURE;
685     }
686     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
687     ret = g_devResInstance->GetUint64(audioNode, SMARTPA_NUM, &data, DEFAULT_UINT32_MAX);
688     if ((ret != HDF_SUCCESS) || (data != U8_DATA)) {
689         HDF_LOGE("%s failed, line: %d", __FUNCTION__, __LINE__);
690         return HDF_FAILURE;
691     }
692     ret = g_devResInstance->GetUint64(audioNode, VOICE_VOL_LEVEL, &data, DEFAULT_UINT32_MAX);
693     if ((ret != HDF_SUCCESS) || (data != U16_DATA)) {
694         HDF_LOGE("%s failed, line: %d", __FUNCTION__, __LINE__);
695         return HDF_FAILURE;
696     }
697     ret = g_devResInstance->GetUint64(audioNode, SMARTPA_ADDR, &data, DEFAULT_UINT32_MAX);
698     if ((ret != HDF_SUCCESS) || (data != U32_DATA)) {
699         HDF_LOGE("%s failed, line: %d", __FUNCTION__, __LINE__);
700         return HDF_FAILURE;
701     }
702     ret = g_devResInstance->GetUint64(audioNode, READ_U64DATA, &data, DEFAULT_UINT64_MAX);
703     if ((ret != HDF_SUCCESS) || (data != U64_DATA)) {
704         HDF_LOGE("%s failed, line: %d", __FUNCTION__, __LINE__);
705         return HDF_FAILURE;
706     }
707     return HDF_SUCCESS;
708 }
709 
HcsTestGetUint64AttrValueFail(void)710 int HcsTestGetUint64AttrValueFail(void)
711 {
712     const struct DeviceResourceNode *audioNode = NULL;
713     uint64_t data;
714     int32_t ret;
715     if (!TestGetRootNode()) {
716         return HDF_FAILURE;
717     }
718     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
719     ret = g_devResInstance->GetUint64(audioNode, INVALID_STRING, &data, DEFAULT_UINT64_MAX);
720     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT64_MAX)) {
721         return HDF_FAILURE;
722     }
723     ret = g_devResInstance->GetUint64(audioNode, READ_U64DATA, NULL, DEFAULT_UINT64_MAX);
724     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT64_MAX)) {
725         return HDF_FAILURE;
726     }
727     return HDF_SUCCESS;
728 }
729 
HcsTestGetUint64ArrayElemSuccess(void)730 int HcsTestGetUint64ArrayElemSuccess(void)
731 {
732     const struct DeviceResourceNode *dataType = NULL;
733     uint64_t data[DATA_TYPE_NUM_U64] = { 0 };
734     const uint64_t testData[DATA_TYPE_NUM_U64] = { U8_DATA, U16_DATA, U32_DATA, U64_DATA };
735     int32_t i;
736     int32_t count;
737     if (!TestGetRootNode()) {
738         return HDF_FAILURE;
739     }
740     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
741     count = g_devResInstance->GetElemNum(dataType, READ_FOUR_DATA_TYPE);
742     if (count != DATA_TYPE_NUM_U64) {
743         return HDF_FAILURE;
744     }
745     for (i = 0; i < count; i++) {
746         int32_t ret = g_devResInstance->GetUint64ArrayElem(dataType, READ_FOUR_DATA_TYPE, i, &data[i],
747             DEFAULT_UINT64_MAX);
748         if ((ret != HDF_SUCCESS) || (data[i] != testData[i])) {
749             return HDF_FAILURE;
750         }
751     }
752     return HDF_SUCCESS;
753 }
754 
HcsTestGetUint64ArrayElemFail(void)755 int HcsTestGetUint64ArrayElemFail(void)
756 {
757     const struct DeviceResourceNode *dataType = NULL;
758     uint64_t data;
759     int32_t ret;
760     if (!TestGetRootNode()) {
761         return HDF_FAILURE;
762     }
763     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
764     ret = g_devResInstance->GetUint64ArrayElem(dataType, READ_FOUR_DATA_TYPE, DATA_TYPE_NUM_U64, &data,
765         DEFAULT_UINT64_MAX);
766     if ((ret == HDF_SUCCESS) || (data != DEFAULT_UINT64_MAX)) {
767         return HDF_FAILURE;
768     }
769     return HDF_SUCCESS;
770 }
771 
HcsTestGetUint64ArraySuccess(void)772 int HcsTestGetUint64ArraySuccess(void)
773 {
774     const struct DeviceResourceNode *dataType = NULL;
775     uint64_t data[DATA_TYPE_NUM_U64] = { 0 };
776     int32_t ret;
777     if (!TestGetRootNode()) {
778         return HDF_FAILURE;
779     }
780     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
781     ret = g_devResInstance->GetUint64Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64,
782         DEFAULT_UINT64_MAX);
783     // the 0, 1, 2 represents the location in array.
784     if ((ret != HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != U8_DATA) || (data[INDEX_NUM_ONE] != U16_DATA) ||
785         (data[INDEX_NUM_TWO] != U32_DATA) || (data[INDEX_NUM_THREE] != U64_DATA)) {
786         return HDF_FAILURE;
787     }
788     return HDF_SUCCESS;
789 }
790 
HcsTestGetUint64ArrayFail(void)791 int HcsTestGetUint64ArrayFail(void)
792 {
793     const struct DeviceResourceNode *dataType = NULL;
794     uint64_t data[DATA_TYPE_NUM_U64 + 1] = { 0 };
795     int32_t ret;
796     if (!TestGetRootNode()) {
797         return HDF_FAILURE;
798     }
799     dataType = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_DATA_TYPE_TEST);
800     ret = g_devResInstance->GetUint64Array(dataType, READ_FOUR_DATA_TYPE, data, 0, DEFAULT_UINT64_MAX);
801     // the 0, 1, 2 represents the location in array, the 0 of second param is default value.
802     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != TEST_DATA_ZERO) || (data[INDEX_NUM_ONE] != TEST_DATA_ZERO) ||
803         (data[INDEX_NUM_TWO] != TEST_DATA_ZERO)) {
804         return HDF_FAILURE;
805     }
806     ret = g_devResInstance->GetUint64Array(dataType, READ_FOUR_DATA_TYPE, data, DATA_TYPE_NUM_U64 + 1,
807         DEFAULT_UINT64_MAX);
808     // the 0, 1, 2, 3, 4 represents the location in array
809     if ((ret == HDF_SUCCESS) || (data[INDEX_NUM_ZERO] != U8_DATA) || (data[INDEX_NUM_ONE] != U16_DATA) ||
810         (data[INDEX_NUM_TWO] != U32_DATA) || (data[INDEX_NUM_THREE] != U64_DATA) ||
811         (data[INDEX_NUM_FOUR] != DEFAULT_UINT64_MAX)) {
812         return HDF_FAILURE;
813     }
814     return HDF_SUCCESS;
815 }
816 
HcsTestGetElemNumSuccess(void)817 int HcsTestGetElemNumSuccess(void)
818 {
819     const struct DeviceResourceNode *fingerNode = NULL;
820     int32_t count;
821     if (!TestGetRootNode()) {
822         return HDF_FAILURE;
823     }
824     count = g_devResInstance->GetElemNum(g_testRoot, BOARD_ID);
825     if (count != BOARDID_LENGTH) {
826         return HDF_FAILURE;
827     }
828     fingerNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_FINGERPRINT_INFO);
829     count = g_devResInstance->GetElemNum(fingerNode, READ_U32_INDEX);
830     if (count != DATA_TYPE_NUM_U32) {
831         return HDF_FAILURE;
832     }
833     count = g_devResInstance->GetElemNum(fingerNode, STRING_LIST_NAMES);
834     if (count != DATA_TYPE_NUM_U32) {
835         return HDF_FAILURE;
836     }
837     return HDF_SUCCESS;
838 }
839 
HcsTestGetElemNumFail(void)840 int HcsTestGetElemNumFail(void)
841 {
842     const struct DeviceResourceNode *fingerNode = NULL;
843     int32_t count;
844     if (!TestGetRootNode()) {
845         return HDF_FAILURE;
846     }
847     fingerNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_FINGERPRINT_INFO);
848     // the dual_fingerprint attr do not array, so the count is HDF_FAILURE.
849     count = g_devResInstance->GetElemNum(fingerNode, DUAL_FINGERPRINT);
850     if (count != HDF_FAILURE) {
851         return HDF_FAILURE;
852     }
853     // the NULL attr is not exist, so the count is HDF_FAILURE.
854     count = g_devResInstance->GetElemNum(fingerNode, INVALID_STRING);
855     if (count != HDF_FAILURE) {
856         return HDF_FAILURE;
857     }
858     return HDF_SUCCESS;
859 }
860 
HcsTestGetChildNodeSuccess(void)861 int HcsTestGetChildNodeSuccess(void)
862 {
863     const struct DeviceResourceNode *audioNode = NULL;
864     const struct DeviceResourceNode *fingerprintNode = NULL;
865     const struct DeviceResourceNode *oneNode = NULL;
866     if (!TestGetRootNode()) {
867         return HDF_FAILURE;
868     }
869     audioNode = g_devResInstance->GetChildNode(g_testRoot, AUDIO_INFO);
870     if (audioNode == NULL) {
871         return HDF_FAILURE;
872     }
873     fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
874     if (fingerprintNode == NULL) {
875         return HDF_FAILURE;
876     }
877     oneNode = g_devResInstance->GetChildNode(fingerprintNode, "fingerprint_one");
878     if (oneNode == NULL) {
879         return HDF_FAILURE;
880     }
881     return HDF_SUCCESS;
882 }
883 
HcsTestGetChildNodeFail(void)884 int HcsTestGetChildNodeFail(void)
885 {
886     const struct DeviceResourceNode *twoNode = NULL;
887     const struct DeviceResourceNode *nullNode = NULL;
888     if (!TestGetRootNode()) {
889         return HDF_FAILURE;
890     }
891     twoNode = g_devResInstance->GetChildNode(g_testRoot, "fingerprint_two");
892     if (twoNode != NULL) {
893         return HDF_FAILURE;
894     }
895     nullNode = g_devResInstance->GetChildNode(g_testRoot, INVALID_NODE);
896     if (nullNode != NULL) {
897         return HDF_FAILURE;
898     }
899     nullNode = g_devResInstance->GetChildNode(NULL, INVALID_NODE);
900     if (nullNode != NULL) {
901         return HDF_FAILURE;
902     }
903     nullNode = g_devResInstance->GetChildNode(g_testRoot, NULL);
904     if (nullNode != NULL) {
905         return HDF_FAILURE;
906     }
907     return HDF_SUCCESS;
908 }
909 
HcsTestTraverseAttrInNodeSuccess(void)910 int HcsTestTraverseAttrInNodeSuccess(void)
911 {
912     const struct DeviceResourceNode *audioNode = NULL;
913     struct DeviceResourceAttr *pp = NULL;
914     if (!TestGetRootNode()) {
915         return HDF_FAILURE;
916     }
917     audioNode = g_devResInstance->GetChildNode(g_testRoot, AUDIO_INFO);
918     if (audioNode == NULL) {
919         return HDF_FAILURE;
920     }
921     DEV_RES_NODE_FOR_EACH_ATTR(audioNode, pp) {
922         if ((pp == NULL) || (pp->name == NULL)) {
923             break;
924         }
925         if (strncmp(pp->name, "dual_smartpa_delay", strlen("dual_smartpa_delay")) != 0) {
926             continue;
927         } else {
928             break;
929         }
930     }
931     if (pp == NULL) {
932         return HDF_FAILURE;
933     }
934     return HDF_SUCCESS;
935 }
936 
HcsTestTraverseAttrInNodeFail(void)937 int HcsTestTraverseAttrInNodeFail(void)
938 {
939     const struct DeviceResourceNode *fingerprintNode = NULL;
940     struct DeviceResourceAttr *pp = NULL;
941     const struct DeviceResourceNode *childNode = NULL;
942     if (!TestGetRootNode()) {
943         return HDF_FAILURE;
944     }
945     fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
946     if (fingerprintNode == NULL) {
947         return HDF_FAILURE;
948     }
949     DEV_RES_NODE_FOR_EACH_ATTR(fingerprintNode, pp) {
950         if ((pp == NULL) || (pp->name == NULL)) {
951             break;
952         }
953         if (strncmp(pp->name, "dual-fingerprint", strlen("dual-fingerprint")) != 0) {
954             continue;
955         } else {
956             break;
957         }
958     }
959     if (pp != NULL) {
960         return HDF_FAILURE;
961     }
962 
963     DEV_RES_NODE_FOR_EACH_CHILD_NODE(fingerprintNode, childNode) {
964         if ((childNode == NULL) || (childNode->name == NULL)) {
965             break;
966         }
967         if ((strcmp(childNode->name, "fingerprint_one") == 0) || (strcmp(childNode->name, "fingerprint_two") == 0)) {
968             HDF_LOGE("%s: childNode->name is %s", __FUNCTION__, childNode->name);
969             continue;
970         } else {
971             HDF_LOGE("%s: failed, childNode->name is %s", __FUNCTION__, childNode->name);
972             return HDF_FAILURE;
973         }
974     }
975 
976     return HDF_SUCCESS;
977 }
978 
HcsTestGetStringSuccess(void)979 int HcsTestGetStringSuccess(void)
980 {
981     const struct DeviceResourceNode *audioNode = NULL;
982     const char *type = NULL;
983     int32_t readString;
984     if (!TestGetRootNode()) {
985         return HDF_FAILURE;
986     }
987     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
988     readString = g_devResInstance->GetString(audioNode, "cust_name", &type, NULL);
989     if ((readString != HDF_SUCCESS) || (type == NULL) || (strcmp(type, "audio_custom_v2") != HDF_SUCCESS)) {
990         return HDF_FAILURE;
991     }
992     return HDF_SUCCESS;
993 }
994 
HcsTestGetStringFail(void)995 int HcsTestGetStringFail(void)
996 {
997     const struct DeviceResourceNode *audioNode = NULL;
998     const char *type = NULL;
999     int32_t testReadString;
1000     if (!TestGetRootNode()) {
1001         return HDF_FAILURE;
1002     }
1003     audioNode = g_devResInstance->GetNodeByMatchAttr(g_testRoot, HW_AUDIO_INFO);
1004     testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, &type, STRING_ATTR_VALUE);
1005     if ((testReadString == HDF_SUCCESS) || (type == NULL) || (strcmp(type, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
1006         return HDF_FAILURE;
1007     }
1008     testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, NULL, STRING_ATTR_VALUE);
1009     if ((testReadString == HDF_SUCCESS) || (type == NULL) || (strcmp(type, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
1010         return HDF_FAILURE;
1011     }
1012     testReadString = g_devResInstance->GetString(audioNode, INVALID_STRING, &type, NULL);
1013     if ((testReadString == HDF_SUCCESS) || (type != NULL)) {
1014         return HDF_FAILURE;
1015     }
1016     return HDF_SUCCESS;
1017 }
1018 
HcsTestGetStringArrayElemSuccess(void)1019 int HcsTestGetStringArrayElemSuccess(void)
1020 {
1021     const char *rawDataDts = NULL;
1022     const struct DeviceResourceNode *fingerprintNode = NULL;
1023     int32_t ret;
1024     if (!TestGetRootNode()) {
1025         return HDF_FAILURE;
1026     }
1027     fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
1028     // the third param(0) is the location in string_list_names array.
1029     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 0, &rawDataDts, NULL);
1030     if ((ret != HDF_SUCCESS) || (strcmp(rawDataDts, "first") != HDF_SUCCESS)) {
1031         return HDF_FAILURE;
1032     }
1033     // the third param(1) is the location in string_list_names array.
1034     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 1, &rawDataDts, NULL);
1035     if ((ret != HDF_SUCCESS) || (strcmp(rawDataDts, "second") != HDF_SUCCESS)) {
1036         return HDF_FAILURE;
1037     }
1038     // the third param(2) is the location in string_list_names array.
1039     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 2, &rawDataDts, NULL);
1040     if ((ret != HDF_SUCCESS) || (strcmp(rawDataDts, "third") != HDF_SUCCESS)) {
1041         return HDF_FAILURE;
1042     }
1043     return HDF_SUCCESS;
1044 }
1045 
HcsTestGetStringArrayElemFail(void)1046 int HcsTestGetStringArrayElemFail(void)
1047 {
1048     const char *rawDataDts = NULL;
1049     const struct DeviceResourceNode *fingerprintNode = NULL;
1050     int32_t ret;
1051     if (!TestGetRootNode()) {
1052         return HDF_FAILURE;
1053     }
1054     fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
1055     // the third param(3) is the location in string_list_names array.
1056     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 3, &rawDataDts, STRING_ATTR_VALUE);
1057     if ((ret == HDF_SUCCESS) || (strcmp(rawDataDts, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
1058         return HDF_FAILURE;
1059     }
1060 
1061     // the third param(1) is the location in string_list_names array.
1062     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, READ_U32_INDEX, 1, &rawDataDts, STRING_ATTR_VALUE);
1063     if ((ret == HDF_SUCCESS) || (strcmp(rawDataDts, STRING_ATTR_VALUE) != HDF_SUCCESS)) {
1064         return HDF_FAILURE;
1065     }
1066     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 1, NULL, STRING_ATTR_VALUE);
1067     if (ret == HDF_SUCCESS) {
1068         return HDF_FAILURE;
1069     }
1070     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, STRING_LIST_NAMES, 1, &rawDataDts, NULL);
1071     if (ret != HDF_SUCCESS) {
1072         return HDF_FAILURE;
1073     }
1074     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, READ_U32_INDEX, 1, NULL, STRING_ATTR_VALUE);
1075     if (ret == HDF_SUCCESS) {
1076         return HDF_FAILURE;
1077     }
1078     ret = g_devResInstance->GetStringArrayElem(fingerprintNode, READ_U32_INDEX, 1, &rawDataDts, NULL);
1079     if ((ret == HDF_SUCCESS) || (rawDataDts != NULL)) {
1080         return HDF_FAILURE;
1081     }
1082     return HDF_SUCCESS;
1083 }
1084 
HcsTestGetNodeAttrRefSuccess(void)1085 int HcsTestGetNodeAttrRefSuccess(void)
1086 {
1087     const struct DeviceResourceNode *fingerprintNode = NULL;
1088     const struct DeviceResourceNode *ret = NULL;
1089     if (!TestGetRootNode()) {
1090         return HDF_FAILURE;
1091     }
1092     fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
1093     ret = g_devResInstance->GetNodeByRefAttr(fingerprintNode, FINGER_INFO);
1094     if (ret == NULL) {
1095         return HDF_FAILURE;
1096     }
1097     ret = g_devResInstance->GetNodeByRefAttr(fingerprintNode, AUDIO_INFO);
1098     if (ret == NULL) {
1099         return HDF_FAILURE;
1100     }
1101     return HDF_SUCCESS;
1102 }
1103 
HcsTestGetNodeAttrRefFail(void)1104 int HcsTestGetNodeAttrRefFail(void)
1105 {
1106     const struct DeviceResourceNode *fingerprintNode = NULL;
1107     const struct DeviceResourceNode *ret = NULL;
1108     if (!TestGetRootNode()) {
1109         return HDF_FAILURE;
1110     }
1111     fingerprintNode = g_devResInstance->GetChildNode(g_testRoot, FINGERPRINT_INFO);
1112     ret = g_devResInstance->GetNodeByRefAttr(fingerprintNode, DUAL_FINGERPRINT);
1113     if (ret != NULL) {
1114         return HDF_FAILURE;
1115     }
1116     ret = g_devResInstance->GetNodeByRefAttr(NULL, DUAL_FINGERPRINT);
1117     if (ret != NULL) {
1118         return HDF_FAILURE;
1119     }
1120     ret = g_devResInstance->GetNodeByRefAttr(fingerprintNode, NULL);
1121     if (ret != NULL) {
1122         return HDF_FAILURE;
1123     }
1124     ret = g_devResInstance->GetNodeByRefAttr(NULL, FINGER_INFO);
1125     if (ret != NULL) {
1126         return HDF_FAILURE;
1127     }
1128     return HDF_SUCCESS;
1129 }