1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <errno.h>
23#include <getopt.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <time.h>
28#include "futextest.h"
29#include "logging.h"
30
31#define timeout_ns 100000
32
33void usage(char *prog)
34{
35 printf("Usage: %s\n", prog);
36 printf(" -c Use color\n");
37 printf(" -h Display this help message\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 struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
45 futex_t f1 = FUTEX_INITIALIZER;
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 'v':
58 log_verbosity(atoi(optarg));
59 break;
60 default:
61 usage(basename(argv[0]));
62 exit(1);
63 }
64 }
65
66 printf("%s: Test the unexpected futex value in FUTEX_WAIT\n",
67 basename(argv[0]));
68
69 info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
70 res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
71 if (!res || errno != EWOULDBLOCK) {
72 fail("futex_wait returned: %d %s\n",
73 res ? errno : res, res ? strerror(errno) : "");
74 ret = RET_FAIL;
75 }
76
77 print_result(ret);
78 return ret;
79}
80