lib1564.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at https://curl.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. #include "test.h"
  23. #include "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. #define TEST_HANG_TIMEOUT 60 * 1000
  27. #define WAKEUP_NUM 10
  28. int test(char *URL)
  29. {
  30. CURLM *multi = NULL;
  31. int numfds;
  32. int i;
  33. int res = 0;
  34. struct timeval time_before_wait, time_after_wait;
  35. (void)URL;
  36. start_test_timing();
  37. global_init(CURL_GLOBAL_ALL);
  38. multi_init(multi);
  39. /* no wakeup */
  40. time_before_wait = tutil_tvnow();
  41. multi_poll(multi, NULL, 0, 1000, &numfds);
  42. time_after_wait = tutil_tvnow();
  43. if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
  44. fprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
  45. __FILE__, __LINE__);
  46. res = TEST_ERR_MAJOR_BAD;
  47. goto test_cleanup;
  48. }
  49. abort_on_test_timeout();
  50. /* try a single wakeup */
  51. res_multi_wakeup(multi);
  52. time_before_wait = tutil_tvnow();
  53. multi_poll(multi, NULL, 0, 1000, &numfds);
  54. time_after_wait = tutil_tvnow();
  55. if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) {
  56. fprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
  57. __FILE__, __LINE__);
  58. res = TEST_ERR_MAJOR_BAD;
  59. goto test_cleanup;
  60. }
  61. abort_on_test_timeout();
  62. /* previous wakeup should not wake up this */
  63. time_before_wait = tutil_tvnow();
  64. multi_poll(multi, NULL, 0, 1000, &numfds);
  65. time_after_wait = tutil_tvnow();
  66. if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
  67. fprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
  68. __FILE__, __LINE__);
  69. res = TEST_ERR_MAJOR_BAD;
  70. goto test_cleanup;
  71. }
  72. abort_on_test_timeout();
  73. /* try lots of wakeup */
  74. for(i = 0; i < WAKEUP_NUM; ++i)
  75. res_multi_wakeup(multi);
  76. time_before_wait = tutil_tvnow();
  77. multi_poll(multi, NULL, 0, 1000, &numfds);
  78. time_after_wait = tutil_tvnow();
  79. if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) {
  80. fprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
  81. __FILE__, __LINE__);
  82. res = TEST_ERR_MAJOR_BAD;
  83. goto test_cleanup;
  84. }
  85. abort_on_test_timeout();
  86. /* Even lots of previous wakeups should not wake up this. */
  87. time_before_wait = tutil_tvnow();
  88. multi_poll(multi, NULL, 0, 1000, &numfds);
  89. time_after_wait = tutil_tvnow();
  90. if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
  91. fprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
  92. __FILE__, __LINE__);
  93. res = TEST_ERR_MAJOR_BAD;
  94. goto test_cleanup;
  95. }
  96. abort_on_test_timeout();
  97. test_cleanup:
  98. curl_multi_cleanup(multi);
  99. curl_global_cleanup();
  100. return res;
  101. }