1 /*******************************************************************************
2 * The confidential and proprietary information contained in this file may      *
3 * only be used by a person authorised under and to the extent permitted        *
4 * by a subsisting licensing agreement from ARM Limited or its affiliates.      *
5 *   (C) COPYRIGHT [2001-2017] ARM Limited or its affiliates.                   *
6 *       ALL RIGHTS RESERVED                                                    *
7 * This entire notice must be reproduced on all copies of this file             *
8 * and copies of this file may only be made by a person if such person is       *
9 * permitted to do so under the terms of a subsisting license agreement         *
10 * from ARM Limited or its affiliates.                                          *
11 *******************************************************************************/
12 
13 #ifndef TEST_PAL_LOG_H_
14 #define TEST_PAL_LOG_H_
15 
16 #include <stdint.h>
17 #include <stdio.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* In order to print the name of the function, while implementing
24  * a generic declaration and an OS-dependent definition, we use a macro that
25  * calls a PAL function with __FUNCTION__ as an argument.
26  */
27 
28 /******************************************************************************/
29 /*
30  * @brief This variadic function prints to stderr with or without the name of
31  * the calling function.
32  * When function is NULL, the name of the function is not printed.
33  *
34  * @param[in]
35  * function - The name of the calling function (can be NULL).
36  * format - The printed string.
37  * ... - Arguments
38  *
39  * @param[out]
40  *
41  * @return
42  */
43 void Test_PalPrintfError(const char *function, const char *format, ...);
44 
45 /******************************************************************************/
46 /*
47  * @brief This variadic function prints to stderr and to a file with or without
48  * the name of the calling function.
49  * When function is NULL, the name of the function is not printed.
50  *
51  * @param[in]
52  * fd - File descriptor.
53  * function - The name of the calling function (can be NULL).
54  * format - The printed string.
55  * ... - Arguments
56  *
57  * @param[out]
58  *
59  * @return
60  */
61 void Test_PalFprintfError(void *fd, const char *function,
62         const char *format, ...);
63 
64 /******************************************************************************/
65 /*
66  * @brief This variadic function prints messages to stderr.
67  *
68  * @param[in]
69  * format - The printed string.
70  * ... - Arguments
71  *
72  * @param[out]
73  *
74  * @return
75  */
76 void Test_PalPrintfMessage(const char *format, ...);
77 
78 /******************************************************************************/
79 /*
80  * @brief This variadic function prints strings to stdout with or without
81  * the name of the calling function.
82  * When function is NULL, the name of the function is not printed.
83  *
84  * @param[in]
85  * function - The name of the calling function (can be NULL).
86  * format - The printed string.
87  * ... - Arguments
88  *
89  * @param[out]
90  *
91  * @return
92  */
93 void Test_PalPrintf(const char *function, const char *format, ...);
94 
95 /******************************************************************************/
96 /*
97  * @brief This variadic function prints strings to stdout and to a file
98  * with or without the name of the calling function.
99  * When function is NULL, the name of the function is not printed.
100  *
101  * @param[in]
102  * fd - File descriptor.
103  * function - The name of the calling function (can be NULL).
104  * format - The printed string.
105  * ... - Arguments
106  *
107  * @param[out]
108  *
109  * @return
110  */
111 void Test_PalFprintf(void *fd, const char *function, const char *format, ...);
112 
113 /******************************************************************************/
114 /*
115  * @brief This variadic function prints bytes in a buffer to stdout
116  * with or without the name of the calling function.
117  * When function is NULL, the name of the function is not printed.
118  *
119  * @param[in]
120  * function - The name of the calling function (can be NULL).
121  * buffName - The name of the buffer.
122  * buff - Buffer address.
123  * size - The size of the buffer.
124  *
125  * @param[out]
126  *
127  * @return
128  */
129 void Test_PalPrintByteBuff(const char *function, const char *buffName,
130                         uint8_t *buff, uint32_t size);
131 
132 /******************************************************************************/
133 /*
134  * @brief This variadic function prints bytes in a buffer to a file
135  * with or without the name of the calling function.
136  * When function is NULL, the name of the function is not printed.
137  *
138  * @param[in]
139  * fd - File descriptor.
140  * function - The name of the calling function (can be NULL).
141  * buffName - The name of the buffer.
142  * buff - Buffer address.
143  * size - The size of the buffer.
144  *
145  * @param[out]
146  *
147  * @return
148  */
149 void Test_PalFprintByteBuff(void *fd, const char *function,
150             const char *buffName, uint8_t *buff, uint32_t size);
151 
152 /******************************************************************************/
153 /*
154  * @brief This variadic function prints bytes in a buffer to a file
155  * with or without the name of the calling function.
156  * When function is NULL, the name of the function is not printed.
157  *
158  * @param[in]
159  * fd - File descriptor.
160  * function - The name of the calling function (can be NULL).
161  * buffName - The name of the buffer.
162  * buff - Buffer address.
163  * size - The size of the buffer.
164  * maxSize - Maximum size to print.
165  *
166  * @param[out]
167  *
168  * @return
169  */
170 void Test_PalFprintfByteBuffMax(void *fd, const char *function,
171             const char *buffName, uint8_t *buff, uint32_t size,
172             uint32_t maxSize);
173 
174 /******************************************************************************/
175 /*
176  * @brief This variadic function prints words in a buffer with or without the
177  * name of the calling function.
178  * When function is NULL, the name of the function is not printed (can be NULL).
179  *
180  * @param[in]
181  * function - The name of the calling function.
182  * buffName - The name of the buffer.
183  * buff - Buffer address.
184  * size - The size of the buffer.
185  *
186  * @param[out]
187  *
188  * @return
189  */
190 void Test_PalPrintWordBuff(const char *function, const char *buffName,
191             uint32_t *buff, uint32_t size);
192 
193 /******************************************************************************/
194 /*
195  * @brief This macro prints errors with the name of the calling function.
196  *
197  * @param[in]
198  * format - The printed string.
199  * ... - Arguments
200  *
201  * @param[out]
202  *
203  * @return
204  */
205 #define TEST_PRINTF_ERROR(format, ...)  {\
206     Test_PalPrintfError(__FUNCTION__, format, ##__VA_ARGS__);\
207 }
208 
209 /******************************************************************************/
210 /*
211  * @brief This macro prints to a file with the name of the calling function.
212  *
213  * @param[in]
214  * fd - File descriptor.
215  * format - The printed string.
216  * ... - Arguments
217  *
218  * @param[out]
219  *
220  * @return
221  */
222 #define TEST_FPRINTF_ERROR(fd, format, ...)  {\
223     Test_PalFprintfError(fd, __FUNCTION__, format, ##__VA_ARGS__);\
224 }
225 
226 /******************************************************************************/
227 /*
228  * @brief This macro prints messages.
229  *
230  * @param[in]
231  * format - The printed string.
232  * ... - Arguments
233  *
234  * @param[out]
235  *
236  * @return
237  */
238 #define TEST_PRINTF_MESSAGE(format, ...)  {\
239     Test_PalPrintfMessage(format, ##__VA_ARGS__);\
240 }
241 
242 #ifdef TEST_DEBUG
243 
244 /******************************************************************************/
245 /*
246  * @brief This macro prints strings with the name of the calling function.
247  *
248  * @param[in]
249  * format - The printed string.
250  * ... - Arguments
251  *
252  * @param[out]
253  *
254  * @return
255  */
256 #define TEST_PRINTF(format, ...)  {\
257     Test_PalPrintf(__FUNCTION__, format, ##__VA_ARGS__);\
258     Test_PalPrintf(NULL, "\n");\
259 }
260 
261 /******************************************************************************/
262 /*
263  * @brief This macro prints strings to a file with the name of the calling function.
264  *
265  * @param[in]
266  * fd - File descriptor.
267  * format - The printed string.
268  * ... - Arguments
269  *
270  * @param[out]
271  *
272  * @return
273  */
274 #define TEST_FPRINTF(fd, format, ...)  {\
275     Test_PalFprintf(fd, __FUNCTION__, format, ##__VA_ARGS__);\
276     Test_PalFprintf(fd, NULL, "\n");\
277 }
278 
279 /******************************************************************************/
280 /*
281  * @brief This macro prints strings without the name of the calling function.
282  *
283  * @param[in]
284  * format - The printed string.
285  * ... - Arguments
286  *
287  * @param[out]
288  *
289  * @return
290  */
291 #define TEST_PRINTF_NO_FUNC(format, ...)  {\
292     Test_PalPrintf(NULL, format, ##__VA_ARGS__);\
293     Test_PalPrintf(NULL, "\n");\
294 }
295 
296 /******************************************************************************/
297 /*
298  * @brief This macro prints strings to a file without the name of the calling function.
299  *
300  * @param[in]
301  * fd - File descriptor.
302  * format - The printed string.
303  * ... - Arguments
304  *
305  * @param[out]
306  *
307  * @return
308  */
309 #define TEST_FPRINTF_NO_FUNC(fd, format, ...)  {\
310     Test_PalFprintf(fd, NULL, format, ##__VA_ARGS__);\
311     Test_PalFprintf(fd, NULL, "\n");\
312 }
313 
314 /******************************************************************************/
315 /*
316  * @brief This macro prints bytes in a buffer with the name of the calling
317  * function.
318  *
319  * @param[in]
320  * buffName - The name of the buffer.
321  * buff - Buffer address.
322  * size - The size of the buffer.
323  *
324  * @param[out]
325  *
326  * @return
327  */
328 #define TEST_PRINT_BYTE_BUFF(buffName, buff, size)  {\
329     Test_PalPrintByteBuff(__FUNCTION__, buffName, buff, size);\
330 }
331 
332 /******************************************************************************/
333 /*
334  * @brief This macro prints bytes in a buffer to a file with
335  * the name of the calling function.
336  *
337  * @param[in]
338  * fd - File descriptor.
339  * buffName - The name of the buffer.
340  * buff - Buffer address.
341  * size - The size of the buffer.
342  *
343  * @param[out]
344  *
345  * @return
346  */
347 #define TEST_FPRINT_BYTE_BUFF(fd, buffName, buff, size)  {\
348     Test_PalFprintByteBuff(fd, __FUNCTION__, buffName, buff, size);\
349 }
350 
351 /******************************************************************************/
352 /*
353  * @brief This macro prints bytes in a buffer to a file with the name of the
354  * calling function.
355  *
356  * @param[in]
357  * fd - File descriptor.
358  * buffName - The name of the buffer.
359  * buff - Buffer address.
360  * size - The size of the buffer.
361  * maxSize - Maximum size to print.
362  *
363  * @param[out]
364  *
365  * @return
366  */
367 #define TEST_FPRINT_BYTE_BUFF_MAX(fd, buffName, buff, size, maxSize) {\
368     Test_PalFprintfByteBuffMax(fd, __FUNCTION__, buffName, buff, size,\
369                 maxSize);\
370 }
371 
372 /******************************************************************************/
373 /*
374  * @brief This macro prints words in a buffer with the name of the calling
375  * function.
376  *
377  * @param[in]
378  * buffName - The name of the buffer.
379  * buff - Buffer address.
380  * size - The size of the buffer.
381  *
382  * @param[out]
383  *
384  * @return
385  */
386 #define TEST_PRINT_WORD_BUFF(buffName, buff, size) {\
387     Test_PalPrintWordBuff(__FUNCTION__, buffName, buff, size);\
388 }
389 
390 /* void TEST_PRINT_BYTE_BUFFP(buffName, buff, size);
391    void TEST_FPRINT_LONG_NUM(const char *fd, const char *buffName,
392    uint32_t *buff, uint32_t size); */
393 #else
394 #define TEST_PRINTF(format, ...) do { } while (0)
395 #define TEST_FPRINTF(fd, format, ...) do { } while (0)
396 #define TEST_PRINTF_NO_FUNC(format, ...) do { } while (0)
397 #define TEST_FPRINTF_NO_FUNC(fd, format, ...) do { } while (0)
398 #define TEST_PRINT_BYTE_BUFF(buffName, buff, size) do { } while (0)
399 #define TEST_FPRINT_BYTE_BUFF(fd, buffName, buff, size) do { } while (0)
400 #define TEST_FPRINT_BYTE_BUFF_MAX(fd, buffName, buff, size, maxSize) do { } while (0)
401 #define TEST_PRINT_WORD_BUFF(buffName, buff, size) do { } while (0)
402 #endif
403 
404 #ifdef __cplusplus
405 }
406 #endif
407 
408 #endif /* TEST_PAL_LOG_H_ */
409