staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / futex / functional / futex_wait_timeout.c
blobee55e6d389a3f053194435342c4e471dc7cf8786
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /******************************************************************************
4 * Copyright © International Business Machines Corp., 2009
6 * DESCRIPTION
7 * Block on a futex and wait for timeout.
9 * AUTHOR
10 * Darren Hart <dvhart@linux.intel.com>
12 * HISTORY
13 * 2009-Nov-6: Initial version by Darren Hart <dvhart@linux.intel.com>
15 *****************************************************************************/
17 #include <errno.h>
18 #include <getopt.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <time.h>
23 #include "futextest.h"
24 #include "logging.h"
26 #define TEST_NAME "futex-wait-timeout"
28 static long timeout_ns = 100000; /* 100us default timeout */
30 void usage(char *prog)
32 printf("Usage: %s\n", prog);
33 printf(" -c Use color\n");
34 printf(" -h Display this help message\n");
35 printf(" -t N Timeout in nanoseconds (default: 100,000)\n");
36 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
37 VQUIET, VCRITICAL, VINFO);
40 int main(int argc, char *argv[])
42 futex_t f1 = FUTEX_INITIALIZER;
43 struct timespec to;
44 int res, ret = RET_PASS;
45 int c;
47 while ((c = getopt(argc, argv, "cht:v:")) != -1) {
48 switch (c) {
49 case 'c':
50 log_color(1);
51 break;
52 case 'h':
53 usage(basename(argv[0]));
54 exit(0);
55 case 't':
56 timeout_ns = atoi(optarg);
57 break;
58 case 'v':
59 log_verbosity(atoi(optarg));
60 break;
61 default:
62 usage(basename(argv[0]));
63 exit(1);
67 ksft_print_header();
68 ksft_set_plan(1);
69 ksft_print_msg("%s: Block on a futex and wait for timeout\n",
70 basename(argv[0]));
71 ksft_print_msg("\tArguments: timeout=%ldns\n", timeout_ns);
73 /* initialize timeout */
74 to.tv_sec = 0;
75 to.tv_nsec = timeout_ns;
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;
84 print_result(TEST_NAME, ret);
85 return ret;