Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

authored by

Andrii Nakryiko and committed by
Daniel Borkmann
2d78928c 0e10fd4b

+14
+3
tools/testing/selftests/bpf/prog_tests/percpu_alloc.c
··· 19 19 bpf_program__set_autoload(skel->progs.test_array_map_3, true); 20 20 bpf_program__set_autoload(skel->progs.test_array_map_4, true); 21 21 22 + skel->bss->my_pid = getpid(); 22 23 skel->rodata->nr_cpus = libbpf_num_possible_cpus(); 23 24 24 25 err = percpu_alloc_array__load(skel); ··· 52 51 53 52 bpf_program__set_autoload(skel->progs.test_array_map_10, true); 54 53 54 + skel->bss->my_pid = getpid(); 55 55 skel->rodata->nr_cpus = libbpf_num_possible_cpus(); 56 56 57 57 err = percpu_alloc_array__load(skel); ··· 87 85 if (!ASSERT_OK_PTR(skel, "percpu_alloc_cgrp_local_storage__open")) 88 86 goto close_fd; 89 87 88 + skel->bss->my_pid = getpid(); 90 89 skel->rodata->nr_cpus = libbpf_num_possible_cpus(); 91 90 92 91 err = percpu_alloc_cgrp_local_storage__load(skel);
+7
tools/testing/selftests/bpf/progs/percpu_alloc_array.c
··· 71 71 } 72 72 73 73 int cpu0_field_d, sum_field_c; 74 + int my_pid; 74 75 75 76 /* Summarize percpu data */ 76 77 SEC("?fentry/bpf_fentry_test3") ··· 81 80 int i, index = 0; 82 81 struct val_t *v; 83 82 struct elem *e; 83 + 84 + if ((bpf_get_current_pid_tgid() >> 32) != my_pid) 85 + return 0; 84 86 85 87 e = bpf_map_lookup_elem(&array, &index); 86 88 if (!e) ··· 133 129 int i, index = 0; 134 130 struct val_t *v; 135 131 struct elem *e; 132 + 133 + if ((bpf_get_current_pid_tgid() >> 32) != my_pid) 134 + return 0; 136 135 137 136 e = bpf_map_lookup_elem(&array, &index); 138 137 if (!e)
+4
tools/testing/selftests/bpf/progs/percpu_alloc_cgrp_local_storage.c
··· 70 70 } 71 71 72 72 int cpu0_field_d, sum_field_c; 73 + int my_pid; 73 74 74 75 /* Summarize percpu data collection */ 75 76 SEC("fentry/bpf_fentry_test3") ··· 81 80 struct val_t *v; 82 81 struct elem *e; 83 82 int i; 83 + 84 + if ((bpf_get_current_pid_tgid() >> 32) != my_pid) 85 + return 0; 84 86 85 87 task = bpf_get_current_task_btf(); 86 88 e = bpf_cgrp_storage_get(&cgrp, task->cgroups->dfl_cgrp, 0, 0);