On Thu, Oct 12, 2023 at 6:37 AM Andrii Nakryiko <andrii@xxxxxxxxxx> wrote: > > Make these non-serial tests filter BPF programs by intended PID of > a test runner process. This makes it isolated from other parallel tests > that might interfere accidentally. > > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > --- > tools/testing/selftests/bpf/prog_tests/percpu_alloc.c | 3 +++ > tools/testing/selftests/bpf/progs/percpu_alloc_array.c | 7 +++++++ > .../selftests/bpf/progs/percpu_alloc_cgrp_local_storage.c | 4 ++++ > 3 files changed, 14 insertions(+) > > diff --git a/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c b/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c > index 9541e9b3a034..343da65864d6 100644 > --- a/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c > +++ b/tools/testing/selftests/bpf/prog_tests/percpu_alloc.c > @@ -19,6 +19,7 @@ static void test_array(void) > bpf_program__set_autoload(skel->progs.test_array_map_3, true); > bpf_program__set_autoload(skel->progs.test_array_map_4, true); > > + skel->bss->my_pid = getpid(); > skel->rodata->nr_cpus = libbpf_num_possible_cpus(); > > err = percpu_alloc_array__load(skel); > @@ -51,6 +52,7 @@ static void test_array_sleepable(void) > > bpf_program__set_autoload(skel->progs.test_array_map_10, true); > > + skel->bss->my_pid = getpid(); > skel->rodata->nr_cpus = libbpf_num_possible_cpus(); > > err = percpu_alloc_array__load(skel); > @@ -85,6 +87,7 @@ static void test_cgrp_local_storage(void) > if (!ASSERT_OK_PTR(skel, "percpu_alloc_cgrp_local_storage__open")) > goto close_fd; > > + skel->bss->my_pid = getpid(); > skel->rodata->nr_cpus = libbpf_num_possible_cpus(); > > err = percpu_alloc_cgrp_local_storage__load(skel); > diff --git a/tools/testing/selftests/bpf/progs/percpu_alloc_array.c b/tools/testing/selftests/bpf/progs/percpu_alloc_array.c > index bbc45346e006..37c2d2608ec0 100644 > --- a/tools/testing/selftests/bpf/progs/percpu_alloc_array.c > +++ b/tools/testing/selftests/bpf/progs/percpu_alloc_array.c > @@ -71,6 +71,7 @@ int BPF_PROG(test_array_map_2) > } > > int cpu0_field_d, sum_field_c; > +int my_pid; > > /* Summarize percpu data */ > SEC("?fentry/bpf_fentry_test3") > @@ -81,6 +82,9 @@ int BPF_PROG(test_array_map_3) > struct val_t *v; > struct elem *e; > > + if ((bpf_get_current_pid_tgid() >> 32) != my_pid) > + return 0; > + > e = bpf_map_lookup_elem(&array, &index); > if (!e) > return 0; > @@ -130,6 +134,9 @@ int BPF_PROG(test_array_map_10) > struct val_t *v; > struct elem *e; > > + if ((bpf_get_current_pid_tgid() >> 32) != my_pid) > + return 0; > + > e = bpf_map_lookup_elem(&array, &index); > if (!e) > return 0; > diff --git a/tools/testing/selftests/bpf/progs/percpu_alloc_cgrp_local_storage.c b/tools/testing/selftests/bpf/progs/percpu_alloc_cgrp_local_storage.c > index 1c36a241852c..a2acf9aa6c24 100644 > --- a/tools/testing/selftests/bpf/progs/percpu_alloc_cgrp_local_storage.c > +++ b/tools/testing/selftests/bpf/progs/percpu_alloc_cgrp_local_storage.c > @@ -70,6 +70,7 @@ int BPF_PROG(test_cgrp_local_storage_2) > } > > int cpu0_field_d, sum_field_c; > +int my_pid; > > /* Summarize percpu data collection */ > SEC("fentry/bpf_fentry_test3") > @@ -81,6 +82,9 @@ int BPF_PROG(test_cgrp_local_storage_3) > struct elem *e; > int i; > > + if ((bpf_get_current_pid_tgid() >> 32) != my_pid) > + return 0; > + > task = bpf_get_current_task_btf(); a small nit. We have already got the current task. Should we better use if (task->pid != my_pid) instead ? > e = bpf_cgrp_storage_get(&cgrp, task->cgroups->dfl_cgrp, 0, 0); > if (!e) > -- > 2.34.1 > > -- Regards Yafang