1 /*
2 Copyright (c) 2018, MIPI Alliance, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17 * Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * Contributors:
36 * Norbert Schulz (Intel Corporation) - Initial API and implementation
37 */
38
39 #include <string>
40 #include <stdint.h>
41 #include "mipi_syst_gtest.h"
42
43 #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA) &&\
44 defined(MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE) &&\
45 defined(MIPI_SYST_PCFG_ENABLE_PRINTF_API)
46
47 #define mipi_syst_write_printf_string(a,b,c, ...) \
48 (sstr.str(""),\
49 ::mipi_syst_write_printf_string(a,b,c, __VA_ARGS__ ),\
50 result = sstr.str(),\
51 result.c_str())
52
53 #define mipi_syst_write_printf_catalog64(a,b,c, ...) \
54 (sstr.str(""),\
55 ::mipi_syst_write_printf_catalog64(a,b,c, __VA_ARGS__ ),\
56 result = sstr.str(),\
57 result.c_str())
58
59 #define mipi_syst_write_printf_catalog32(a,b,c, ...) \
60 (sstr.str(""),\
61 ::mipi_syst_write_printf_catalog32(a,b,c, __VA_ARGS__ ),\
62 result = sstr.str(),\
63 result.c_str())
64
65 class MipiSysTFixturePrintf : public MipiSysTFixtureOutput
66 {
67 public:
SetUp()68 void SetUp() {
69 MipiSysTFixtureOutput::SetUp();
70 }
71
TearDown()72 void TearDown() {
73 MipiSysTFixtureOutput::TearDown();
74 }
75
76 static std::string result;
77 };
78
79 std::string MipiSysTFixturePrintf::result;
80
TEST_F(MipiSysTFixturePrintf,syst_printf_null)81 TEST_F(MipiSysTFixturePrintf, syst_printf_null)
82 {
83 EXPECT_STREQ(
84 xform(""),
85 MIPI_SYST_PRINTF(0, MIPI_SYST_SEVERITY_INFO, (char*) 0)
86 );
87 EXPECT_STREQ(
88 xform("<D32TS>05012242[typ=2:5 mu=1:2 sev=4 len]<D16>0007<D32>6c756e28<D16>296c<D8>00<FLAG>"),
89 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, (char*) 0)
90 );
91 }
92
TEST_F(MipiSysTFixturePrintf,syst_printf_basic)93 TEST_F(MipiSysTFixturePrintf, syst_printf_basic)
94 {
95 EXPECT_STREQ(
96 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0001<D8>00<FLAG>"),
97 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "")
98 );
99
100 EXPECT_STREQ(
101 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0003<D16>2525<D8>00<FLAG>"),
102 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%%")
103 );
104
105 EXPECT_STREQ(
106 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000e<D64>6f77206f6c6c6568<D32>20646c72<D16>0021<FLAG>"),
107 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "hello world !")
108 );
109 }
110
TEST_F(MipiSysTFixturePrintf,syst_printf_invalid)111 TEST_F(MipiSysTFixturePrintf, syst_printf_invalid)
112 {
113 EXPECT_STREQ(
114 xform("<D32TS>05012242[typ=2:5 mu=1:2 sev=4 len]<D16>0007<D32>6c756e28<D16>296c<D8>00<FLAG>"),
115 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, 0)
116 );
117 EXPECT_STREQ(
118 xform("<D32TS>05012242[typ=2:5 mu=1:2 sev=4 len]<D16>0003<D16>6225<D8>00<FLAG>"),
119 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%b", 1)
120 );
121 std::string tooLong(MIPI_SYST_PCFG_PRINTF_ARGBUF_SIZE, 'X');
122
123 EXPECT_STREQ(
124 xform("<D32TS>05012242[typ=2:5 mu=1:2 sev=4 len]<D16>0020<D64>5858585858585858<D64>5858585858585858<D64>5858585858585858<D64>5858585858585858<FLAG>"),
125 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, tooLong.c_str(), 1)
126 );
127
128 tooLong.resize(MIPI_SYST_PCFG_PRINTF_ARGBUF_SIZE /2);
129 EXPECT_STREQ(
130 xform("<D32TS>05012242[typ=2:5 mu=1:2 sev=4 len]<D16>0006<D32>25207325<D16>0073<FLAG>"),
131 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%s %s", tooLong.c_str(), tooLong.c_str())
132 );
133 }
TEST_F(MipiSysTFixturePrintf,syst_printf_flags)134 TEST_F(MipiSysTFixturePrintf, syst_printf_flags)
135 {
136 EXPECT_STREQ(
137 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>1122334400642b25<FLAG>"),
138 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%+d", 0x11223344)
139 );
140 EXPECT_STREQ(
141 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>1122334400642d25<FLAG>"),
142 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%-d", 0x11223344)
143 );
144 EXPECT_STREQ(
145 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>1122334400642025<FLAG>"),
146 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "% d", 0x11223344)
147 );
148 EXPECT_STREQ(
149 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>1122334400642325<FLAG>"),
150 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%#d", 0x11223344)
151 );
152 EXPECT_STREQ(
153 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>1122334400643025<FLAG>"),
154 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%0d", 0x11223344)
155 );
156 }
157
TEST_F(MipiSysTFixturePrintf,syst_printf_width)158 TEST_F(MipiSysTFixturePrintf, syst_printf_width)
159 {
160 EXPECT_STREQ(
161 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>1122334400643325<FLAG>"),
162 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%3d", 0x11223344)
163 );
164 EXPECT_STREQ(
165 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000c<D64>000000ab00642a25<D32>11223344<FLAG>"),
166 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%*d", 0xab, 0x11223344)
167 );
168 EXPECT_STREQ(
169 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0012<D64>ccdd00642a2e2a25<D64>334412345678aabb<D16>1122<FLAG>"),
170 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%*.*d", 0xaabbccdd, 0x12345678, 0x11223344)
171 );
172 }
173
TEST_F(MipiSysTFixturePrintf,syst_printf_floatingpoint)174 TEST_F(MipiSysTFixturePrintf, syst_printf_floatingpoint)
175 {
176 EXPECT_STREQ(
177 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea006625<D16>0921<D8>40<FLAG>"),
178 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%f", 3.14159265359)
179 );
180 EXPECT_STREQ(
181 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea004625<D16>0921<D8>40<FLAG>"),
182 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%F", 3.14159265359)
183 );
184 EXPECT_STREQ(
185 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea006525<D16>0921<D8>40<FLAG>"),
186 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%e", 3.14159265359)
187 );
188 EXPECT_STREQ(
189 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea004525<D16>0921<D8>40<FLAG>"),
190 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%E", 3.14159265359)
191 );
192 EXPECT_STREQ(
193 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea006725<D16>0921<D8>40<FLAG>"),
194 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%g", 3.14159265359)
195 );
196 EXPECT_STREQ(
197 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea006125<D16>0921<D8>40<FLAG>"),
198 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%a", 3.14159265359)
199 );
200 EXPECT_STREQ(
201 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea004125<D16>0921<D8>40<FLAG>"),
202 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%A", 3.14159265359)
203 );
204 EXPECT_STREQ(
205 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea004725<D16>0921<D8>40<FLAG>"),
206 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%G", 3.14159265359)
207 );
208
209 EXPECT_STREQ(
210 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000c<D64>54442eea00664c25<D32>400921fb<FLAG>"),
211 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%Lf", (long double)3.14159265359)
212 );
213 }
214
TEST_F(MipiSysTFixturePrintf,syst_printf_floatingpoint_precison)215 TEST_F(MipiSysTFixturePrintf, syst_printf_floatingpoint_precison)
216 {
217 EXPECT_STREQ(
218 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>fb54442eea006625<D16>0921<D8>40<FLAG>"),
219 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%f", 3.14159265359)
220 );
221
222 EXPECT_STREQ(
223 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000c<D64>54442eea00663325<D32>400921fb<FLAG>"),
224 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%3f", 3.14159265359)
225 );
226
227 EXPECT_STREQ(
228 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0010<D64>006630312e313125<D64>400921fb54442eea<FLAG>"),
229 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%11.10f", 3.14159265359)
230 );
231
232 EXPECT_STREQ(
233 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0016<D64>000a00662a2e2a25<D64>2eea0000000b0000<D32>21fb5444<D16>4009<FLAG>"),
234 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%*.*f", 10, 11, 3.14159265359)
235 );
236 }
237
TEST_F(MipiSysTFixturePrintf,syst_printf_modifier)238 TEST_F(MipiSysTFixturePrintf, syst_printf_modifier)
239 {
240 unsigned int hh = 0x12;
241 unsigned short int h = 0x1234;
242 long int l = (long int)-1;
243 unsigned long long int ll = 0x1122334455667788ull;
244 uintmax_t j = 0x1122334455667788ull;
245 size_t z = (size_t)-1;
246 ptrdiff_t t = (ptrdiff_t)-1;
247
248 EXPECT_STREQ(
249 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0009<D64>0000120064686825<D8>00<FLAG>"),
250 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%hhd", hh)
251 );
252 EXPECT_STREQ(
253 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>0000123400646825<FLAG>"),
254 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%hd", h)
255 );
256 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
257 EXPECT_STREQ(
258 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000c<D64>ffffffff00646c25<D32>ffffffff<FLAG>"),
259 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%ld", l)
260 );
261
262 EXPECT_STREQ(
263 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000c<D64>ffffffff00647a25<D32>ffffffff<FLAG>"),
264 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%zd", z)
265 );
266
267 EXPECT_STREQ(
268 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000c<D64>ffffffff00647425<D32>ffffffff<FLAG>"),
269 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%td", t)
270 );
271 #else
272 EXPECT_STREQ(
273 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>ffffffff00646c25<FLAG>"),
274 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%ld", l)
275 );
276 EXPECT_STREQ(
277 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>ffffffff00647a25<FLAG>"),
278 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%zd", z)
279 );
280 EXPECT_STREQ(
281 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>ffffffff00647425<FLAG>"),
282 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%td", t)
283 );
284 #endif
285
286 EXPECT_STREQ(
287 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000d<D64>66778800646c6c25<D32>22334455<D8>11<FLAG>"),
288 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%lld", ll)
289 );
290
291 EXPECT_STREQ(
292 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000c<D64>5566778800646a25<D32>11223344<FLAG>"),
293 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%jd", j)
294 );
295 }
296
TEST_F(MipiSysTFixturePrintf,syst_printf_pointer)297 TEST_F(MipiSysTFixturePrintf, syst_printf_pointer)
298 {
299 void * p = (void*)-1;
300
301 if (sizeof(p) == 8) {
302 EXPECT_STREQ(
303 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>000b<D64>ffffffffff007025<D16>ffff<D8>ff<FLAG>"),
304 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%p", p)
305 );
306 } else {
307 EXPECT_STREQ(
308 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0007<D32>ff007025<D16>ffff<D8>ff<FLAG>"),
309 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%p", p)
310 );
311 }
312 }
313
TEST_F(MipiSysTFixturePrintf,syst_printf_char)314 TEST_F(MipiSysTFixturePrintf, syst_printf_char)
315 {
316 char c = 'C';
317 wint_t w = 'W';
318
319 EXPECT_STREQ(
320 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0007<D32>43006325<D16>0000<D8>00<FLAG>"),
321 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%c", c)
322 );
323
324 EXPECT_STREQ(
325 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0008<D64>0000005700636c25<FLAG>"),
326 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "%lc", w)
327 );
328 }
329
TEST_F(MipiSysTFixturePrintf,syst_printf_combinations)330 TEST_F(MipiSysTFixturePrintf, syst_printf_combinations)
331 {
332 EXPECT_STREQ(
333 xform("<D32TS>0b012242[typ=2:b mu=1:2 sev=4 len]<D16>0031<D64>6a20732520656854<D64>766f206465706d75<D64>2520656874207265<D64>6d69742064252073<D64>00776f63002e7365<D64>000005006e6f6f6d<D8>00<FLAG>"),
334 MIPI_SYST_PRINTF(ph, MIPI_SYST_SEVERITY_INFO, "The %s jumped over the %s %d times.", "cow", "moon", 5)
335 );
336 }
337 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
TEST_F(MipiSysTFixturePrintf,syst_printf_loc)338 TEST_F(MipiSysTFixturePrintf, syst_printf_loc)
339 {
340 EXPECT_STREQ(
341 xform("<D32TS>0b012342[typ=2:b mu=1:2 sev=4 loc len]<D8>00<D32>5678abcd<D16>0031<D64>6a20732520656854<D64>766f206465706d75<D64>2520656874207265<D64>6d69742064252073<D64>00776f63002e7365<D64>000005006e6f6f6d<D8>00<FLAG>"),
342 MIPI_SYST_PRINTF_LOC16(ph, MIPI_SYST_SEVERITY_INFO, 0xabcd, "The %s jumped over the %s %d times.", "cow", "moon", 5)
343 );
344
345 EXPECT_STREQ(
346 xform("<D32TS>0b012342[typ=2:b mu=1:2 sev=4 loc len]<D8>01<D64>12345678aabbccdd<D16>0031<D64>6a20732520656854<D64>766f206465706d75<D64>2520656874207265<D64>6d69742064252073<D64>00776f63002e7365<D64>000005006e6f6f6d<D8>00<FLAG>"),
347 MIPI_SYST_PRINTF_LOC32(ph, MIPI_SYST_SEVERITY_INFO, 0xaabbccdd, "The %s jumped over the %s %d times.", "cow", "moon", 5)
348 );
349
350 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
351 EXPECT_STREQ(
352 xform("<D32TS>0b012342[typ=2:b mu=1:2 sev=4 loc len]<D8>03<D64>12345678aabbccdd<D16>0031<D64>6a20732520656854<D64>766f206465706d75<D64>2520656874207265<D64>6d69742064252073<D64>00776f63002e7365<D64>000005006e6f6f6d<D8>00<FLAG>"),
353 MIPI_SYST_PRINTF_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO, "The %s jumped over the %s %d times.", "cow", "moon", 5)
354 );
355 #else
356 EXPECT_STREQ(
357 xform("<D32TS>0b012342[typ=2:b mu=1:2 sev=4 loc len]<D8>02<D32>12345678<D16>0031<D64>6a20732520656854<D64>766f206465706d75<D64>2520656874207265<D64>6d69742064252073<D64>00776f63002e7365<D64>000005006e6f6f6d<D8>00<FLAG>"),
358 MIPI_SYST_PRINTF_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO, "The %s jumped over the %s %d times.", "cow", "moon", 5)
359 );
360 #endif
361 }
362 #endif // MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
363
364 #if defined(MIPI_SYST_PCFG_ENABLE_CATID64_API)
365
TEST_F(MipiSysTFixturePrintf,syst_catalog64_printf_null)366 TEST_F(MipiSysTFixturePrintf, syst_catalog64_printf_null)
367 {
368 EXPECT_STREQ(
369 xform(""),
370 MIPI_SYST_CATPRINTF64(NULL, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788, "")
371 );
372 }
373
TEST_F(MipiSysTFixturePrintf,syst_catalog64_printf_invalid)374 TEST_F(MipiSysTFixturePrintf, syst_catalog64_printf_invalid)
375 {
376 EXPECT_STREQ(
377 xform("<D32TS>05012242[typ=2:5 mu=1:2 sev=4 len]<D16>0007<D32>61746163<D16>6772<D8>00<FLAG>"),
378 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344, -1, -1)
379 );
380 }
381
TEST_F(MipiSysTFixturePrintf,syst_catalog64_printf_basic)382 TEST_F(MipiSysTFixturePrintf, syst_catalog64_printf_basic)
383 {
384 EXPECT_STREQ(
385 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0008<D64>1122334455667788<FLAG>"),
386 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788, "")
387 );
388
389 // check that formt string is not added into payload
390 EXPECT_STREQ(
391 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0008<D64>1122334455667788<FLAG>"),
392 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull, "Hello world")
393 );
394
395 EXPECT_STREQ(
396 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>000c<D64>1122334455667788<D32>00000058<FLAG>"),
397 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
398 "%c", MIPI_SYST_PARAM_CHAR('X'))
399 );
400 EXPECT_STREQ(
401 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>000c<D64>1122334455667788<D32>00000058<FLAG>"),
402 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
403 "%c", MIPI_SYST_PARAM_WCHAR(L'X'))
404 );
405 EXPECT_STREQ(
406 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>000c<D64>1122334455667788<D32>abcd1234<FLAG>"),
407 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
408 "%c", MIPI_SYST_PARAM_INT(0xabcd1234))
409 );
410
411 EXPECT_STREQ(
412 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>1234567887654321<FLAG>"),
413 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
414 "%lld", MIPI_SYST_PARAM_LONGLONG(0x1234567887654321ull))
415 );
416
417 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
418 EXPECT_STREQ(
419 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>0000000012345678<FLAG>"),
420 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
421 "%ld", MIPI_SYST_PARAM_LONG(0x12345678))
422 );
423
424 EXPECT_STREQ(
425 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>1234567887654321<FLAG>"),
426 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
427 "%z", MIPI_SYST_PARAM_SIZE_T(0x1234567887654321ull))
428 );
429 EXPECT_STREQ(
430 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>1234567887654321<FLAG>"),
431 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
432 "%t", MIPI_SYST_PARAM_PTRDIFF_T(0x1234567887654321ull))
433 );
434 EXPECT_STREQ(
435 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>1234567887654321<FLAG>"),
436 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
437 "%p", MIPI_SYST_PARAM_PTR(0x1234567887654321ull))
438 );
439 #else
440 EXPECT_STREQ(
441 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>000c<D64>1122334455667788<D32>12345678<FLAG>"),
442 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
443 "%ld", MIPI_SYST_PARAM_LONG(0x12345678))
444 );
445
446 EXPECT_STREQ(
447 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>000c<D64>1122334455667788<D32>12345678<FLAG>"),
448 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
449 "%z", MIPI_SYST_PARAM_SIZE_T(0x12345678))
450 );
451 EXPECT_STREQ(
452 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>000c<D64>1122334455667788<D32>12345678<FLAG>"),
453 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
454 "%t", MIPI_SYST_PARAM_PTRDIFF_T(0x12345678))
455 );
456 EXPECT_STREQ(
457 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>000c<D64>1122334455667788<D32>12345678<FLAG>"),
458 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
459 "%p", MIPI_SYST_PARAM_PTR(0x12345678))
460 );
461 #endif //defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
462
463 EXPECT_STREQ(
464 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>4000000000000000<FLAG>"),
465 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
466 "%f", MIPI_SYST_PARAM_FLOAT((float)2.0))
467 );
468 EXPECT_STREQ(
469 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>4000000000000000<FLAG>"),
470 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
471 "%f", MIPI_SYST_PARAM_DOUBLE((double)2.0))
472 );
473 EXPECT_STREQ(
474 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0010<D64>1122334455667788<D64>4000000000000000<FLAG>"),
475 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788ull,
476 "%lf", MIPI_SYST_PARAM_LONGDOUBLE((long double)2.0))
477 );
478 }
479
TEST_F(MipiSysTFixturePrintf,syst_catalog64_printf_string)480 TEST_F(MipiSysTFixturePrintf, syst_catalog64_printf_string)
481 {
482 EXPECT_STREQ(
483 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0009<D64>1122334455667788<D8>00<FLAG>"),
484 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788,
485 "%s", MIPI_SYST_PARAM_CSTR(""))
486 );
487
488 EXPECT_STREQ(
489 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0016<D64>1122334455667788<D64>6f77206f6c6c6568<D32>20646c72<D16>0021<FLAG>"),
490 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788,
491 "%s", MIPI_SYST_PARAM_CSTR("hello world !"))
492 );
493
494 EXPECT_STREQ(
495 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>0035<D64>1122334455667788<D64>3333003232003100<D64>3500343434340033<D64>3636360035353535<D64>3737373700363636<D64>3838383800373737<D32>38383838<D8>00<FLAG>"),
496 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788,
497 "%s",
498 MIPI_SYST_PARAM_CSTR(""),
499 MIPI_SYST_PARAM_CSTR("1"),
500 MIPI_SYST_PARAM_CSTR("22"),
501 MIPI_SYST_PARAM_CSTR("333"),
502 MIPI_SYST_PARAM_CSTR("4444"),
503 MIPI_SYST_PARAM_CSTR("55555"),
504 MIPI_SYST_PARAM_CSTR("666666"),
505 MIPI_SYST_PARAM_CSTR("7777777"),
506 MIPI_SYST_PARAM_CSTR("88888888")
507 )
508 );
509 EXPECT_STREQ(
510 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>001e<D64>1122334455667788<D64>6f77206f6c6c6568<D64>3231002120646c72<D32>12340033<D16>abcd<FLAG>"),
511 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788,
512 "%s %s %d",
513 MIPI_SYST_PARAM_CSTR("hello world !"),
514 MIPI_SYST_PARAM_CSTR("123"),
515 MIPI_SYST_PARAM_INT(0xabcd1234)
516 )
517 );
518 }
519
TEST_F(MipiSysTFixturePrintf,syst_catalog64_printf_mixed)520 TEST_F(MipiSysTFixturePrintf, syst_catalog64_printf_mixed)
521 {
522 EXPECT_STREQ(
523 xform("<D32TS>02012243[typ=3:2 mu=1:2 sev=4 len]<D16>001e<D64>1122334455667788<D64>6f77206f6c6c6568<D64>3231002120646c72<D32>12340033<D16>abcd<FLAG>"),
524 MIPI_SYST_CATPRINTF64(ph, MIPI_SYST_SEVERITY_INFO, 0x1122334455667788,
525 "%s %s %d",
526 MIPI_SYST_PARAM_CSTR("hello world !"),
527 MIPI_SYST_PARAM_CSTR("123"),
528 MIPI_SYST_PARAM_INT(0xabcd1234)
529 )
530 );
531 }
532 #endif // #if defined(MIPI_SYST_PCFG_ENABLE_CATID64_API)
533
534 #if defined(MIPI_SYST_PCFG_ENABLE_CATID32_API)
535
TEST_F(MipiSysTFixturePrintf,syst_catalog32_printf_null)536 TEST_F(MipiSysTFixturePrintf, syst_catalog32_printf_null)
537 {
538 EXPECT_STREQ(
539 xform(""),
540 MIPI_SYST_CATPRINTF32(NULL, MIPI_SYST_SEVERITY_INFO, 0x11223344, "")
541 );
542 }
543
TEST_F(MipiSysTFixturePrintf,syst_catalog32_printf_invalid)544 TEST_F(MipiSysTFixturePrintf, syst_catalog32_printf_invalid)
545 {
546 EXPECT_STREQ(
547 xform("<D32TS>05012242[typ=2:5 mu=1:2 sev=4 len]<D16>0007<D32>61746163<D16>6772<D8>00<FLAG>"),
548 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344, -1, -1)
549 );
550 }
551
TEST_F(MipiSysTFixturePrintf,syst_catalog32_printf_basic)552 TEST_F(MipiSysTFixturePrintf, syst_catalog32_printf_basic)
553 {
554 EXPECT_STREQ(
555 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0004<D32>11223344<FLAG>"),
556 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344, "")
557 );
558
559 // check that format string is not added into payload
560 EXPECT_STREQ(
561 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0004<D32>11223344<FLAG>"),
562 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull, "Hello world")
563 );
564
565 EXPECT_STREQ(
566 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>0000005811223344<FLAG>"),
567 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
568 "%c", MIPI_SYST_PARAM_CHAR('X'))
569 );
570 EXPECT_STREQ(
571 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>0000123411223344<FLAG>"),
572 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
573 "%hhd", MIPI_SYST_PARAM_SHORT(0x1234))
574 );
575 EXPECT_STREQ(
576 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>0000005811223344<FLAG>"),
577 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
578 "%lc", MIPI_SYST_PARAM_WCHAR(L'X'))
579 );
580
581 EXPECT_STREQ(
582 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>abcd123411223344<FLAG>"),
583 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
584 "%d", MIPI_SYST_PARAM_INT(0xabcd1234))
585 );
586
587 EXPECT_STREQ(
588 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>8765432111223344<D32>12345678<FLAG>"),
589 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
590 "%lld", MIPI_SYST_PARAM_LONGLONG(0x1234567887654321ull))
591 );
592
593 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
594 EXPECT_STREQ(
595 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>1234567811223344<D32>00000000<FLAG>"),
596 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
597 "%ld", MIPI_SYST_PARAM_LONG(0x12345678))
598 );
599
600 EXPECT_STREQ(
601 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>8765432111223344<D32>12345678<FLAG>"),
602 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
603 "%z", MIPI_SYST_PARAM_SIZE_T(0x1234567887654321ull))
604 );
605 EXPECT_STREQ(
606 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>8765432111223344<D32>12345678<FLAG>"),
607 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
608 "%t", MIPI_SYST_PARAM_PTRDIFF_T(0x1234567887654321ull))
609 );
610 EXPECT_STREQ(
611 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>8765432111223344<D32>12345678<FLAG>"),
612 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
613 "%p", MIPI_SYST_PARAM_PTR(0x1234567887654321ull))
614 );
615 #else
616 EXPECT_STREQ(
617 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>1234567811223344<FLAG>"),
618 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
619 "%ld", MIPI_SYST_PARAM_LONG(0x12345678))
620 );
621
622 EXPECT_STREQ(
623 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>1234567811223344<FLAG>"),
624 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
625 "%z", MIPI_SYST_PARAM_SIZE_T(0x12345678))
626 );
627 EXPECT_STREQ(
628 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>1234567811223344<FLAG>"),
629 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
630 "%t", MIPI_SYST_PARAM_PTRDIFF_T(0x12345678))
631 );
632 EXPECT_STREQ(
633 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0008<D64>1234567811223344<FLAG>"),
634 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
635 "%p", MIPI_SYST_PARAM_PTR(0x12345678))
636 );
637 #endif //defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
638
639 EXPECT_STREQ(
640 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>0000000011223344<D32>40000000<FLAG>"),
641 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
642 "%f", MIPI_SYST_PARAM_FLOAT((float)2.0))
643 );
644 EXPECT_STREQ(
645 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>0000000011223344<D32>40000000<FLAG>"),
646 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
647 "%f", MIPI_SYST_PARAM_DOUBLE((double)2.0))
648 );
649 EXPECT_STREQ(
650 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>000c<D64>0000000011223344<D32>40000000<FLAG>"),
651 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344ull,
652 "%lf", MIPI_SYST_PARAM_LONGDOUBLE((long double)2.0))
653 );
654 }
655
TEST_F(MipiSysTFixturePrintf,syst_catalog32_printf_string)656 TEST_F(MipiSysTFixturePrintf, syst_catalog32_printf_string)
657 {
658 EXPECT_STREQ(
659 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0005<D32>11223344<D8>00<FLAG>"),
660 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344,
661 "%s", MIPI_SYST_PARAM_CSTR(""))
662 );
663
664 EXPECT_STREQ(
665 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0012<D64>6c6c656811223344<D64>20646c726f77206f<D16>0021<FLAG>"),
666 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344,
667 "%s", MIPI_SYST_PARAM_CSTR("hello world !"))
668 );
669
670 EXPECT_STREQ(
671 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>0031<D64>3200310011223344<D64>3434003333330032<D64>3535353535003434<D64>0036363636363600<D64>0037373737373737<D64>3838383838383838<D8>00<FLAG>"),
672 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344,
673 "%s",
674 MIPI_SYST_PARAM_CSTR(""),
675 MIPI_SYST_PARAM_CSTR("1"),
676 MIPI_SYST_PARAM_CSTR("22"),
677 MIPI_SYST_PARAM_CSTR("333"),
678 MIPI_SYST_PARAM_CSTR("4444"),
679 MIPI_SYST_PARAM_CSTR("55555"),
680 MIPI_SYST_PARAM_CSTR("666666"),
681 MIPI_SYST_PARAM_CSTR("7777777"),
682 MIPI_SYST_PARAM_CSTR("88888888")
683 )
684 );
685 EXPECT_STREQ(
686 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>001a<D64>6c6c656811223344<D64>20646c726f77206f<D64>1234003332310021<D16>abcd<FLAG>"),
687 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344,
688 "%s %s %d",
689 MIPI_SYST_PARAM_CSTR("hello world !"),
690 MIPI_SYST_PARAM_CSTR("123"),
691 MIPI_SYST_PARAM_INT(0xabcd1234)
692 )
693 );
694 }
695
TEST_F(MipiSysTFixturePrintf,syst_catalog32_printf_mixed)696 TEST_F(MipiSysTFixturePrintf, syst_catalog32_printf_mixed)
697 {
698 EXPECT_STREQ(
699 xform("<D32TS>01012243[typ=3:1 mu=1:2 sev=4 len]<D16>001a<D64>6c6c656811223344<D64>20646c726f77206f<D64>1234003332310021<D16>abcd<FLAG>"),
700 MIPI_SYST_CATPRINTF32(ph, MIPI_SYST_SEVERITY_INFO, 0x11223344,
701 "%s %s %d",
702 MIPI_SYST_PARAM_CSTR("hello world !"),
703 MIPI_SYST_PARAM_CSTR("123"),
704 MIPI_SYST_PARAM_INT(0xabcd1234)
705 )
706 );
707 }
708 #endif // #if defined(MIPI_SYST_PCFG_ENABLE_CATID32_API)
709 #endif //MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA && MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE && MIPI_SYST_PCFG_ENABLE_PRINTF_API