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.
11 * Gowrishankar <gowrishankar.m@in.ibm.com>
14 * 2009-Nov-14: Initial version by Gowrishankar <gowrishankar.m@in.ibm.com>
16 *****************************************************************************/
24 #include "futextest.h"
27 #define TEST_NAME "futex-wait-wouldblock"
28 #define timeout_ns 100000
30 void usage(char *prog
)
32 printf("Usage: %s\n", prog
);
33 printf(" -c Use color\n");
34 printf(" -h Display this help message\n");
35 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
36 VQUIET
, VCRITICAL
, VINFO
);
39 int main(int argc
, char *argv
[])
41 struct timespec to
= {.tv_sec
= 0, .tv_nsec
= timeout_ns
};
42 futex_t f1
= FUTEX_INITIALIZER
;
43 int res
, ret
= RET_PASS
;
46 while ((c
= getopt(argc
, argv
, "cht:v:")) != -1) {
52 usage(basename(argv
[0]));
55 log_verbosity(atoi(optarg
));
58 usage(basename(argv
[0]));
65 ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n",
68 info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1
, &f1
, f1
+1);
69 res
= futex_wait(&f1
, f1
+1, &to
, FUTEX_PRIVATE_FLAG
);
70 if (!res
|| errno
!= EWOULDBLOCK
) {
71 fail("futex_wait returned: %d %s\n",
72 res
? errno
: res
, res
? strerror(errno
) : "");
76 print_result(TEST_NAME
, ret
);