1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * Copyright © International Business Machines Corp., 2009
7 * Block on a futex and wait for timeout.
10 * Darren Hart <dvhart@linux.intel.com>
13 * 2009-Nov-6: Initial version by Darren Hart <dvhart@linux.intel.com>
15 *****************************************************************************/
23 #include "futextest.h"
26 #define TEST_NAME "futex-wait-timeout"
28 static long timeout_ns
= 100000; /* 100us default timeout */
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(" -t N Timeout in nanoseconds (default: 100,000)\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 futex_t f1
= FUTEX_INITIALIZER
;
44 int res
, ret
= RET_PASS
;
47 while ((c
= getopt(argc
, argv
, "cht:v:")) != -1) {
53 usage(basename(argv
[0]));
56 timeout_ns
= atoi(optarg
);
59 log_verbosity(atoi(optarg
));
62 usage(basename(argv
[0]));
69 ksft_print_msg("%s: Block on a futex and wait for timeout\n",
71 ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns
);
73 /* initialize timeout */
75 to
.tv_nsec
= timeout_ns
;
77 info("Calling futex_wait on f1: %u @ %p\n", f1
, &f1
);
78 res
= futex_wait(&f1
, f1
, &to
, FUTEX_PRIVATE_FLAG
);
79 if (!res
|| errno
!= ETIMEDOUT
) {
80 fail("futex_wait returned %d\n", ret
< 0 ? errno
: ret
);
84 print_result(TEST_NAME
, ret
);