futex_wait_wouldblock.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * Test if FUTEX_WAIT op returns -EWOULDBLOCK if the futex value differs
  12. * from the expected one.
  13. *
  14. * AUTHOR
  15. * Gowrishankar <gowrishankar.m@in.ibm.com>
  16. *
  17. * HISTORY
  18. * 2009-Nov-14: Initial version by Gowrishankar <gowrishankar.m@in.ibm.com>
  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. #define timeout_ns 100000
  30. void usage(char *prog)
  31. {
  32. printf("Usage: %s\n", prog);
  33. printf(" -c Use color\n");
  34. printf(" -h Display this help message\n");
  35. printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
  36. VQUIET, VCRITICAL, VINFO);
  37. }
  38. int main(int argc, char *argv[])
  39. {
  40. struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
  41. futex_t f1 = FUTEX_INITIALIZER;
  42. int res, ret = RET_PASS;
  43. int c;
  44. while ((c = getopt(argc, argv, "cht:v:")) != -1) {
  45. switch (c) {
  46. case 'c':
  47. log_color(1);
  48. break;
  49. case 'h':
  50. usage(basename(argv[0]));
  51. exit(0);
  52. case 'v':
  53. log_verbosity(atoi(optarg));
  54. break;
  55. default:
  56. usage(basename(argv[0]));
  57. exit(1);
  58. }
  59. }
  60. printf("%s: Test the unexpected futex value in FUTEX_WAIT\n",
  61. basename(argv[0]));
  62. info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
  63. res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
  64. if (!res || errno != EWOULDBLOCK) {
  65. fail("futex_wait returned: %d %s\n",
  66. res ? errno : res, res ? strerror(errno) : "");
  67. ret = RET_FAIL;
  68. }
  69. print_result(ret);
  70. return ret;
  71. }