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
24#include "testutil.h"
25#include "warnless.h"
26#include "memdebug.h"
27
28#define TEST_HANG_TIMEOUT 60 * 1000
29#define WAKEUP_NUM 10
30
31int 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 res_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 res_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 /* Even lots of previous wakeups should not wake up this. */
113
114 time_before_wait = tutil_tvnow();
115 multi_poll(multi, NULL, 0, 1000, &numfds);
116 time_after_wait = tutil_tvnow();
117
118 if(tutil_tvdiff(time_after_wait, time_before_wait) < 500) {
119 fprintf(stderr, "%s:%d curl_multi_poll returned too early\n",
120 __FILE__, __LINE__);
121 res = TEST_ERR_MAJOR_BAD;
122 goto test_cleanup;
123 }
124
125 abort_on_test_timeout();
126
127test_cleanup:
128
129 curl_multi_cleanup(multi);
130 curl_global_cleanup();
131
132 return res;
133}
134