Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: futex: Test sys_futex_waitv() timeout

Test if the futex_waitv timeout is working as expected, using the
supported clockid options.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210923171111.300673-21-andrealmeid@collabora.com

authored by

André Almeida and committed by
Peter Zijlstra
02e56ccb 5e59c1d1

+20 -1
+20 -1
tools/testing/selftests/futex/functional/futex_wait_timeout.c
··· 17 17 18 18 #include <pthread.h> 19 19 #include "futextest.h" 20 + #include "futex2test.h" 20 21 #include "logging.h" 21 22 22 23 #define TEST_NAME "futex-wait-timeout" ··· 97 96 struct timespec to; 98 97 pthread_t thread; 99 98 int c; 99 + struct futex_waitv waitv = { 100 + .uaddr = (uintptr_t)&f1, 101 + .val = f1, 102 + .flags = FUTEX_32, 103 + .__reserved = 0 104 + }; 100 105 101 106 while ((c = getopt(argc, argv, "cht:v:")) != -1) { 102 107 switch (c) { ··· 125 118 } 126 119 127 120 ksft_print_header(); 128 - ksft_set_plan(7); 121 + ksft_set_plan(9); 129 122 ksft_print_msg("%s: Block on a futex and wait for timeout\n", 130 123 basename(argv[0])); 131 124 ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns); ··· 181 174 /* Test operations that don't support FUTEX_CLOCK_REALTIME */ 182 175 res = futex_lock_pi(&futex_pi, NULL, 0, FUTEX_CLOCK_REALTIME); 183 176 test_timeout(res, &ret, "futex_lock_pi invalid timeout flag", ENOSYS); 177 + 178 + /* futex_waitv with CLOCK_MONOTONIC */ 179 + if (futex_get_abs_timeout(CLOCK_MONOTONIC, &to, timeout_ns)) 180 + return RET_FAIL; 181 + res = futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC); 182 + test_timeout(res, &ret, "futex_waitv monotonic", ETIMEDOUT); 183 + 184 + /* futex_waitv with CLOCK_REALTIME */ 185 + if (futex_get_abs_timeout(CLOCK_REALTIME, &to, timeout_ns)) 186 + return RET_FAIL; 187 + res = futex_waitv(&waitv, 1, 0, &to, CLOCK_REALTIME); 188 + test_timeout(res, &ret, "futex_waitv realtime", ETIMEDOUT); 184 189 185 190 ksft_print_cnts(); 186 191 return ret;