diff options
| author | Jakub Kicinski <kuba@kernel.org> | 2025-05-16 18:01:34 -0700 |
|---|---|---|
| committer | Jakub Kicinski <kuba@kernel.org> | 2025-05-16 18:01:34 -0700 |
| commit | b8fa067c4a76e9a28f2003a50ff9b60f00b11168 (patch) | |
| tree | 0ca72c6f0749fdf9076dc0b04825f975ce6f67ce /tools/testing/vsock/timeout.c | |
| parent | 9e1f7a3119cd4c5678f226033a9b9fb98917700b (diff) | |
| parent | 3c6abbe85bccd8efb5d9147a022b1d4012cb1809 (diff) | |
Merge branch 'vsock-test-improve-sigpipe-test-reliability'
Stefano Garzarella says:
====================
vsock/test: improve sigpipe test reliability
Running the tests continuously I noticed that sometimes the sigpipe
test would fail due to a race between the control message of the test
and the vsock transport messages.
While I was at it I also improved the test by checking the errno we
expect.
v1: https://lore.kernel.org/20250508142005.135857-1-sgarzare@redhat.com
====================
Link: https://patch.msgid.link/20250514141927.159456-1-sgarzare@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/vsock/timeout.c')
| -rw-r--r-- | tools/testing/vsock/timeout.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/testing/vsock/timeout.c b/tools/testing/vsock/timeout.c index 44aee49b6cee..1453d38e08bb 100644 --- a/tools/testing/vsock/timeout.c +++ b/tools/testing/vsock/timeout.c @@ -21,6 +21,7 @@ #include <stdbool.h> #include <unistd.h> #include <stdio.h> +#include <time.h> #include "timeout.h" static volatile bool timeout; @@ -28,6 +29,8 @@ static volatile bool timeout; /* SIGALRM handler function. Do not use sleep(2), alarm(2), or * setitimer(2) while using this API - they may interfere with each * other. + * + * If you need to sleep, please use timeout_sleep() provided by this API. */ void sigalrm(int signo) { @@ -58,3 +61,18 @@ void timeout_end(void) alarm(0); timeout = false; } + +/* Sleep in a timeout section. + * + * nanosleep(2) can be used with this API since POSIX.1 explicitly + * specifies that it does not interact with signals. + */ +int timeout_usleep(useconds_t usec) +{ + struct timespec ts = { + .tv_sec = usec / 1000000, + .tv_nsec = (usec % 1000000) * 1000, + }; + + return nanosleep(&ts, NULL); +} |
