Merge tag 'platform-drivers-x86-v4.5-2' of git://git.infradead.org/users/dvhart/linux...
[deliverable/linux.git] / lib / test_printf.c
index 3393d667c6b8ae99cf8a3cd65fac086250edefe9..4f6ae60433bc5d1e1d6df9b7c8d5d359512ad82a 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 
+#include <linux/bitmap.h>
+#include <linux/dcache.h>
 #include <linux/socket.h>
 #include <linux/in.h>
 
@@ -127,6 +129,7 @@ __test(const char *expect, int elen, const char *fmt, ...)
 
        p = kvasprintf(GFP_KERNEL, fmt, ap);
        if (p) {
+               total_tests++;
                if (memcmp(p, expect, elen+1)) {
                        pr_warn("kvasprintf(..., \"%s\", ...) returned '%s', expected '%s'\n",
                                fmt, p, expect);
@@ -158,6 +161,30 @@ test_number(void)
        test("0x1234abcd  ", "%#-12x", 0x1234abcd);
        test("  0x1234abcd", "%#12x", 0x1234abcd);
        test("0|001| 12|+123| 1234|-123|-1234", "%d|%03d|%3d|%+d|% d|%+d|% d", 0, 1, 12, 123, 1234, -123, -1234);
+       test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1);
+       test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1);
+       test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627);
+       /*
+        * POSIX/C99: »The result of converting zero with an explicit
+        * precision of zero shall be no characters.« Hence the output
+        * from the below test should really be "00|0||| ". However,
+        * the kernel's printf also produces a single 0 in that
+        * case. This test case simply documents the current
+        * behaviour.
+        */
+       test("00|0|0|0|0", "%.2d|%.1d|%.0d|%.*d|%1.0d", 0, 0, 0, 0, 0, 0);
+#ifndef __CHAR_UNSIGNED__
+       {
+               /*
+                * Passing a 'char' to a %02x specifier doesn't do
+                * what was presumably the intention when char is
+                * signed and the value is negative. One must either &
+                * with 0xff or cast to u8.
+                */
+               char val = -16;
+               test("0xfffffff0|0xf0|0xf0", "%#02x|%#02x|%#02x", val, val & 0xff, (u8)val);
+       }
+#endif
 }
 
 static void __init
@@ -300,9 +327,35 @@ uuid(void)
        test("03020100-0504-0706-0809-0A0B0C0D0E0F", "%pUL", uuid);
 }
 
+static struct dentry test_dentry[4] __initdata = {
+       { .d_parent = &test_dentry[0],
+         .d_name = QSTR_INIT(test_dentry[0].d_iname, 3),
+         .d_iname = "foo" },
+       { .d_parent = &test_dentry[0],
+         .d_name = QSTR_INIT(test_dentry[1].d_iname, 5),
+         .d_iname = "bravo" },
+       { .d_parent = &test_dentry[1],
+         .d_name = QSTR_INIT(test_dentry[2].d_iname, 4),
+         .d_iname = "alfa" },
+       { .d_parent = &test_dentry[2],
+         .d_name = QSTR_INIT(test_dentry[3].d_iname, 5),
+         .d_iname = "romeo" },
+};
+
 static void __init
 dentry(void)
 {
+       test("foo", "%pd", &test_dentry[0]);
+       test("foo", "%pd2", &test_dentry[0]);
+
+       test("romeo", "%pd", &test_dentry[3]);
+       test("alfa/romeo", "%pd2", &test_dentry[3]);
+       test("bravo/alfa/romeo", "%pd3", &test_dentry[3]);
+       test("/bravo/alfa/romeo", "%pd4", &test_dentry[3]);
+       test("/bravo/alfa", "%pd4", &test_dentry[2]);
+
+       test("bravo/alfa  |bravo/alfa  ", "%-12pd2|%*pd2", &test_dentry[2], -12, &test_dentry[2]);
+       test("  bravo/alfa|  bravo/alfa", "%12pd2|%*pd2", &test_dentry[2], 12, &test_dentry[2]);
 }
 
 static void __init
@@ -315,6 +368,20 @@ struct_clk(void)
 {
 }
 
+static void __init
+large_bitmap(void)
+{
+       const int nbits = 1 << 16;
+       unsigned long *bits = kcalloc(BITS_TO_LONGS(nbits), sizeof(long), GFP_KERNEL);
+       if (!bits)
+               return;
+
+       bitmap_set(bits, 1, 20);
+       bitmap_set(bits, 60000, 15);
+       test("1-20,60000-60014", "%*pbl", nbits, bits);
+       kfree(bits);
+}
+
 static void __init
 bitmap(void)
 {
@@ -334,6 +401,8 @@ bitmap(void)
        bitmap_fill(bits, 20);
        test("fffff|fffff", "%20pb|%*pb", bits, 20, bits);
        test("0-19|0-19", "%20pbl|%*pbl", bits, 20, bits);
+
+       large_bitmap();
 }
 
 static void __init
This page took 0.031983 seconds and 5 git commands to generate.