net: sched: pie: add derandomization mechanism
[sfrench/cifs-2.6.git] / lib / test_printf.c
index 53527ea822b53c0c35eb0025cd80cecde54403b3..659b6cc0d483e3018a3b511bb53d714ee116cbcb 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/module.h>
 #include <linux/printk.h>
 #include <linux/random.h>
+#include <linux/rtc.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 
@@ -249,12 +250,11 @@ plain_format(void)
 #endif /* BITS_PER_LONG == 64 */
 
 static int __init
-plain_hash(void)
+plain_hash_to_buffer(const void *p, char *buf, size_t len)
 {
-       char buf[PLAIN_BUF_SIZE];
        int nchars;
 
-       nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR);
+       nchars = snprintf(buf, len, "%p", p);
 
        if (nchars != PTR_WIDTH)
                return -1;
@@ -265,6 +265,20 @@ plain_hash(void)
                return 0;
        }
 
+       return 0;
+}
+
+
+static int __init
+plain_hash(void)
+{
+       char buf[PLAIN_BUF_SIZE];
+       int ret;
+
+       ret = plain_hash_to_buffer(PTR, buf, PLAIN_BUF_SIZE);
+       if (ret)
+               return ret;
+
        if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0)
                return -1;
 
@@ -294,6 +308,23 @@ plain(void)
        }
 }
 
+static void __init
+test_hashed(const char *fmt, const void *p)
+{
+       char buf[PLAIN_BUF_SIZE];
+       int ret;
+
+       /*
+        * No need to increase failed test counter since this is assumed
+        * to be called after plain().
+        */
+       ret = plain_hash_to_buffer(p, buf, PLAIN_BUF_SIZE);
+       if (ret)
+               return;
+
+       test(buf, fmt, p);
+}
+
 static void __init
 symbol_ptr(void)
 {
@@ -418,6 +449,29 @@ struct_va_format(void)
 {
 }
 
+static void __init
+struct_rtc_time(void)
+{
+       /* 1543210543 */
+       const struct rtc_time tm = {
+               .tm_sec = 43,
+               .tm_min = 35,
+               .tm_hour = 5,
+               .tm_mday = 26,
+               .tm_mon = 10,
+               .tm_year = 118,
+       };
+
+       test_hashed("%pt", &tm);
+
+       test("2018-11-26T05:35:43", "%ptR", &tm);
+       test("0118-10-26T05:35:43", "%ptRr", &tm);
+       test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm);
+       test("05:35:43|0118-10-26", "%ptRtr|%ptRdr", &tm, &tm);
+       test("05:35:43|2018-11-26", "%ptRttr|%ptRdtr", &tm, &tm);
+       test("05:35:43 tr|2018-11-26 tr", "%ptRt tr|%ptRd tr", &tm, &tm);
+}
+
 static void __init
 struct_clk(void)
 {
@@ -529,6 +583,7 @@ test_pointer(void)
        uuid();
        dentry();
        struct_va_format();
+       struct_rtc_time();
        struct_clk();
        bitmap();
        netdev_features();