diff options
Diffstat (limited to 'lib/test_printf.c')
-rw-r--r-- | lib/test_printf.c | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/lib/test_printf.c b/lib/test_printf.c index 53527ea822b5..659b6cc0d483 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/module.h> | 9 | #include <linux/module.h> |
10 | #include <linux/printk.h> | 10 | #include <linux/printk.h> |
11 | #include <linux/random.h> | 11 | #include <linux/random.h> |
12 | #include <linux/rtc.h> | ||
12 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
13 | #include <linux/string.h> | 14 | #include <linux/string.h> |
14 | 15 | ||
@@ -249,12 +250,11 @@ plain_format(void) | |||
249 | #endif /* BITS_PER_LONG == 64 */ | 250 | #endif /* BITS_PER_LONG == 64 */ |
250 | 251 | ||
251 | static int __init | 252 | static int __init |
252 | plain_hash(void) | 253 | plain_hash_to_buffer(const void *p, char *buf, size_t len) |
253 | { | 254 | { |
254 | char buf[PLAIN_BUF_SIZE]; | ||
255 | int nchars; | 255 | int nchars; |
256 | 256 | ||
257 | nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR); | 257 | nchars = snprintf(buf, len, "%p", p); |
258 | 258 | ||
259 | if (nchars != PTR_WIDTH) | 259 | if (nchars != PTR_WIDTH) |
260 | return -1; | 260 | return -1; |
@@ -265,6 +265,20 @@ plain_hash(void) | |||
265 | return 0; | 265 | return 0; |
266 | } | 266 | } |
267 | 267 | ||
268 | return 0; | ||
269 | } | ||
270 | |||
271 | |||
272 | static int __init | ||
273 | plain_hash(void) | ||
274 | { | ||
275 | char buf[PLAIN_BUF_SIZE]; | ||
276 | int ret; | ||
277 | |||
278 | ret = plain_hash_to_buffer(PTR, buf, PLAIN_BUF_SIZE); | ||
279 | if (ret) | ||
280 | return ret; | ||
281 | |||
268 | if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0) | 282 | if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0) |
269 | return -1; | 283 | return -1; |
270 | 284 | ||
@@ -295,6 +309,23 @@ plain(void) | |||
295 | } | 309 | } |
296 | 310 | ||
297 | static void __init | 311 | static void __init |
312 | test_hashed(const char *fmt, const void *p) | ||
313 | { | ||
314 | char buf[PLAIN_BUF_SIZE]; | ||
315 | int ret; | ||
316 | |||
317 | /* | ||
318 | * No need to increase failed test counter since this is assumed | ||
319 | * to be called after plain(). | ||
320 | */ | ||
321 | ret = plain_hash_to_buffer(p, buf, PLAIN_BUF_SIZE); | ||
322 | if (ret) | ||
323 | return; | ||
324 | |||
325 | test(buf, fmt, p); | ||
326 | } | ||
327 | |||
328 | static void __init | ||
298 | symbol_ptr(void) | 329 | symbol_ptr(void) |
299 | { | 330 | { |
300 | } | 331 | } |
@@ -419,6 +450,29 @@ struct_va_format(void) | |||
419 | } | 450 | } |
420 | 451 | ||
421 | static void __init | 452 | static void __init |
453 | struct_rtc_time(void) | ||
454 | { | ||
455 | /* 1543210543 */ | ||
456 | const struct rtc_time tm = { | ||
457 | .tm_sec = 43, | ||
458 | .tm_min = 35, | ||
459 | .tm_hour = 5, | ||
460 | .tm_mday = 26, | ||
461 | .tm_mon = 10, | ||
462 | .tm_year = 118, | ||
463 | }; | ||
464 | |||
465 | test_hashed("%pt", &tm); | ||
466 | |||
467 | test("2018-11-26T05:35:43", "%ptR", &tm); | ||
468 | test("0118-10-26T05:35:43", "%ptRr", &tm); | ||
469 | test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm); | ||
470 | test("05:35:43|0118-10-26", "%ptRtr|%ptRdr", &tm, &tm); | ||
471 | test("05:35:43|2018-11-26", "%ptRttr|%ptRdtr", &tm, &tm); | ||
472 | test("05:35:43 tr|2018-11-26 tr", "%ptRt tr|%ptRd tr", &tm, &tm); | ||
473 | } | ||
474 | |||
475 | static void __init | ||
422 | struct_clk(void) | 476 | struct_clk(void) |
423 | { | 477 | { |
424 | } | 478 | } |
@@ -529,6 +583,7 @@ test_pointer(void) | |||
529 | uuid(); | 583 | uuid(); |
530 | dentry(); | 584 | dentry(); |
531 | struct_va_format(); | 585 | struct_va_format(); |
586 | struct_rtc_time(); | ||
532 | struct_clk(); | 587 | struct_clk(); |
533 | bitmap(); | 588 | bitmap(); |
534 | netdev_features(); | 589 | netdev_features(); |