Skip to content

Commit 2b5cf9f

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: Guarantee that useep() calls nanosleep() syscall
Some implementations of C runtime library won't call nanosleep() syscall from usleep(). But a bunch of kprobe/tracepoint selftests rely on nanosleep being called to trigger them. To make this more reliable, "override" usleep implementation and call nanosleep explicitly. Signed-off-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Cc: Julia Kartseva <[email protected]> Link: https://lore.kernel.org/bpf/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 6ae32b2 commit 2b5cf9f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tools/testing/selftests/bpf/test_progs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ struct prog_test_def {
2929
int old_error_cnt;
3030
};
3131

32+
/* Override C runtime library's usleep() implementation to ensure nanosleep()
33+
* is always called. Usleep is frequently used in selftests as a way to
34+
* trigger kprobe and tracepoints.
35+
*/
36+
int usleep(useconds_t usec)
37+
{
38+
return syscall(__NR_nanosleep, usec * 1000UL);
39+
}
40+
3241
static bool should_run(struct test_selector *sel, int num, const char *name)
3342
{
3443
int i;

0 commit comments

Comments
 (0)