futex_wait_wouldblock.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. ksft_print_header();
  62. ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n",
  63. basename(argv[0]));
  64. info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
  65. res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
  66. if (!res || errno != EWOULDBLOCK) {
  67. fail("futex_wait returned: %d %s\n",
  68. res ? errno : res, res ? strerror(errno) : "");
  69. ret = RET_FAIL;
  70. }
  71. print_result(TEST_NAME, ret);
  72. return ret;
  73. }