Skip to content

Commit 0100b17

Browse files
RtoaxKernel Patches Daemon
authored andcommitted
selftests/bpf: Add tests for bpf_strnstr
Add tests for bpf_strnstr(): bpf_strnstr("", "", 0) = 0 bpf_strnstr("hello world", "hello", 5) = 0 bpf_strnstr(str, "hello", 4) = -ENOENT bpf_strnstr("", "a", 0) = -ENOENT Signed-off-by: Rong Tao <[email protected]>
1 parent 0715f71 commit 0100b17

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/testing/selftests/bpf/progs/string_kfuncs_success.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ __test(2) int test_strcspn(void *ctx) { return bpf_strcspn(str, "lo"); }
3030
__test(6) int test_strstr_found(void *ctx) { return bpf_strstr(str, "world"); }
3131
__test(-ENOENT) int test_strstr_notfound(void *ctx) { return bpf_strstr(str, "hi"); }
3232
__test(0) int test_strstr_empty(void *ctx) { return bpf_strstr(str, ""); }
33-
__test(0) int test_strnstr_found(void *ctx) { return bpf_strnstr(str, "hello", 6); }
34-
__test(-ENOENT) int test_strnstr_notfound(void *ctx) { return bpf_strnstr(str, "hi", 10); }
33+
__test(0) int test_strnstr_found1(void *ctx) { return bpf_strnstr("", "", 0); }
34+
__test(0) int test_strnstr_found2(void *ctx) { return bpf_strnstr(str, "hello", 5); }
35+
__test(0) int test_strnstr_found3(void *ctx) { return bpf_strnstr(str, "hello", 6); }
36+
__test(-ENOENT) int test_strnstr_notfound1(void *ctx) { return bpf_strnstr(str, "hi", 10); }
37+
__test(-ENOENT) int test_strnstr_notfound2(void *ctx) { return bpf_strnstr(str, "hello", 4); }
38+
__test(-ENOENT) int test_strnstr_notfound3(void *ctx) { return bpf_strnstr("", "a", 0); }
3539
__test(0) int test_strnstr_empty(void *ctx) { return bpf_strnstr(str, "", 1); }
3640

3741
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)