~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/futex/functional/futex_wait_timeout.c

Version: ~ [ linux-5.11-rc3 ] ~ [ linux-5.10.7 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.89 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.167 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.215 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.251 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.251 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /******************************************************************************
  2  *
  3  *   Copyright © International Business Machines  Corp., 2009
  4  *
  5  *   This program is free software;  you can redistribute it and/or modify
  6  *   it under the terms of the GNU General Public License as published by
  7  *   the Free Software Foundation; either version 2 of the License, or
  8  *   (at your option) any later version.
  9  *
 10  * DESCRIPTION
 11  *      Block on a futex and wait for timeout.
 12  *
 13  * AUTHOR
 14  *      Darren Hart <dvhart@linux.intel.com>
 15  *
 16  * HISTORY
 17  *      2009-Nov-6: Initial version by Darren Hart <dvhart@linux.intel.com>
 18  *
 19  *****************************************************************************/
 20 
 21 #include <errno.h>
 22 #include <getopt.h>
 23 #include <stdio.h>
 24 #include <stdlib.h>
 25 #include <string.h>
 26 #include <time.h>
 27 #include "futextest.h"
 28 #include "logging.h"
 29 
 30 static long timeout_ns = 100000;        /* 100us default timeout */
 31 
 32 void usage(char *prog)
 33 {
 34         printf("Usage: %s\n", prog);
 35         printf("  -c    Use color\n");
 36         printf("  -h    Display this help message\n");
 37         printf("  -t N  Timeout in nanoseconds (default: 100,000)\n");
 38         printf("  -v L  Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
 39                VQUIET, VCRITICAL, VINFO);
 40 }
 41 
 42 int main(int argc, char *argv[])
 43 {
 44         futex_t f1 = FUTEX_INITIALIZER;
 45         struct timespec to;
 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 't':
 58                         timeout_ns = atoi(optarg);
 59                         break;
 60                 case 'v':
 61                         log_verbosity(atoi(optarg));
 62                         break;
 63                 default:
 64                         usage(basename(argv[0]));
 65                         exit(1);
 66                 }
 67         }
 68 
 69         printf("%s: Block on a futex and wait for timeout\n",
 70                basename(argv[0]));
 71         printf("\tArguments: timeout=%ldns\n", timeout_ns);
 72 
 73         /* initialize timeout */
 74         to.tv_sec = 0;
 75         to.tv_nsec = timeout_ns;
 76 
 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;
 82         }
 83 
 84         print_result(ret);
 85         return ret;
 86 }
 87 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp