summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2026-03-06 02:07:40 +0300
committerAndrii Nakryiko <andrii@kernel.org>2026-03-06 02:07:41 +0300
commit748f9c6811b973a518436136fb86e6284a8854c1 (patch)
tree3c3e12a0901a7d339cb62e9b530b85566923f63f /tools
parent8a2a3aaf90cf671caaca88fe57362c8b169ef392 (diff)
parent7f20d371fd879f5bb9be739c86c9bac13ea920c8 (diff)
downloadlinux-748f9c6811b973a518436136fb86e6284a8854c1.tar.xz
Merge branch 'selftests-bpf-fix-bpf_cookie-failures'
Sun Jian says: ==================== selftests/bpf: fix bpf_cookie failures Fix bpf_cookie failures due to missing bpf_testmod and flaky perf_event triggering. Tested: ./test_progs -t bpf_cookie/perf_event -vv (30 runs): 0 failures ./test_progs -t bpf_cookie -vv ==================== Link: https://patch.msgid.link/20260228074555.122950-1-sun.jian.kdev@gmail.com Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/bpf_cookie.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
index 75f4dff7d042..35adc3f6d443 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c
@@ -6,6 +6,7 @@
#include <sys/syscall.h>
#include <sys/mman.h>
#include <unistd.h>
+#include <linux/compiler.h>
#include <test_progs.h>
#include <network_helpers.h>
#include <bpf/btf.h>
@@ -105,6 +106,11 @@ static void kprobe_multi_link_api_subtest(void)
unsigned long long addrs[8];
__u64 cookies[8];
+ if (!env.has_testmod) {
+ test__skip();
+ return;
+ }
+
if (!ASSERT_OK(load_kallsyms(), "load_kallsyms"))
goto cleanup;
@@ -192,6 +198,11 @@ static void kprobe_multi_attach_api_subtest(void)
};
__u64 cookies[8];
+ if (!env.has_testmod) {
+ test__skip();
+ return;
+ }
+
skel = kprobe_multi__open_and_load();
if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load"))
goto cleanup;
@@ -421,11 +432,12 @@ cleanup:
bpf_link__destroy(link3);
}
-static void burn_cpu(void)
+static void burn_cpu(long loops)
{
- volatile int j = 0;
+ long j = 0;
cpu_set_t cpu_set;
- int i, err;
+ long i;
+ int err;
/* generate some branches on cpu 0 */
CPU_ZERO(&cpu_set);
@@ -433,9 +445,10 @@ static void burn_cpu(void)
err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set), &cpu_set);
ASSERT_OK(err, "set_thread_affinity");
- /* spin the loop for a while (random high number) */
- for (i = 0; i < 1000000; ++i)
+ for (i = 0; i < loops; ++i) {
++j;
+ barrier();
+ }
}
static void pe_subtest(struct test_bpf_cookie *skel)
@@ -451,7 +464,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
attr.type = PERF_TYPE_SOFTWARE;
attr.config = PERF_COUNT_SW_CPU_CLOCK;
attr.sample_period = 100000;
- pfd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, PERF_FLAG_FD_CLOEXEC);
+ pfd = syscall(__NR_perf_event_open, &attr, 0, -1, -1, PERF_FLAG_FD_CLOEXEC);
if (!ASSERT_GE(pfd, 0, "perf_fd"))
goto cleanup;
@@ -460,7 +473,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
if (!ASSERT_OK_PTR(link, "link1"))
goto cleanup;
- burn_cpu(); /* trigger BPF prog */
+ burn_cpu(100000000L); /* trigger BPF prog */
ASSERT_EQ(skel->bss->pe_res, 0x100000, "pe_res1");
@@ -479,7 +492,7 @@ static void pe_subtest(struct test_bpf_cookie *skel)
if (!ASSERT_OK_PTR(link, "link2"))
goto cleanup;
- burn_cpu(); /* trigger BPF prog */
+ burn_cpu(100000000L); /* trigger BPF prog */
ASSERT_EQ(skel->bss->pe_res, 0x200000, "pe_res2");