Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftest/bpf: Extend the bpf_snprintf() test for "%c".

This patch adds various "positive" patterns for "%c" and two "negative"
patterns for wide character.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210814015718.42704-5-kuniyu@amazon.co.jp

authored by

Kuniyuki Iwashima and committed by
Andrii Nakryiko
ce547335 04e92818

+6 -4
+3 -1
tools/testing/selftests/bpf/prog_tests/snprintf.c
··· 19 19 #define EXP_ADDR_OUT "0000000000000000 ffff00000add4e55 " 20 20 #define EXP_ADDR_RET sizeof(EXP_ADDR_OUT "unknownhashedptr") 21 21 22 - #define EXP_STR_OUT "str1 longstr" 22 + #define EXP_STR_OUT "str1 a b c d e longstr" 23 23 #define EXP_STR_RET sizeof(EXP_STR_OUT) 24 24 25 25 #define EXP_OVER_OUT "%over" ··· 114 114 ASSERT_ERR(load_single_snprintf("%"), "invalid specifier 3"); 115 115 ASSERT_ERR(load_single_snprintf("%12345678"), "invalid specifier 4"); 116 116 ASSERT_ERR(load_single_snprintf("%--------"), "invalid specifier 5"); 117 + ASSERT_ERR(load_single_snprintf("%lc"), "invalid specifier 6"); 118 + ASSERT_ERR(load_single_snprintf("%llc"), "invalid specifier 7"); 117 119 ASSERT_ERR(load_single_snprintf("\x80"), "non ascii character"); 118 120 ASSERT_ERR(load_single_snprintf("\x1"), "non printable character"); 119 121 }
+3 -3
tools/testing/selftests/bpf/progs/test_snprintf.c
··· 59 59 /* Kernel pointers */ 60 60 addr_ret = BPF_SNPRINTF(addr_out, sizeof(addr_out), "%pK %px %p", 61 61 0, 0xFFFF00000ADD4E55, 0xFFFF00000ADD4E55); 62 - /* Strings embedding */ 63 - str_ret = BPF_SNPRINTF(str_out, sizeof(str_out), "%s %+05s", 64 - str1, longstr); 62 + /* Strings and single-byte character embedding */ 63 + str_ret = BPF_SNPRINTF(str_out, sizeof(str_out), "%s % 9c %+2c %-3c %04c %0c %+05s", 64 + str1, 'a', 'b', 'c', 'd', 'e', longstr); 65 65 /* Overflow */ 66 66 over_ret = BPF_SNPRINTF(over_out, sizeof(over_out), "%%overflow"); 67 67 /* Padding of fixed width numbers */