diff options
author | Christian Grothoff <christian@grothoff.org> | 2008-04-13 02:41:51 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2008-04-13 02:41:51 +0000 |
commit | 359fcdda235f8ce9c625e1789e6b22bb30d592fd (patch) | |
tree | 327f1aab56e511c5c290b818cefabee5522a262e | |
parent | b85440f3fa01d5072fe5bcd53280fb6527390344 (diff) | |
download | libmicrohttpd-359fcdda235f8ce9c625e1789e6b22bb30d592fd.tar.gz libmicrohttpd-359fcdda235f8ce9c625e1789e6b22bb30d592fd.zip |
zzuf-ing get_chunked
-rw-r--r-- | src/testzzuf/daemontest_get_chunked.c | 309 |
1 files changed, 141 insertions, 168 deletions
diff --git a/src/testzzuf/daemontest_get_chunked.c b/src/testzzuf/daemontest_get_chunked.c index 4b2739cf..4110d874 100644 --- a/src/testzzuf/daemontest_get_chunked.c +++ b/src/testzzuf/daemontest_get_chunked.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 |
@@ -21,10 +21,6 @@ | |||
21 | /** | 21 | /** |
22 | * @file daemontest_get_chunked.c | 22 | * @file daemontest_get_chunked.c |
23 | * @brief Testcase for libmicrohttpd GET operations with chunked content encoding | 23 | * @brief Testcase for libmicrohttpd GET operations with chunked content encoding |
24 | * TODO: | ||
25 | * - how to test that chunking was actually used? | ||
26 | * - use CURLOPT_HEADERFUNCTION to validate | ||
27 | * footer was sent | ||
28 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
29 | */ | 25 | */ |
30 | 26 | ||
@@ -39,6 +35,18 @@ | |||
39 | #include <unistd.h> | 35 | #include <unistd.h> |
40 | #endif | 36 | #endif |
41 | 37 | ||
38 | #include "socat.c" | ||
39 | |||
40 | /** | ||
41 | * A larger loop count will run more random tests -- | ||
42 | * which would be good, except that it may take too | ||
43 | * long for most user's patience. So this small | ||
44 | * value is the default. | ||
45 | */ | ||
46 | #define LOOP_COUNT 10 | ||
47 | |||
48 | #define CURL_TIMEOUT 50L | ||
49 | |||
42 | struct CBC | 50 | struct CBC |
43 | { | 51 | { |
44 | char *buf; | 52 | char *buf; |
@@ -120,68 +128,43 @@ ahc_echo (void *cls, | |||
120 | } | 128 | } |
121 | 129 | ||
122 | static int | 130 | static int |
123 | validate (struct CBC cbc, int ebase) | ||
124 | { | ||
125 | int i; | ||
126 | char buf[128]; | ||
127 | |||
128 | if (cbc.pos != 128 * 10) | ||
129 | return ebase; | ||
130 | |||
131 | for (i = 0; i < 10; i++) | ||
132 | { | ||
133 | memset (buf, 'A' + i, 128); | ||
134 | if (0 != memcmp (buf, &cbc.buf[i * 128], 128)) | ||
135 | { | ||
136 | fprintf (stderr, | ||
137 | "Got `%.*s'\nWant `%.*s'\n", | ||
138 | 128, buf, 128, &cbc.buf[i * 128]); | ||
139 | return ebase * 2; | ||
140 | } | ||
141 | } | ||
142 | return 0; | ||
143 | } | ||
144 | |||
145 | static int | ||
146 | testInternalGet () | 131 | testInternalGet () |
147 | { | 132 | { |
148 | struct MHD_Daemon *d; | 133 | struct MHD_Daemon *d; |
149 | CURL *c; | 134 | CURL *c; |
150 | char buf[2048]; | 135 | char buf[2048]; |
151 | struct CBC cbc; | 136 | struct CBC cbc; |
152 | CURLcode errornum; | 137 | int i; |
153 | 138 | ||
154 | cbc.buf = buf; | 139 | cbc.buf = buf; |
155 | cbc.size = 2048; | 140 | cbc.size = 2048; |
156 | cbc.pos = 0; | 141 | cbc.pos = 0; |
157 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, | 142 | d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */, |
158 | 1080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 143 | 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
159 | if (d == NULL) | 144 | if (d == NULL) |
160 | return 1; | 145 | return 1; |
161 | c = curl_easy_init (); | 146 | zzuf_socat_start(); |
162 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1080/hello_world"); | 147 | for (i=0;i<LOOP_COUNT;i++) { |
163 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 148 | fprintf(stderr, "."); |
164 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 149 | c = curl_easy_init (); |
165 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 150 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
166 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | 151 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
167 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | 152 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
168 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 153 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
169 | // NOTE: use of CONNECTTIMEOUT without also | 154 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); |
170 | // setting NOSIGNAL results in really weird | 155 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); |
171 | // crashes on my system! | 156 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
172 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | 157 | // NOTE: use of CONNECTTIMEOUT without also |
173 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 158 | // setting NOSIGNAL results in really weird |
174 | { | 159 | // crashes on my system! |
175 | fprintf (stderr, | 160 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); |
176 | "curl_easy_perform failed: `%s'\n", | 161 | curl_easy_perform (c); |
177 | curl_easy_strerror (errornum)); | 162 | curl_easy_cleanup (c); |
178 | curl_easy_cleanup (c); | 163 | } |
179 | MHD_stop_daemon (d); | 164 | fprintf(stderr, "\n"); |
180 | return 2; | 165 | zzuf_socat_stop(); |
181 | } | ||
182 | curl_easy_cleanup (c); | ||
183 | MHD_stop_daemon (d); | 166 | MHD_stop_daemon (d); |
184 | return validate (cbc, 4); | 167 | return 0; |
185 | } | 168 | } |
186 | 169 | ||
187 | static int | 170 | static int |
@@ -191,39 +174,37 @@ testMultithreadedGet () | |||
191 | CURL *c; | 174 | CURL *c; |
192 | char buf[2048]; | 175 | char buf[2048]; |
193 | struct CBC cbc; | 176 | struct CBC cbc; |
194 | CURLcode errornum; | 177 | int i; |
195 | 178 | ||
196 | cbc.buf = buf; | 179 | cbc.buf = buf; |
197 | cbc.size = 2048; | 180 | cbc.size = 2048; |
198 | cbc.pos = 0; | 181 | cbc.pos = 0; |
199 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG, | 182 | d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION /* | MHD_USE_DEBUG */, |
200 | 1081, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 183 | 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
201 | if (d == NULL) | 184 | if (d == NULL) |
202 | return 16; | 185 | return 16; |
203 | c = curl_easy_init (); | 186 | zzuf_socat_start(); |
204 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1081/hello_world"); | 187 | for (i=0;i<LOOP_COUNT;i++) { |
205 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | 188 | fprintf(stderr, "."); |
206 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | 189 | c = curl_easy_init (); |
207 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | 190 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
208 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | 191 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
209 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | 192 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
210 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); | 193 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
211 | // NOTE: use of CONNECTTIMEOUT without also | 194 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); |
212 | // setting NOSIGNAL results in really weird | 195 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
213 | // crashes on my system! | 196 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); |
214 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | 197 | // NOTE: use of CONNECTTIMEOUT without also |
215 | if (CURLE_OK != (errornum = curl_easy_perform (c))) | 198 | // setting NOSIGNAL results in really weird |
216 | { | 199 | // crashes on my system! |
217 | fprintf (stderr, | 200 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); |
218 | "curl_easy_perform failed: `%s'\n", | 201 | curl_easy_perform (c); |
219 | curl_easy_strerror (errornum)); | 202 | curl_easy_cleanup (c); |
220 | curl_easy_cleanup (c); | 203 | } |
221 | MHD_stop_daemon (d); | 204 | fprintf(stderr, "\n"); |
222 | return 32; | 205 | zzuf_socat_stop(); |
223 | } | ||
224 | curl_easy_cleanup (c); | ||
225 | MHD_stop_daemon (d); | 206 | MHD_stop_daemon (d); |
226 | return validate (cbc, 64); | 207 | return 0; |
227 | } | 208 | } |
228 | 209 | ||
229 | 210 | ||
@@ -241,32 +222,18 @@ testExternalGet () | |||
241 | fd_set es; | 222 | fd_set es; |
242 | int max; | 223 | int max; |
243 | int running; | 224 | int running; |
244 | struct CURLMsg *msg; | ||
245 | time_t start; | 225 | time_t start; |
246 | struct timeval tv; | 226 | struct timeval tv; |
227 | int i; | ||
247 | 228 | ||
248 | multi = NULL; | 229 | multi = NULL; |
249 | cbc.buf = buf; | 230 | cbc.buf = buf; |
250 | cbc.size = 2048; | 231 | cbc.size = 2048; |
251 | cbc.pos = 0; | 232 | cbc.pos = 0; |
252 | d = MHD_start_daemon (MHD_USE_DEBUG, | 233 | d = MHD_start_daemon (MHD_NO_FLAG /* | MHD_USE_DEBUG */, |
253 | 1082, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); | 234 | 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); |
254 | if (d == NULL) | 235 | if (d == NULL) |
255 | return 256; | 236 | return 256; |
256 | c = curl_easy_init (); | ||
257 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:1082/hello_world"); | ||
258 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); | ||
259 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); | ||
260 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); | ||
261 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | ||
262 | curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); | ||
263 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 5L); | ||
264 | // NOTE: use of CONNECTTIMEOUT without also | ||
265 | // setting NOSIGNAL results in really weird | ||
266 | // crashes on my system! | ||
267 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); | ||
268 | |||
269 | |||
270 | multi = curl_multi_init (); | 237 | multi = curl_multi_init (); |
271 | if (multi == NULL) | 238 | if (multi == NULL) |
272 | { | 239 | { |
@@ -274,72 +241,81 @@ testExternalGet () | |||
274 | MHD_stop_daemon (d); | 241 | MHD_stop_daemon (d); |
275 | return 512; | 242 | return 512; |
276 | } | 243 | } |
277 | mret = curl_multi_add_handle (multi, c); | 244 | zzuf_socat_start(); |
278 | if (mret != CURLM_OK) | 245 | for (i=0;i<LOOP_COUNT;i++) { |
279 | { | 246 | fprintf(stderr, "."); |
280 | curl_multi_cleanup (multi); | 247 | c = curl_easy_init (); |
281 | curl_easy_cleanup (c); | 248 | curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11081/hello_world"); |
282 | MHD_stop_daemon (d); | 249 | curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); |
283 | return 1024; | 250 | curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); |
284 | } | 251 | curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); |
285 | start = time (NULL); | 252 | curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); |
286 | while ((time (NULL) - start < 5) && (multi != NULL)) | 253 | curl_easy_setopt (c, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT); |
287 | { | 254 | curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT_MS, CURL_TIMEOUT); |
288 | max = 0; | 255 | // NOTE: use of CONNECTTIMEOUT without also |
289 | FD_ZERO (&rs); | 256 | // setting NOSIGNAL results in really weird |
290 | FD_ZERO (&ws); | 257 | // crashes on my system! |
291 | FD_ZERO (&es); | 258 | curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); |
292 | curl_multi_perform (multi, &running); | 259 | mret = curl_multi_add_handle (multi, c); |
293 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); | 260 | if (mret != CURLM_OK) |
294 | if (mret != CURLM_OK) | 261 | { |
295 | { | 262 | curl_multi_cleanup (multi); |
296 | curl_multi_remove_handle (multi, c); | 263 | curl_easy_cleanup (c); |
297 | curl_multi_cleanup (multi); | 264 | zzuf_socat_stop(); |
298 | curl_easy_cleanup (c); | 265 | MHD_stop_daemon (d); |
299 | MHD_stop_daemon (d); | 266 | return 1024; |
300 | return 2048; | 267 | } |
301 | } | 268 | start = time (NULL); |
302 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) | 269 | while ((time (NULL) - start < 5) && (c != NULL)) |
303 | { | 270 | { |
304 | curl_multi_remove_handle (multi, c); | 271 | max = 0; |
305 | curl_multi_cleanup (multi); | 272 | FD_ZERO (&rs); |
306 | curl_easy_cleanup (c); | 273 | FD_ZERO (&ws); |
307 | MHD_stop_daemon (d); | 274 | FD_ZERO (&es); |
308 | return 4096; | 275 | curl_multi_perform (multi, &running); |
309 | } | 276 | mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); |
310 | tv.tv_sec = 0; | 277 | if (mret != CURLM_OK) |
311 | tv.tv_usec = 1000; | 278 | { |
312 | select (max + 1, &rs, &ws, &es, &tv); | 279 | curl_multi_remove_handle (multi, c); |
313 | curl_multi_perform (multi, &running); | 280 | curl_multi_cleanup (multi); |
314 | if (running == 0) | 281 | curl_easy_cleanup (c); |
315 | { | 282 | zzuf_socat_stop(); |
316 | msg = curl_multi_info_read (multi, &running); | 283 | MHD_stop_daemon (d); |
317 | if (msg == NULL) | 284 | return 2048; |
318 | break; | 285 | } |
319 | if (msg->msg == CURLMSG_DONE) | 286 | if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) |
320 | { | 287 | { |
321 | if (msg->data.result != CURLE_OK) | 288 | curl_multi_remove_handle (multi, c); |
322 | printf ("%s failed at %s:%d: `%s'\n", | 289 | curl_multi_cleanup (multi); |
323 | "curl_multi_perform", | 290 | curl_easy_cleanup (c); |
324 | __FILE__, | 291 | zzuf_socat_stop(); |
325 | __LINE__, curl_easy_strerror (msg->data.result)); | 292 | MHD_stop_daemon (d); |
326 | curl_multi_remove_handle (multi, c); | 293 | return 4096; |
327 | curl_multi_cleanup (multi); | 294 | } |
328 | curl_easy_cleanup (c); | 295 | tv.tv_sec = 0; |
329 | c = NULL; | 296 | tv.tv_usec = 1000; |
330 | multi = NULL; | 297 | select (max + 1, &rs, &ws, &es, &tv); |
331 | } | 298 | curl_multi_perform (multi, &running); |
332 | } | 299 | if (running == 0) |
333 | MHD_run (d); | 300 | { |
334 | } | 301 | curl_multi_info_read (multi, &running); |
335 | if (multi != NULL) | 302 | curl_multi_remove_handle (multi, c); |
336 | { | 303 | curl_easy_cleanup (c); |
337 | curl_multi_remove_handle (multi, c); | 304 | c = NULL; |
338 | curl_easy_cleanup (c); | 305 | } |
339 | curl_multi_cleanup (multi); | 306 | MHD_run (d); |
340 | } | 307 | } |
308 | if (c != NULL) | ||
309 | { | ||
310 | curl_multi_remove_handle (multi, c); | ||
311 | curl_easy_cleanup (c); | ||
312 | } | ||
313 | } | ||
314 | fprintf(stderr, "\n"); | ||
315 | curl_multi_cleanup (multi); | ||
316 | zzuf_socat_stop(); | ||
341 | MHD_stop_daemon (d); | 317 | MHD_stop_daemon (d); |
342 | return validate (cbc, 8192); | 318 | return 0; |
343 | } | 319 | } |
344 | 320 | ||
345 | 321 | ||
@@ -352,11 +328,8 @@ main (int argc, char *const *argv) | |||
352 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 328 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
353 | return 2; | 329 | return 2; |
354 | errorCount += testInternalGet (); | 330 | errorCount += testInternalGet (); |
355 | if (0) | 331 | errorCount += testMultithreadedGet (); |
356 | { | 332 | errorCount += testExternalGet (); |
357 | errorCount += testMultithreadedGet (); | ||
358 | errorCount += testExternalGet (); | ||
359 | } | ||
360 | if (errorCount != 0) | 333 | if (errorCount != 0) |
361 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 334 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
362 | curl_global_cleanup (); | 335 | curl_global_cleanup (); |