1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * Copyright FUJITSU LIMITED 2010
5 * Copyright KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
8 * Internally, Futex has two handling mode, anon and file. The private file
9 * mapping is special. At first it behave as file, but after write anything
10 * it behave as anon. This test is intent to test such case.
13 * KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
16 * 2010-Jan-6: Initial version by KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
18 *****************************************************************************/
25 #include <linux/futex.h>
31 #include "futextest.h"
33 #define TEST_NAME "futex-wait-private-mapped-file"
36 char pad
[PAGE_SZ
] = {1};
38 char pad2
[PAGE_SZ
] = {1};
40 #define WAKE_WAIT_US 3000000
41 struct timespec wait_timeout
= { .tv_sec
= 5, .tv_nsec
= 0};
43 void usage(char *prog
)
45 printf("Usage: %s\n", prog
);
46 printf(" -c Use color\n");
47 printf(" -h Display this help message\n");
48 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
49 VQUIET
, VCRITICAL
, VINFO
);
52 void *thr_futex_wait(void *arg
)
57 ret
= futex_wait(&val
, 1, &wait_timeout
, 0);
58 if (ret
&& errno
!= EWOULDBLOCK
&& errno
!= ETIMEDOUT
) {
59 error("futex error.\n", errno
);
60 print_result(TEST_NAME
, RET_ERROR
);
64 if (ret
&& errno
== ETIMEDOUT
)
65 fail("waiter timedout\n");
67 info("futex_wait: ret = %d, errno = %d\n", ret
, errno
);
72 int main(int argc
, char **argv
)
79 while ((c
= getopt(argc
, argv
, "chv:")) != -1) {
85 usage(basename(argv
[0]));
88 log_verbosity(atoi(optarg
));
91 usage(basename(argv
[0]));
99 "%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
);
123 print_result(TEST_NAME
, ret
);