1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * Copyright © International Business Machines Corp., 2009
7 * Test if FUTEX_WAIT op returns -EWOULDBLOCK if the futex value differs
8 * from the expected one.
16 *****************************************************************************/
24 #include "futextest.h"
25 #include "futex2test.h"
28 #define TEST_NAME "futex-wait-wouldblock"
29 #define timeout_ns 100000
31 void usage(char *prog)
33 printf("Usage: %s\n", prog);
34 printf(" -c Use color\n");
35 printf(" -h Display this help message\n");
36 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
37 VQUIET, VCRITICAL, VINFO);
40 int main(int argc, char *argv[])
42 struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
43 futex_t f1 = FUTEX_INITIALIZER;
44 int res, ret = RET_PASS;
46 struct futex_waitv waitv = {
47 .uaddr = (uintptr_t)&f1,
53 while ((c = getopt(argc, argv, "cht:v:")) != -1) {
59 usage(basename(argv[0]));
62 log_verbosity(atoi(optarg));
65 usage(basename(argv[0]));
72 ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n",
75 info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
76 res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
77 if (!res || errno != EWOULDBLOCK) {
78 ksft_test_result_fail("futex_wait returned: %d %s\n",
80 res ? strerror(errno) : "");
83 ksft_test_result_pass("futex_wait\n");
86 if (clock_gettime(CLOCK_MONOTONIC, &to)) {
87 error("clock_gettime failed\n", errno);
91 to.tv_nsec += timeout_ns;
93 if (to.tv_nsec >= 1000000000) {
95 to.tv_nsec -= 1000000000;
98 info("Calling futex_waitv on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
99 res = futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC);
100 if (!res || errno != EWOULDBLOCK) {
101 ksft_test_result_pass("futex_waitv returned: %d %s\n",
103 res ? strerror(errno) : "");
106 ksft_test_result_pass("futex_waitv\n");