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 "hdf_log.h"
10 #include "hcs_macro.h"
11 #include "hdf_macro_test.h"
12
13 #define HDF_LOG_TAG hcs_macro_cases
14
15 #define AUDIO_INFO_NODE_SMARTPA_ADDR 65536
16 #define AUDIO_INFO_NODE_SMARTPA_NUM 1
17 #define AUDIO_INFO_NODE_BUILDIN_PRIMARY_MIC_EXIST 1
18 #define AUDIO_INFO_NODE_BUILDIN_SECOND_MIC_EXIST 1
19 #define AUDIO_INFO_NODE_VOICE_LEVEL 256
20 #define AUDIO_INFO_NODE_U64_DATA 0x100000000
21 #define FP_NODE_U32_IDX_SIZE 3
22 #define FP_INFO_NODE_STR_LIST_SIZE 3
23 #define DATA_TEST_NODE_FOUR_DATA_SIZE 4
24 #define DATA_TEST_NODE_U8_DATA_SIZE 8
25 #define DATA_TEST_NODE_U16_DATA_SIZE 8
26 #define BOARD_ID_DATA_SIZE 2
27 #define MODEM_ID_DATA_SIZE 2
28 #define BOARD_ID_VALUE 8000
29 #define FP_ONE_IDX 0
30 #define FP_TWO_IDX 1
31 #define FP_THREE_IDX 2
32
33 #define CHECK_STRING_EQU(part1, part2) \
34 if (strcmp(part1, part2)) { \
35 HDF_LOGE("%s %s %d\n", part1, part2, __LINE__); \
36 return HDF_FAILURE; \
37 }
38
39 #define CHECK_INT_EQU(part1, part2) \
40 if ((part1) != (part2)) { \
41 HDF_LOGE("%d\n", __LINE__); \
42 return HDF_FAILURE; \
43 }
44
45 #define FP_CHILD_DEAL(node) \
46 CHECK_STRING_EQU(HCS_PROP(node, status), g_fpData[index].child.status)
47
48 #define FP_DEAL(node) \
49 do { \
50 CHECK_STRING_EQU(HCS_PROP(node, product), g_fpData[index].product); \
51 CHECK_STRING_EQU(HCS_PROP(node, chip), g_fpData[index].chip); \
52 node##_foreach_child(FP_CHILD_DEAL); \
53 CHECK_STRING_EQU(HCS_PROP(node, status), g_fpData[index].status); \
54 index++; \
55 } while (0)
56
57 #define FP_DEAL_(node) FP_DEAL(node)
58
59 #define FP_CHILD_DEAL_VARGS(node, fpArgs, idx) \
60 CHECK_STRING_EQU(HCS_PROP(node, status), (fpArgs)[idx].child.status)
61
62 #define FP_DEAL_VARGS(node, fpArgs, idx) \
63 do { \
64 CHECK_STRING_EQU(HCS_PROP(node, product), (fpArgs)[(idx)].product); \
65 CHECK_STRING_EQU(HCS_PROP(node, chip), (fpArgs)[(idx)].chip); \
66 node##_foreach_child_vargs(FP_CHILD_DEAL_VARGS, fpArgs, idx); \
67 CHECK_STRING_EQU(HCS_PROP(node, status), (fpArgs)[(idx)].status); \
68 (idx)++; \
69 } while (0)
70
71 #define FP_DEAL_VARGS_(node, fpArgs, idx) FP_DEAL_VARGS(node, fpArgs, idx)
72
73 struct OneChild {
74 const char *status;
75 };
76 struct FingerPrint {
77 const char *product;
78 const char *chip;
79 struct OneChild child;
80 const char *status;
81 };
82
83 #define AUDIO_INFO_NODE HCS_NODE(HCS_ROOT, audio_info)
84 #define FP_INFO_NODE HCS_NODE(HCS_ROOT, fingerprint_info)
85 #define FP_INFO_ONE_NODE HCS_NODE(FP_INFO_NODE, fingerprint_one)
86 #define FP_INFO_TWO_NODE HCS_NODE(FP_INFO_NODE, fingerprint_two)
87 #define DATA_TYPE_TEST_NODE HCS_NODE(HCS_ROOT, data_type_test)
88 #define FP_INFO_THREE_NODE HCS_NODE(HCS_ROOT, fingerprint_three)
89 #define FP_INFO_AUDIO_NODE HCS_NODE(FP_INFO_NODE, audio_info)
90
91 static struct FingerPrint g_fpData[] = {
92 { "test", "one", { "ok" }, "ok" },
93 { "test", "two", { "ok" }, "disable" },
94 { "test", "three", { "ok" }, "disable" }
95 };
96
TraversalInfoReadU32(void)97 static int TraversalInfoReadU32(void)
98 {
99 const uint32_t infoReadU32[] = { 1, 256, 65536 };
100 const uint32_t infoReadU32Gen[] = HCS_ARRAYS(HCS_NODE(FP_INFO_NODE, read_u32_index));
101 int i;
102
103 for (i = 0; i < HCS_ARRAYS_SIZE(HCS_NODE(FP_INFO_NODE, read_u32_index)); i++) {
104 CHECK_INT_EQU(infoReadU32Gen[i], infoReadU32[i]);
105 }
106
107 return HDF_SUCCESS;
108 }
109
TraversalStringListNames(void)110 static int TraversalStringListNames(void)
111 {
112 const char *stringListNames[] = {"first", "second", "third"};
113 const char *stringListNamesGen[] = HCS_ARRAYS(HCS_NODE(FP_INFO_NODE, string_list_names));
114 int i;
115
116 for (i = 0; i < HCS_ARRAYS_SIZE(HCS_NODE(FP_INFO_NODE, string_list_names)); i++) {
117 CHECK_STRING_EQU(stringListNamesGen[i], stringListNames[i]);
118 }
119
120 return HDF_SUCCESS;
121 }
122
TraversalReadFourDatas(void)123 static int TraversalReadFourDatas(void)
124 {
125 const uint64_t readFourDatas[] = { 0x1, 0x100, 0x10000, 0x100000000 };
126 const uint64_t readFourDatasGen[] = HCS_ARRAYS(HCS_NODE(DATA_TYPE_TEST_NODE, read_four_data_type));
127 int i;
128
129 for (i = 0; i < HCS_ARRAYS_SIZE(HCS_NODE(DATA_TYPE_TEST_NODE, read_four_data_type)); i++) {
130 CHECK_INT_EQU(readFourDatasGen[i], readFourDatas[i]);
131 }
132
133 return HDF_SUCCESS;
134 }
135
TraversalTestU8ElemData(void)136 static int TraversalTestU8ElemData(void)
137 {
138 const uint8_t testU8ElemData[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
139 const uint8_t testU8ElemDataGen[] = HCS_ARRAYS(HCS_NODE(DATA_TYPE_TEST_NODE, test_u8_elem_data));
140 int i;
141
142 for (i = 0; i < HCS_ARRAYS_SIZE(HCS_NODE(DATA_TYPE_TEST_NODE, test_u8_elem_data)); i++) {
143 CHECK_INT_EQU(testU8ElemDataGen[i], testU8ElemData[i]);
144 }
145
146 return HDF_SUCCESS;
147 }
TraversalTestU16ElemData(void)148 static int TraversalTestU16ElemData(void)
149 {
150 const uint16_t testU16ElemData[] = { 0, 1, 2, 3, 4, 5, 256, 257 };
151 const uint16_t testU16ElemDataGen[] = HCS_ARRAYS(HCS_NODE(DATA_TYPE_TEST_NODE, test_u16_elem_data));
152 int i;
153
154 for (i = 0; i < HCS_ARRAYS_SIZE(HCS_NODE(DATA_TYPE_TEST_NODE, test_u16_elem_data)); i++) {
155 CHECK_INT_EQU(testU16ElemDataGen[i], testU16ElemData[i]);
156 }
157
158 return HDF_SUCCESS;
159 }
TraversalBoardId(void)160 static int TraversalBoardId(void)
161 {
162 const uint32_t boardId[] = { 65536, 256 };
163 const uint32_t boardIdGen[] = HCS_ARRAYS(HCS_NODE(HCS_ROOT, board_id));
164 int i;
165
166 for (i = 0; i < HCS_ARRAYS_SIZE(HCS_NODE(HCS_ROOT, board_id)); i++) {
167 CHECK_INT_EQU(boardIdGen[i], boardId[i]);
168 }
169
170 return HDF_SUCCESS;
171 }
TraversalModemId(void)172 static int TraversalModemId(void)
173 {
174 const uint32_t modemId[] = { 0xF6B40136, 0x0 };
175 const uint32_t modemIdGen[] = HCS_ARRAYS(HCS_NODE(HCS_ROOT, modem_id));
176 int i;
177
178 for (i = 0; i < HCS_ARRAYS_SIZE(HCS_NODE(HCS_ROOT, modem_id)); i++) {
179 CHECK_INT_EQU(modemIdGen[i], modemId[i]);
180 }
181
182 return HDF_SUCCESS;
183 }
184
TraversalAudio(void)185 static int TraversalAudio(void)
186 {
187 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, match_attr), "hw,hw_audio_info");
188 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, pa_identifier), "smartpakit");
189 CHECK_INT_EQU(HCS_PROP(AUDIO_INFO_NODE, smartpa_addr), AUDIO_INFO_NODE_SMARTPA_ADDR);
190 CHECK_INT_EQU(HCS_PROP(AUDIO_INFO_NODE, smartpa_num), AUDIO_INFO_NODE_SMARTPA_NUM);
191 CHECK_INT_EQU(HCS_PROP(AUDIO_INFO_NODE, builtin_primary_mic_exist), AUDIO_INFO_NODE_BUILDIN_PRIMARY_MIC_EXIST);
192 CHECK_INT_EQU(HCS_PROP(AUDIO_INFO_NODE, builtin_second_mic_exist), AUDIO_INFO_NODE_BUILDIN_SECOND_MIC_EXIST);
193 CHECK_INT_EQU(HCS_PROP(AUDIO_INFO_NODE, voice_vol_level), AUDIO_INFO_NODE_VOICE_LEVEL);
194 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, cust_name), "audio_custom_v2");
195 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, dual_smartpa_delay), "true");
196 CHECK_INT_EQU(HCS_PROP(AUDIO_INFO_NODE, read_u64data), AUDIO_INFO_NODE_U64_DATA);
197 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, status), "ok");
198
199 return HDF_SUCCESS;
200 }
201
TraversalFPFingerInfo(void)202 static int TraversalFPFingerInfo(void)
203 {
204 int index = FP_ONE_IDX;
205 FP_DEAL_(HCS_NODE(FP_INFO_NODE, finger_info));
206 return HDF_SUCCESS;
207 }
208
TraversalFPAudio(void)209 static int TraversalFPAudio(void)
210 {
211 CHECK_STRING_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, match_attr), "hw,hw_audio_info");
212 CHECK_STRING_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, pa_identifier), "smartpakit");
213 CHECK_INT_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, smartpa_addr), AUDIO_INFO_NODE_SMARTPA_ADDR);
214 CHECK_INT_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, smartpa_num), AUDIO_INFO_NODE_SMARTPA_NUM);
215 CHECK_INT_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, builtin_primary_mic_exist), AUDIO_INFO_NODE_BUILDIN_PRIMARY_MIC_EXIST);
216 CHECK_INT_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, builtin_second_mic_exist), AUDIO_INFO_NODE_BUILDIN_SECOND_MIC_EXIST);
217 CHECK_INT_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, voice_vol_level), AUDIO_INFO_NODE_VOICE_LEVEL);
218 CHECK_STRING_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, cust_name), "audio_custom_v2");
219 CHECK_STRING_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, dual_smartpa_delay), "true");
220 CHECK_INT_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, read_u64data), AUDIO_INFO_NODE_U64_DATA);
221 CHECK_STRING_EQU(HCS_PROP(FP_INFO_AUDIO_NODE, status), "ok");
222 return HDF_SUCCESS;
223 }
224
TraversalFPOne(void)225 static int TraversalFPOne(void)
226 {
227 int index = FP_ONE_IDX;
228 FP_DEAL_(HCS_NODE(FP_INFO_NODE, fingerprint_one));
229 index = FP_ONE_IDX;
230 FP_DEAL_VARGS_(HCS_NODE(FP_INFO_NODE, fingerprint_one), g_fpData, index);
231 return HDF_SUCCESS;
232 }
233
TraversalFPTwo(void)234 static int TraversalFPTwo(void)
235 {
236 int index = FP_TWO_IDX;
237 FP_DEAL_(HCS_NODE(FP_INFO_NODE, fingerprint_two));
238 index = FP_TWO_IDX;
239 FP_DEAL_VARGS_(HCS_NODE(FP_INFO_NODE, fingerprint_two), g_fpData, index);
240 return HDF_SUCCESS;
241 }
242
TraversalPringerprintThree(void)243 static int TraversalPringerprintThree(void)
244 {
245 int index = FP_THREE_IDX;
246 FP_DEAL_(HCS_NODE(HCS_ROOT, fingerprint_three));
247 index = FP_THREE_IDX;
248 FP_DEAL_VARGS_(HCS_NODE(HCS_ROOT, fingerprint_three), g_fpData, index);
249 return HDF_SUCCESS;
250 }
251
TraversalFPInfo(void)252 static int TraversalFPInfo(void)
253 {
254 CHECK_STRING_EQU(HCS_PROP(FP_INFO_NODE, match_attr), "hw,hw_fingerprint_info");
255 CHECK_INT_EQU(TraversalInfoReadU32(), HDF_SUCCESS);
256 CHECK_INT_EQU(TraversalFPFingerInfo(), HDF_SUCCESS);
257 CHECK_INT_EQU(TraversalFPAudio(), HDF_SUCCESS);
258 CHECK_INT_EQU(TraversalFPOne(), HDF_SUCCESS);
259 CHECK_STRING_EQU(HCS_PROP(FP_INFO_NODE, dual_fingerprint), "false");
260 CHECK_INT_EQU(TraversalFPTwo(), HDF_SUCCESS);
261 CHECK_INT_EQU(TraversalStringListNames(), HDF_SUCCESS);
262 CHECK_STRING_EQU(HCS_PROP(FP_INFO_NODE, status), "ok");
263
264 return HDF_SUCCESS;
265 }
266
TraversalDataTypeTest(void)267 static int TraversalDataTypeTest(void)
268 {
269 CHECK_STRING_EQU(HCS_PROP(DATA_TYPE_TEST_NODE, match_attr), "hw,data_type_test");
270 CHECK_INT_EQU(TraversalReadFourDatas(), HDF_SUCCESS);
271 CHECK_INT_EQU(TraversalTestU8ElemData(), HDF_SUCCESS);
272 CHECK_INT_EQU(TraversalTestU16ElemData(), HDF_SUCCESS);
273 return HDF_SUCCESS;
274 }
275
HcsMacroGetOneNode(void)276 int HcsMacroGetOneNode(void)
277 {
278 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, match_attr), "hw,hw_audio_info");
279 return HDF_SUCCESS;
280 }
281
HcsMacroCheckNodeExists(void)282 int HcsMacroCheckNodeExists(void)
283 {
284 #if HCS_NODE_EXISTS(AUDIO_INFO_NODE)
285 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, match_attr), "hw,hw_audio_info");
286 return HDF_SUCCESS;
287 #else
288 return HDF_FAILURE;
289 #endif
290 }
291
HcsMacroCheckNodeNotExists(void)292 int HcsMacroCheckNodeNotExists(void)
293 {
294 #if HCS_NODE_EXISTS(HCS_NODE(AUDIO_INFO_NODE, node_not_exists))
295 return HDF_FAILURE;
296 #else
297 return HDF_SUCCESS;
298 #endif
299 }
300
HcsMacroCheckPropExists(void)301 int HcsMacroCheckPropExists(void)
302 {
303 #if HCS_NODE_HAS_PROP(AUDIO_INFO_NODE, match_attr)
304 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, match_attr), "hw,hw_audio_info");
305 return HDF_SUCCESS;
306 #else
307 return HDF_FAILURE;
308 #endif
309 }
310
HcsMacroCheckPropNotExists(void)311 int HcsMacroCheckPropNotExists(void)
312 {
313 #if HCS_NODE_HAS_PROP(AUDIO_INFO_NODE, prop_not_exists)
314 return HDF_FAILURE;
315 #else
316 return HDF_SUCCESS;
317 #endif
318 }
319
HcsMacroGetOneNodeProp(void)320 int HcsMacroGetOneNodeProp(void)
321 {
322 CHECK_STRING_EQU(HCS_PROP(AUDIO_INFO_NODE, pa_identifier), "smartpakit");
323 return HDF_SUCCESS;
324 }
325
HcsMacroTraversalOneNode(void)326 int HcsMacroTraversalOneNode(void)
327 {
328 return TraversalAudio();
329 }
330
HcsMacroGetArraySize(void)331 int HcsMacroGetArraySize(void)
332 {
333 CHECK_INT_EQU(HCS_ARRAYS_SIZE(HCS_NODE(FP_INFO_NODE, read_u32_index)), FP_NODE_U32_IDX_SIZE);
334 CHECK_INT_EQU(HCS_ARRAYS_SIZE(HCS_NODE(FP_INFO_NODE, string_list_names)), FP_INFO_NODE_STR_LIST_SIZE);
335 CHECK_INT_EQU(HCS_ARRAYS_SIZE(HCS_NODE(DATA_TYPE_TEST_NODE, read_four_data_type)), DATA_TEST_NODE_FOUR_DATA_SIZE);
336 CHECK_INT_EQU(HCS_ARRAYS_SIZE(HCS_NODE(DATA_TYPE_TEST_NODE, test_u8_elem_data)), DATA_TEST_NODE_U8_DATA_SIZE);
337 CHECK_INT_EQU(HCS_ARRAYS_SIZE(HCS_NODE(DATA_TYPE_TEST_NODE, test_u16_elem_data)), DATA_TEST_NODE_U16_DATA_SIZE);
338 CHECK_INT_EQU(HCS_ARRAYS_SIZE(HCS_NODE(HCS_ROOT, board_id)), BOARD_ID_DATA_SIZE);
339 CHECK_INT_EQU(HCS_ARRAYS_SIZE(HCS_NODE(HCS_ROOT, modem_id)), MODEM_ID_DATA_SIZE);
340 return HDF_SUCCESS;
341 }
342
HcsMacroGetArrayElement(void)343 int HcsMacroGetArrayElement(void)
344 {
345 const uint32_t infoReadU32[] = { 1, 256, 65536 };
346 const uint32_t infoReadU32Gen[] = HCS_ARRAYS(HCS_NODE(FP_INFO_NODE, read_u32_index));
347
348 CHECK_INT_EQU(infoReadU32Gen[0], infoReadU32[0]);
349
350 return HDF_SUCCESS;
351 }
352
HcsMacroTraversalOneArray(void)353 int HcsMacroTraversalOneArray(void)
354 {
355 return TraversalInfoReadU32();
356 }
357
HcsMacroTraversalAllArray(void)358 int HcsMacroTraversalAllArray(void)
359 {
360 CHECK_INT_EQU(TraversalInfoReadU32(), HDF_SUCCESS);
361 CHECK_INT_EQU(TraversalStringListNames(), HDF_SUCCESS);
362 CHECK_INT_EQU(TraversalReadFourDatas(), HDF_SUCCESS);
363 CHECK_INT_EQU(TraversalTestU8ElemData(), HDF_SUCCESS);
364 CHECK_INT_EQU(TraversalTestU16ElemData(), HDF_SUCCESS);
365 CHECK_INT_EQU(TraversalBoardId(), HDF_SUCCESS);
366 CHECK_INT_EQU(TraversalModemId(), HDF_SUCCESS);
367 return HDF_SUCCESS;
368 }
369
HcsMacroTraversalOneNodeChild(void)370 int HcsMacroTraversalOneNodeChild(void)
371 {
372 int index = 0;
373
374 HCS_FOREACH_CHILD(FP_INFO_NODE, FP_DEAL);
375 return HDF_SUCCESS;
376 }
377
HcsMacroTraversalOneNodeChildVargs(void)378 int HcsMacroTraversalOneNodeChildVargs(void)
379 {
380 int index = 0;
381
382 HCS_FOREACH_CHILD_VARGS(FP_INFO_NODE, FP_DEAL_VARGS, g_fpData, index);
383 return HDF_SUCCESS;
384 }
385
HcsMacroGetOneFile(void)386 int HcsMacroGetOneFile(void)
387 {
388 CHECK_STRING_EQU(HCS_PROP(HCS_ROOT, match_attr), "test,config");
389 CHECK_INT_EQU(TraversalAudio(), HDF_SUCCESS);
390 CHECK_INT_EQU(TraversalFPInfo(), HDF_SUCCESS);
391 CHECK_INT_EQU(TraversalDataTypeTest(), HDF_SUCCESS);
392 CHECK_INT_EQU(TraversalBoardId(), HDF_SUCCESS);
393 CHECK_STRING_EQU(HCS_PROP(HCS_ROOT, support_Device), "TP LCD Sensor");
394 CHECK_INT_EQU(TraversalPringerprintThree(), HDF_SUCCESS);
395 CHECK_INT_EQU(TraversalModemId(), HDF_SUCCESS);
396 CHECK_INT_EQU(HCS_PROP(HCS_ROOT, boardId), BOARD_ID_VALUE);
397
398 return HDF_SUCCESS;
399 }
400