1 /******************************************************************************
3 * Copyright FUJITSU LIMITED 2010
4 * Copyright KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 * Internally, Futex has two handling mode, anon and file. The private file
13 * mapping is special. At first it behave as file, but after write anything
14 * it behave as anon. This test is intent to test such case.
17 * KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
20 * 2010-Jan-6: Initial version by KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
22 *****************************************************************************/
29 #include <linux/futex.h>
35 #include "futextest.h"
39 char pad
[PAGE_SZ
] = {1};
41 char pad2
[PAGE_SZ
] = {1};
43 #define WAKE_WAIT_US 3000000
44 struct timespec wait_timeout
= { .tv_sec
= 5, .tv_nsec
= 0};
46 void usage(char *prog
)
48 printf("Usage: %s\n", prog
);
49 printf(" -c Use color\n");
50 printf(" -h Display this help message\n");
51 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
52 VQUIET
, VCRITICAL
, VINFO
);
55 void *thr_futex_wait(void *arg
)
60 ret
= futex_wait(&val
, 1, &wait_timeout
, 0);
61 if (ret
&& errno
!= EWOULDBLOCK
&& errno
!= ETIMEDOUT
) {
62 error("futex error.\n", errno
);
63 print_result(RET_ERROR
);
67 if (ret
&& errno
== ETIMEDOUT
)
68 fail("waiter timedout\n");
70 info("futex_wait: ret = %d, errno = %d\n", ret
, errno
);
75 int main(int argc
, char **argv
)
82 while ((c
= getopt(argc
, argv
, "chv:")) != -1) {
88 usage(basename(argv
[0]));
91 log_verbosity(atoi(optarg
));
94 usage(basename(argv
[0]));
99 printf("%s: Test the futex value of private file mappings in FUTEX_WAIT\n",
102 ret
= pthread_create(&thr
, NULL
, thr_futex_wait
, NULL
);
104 fprintf(stderr
, "pthread_create error\n");
109 info("wait a while\n");
110 usleep(WAKE_WAIT_US
);
112 res
= futex_wake(&val
, 1, 0);
113 info("futex_wake %d\n", res
);
115 fail("FUTEX_WAKE didn't find the waiting thread.\n");
120 pthread_join(thr
, NULL
);