| 1 |
/*************************************************************************** |
| 2 |
* _ _ ____ _ |
| 3 |
* Project ___| | | | _ \| | |
| 4 |
* / __| | | | |_) | | |
| 5 |
* | (__| |_| | _ <| |___ |
| 6 |
* \___|\___/|_| \_\_____| |
| 7 |
* |
| 8 |
* Copyright (C) 1998 - 2019, Daniel Stenberg, <[email protected]>, 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.haxx.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 |
|
| 24 |
#include "testutil.h" |
| 25 |
#include "warnless.h" |
| 26 |
#include "memdebug.h" |
| 27 |
|
| 28 |
#define TEST_HANG_TIMEOUT 60 * 1000 |
| 29 |
#define WAKEUP_NUM 1234567 |
| 30 |
|
| 31 |
int test(char *URL) |
| 32 |
{ |
| 33 |
CURLM *multi = NULL; |
| 34 |
int numfds; |
| 35 |
int i; |
| 36 |
int res = 0; |
| 37 |
struct timeval time_before_wait, time_after_wait; |
| 38 |
|
| 39 |
(void)URL; |
| 40 |
|
| 41 |
start_test_timing(); |
| 42 |
|
| 43 |
global_init(CURL_GLOBAL_ALL); |
| 44 |
|
| 45 |
multi_init(multi); |
| 46 |
|
| 47 |
/* no wakeup */ |
| 48 |
|
| 49 |
time_before_wait = tutil_tvnow(); |
| 50 |
multi_poll(multi, NULL, 0, 1000, &numfds); |
| 51 |
time_after_wait = tutil_tvnow(); |
| 52 |
|
| 53 |
if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) { |
| 54 |
fprintf(stderr, "%s:%d curl_multi_poll returned too early\n", |
| 55 |
__FILE__, __LINE__); |
| 56 |
res = TEST_ERR_MAJOR_BAD; |
| 57 |
goto test_cleanup; |
| 58 |
} |
| 59 |
|
| 60 |
abort_on_test_timeout(); |
| 61 |
|
| 62 |
/* try a single wakeup */ |
| 63 |
|
| 64 |
multi_wakeup(multi); |
| 65 |
|
| 66 |
time_before_wait = tutil_tvnow(); |
| 67 |
multi_poll(multi, NULL, 0, 1000, &numfds); |
| 68 |
time_after_wait = tutil_tvnow(); |
| 69 |
|
| 70 |
if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) { |
| 71 |
fprintf(stderr, "%s:%d curl_multi_poll returned too late\n", |
| 72 |
__FILE__, __LINE__); |
| 73 |
res = TEST_ERR_MAJOR_BAD; |
| 74 |
goto test_cleanup; |
| 75 |
} |
| 76 |
|
| 77 |
abort_on_test_timeout(); |
| 78 |
|
| 79 |
/* previous wakeup should not wake up this */ |
| 80 |
|
| 81 |
time_before_wait = tutil_tvnow(); |
| 82 |
multi_poll(multi, NULL, 0, 1000, &numfds); |
| 83 |
time_after_wait = tutil_tvnow(); |
| 84 |
|
| 85 |
if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) { |
| 86 |
fprintf(stderr, "%s:%d curl_multi_poll returned too early\n", |
| 87 |
__FILE__, __LINE__); |
| 88 |
res = TEST_ERR_MAJOR_BAD; |
| 89 |
goto test_cleanup; |
| 90 |
} |
| 91 |
|
| 92 |
abort_on_test_timeout(); |
| 93 |
|
| 94 |
/* try lots of wakeup */ |
| 95 |
|
| 96 |
for(i = 0; i < WAKEUP_NUM; ++i) |
| 97 |
multi_wakeup(multi); |
| 98 |
|
| 99 |
time_before_wait = tutil_tvnow(); |
| 100 |
multi_poll(multi, NULL, 0, 1000, &numfds); |
| 101 |
time_after_wait = tutil_tvnow(); |
| 102 |
|
| 103 |
if(tutil_tvdiff(time_after_wait, time_before_wait) > 500) { |
| 104 |
fprintf(stderr, "%s:%d curl_multi_poll returned too late\n", |
| 105 |
__FILE__, __LINE__); |
| 106 |
res = TEST_ERR_MAJOR_BAD; |
| 107 |
goto test_cleanup; |
| 108 |
} |
| 109 |
|
| 110 |
abort_on_test_timeout(); |
| 111 |
|
| 112 |
#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) \ |
| 113 |
&& !defined(__CYGWIN__) |
| 114 |
/* Even lots of previous wakeups should not wake up this. |
| 115 |
|
| 116 |
On Windows (particularly when using MinGW), the socketpair |
| 117 |
used for curl_multi_wakeup() is really asynchronous, |
| 118 |
meaning when it's called a lot, it can take some time |
| 119 |
before all of the data can be read. Sometimes it can wake |
| 120 |
up more than one curl_multi_poll() call. */ |
| 121 |
|
| 122 |
time_before_wait = tutil_tvnow(); |
| 123 |
multi_poll(multi, NULL, 0, 1000, &numfds); |
| 124 |
time_after_wait = tutil_tvnow(); |
| 125 |
|
| 126 |
if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) { |
| 127 |
fprintf(stderr, "%s:%d curl_multi_poll returned too early\n", |
| 128 |
__FILE__, __LINE__); |
| 129 |
res = TEST_ERR_MAJOR_BAD; |
| 130 |
goto test_cleanup; |
| 131 |
} |
| 132 |
|
| 133 |
abort_on_test_timeout(); |
| 134 |
#endif |
| 135 |
|
| 136 |
test_cleanup: |
| 137 |
|
| 138 |
curl_multi_cleanup(multi); |
| 139 |
curl_global_cleanup(); |
| 140 |
|
| 141 |
return res; |
| 142 |
} |