1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <errno.h>
22#include <getopt.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <time.h>
27#include "futextest.h"
28#include "logging.h"
29
30static long timeout_ns = 100000;
31
32void usage(char *prog)
33{
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);
40}
41
42int main(int argc, char *argv[])
43{
44 futex_t f1 = FUTEX_INITIALIZER;
45 struct timespec to;
46 int res, ret = RET_PASS;
47 int c;
48
49 while ((c = getopt(argc, argv, "cht:v:")) != -1) {
50 switch (c) {
51 case 'c':
52 log_color(1);
53 break;
54 case 'h':
55 usage(basename(argv[0]));
56 exit(0);
57 case 't':
58 timeout_ns = atoi(optarg);
59 break;
60 case 'v':
61 log_verbosity(atoi(optarg));
62 break;
63 default:
64 usage(basename(argv[0]));
65 exit(1);
66 }
67 }
68
69 printf("%s: Block on a futex and wait for timeout\n",
70 basename(argv[0]));
71 printf("\tArguments: timeout=%ldns\n", timeout_ns);
72
73
74 to.tv_sec = 0;
75 to.tv_nsec = timeout_ns;
76
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);
81 ret = RET_FAIL;
82 }
83
84 print_result(ret);
85 return ret;
86}
87