[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200313061837.3685572-1-andriin@fb.com>
Date: Thu, 12 Mar 2020 23:18:37 -0700
From: Andrii Nakryiko <andriin@...com>
To: <bpf@...r.kernel.org>, <netdev@...r.kernel.org>, <ast@...com>,
<daniel@...earbox.net>
CC: <andrii.nakryiko@...il.com>, <kernel-team@...com>,
Andrii Nakryiko <andriin@...com>
Subject: [PATCH bpf-next] selftests/bpf: fix usleep() implementation
nanosleep syscall expects pointer to struct timespec, not nanoseconds
directly. Current implementation fulfills its purpose of invoking nanosleep
syscall, but doesn't really provide sleeping capabilities, which can cause
flakiness for tests relying on usleep() to wait for something.
Fixes: ec12a57b822c ("selftests/bpf: Guarantee that useep() calls nanosleep() syscall")
Signed-off-by: Andrii Nakryiko <andriin@...com>
---
tools/testing/selftests/bpf/test_progs.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
index 2b0bc1171c9c..b6201dd82edf 100644
--- a/tools/testing/selftests/bpf/test_progs.c
+++ b/tools/testing/selftests/bpf/test_progs.c
@@ -35,7 +35,16 @@ struct prog_test_def {
*/
int usleep(useconds_t usec)
{
- return syscall(__NR_nanosleep, usec * 1000UL);
+ struct timespec ts;
+
+ if (usec > 999999) {
+ ts.tv_sec = usec / 1000000;
+ ts.tv_nsec = usec % 1000000;
+ } else {
+ ts.tv_sec = 0;
+ ts.tv_nsec = usec;
+ }
+ return nanosleep(&ts, NULL);
}
static bool should_run(struct test_selector *sel, int num, const char *name)
--
2.17.1
Powered by blists - more mailing lists