Skip to content

Commit 2d78928

Browse files
anakryikoborkmann
authored andcommitted
selftests/bpf: Improve percpu_alloc test robustness
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@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Eduard Zingerman <eddyz87@gmail.com> Link: https://lore.kernel.org/bpf/20231011223728.3188086-2-andrii@kernel.org
1 parent 0e10fd4 commit 2d78928

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

tools/testing/selftests/bpf/prog_tests/percpu_alloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static void test_array(void)
1919
bpf_program__set_autoload(skel->progs.test_array_map_3, true);
2020
bpf_program__set_autoload(skel->progs.test_array_map_4, true);
2121

22+
skel->bss->my_pid = getpid();
2223
skel->rodata->nr_cpus = libbpf_num_possible_cpus();
2324

2425
err = percpu_alloc_array__load(skel);
@@ -51,6 +52,7 @@ static void test_array_sleepable(void)
5152

5253
bpf_program__set_autoload(skel->progs.test_array_map_10, true);
5354

55+
skel->bss->my_pid = getpid();
5456
skel->rodata->nr_cpus = libbpf_num_possible_cpus();
5557

5658
err = percpu_alloc_array__load(skel);
@@ -85,6 +87,7 @@ static void test_cgrp_local_storage(void)
8587
if (!ASSERT_OK_PTR(skel, "percpu_alloc_cgrp_local_storage__open"))
8688
goto close_fd;
8789

90+
skel->bss->my_pid = getpid();
8891
skel->rodata->nr_cpus = libbpf_num_possible_cpus();
8992

9093
err = percpu_alloc_cgrp_local_storage__load(skel);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int BPF_PROG(test_array_map_2)
7171
}
7272

7373
int cpu0_field_d, sum_field_c;
74+
int my_pid;
7475

7576
/* Summarize percpu data */
7677
SEC("?fentry/bpf_fentry_test3")
@@ -81,6 +82,9 @@ int BPF_PROG(test_array_map_3)
8182
struct val_t *v;
8283
struct elem *e;
8384

85+
if ((bpf_get_current_pid_tgid() >> 32) != my_pid)
86+
return 0;
87+
8488
e = bpf_map_lookup_elem(&array, &index);
8589
if (!e)
8690
return 0;
@@ -130,6 +134,9 @@ int BPF_PROG(test_array_map_10)
130134
struct val_t *v;
131135
struct elem *e;
132136

137+
if ((bpf_get_current_pid_tgid() >> 32) != my_pid)
138+
return 0;
139+
133140
e = bpf_map_lookup_elem(&array, &index);
134141
if (!e)
135142
return 0;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ int BPF_PROG(test_cgrp_local_storage_2)
7070
}
7171

7272
int cpu0_field_d, sum_field_c;
73+
int my_pid;
7374

7475
/* Summarize percpu data collection */
7576
SEC("fentry/bpf_fentry_test3")
@@ -81,6 +82,9 @@ int BPF_PROG(test_cgrp_local_storage_3)
8182
struct elem *e;
8283
int i;
8384

85+
if ((bpf_get_current_pid_tgid() >> 32) != my_pid)
86+
return 0;
87+
8488
task = bpf_get_current_task_btf();
8589
e = bpf_cgrp_storage_get(&cgrp, task->cgroups->dfl_cgrp, 0, 0);
8690
if (!e)

0 commit comments

Comments
 (0)