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"
37 #define TEST_NAME "futex-wait-private-mapped-file"
40 char pad[PAGE_SZ] = {1};
42 char pad2[PAGE_SZ] = {1};
44 #define WAKE_WAIT_US 3000000
45 struct timespec wait_timeout = { .tv_sec = 5, .tv_nsec = 0};
47 void usage(char *prog)
49 printf("Usage: %s\n", prog);
50 printf(" -c Use color\n");
51 printf(" -h Display this help message\n");
52 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
53 VQUIET, VCRITICAL, VINFO);
56 void *thr_futex_wait(void *arg)
61 ret = futex_wait(&val, 1, &wait_timeout, 0);
62 if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT) {
63 error("futex error.\n", errno);
64 print_result(TEST_NAME, RET_ERROR);
68 if (ret && errno == ETIMEDOUT)
69 fail("waiter timedout\n");
71 info("futex_wait: ret = %d, errno = %d\n", ret, errno);
76 int main(int argc, char **argv)
83 while ((c = getopt(argc, argv, "chv:")) != -1) {
89 usage(basename(argv[0]));
92 log_verbosity(atoi(optarg));
95 usage(basename(argv[0]));
102 "%s: Test the futex value of private file mappings in FUTEX_WAIT\n",
105 ret = pthread_create(&thr, NULL, thr_futex_wait, NULL);
107 fprintf(stderr, "pthread_create error\n");
112 info("wait a while\n");
113 usleep(WAKE_WAIT_US);
115 res = futex_wake(&val, 1, 0);
116 info("futex_wake %d\n", res);
118 fail("FUTEX_WAKE didn't find the waiting thread.\n");
123 pthread_join(thr, NULL);
126 print_result(TEST_NAME, ret);