Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Test cases for printf facility. |
| 4 | */ |
| 5 | |
| 6 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 7 | |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/printk.h> |
| 12 | #include <linux/random.h> |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 13 | #include <linux/rtc.h> |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 14 | #include <linux/slab.h> |
| 15 | #include <linux/string.h> |
| 16 | |
Rasmus Villemoes | 857cca4 | 2016-01-15 16:59:06 -0800 | [diff] [blame] | 17 | #include <linux/bitmap.h> |
Rasmus Villemoes | 251c723 | 2016-01-15 16:59:09 -0800 | [diff] [blame] | 18 | #include <linux/dcache.h> |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 19 | #include <linux/socket.h> |
| 20 | #include <linux/in.h> |
| 21 | |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 22 | #include <linux/gfp.h> |
| 23 | #include <linux/mm.h> |
| 24 | |
Sakari Ailus | f1ce39d | 2019-10-03 15:32:19 +0300 | [diff] [blame] | 25 | #include <linux/property.h> |
| 26 | |
Tobin C. Harding | 6b1a4d5 | 2019-04-05 12:58:57 +1100 | [diff] [blame] | 27 | #include "../tools/testing/selftests/kselftest_module.h" |
| 28 | |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 29 | #define BUF_SIZE 256 |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 30 | #define PAD_SIZE 16 |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 31 | #define FILL_CHAR '$' |
| 32 | |
Timur Tabi | 4e89a78 | 2021-02-14 10:13:46 -0600 | [diff] [blame] | 33 | KSTM_MODULE_GLOBALS(); |
| 34 | |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 35 | static char *test_buffer __initdata; |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 36 | static char *alloced_buffer __initdata; |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 37 | |
Timur Tabi | 5ead723 | 2021-02-14 10:13:48 -0600 | [diff] [blame] | 38 | extern bool no_hash_pointers; |
| 39 | |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 40 | static int __printf(4, 0) __init |
| 41 | do_test(int bufsize, const char *expect, int elen, |
| 42 | const char *fmt, va_list ap) |
| 43 | { |
| 44 | va_list aq; |
| 45 | int ret, written; |
| 46 | |
| 47 | total_tests++; |
| 48 | |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 49 | memset(alloced_buffer, FILL_CHAR, BUF_SIZE + 2*PAD_SIZE); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 50 | va_copy(aq, ap); |
| 51 | ret = vsnprintf(test_buffer, bufsize, fmt, aq); |
| 52 | va_end(aq); |
| 53 | |
| 54 | if (ret != elen) { |
| 55 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n", |
| 56 | bufsize, fmt, ret, elen); |
| 57 | return 1; |
| 58 | } |
| 59 | |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 60 | if (memchr_inv(alloced_buffer, FILL_CHAR, PAD_SIZE)) { |
| 61 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote before buffer\n", bufsize, fmt); |
| 62 | return 1; |
| 63 | } |
| 64 | |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 65 | if (!bufsize) { |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 66 | if (memchr_inv(test_buffer, FILL_CHAR, BUF_SIZE + PAD_SIZE)) { |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 67 | pr_warn("vsnprintf(buf, 0, \"%s\", ...) wrote to buffer\n", |
| 68 | fmt); |
| 69 | return 1; |
| 70 | } |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | written = min(bufsize-1, elen); |
| 75 | if (test_buffer[written]) { |
| 76 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) did not nul-terminate buffer\n", |
| 77 | bufsize, fmt); |
| 78 | return 1; |
| 79 | } |
| 80 | |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 81 | if (memchr_inv(test_buffer + written + 1, FILL_CHAR, BUF_SIZE + PAD_SIZE - (written + 1))) { |
| 82 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote beyond the nul-terminator\n", |
| 83 | bufsize, fmt); |
| 84 | return 1; |
| 85 | } |
| 86 | |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 87 | if (memcmp(test_buffer, expect, written)) { |
| 88 | pr_warn("vsnprintf(buf, %d, \"%s\", ...) wrote '%s', expected '%.*s'\n", |
| 89 | bufsize, fmt, test_buffer, written, expect); |
| 90 | return 1; |
| 91 | } |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static void __printf(3, 4) __init |
| 96 | __test(const char *expect, int elen, const char *fmt, ...) |
| 97 | { |
| 98 | va_list ap; |
| 99 | int rand; |
| 100 | char *p; |
| 101 | |
Rasmus Villemoes | fd0515d | 2016-01-15 16:58:50 -0800 | [diff] [blame] | 102 | if (elen >= BUF_SIZE) { |
| 103 | pr_err("error in test suite: expected output length %d too long. Format was '%s'.\n", |
| 104 | elen, fmt); |
| 105 | failed_tests++; |
| 106 | return; |
| 107 | } |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 108 | |
| 109 | va_start(ap, fmt); |
| 110 | |
| 111 | /* |
| 112 | * Every fmt+args is subjected to four tests: Three where we |
| 113 | * tell vsnprintf varying buffer sizes (plenty, not quite |
| 114 | * enough and 0), and then we also test that kvasprintf would |
| 115 | * be able to print it as expected. |
| 116 | */ |
| 117 | failed_tests += do_test(BUF_SIZE, expect, elen, fmt, ap); |
| 118 | rand = 1 + prandom_u32_max(elen+1); |
| 119 | /* Since elen < BUF_SIZE, we have 1 <= rand <= BUF_SIZE. */ |
| 120 | failed_tests += do_test(rand, expect, elen, fmt, ap); |
| 121 | failed_tests += do_test(0, expect, elen, fmt, ap); |
| 122 | |
| 123 | p = kvasprintf(GFP_KERNEL, fmt, ap); |
| 124 | if (p) { |
Rasmus Villemoes | b79a7db | 2016-01-15 16:59:02 -0800 | [diff] [blame] | 125 | total_tests++; |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 126 | if (memcmp(p, expect, elen+1)) { |
| 127 | pr_warn("kvasprintf(..., \"%s\", ...) returned '%s', expected '%s'\n", |
| 128 | fmt, p, expect); |
| 129 | failed_tests++; |
| 130 | } |
| 131 | kfree(p); |
| 132 | } |
| 133 | va_end(ap); |
| 134 | } |
| 135 | |
| 136 | #define test(expect, fmt, ...) \ |
| 137 | __test(expect, strlen(expect), fmt, ##__VA_ARGS__) |
| 138 | |
| 139 | static void __init |
| 140 | test_basic(void) |
| 141 | { |
| 142 | /* Work around annoying "warning: zero-length gnu_printf format string". */ |
| 143 | char nul = '\0'; |
| 144 | |
| 145 | test("", &nul); |
| 146 | test("100%", "100%%"); |
| 147 | test("xxx%yyy", "xxx%cyyy", '%'); |
| 148 | __test("xxx\0yyy", 7, "xxx%cyyy", '\0'); |
| 149 | } |
| 150 | |
| 151 | static void __init |
| 152 | test_number(void) |
| 153 | { |
| 154 | test("0x1234abcd ", "%#-12x", 0x1234abcd); |
| 155 | test(" 0x1234abcd", "%#12x", 0x1234abcd); |
| 156 | test("0|001| 12|+123| 1234|-123|-1234", "%d|%03d|%3d|%+d|% d|%+d|% d", 0, 1, 12, 123, 1234, -123, -1234); |
Rasmus Villemoes | 1ca8e8e | 2016-01-15 16:58:59 -0800 | [diff] [blame] | 157 | test("0|1|1|128|255", "%hhu|%hhu|%hhu|%hhu|%hhu", 0, 1, 257, 128, -1); |
| 158 | test("0|1|1|-128|-1", "%hhd|%hhd|%hhd|%hhd|%hhd", 0, 1, 257, 128, -1); |
| 159 | test("2015122420151225", "%ho%ho%#ho", 1037, 5282, -11627); |
| 160 | /* |
| 161 | * POSIX/C99: »The result of converting zero with an explicit |
| 162 | * precision of zero shall be no characters.« Hence the output |
| 163 | * from the below test should really be "00|0||| ". However, |
| 164 | * the kernel's printf also produces a single 0 in that |
| 165 | * case. This test case simply documents the current |
| 166 | * behaviour. |
| 167 | */ |
| 168 | test("00|0|0|0|0", "%.2d|%.1d|%.0d|%.*d|%1.0d", 0, 0, 0, 0, 0, 0); |
| 169 | #ifndef __CHAR_UNSIGNED__ |
| 170 | { |
| 171 | /* |
| 172 | * Passing a 'char' to a %02x specifier doesn't do |
| 173 | * what was presumably the intention when char is |
| 174 | * signed and the value is negative. One must either & |
| 175 | * with 0xff or cast to u8. |
| 176 | */ |
| 177 | char val = -16; |
| 178 | test("0xfffffff0|0xf0|0xf0", "%#02x|%#02x|%#02x", val, val & 0xff, (u8)val); |
| 179 | } |
| 180 | #endif |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | static void __init |
| 184 | test_string(void) |
| 185 | { |
| 186 | test("", "%s%.0s", "", "123"); |
| 187 | test("ABCD|abc|123", "%s|%.3s|%.*s", "ABCD", "abcdef", 3, "123456"); |
| 188 | test("1 | 2|3 | 4|5 ", "%-3s|%3s|%-*s|%*s|%*s", "1", "2", 3, "3", 3, "4", -3, "5"); |
Rasmus Villemoes | f176eb4 | 2016-01-15 16:58:56 -0800 | [diff] [blame] | 189 | test("1234 ", "%-10.4s", "123456"); |
| 190 | test(" 1234", "%10.4s", "123456"); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 191 | /* |
Rasmus Villemoes | f176eb4 | 2016-01-15 16:58:56 -0800 | [diff] [blame] | 192 | * POSIX and C99 say that a negative precision (which is only |
| 193 | * possible to pass via a * argument) should be treated as if |
| 194 | * the precision wasn't present, and that if the precision is |
| 195 | * omitted (as in %.s), the precision should be taken to be |
| 196 | * 0. However, the kernel's printf behave exactly opposite, |
| 197 | * treating a negative precision as 0 and treating an omitted |
| 198 | * precision specifier as if no precision was given. |
| 199 | * |
| 200 | * These test cases document the current behaviour; should |
| 201 | * anyone ever feel the need to follow the standards more |
| 202 | * closely, this can be revisited. |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 203 | */ |
Rasmus Villemoes | f176eb4 | 2016-01-15 16:58:56 -0800 | [diff] [blame] | 204 | test(" ", "%4.*s", -5, "123456"); |
| 205 | test("123456", "%.s", "123456"); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 206 | test("a||", "%.s|%.0s|%.*s", "a", "b", 0, "c"); |
| 207 | test("a | | ", "%-3.s|%-3.0s|%-3.*s", "a", "b", 0, "c"); |
| 208 | } |
| 209 | |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 210 | #define PLAIN_BUF_SIZE 64 /* leave some space so we don't oops */ |
| 211 | |
| 212 | #if BITS_PER_LONG == 64 |
| 213 | |
| 214 | #define PTR_WIDTH 16 |
Andy Shevchenko | c604b40 | 2018-02-16 23:07:03 +0200 | [diff] [blame] | 215 | #define PTR ((void *)0xffff0123456789abUL) |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 216 | #define PTR_STR "ffff0123456789ab" |
Thierry Escande | ce041c4 | 2018-06-13 19:18:40 +0200 | [diff] [blame] | 217 | #define PTR_VAL_NO_CRNG "(____ptrval____)" |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 218 | #define ZEROS "00000000" /* hex 32 zero bits */ |
Ilya Dryomov | 7bd57fb | 2020-05-19 13:26:57 +0200 | [diff] [blame] | 219 | #define ONES "ffffffff" /* hex 32 one bits */ |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 220 | |
| 221 | static int __init |
| 222 | plain_format(void) |
| 223 | { |
| 224 | char buf[PLAIN_BUF_SIZE]; |
| 225 | int nchars; |
| 226 | |
| 227 | nchars = snprintf(buf, PLAIN_BUF_SIZE, "%p", PTR); |
| 228 | |
Thierry Escande | ce041c4 | 2018-06-13 19:18:40 +0200 | [diff] [blame] | 229 | if (nchars != PTR_WIDTH) |
| 230 | return -1; |
| 231 | |
| 232 | if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) { |
| 233 | pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"", |
| 234 | PTR_VAL_NO_CRNG); |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | if (strncmp(buf, ZEROS, strlen(ZEROS)) != 0) |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 239 | return -1; |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | #else |
| 245 | |
| 246 | #define PTR_WIDTH 8 |
| 247 | #define PTR ((void *)0x456789ab) |
| 248 | #define PTR_STR "456789ab" |
Thierry Escande | ce041c4 | 2018-06-13 19:18:40 +0200 | [diff] [blame] | 249 | #define PTR_VAL_NO_CRNG "(ptrval)" |
Petr Mladek | 3e5903e | 2019-04-17 13:53:48 +0200 | [diff] [blame] | 250 | #define ZEROS "" |
Ilya Dryomov | 7bd57fb | 2020-05-19 13:26:57 +0200 | [diff] [blame] | 251 | #define ONES "" |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 252 | |
| 253 | static int __init |
| 254 | plain_format(void) |
| 255 | { |
| 256 | /* Format is implicitly tested for 32 bit machines by plain_hash() */ |
| 257 | return 0; |
| 258 | } |
| 259 | |
| 260 | #endif /* BITS_PER_LONG == 64 */ |
| 261 | |
| 262 | static int __init |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 263 | plain_hash_to_buffer(const void *p, char *buf, size_t len) |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 264 | { |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 265 | int nchars; |
| 266 | |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 267 | nchars = snprintf(buf, len, "%p", p); |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 268 | |
Thierry Escande | ce041c4 | 2018-06-13 19:18:40 +0200 | [diff] [blame] | 269 | if (nchars != PTR_WIDTH) |
| 270 | return -1; |
| 271 | |
| 272 | if (strncmp(buf, PTR_VAL_NO_CRNG, PTR_WIDTH) == 0) { |
| 273 | pr_warn("crng possibly not yet initialized. plain 'p' buffer contains \"%s\"", |
| 274 | PTR_VAL_NO_CRNG); |
| 275 | return 0; |
| 276 | } |
| 277 | |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 281 | static int __init |
| 282 | plain_hash(void) |
| 283 | { |
| 284 | char buf[PLAIN_BUF_SIZE]; |
| 285 | int ret; |
| 286 | |
| 287 | ret = plain_hash_to_buffer(PTR, buf, PLAIN_BUF_SIZE); |
| 288 | if (ret) |
| 289 | return ret; |
| 290 | |
Thierry Escande | ce041c4 | 2018-06-13 19:18:40 +0200 | [diff] [blame] | 291 | if (strncmp(buf, PTR_STR, PTR_WIDTH) == 0) |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 292 | return -1; |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * We can't use test() to test %p because we don't know what output to expect |
| 299 | * after an address is hashed. |
| 300 | */ |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 301 | static void __init |
| 302 | plain(void) |
| 303 | { |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 304 | int err; |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 305 | |
Timur Tabi | 5ead723 | 2021-02-14 10:13:48 -0600 | [diff] [blame] | 306 | if (no_hash_pointers) { |
| 307 | pr_warn("skipping plain 'p' tests"); |
| 308 | skipped_tests += 2; |
| 309 | return; |
| 310 | } |
| 311 | |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 312 | err = plain_hash(); |
| 313 | if (err) { |
| 314 | pr_warn("plain 'p' does not appear to be hashed\n"); |
| 315 | failed_tests++; |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | err = plain_format(); |
| 320 | if (err) { |
| 321 | pr_warn("hashing plain 'p' has unexpected format\n"); |
| 322 | failed_tests++; |
| 323 | } |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | static void __init |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 327 | test_hashed(const char *fmt, const void *p) |
| 328 | { |
| 329 | char buf[PLAIN_BUF_SIZE]; |
| 330 | int ret; |
| 331 | |
| 332 | /* |
| 333 | * No need to increase failed test counter since this is assumed |
| 334 | * to be called after plain(). |
| 335 | */ |
| 336 | ret = plain_hash_to_buffer(p, buf, PLAIN_BUF_SIZE); |
| 337 | if (ret) |
| 338 | return; |
| 339 | |
| 340 | test(buf, fmt, p); |
| 341 | } |
| 342 | |
Ilya Dryomov | 7bd57fb | 2020-05-19 13:26:57 +0200 | [diff] [blame] | 343 | /* |
| 344 | * NULL pointers aren't hashed. |
| 345 | */ |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 346 | static void __init |
Petr Mladek | 3e5903e | 2019-04-17 13:53:48 +0200 | [diff] [blame] | 347 | null_pointer(void) |
| 348 | { |
Ilya Dryomov | 7bd57fb | 2020-05-19 13:26:57 +0200 | [diff] [blame] | 349 | test(ZEROS "00000000", "%p", NULL); |
Petr Mladek | 3e5903e | 2019-04-17 13:53:48 +0200 | [diff] [blame] | 350 | test(ZEROS "00000000", "%px", NULL); |
| 351 | test("(null)", "%pE", NULL); |
| 352 | } |
| 353 | |
Ilya Dryomov | 7bd57fb | 2020-05-19 13:26:57 +0200 | [diff] [blame] | 354 | /* |
| 355 | * Error pointers aren't hashed. |
| 356 | */ |
| 357 | static void __init |
| 358 | error_pointer(void) |
| 359 | { |
| 360 | test(ONES "fffffff5", "%p", ERR_PTR(-11)); |
| 361 | test(ONES "fffffff5", "%px", ERR_PTR(-11)); |
| 362 | test("(efault)", "%pE", ERR_PTR(-11)); |
| 363 | } |
| 364 | |
Petr Mladek | 3e5903e | 2019-04-17 13:53:48 +0200 | [diff] [blame] | 365 | #define PTR_INVALID ((void *)0x000000ab) |
| 366 | |
| 367 | static void __init |
| 368 | invalid_pointer(void) |
| 369 | { |
| 370 | test_hashed("%p", PTR_INVALID); |
| 371 | test(ZEROS "000000ab", "%px", PTR_INVALID); |
| 372 | test("(efault)", "%pE", PTR_INVALID); |
| 373 | } |
| 374 | |
| 375 | static void __init |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 376 | symbol_ptr(void) |
| 377 | { |
| 378 | } |
| 379 | |
| 380 | static void __init |
| 381 | kernel_ptr(void) |
| 382 | { |
Tobin C. Harding | ad67b74 | 2017-11-01 15:32:23 +1100 | [diff] [blame] | 383 | /* We can't test this without access to kptr_restrict. */ |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static void __init |
| 387 | struct_resource(void) |
| 388 | { |
| 389 | } |
| 390 | |
| 391 | static void __init |
| 392 | addr(void) |
| 393 | { |
| 394 | } |
| 395 | |
| 396 | static void __init |
| 397 | escaped_str(void) |
| 398 | { |
| 399 | } |
| 400 | |
| 401 | static void __init |
| 402 | hex_string(void) |
| 403 | { |
| 404 | const char buf[3] = {0xc0, 0xff, 0xee}; |
| 405 | |
| 406 | test("c0 ff ee|c0:ff:ee|c0-ff-ee|c0ffee", |
| 407 | "%3ph|%3phC|%3phD|%3phN", buf, buf, buf, buf); |
| 408 | test("c0 ff ee|c0:ff:ee|c0-ff-ee|c0ffee", |
| 409 | "%*ph|%*phC|%*phD|%*phN", 3, buf, 3, buf, 3, buf, 3, buf); |
| 410 | } |
| 411 | |
| 412 | static void __init |
| 413 | mac(void) |
| 414 | { |
| 415 | const u8 addr[6] = {0x2d, 0x48, 0xd6, 0xfc, 0x7a, 0x05}; |
| 416 | |
| 417 | test("2d:48:d6:fc:7a:05", "%pM", addr); |
| 418 | test("05:7a:fc:d6:48:2d", "%pMR", addr); |
| 419 | test("2d-48-d6-fc-7a-05", "%pMF", addr); |
| 420 | test("2d48d6fc7a05", "%pm", addr); |
| 421 | test("057afcd6482d", "%pmR", addr); |
| 422 | } |
| 423 | |
| 424 | static void __init |
| 425 | ip4(void) |
| 426 | { |
| 427 | struct sockaddr_in sa; |
| 428 | |
| 429 | sa.sin_family = AF_INET; |
| 430 | sa.sin_port = cpu_to_be16(12345); |
| 431 | sa.sin_addr.s_addr = cpu_to_be32(0x7f000001); |
| 432 | |
| 433 | test("127.000.000.001|127.0.0.1", "%pi4|%pI4", &sa.sin_addr, &sa.sin_addr); |
| 434 | test("127.000.000.001|127.0.0.1", "%piS|%pIS", &sa, &sa); |
| 435 | sa.sin_addr.s_addr = cpu_to_be32(0x01020304); |
| 436 | test("001.002.003.004:12345|1.2.3.4:12345", "%piSp|%pISp", &sa, &sa); |
| 437 | } |
| 438 | |
| 439 | static void __init |
| 440 | ip6(void) |
| 441 | { |
| 442 | } |
| 443 | |
| 444 | static void __init |
| 445 | ip(void) |
| 446 | { |
| 447 | ip4(); |
| 448 | ip6(); |
| 449 | } |
| 450 | |
| 451 | static void __init |
| 452 | uuid(void) |
| 453 | { |
| 454 | const char uuid[16] = {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, |
| 455 | 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf}; |
| 456 | |
| 457 | test("00010203-0405-0607-0809-0a0b0c0d0e0f", "%pUb", uuid); |
| 458 | test("00010203-0405-0607-0809-0A0B0C0D0E0F", "%pUB", uuid); |
| 459 | test("03020100-0504-0706-0809-0a0b0c0d0e0f", "%pUl", uuid); |
| 460 | test("03020100-0504-0706-0809-0A0B0C0D0E0F", "%pUL", uuid); |
| 461 | } |
| 462 | |
Rasmus Villemoes | 251c723 | 2016-01-15 16:59:09 -0800 | [diff] [blame] | 463 | static struct dentry test_dentry[4] __initdata = { |
| 464 | { .d_parent = &test_dentry[0], |
| 465 | .d_name = QSTR_INIT(test_dentry[0].d_iname, 3), |
| 466 | .d_iname = "foo" }, |
| 467 | { .d_parent = &test_dentry[0], |
| 468 | .d_name = QSTR_INIT(test_dentry[1].d_iname, 5), |
| 469 | .d_iname = "bravo" }, |
| 470 | { .d_parent = &test_dentry[1], |
| 471 | .d_name = QSTR_INIT(test_dentry[2].d_iname, 4), |
| 472 | .d_iname = "alfa" }, |
| 473 | { .d_parent = &test_dentry[2], |
| 474 | .d_name = QSTR_INIT(test_dentry[3].d_iname, 5), |
| 475 | .d_iname = "romeo" }, |
| 476 | }; |
| 477 | |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 478 | static void __init |
| 479 | dentry(void) |
| 480 | { |
Rasmus Villemoes | 251c723 | 2016-01-15 16:59:09 -0800 | [diff] [blame] | 481 | test("foo", "%pd", &test_dentry[0]); |
| 482 | test("foo", "%pd2", &test_dentry[0]); |
| 483 | |
Jia He | cf6b792 | 2019-08-09 09:24:57 +0800 | [diff] [blame] | 484 | test("(null)", "%pd", NULL); |
| 485 | test("(efault)", "%pd", PTR_INVALID); |
Jia He | cf6b792 | 2019-08-09 09:24:57 +0800 | [diff] [blame] | 486 | test("(null)", "%pD", NULL); |
| 487 | test("(efault)", "%pD", PTR_INVALID); |
| 488 | |
Rasmus Villemoes | 251c723 | 2016-01-15 16:59:09 -0800 | [diff] [blame] | 489 | test("romeo", "%pd", &test_dentry[3]); |
| 490 | test("alfa/romeo", "%pd2", &test_dentry[3]); |
| 491 | test("bravo/alfa/romeo", "%pd3", &test_dentry[3]); |
| 492 | test("/bravo/alfa/romeo", "%pd4", &test_dentry[3]); |
| 493 | test("/bravo/alfa", "%pd4", &test_dentry[2]); |
| 494 | |
| 495 | test("bravo/alfa |bravo/alfa ", "%-12pd2|%*pd2", &test_dentry[2], -12, &test_dentry[2]); |
| 496 | test(" bravo/alfa| bravo/alfa", "%12pd2|%*pd2", &test_dentry[2], 12, &test_dentry[2]); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | static void __init |
| 500 | struct_va_format(void) |
| 501 | { |
| 502 | } |
| 503 | |
| 504 | static void __init |
Andy Shevchenko | 7daac5b | 2020-04-15 20:00:44 +0300 | [diff] [blame] | 505 | time_and_date(void) |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 506 | { |
| 507 | /* 1543210543 */ |
| 508 | const struct rtc_time tm = { |
| 509 | .tm_sec = 43, |
| 510 | .tm_min = 35, |
| 511 | .tm_hour = 5, |
| 512 | .tm_mday = 26, |
| 513 | .tm_mon = 10, |
| 514 | .tm_year = 118, |
| 515 | }; |
Andy Shevchenko | 7daac5b | 2020-04-15 20:00:44 +0300 | [diff] [blame] | 516 | /* 2019-01-04T15:32:23 */ |
| 517 | time64_t t = 1546615943; |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 518 | |
Andy Shevchenko | 7daac5b | 2020-04-15 20:00:44 +0300 | [diff] [blame] | 519 | test("(%pt?)", "%pt", &tm); |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 520 | test("2018-11-26T05:35:43", "%ptR", &tm); |
| 521 | test("0118-10-26T05:35:43", "%ptRr", &tm); |
| 522 | test("05:35:43|2018-11-26", "%ptRt|%ptRd", &tm, &tm); |
| 523 | test("05:35:43|0118-10-26", "%ptRtr|%ptRdr", &tm, &tm); |
| 524 | test("05:35:43|2018-11-26", "%ptRttr|%ptRdtr", &tm, &tm); |
| 525 | test("05:35:43 tr|2018-11-26 tr", "%ptRt tr|%ptRd tr", &tm, &tm); |
Andy Shevchenko | 7daac5b | 2020-04-15 20:00:44 +0300 | [diff] [blame] | 526 | |
| 527 | test("2019-01-04T15:32:23", "%ptT", &t); |
| 528 | test("0119-00-04T15:32:23", "%ptTr", &t); |
| 529 | test("15:32:23|2019-01-04", "%ptTt|%ptTd", &t, &t); |
| 530 | test("15:32:23|0119-00-04", "%ptTtr|%ptTdr", &t, &t); |
Andy Shevchenko | 20bc8c1 | 2021-05-11 18:39:55 +0300 | [diff] [blame] | 531 | |
| 532 | test("2019-01-04 15:32:23", "%ptTs", &t); |
| 533 | test("0119-00-04 15:32:23", "%ptTsr", &t); |
| 534 | test("15:32:23|2019-01-04", "%ptTts|%ptTds", &t, &t); |
| 535 | test("15:32:23|0119-00-04", "%ptTtrs|%ptTdrs", &t, &t); |
Andy Shevchenko | 4d42c44 | 2018-12-04 23:23:11 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void __init |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 539 | struct_clk(void) |
| 540 | { |
| 541 | } |
| 542 | |
| 543 | static void __init |
Rasmus Villemoes | 857cca4 | 2016-01-15 16:59:06 -0800 | [diff] [blame] | 544 | large_bitmap(void) |
| 545 | { |
| 546 | const int nbits = 1 << 16; |
Andy Shevchenko | 2821fd0 | 2019-03-04 12:00:09 +0200 | [diff] [blame] | 547 | unsigned long *bits = bitmap_zalloc(nbits, GFP_KERNEL); |
Rasmus Villemoes | 857cca4 | 2016-01-15 16:59:06 -0800 | [diff] [blame] | 548 | if (!bits) |
| 549 | return; |
| 550 | |
| 551 | bitmap_set(bits, 1, 20); |
| 552 | bitmap_set(bits, 60000, 15); |
| 553 | test("1-20,60000-60014", "%*pbl", nbits, bits); |
Andy Shevchenko | 2821fd0 | 2019-03-04 12:00:09 +0200 | [diff] [blame] | 554 | bitmap_free(bits); |
Rasmus Villemoes | 857cca4 | 2016-01-15 16:59:06 -0800 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static void __init |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 558 | bitmap(void) |
| 559 | { |
| 560 | DECLARE_BITMAP(bits, 20); |
| 561 | const int primes[] = {2,3,5,7,11,13,17,19}; |
| 562 | int i; |
| 563 | |
| 564 | bitmap_zero(bits, 20); |
| 565 | test("00000|00000", "%20pb|%*pb", bits, 20, bits); |
| 566 | test("|", "%20pbl|%*pbl", bits, 20, bits); |
| 567 | |
| 568 | for (i = 0; i < ARRAY_SIZE(primes); ++i) |
| 569 | set_bit(primes[i], bits); |
| 570 | test("a28ac|a28ac", "%20pb|%*pb", bits, 20, bits); |
| 571 | test("2-3,5,7,11,13,17,19|2-3,5,7,11,13,17,19", "%20pbl|%*pbl", bits, 20, bits); |
| 572 | |
| 573 | bitmap_fill(bits, 20); |
| 574 | test("fffff|fffff", "%20pb|%*pb", bits, 20, bits); |
| 575 | test("0-19|0-19", "%20pbl|%*pbl", bits, 20, bits); |
Rasmus Villemoes | 857cca4 | 2016-01-15 16:59:06 -0800 | [diff] [blame] | 576 | |
| 577 | large_bitmap(); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static void __init |
| 581 | netdev_features(void) |
| 582 | { |
| 583 | } |
| 584 | |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 585 | struct page_flags_test { |
| 586 | int width; |
| 587 | int shift; |
| 588 | int mask; |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 589 | const char *fmt; |
| 590 | const char *name; |
| 591 | }; |
| 592 | |
Matthew Wilcox (Oracle) | c666d44 | 2021-10-19 15:26:17 +0100 | [diff] [blame] | 593 | static const struct page_flags_test pft[] = { |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 594 | {SECTIONS_WIDTH, SECTIONS_PGSHIFT, SECTIONS_MASK, |
Matthew Wilcox (Oracle) | c666d44 | 2021-10-19 15:26:17 +0100 | [diff] [blame] | 595 | "%d", "section"}, |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 596 | {NODES_WIDTH, NODES_PGSHIFT, NODES_MASK, |
Matthew Wilcox (Oracle) | c666d44 | 2021-10-19 15:26:17 +0100 | [diff] [blame] | 597 | "%d", "node"}, |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 598 | {ZONES_WIDTH, ZONES_PGSHIFT, ZONES_MASK, |
Matthew Wilcox (Oracle) | c666d44 | 2021-10-19 15:26:17 +0100 | [diff] [blame] | 599 | "%d", "zone"}, |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 600 | {LAST_CPUPID_WIDTH, LAST_CPUPID_PGSHIFT, LAST_CPUPID_MASK, |
Matthew Wilcox (Oracle) | c666d44 | 2021-10-19 15:26:17 +0100 | [diff] [blame] | 601 | "%#x", "lastcpupid"}, |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 602 | {KASAN_TAG_WIDTH, KASAN_TAG_PGSHIFT, KASAN_TAG_MASK, |
Matthew Wilcox (Oracle) | c666d44 | 2021-10-19 15:26:17 +0100 | [diff] [blame] | 603 | "%#x", "kasantag"}, |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 604 | }; |
| 605 | |
| 606 | static void __init |
| 607 | page_flags_test(int section, int node, int zone, int last_cpupid, |
Matthew Wilcox (Oracle) | a25a085 | 2021-10-19 15:26:18 +0100 | [diff] [blame] | 608 | int kasan_tag, unsigned long flags, const char *name, |
| 609 | char *cmp_buf) |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 610 | { |
| 611 | unsigned long values[] = {section, node, zone, last_cpupid, kasan_tag}; |
Matthew Wilcox (Oracle) | 23efd08 | 2021-10-19 15:26:21 +0100 | [diff] [blame] | 612 | unsigned long size; |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 613 | bool append = false; |
| 614 | int i; |
| 615 | |
Matthew Wilcox (Oracle) | 23efd08 | 2021-10-19 15:26:21 +0100 | [diff] [blame] | 616 | for (i = 0; i < ARRAY_SIZE(values); i++) |
| 617 | flags |= (values[i] & pft[i].mask) << pft[i].shift; |
| 618 | |
| 619 | size = scnprintf(cmp_buf, BUF_SIZE, "%#lx(", flags); |
Matthew Wilcox (Oracle) | a25a085 | 2021-10-19 15:26:18 +0100 | [diff] [blame] | 620 | if (flags & PAGEFLAGS_MASK) { |
Matthew Wilcox (Oracle) | 507f986 | 2021-10-19 15:26:20 +0100 | [diff] [blame] | 621 | size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name); |
Matthew Wilcox (Oracle) | 5b358b0 | 2021-10-19 15:26:19 +0100 | [diff] [blame] | 622 | append = true; |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 623 | } |
| 624 | |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 625 | for (i = 0; i < ARRAY_SIZE(pft); i++) { |
| 626 | if (!pft[i].width) |
| 627 | continue; |
| 628 | |
Matthew Wilcox (Oracle) | 507f986 | 2021-10-19 15:26:20 +0100 | [diff] [blame] | 629 | if (append) |
| 630 | size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|"); |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 631 | |
Matthew Wilcox (Oracle) | 507f986 | 2021-10-19 15:26:20 +0100 | [diff] [blame] | 632 | size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=", |
| 633 | pft[i].name); |
| 634 | size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt, |
| 635 | values[i] & pft[i].mask); |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 636 | append = true; |
| 637 | } |
| 638 | |
Matthew Wilcox (Oracle) | 23efd08 | 2021-10-19 15:26:21 +0100 | [diff] [blame] | 639 | snprintf(cmp_buf + size, BUF_SIZE - size, ")"); |
| 640 | |
Matthew Wilcox (Oracle) | a25a085 | 2021-10-19 15:26:18 +0100 | [diff] [blame] | 641 | test(cmp_buf, "%pGp", &flags); |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 642 | } |
| 643 | |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 644 | static void __init |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 645 | flags(void) |
| 646 | { |
| 647 | unsigned long flags; |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 648 | char *cmp_buffer; |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 649 | gfp_t gfp; |
| 650 | |
| 651 | cmp_buffer = kmalloc(BUF_SIZE, GFP_KERNEL); |
| 652 | if (!cmp_buffer) |
| 653 | return; |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 654 | |
| 655 | flags = 0; |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 656 | page_flags_test(0, 0, 0, 0, 0, flags, "", cmp_buffer); |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 657 | |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 658 | flags = 1UL << NR_PAGEFLAGS; |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 659 | page_flags_test(0, 0, 0, 0, 0, flags, "", cmp_buffer); |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 660 | |
| 661 | flags |= 1UL << PG_uptodate | 1UL << PG_dirty | 1UL << PG_lru |
| 662 | | 1UL << PG_active | 1UL << PG_swapbacked; |
Yafang Shao | c244297 | 2021-03-19 18:12:46 +0800 | [diff] [blame] | 663 | page_flags_test(1, 1, 1, 0x1fffff, 1, flags, |
| 664 | "uptodate|dirty|lru|active|swapbacked", |
| 665 | cmp_buffer); |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 666 | |
David Hildenbrand | 8d0920b | 2021-04-22 12:08:20 +0200 | [diff] [blame] | 667 | flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC; |
| 668 | test("read|exec|mayread|maywrite|mayexec", "%pGv", &flags); |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 669 | |
| 670 | gfp = GFP_TRANSHUGE; |
| 671 | test("GFP_TRANSHUGE", "%pGg", &gfp); |
| 672 | |
| 673 | gfp = GFP_ATOMIC|__GFP_DMA; |
| 674 | test("GFP_ATOMIC|GFP_DMA", "%pGg", &gfp); |
| 675 | |
| 676 | gfp = __GFP_ATOMIC; |
| 677 | test("__GFP_ATOMIC", "%pGg", &gfp); |
| 678 | |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 679 | /* Any flags not translated by the table should remain numeric */ |
| 680 | gfp = ~__GFP_BITS_MASK; |
| 681 | snprintf(cmp_buffer, BUF_SIZE, "%#lx", (unsigned long) gfp); |
| 682 | test(cmp_buffer, "%pGg", &gfp); |
| 683 | |
| 684 | snprintf(cmp_buffer, BUF_SIZE, "__GFP_ATOMIC|%#lx", |
| 685 | (unsigned long) gfp); |
| 686 | gfp |= __GFP_ATOMIC; |
| 687 | test(cmp_buffer, "%pGg", &gfp); |
| 688 | |
| 689 | kfree(cmp_buffer); |
| 690 | } |
| 691 | |
Sakari Ailus | f1ce39d | 2019-10-03 15:32:19 +0300 | [diff] [blame] | 692 | static void __init fwnode_pointer(void) |
| 693 | { |
| 694 | const struct software_node softnodes[] = { |
| 695 | { .name = "first", }, |
| 696 | { .name = "second", .parent = &softnodes[0], }, |
| 697 | { .name = "third", .parent = &softnodes[1], }, |
| 698 | { NULL /* Guardian */ } |
| 699 | }; |
| 700 | const char * const full_name = "first/second/third"; |
| 701 | const char * const full_name_second = "first/second"; |
| 702 | const char * const second_name = "second"; |
| 703 | const char * const third_name = "third"; |
| 704 | int rval; |
| 705 | |
| 706 | rval = software_node_register_nodes(softnodes); |
| 707 | if (rval) { |
| 708 | pr_warn("cannot register softnodes; rval %d\n", rval); |
| 709 | return; |
| 710 | } |
| 711 | |
| 712 | test(full_name_second, "%pfw", software_node_fwnode(&softnodes[1])); |
| 713 | test(full_name, "%pfw", software_node_fwnode(&softnodes[2])); |
| 714 | test(full_name, "%pfwf", software_node_fwnode(&softnodes[2])); |
| 715 | test(second_name, "%pfwP", software_node_fwnode(&softnodes[1])); |
| 716 | test(third_name, "%pfwP", software_node_fwnode(&softnodes[2])); |
| 717 | |
Daniel Scally | f0328be | 2021-01-07 14:28:32 +0100 | [diff] [blame] | 718 | software_node_unregister_nodes(softnodes); |
Sakari Ailus | f1ce39d | 2019-10-03 15:32:19 +0300 | [diff] [blame] | 719 | } |
| 720 | |
Sakari Ailus | af612e4 | 2021-02-16 17:57:20 +0200 | [diff] [blame] | 721 | static void __init fourcc_pointer(void) |
| 722 | { |
| 723 | struct { |
| 724 | u32 code; |
| 725 | char *str; |
| 726 | } const try[] = { |
| 727 | { 0x3231564e, "NV12 little-endian (0x3231564e)", }, |
| 728 | { 0xb231564e, "NV12 big-endian (0xb231564e)", }, |
| 729 | { 0x10111213, ".... little-endian (0x10111213)", }, |
| 730 | { 0x20303159, "Y10 little-endian (0x20303159)", }, |
| 731 | }; |
| 732 | unsigned int i; |
| 733 | |
| 734 | for (i = 0; i < ARRAY_SIZE(try); i++) |
| 735 | test(try[i].str, "%p4cc", &try[i].code); |
| 736 | } |
| 737 | |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 738 | static void __init |
Rasmus Villemoes | 57f5677 | 2019-10-15 21:07:05 +0200 | [diff] [blame] | 739 | errptr(void) |
| 740 | { |
| 741 | test("-1234", "%pe", ERR_PTR(-1234)); |
| 742 | |
| 743 | /* Check that %pe with a non-ERR_PTR gets treated as ordinary %p. */ |
| 744 | BUILD_BUG_ON(IS_ERR(PTR)); |
| 745 | test_hashed("%pe", PTR); |
| 746 | |
| 747 | #ifdef CONFIG_SYMBOLIC_ERRNAME |
| 748 | test("(-ENOTSOCK)", "(%pe)", ERR_PTR(-ENOTSOCK)); |
| 749 | test("(-EAGAIN)", "(%pe)", ERR_PTR(-EAGAIN)); |
| 750 | BUILD_BUG_ON(EAGAIN != EWOULDBLOCK); |
| 751 | test("(-EAGAIN)", "(%pe)", ERR_PTR(-EWOULDBLOCK)); |
| 752 | test("[-EIO ]", "[%-8pe]", ERR_PTR(-EIO)); |
| 753 | test("[ -EIO]", "[%8pe]", ERR_PTR(-EIO)); |
| 754 | test("-EPROBE_DEFER", "%pe", ERR_PTR(-EPROBE_DEFER)); |
| 755 | #endif |
| 756 | } |
| 757 | |
| 758 | static void __init |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 759 | test_pointer(void) |
| 760 | { |
| 761 | plain(); |
Petr Mladek | 3e5903e | 2019-04-17 13:53:48 +0200 | [diff] [blame] | 762 | null_pointer(); |
Ilya Dryomov | 7bd57fb | 2020-05-19 13:26:57 +0200 | [diff] [blame] | 763 | error_pointer(); |
Petr Mladek | 3e5903e | 2019-04-17 13:53:48 +0200 | [diff] [blame] | 764 | invalid_pointer(); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 765 | symbol_ptr(); |
| 766 | kernel_ptr(); |
| 767 | struct_resource(); |
| 768 | addr(); |
| 769 | escaped_str(); |
| 770 | hex_string(); |
| 771 | mac(); |
| 772 | ip(); |
| 773 | uuid(); |
| 774 | dentry(); |
| 775 | struct_va_format(); |
Andy Shevchenko | 7daac5b | 2020-04-15 20:00:44 +0300 | [diff] [blame] | 776 | time_and_date(); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 777 | struct_clk(); |
| 778 | bitmap(); |
| 779 | netdev_features(); |
Vlastimil Babka | edf14cd | 2016-03-15 14:55:56 -0700 | [diff] [blame] | 780 | flags(); |
Rasmus Villemoes | 57f5677 | 2019-10-15 21:07:05 +0200 | [diff] [blame] | 781 | errptr(); |
Sakari Ailus | f1ce39d | 2019-10-03 15:32:19 +0300 | [diff] [blame] | 782 | fwnode_pointer(); |
Sakari Ailus | af612e4 | 2021-02-16 17:57:20 +0200 | [diff] [blame] | 783 | fourcc_pointer(); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 784 | } |
| 785 | |
Tobin C. Harding | 6b1a4d5 | 2019-04-05 12:58:57 +1100 | [diff] [blame] | 786 | static void __init selftest(void) |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 787 | { |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 788 | alloced_buffer = kmalloc(BUF_SIZE + 2*PAD_SIZE, GFP_KERNEL); |
| 789 | if (!alloced_buffer) |
Tobin C. Harding | 6b1a4d5 | 2019-04-05 12:58:57 +1100 | [diff] [blame] | 790 | return; |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 791 | test_buffer = alloced_buffer + PAD_SIZE; |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 792 | |
| 793 | test_basic(); |
| 794 | test_number(); |
| 795 | test_string(); |
| 796 | test_pointer(); |
| 797 | |
Rasmus Villemoes | 331e4de | 2016-01-15 16:58:53 -0800 | [diff] [blame] | 798 | kfree(alloced_buffer); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 799 | } |
| 800 | |
Tobin C. Harding | 6b1a4d5 | 2019-04-05 12:58:57 +1100 | [diff] [blame] | 801 | KSTM_MODULE_LOADERS(test_printf); |
Rasmus Villemoes | 707cc72 | 2015-11-06 16:30:29 -0800 | [diff] [blame] | 802 | MODULE_AUTHOR("Rasmus Villemoes <linux@rasmusvillemoes.dk>"); |
| 803 | MODULE_LICENSE("GPL"); |