printf: add IPv6 address format tests
PATCH 1/1 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.
Validated with the arm64 printf KUnit suite and a W=1 rebuild of lib/tests/printf_kunit.o.
--- lib/tests/printf_kunit.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
lib/tests/printf_kunit.c +22 -0
@@ -17,6 +17,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>
@@ -437,6 +438,27 @@ ip4(struct kunit *kunittest)static void ip6 (struct kunit *kunittest) { +const struct in6_addr addr = { + .s6_addr = {0x00 ,0x01 ,0x00 ,0x02 ,0x00 ,0x03 ,0x00 ,0x04 , +0x00 ,0x05 ,0x00 ,0x06 ,0x00 ,0x07 ,0x00 ,0x08 } + }; +const struct in6_addr single_zero = { + .s6_addr = {0x00 ,0x01 ,0x00 ,0x00 ,0x00 ,0x03 ,0x00 ,0x04 , +0x00 ,0x05 ,0x00 ,0x06 ,0x00 ,0x07 ,0x00 ,0x08 } + }; +struct sockaddr_in6 sa = { + .sin6_family =AF_INET6 , + .sin6_port =cpu_to_be16 (12345 ), + .sin6_addr = addr, + }; + +test ("00010002000300040005000600070008|0001:0002:0003:0004:0005:0006:0007:0008" , +"%pi6|%pI6" , &addr, &addr); +test ("00010002000300040005000600070008|0001:0002:0003:0004:0005:0006:0007:0008" , +"%piS|%pIS" , &sa, &sa); +test ("1:2:3:4:5:6:7:8" ,"%pI6c" , &addr); +test ("1:0:3:4:5:6:7:8" ,"%pI6c" , &single_zero); +test ("[1:2:3:4:5:6:7:8]:12345" ,"%pISpc" , &sa); } static void
Signature · 1 line
2.50.1 (Apple Git-155)
Quoted 10 lines · Shuvam Pandey
printf_kunitalready covers IPv4 address formatting, but theip6()test case is empty even thoughprintk-formats.rstdocuments %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.Validated with the arm64 printf KUnit suite and a W=1 rebuild of
lib/tests/printf_kunit.o.
No need to put this paragraph into the commit message, it's implied that the author of the change has validated and tested it beforehand.
Otherwise, test cases are always warmly welcome!
Signature · 2 lines
With Best Regards, Andy Shevchenko
Petr Mladek
maintainerQuoted 4 lines · Shuvam Pandey
printf_kunitalready covers IPv4 address formatting, but theip6()test case is empty even thoughprintk-formats.rstdocuments %pI6, %pi6, %pI6c, and generic %pIS variants.
Quoted 8 lines
Add focused IPv6 checks for raw and generic formatting, compressed output, the single-zero %pI6c corner case, and bracketed port formatting for
sockaddr_in6.Validated with the arm64 printf KUnit suite and a W=1 rebuild of
lib/tests/printf_kunit.o.Signed-off-by Shuvam Pandey <[email protected]>
JFYI, the patch has been comitted into printk/linux.git, branch for-7.1.
Note that I have removed the last paragraph about validating as suggested by Andy, see
https://git.kernel.org/pub/scm/linux/kernel/git/printk/linux.git/commit/?h=for-7.1&id=f4cf0992be37e6a8bc6cf9108f2c9628a6188381
Best Regards,
Petr