diff mbox series

[PATCHv2,bpf-next,2/3] selftests/bpf: Add serial_test_kprobe_multi_bench_attach_kernel/module tests

Message ID 20230113143303.867580-3-jolsa@kernel.org (mailing list archive)
State New, archived
Headers show
Series kallsyms: Optimize the search for module symbols by livepatch and bpf | expand

Commit Message

Jiri Olsa Jan. 13, 2023, 2:33 p.m. UTC
Add bench test for module portion of the symbols as well.

  # ./test_progs -v -t kprobe_multi_bench_attach_module
  bpf_testmod.ko is already unloaded.
  Loading bpf_testmod.ko...
  Successfully loaded bpf_testmod.ko.
  test_kprobe_multi_bench_attach:PASS:get_syms 0 nsec
  test_kprobe_multi_bench_attach:PASS:kprobe_multi_empty__open_and_load 0 nsec
  test_kprobe_multi_bench_attach:PASS:bpf_program__attach_kprobe_multi_opts 0 nsec
  test_kprobe_multi_bench_attach: found 26620 functions
  test_kprobe_multi_bench_attach: attached in   0.182s
  test_kprobe_multi_bench_attach: detached in   0.082s
  #96      kprobe_multi_bench_attach_module:OK
  Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
  Successfully unloaded bpf_testmod.ko.

It's useful for testing kprobe multi link modules resolving.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 .../bpf/prog_tests/kprobe_multi_test.c        | 21 ++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

Comments

Song Liu Jan. 13, 2023, 8:27 p.m. UTC | #1
On Fri, Jan 13, 2023 at 6:43 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Add bench test for module portion of the symbols as well.
>
>   # ./test_progs -v -t kprobe_multi_bench_attach_module
>   bpf_testmod.ko is already unloaded.
>   Loading bpf_testmod.ko...
>   Successfully loaded bpf_testmod.ko.
>   test_kprobe_multi_bench_attach:PASS:get_syms 0 nsec
>   test_kprobe_multi_bench_attach:PASS:kprobe_multi_empty__open_and_load 0 nsec
>   test_kprobe_multi_bench_attach:PASS:bpf_program__attach_kprobe_multi_opts 0 nsec
>   test_kprobe_multi_bench_attach: found 26620 functions
>   test_kprobe_multi_bench_attach: attached in   0.182s
>   test_kprobe_multi_bench_attach: detached in   0.082s
>   #96      kprobe_multi_bench_attach_module:OK
>   Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
>   Successfully unloaded bpf_testmod.ko.
>
> It's useful for testing kprobe multi link modules resolving.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>

Acked-by: Song Liu <song@kernel.org>

