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