diff options
Diffstat (limited to 'src/testzzuf/daemontest_put.c')
-rw-r--r-- | src/testzzuf/daemontest_put.c | 294 |
1 files changed, 144 insertions, 150 deletions
diff --git a/src/testzzuf/daemontest_put.c b/src/testzzuf/daemontest_put.c index e1f89402..82ab2289 100644 --- a/src/testzzuf/daemontest_put.c +++ b/src/testzzuf/daemontest_put.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libmicrohttpd | 2 | This file is part of libmicrohttpd |
3 | (C) 2007 Christian Grothoff | 3 | (C) 2007, 2008 Christian Grothoff |
4 | 4 | ||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | 5 | libmicrohttpd is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -35,6 +35,19 @@ | |||
35 | #include <unistd.h> | 35 | #include <unistd.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | |||
39 | #include "socat.c" | ||
40 | |||
41 | /** | ||
42 | * A larger loop count will run more random tests -- | ||
43 | * which would be good, except that it may take too | ||
44 | * long for most user's patience. So this small | ||
45 | * value is the default. | ||
46 | */ | ||
47 | #define LOOP_COUNT 10 | ||
48 | |||
49 | #define CURL_TIMEOUT 50L | ||
50 | |||
38 | static int oneone; | 51 | static int oneone; |
39 | 52 | ||
40 | struct CBC | 53 | struct CBC |
@@ -118,50 +131,45 @@ testInternalPut () | |||
118 | struct CBC cbc; | 131 | struct CBC cbc; |
119 | unsigned int pos = 0; | 132 | unsigned int pos = 0; |
120 | int done_flag = 0; | 133 | int done_flag = 0; |
121 | CURLcode errornum; | 134 | int i; |
122 | 135 | ||
123 | cbc.buf = buf; | 136 | cbc.buf = buf; |
124 | cbc.size = 2048; | 137 | cbc.size = 2048; |
125 | cbc.pos = 0; | 138 | cbc.pos = 0; |
126 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, | 139 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */ , |
127 | 1080, | 140 | 11080, |
128 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 141 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
129 | if (d == NULL) | 142 | if (d == NULL) |
130 | return 1; | 143 | return 1; |
131 | c = curl_easy_init (); | 144 | zzuf_socat_start (); |
132 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); | 145 | for (i = 0; i < LOOP_COUNT; i++) |
133 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
134 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
135 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
136 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
137 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
138 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
139 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
140 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
141 | if (oneone) | ||
142 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
143 | else | ||
144 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
145 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
146 | // NOTE: use of CONNECTTIMEOUT without also | ||
147 | // setting NOSIGNAL results in really weird | ||
148 | // crashes on my system! | ||
149 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
150 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
151 | { | 146 | { |
152 | fprintf (stderr, | 147 | fprintf (stderr, "."); |
153 | "curl_easy_perform failed: `%s'\n", | 148 | c = curl_easy_init (); |
154 | curl_easy_strerror (errornum)); | 149 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
150 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
151 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
152 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
153 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
154 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
155 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
156 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
157 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
158 | if (oneone) | ||
159 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
160 | else | ||
161 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
162 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
163 | // NOTE: use of CONNECTTIMEOUT without also | ||
164 | // setting NOSIGNAL results in really weird | ||
165 | // crashes on my system! | ||
166 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
167 | curl_easy_perform (c); | ||
155 | curl_easy_cleanup (c); | 168 | curl_easy_cleanup (c); |
156 | MHD_stop_daemon (d); | ||
157 | return 2; | ||
158 | } | 169 | } |
159 | curl_easy_cleanup (c); | 170 | fprintf (stderr, "\n"); |
171 | zzuf_socat_stop (); | ||
160 | MHD_stop_daemon (d); | 172 | MHD_stop_daemon (d); |
161 | if (cbc.pos != strlen ("/hello_world")) | ||
162 | return 4; | ||
163 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
164 | return 8; | ||
165 | return 0; | 173 | return 0; |
166 | } | 174 | } |
167 | 175 | ||
@@ -174,51 +182,45 @@ testMultithreadedPut () | |||
174 | struct CBC cbc; | 182 | struct CBC cbc; |
175 | unsigned int pos = 0; | 183 | unsigned int pos = 0; |
176 | int done_flag = 0; | 184 | int done_flag = 0; |
177 | CURLcode errornum; | 185 | int i; |
178 | 186 | ||
179 | cbc.buf = buf; | 187 | cbc.buf = buf; |
180 | cbc.size = 2048; | 188 | cbc.size = 2048; |
181 | cbc.pos = 0; | 189 | cbc.pos = 0; |
182 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, | 190 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */ , |
183 | 1081, | 191 | 11080, |
184 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 192 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
185 | if (d == NULL) | 193 | if (d == NULL) |
186 | return 16; | 194 | return 16; |
187 | c = curl_easy_init (); | 195 | zzuf_socat_start (); |
188 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); | 196 | for (i = 0; i < LOOP_COUNT; i++) |
189 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
190 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
191 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
192 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
193 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
194 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
195 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
196 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
197 | if (oneone) | ||
198 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
199 | else | ||
200 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
201 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
202 | // NOTE: use of CONNECTTIMEOUT without also | ||
203 | // setting NOSIGNAL results in really weird | ||
204 | // crashes on my system! | ||
205 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
206 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | ||
207 | { | 197 | { |
208 | fprintf (stderr, | 198 | fprintf (stderr, "."); |
209 | "curl_easy_perform failed: `%s'\n", | 199 | c = curl_easy_init (); |
210 | curl_easy_strerror (errornum)); | 200 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
201 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
202 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
203 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
204 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
205 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
206 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
207 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
208 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
209 | if (oneone) | ||
210 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
211 | else | ||
212 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
213 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
214 | // NOTE: use of CONNECTTIMEOUT without also | ||
215 | // setting NOSIGNAL results in really weird | ||
216 | // crashes on my system! | ||
217 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
218 | curl_easy_perform (c); | ||
211 | curl_easy_cleanup (c); | 219 | curl_easy_cleanup (c); |
212 | MHD_stop_daemon (d); | ||
213 | return 32; | ||
214 | } | 220 | } |
215 | curl_easy_cleanup (c); | 221 | fprintf (stderr, "\n"); |
222 | zzuf_socat_stop (); | ||
216 | MHD_stop_daemon (d); | 223 | MHD_stop_daemon (d); |
217 | if (cbc.pos != strlen ("/hello_world")) | ||
218 | return 64; | ||
219 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
220 | return 128; | ||
221 | |||
222 | return 0; | 224 | return 0; |
223 | } | 225 | } |
224 | 226 | ||
@@ -237,118 +239,113 @@ testExternalPut () | |||
237 | fd_set es; | 239 | fd_set es; |
238 | int max; | 240 | int max; |
239 | int running; | 241 | int running; |
240 | struct CURLMsg *msg; | ||
241 | time_t start; | 242 | time_t start; |
242 | struct timeval tv; | 243 | struct timeval tv; |
243 | unsigned int pos = 0; | 244 | unsigned int pos = 0; |
244 | int done_flag = 0; | 245 | int done_flag = 0; |
246 | int i; | ||
245 | 247 | ||
246 | multi = NULL; | 248 | multi = NULL; |
247 | cbc.buf = buf; | 249 | cbc.buf = buf; |
248 | cbc.size = 2048; | 250 | cbc.size = 2048; |
249 | cbc.pos = 0; | 251 | cbc.pos = 0; |
250 | d = MHD_start_daemon (MHD_USE_DEBUG, | 252 | d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */ , |
251 | 1082, | 253 | 11080, |
252 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); | 254 | NULL, NULL, &ahc_echo, &done_flag, MHD_OPTION_END); |
253 | if (d == NULL) | 255 | if (d == NULL) |
254 | return 256; | 256 | return 256; |
255 | c = curl_easy_init (); | ||
256 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); | ||
257 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
258 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
259 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
260 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
261 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
262 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
263 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
264 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
265 | if (oneone) | ||
266 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
267 | else | ||
268 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
269 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | ||
270 | // NOTE: use of CONNECTTIMEOUT without also | ||
271 | // setting NOSIGNAL results in really weird | ||
272 | // crashes on my system! | ||
273 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
274 | |||
275 | |||
276 | multi = curl_multi_init (); | 257 | multi = curl_multi_init (); |
277 | if (multi == NULL) | 258 | if (multi == NULL) |
278 | { | 259 | { |
279 | curl_easy_cleanup (c); | ||
280 | MHD_stop_daemon (d); | 260 | MHD_stop_daemon (d); |
281 | return 512; | 261 | return 512; |
282 | } | 262 | } |
283 | mret = curl_multi_add_handle (multi, c); | 263 | zzuf_socat_start (); |
284 | if (mret != CURLM_OK) | 264 | for (i = 0; i < LOOP_COUNT; i++) |
285 | { | ||
286 | curl_multi_cleanup (multi); | ||
287 | curl_easy_cleanup (c); | ||
288 | MHD_stop_daemon (d); | ||
289 | return 1024; | ||
290 | } | ||
291 | start = time (NULL); | ||
292 | while ((time (NULL) - start < 5) && (multi != NULL)) | ||
293 | { | 265 | { |
294 | max = 0; | 266 | fprintf (stderr, "."); |
295 | FD_ZERO (&rs); | 267 | |
296 | FD_ZERO (&ws); | 268 | c = curl_easy_init (); |
297 | FD_ZERO (&es); | 269 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
298 | curl_multi_perform (multi, &running); | 270 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
299 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 271 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
272 | curl_easy_setopt (c, CURLOPT_READFUNCTION, &putBuffer); | ||
273 | curl_easy_setopt (c, CURLOPT_READDATA, &pos); | ||
274 | curl_easy_setopt (c, CURLOPT_UPLOAD, 1L); | ||
275 | curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 8L); | ||
276 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
277 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); | ||
278 | if (oneone) | ||
279 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
280 | else | ||
281 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); | ||
282 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); | ||
283 | // NOTE: use of CONNECTTIMEOUT without also | ||
284 | // setting NOSIGNAL results in really weird | ||
285 | // crashes on my system! | ||
286 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
287 | |||
288 | |||
289 | |||
290 | mret = curl_multi_add_handle (multi, c); | ||
300 | if (mret != CURLM_OK) | 291 | if (mret != CURLM_OK) |
301 | { | 292 | { |
302 | curl_multi_remove_handle (multi, c); | ||
303 | curl_multi_cleanup (multi); | ||
304 | curl_easy_cleanup (c); | ||
305 | MHD_stop_daemon (d); | ||
306 | return 2048; | ||
307 | } | ||
308 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
309 | { | ||
310 | curl_multi_remove_handle (multi, c); | ||
311 | curl_multi_cleanup (multi); | 293 | curl_multi_cleanup (multi); |
312 | curl_easy_cleanup (c); | 294 | curl_easy_cleanup (c); |
295 | zzuf_socat_stop (); | ||
313 | MHD_stop_daemon (d); | 296 | MHD_stop_daemon (d); |
314 | return 4096; | 297 | return 1024; |
315 | } | 298 | } |
316 | tv.tv_sec = 0; | 299 | start = time (NULL); |
317 | tv.tv_usec = 1000; | 300 | while ((time (NULL) - start < 5) && (c != NULL)) |
318 | select (max + 1, &rs, &ws, &es, &tv); | ||
319 | curl_multi_perform (multi, &running); | ||
320 | if (running == 0) | ||
321 | { | 301 | { |
322 | msg = curl_multi_info_read (multi, &running); | 302 | max = 0; |
323 | if (msg == NULL) | 303 | FD_ZERO (&rs); |
324 | break; | 304 | FD_ZERO (&ws); |
325 | if (msg->msg == CURLMSG_DONE) | 305 | FD_ZERO (&es); |
306 | curl_multi_perform (multi, &running); | ||
307 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | ||
308 | if (mret != CURLM_OK) | ||
326 | { | 309 | { |
327 | if (msg->data.result != CURLE_OK) | ||
328 | printf ("%s failed at %s:%d: `%s'\n", | ||
329 | "curl_multi_perform", | ||
330 | __FILE__, | ||
331 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
332 | curl_multi_remove_handle (multi, c); | 310 | curl_multi_remove_handle (multi, c); |
333 | curl_multi_cleanup (multi); | 311 | curl_multi_cleanup (multi); |
334 | curl_easy_cleanup (c); | 312 | curl_easy_cleanup (c); |
313 | zzuf_socat_stop (); | ||
314 | MHD_stop_daemon (d); | ||
315 | return 2048; | ||
316 | } | ||
317 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | ||
318 | { | ||
319 | curl_multi_remove_handle (multi, c); | ||
320 | curl_multi_cleanup (multi); | ||
321 | curl_easy_cleanup (c); | ||
322 | zzuf_socat_stop (); | ||
323 | MHD_stop_daemon (d); | ||
324 | return 4096; | ||
325 | } | ||
326 | tv.tv_sec = 0; | ||
327 | tv.tv_usec = 1000; | ||
328 | select (max + 1, &rs, &ws, &es, &tv); | ||
329 | curl_multi_perform (multi, &running); | ||
330 | if (running == 0) | ||
331 | { | ||
332 | curl_multi_info_read (multi, &running); | ||
333 | curl_multi_remove_handle (multi, c); | ||
334 | curl_easy_cleanup (c); | ||
335 | c = NULL; | 335 | c = NULL; |
336 | multi = NULL; | ||
337 | } | 336 | } |
337 | MHD_run (d); | ||
338 | } | ||
339 | if (c != NULL) | ||
340 | { | ||
341 | curl_multi_remove_handle (multi, c); | ||
342 | curl_easy_cleanup (c); | ||
338 | } | 343 | } |
339 | MHD_run (d); | ||
340 | } | ||
341 | if (multi != NULL) | ||
342 | { | ||
343 | curl_multi_remove_handle (multi, c); | ||
344 | curl_easy_cleanup (c); | ||
345 | curl_multi_cleanup (multi); | ||
346 | } | 344 | } |
345 | fprintf (stderr, "\n"); | ||
346 | curl_multi_cleanup (multi); | ||
347 | zzuf_socat_stop (); | ||
347 | MHD_stop_daemon (d); | 348 | MHD_stop_daemon (d); |
348 | if (cbc.pos != strlen ("/hello_world")) | ||
349 | return 8192; | ||
350 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
351 | return 16384; | ||
352 | return 0; | 349 | return 0; |
353 | } | 350 | } |
354 | 351 | ||
@@ -363,11 +360,8 @@ main (int argc, char *const *argv) | |||
363 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 360 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
364 | return 2; | 361 | return 2; |
365 | errorCount += testInternalPut (); | 362 | errorCount += testInternalPut (); |
366 | if (0) | 363 | errorCount += testMultithreadedPut (); |
367 | { | 364 | errorCount += testExternalPut (); |
368 | errorCount += testMultithreadedPut (); | ||
369 | errorCount += testExternalPut (); | ||
370 | } | ||
371 | if (errorCount != 0) | 365 | if (errorCount != 0) |
372 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 366 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
373 | curl_global_cleanup (); | 367 | curl_global_cleanup (); |