> ---
>  .../bpf/prog_tests/kprobe_multi_test.c        | 21 ++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> index c6f37e825f11..017a6996f3fa 100644
> --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> @@ -322,7 +322,7 @@ static bool symbol_equal(long key1, long key2, void *ctx __maybe_unused)
>         return strcmp((const char *) key1, (const char *) key2) == 0;
>  }
>
> -static int get_syms(char ***symsp, size_t *cntp)
> +static int get_syms(char ***symsp, size_t *cntp, bool kernel)
>  {
>         size_t cap = 0, cnt = 0, i;
>         char *name = NULL, **syms = NULL;
> @@ -349,8 +349,9 @@ static int get_syms(char ***symsp, size_t *cntp)
>         }
>
>         while (fgets(buf, sizeof(buf), f)) {
> -               /* skip modules */
> -               if (strchr(buf, '['))
> +               if (kernel && strchr(buf, '['))
> +                       continue;
> +               if (!kernel && !strchr(buf, '['))
>                         continue;
>
>                 free(name);
> @@ -404,7 +405,7 @@ static int get_syms(char ***symsp, size_t *cntp)
>         return err;
>  }
>
> -void serial_test_kprobe_multi_bench_attach(void)
> +static void test_kprobe_multi_bench_attach(bool kernel)
>  {
>         LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
>         struct kprobe_multi_empty *skel = NULL;
> @@ -415,7 +416,7 @@ void serial_test_kprobe_multi_bench_attach(void)
>         char **syms = NULL;
>         size_t cnt = 0, i;
>
> -       if (!ASSERT_OK(get_syms(&syms, &cnt), "get_syms"))
> +       if (!ASSERT_OK(get_syms(&syms, &cnt, kernel), "get_syms"))
>                 return;
>
>         skel = kprobe_multi_empty__open_and_load();
> @@ -453,6 +454,16 @@ void serial_test_kprobe_multi_bench_attach(void)
>         }
>  }
>
> +void serial_test_kprobe_multi_bench_attach_kernel(void)
> +{
> +       test_kprobe_multi_bench_attach(true);
> +}
> +
> +void serial_test_kprobe_multi_bench_attach_module(void)
> +{
> +       test_kprobe_multi_bench_attach(false);
> +}
> +
>  void test_kprobe_multi_test(void)
>  {
>         if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))
> --
> 2.39.0
>
Andrii Nakryiko Jan. 13, 2023, 10:43 p.m. UTC | #2
On Fri, Jan 13, 2023 at 6:33 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Add bench test for module portion of the symbols as well.
>
>   # ./test_progs -v -t kprobe_multi_bench_attach_module
>   bpf_testmod.ko is already unloaded.
>   Loading bpf_testmod.ko...
>   Successfully loaded bpf_testmod.ko.
>   test_kprobe_multi_bench_attach:PASS:get_syms 0 nsec
>   test_kprobe_multi_bench_attach:PASS:kprobe_multi_empty__open_and_load 0 nsec
>   test_kprobe_multi_bench_attach:PASS:bpf_program__attach_kprobe_multi_opts 0 nsec
>   test_kprobe_multi_bench_attach: found 26620 functions
>   test_kprobe_multi_bench_attach: attached in   0.182s
>   test_kprobe_multi_bench_attach: detached in   0.082s
>   #96      kprobe_multi_bench_attach_module:OK
>   Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
>   Successfully unloaded bpf_testmod.ko.
>
> It's useful for testing kprobe multi link modules resolving.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  .../bpf/prog_tests/kprobe_multi_test.c        | 21 ++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> index c6f37e825f11..017a6996f3fa 100644
> --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> @@ -322,7 +322,7 @@ static bool symbol_equal(long key1, long key2, void *ctx __maybe_unused)
>         return strcmp((const char *) key1, (const char *) key2) == 0;
>  }
>
> -static int get_syms(char ***symsp, size_t *cntp)
> +static int get_syms(char ***symsp, size_t *cntp, bool kernel)
>  {
>         size_t cap = 0, cnt = 0, i;
>         char *name = NULL, **syms = NULL;
> @@ -349,8 +349,9 @@ static int get_syms(char ***symsp, size_t *cntp)
>         }
>
>         while (fgets(buf, sizeof(buf), f)) {
> -               /* skip modules */
> -               if (strchr(buf, '['))
> +               if (kernel && strchr(buf, '['))
> +                       continue;
> +               if (!kernel && !strchr(buf, '['))
>                         continue;
>
>                 free(name);
> @@ -404,7 +405,7 @@ static int get_syms(char ***symsp, size_t *cntp)
>         return err;
>  }
>
> -void serial_test_kprobe_multi_bench_attach(void)
> +static void test_kprobe_multi_bench_attach(bool kernel)
>  {
>         LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
>         struct kprobe_multi_empty *skel = NULL;
> @@ -415,7 +416,7 @@ void serial_test_kprobe_multi_bench_attach(void)
>         char **syms = NULL;
>         size_t cnt = 0, i;
>
> -       if (!ASSERT_OK(get_syms(&syms, &cnt), "get_syms"))
> +       if (!ASSERT_OK(get_syms(&syms, &cnt, kernel), "get_syms"))
>                 return;
>
>         skel = kprobe_multi_empty__open_and_load();
> @@ -453,6 +454,16 @@ void serial_test_kprobe_multi_bench_attach(void)
>         }
>  }
>
> +void serial_test_kprobe_multi_bench_attach_kernel(void)
> +{
> +       test_kprobe_multi_bench_attach(true);
> +}
> +
> +void serial_test_kprobe_multi_bench_attach_module(void)
> +{
> +       test_kprobe_multi_bench_attach(false);
> +}
> +

minor nit: probably would be better to make kernel and module variants
into subtests?



