1 /******************************************************************************
3 * Copyright © International Business Machines Corp., 2009
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
11 * Block on a futex and wait for timeout.
14 * Darren Hart <dvhart@linux.intel.com>
17 * 2009-Nov-6: Initial version by Darren Hart <dvhart@linux.intel.com>
19 *****************************************************************************/
27 #include "futextest.h"
30 static long timeout_ns = 100000; /* 100us default timeout */
32 void usage(char *prog)
34 printf("Usage: %s\n", prog);
35 printf(" -c Use color\n");
36 printf(" -h Display this help message\n");
37 printf(" -t N Timeout in nanoseconds (default: 100,000)\n");
38 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
39 VQUIET, VCRITICAL, VINFO);
42 int main(int argc, char *argv[])
44 futex_t f1 = FUTEX_INITIALIZER;
46 int res, ret = RET_PASS;
49 while ((c = getopt(argc, argv, "cht:v:")) != -1) {
55 usage(basename(argv[0]));
58 timeout_ns = atoi(optarg);
61 log_verbosity(atoi(optarg));
64 usage(basename(argv[0]));
69 printf("%s: Block on a futex and wait for timeout\n",
71 printf("\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);