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 #include <stdlib.h>
14 #include <string.h>
15 #include <stdarg.h>
16 #include <stdbool.h>
17 #include "test_pal_log.h"
18
19 /******************************************************************************/
Test_PalPrintfError(const char * function,const char * format,...)20 void Test_PalPrintfError(const char *function, const char *format, ...)
21 {
22 va_list args;
23
24 va_start(args, format);
25
26 if (function)
27 fprintf(stderr, "%s(): ", function);
28 vfprintf(stderr, format, args);
29 fprintf(stderr, "\n");
30 fflush(stderr);
31
32 va_end(args);
33 }
34
35
36 /******************************************************************************/
Test_PalFprintfError(void * fd,const char * function,const char * format,...)37 void Test_PalFprintfError(void *fd, const char *function, const char *format, ...)
38 {
39 FILE *fd_l = (FILE *)fd;
40 va_list args;
41
42 va_start(args, format);
43
44 if (function)
45 fprintf(fd_l, "%s(): ", function);
46 vfprintf(fd_l, format, args);
47 fprintf(fd_l, "\n");
48 fflush(fd_l);
49
50 if (function)
51 fprintf(stderr, "%s(): ", function);
52 vfprintf(stderr, format, args);
53 fprintf(stderr, "\n");
54 fflush(stderr);
55
56 va_end(args);
57 }
58
59 /******************************************************************************/
Test_PalPrintfMessage(const char * format,...)60 void Test_PalPrintfMessage(const char *format, ...)
61 {
62 va_list args;
63
64 va_start(args, format);
65
66 vfprintf(stderr, format, args);
67 fflush(stderr);
68
69 va_end(args);
70 }
71
72 /******************************************************************************/
Test_PalPrintf(const char * function,const char * format,...)73 void Test_PalPrintf(const char *function, const char *format, ...)
74 {
75 va_list args;
76
77 va_start(args, format);
78
79 if (function)
80 fprintf(stdout, "%s(): ", function);
81 vfprintf(stdout, format, args);
82 fflush(stdout);
83
84 va_end(args);
85 }
86
87 /******************************************************************************/
Test_PalFprintf(void * fd,const char * function,const char * format,...)88 void Test_PalFprintf(void *fd, const char *function, const char *format, ...)
89 {
90 FILE *fd_l = (FILE *)fd;
91 va_list args;
92
93 va_start(args, format);
94
95 if (function)
96 fprintf(fd_l, "%s(): ", function);
97 vfprintf(fd_l, format, args);
98 fflush(fd_l);
99
100 if (function)
101 fprintf(stdout, "%s(): ", function);
102 vfprintf(stdout, format, args);
103 fflush(stdout);
104
105 va_end(args);
106 }
107
108 /******************************************************************************/
Test_PalPrintByteBuff(const char * function,const char * buffName,uint8_t * buff,uint32_t size)109 void Test_PalPrintByteBuff(const char *function, const char *buffName,
110 uint8_t *buff, uint32_t size)
111 {
112 unsigned int i = 0;
113
114 Test_PalPrintf(function, "printing %s, byte size %d\n",
115 buffName, (unsigned int)size);
116 for (i = 0; i < size; i++) {
117 if (!(i%16))
118 Test_PalPrintf(NULL, "\n\t");
119 Test_PalPrintf(NULL, "0x%02X ",
120 (unsigned char)(*((unsigned char *)buff+i)));
121 }
122 Test_PalPrintf(NULL, "\n");
123 }
124
125 /******************************************************************************/
Test_PalFprintByteBuff(void * fd,const char * function,const char * buffName,uint8_t * buff,uint32_t size)126 void Test_PalFprintByteBuff(void *fd, const char *function,
127 const char *buffName, uint8_t *buff, uint32_t size)
128 {
129 FILE *fd_l = (FILE *)fd;
130 unsigned int i = 0;
131
132 Test_PalFprintf(fd_l, function, "printing %s, byte size %d", buffName,
133 (unsigned int)size);
134 for (i = 0; i < size; i++) {
135 if (!(i%16))
136 Test_PalFprintf(fd_l, NULL, "\n\t");
137 Test_PalFprintf(fd_l, NULL, "0x%02X ",
138 (unsigned char)(*((unsigned char *)buff+i)));
139 }
140 Test_PalFprintf(fd_l, NULL, "\n");
141 }
142
143 /******************************************************************************/
Test_PalFprintfByteBuffMax(void * fd,const char * function,const char * buffName,uint8_t * buff,uint32_t size,uint32_t maxSize)144 void Test_PalFprintfByteBuffMax(void *fd, const char *function,
145 const char *buffName, uint8_t *buff, uint32_t size, uint32_t maxSize)
146 {
147 int i = 0;
148 FILE *fd_l = (FILE *)fd;
149 int minSize = ((size > maxSize) ? maxSize:size);
150
151 Test_PalFprintf(fd_l, function, "printing %s, buff size %d, max size %d",
152 buffName, (unsigned int)size, (unsigned int)maxSize);
153
154 for (i = 0; i < minSize; i++) {
155 if (!(i%16))
156 Test_PalFprintf(fd_l, NULL, "\n\t");
157 Test_PalFprintf(fd_l, NULL, "0x%02X ",
158 (unsigned char)(*((unsigned char *)buff+i)));
159 }
160 Test_PalFprintf(fd_l, NULL, "\n");
161 }
162
163 /******************************************************************************/
Test_PalPrintWordBuff(const char * function,const char * buffName,uint32_t * buff,uint32_t size)164 void Test_PalPrintWordBuff(const char *function, const char *buffName,
165 uint32_t *buff, uint32_t size)
166 {
167 uint8_t i = 0;
168
169 Test_PalPrintf(function, "printing %s, word size %d\n", buffName,
170 (unsigned int)size);
171 for (i = 0; i < size; i++) {
172 if (!(i%4))
173 Test_PalPrintf(NULL, "\n\t");
174 Test_PalPrintf(NULL, "0x%08X ",
175 (unsigned int)(*((unsigned int *)buff+i)));
176 }
177 Test_PalPrintf(NULL, "\n");
178 }
179
180 /* inline void TEST_PRINT_BYTE_BUFFP(buffName, buff, size);
181 inline void TEST_FPRINT_LONG_NUM(const char *fd, const char *buffName,
182 uint32_t *buff, uint32_t size); */
183