>  void test_kprobe_multi_test(void)
>  {
>         if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))
> --
> 2.39.0
>
Jiri Olsa Jan. 15, 2023, 9:49 p.m. UTC | #3
On Fri, Jan 13, 2023 at 02:43:47PM -0800, Andrii Nakryiko wrote:
> On Fri, Jan 13, 2023 at 6:33 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > Add bench test for module portion of the symbols as well.
> >
> >   # ./test_progs -v -t kprobe_multi_bench_attach_module
> >   bpf_testmod.ko is already unloaded.
> >   Loading bpf_testmod.ko...
> >   Successfully loaded bpf_testmod.ko.
> >   test_kprobe_multi_bench_attach:PASS:get_syms 0 nsec
> >   test_kprobe_multi_bench_attach:PASS:kprobe_multi_empty__open_and_load 0 nsec
> >   test_kprobe_multi_bench_attach:PASS:bpf_program__attach_kprobe_multi_opts 0 nsec
> >   test_kprobe_multi_bench_attach: found 26620 functions
> >   test_kprobe_multi_bench_attach: attached in   0.182s
> >   test_kprobe_multi_bench_attach: detached in   0.082s
> >   #96      kprobe_multi_bench_attach_module:OK
> >   Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED
> >   Successfully unloaded bpf_testmod.ko.
> >
> > It's useful for testing kprobe multi link modules resolving.
> >
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  .../bpf/prog_tests/kprobe_multi_test.c        | 21 ++++++++++++++-----
> >  1 file changed, 16 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> > index c6f37e825f11..017a6996f3fa 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
> > @@ -322,7 +322,7 @@ static bool symbol_equal(long key1, long key2, void *ctx __maybe_unused)
> >         return strcmp((const char *) key1, (const char *) key2) == 0;
> >  }
> >
> > -static int get_syms(char ***symsp, size_t *cntp)
> > +static int get_syms(char ***symsp, size_t *cntp, bool kernel)
> >  {
> >         size_t cap = 0, cnt = 0, i;
> >         char *name = NULL, **syms = NULL;
> > @@ -349,8 +349,9 @@ static int get_syms(char ***symsp, size_t *cntp)
> >         }
> >
> >         while (fgets(buf, sizeof(buf), f)) {
> > -               /* skip modules */
> > -               if (strchr(buf, '['))
> > +               if (kernel && strchr(buf, '['))
> > +                       continue;
> > +               if (!kernel && !strchr(buf, '['))
> >                         continue;
> >
> >                 free(name);
> > @@ -404,7 +405,7 @@ static int get_syms(char ***symsp, size_t *cntp)
> >         return err;
> >  }
> >
> > -void serial_test_kprobe_multi_bench_attach(void)
> > +static void test_kprobe_multi_bench_attach(bool kernel)
> >  {
> >         LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
> >         struct kprobe_multi_empty *skel = NULL;
> > @@ -415,7 +416,7 @@ void serial_test_kprobe_multi_bench_attach(void)
> >         char **syms = NULL;
> >         size_t cnt = 0, i;
> >
> > -       if (!ASSERT_OK(get_syms(&syms, &cnt), "get_syms"))
> > +       if (!ASSERT_OK(get_syms(&syms, &cnt, kernel), "get_syms"))
> >                 return;
> >
> >         skel = kprobe_multi_empty__open_and_load();
> > @@ -453,6 +454,16 @@ void serial_test_kprobe_multi_bench_attach(void)
> >         }
> >  }
> >
> > +void serial_test_kprobe_multi_bench_attach_kernel(void)
> > +{
> > +       test_kprobe_multi_bench_attach(true);
> > +}
> > +
> > +void serial_test_kprobe_multi_bench_attach_module(void)
> > +{
> > +       test_kprobe_multi_bench_attach(false);
> > +}
> > +
> 
> minor nit: probably would be better to make kernel and module variants
> into subtests?

ok, will change that

thanks,
jirka
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
index c6f37e825f11..017a6996f3fa 100644
--- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c
@@ -322,7 +322,7 @@  static bool symbol_equal(long key1, long key2, void *ctx __maybe_unused)
 	return strcmp((const char *) key1, (const char *) key2) == 0;
 }
 
-static int get_syms(char ***symsp, size_t *cntp)
+static int get_syms(char ***symsp, size_t *cntp, bool kernel)
 {
 	size_t cap = 0, cnt = 0, i;
 	char *name = NULL, **syms = NULL;
@@ -349,8 +349,9 @@  static int get_syms(char ***symsp, size_t *cntp)
 	}
 
 	while (fgets(buf, sizeof(buf), f)) {
-		/* skip modules */
-		if (strchr(buf, '['))
+		if (kernel && strchr(buf, '['))
+			continue;
+		if (!kernel && !strchr(buf, '['))
 			continue;
 
 		free(name);
@@ -404,7 +405,7 @@  static int get_syms(char ***symsp, size_t *cntp)
 	return err;
 }
 
-void serial_test_kprobe_multi_bench_attach(void)
+static void test_kprobe_multi_bench_attach(bool kernel)
 {
 	LIBBPF_OPTS(bpf_kprobe_multi_opts, opts);
 	struct kprobe_multi_empty *skel = NULL;
@@ -415,7 +416,7 @@  void serial_test_kprobe_multi_bench_attach(void)
 	char **syms = NULL;
 	size_t cnt = 0, i;
 
-	if (!ASSERT_OK(get_syms(&syms, &cnt), "get_syms"))
+	if (!ASSERT_OK(get_syms(&syms, &cnt, kernel), "get_syms"))
 		return;
 
 	skel = kprobe_multi_empty__open_and_load();
@@ -453,6 +454,16 @@  void serial_test_kprobe_multi_bench_attach(void)
 	}
 }
 
+void serial_test_kprobe_multi_bench_attach_kernel(void)
+{
+	test_kprobe_multi_bench_attach(true);
+}
+
+void serial_test_kprobe_multi_bench_attach_module(void)
+{
+	test_kprobe_multi_bench_attach(false);
+}
+
 void test_kprobe_multi_test(void)
 {
 	if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))