lib1564.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2022, 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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "test.h"
  25. #include "testutil.h"
  26. #include "warnless.h"
  27. #include "memdebug.h"
  28. #define TEST_HANG_TIMEOUT 60 * 1000
  29. #define WAKEUP_NUM 10
  30. int test(char *URL)
  31. {
  32. CURLM *multi = NULL;
  33. int numfds;
  34. int i;
  35. int res = 0;
  36. struct timeval time_before_wait, time_after_wait;
  37. (void)URL;
  38. start_test_timing();
  39. global_init(CURL_GLOBAL_ALL);
  40. multi_init(multi);
  41. /* no wakeup */
  42. time_before_wait = tutil_tvnow();
  43. multi_poll(multi, NULL, 0, 1000, &numfds);
  44. time_after_wait = tutil_tvnow();
  45. if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
  46. fprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
  47. __FILE__, __LINE__);
  48. res = TEST_ERR_MAJOR_BAD;
  49. goto test_cleanup;
  50. }
  51. abort_on_test_timeout();
  52. /* try a single wakeup */
  53. res_multi_wakeup(multi);
  54. time_before_wait = tutil_tvnow();
  55. multi_poll(multi, NULL, 0, 1000, &numfds);
  56. time_after_wait = tutil_tvnow();
  57. if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) {
  58. fprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
  59. __FILE__, __LINE__);
  60. res = TEST_ERR_MAJOR_BAD;
  61. goto test_cleanup;
  62. }
  63. abort_on_test_timeout();
  64. /* previous wakeup should not wake up this */
  65. time_before_wait = tutil_tvnow();
  66. multi_poll(multi, NULL, 0, 1000, &numfds);
  67. time_after_wait = tutil_tvnow();
  68. if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
  69. fprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
  70. __FILE__, __LINE__);
  71. res = TEST_ERR_MAJOR_BAD;
  72. goto test_cleanup;
  73. }
  74. abort_on_test_timeout();
  75. /* try lots of wakeup */
  76. for(i = 0; i < WAKEUP_NUM; ++i)
  77. res_multi_wakeup(multi);
  78. time_before_wait = tutil_tvnow();
  79. multi_poll(multi, NULL, 0, 1000, &numfds);
  80. time_after_wait = tutil_tvnow();
  81. if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) {
  82. fprintf(stderr, "%s:%d curl_multi_poll returned too late\n",
  83. __FILE__, __LINE__);
  84. res = TEST_ERR_MAJOR_BAD;
  85. goto test_cleanup;
  86. }
  87. abort_on_test_timeout();
  88. /* Even lots of previous wakeups should not wake up this. */
  89. time_before_wait = tutil_tvnow();
  90. multi_poll(multi, NULL, 0, 1000, &numfds);
  91. time_after_wait = tutil_tvnow();
  92. if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
  93. fprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
  94. __FILE__, __LINE__);
  95. res = TEST_ERR_MAJOR_BAD;
  96. goto test_cleanup;
  97. }
  98. abort_on_test_timeout();
  99. test_cleanup:
  100. curl_multi_cleanup(multi);
  101. curl_global_cleanup();
  102. return res;
  103. }