Skip to content

Commit f4cf099

Browse files
shuv-amppmladek
authored andcommitted
printf: add IPv6 address format tests
printf_kunit already covers IPv4 address formatting, but the ip6() test case is empty even though printk-formats.rst documents %pI6, %pi6, %pI6c, and generic %pIS variants. Add focused IPv6 checks for raw and generic formatting, compressed output, the single-zero %pI6c corner case, and bracketed port formatting for sockaddr_in6. Signed-off-by: Shuvam Pandey <shuvampandey1@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Petr Mladek <pmladek@suse.com> Tested-by: Petr Mladek <pmladek@suse.com> Link: https://patch.msgid.link/20260317114548.98919-1-shuvampandey1@gmail.com [pmladek@suse.com: Removed non-necessary details from the commit message.] Signed-off-by: Petr Mladek <pmladek@suse.com>
1 parent db9571a commit f4cf099

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

lib/tests/printf_kunit.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/dcache.h>
1818
#include <linux/socket.h>
1919
#include <linux/in.h>
20+
#include <linux/in6.h>
2021

2122
#include <linux/gfp.h>
2223
#include <linux/mm.h>
@@ -437,6 +438,27 @@ ip4(struct kunit *kunittest)
437438
static void
438439
ip6(struct kunit *kunittest)
439440
{
441+
const struct in6_addr addr = {
442+
.s6_addr = { 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
443+
0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }
444+
};
445+
const struct in6_addr single_zero = {
446+
.s6_addr = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x04,
447+
0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08 }
448+
};
449+
struct sockaddr_in6 sa = {
450+
.sin6_family = AF_INET6,
451+
.sin6_port = cpu_to_be16(12345),
452+
.sin6_addr = addr,
453+
};
454+
455+
test("00010002000300040005000600070008|0001:0002:0003:0004:0005:0006:0007:0008",
456+
"%pi6|%pI6", &addr, &addr);
457+
test("00010002000300040005000600070008|0001:0002:0003:0004:0005:0006:0007:0008",
458+
"%piS|%pIS", &sa, &sa);
459+
test("1:2:3:4:5:6:7:8", "%pI6c", &addr);
460+
test("1:0:3:4:5:6:7:8", "%pI6c", &single_zero);
461+
test("[1:2:3:4:5:6:7:8]:12345", "%pISpc", &sa);
440462
}
441463

442464
static void

0 commit comments

Comments
 (0)