Skip to content

Commit

Permalink
selftest/bpf: Extend the bpf_snprintf() test for "%c".
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Kuniyuki Iwashima authored and Andrii Nakryiko committed Aug 15, 2021
1 parent 04e9281 commit ce54733
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tools/testing/selftests/bpf/prog_tests/snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define EXP_ADDR_OUT "0000000000000000 ffff00000add4e55 "
#define EXP_ADDR_RET sizeof(EXP_ADDR_OUT "unknownhashedptr")

#define EXP_STR_OUT "str1 longstr"
#define EXP_STR_OUT "str1 a b c d e longstr"
#define EXP_STR_RET sizeof(EXP_STR_OUT)

#define EXP_OVER_OUT "%over"
Expand Down Expand Up @@ -114,6 +114,8 @@ void test_snprintf_negative(void)
ASSERT_ERR(load_single_snprintf("%"), "invalid specifier 3");
ASSERT_ERR(load_single_snprintf("%12345678"), "invalid specifier 4");
ASSERT_ERR(load_single_snprintf("%--------"), "invalid specifier 5");
ASSERT_ERR(load_single_snprintf("%lc"), "invalid specifier 6");
ASSERT_ERR(load_single_snprintf("%llc"), "invalid specifier 7");
ASSERT_ERR(load_single_snprintf("\x80"), "non ascii character");
ASSERT_ERR(load_single_snprintf("\x1"), "non printable character");
}
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/bpf/progs/test_snprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ int handler(const void *ctx)
/* Kernel pointers */
addr_ret = BPF_SNPRINTF(addr_out, sizeof(addr_out), "%pK %px %p",
0, 0xFFFF00000ADD4E55, 0xFFFF00000ADD4E55);
/* Strings embedding */
str_ret = BPF_SNPRINTF(str_out, sizeof(str_out), "%s %+05s",
str1, longstr);
/* Strings and single-byte character embedding */
str_ret = BPF_SNPRINTF(str_out, sizeof(str_out), "%s % 9c %+2c %-3c %04c %0c %+05s",
str1, 'a', 'b', 'c', 'd', 'e', longstr);
/* Overflow */
over_ret = BPF_SNPRINTF(over_out, sizeof(over_out), "%%overflow");
/* Padding of fixed width numbers */
Expand Down

0 comments on commit ce54733

Please sign in to comment.