diff --git a/src/testzzuf/Makefile.am b/src/testzzuf/Makefile.am index 0ebaf893..9e9d27a3 100644 --- a/src/testzzuf/Makefile.am +++ b/src/testzzuf/Makefile.am @@ -2,6 +2,8 @@ SUBDIRS = . INCLUDES = -I$(top_srcdir)/src/include +EXTRA_DIST = README socat.c + check_PROGRAMS = \ daemontest_get \ daemontest_post \ diff --git a/src/testzzuf/README b/src/testzzuf/README new file mode 100644 index 00000000..5ee15698 --- /dev/null +++ b/src/testzzuf/README @@ -0,0 +1,13 @@ +Testcases in this directory require zzuf and socat. + +zzuf is used to randomly mess with the TCP connection between the CURL +clients and the MHD server. The goal is to expose problems in MHD's +error handling (by introducing random syntax errors). socat is +used to listen on port 11081 and forward the randomzied stream to +port 11080 where MHD is waiting. + +As a result, the testcases in this directory do NOT check that +whatever CURL returns is what was expected -- random modifications to +the TCP stream can have random effects ;-). Testcases "fail" if the +code crashes or hangs indefinitely. + diff --git a/src/testzzuf/daemontest_get.c b/src/testzzuf/daemontest_get.c index 2d5729c1..d7b11f3e 100644 --- a/src/testzzuf/daemontest_get.c +++ b/src/testzzuf/daemontest_get.c @@ -1,6 +1,6 @@ /* This file is part of libmicrohttpd - (C) 2007 Christian Grothoff + (C) 2007, 2008 Christian Grothoff libmicrohttpd is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -21,7 +21,6 @@ /** * @file daemontest_get.c * @brief Testcase for libmicrohttpd GET operations - * TODO: test parsing of query * @author Christian Grothoff */ @@ -36,6 +35,18 @@ #include #endif +#include "socat.c" + +/** + * A larger loop count will run more random tests -- + * which would be good, except that it may take too + * long for most user's patience. So this small + * value is the default. + */ +#define LOOP_COUNT 10 + +#define CURL_TIMEOUT 50L + static int oneone; struct CBC @@ -96,45 +107,39 @@ testInternalGet () CURL *c; char buf[2048]; struct CBC cbc; - CURLcode errornum; + int i; cbc.buf = buf; cbc.size = 2048; cbc.pos = 0; - d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_DEBUG, + d = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY /* | MHD_USE_DEBUG */, 11080, NULL, NULL, &ahc_echo, "GET", MHD_OPTION_END); if (d == NULL) return 1; - c = curl_easy_init (); - curl_easy_setopt (c, CURLOPT_URL, "http://localhost:11080/hello_world"); - curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer); - curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc); - curl_easy_setopt (c, CURLOPT_FAILONERROR, 1); - curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L); - curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 15L); - if (oneone) - curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); - else - curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); - // NOTE: use of CONNECTTIMEOUT without also - // setting NOSIGNAL results in really weird - // crashes on my system! - curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1); - if (CURLE_OK != (errornum = curl_easy_perform (c))) - { - fprintf (stderr, - "curl_easy_perform failed: `%s'\n", - curl_easy_strerror (errornum)); - curl_easy_cleanup (c); - MHD_stop_daemon (d); - return 2; - } - curl_easy_cleanup (c); + zzuf_socat_start(); + for (i=0;imsg == CURLMSG_DONE) - { - if (msg->data.result != CURLE_OK) - printf ("%s failed at %s:%d: `%s'\n", - "curl_multi_perform", - __FILE__, - __LINE__, curl_easy_strerror (msg->data.result)); - curl_multi_remove_handle (multi, c); - curl_multi_cleanup (multi); - curl_easy_cleanup (c); - c = NULL; - multi = NULL; - } - } - MHD_run (d); - } - if (multi != NULL) - { - curl_multi_remove_handle (multi, c); - curl_easy_cleanup (c); - curl_multi_cleanup (multi); - } + zzuf_socat_start(); + for (i=0;i +#include +#include +#include + + +static pid_t zzuf_pid; + +static void +zzuf_socat_start() { + int status; + char * const args[] = { + "zzuf", + "--ratio=0.0:0.75", + "-n", + "-A", + "socat", + "TCP4-LISTEN:11081,reuseaddr,fork", + "TCP4:127.0.0.1:11080", + NULL, + }; + zzuf_pid = fork(); + if (zzuf_pid == -1) { + fprintf(stderr, + "fork failed: %s\n", + strerror(errno)); + exit(1); + } + if (zzuf_pid != 0) + { + sleep(1); /* allow zzuf and socat to start */ + status = 0; + if (0 < waitpid(zzuf_pid, &status, WNOHANG)) + { + if (WIFEXITED(status)) + fprintf(stderr, + "zzuf died with status code %d!\n", + WEXITSTATUS(status)); + if (WIFSIGNALED(status)) + fprintf(stderr, + "zzuf died from signal %d!\n", + WTERMSIG(status)); + exit(1); + } + return; + } + setpgrp(); + execvp("zzuf", + args); + fprintf(stderr, + "execution of `zzuf' failed: %s\n", + strerror(errno)); + zzuf_pid = 0; /* fork failed */ + exit(1); +} + + +static void +zzuf_socat_stop() { + int status; + if (zzuf_pid != 0) + { + if (0 != killpg(zzuf_pid, SIGINT)) + fprintf(stderr, + "Failed to killpg: %s\n", + strerror(errno)); + kill(zzuf_pid, SIGINT); + waitpid(zzuf_pid, &status, 0); + sleep(1); /* allow socat to also die in peace */ + } +} + +/* end of socat.c */