diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2022-08-29 15:21:21 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2022-08-29 15:24:27 -0400 |
commit | ca47f1b1e82bd1bfdda2fa2fcd74c681047f95bd (patch) | |
tree | 2fbc55aa18b43f963c8a9bc57d74ab02250a5946 | |
parent | 3bc1bc0b59d04e997db25b84babf459ca1cd80b7 (diff) |
lib/test_printf.c: Add ip6 tests
This adds missing tests for ip6 address: both bare address and
sockaddr_in6, as well as the additional flags for compressed address,
port, scope and flow.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
-rw-r--r-- | lib/test_printf.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/test_printf.c b/lib/test_printf.c index 4bd15a593fbd..6a56dbf076ab 100644 --- a/lib/test_printf.c +++ b/lib/test_printf.c @@ -18,6 +18,7 @@ #include <linux/dcache.h> #include <linux/socket.h> #include <linux/in.h> +#include <linux/in6.h> #include <linux/gfp.h> #include <linux/mm.h> @@ -61,6 +62,9 @@ do_test(int bufsize, const char *expect, int elen, pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d\n", bufsize, fmt, ret, elen); return 1; + pr_warn("vsnprintf(buf, %d, \"%s\", ...) returned %d, expected %d (%s != %s)\n", + bufsize, fmt, ret, elen, test_buffer, expect); + return 1; } if (memchr_inv(alloced_buffer, FILL_CHAR, PAD_SIZE)) { @@ -452,6 +456,31 @@ ip4(void) static void __init ip6(void) { + struct sockaddr_in6 sa = { .sin6_family = AF_INET6 }; + + sa.sin6_port = cpu_to_be16(12345); + sa.sin6_addr.in6_u.u6_addr16[0] = cpu_to_be16(1); + sa.sin6_addr.in6_u.u6_addr16[1] = cpu_to_be16(2); + sa.sin6_addr.in6_u.u6_addr16[6] = cpu_to_be16(7); + sa.sin6_addr.in6_u.u6_addr16[7] = cpu_to_be16(8); + sa.sin6_flowinfo = cpu_to_be32(8008); + sa.sin6_scope_id = 4004; + + test("00010002000000000000000000070008", "%pi6", &sa.sin6_addr); + test("00010002000000000000000000070008", "%piS", &sa); + test("0001:0002:0000:0000:0000:0000:0007:0008", "%pI6", &sa.sin6_addr); + test("0001:0002:0000:0000:0000:0000:0007:0008", "%pIS", &sa); + test("1:2::7:8", "%pISc", &sa); + + test("[0001:0002:0000:0000:0000:0000:0007:0008]:12345", "%pISp", &sa); + test("[0001:0002:0000:0000:0000:0000:0007:0008]%4004", "%pISs", &sa); + test("[0001:0002:0000:0000:0000:0000:0007:0008]/8008", "%pISf", &sa); + + test("[1:2::7:8]:12345", "%pIScp", &sa); + test("[1:2::7:8]%4004", "%pIScs", &sa); + test("[1:2::7:8]/8008", "%pIScf", &sa); + + test("[1:2::7:8]:12345/8008%4004", "%pIScpsf", &sa); } static void __init |