Skip to content

Commit eca8bb9

Browse files
theihorgregkh
authored andcommitted
selftests/bpf: Check for timeout in perf_link test
commit e6c209d upstream. Recently perf_link test started unreliably failing on libbpf CI: * https://github.com/libbpf/libbpf/actions/runs/11260672407/job/31312405473 * https://github.com/libbpf/libbpf/actions/runs/11260992334/job/31315514626 * https://github.com/libbpf/libbpf/actions/runs/11263162459/job/31320458251 Part of the test is running a dummy loop for a while and then checking for a counter incremented by the test program. Instead of waiting for an arbitrary number of loop iterations once, check for the test counter in a loop and use get_time_ns() helper to enforce a 100ms timeout. v1: https://lore.kernel.org/bpf/zuRd072x9tumn2iN4wDNs5av0nu5nekMNV4PkR-YwCT10eFFTrUtZBRkLWFbrcCe7guvLStGQlhibo8qWojCO7i2-NGajes5GYIyynexD-w=@pm.me/ Signed-off-by: Ihor Solodrai <ihor.solodrai@pm.me> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20241011153104.249800-1-ihor.solodrai@pm.me Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9d1807b commit eca8bb9

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
#include <pthread.h>
55
#include <sched.h>
66
#include <test_progs.h>
7+
#include "testing_helpers.h"
78
#include "test_perf_link.skel.h"
89

10+
#define BURN_TIMEOUT_MS 100
11+
#define BURN_TIMEOUT_NS BURN_TIMEOUT_MS * 1000000
12+
913
static void burn_cpu(void)
1014
{
1115
volatile int j = 0;
@@ -32,6 +36,7 @@ void serial_test_perf_link(void)
3236
int run_cnt_before, run_cnt_after;
3337
struct bpf_link_info info;
3438
__u32 info_len = sizeof(info);
39+
__u64 timeout_time_ns;
3540

3641
/* create perf event */
3742
memset(&attr, 0, sizeof(attr));
@@ -63,8 +68,14 @@ void serial_test_perf_link(void)
6368
ASSERT_GT(info.prog_id, 0, "link_prog_id");
6469

6570
/* ensure we get at least one perf_event prog execution */
66-
burn_cpu();
67-
ASSERT_GT(skel->bss->run_cnt, 0, "run_cnt");
71+
timeout_time_ns = get_time_ns() + BURN_TIMEOUT_NS;
72+
while (true) {
73+
burn_cpu();
74+
if (skel->bss->run_cnt > 0)
75+
break;
76+
if (!ASSERT_LT(get_time_ns(), timeout_time_ns, "run_cnt_timeout"))
77+
break;
78+
}
6879

6980
/* perf_event is still active, but we close link and BPF program
7081
* shouldn't be executed anymore

0 commit comments

Comments
 (0)