futex_wait_wouldblock.c 2.0 KB

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