On Thu, Aug 28, 2025 at 4:08 AM Rong Tao <rt...@foxmail.com> wrote: > > From: Rong Tao <rong...@cestc.cn> > > Add two tests for bpf_strnstr(): > > bpf_strnstr("", "", 0) = 0 > bpf_strnstr("hello world", "hello", 5) = 0 > > Signed-off-by: Rong Tao <rong...@cestc.cn> > --- > tools/testing/selftests/bpf/progs/string_kfuncs_success.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/bpf/progs/string_kfuncs_success.c > b/tools/testing/selftests/bpf/progs/string_kfuncs_success.c > index 46697f381878..1b56bd5860e9 100644 > --- a/tools/testing/selftests/bpf/progs/string_kfuncs_success.c > +++ b/tools/testing/selftests/bpf/progs/string_kfuncs_success.c > @@ -30,7 +30,9 @@ __test(2) int test_strcspn(void *ctx) { return > bpf_strcspn(str, "lo"); } > __test(6) int test_strstr_found(void *ctx) { return bpf_strstr(str, > "world"); } > __test(-ENOENT) int test_strstr_notfound(void *ctx) { return bpf_strstr(str, > "hi"); } > __test(0) int test_strstr_empty(void *ctx) { return bpf_strstr(str, ""); } > -__test(0) int test_strnstr_found(void *ctx) { return bpf_strnstr(str, > "hello", 6); } > +__test(0) int test_strnstr_found1(void *ctx) { return bpf_strnstr("", "", > 0); } > +__test(0) int test_strnstr_found2(void *ctx) { return bpf_strnstr(str, > "hello", 5); }
add (str, "hello", 4) == -ENOENT case? Also let's add negative ("", "a", 0) == -ENOENT case? pw-bot: cr > +__test(0) int test_strnstr_found3(void *ctx) { return bpf_strnstr(str, > "hello", 6); } > __test(-ENOENT) int test_strnstr_notfound(void *ctx) { return > bpf_strnstr(str, "hi", 10); } > __test(0) int test_strnstr_empty(void *ctx) { return bpf_strnstr(str, "", > 1); } > > -- > 2.51.0 >