Skip to content

Commit

Permalink
selftests/bpf: Guarantee that useep() calls nanosleep() syscall
Browse files Browse the repository at this point in the history
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 <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Cc: Julia Kartseva <hex@fb.com>
Link: https://lore.kernel.org/bpf/20200311185345.3874602-1-andriin@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Andrii Nakryiko authored and Alexei Starovoitov committed Mar 13, 2020
1 parent 6ae32b2 commit 2b5cf9f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tools/testing/selftests/bpf/test_progs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ struct prog_test_def {
int old_error_cnt;
};

/* Override C runtime library's usleep() implementation to ensure nanosleep()
* is always called. Usleep is frequently used in selftests as a way to
* trigger kprobe and tracepoints.
*/
int usleep(useconds_t usec)
{
return syscall(__NR_nanosleep, usec * 1000UL);
}

static bool should_run(struct test_selector *sel, int num, const char *name)
{
int i;
Expand Down

0 comments on commit 2b5cf9f

Please sign in to comment.