* [PATCH bpf-next] selftests/bpf: guarantee that useep() calls nanosleep() syscall
@ 2020-03-11 18:53 Andrii Nakryiko
2020-03-13 1:16 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2020-03-11 18:53 UTC (permalink / raw)
To: bpf, netdev, ast, daniel
Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko, Julia Kartseva
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.
Cc: Julia Kartseva <hex@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
---
tools/testing/selftests/bpf/test_progs.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index a969c77e9456..2b0bc1171c9c 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: guarantee that useep() calls nanosleep() syscall
2020-03-11 18:53 [PATCH bpf-next] selftests/bpf: guarantee that useep() calls nanosleep() syscall Andrii Nakryiko
@ 2020-03-13 1:16 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2020-03-13 1:16 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Kernel Team, Julia Kartseva
On Wed, Mar 11, 2020 at 11:54 AM Andrii Nakryiko <andriin@fb.com> wrote:
>
> 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.
>
> Cc: Julia Kartseva <hex@fb.com>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Applied. Thanks
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-03-13 1:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 18:53 [PATCH bpf-next] selftests/bpf: guarantee that useep() calls nanosleep() syscall Andrii Nakryiko
2020-03-13 1:16 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).