aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libtest')
-rw-r--r--tests/libtest/Makefile.inc21
-rw-r--r--tests/libtest/first.c56
-rw-r--r--tests/libtest/lib500.c2
-rw-r--r--tests/libtest/lib502.c94
-rw-r--r--tests/libtest/lib503.c128
-rw-r--r--tests/libtest/lib504.c122
-rw-r--r--tests/libtest/lib505.c6
-rw-r--r--tests/libtest/lib506.c3
-rw-r--r--tests/libtest/lib507.c123
-rw-r--r--tests/libtest/lib518.c7
-rw-r--r--tests/libtest/lib525.c169
-rw-r--r--tests/libtest/lib526.c237
-rw-r--r--tests/libtest/lib530.c181
-rw-r--r--tests/libtest/lib533.c151
-rw-r--r--tests/libtest/lib536.c153
-rw-r--r--tests/libtest/lib537.c7
-rw-r--r--tests/libtest/lib540.c177
-rw-r--r--tests/libtest/lib541.c13
-rw-r--r--tests/libtest/lib542.c13
-rw-r--r--tests/libtest/lib554.c19
-rw-r--r--tests/libtest/lib555.c116
-rw-r--r--tests/libtest/lib560.c80
-rw-r--r--tests/libtest/lib562.c14
-rw-r--r--tests/libtest/lib564.c120
-rw-r--r--tests/libtest/lib566.c1
-rw-r--r--tests/libtest/lib567.c2
-rw-r--r--tests/libtest/lib568.c1
-rw-r--r--tests/libtest/lib569.c1
-rw-r--r--tests/libtest/lib570.c1
-rw-r--r--tests/libtest/lib571.c4
-rw-r--r--tests/libtest/lib572.c1
-rw-r--r--tests/libtest/lib573.c93
-rw-r--r--tests/libtest/lib574.c1
-rw-r--r--tests/libtest/lib575.c87
-rw-r--r--tests/libtest/lib576.c2
-rw-r--r--tests/libtest/lib578.c1
-rw-r--r--tests/libtest/lib579.c1
-rw-r--r--tests/libtest/lib582.c176
-rw-r--r--tests/libtest/lib583.c59
-rw-r--r--tests/libtest/lib586.c246
-rw-r--r--tests/libtest/test.h338
41 files changed, 1501 insertions, 1526 deletions
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index 98e33c1f1..86b3b29ab 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -15,7 +15,7 @@ noinst_PROGRAMS = chkhostname \
lib579 lib529 lib530 lib532 lib533 lib536 lib537 lib540 lib541 lib542 \
lib543 lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555 \
lib556 lib539 lib557 lib560 lib562 lib564 lib565 lib566 lib567 lib568 \
- lib569 lib570 lib571 lib572 lib573 lib582 lib583 lib585
+ lib569 lib570 lib571 lib572 lib573 lib582 lib583 lib585 lib587
chkhostname_SOURCES = chkhostname.c $(top_srcdir)/lib/curl_gethostname.c
chkhostname_LDADD = @CURL_NETWORK_LIBS@
@@ -26,7 +26,7 @@ lib500_SOURCES = lib500.c $(SUPPORTFILES)
lib501_SOURCES = lib501.c $(SUPPORTFILES)
-lib502_SOURCES = lib502.c $(SUPPORTFILES) $(TESTUTIL)
+lib502_SOURCES = lib502.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib503_SOURCES = lib503.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
@@ -56,7 +56,7 @@ lib516_SOURCES = lib516.c $(SUPPORTFILES)
lib517_SOURCES = lib517.c $(SUPPORTFILES)
-lib518_SOURCES = lib518.c $(SUPPORTFILES)
+lib518_SOURCES = lib518.c $(SUPPORTFILES) $(WARNLESS)
lib519_SOURCES = lib519.c $(SUPPORTFILES)
@@ -89,11 +89,11 @@ lib533_SOURCES = lib533.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib536_SOURCES = lib536.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
-lib537_SOURCES = lib537.c $(SUPPORTFILES)
+lib537_SOURCES = lib537.c $(SUPPORTFILES) $(WARNLESS)
lib539_SOURCES = lib539.c $(SUPPORTFILES)
-lib540_SOURCES = lib540.c $(SUPPORTFILES) $(WARNLESS)
+lib540_SOURCES = lib540.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib541_SOURCES = lib541.c $(SUPPORTFILES)
@@ -113,7 +113,7 @@ lib548_CPPFLAGS = $(AM_CPPFLAGS) -DLIB548
lib549_SOURCES = lib549.c $(SUPPORTFILES)
-lib555_SOURCES = lib555.c $(SUPPORTFILES) $(TESTUTIL)
+lib555_SOURCES = lib555.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib552_SOURCES = lib552.c $(SUPPORTFILES)
@@ -125,11 +125,11 @@ lib556_SOURCES = lib556.c $(SUPPORTFILES)
lib557_SOURCES = lib557.c $(SUPPORTFILES)
-lib560_SOURCES = lib560.c $(SUPPORTFILES) $(WARNLESS)
+lib560_SOURCES = lib560.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib574_SOURCES = lib574.c $(SUPPORTFILES)
-lib575_SOURCES = lib575.c $(SUPPORTFILES) $(WARNLESS)
+lib575_SOURCES = lib575.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib576_SOURCES = lib576.c $(SUPPORTFILES)
@@ -154,7 +154,7 @@ lib571_SOURCES = lib571.c $(SUPPORTFILES)
lib572_SOURCES = lib572.c $(SUPPORTFILES)
-lib573_SOURCES = lib573.c $(SUPPORTFILES) $(TESTUTIL)
+lib573_SOURCES = lib573.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
lib578_SOURCES = lib578.c $(SUPPORTFILES)
@@ -166,3 +166,6 @@ lib583_SOURCES = lib583.c $(SUPPORTFILES)
lib585_SOURCES = lib500.c $(SUPPORTFILES)
lib585_CPPFLAGS = $(AM_CPPFLAGS) -DLIB585
+
+lib587_SOURCES = lib554.c $(SUPPORTFILES)
+lib587_CPPFLAGS = $(AM_CPPFLAGS) -DLIB587
diff --git a/tests/libtest/first.c b/tests/libtest/first.c
index 205d3943f..57e6ddd79 100644
--- a/tests/libtest/first.c
+++ b/tests/libtest/first.c
@@ -30,19 +30,25 @@
# include "memdebug.h"
#endif
-int select_test (int num_fds, fd_set *rd, fd_set *wr, fd_set *exc,
- struct timeval *tv)
+int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
+ struct timeval *tv)
{
+ if(nfds < 0) {
+ SET_SOCKERRNO(EINVAL);
+ return -1;
+ }
#ifdef USE_WINSOCK
- /* Winsock doesn't like no socket set in 'rd', 'wr' or 'exc'. This is
- * case when 'num_fds <= 0. So sleep.
+ /*
+ * Winsock select() requires that at least one of the three fd_set
+ * pointers is not NULL and points to a non-empty fdset. IOW Winsock
+ * select() can not be used to sleep without a single fd_set.
*/
- if (num_fds <= 0) {
+ if(!nfds) {
Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
return 0;
}
#endif
- return select(num_fds, rd, wr, exc, tv);
+ return select(nfds, rd, wr, exc, tv);
}
char *libtest_arg2=NULL;
@@ -50,28 +56,31 @@ char *libtest_arg3=NULL;
int test_argc;
char **test_argv;
+struct timeval tv_test_start; /* for test timing */
+
#ifdef UNITTESTS
int unitfail; /* for unittests */
#endif
-int main(int argc, char **argv)
-{
- char *URL;
-
#ifdef CURLDEBUG
- /* this sends all memory debug messages to a logfile named memdump */
- char *env = curl_getenv("CURL_MEMDEBUG");
+static void memory_tracking_init(void)
+{
+ char *env;
+ /* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
+ env = curl_getenv("CURL_MEMDEBUG");
if(env) {
/* use the value as file name */
- char *s = strdup(env);
+ char fname[CURL_MT_LOGFNAME_BUFSIZE];
+ if(strlen(env) >= CURL_MT_LOGFNAME_BUFSIZE)
+ env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
+ strcpy(fname, env);
curl_free(env);
- curl_memdebug(s);
- free(s);
- /* this weird strdup() and stuff here is to make the curl_free() get
- called before the memdebug() as otherwise the memdebug tracing will
- with tracing a free() without an alloc! */
+ curl_memdebug(fname);
+ /* this weird stuff here is to make curl_free() get called
+ before curl_memdebug() as otherwise memory tracking will
+ log a free() without an alloc! */
}
- /* this enables the fail-on-alloc-number-N functionality */
+ /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
env = curl_getenv("CURL_MEMLIMIT");
if(env) {
char *endptr;
@@ -80,8 +89,17 @@ int main(int argc, char **argv)
curl_memlimit(num);
curl_free(env);
}
+}
+#else
+# define memory_tracking_init() Curl_nop_stmt
#endif
+int main(int argc, char **argv)
+{
+ char *URL;
+
+ memory_tracking_init();
+
/*
* Setup proper locale from environment. This is needed to enable locale-
* specific behaviour by the C library in order to test for undesired side
diff --git a/tests/libtest/lib500.c b/tests/libtest/lib500.c
index 8ebeb1292..51680fc31 100644
--- a/tests/libtest/lib500.c
+++ b/tests/libtest/lib500.c
@@ -52,7 +52,7 @@ static void setupcallbacks(CURL *curl)
}
#else
-#define setupcallbacks(x)
+#define setupcallbacks(x) Curl_nop_stmt
#endif
diff --git a/tests/libtest/lib502.c b/tests/libtest/lib502.c
index 9ade12afb..554583ae2 100644
--- a/tests/libtest/lib502.c
+++ b/tests/libtest/lib502.c
@@ -22,10 +22,10 @@
#include "test.h"
#include "testutil.h"
+#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
/*
* Get a single URL without select().
@@ -33,71 +33,57 @@
int test(char *URL)
{
- CURL *c;
+ CURL *c = NULL;
CURLM *m = NULL;
int res = 0;
- int running=1;
- struct timeval mp_start;
- char mp_timedout = FALSE;
+ int running;
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- if ((c = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ global_init(CURL_GLOBAL_ALL);
- test_setopt(c, CURLOPT_URL, URL);
+ easy_init(c);
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_setopt(c, CURLOPT_URL, URL);
- if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(m);
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- while (running) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
- fprintf(stderr, "nothing left running.\n");
- break;
- }
- }
+ multi_add_handle(m, c);
+
+ for(;;) {
+ struct timeval timeout;
+ fd_set fdread, fdwrite, fdexcep;
+ int maxfd = -99;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000L; /* 100 ms */
+
+ multi_perform(m, &running);
- if (mp_timedout) {
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
+
+ if(!running)
+ break; /* done */
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+
+ multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ abort_on_test_timeout();
}
test_cleanup:
- if(m) {
- curl_multi_remove_handle(m, c);
- curl_multi_cleanup(m);
- }
+ /* proper cleanup sequence - type PA */
+
+ curl_multi_remove_handle(m, c);
+ curl_multi_cleanup(m);
curl_easy_cleanup(c);
curl_global_cleanup();
diff --git a/tests/libtest/lib503.c b/tests/libtest/lib503.c
index 25a641548..f3f96aaa5 100644
--- a/tests/libtest/lib503.c
+++ b/tests/libtest/lib503.c
@@ -21,14 +21,11 @@
***************************************************************************/
#include "test.h"
-#include <sys/types.h>
-
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
/*
* Source code in here hugely as reported in bug report 651460 by
@@ -40,123 +37,62 @@
int test(char *URL)
{
- CURL *c;
+ CURL *c = NULL;
CURLM *m = NULL;
int res = 0;
int running;
- char done = FALSE;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
-
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
- if ((c = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- test_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
- test_setopt(c, CURLOPT_URL, URL);
- test_setopt(c, CURLOPT_USERPWD, "test:ing");
- test_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing");
- test_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L);
- test_setopt(c, CURLOPT_HEADER, 1L);
-
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ global_init(CURL_GLOBAL_ALL);
- if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_init(c);
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ easy_setopt(c, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
+ easy_setopt(c, CURLOPT_URL, URL);
+ easy_setopt(c, CURLOPT_USERPWD, "test:ing");
+ easy_setopt(c, CURLOPT_PROXYUSERPWD, "test:ing");
+ easy_setopt(c, CURLOPT_HTTPPROXYTUNNEL, 1L);
+ easy_setopt(c, CURLOPT_HEADER, 1L);
- while(!done) {
- fd_set rd, wr, exc;
- int max_fd;
+ multi_init(m);
+
+ multi_add_handle(m, c);
+
+ for(;;) {
struct timeval interval;
+ fd_set rd, wr, exc;
+ int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- while (res == CURLM_CALL_MULTI_PERFORM) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
- done = TRUE;
- break;
- }
- }
- if (mp_timedout || done)
- break;
-
- if (res != CURLM_OK) {
- fprintf(stderr, "not okay???\n");
- break;
- }
+ multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
+ if(!running)
+ break; /* done */
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
- max_fd = 0;
- if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
- fprintf(stderr, "unexpected failured of fdset.\n");
- res = 89;
- break;
- }
+ multi_fdset(m, &rd, &wr, &exc, &maxfd);
- if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
- fprintf(stderr, "bad select??\n");
- res = 95;
- break;
- }
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
- res = CURLM_CALL_MULTI_PERFORM;
- }
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
}
test_cleanup:
- if(m) {
- curl_multi_remove_handle(m, c);
- curl_multi_cleanup(m);
- }
+ /* proper cleanup sequence - type PA */
+
+ curl_multi_remove_handle(m, c);
+ curl_multi_cleanup(m);
curl_easy_cleanup(c);
curl_global_cleanup();
diff --git a/tests/libtest/lib504.c b/tests/libtest/lib504.c
index f45ac256b..358fc98dc 100644
--- a/tests/libtest/lib504.c
+++ b/tests/libtest/lib504.c
@@ -21,14 +21,11 @@
***************************************************************************/
#include "test.h"
-#include <sys/types.h>
-
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
/*
* Source code in here hugely as reported in bug report 651464 by
@@ -39,85 +36,41 @@
*/
int test(char *URL)
{
- CURL *c;
+ CURL *c = NULL;
int res = 0;
CURLM *m = NULL;
fd_set rd, wr, exc;
- CURLMcode ret;
- char done = FALSE;
int running;
- int max_fd;
- int rc;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
-
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
- if ((c = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
+
+ global_init(CURL_GLOBAL_ALL);
+
+ easy_init(c);
/* The point here is that there must not be anything running on the given
proxy port */
if (libtest_arg2)
- test_setopt(c, CURLOPT_PROXY, libtest_arg2);
- test_setopt(c, CURLOPT_URL, URL);
- test_setopt(c, CURLOPT_VERBOSE, 1L);
-
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_setopt(c, CURLOPT_PROXY, libtest_arg2);
+ easy_setopt(c, CURLOPT_URL, URL);
+ easy_setopt(c, CURLOPT_VERBOSE, 1L);
- if ((ret = curl_multi_add_handle(m, c)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", ret);
- curl_multi_cleanup(m);
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(m);
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_add_handle(m, c);
- while (!done) {
+ for(;;) {
struct timeval interval;
+ int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
fprintf(stderr, "curl_multi_perform()\n");
- ret = CURLM_CALL_MULTI_PERFORM;
+ multi_perform(m, &running);
- while (ret == CURLM_CALL_MULTI_PERFORM) {
- ret = curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- }
- if (mp_timedout)
- break;
+ abort_on_test_timeout();
if(!running) {
/* This is where this code is expected to reach */
@@ -125,47 +78,34 @@ int test(char *URL)
CURLMsg *msg = curl_multi_info_read(m, &numleft);
fprintf(stderr, "Expected: not running\n");
if(msg && !numleft)
- res = 100; /* this is where we should be */
+ res = TEST_ERR_SUCCESS; /* this is where we should be */
else
- res = 99; /* not correct */
- break;
- }
- fprintf(stderr, "running == %d, ret == %d\n", running, ret);
-
- if (ret != CURLM_OK) {
- res = 2;
- break;
+ res = TEST_ERR_FAILURE; /* not correct */
+ break; /* done */
}
+ fprintf(stderr, "running == %d\n", running);
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
- max_fd = 0;
fprintf(stderr, "curl_multi_fdset()\n");
- if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
- fprintf(stderr, "unexpected failured of fdset.\n");
- res = 3;
- break;
- }
- rc = select_test(max_fd+1, &rd, &wr, &exc, &interval);
- fprintf(stderr, "select returned %d\n", rc);
- }
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ multi_fdset(m, &rd, &wr, &exc, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
+
+ abort_on_test_timeout();
}
test_cleanup:
- if(m) {
- curl_multi_remove_handle(m, c);
- curl_multi_cleanup(m);
- }
+ /* proper cleanup sequence - type PA */
+
+ curl_multi_remove_handle(m, c);
+ curl_multi_cleanup(m);
curl_easy_cleanup(c);
curl_global_cleanup();
diff --git a/tests/libtest/lib505.c b/tests/libtest/lib505.c
index 0a255d673..394131ebe 100644
--- a/tests/libtest/lib505.c
+++ b/tests/libtest/lib505.c
@@ -24,12 +24,6 @@
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
diff --git a/tests/libtest/lib506.c b/tests/libtest/lib506.c
index 6476b9546..4477eaa50 100644
--- a/tests/libtest/lib506.c
+++ b/tests/libtest/lib506.c
@@ -20,9 +20,6 @@
*
***************************************************************************/
#include "test.h"
-#include <stdlib.h>
-#include <ctype.h>
-#include <errno.h>
#include <curl/mprintf.h>
diff --git a/tests/libtest/lib507.c b/tests/libtest/lib507.c
index c5a009d8c..87c21defb 100644
--- a/tests/libtest/lib507.c
+++ b/tests/libtest/lib507.c
@@ -25,75 +25,40 @@
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
int test(char *URL)
{
- CURL* curls;
- CURLM* multi;
+ CURL* curls = NULL;
+ CURLM* multi = NULL;
int still_running;
int i = -1;
int res = 0;
CURLMsg *msg;
- CURLMcode ret;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
-
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
- if ((multi = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- if ((curls = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_multi_cleanup(multi);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ global_init(CURL_GLOBAL_ALL);
- test_setopt(curls, CURLOPT_URL, URL);
- test_setopt(curls, CURLOPT_HEADER, 1L);
+ multi_init(multi);
- if ((ret = curl_multi_add_handle(multi, curls)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", ret);
- curl_easy_cleanup(curls);
- curl_multi_cleanup(multi);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_init(curls);
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
+ easy_setopt(curls, CURLOPT_URL, URL);
+ easy_setopt(curls, CURLOPT_HEADER, 1L);
- do {
- ret = curl_multi_perform(multi, &still_running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- } while (ret == CURLM_CALL_MULTI_PERFORM);
+ multi_add_handle(multi, curls);
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_perform(multi, &still_running);
- while ((!ml_timedout) && (!mp_timedout) && (still_running)) {
+ abort_on_test_timeout();
+
+ while(still_running) {
struct timeval timeout;
- int rc;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
- int maxfd;
+ int maxfd = -99;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
@@ -101,49 +66,29 @@ int test(char *URL)
timeout.tv_sec = 1;
timeout.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
-
- curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
- rc = select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
- switch(rc) {
- case -1:
- break;
- case 0:
- default:
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
- do {
- ret = curl_multi_perform(multi, &still_running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- } while (ret == CURLM_CALL_MULTI_PERFORM);
- break;
- }
- }
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- i = TEST_ERR_RUNS_FOREVER;
- }
- else {
- msg = curl_multi_info_read(multi, &still_running);
- if(msg)
- /* this should now contain a result code from the easy handle,
- get it */
- i = msg->data.result;
+ multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ abort_on_test_timeout();
+
+ multi_perform(multi, &still_running);
+
+ abort_on_test_timeout();
}
+ msg = curl_multi_info_read(multi, &still_running);
+ if(msg)
+ /* this should now contain a result code from the easy handle,
+ get it */
+ i = msg->data.result;
+
test_cleanup:
+ /* undocumented cleanup sequence - type UA */
+
curl_multi_cleanup(multi);
curl_easy_cleanup(curls);
curl_global_cleanup();
diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c
index c483d7ade..23f7f17c6 100644
--- a/tests/libtest/lib518.c
+++ b/tests/libtest/lib518.c
@@ -21,9 +21,6 @@
***************************************************************************/
#include "test.h"
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
@@ -33,10 +30,8 @@
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
+#include "warnless.h"
#include "memdebug.h"
#ifndef FD_SETSIZE
diff --git a/tests/libtest/lib525.c b/tests/libtest/lib525.c
index f034050eb..ca128cb9c 100644
--- a/tests/libtest/lib525.c
+++ b/tests/libtest/lib525.c
@@ -21,45 +21,45 @@
***************************************************************************/
#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
int test(char *URL)
{
int res = 0;
- CURL *curl;
- FILE *hd_src ;
+ CURL *curl = NULL;
+ FILE *hd_src = NULL;
int hd ;
int error;
struct_stat file_info;
- int running;
- char done=FALSE;
CURLM *m = NULL;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
+ int running;
+
+ start_test_timing();
- if (!libtest_arg2) {
+ if(!libtest_arg2) {
+#ifdef LIB529
+ /* test 529 */
+ fprintf(stderr, "Usage: lib529 [url] [uploadfile]\n");
+#else
+ /* test 525 */
fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
- return -1;
+#endif
+ return TEST_ERR_USAGE;
}
hd_src = fopen(libtest_arg2, "rb");
if(NULL == hd_src) {
error = ERRNO;
- fprintf(stderr, "fopen() failed with error: %d %s\n",
+ fprintf(stderr, "fopen() failed with error: %d (%s)\n",
error, strerror(error));
- fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
- return TEST_ERR_MAJOR_BAD;
+ fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
+ return TEST_ERR_FOPEN;
}
/* get the file size of the local file */
@@ -67,40 +67,35 @@ int test(char *URL)
if(hd == -1) {
/* can't open file, bail out */
error = ERRNO;
- fprintf(stderr, "fstat() failed with error: %d %s\n",
+ fprintf(stderr, "fstat() failed with error: %d (%s)\n",
error, strerror(error));
- fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
+ fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
fclose(hd_src);
- return -1;
+ return TEST_ERR_FSTAT;
}
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
+ res_global_init(CURL_GLOBAL_ALL);
+ if(res) {
fclose(hd_src);
- return TEST_ERR_MAJOR_BAD;
+ return res;
}
- if ((curl = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- fclose(hd_src);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_init(curl);
/* enable uploading */
- test_setopt(curl, CURLOPT_UPLOAD, 1L);
+ easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
- test_setopt(curl,CURLOPT_URL, URL);
+ easy_setopt(curl,CURLOPT_URL, URL);
/* go verbose */
- test_setopt(curl, CURLOPT_VERBOSE, 1L);
+ easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* use active FTP */
- test_setopt(curl, CURLOPT_FTPPORT, "-");
+ easy_setopt(curl, CURLOPT_FTPPORT, "-");
/* now specify which file to upload */
- test_setopt(curl, CURLOPT_READDATA, hd_src);
+ easy_setopt(curl, CURLOPT_READDATA, hd_src);
/* NOTE: if you want this code to work on Windows with libcurl as a DLL, you
MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to
@@ -111,114 +106,60 @@ int test(char *URL)
option you MUST make sure that the type of the passed-in argument is a
curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
make sure that to pass in a type 'long' argument. */
- test_setopt(curl, CURLOPT_INFILESIZE_LARGE,
- (curl_off_t)file_info.st_size);
-
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- fclose(hd_src);
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
- if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- fclose(hd_src);
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(m);
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_add_handle(m, curl);
- while (!done) {
- fd_set rd, wr, exc;
- int max_fd;
+ for(;;) {
struct timeval interval;
+ fd_set rd, wr, exc;
+ int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- while (res == CURLM_CALL_MULTI_PERFORM) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
- done = TRUE;
- break;
- }
- }
- if (mp_timedout || done)
- break;
-
- if (res != CURLM_OK) {
- fprintf(stderr, "not okay???\n");
- break;
- }
+ multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
+ if(!running)
+ break; /* done */
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
- max_fd = 0;
- if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
- fprintf(stderr, "unexpected failured of fdset.\n");
- res = 189;
- break;
- }
+ multi_fdset(m, &rd, &wr, &exc, &maxfd);
- if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
- fprintf(stderr, "bad select??\n");
- res = 195;
- break;
- }
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
- res = CURLM_CALL_MULTI_PERFORM;
- }
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
}
test_cleanup:
#ifdef LIB529
/* test 529 */
- if(m) {
- curl_multi_remove_handle(m, curl);
- curl_multi_cleanup(m);
- }
+ /* proper cleanup sequence - type PA */
+ curl_multi_remove_handle(m, curl);
+ curl_multi_cleanup(m);
curl_easy_cleanup(curl);
+ curl_global_cleanup();
#else
/* test 525 */
- if(m)
- curl_multi_remove_handle(m, curl);
+ /* proper cleanup sequence - type PB */
+ curl_multi_remove_handle(m, curl);
curl_easy_cleanup(curl);
- if(m)
- curl_multi_cleanup(m);
+ curl_multi_cleanup(m);
+ curl_global_cleanup();
#endif
- fclose(hd_src); /* close the local file */
+ /* close the local file */
+ fclose(hd_src);
- curl_global_cleanup();
return res;
}
diff --git a/tests/libtest/lib526.c b/tests/libtest/lib526.c
index a0085ec3c..9db04dba7 100644
--- a/tests/libtest/lib526.c
+++ b/tests/libtest/lib526.c
@@ -40,16 +40,13 @@
#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
#define NUM_HANDLES 4
@@ -58,192 +55,130 @@ int test(char *URL)
int res = 0;
CURL *curl[NUM_HANDLES];
int running;
- char done=FALSE;
CURLM *m = NULL;
- int current=0;
- int i, j;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
-
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
+ int current = 0;
+ int i;
+
+ for(i=0; i < NUM_HANDLES; i++)
+ curl[i] = NULL;
+
+ start_test_timing();
+
+ global_init(CURL_GLOBAL_ALL);
/* get NUM_HANDLES easy handles */
for(i=0; i < NUM_HANDLES; i++) {
- curl[i] = curl_easy_init();
- if(!curl[i]) {
- fprintf(stderr, "curl_easy_init() failed "
- "on handle #%d\n", i);
- for (j=i-1; j >= 0; j--) {
- curl_easy_cleanup(curl[j]);
- }
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
- res = curl_easy_setopt(curl[i], CURLOPT_URL, URL);
- if(res) {
- fprintf(stderr, "curl_easy_setopt() failed "
- "on handle #%d\n", i);
- for (j=i; j >= 0; j--) {
- curl_easy_cleanup(curl[j]);
- }
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
-
+ easy_init(curl[i]);
+ /* specify target */
+ easy_setopt(curl[i], CURLOPT_URL, URL);
/* go verbose */
- res = curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
- if(res) {
- fprintf(stderr, "curl_easy_setopt() failed "
- "on handle #%d\n", i);
- for (j=i; j >= 0; j--) {
- curl_easy_cleanup(curl[j]);
- }
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
+ easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
}
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- for(i=0; i < NUM_HANDLES; i++) {
- curl_easy_cleanup(curl[i]);
- }
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(m);
- if ((res = (int)curl_multi_add_handle(m, curl[current])) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- for(i=0; i < NUM_HANDLES; i++) {
- curl_easy_cleanup(curl[i]);
- }
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
-
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_add_handle(m, curl[current]);
fprintf(stderr, "Start at URL 0\n");
- while (!done) {
- fd_set rd, wr, exc;
- int max_fd;
+ for(;;) {
struct timeval interval;
+ fd_set rd, wr, exc;
+ int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- while (res == CURLM_CALL_MULTI_PERFORM) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
+ multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
+ if(!running) {
#ifdef LIB527
- /* NOTE: this code does not remove the handle from the multi handle
- here, which would be the nice, sane and documented way of working.
- This however tests that the API survives this abuse gracefully. */
- curl_easy_cleanup(curl[current]);
+ /* NOTE: this code does not remove the handle from the multi handle
+ here, which would be the nice, sane and documented way of working.
+ This however tests that the API survives this abuse gracefully. */
+ curl_easy_cleanup(curl[current]);
+ curl[current] = NULL;
#endif
- if(++current < NUM_HANDLES) {
- fprintf(stderr, "Advancing to URL %d\n", current);
+ if(++current < NUM_HANDLES) {
+ fprintf(stderr, "Advancing to URL %d\n", current);
#ifdef LIB532
- /* first remove the only handle we use */
- curl_multi_remove_handle(m, curl[0]);
-
- /* make us re-use the same handle all the time, and try resetting
- the handle first too */
- curl_easy_reset(curl[0]);
- test_setopt(curl[0], CURLOPT_URL, URL);
- test_setopt(curl[0], CURLOPT_VERBOSE, 1L);
-
- /* re-add it */
- res = (int)curl_multi_add_handle(m, curl[0]);
+ /* first remove the only handle we use */
+ curl_multi_remove_handle(m, curl[0]);
+
+ /* make us re-use the same handle all the time, and try resetting
+ the handle first too */
+ curl_easy_reset(curl[0]);
+ easy_setopt(curl[0], CURLOPT_URL, URL);
+ /* go verbose */
+ easy_setopt(curl[0], CURLOPT_VERBOSE, 1L);
+
+ /* re-add it */
+ multi_add_handle(m, curl[0]);
#else
- res = (int)curl_multi_add_handle(m, curl[current]);
+ multi_add_handle(m, curl[current]);
#endif
- if(res) {
- fprintf(stderr, "add handle failed: %d.\n", res);
- res = 243;
- break;
- }
- }
- else
- done = TRUE; /* bail out */
- break;
}
- }
- if (mp_timedout || done)
- break;
-
- if (res != CURLM_OK) {
- fprintf(stderr, "not okay???\n");
- break;
+ else {
+ break; /* done */
+ }
}
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
- max_fd = 0;
- if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
- fprintf(stderr, "unexpected failured of fdset.\n");
- res = 189;
- break;
- }
+ multi_fdset(m, &rd, &wr, &exc, &maxfd);
- if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
- fprintf(stderr, "bad select??\n");
- res = 195;
- break;
- }
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
- res = CURLM_CALL_MULTI_PERFORM;
- }
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
}
-#ifdef LIB532
test_cleanup:
-#endif
-#ifndef LIB527
- /* get NUM_HANDLES easy handles */
+#if defined(LIB526)
+
+ /* test 526 and 528 */
+ /* proper cleanup sequence - type PB */
+
for(i=0; i < NUM_HANDLES; i++) {
-#ifdef LIB526
- if(m)
- curl_multi_remove_handle(m, curl[i]);
-#endif
+ curl_multi_remove_handle(m, curl[i]);
curl_easy_cleanup(curl[i]);
}
-#endif
- if(m)
- curl_multi_cleanup(m);
+ curl_multi_cleanup(m);
+ curl_global_cleanup();
+#elif defined(LIB527)
+
+ /* test 527 */
+
+ /* Upon non-failure test flow the easy's have already been cleanup'ed. In
+ case there is a failure we arrive here with easy's that have not been
+ cleanup'ed yet, in this case we have to cleanup them or otherwise these
+ will be leaked, let's use undocumented cleanup sequence - type UB */
+
+ if(res)
+ for(i=0; i < NUM_HANDLES; i++)
+ curl_easy_cleanup(curl[i]);
+
+ curl_multi_cleanup(m);
curl_global_cleanup();
+
+#elif defined(LIB532)
+
+ /* test 532 */
+ /* undocumented cleanup sequence - type UB */
+
+ for(i=0; i < NUM_HANDLES; i++)
+ curl_easy_cleanup(curl[i]);
+ curl_multi_cleanup(m);
+ curl_global_cleanup();
+
+#endif
+
return res;
}
diff --git a/tests/libtest/lib530.c b/tests/libtest/lib530.c
index add64ea31..ad84ff8a5 100644
--- a/tests/libtest/lib530.c
+++ b/tests/libtest/lib530.c
@@ -21,22 +21,11 @@
***************************************************************************/
#include "test.h"
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
#define NUM_HANDLES 4
@@ -45,173 +34,71 @@ int test(char *URL)
int res = 0;
CURL *curl[NUM_HANDLES];
int running;
- char done=FALSE;
- CURLM *m;
- int i, j;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
+ CURLM *m = NULL;
+ int i;
char target_url[256];
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
+ for(i=0; i < NUM_HANDLES; i++)
+ curl[i] = NULL;
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
+
+ global_init(CURL_GLOBAL_ALL);
+
+ multi_init(m);
/* get NUM_HANDLES easy handles */
for(i=0; i < NUM_HANDLES; i++) {
- curl[i] = curl_easy_init();
- if(!curl[i]) {
- fprintf(stderr, "curl_easy_init() failed "
- "on handle #%d\n", i);
- for (j=i-1; j >= 0; j--) {
- curl_multi_remove_handle(m, curl[j]);
- curl_easy_cleanup(curl[j]);
- }
- curl_multi_cleanup(m);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
+ /* get an easy handle */
+ easy_init(curl[i]);
+ /* specify target */
sprintf(target_url, "%s%04i", URL, i + 1);
target_url[sizeof(target_url) - 1] = '\0';
-
- res = curl_easy_setopt(curl[i], CURLOPT_URL, target_url);
- if(res) {
- fprintf(stderr, "curl_easy_setopt() failed "
- "on handle #%d\n", i);
- for (j=i; j >= 0; j--) {
- curl_multi_remove_handle(m, curl[j]);
- curl_easy_cleanup(curl[j]);
- }
- curl_multi_cleanup(m);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
-
+ easy_setopt(curl[i], CURLOPT_URL, target_url);
/* go verbose */
- res = curl_easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
- if(res) {
- fprintf(stderr, "curl_easy_setopt() failed "
- "on handle #%d\n", i);
- for (j=i; j >= 0; j--) {
- curl_multi_remove_handle(m, curl[j]);
- curl_easy_cleanup(curl[j]);
- }
- curl_multi_cleanup(m);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
-
+ easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
/* include headers */
- res = curl_easy_setopt(curl[i], CURLOPT_HEADER, 1L);
- if(res) {
- fprintf(stderr, "curl_easy_setopt() failed "
- "on handle #%d\n", i);
- for (j=i; j >= 0; j--) {
- curl_multi_remove_handle(m, curl[j]);
- curl_easy_cleanup(curl[j]);
- }
- curl_multi_cleanup(m);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
-
+ easy_setopt(curl[i], CURLOPT_HEADER, 1L);
/* add handle to multi */
- if ((res = (int)curl_multi_add_handle(m, curl[i])) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "on handle #%d with code %d\n", i, res);
- curl_easy_cleanup(curl[i]);
- for (j=i-1; j >= 0; j--) {
- curl_multi_remove_handle(m, curl[j]);
- curl_easy_cleanup(curl[j]);
- }
- curl_multi_cleanup(m);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD + i;
- }
+ multi_add_handle(m, curl[i]);
}
- curl_multi_setopt(m, CURLMOPT_PIPELINING, 1L);
-
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_setopt(m, CURLMOPT_PIPELINING, 1L);
fprintf(stderr, "Start at URL 0\n");
- while (!done) {
- fd_set rd, wr, exc;
- int max_fd;
+ for(;;) {
struct timeval interval;
+ fd_set rd, wr, exc;
+ int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- while (res == CURLM_CALL_MULTI_PERFORM) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
- done = TRUE; /* bail out */
- break;
- }
- }
- if (mp_timedout || done)
- break;
-
- if (res != CURLM_OK) {
- fprintf(stderr, "not okay???\n");
- break;
- }
+ multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
+ if(!running)
+ break; /* done */
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
- max_fd = 0;
- if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
- fprintf(stderr, "unexpected failured of fdset.\n");
- res = 189;
- break;
- }
+ multi_fdset(m, &rd, &wr, &exc, &maxfd);
- if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
- fprintf(stderr, "bad select??\n");
- res = 195;
- break;
- }
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
- res = CURLM_CALL_MULTI_PERFORM;
- }
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
}
-/* test_cleanup: */
+test_cleanup:
+
+ /* proper cleanup sequence - type PB */
- /* cleanup NUM_HANDLES easy handles */
for(i=0; i < NUM_HANDLES; i++) {
curl_multi_remove_handle(m, curl[i]);
curl_easy_cleanup(curl[i]);
diff --git a/tests/libtest/lib533.c b/tests/libtest/lib533.c
index 606eba75c..fdc18a1eb 100644
--- a/tests/libtest/lib533.c
+++ b/tests/libtest/lib533.c
@@ -23,156 +23,89 @@
#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
int test(char *URL)
{
int res = 0;
- CURL *curl;
+ CURL *curl = NULL;
int running;
- char done=FALSE;
CURLM *m = NULL;
int current=0;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
-
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
- if ((curl = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- test_setopt(curl, CURLOPT_URL, URL);
- test_setopt(curl, CURLOPT_VERBOSE, 1);
- test_setopt(curl, CURLOPT_FAILONERROR, 1);
+ global_init(CURL_GLOBAL_ALL);
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_init(curl);
- if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_setopt(curl, CURLOPT_URL, URL);
+ easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
+
+ multi_init(m);
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_add_handle(m, curl);
fprintf(stderr, "Start at URL 0\n");
- while (!done) {
- fd_set rd, wr, exc;
- int max_fd;
+ for(;;) {
struct timeval interval;
+ fd_set rd, wr, exc;
+ int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- while (res == CURLM_CALL_MULTI_PERFORM) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
- if(!current++) {
- fprintf(stderr, "Advancing to URL 1\n");
- /* remove the handle we use */
- curl_multi_remove_handle(m, curl);
-
- /* make us re-use the same handle all the time, and try resetting
- the handle first too */
- curl_easy_reset(curl);
- test_setopt(curl, CURLOPT_URL, libtest_arg2);
- test_setopt(curl, CURLOPT_VERBOSE, 1);
- test_setopt(curl, CURLOPT_FAILONERROR, 1);
-
- /* re-add it */
- res = (int)curl_multi_add_handle(m, curl);
- if(res) {
- fprintf(stderr, "add handle failed: %d.\n", res);
- res = 243;
- break;
- }
- }
- else
- done = TRUE; /* bail out */
- break;
- }
- }
- if (mp_timedout || done)
- break;
+ multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
+ if(!running) {
+ if(!current++) {
+ fprintf(stderr, "Advancing to URL 1\n");
+ /* remove the handle we use */
+ curl_multi_remove_handle(m, curl);
- if (res != CURLM_OK) {
- fprintf(stderr, "not okay???\n");
- break;
+ /* make us re-use the same handle all the time, and try resetting
+ the handle first too */
+ curl_easy_reset(curl);
+ easy_setopt(curl, CURLOPT_URL, libtest_arg2);
+ easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
+
+ /* re-add it */
+ multi_add_handle(m, curl);
+ }
+ else
+ break; /* done */
}
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
- max_fd = 0;
- if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
- fprintf(stderr, "unexpected failured of fdset.\n");
- res = 189;
- break;
- }
+ multi_fdset(m, &rd, &wr, &exc, &maxfd);
- if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
- fprintf(stderr, "bad select??\n");
- res = 195;
- break;
- }
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
- res = CURLM_CALL_MULTI_PERFORM;
- }
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
}
test_cleanup:
+ /* undocumented cleanup sequence - type UB */
+
curl_easy_cleanup(curl);
- if(m)
- curl_multi_cleanup(m);
+ curl_multi_cleanup(m);
curl_global_cleanup();
return res;
diff --git a/tests/libtest/lib536.c b/tests/libtest/lib536.c
index dca880cea..e3ae402b7 100644
--- a/tests/libtest/lib536.c
+++ b/tests/libtest/lib536.c
@@ -21,128 +21,117 @@
***************************************************************************/
#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
-static CURLMcode perform(CURLM * multi)
+static int perform(CURLM *multi)
{
int handles;
- CURLMcode code;
fd_set fdread, fdwrite, fdexcep;
- struct timeval mp_start;
- char mp_timedout = FALSE;
-
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- for (;;) {
- static struct timeval timeout = /* 100 ms */ { 0, 100000L };
- int maxfd = -1;
-
- code = curl_multi_perform(multi, &handles);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (handles <= 0)
- return CURLM_OK;
-
- switch (code) {
- case CURLM_OK:
- break;
- case CURLM_CALL_MULTI_PERFORM:
- continue;
- default:
- return code;
- }
+ int res = 0;
+
+ for(;;) {
+ struct timeval interval;
+ int maxfd = -99;
+
+ interval.tv_sec = 0;
+ interval.tv_usec = 100000L; /* 100 ms */
+
+ res_multi_perform(multi, &handles);
+ if(res)
+ return res;
+
+ res_test_timedout();
+ if(res)
+ return res;
+
+ if(!handles)
+ break; /* done */
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
- curl_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
- /* In a real-world program you OF COURSE check the return code of the
- function calls. On success, the value of maxfd is guaranteed to be
- greater or equal than -1. We call select(maxfd + 1, ...), specially in
- case of (maxfd == -1), we call select(0, ...), which is basically equal
- to sleep. */
+ res_multi_fdset(multi, &fdread, &fdwrite, &fdexcep, &maxfd);
+ if(res)
+ return res;
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
- if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1)
- return (CURLMcode) ~CURLM_OK;
+ res_select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &interval);
+ if(res)
+ return res;
+
+ res_test_timedout();
+ if(res)
+ return res;
}
- /* We only reach this point if (mp_timedout) */
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- return (CURLMcode) ~CURLM_OK;
+ return 0; /* success */
}
int test(char *URL)
{
- CURLM *multi;
- CURL *easy;
+ CURLM *multi = NULL;
+ CURL *easy = NULL;
int res = 0;
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- if ((multi = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ global_init(CURL_GLOBAL_ALL);
- if ((easy = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_multi_cleanup(multi);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(multi);
- curl_multi_setopt(multi, CURLMOPT_PIPELINING, 1L);
+ easy_init(easy);
- test_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
- test_setopt(easy, CURLOPT_FAILONERROR, 1L);
- test_setopt(easy, CURLOPT_URL, URL);
+ multi_setopt(multi, CURLMOPT_PIPELINING, 1L);
- if (curl_multi_add_handle(multi, easy) != CURLM_OK) {
- printf("curl_multi_add_handle() failed\n");
- res = TEST_ERR_MAJOR_BAD;
- } else {
- if (perform(multi) != CURLM_OK)
- printf("retrieve 1 failed\n");
+ easy_setopt(easy, CURLOPT_WRITEFUNCTION, fwrite);
+ easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
+ easy_setopt(easy, CURLOPT_URL, URL);
- curl_multi_remove_handle(multi, easy);
+ res_multi_add_handle(multi, easy);
+ if(res) {
+ printf("curl_multi_add_handle() 1 failed\n");
+ goto test_cleanup;
}
+
+ res = perform(multi);
+ if(res) {
+ printf("retrieve 1 failed\n");
+ goto test_cleanup;
+ }
+
+ curl_multi_remove_handle(multi, easy);
+
curl_easy_reset(easy);
- test_setopt(easy, CURLOPT_FAILONERROR, 1L);
- test_setopt(easy, CURLOPT_URL, libtest_arg2);
+ easy_setopt(easy, CURLOPT_FAILONERROR, 1L);
+ easy_setopt(easy, CURLOPT_URL, libtest_arg2);
- if (curl_multi_add_handle(multi, easy) != CURLM_OK) {
+ res_multi_add_handle(multi, easy);
+ if(res) {
printf("curl_multi_add_handle() 2 failed\n");
- res = TEST_ERR_MAJOR_BAD;
- } else {
- if (perform(multi) != CURLM_OK)
- printf("retrieve 2 failed\n");
+ goto test_cleanup;
+ }
- curl_multi_remove_handle(multi, easy);
+ res = perform(multi);
+ if(res) {
+ printf("retrieve 2 failed\n");
+ goto test_cleanup;
}
+ curl_multi_remove_handle(multi, easy);
+
test_cleanup:
+ /* undocumented cleanup sequence - type UB */
+
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_global_cleanup();
diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c
index 97119129b..24d252235 100644
--- a/tests/libtest/lib537.c
+++ b/tests/libtest/lib537.c
@@ -21,9 +21,6 @@
***************************************************************************/
#include "test.h"
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
@@ -33,10 +30,8 @@
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
+#include "warnless.h"
#include "memdebug.h"
#if !defined(HAVE_POLL_FINE) && \
diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c
index 55457dd46..21d14872b 100644
--- a/tests/libtest/lib540.c
+++ b/tests/libtest/lib540.c
@@ -30,84 +30,111 @@
#include "test.h"
+#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
+#define TEST_HANG_TIMEOUT 60 * 1000
+
#define PROXY libtest_arg2
#define PROXYUSERPWD libtest_arg3
#define HOST test_argv[4]
-static int init(CURLM *cm, const char* url, const char* userpwd,
+#define NUM_HANDLES 2
+
+CURL *eh[NUM_HANDLES];
+
+static int init(int num, CURLM *cm, const char* url, const char* userpwd,
struct curl_slist *headers)
{
- CURL *eh;
- int res;
+ int res = 0;
- if ((eh = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- return 1; /* failure */
- }
+ res_easy_init(eh[num]);
+ if(res)
+ goto init_failed;
- res = curl_easy_setopt(eh, CURLOPT_URL, url);
- if(res) return 1;
- res = curl_easy_setopt(eh, CURLOPT_PROXY, PROXY);
- if(res) return 1;
- res = curl_easy_setopt(eh, CURLOPT_PROXYUSERPWD, userpwd);
- if(res) return 1;
- res = curl_easy_setopt(eh, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
- if(res) return 1;
- res = curl_easy_setopt(eh, CURLOPT_VERBOSE, 1L);
- if(res) return 1;
- res = curl_easy_setopt(eh, CURLOPT_HEADER, 1L);
- if(res) return 1;
- res = curl_easy_setopt(eh, CURLOPT_HTTPHEADER, headers); /* custom Host: */
- if(res) return 1;
-
- if ((res = (int)curl_multi_add_handle(cm, eh)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- return 1; /* failure */
- }
+ res_easy_setopt(eh[num], CURLOPT_URL, url);
+ if(res)
+ goto init_failed;
+
+ res_easy_setopt(eh[num], CURLOPT_PROXY, PROXY);
+ if(res)
+ goto init_failed;
+
+ res_easy_setopt(eh[num], CURLOPT_PROXYUSERPWD, userpwd);
+ if(res)
+ goto init_failed;
+
+ res_easy_setopt(eh[num], CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
+ if(res)
+ goto init_failed;
+
+ res_easy_setopt(eh[num], CURLOPT_VERBOSE, 1L);
+ if(res)
+ goto init_failed;
+
+ res_easy_setopt(eh[num], CURLOPT_HEADER, 1L);
+ if(res)
+ goto init_failed;
+
+ res_easy_setopt(eh[num], CURLOPT_HTTPHEADER, headers); /* custom Host: */
+ if(res)
+ goto init_failed;
+
+ res_multi_add_handle(cm, eh[num]);
+ if(res)
+ goto init_failed;
return 0; /* success */
+
+init_failed:
+
+ curl_easy_cleanup(eh[num]);
+ eh[num] = NULL;
+
+ return res; /* failure */
}
-static int loop(CURLM *cm, const char* url, const char* userpwd,
+static int loop(int num, CURLM *cm, const char* url, const char* userpwd,
struct curl_slist *headers)
{
CURLMsg *msg;
- CURLMcode code;
long L;
- int M, Q, U = -1;
+ int Q, U = -1;
fd_set R, W, E;
struct timeval T;
+ int res = 0;
- if(init(cm, url, userpwd, headers))
- return 1; /* failure */
+ res = init(num, cm, url, userpwd, headers);
+ if(res)
+ return res;
while (U) {
- do {
- code = curl_multi_perform(cm, &U);
- } while (code == CURLM_CALL_MULTI_PERFORM);
+ int M = -99;
+
+ res_multi_perform(cm, &U);
+ if(res)
+ return res;
+
+ res_test_timedout();
+ if(res)
+ return res;
if (U) {
FD_ZERO(&R);
FD_ZERO(&W);
FD_ZERO(&E);
- if (curl_multi_fdset(cm, &R, &W, &E, &M)) {
- fprintf(stderr, "E: curl_multi_fdset\n");
- return 1; /* failure */
- }
+ res_multi_fdset(cm, &R, &W, &E, &M);
+ if(res)
+ return res;
- /* In a real-world program you OF COURSE check the return that maxfd is
- bigger than -1 so that the call to select() below makes sense! */
+ /* At this point, M is guaranteed to be greater or equal than -1. */
- if (curl_multi_timeout(cm, &L)) {
- fprintf(stderr, "E: curl_multi_timeout\n");
- return 1; /* failure */
- }
+ res_multi_timeout(cm, &L);
+ if(res)
+ return res;
if(L != -1) {
T.tv_sec = L/1000;
@@ -118,24 +145,33 @@ static int loop(CURLM *cm, const char* url, const char* userpwd,
T.tv_usec = 0;
}
- if (0 > select(M+1, &R, &W, &E, &T)) {
- fprintf(stderr, "E: select\n");
- return 1; /* failure */
- }
+ res_select_test(M+1, &R, &W, &E, &T);
+ if(res)
+ return res;
}
- while ((msg = curl_multi_info_read(cm, &Q))) {
- if (msg->msg == CURLMSG_DONE) {
+ while((msg = curl_multi_info_read(cm, &Q)) != NULL) {
+ if(msg->msg == CURLMSG_DONE) {
+ int i;
CURL *e = msg->easy_handle;
fprintf(stderr, "R: %d - %s\n", (int)msg->data.result,
curl_easy_strerror(msg->data.result));
curl_multi_remove_handle(cm, e);
curl_easy_cleanup(e);
+ for(i=0; i < NUM_HANDLES; i++) {
+ if(eh[i] == e) {
+ eh[i] = NULL;
+ break;
+ }
+ }
}
- else {
+ else
fprintf(stderr, "E: CURLMsg (%d)\n", (int)msg->msg);
- }
}
+
+ res_test_timedout();
+ if(res)
+ return res;
}
return 0; /* success */
@@ -146,7 +182,13 @@ int test(char *URL)
CURLM *cm = NULL;
struct curl_slist *headers = NULL;
char buffer[246]; /* naively fixed-size */
- int res;
+ int res = 0;
+ int i;
+
+ for(i=0; i < NUM_HANDLES; i++)
+ eh[i] = NULL;
+
+ start_test_timing();
if(test_argc < 4)
return 99;
@@ -160,30 +202,37 @@ int test(char *URL)
return TEST_ERR_MAJOR_BAD;
}
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
+ res_global_init(CURL_GLOBAL_ALL);
+ if(res) {
curl_slist_free_all(headers);
- return TEST_ERR_MAJOR_BAD;
+ return res;
}
- if ((cm = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_slist_free_all(headers);
+ res_multi_init(cm);
+ if(res) {
curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
+ curl_slist_free_all(headers);
+ return res;
}
- res = loop(cm, URL, PROXYUSERPWD, headers);
+ res = loop(0, cm, URL, PROXYUSERPWD, headers);
if(res)
goto test_cleanup;
fprintf(stderr, "lib540: now we do the request again\n");
- res = loop(cm, URL, PROXYUSERPWD, headers);
+
+ res = loop(1, cm, URL, PROXYUSERPWD, headers);
test_cleanup:
- curl_multi_cleanup(cm);
+ /* proper cleanup sequence - type PB */
+ for(i=0; i < NUM_HANDLES; i++) {
+ curl_multi_remove_handle(cm, eh[i]);
+ curl_easy_cleanup(eh[i]);
+ }
+
+ curl_multi_cleanup(cm);
curl_global_cleanup();
curl_slist_free_all(headers);
diff --git a/tests/libtest/lib541.c b/tests/libtest/lib541.c
index 6af7bc5cf..5fe8dd8ad 100644
--- a/tests/libtest/lib541.c
+++ b/tests/libtest/lib541.c
@@ -21,23 +21,10 @@
***************************************************************************/
#include "test.h"
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include "memdebug.h"
/*
diff --git a/tests/libtest/lib542.c b/tests/libtest/lib542.c
index efe8ea24e..84f493f3e 100644
--- a/tests/libtest/lib542.c
+++ b/tests/libtest/lib542.c
@@ -21,23 +21,10 @@
***************************************************************************/
#include "test.h"
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include "memdebug.h"
/*
diff --git a/tests/libtest/lib554.c b/tests/libtest/lib554.c
index ed8d13f05..d20429d91 100644
--- a/tests/libtest/lib554.c
+++ b/tests/libtest/lib554.c
@@ -40,6 +40,14 @@ struct WriteThis {
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
{
+#ifdef LIB587
+ (void)ptr;
+ (void)size;
+ (void)nmemb;
+ (void)userp;
+ return CURL_READFUNC_ABORT;
+#else
+
struct WriteThis *pooh = (struct WriteThis *)userp;
if(size*nmemb < 1)
@@ -53,6 +61,7 @@ static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userp)
}
return 0; /* no more data left to deliver */
+#endif
}
int test(char *URL)
@@ -136,6 +145,16 @@ int test(char *URL)
if(formrc)
printf("curl_formadd(3) = %d\n", (int)formrc);
+ formrc = curl_formadd(&formpost, &lastptr,
+ CURLFORM_COPYNAME, "somename",
+ CURLFORM_BUFFER, "somefile.txt",
+ CURLFORM_BUFFERPTR, "blah blah",
+ CURLFORM_BUFFERLENGTH, 9,
+ CURLFORM_END);
+
+ if(formrc)
+ printf("curl_formadd(4) = %d\n", (int)formrc);
+
if ((curl = curl_easy_init()) == NULL) {
fprintf(stderr, "curl_easy_init() failed\n");
curl_formfree(formpost);
diff --git a/tests/libtest/lib555.c b/tests/libtest/lib555.c
index c67501521..49a81bf57 100644
--- a/tests/libtest/lib555.c
+++ b/tests/libtest/lib555.c
@@ -30,9 +30,10 @@
#include "test.h"
#include "testutil.h"
+#include "warnless.h"
#include "memdebug.h"
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
#define UPLOADTHIS "this is the blurb we want to upload\n"
@@ -74,95 +75,82 @@ static curlioerr ioctlcallback(CURL *handle,
int test(char *URL)
{
- int res;
- CURL *curl;
+ int res = 0;
+ CURL *curl = NULL;
int counter=0;
CURLM *m = NULL;
int running=1;
- struct timeval mp_start;
- char mp_timedout = FALSE;
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- if ((curl = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ global_init(CURL_GLOBAL_ALL);
+
+ easy_init(curl);
- test_setopt(curl, CURLOPT_URL, URL);
- test_setopt(curl, CURLOPT_VERBOSE, 1L);
- test_setopt(curl, CURLOPT_HEADER, 1L);
+ easy_setopt(curl, CURLOPT_URL, URL);
+ easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ easy_setopt(curl, CURLOPT_HEADER, 1L);
/* read the POST data from a callback */
- test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
- test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
- test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
- test_setopt(curl, CURLOPT_READDATA, &counter);
+ easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
+ easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
+ easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
+ easy_setopt(curl, CURLOPT_READDATA, &counter);
/* We CANNOT do the POST fine without setting the size (or choose chunked)! */
- test_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
+ easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(UPLOADTHIS));
- test_setopt(curl, CURLOPT_POST, 1L);
+ easy_setopt(curl, CURLOPT_POST, 1L);
#ifdef CURL_DOES_CONVERSIONS
/* Convert the POST data to ASCII. */
- test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
+ easy_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
#endif
- test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
- test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
- test_setopt(curl, CURLOPT_PROXYAUTH,
+ easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+ easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
+ easy_setopt(curl, CURLOPT_PROXYAUTH,
(long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(m);
- if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
-
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
+ multi_add_handle(m, curl);
while (running) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
+ struct timeval timeout;
+ fd_set fdread, fdwrite, fdexcep;
+ int maxfd = -99;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000L; /* 100 ms */
+
+ multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
#ifdef TPF
sleep(1); /* avoid ctl-10 dump */
#endif
- if (running <= 0) {
- fprintf(stderr, "nothing left running.\n");
- break;
- }
- }
- if (mp_timedout) {
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ if(!running)
+ break; /* done */
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+
+ multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ abort_on_test_timeout();
}
test_cleanup:
- if(m) {
- curl_multi_remove_handle(m, curl);
- curl_multi_cleanup(m);
- }
+ /* proper cleanup sequence - type PA */
+
+ curl_multi_remove_handle(m, curl);
+ curl_multi_cleanup(m);
curl_easy_cleanup(curl);
curl_global_cleanup();
diff --git a/tests/libtest/lib560.c b/tests/libtest/lib560.c
index e375be535..e8be1c7bd 100644
--- a/tests/libtest/lib560.c
+++ b/tests/libtest/lib560.c
@@ -21,7 +21,11 @@
***************************************************************************/
#include "test.h"
+#include "testutil.h"
#include "warnless.h"
+#include "memdebug.h"
+
+#define TEST_HANG_TIMEOUT 60 * 1000
/*
* Simply download a HTTPS file!
@@ -35,46 +39,44 @@
*/
int test(char *URL)
{
- CURL *http_handle;
+ CURL *http_handle = NULL;
CURLM *multi_handle = NULL;
- CURLMcode code;
- int res;
+ int res = 0;
int still_running; /* keep number of running handles */
- http_handle = curl_easy_init();
- if (!http_handle)
- return TEST_ERR_MAJOR_BAD;
+ start_test_timing();
+
+ /*
+ ** curl_global_init called indirectly from curl_easy_init.
+ */
+
+ easy_init(http_handle);
/* set options */
- test_setopt(http_handle, CURLOPT_URL, URL);
- test_setopt(http_handle, CURLOPT_HEADER, 1L);
- test_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
- test_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
+ easy_setopt(http_handle, CURLOPT_URL, URL);
+ easy_setopt(http_handle, CURLOPT_HEADER, 1L);
+ easy_setopt(http_handle, CURLOPT_SSL_VERIFYPEER, 0L);
+ easy_setopt(http_handle, CURLOPT_SSL_VERIFYHOST, 0L);
/* init a multi stack */
- multi_handle = curl_multi_init();
- if (!multi_handle) {
- curl_easy_cleanup(http_handle);
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(multi_handle);
/* add the individual transfers */
- curl_multi_add_handle(multi_handle, http_handle);
+ multi_add_handle(multi_handle, http_handle);
/* we start some action by calling perform right away */
- do {
- code = curl_multi_perform(multi_handle, &still_running);
- } while(code == CURLM_CALL_MULTI_PERFORM);
+ multi_perform(multi_handle, &still_running);
+
+ abort_on_test_timeout();
while(still_running) {
struct timeval timeout;
- int rc; /* select() return code */
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
- int maxfd;
+ int maxfd = -99;
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
@@ -85,33 +87,25 @@ int test(char *URL)
timeout.tv_usec = 0;
/* get file descriptors from the transfers */
- curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
-
- /* In a real-world program you OF COURSE check the return code of the
- function calls, *and* you make sure that maxfd is bigger than -1 so
- that the call to select() below makes sense! */
-
- rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
-
- switch(rc) {
- case -1:
- /* select error */
- break;
- case 0:
- default:
- /* timeout or readable/writable sockets */
- do {
- code = curl_multi_perform(multi_handle, &still_running);
- } while(code == CURLM_CALL_MULTI_PERFORM);
- break;
- }
+ multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ abort_on_test_timeout();
+
+ /* timeout or readable/writable sockets */
+ multi_perform(multi_handle, &still_running);
+
+ abort_on_test_timeout();
}
test_cleanup:
- if(multi_handle)
- curl_multi_cleanup(multi_handle);
+ /* undocumented cleanup sequence - type UA */
+ curl_multi_cleanup(multi_handle);
curl_easy_cleanup(http_handle);
curl_global_cleanup();
diff --git a/tests/libtest/lib562.c b/tests/libtest/lib562.c
index 657a2d3cd..a5f0ea534 100644
--- a/tests/libtest/lib562.c
+++ b/tests/libtest/lib562.c
@@ -19,26 +19,12 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include "memdebug.h"
/*
diff --git a/tests/libtest/lib564.c b/tests/libtest/lib564.c
index d831d21e1..ed00e1bf6 100644
--- a/tests/libtest/lib564.c
+++ b/tests/libtest/lib564.c
@@ -19,138 +19,74 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
int test(char *URL)
{
int res = 0;
- CURL *curl;
+ CURL *curl = NULL;
int running;
- char done=FALSE;
CURLM *m = NULL;
- struct timeval ml_start;
- struct timeval mp_start;
- char ml_timedout = FALSE;
- char mp_timedout = FALSE;
-
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
- if ((curl = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- test_setopt(curl, CURLOPT_URL, URL);
- test_setopt(curl, CURLOPT_VERBOSE, 1);
- test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
- test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+ global_init(CURL_GLOBAL_ALL);
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_init(curl);
- if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_setopt(curl, CURLOPT_URL, URL);
+ easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
+ easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+
+ multi_init(m);
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_add_handle(m, curl);
fprintf(stderr, "Start at URL 0\n");
- while (!done) {
- fd_set rd, wr, exc;
- int max_fd;
+ for(;;) {
struct timeval interval;
+ fd_set rd, wr, exc;
+ int maxfd = -99;
interval.tv_sec = 1;
interval.tv_usec = 0;
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
-
- while (res == CURLM_CALL_MULTI_PERFORM) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
- done = TRUE; /* bail out */
- break;
- }
- }
- if (mp_timedout || done)
- break;
-
- if (res != CURLM_OK) {
- fprintf(stderr, "not okay???\n");
- break;
- }
+ multi_perform(m, &running);
+
+ abort_on_test_timeout();
+
+ if(!running)
+ break; /* done */
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&exc);
- max_fd = 0;
- if (curl_multi_fdset(m, &rd, &wr, &exc, &max_fd) != CURLM_OK) {
- fprintf(stderr, "unexpected failured of fdset.\n");
- res = 189;
- break;
- }
+ multi_fdset(m, &rd, &wr, &exc, &maxfd);
- if (select_test(max_fd+1, &rd, &wr, &exc, &interval) == -1) {
- fprintf(stderr, "bad select??\n");
- res = 195;
- break;
- }
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
- res = CURLM_CALL_MULTI_PERFORM;
- }
+ select_test(maxfd+1, &rd, &wr, &exc, &interval);
- if (ml_timedout || mp_timedout) {
- if (ml_timedout) fprintf(stderr, "ml_timedout\n");
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
}
test_cleanup:
+ /* undocumented cleanup sequence - type UB */
+
curl_easy_cleanup(curl);
- if(m)
- curl_multi_cleanup(m);
+ curl_multi_cleanup(m);
curl_global_cleanup();
return res;
diff --git a/tests/libtest/lib566.c b/tests/libtest/lib566.c
index 4aa6d98e9..ba839d65f 100644
--- a/tests/libtest/lib566.c
+++ b/tests/libtest/lib566.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#include "memdebug.h"
diff --git a/tests/libtest/lib567.c b/tests/libtest/lib567.c
index 7466e7475..573529cd8 100644
--- a/tests/libtest/lib567.c
+++ b/tests/libtest/lib567.c
@@ -19,8 +19,8 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
+
#include "memdebug.h"
/*
diff --git a/tests/libtest/lib568.c b/tests/libtest/lib568.c
index df0cd88d1..4b15821f2 100644
--- a/tests/libtest/lib568.c
+++ b/tests/libtest/lib568.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#ifdef HAVE_SYS_STAT_H
diff --git a/tests/libtest/lib569.c b/tests/libtest/lib569.c
index 366e4c344..a434d7459 100644
--- a/tests/libtest/lib569.c
+++ b/tests/libtest/lib569.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#include <curl/mprintf.h>
diff --git a/tests/libtest/lib570.c b/tests/libtest/lib570.c
index 29d30dbef..a9fac9915 100644
--- a/tests/libtest/lib570.c
+++ b/tests/libtest/lib570.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#include <curl/mprintf.h>
diff --git a/tests/libtest/lib571.c b/tests/libtest/lib571.c
index 1b2bf7b74..c5f7240d0 100644
--- a/tests/libtest/lib571.c
+++ b/tests/libtest/lib571.c
@@ -19,12 +19,8 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
-#ifdef HAVE_SYS_SOCKET_H
-# include <sys/socket.h>
-#endif
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
diff --git a/tests/libtest/lib572.c b/tests/libtest/lib572.c
index b54877cd4..3df4d036a 100644
--- a/tests/libtest/lib572.c
+++ b/tests/libtest/lib572.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#ifdef HAVE_SYS_STAT_H
diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c
index 466185844..943f6e8c8 100644
--- a/tests/libtest/lib573.c
+++ b/tests/libtest/lib573.c
@@ -19,14 +19,13 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#include "testutil.h"
+#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000
-#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
/*
* Get a single URL without select().
@@ -34,65 +33,51 @@
int test(char *URL)
{
- CURL *c;
+ CURL *c = NULL;
CURLM *m = NULL;
int res = 0;
- int running=1;
+ int running = 1;
double connect_time = 0.0;
- struct timeval mp_start;
- char mp_timedout = FALSE;
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
- return TEST_ERR_MAJOR_BAD;
- }
+ start_test_timing();
- if ((c = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ global_init(CURL_GLOBAL_ALL);
- test_setopt(c, CURLOPT_HEADER, 1L);
- test_setopt(c, CURLOPT_URL, URL);
+ easy_init(c);
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_setopt(c, CURLOPT_HEADER, 1L);
+ easy_setopt(c, CURLOPT_URL, URL);
- if ((res = (int)curl_multi_add_handle(m, c)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(c);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(m);
- mp_timedout = FALSE;
- mp_start = tutil_tvnow();
+ multi_add_handle(m, c);
while (running) {
- res = (int)curl_multi_perform(m, &running);
- if (tutil_tvdiff(tutil_tvnow(), mp_start) >
- MULTI_PERFORM_HANG_TIMEOUT) {
- mp_timedout = TRUE;
- break;
- }
- if (running <= 0) {
- fprintf(stderr, "nothing left running.\n");
- break;
- }
- }
+ struct timeval timeout;
+ fd_set fdread, fdwrite, fdexcep;
+ int maxfd = -99;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000L; /* 100 ms */
+
+ multi_perform(m, &running);
- if (mp_timedout) {
- if (mp_timedout) fprintf(stderr, "mp_timedout\n");
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
+ abort_on_test_timeout();
+
+ if(!running)
+ break; /* done */
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+
+ multi_fdset(m, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ abort_on_test_timeout();
}
curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time);
@@ -103,10 +88,10 @@ int test(char *URL)
test_cleanup:
- if(m) {
- curl_multi_remove_handle(m, c);
- curl_multi_cleanup(m);
- }
+ /* proper cleanup sequence - type PA */
+
+ curl_multi_remove_handle(m, c);
+ curl_multi_cleanup(m);
curl_easy_cleanup(c);
curl_global_cleanup();
diff --git a/tests/libtest/lib574.c b/tests/libtest/lib574.c
index 8c5781609..afb2bceae 100644
--- a/tests/libtest/lib574.c
+++ b/tests/libtest/lib574.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#include "memdebug.h"
diff --git a/tests/libtest/lib575.c b/tests/libtest/lib575.c
index 4d0b16576..942df68c5 100644
--- a/tests/libtest/lib575.c
+++ b/tests/libtest/lib575.c
@@ -19,17 +19,16 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
+#define TEST_HANG_TIMEOUT 60 * 1000
+
/* 3x download!
* 1. normal
* 2. dup handle
@@ -38,26 +37,21 @@
int test(char *URL)
{
- CURLMcode m;
- CURL *handle = NULL, *duphandle;
+ CURL *handle = NULL;
+ CURL *duphandle = NULL;
CURLM *mhandle = NULL;
int res = 0;
int still_running = 0;
- if(curl_global_init(CURL_GLOBAL_ALL)) {
- fprintf(stderr, "curl_global_init() failed\n");
- goto test_cleanup;
- }
+ start_test_timing();
- handle = curl_easy_init();
- if(!handle) {
- res = CURLE_OUT_OF_MEMORY;
- goto test_cleanup;
- }
+ global_init(CURL_GLOBAL_ALL);
- test_setopt(handle, CURLOPT_URL, URL);
- test_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
- test_setopt(handle, CURLOPT_VERBOSE, 1L);
+ easy_init(handle);
+
+ easy_setopt(handle, CURLOPT_URL, URL);
+ easy_setopt(handle, CURLOPT_WILDCARDMATCH, 1L);
+ easy_setopt(handle, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(handle);
if(res)
@@ -73,51 +67,48 @@ int test(char *URL)
curl_easy_cleanup(handle);
handle = duphandle;
- mhandle = curl_multi_init();
- if(!mhandle) {
- fprintf(stderr, "curl_multi_init() failed\n");
- goto test_cleanup;
- }
+ multi_init(mhandle);
- curl_multi_add_handle(mhandle, handle);
+ multi_add_handle(mhandle, handle);
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(mhandle, &still_running));
+ multi_perform(mhandle, &still_running);
+
+ abort_on_test_timeout();
while(still_running) {
- static struct timeval timeout = /* 100 ms */ { 0, 100000L };
- int rc;
+ struct timeval timeout;
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
- int max_fdset = -1;
+ int maxfd = -99;
+
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 100000L; /* 100 ms */
+
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);
- m = curl_multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &max_fdset);
- if(m != CURLM_OK) {
- fprintf(stderr, "curl_multi_fdset() error\n");
- goto test_cleanup;
- }
- /* We call select(max_fdset + 1, ...), specially in case of (maxfd == -1),
- * we call select(0, ...), which is basically equal to sleep. */
- rc = select(max_fdset + 1, &fdread, &fdwrite, &fdexcep, &timeout);
- if(rc == -1) {
- fprintf(stderr, "select() error\n");
- goto test_cleanup;
- }
- else {
- while(CURLM_CALL_MULTI_PERFORM ==
- curl_multi_perform(mhandle, &still_running));
- }
+ multi_fdset(mhandle, &fdread, &fdwrite, &fdexcep, &maxfd);
+
+ /* At this point, maxfd is guaranteed to be greater or equal than -1. */
+
+ select_test(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ abort_on_test_timeout();
+
+ multi_perform(mhandle, &still_running);
+
+ abort_on_test_timeout();
}
test_cleanup:
- if(mhandle)
- curl_multi_cleanup(mhandle);
- if(handle)
- curl_easy_cleanup(handle);
+
+ /* undocumented cleanup sequence - type UA */
+
+ curl_multi_cleanup(mhandle);
+ curl_easy_cleanup(handle);
curl_global_cleanup();
+
return res;
}
diff --git a/tests/libtest/lib576.c b/tests/libtest/lib576.c
index 48841b59d..61bb61325 100644
--- a/tests/libtest/lib576.c
+++ b/tests/libtest/lib576.c
@@ -19,8 +19,8 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
+
#include "testutil.h"
#include "memdebug.h"
diff --git a/tests/libtest/lib578.c b/tests/libtest/lib578.c
index 51ead8722..a39b31772 100644
--- a/tests/libtest/lib578.c
+++ b/tests/libtest/lib578.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#include "memdebug.h"
diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c
index ad8ba7e97..56193a181 100644
--- a/tests/libtest/lib579.c
+++ b/tests/libtest/lib579.c
@@ -19,7 +19,6 @@
* KIND, either express or implied.
*
***************************************************************************/
-
#include "test.h"
#include "memdebug.h"
diff --git a/tests/libtest/lib582.c b/tests/libtest/lib582.c
index 3b7f1afee..25b70609c 100644
--- a/tests/libtest/lib582.c
+++ b/tests/libtest/lib582.c
@@ -21,20 +21,19 @@
***************************************************************************/
#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
#include <fcntl.h>
#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"
-#define MAIN_LOOP_HANG_TIMEOUT 4 * 1000
+#define TEST_HANG_TIMEOUT 60 * 1000
struct Sockets
{
- curl_socket_t* sockets;
- int count;
+ curl_socket_t *sockets;
+ int count; /* number of sockets actually stored in array */
+ int max_count; /* max number of sockets that fit in allocated array */
};
struct ReadWriteSockets
@@ -54,8 +53,9 @@ static void removeFd(struct Sockets* sockets, curl_socket_t fd, int mention)
for (i = 0; i < sockets->count; ++i) {
if (sockets->sockets[i] == fd) {
- memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
- sizeof(curl_socket_t) * (sockets->count - i - 1));
+ if (i < sockets->count - 1)
+ memmove(&sockets->sockets[i], &sockets->sockets[i + 1],
+ sizeof(curl_socket_t) * (sockets->count - (i + 1)));
--sockets->count;
}
}
@@ -72,8 +72,29 @@ static void addFd(struct Sockets* sockets, curl_socket_t fd, const char *what)
*/
fprintf(stderr, "Add socket fd %d for %s\n", (int) fd, what);
removeFd(sockets, fd, 0);
- sockets->sockets = realloc(sockets->sockets,
- sizeof(curl_socket_t) * (sockets->count + 1));
+ /*
+ * Allocate array storage when required.
+ */
+ if(!sockets->sockets) {
+ sockets->sockets = malloc(sizeof(curl_socket_t) * 20U);
+ if(!sockets->sockets)
+ return;
+ sockets->max_count = 20;
+ }
+ else if(sockets->count + 1 > sockets->max_count) {
+ curl_socket_t *oldptr = sockets->sockets;
+ sockets->sockets = realloc(oldptr, sizeof(curl_socket_t) *
+ (sockets->max_count + 20));
+ if(!sockets->sockets) {
+ /* cleanup in test_cleanup */
+ sockets->sockets = oldptr;
+ return;
+ }
+ sockets->max_count += 20;
+ }
+ /*
+ * Add file descriptor to array.
+ */
sockets->sockets[sockets->count] = fd;
++sockets->count;
}
@@ -177,13 +198,12 @@ static void updateFdSet(struct Sockets* sockets, fd_set* fdset,
}
}
-static void notifyCurl(CURL* curl, curl_socket_t s, int evBitmask,
- const char* info)
+static void notifyCurl(CURLM *curl, curl_socket_t s, int evBitmask,
+ const char *info)
{
int numhandles = 0;
CURLMcode result = curl_multi_socket_action(curl, s, evBitmask, &numhandles);
- if (result != CURLM_OK && result != CURLM_CALL_MULTI_PERFORM)
- {
+ if (result != CURLM_OK) {
fprintf(stderr, "Curl error on %s: %i (%s)\n",
info, result, curl_multi_strerror(result));
}
@@ -192,14 +212,12 @@ static void notifyCurl(CURL* curl, curl_socket_t s, int evBitmask,
/**
* Invoke curl when a file descriptor is set.
*/
-static void checkFdSet(CURL* curl, struct Sockets* sockets, fd_set* fdset,
- int evBitmask, const char* name)
+static void checkFdSet(CURLM *curl, struct Sockets *sockets, fd_set *fdset,
+ int evBitmask, const char *name)
{
int i;
- for (i = 0; i < sockets->count; ++i)
- {
- if (FD_ISSET(sockets->sockets[i], fdset))
- {
+ for (i = 0; i < sockets->count; ++i) {
+ if (FD_ISSET(sockets->sockets[i], fdset)) {
notifyCurl(curl, sockets->sockets[i], evBitmask, name);
}
}
@@ -208,30 +226,30 @@ static void checkFdSet(CURL* curl, struct Sockets* sockets, fd_set* fdset,
int test(char *URL)
{
int res = 0;
- CURL *curl;
- FILE *hd_src ;
+ CURL *curl = NULL;
+ FILE *hd_src = NULL;
int hd ;
int error;
struct_stat file_info;
CURLM *m = NULL;
- struct timeval ml_start;
- char ml_timedout = FALSE;
- struct ReadWriteSockets sockets = {{0, 0}, {0, 0}};
+ struct ReadWriteSockets sockets = {{NULL, 0, 0}, {NULL, 0, 0}};
struct timeval timeout = {-1, 0};
int success = 0;
+ start_test_timing();
+
if (!libtest_arg3) {
fprintf(stderr, "Usage: lib582 [url] [filename] [username]\n");
- return -1;
+ return TEST_ERR_USAGE;
}
hd_src = fopen(libtest_arg2, "rb");
if(NULL == hd_src) {
error = ERRNO;
- fprintf(stderr, "fopen() failed with error: %d %s\n",
+ fprintf(stderr, "fopen() failed with error: %d (%s)\n",
error, strerror(error));
- fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
- return TEST_ERR_MAJOR_BAD;
+ fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
+ return TEST_ERR_FOPEN;
}
/* get the file size of the local file */
@@ -239,71 +257,49 @@ int test(char *URL)
if(hd == -1) {
/* can't open file, bail out */
error = ERRNO;
- fprintf(stderr, "fstat() failed with error: %d %s\n",
+ fprintf(stderr, "fstat() failed with error: %d (%s)\n",
error, strerror(error));
- fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
+ fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
fclose(hd_src);
- return -1;
+ return TEST_ERR_FSTAT;
}
fprintf(stderr, "Set to upload %d bytes\n", (int)file_info.st_size);
- if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
- fprintf(stderr, "curl_global_init() failed\n");
+ res_global_init(CURL_GLOBAL_ALL);
+ if(res) {
fclose(hd_src);
- return TEST_ERR_MAJOR_BAD;
+ return res;
}
- if ((curl = curl_easy_init()) == NULL) {
- fprintf(stderr, "curl_easy_init() failed\n");
- fclose(hd_src);
- curl_global_cleanup();
- return TEST_ERR_MAJOR_BAD;
- }
+ easy_init(curl);
/* enable uploading */
- test_setopt(curl, CURLOPT_UPLOAD, 1L);
+ easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
- test_setopt(curl,CURLOPT_URL, URL);
+ easy_setopt(curl,CURLOPT_URL, URL);
/* go verbose */
- test_setopt(curl, CURLOPT_VERBOSE, 1L);
+ easy_setopt(curl, CURLOPT_VERBOSE, 1L);
/* now specify which file to upload */
- test_setopt(curl, CURLOPT_READDATA, hd_src);
+ easy_setopt(curl, CURLOPT_READDATA, hd_src);
- test_setopt(curl, CURLOPT_USERPWD, libtest_arg3);
- test_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub");
- test_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key");
+ easy_setopt(curl, CURLOPT_USERPWD, libtest_arg3);
+ easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub");
+ easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key");
- test_setopt(curl, CURLOPT_INFILESIZE_LARGE,
- (curl_off_t)file_info.st_size);
+ easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
- if ((m = curl_multi_init()) == NULL) {
- fprintf(stderr, "curl_multi_init() failed\n");
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- fclose(hd_src);
- return TEST_ERR_MAJOR_BAD;
- }
- test_multi_setopt(m, CURLMOPT_SOCKETFUNCTION, curlSocketCallback);
- test_multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets);
-
- test_multi_setopt(m, CURLMOPT_TIMERFUNCTION, curlTimerCallback);
- test_multi_setopt(m, CURLMOPT_TIMERDATA, &timeout);
-
- if ((res = (int)curl_multi_add_handle(m, curl)) != CURLM_OK) {
- fprintf(stderr, "curl_multi_add_handle() failed, "
- "with code %d\n", res);
- curl_multi_cleanup(m);
- curl_easy_cleanup(curl);
- curl_global_cleanup();
- fclose(hd_src);
- return TEST_ERR_MAJOR_BAD;
- }
+ multi_init(m);
+
+ multi_setopt(m, CURLMOPT_SOCKETFUNCTION, curlSocketCallback);
+ multi_setopt(m, CURLMOPT_SOCKETDATA, &sockets);
+
+ multi_setopt(m, CURLMOPT_TIMERFUNCTION, curlTimerCallback);
+ multi_setopt(m, CURLMOPT_TIMERDATA, &timeout);
- ml_timedout = FALSE;
- ml_start = tutil_tvnow();
+ multi_add_handle(m, curl);
while (!checkForCompletion(m, &success))
{
@@ -311,12 +307,6 @@ int test(char *URL)
curl_socket_t maxFd = 0;
struct timeval tv = {10, 0};
- if (tutil_tvdiff(tutil_tvnow(), ml_start) >
- MAIN_LOOP_HANG_TIMEOUT) {
- ml_timedout = TRUE;
- break;
- }
-
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
updateFdSet(&sockets.read, &readSet, &maxFd);
@@ -345,6 +335,8 @@ int test(char *URL)
/* Curl's timer has elapsed. */
notifyCurl(m, CURL_SOCKET_TIMEOUT, 0, "timeout");
}
+
+ abort_on_test_timeout();
}
if (!success)
@@ -352,28 +344,24 @@ int test(char *URL)
fprintf(stderr, "Error uploading file.\n");
res = TEST_ERR_MAJOR_BAD;
}
- else if (ml_timedout) {
- fprintf(stderr, "ABORTING TEST, since it seems "
- "that it would have run forever.\n");
- res = TEST_ERR_RUNS_FOREVER;
- }
test_cleanup:
- if(m)
- curl_multi_remove_handle(m, curl);
+ /* proper cleanup sequence - type PB */
+
+ curl_multi_remove_handle(m, curl);
curl_easy_cleanup(curl);
- if(m) {
- fprintf(stderr, "Now multi-cleanup!\n");
- curl_multi_cleanup(m);
- }
+ curl_multi_cleanup(m);
+ curl_global_cleanup();
+
+ /* close the local file */
+ fclose(hd_src);
- fclose(hd_src); /* close the local file */
- if (sockets.read.sockets != 0)
+ /* free local memory */
+ if(sockets.read.sockets)
free(sockets.read.sockets);
- if (sockets.write.sockets != 0)
+ if(sockets.write.sockets)
free(sockets.write.sockets);
- curl_global_cleanup();
return res;
}
diff --git a/tests/libtest/lib583.c b/tests/libtest/lib583.c
index f1270e1d3..ad5a5cea7 100644
--- a/tests/libtest/lib583.c
+++ b/tests/libtest/lib583.c
@@ -26,48 +26,59 @@
#include "test.h"
-#include <unistd.h>
#include <sys/stat.h>
+#include "memdebug.h"
+
int test(char *URL)
{
- CURLMcode retVal;
int stillRunning;
- CURLM* multiHandle;
- CURL* curl;
- int res;
+ CURLM* multiHandle = NULL;
+ CURL* curl = NULL;
+ int res = 0;
+
+ global_init(CURL_GLOBAL_ALL);
+
+ multi_init(multiHandle);
+
+ easy_init(curl);
- curl_global_init(CURL_GLOBAL_ALL);
+ easy_setopt(curl, CURLOPT_USERPWD, libtest_arg2);
+ easy_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub");
+ easy_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key");
- multiHandle = curl_multi_init();
- curl = curl_easy_init();
+ easy_setopt(curl, CURLOPT_UPLOAD, 1L);
+ easy_setopt(curl, CURLOPT_VERBOSE, 1L);
- test_setopt(curl, CURLOPT_USERPWD, libtest_arg2);
- test_setopt(curl, CURLOPT_SSH_PUBLIC_KEYFILE, "curl_client_key.pub");
- test_setopt(curl, CURLOPT_SSH_PRIVATE_KEYFILE, "curl_client_key");
+ easy_setopt(curl, CURLOPT_URL, URL);
+ easy_setopt(curl, CURLOPT_INFILESIZE, (long)5);
- curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+ multi_add_handle(multiHandle, curl);
- curl_easy_setopt(curl, CURLOPT_URL, URL);
- curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)5);
+ /* this tests if removing an easy handle immediately after multi
+ perform has been called succeeds or not. */
- curl_multi_add_handle(multiHandle, curl);
- retVal = curl_multi_perform(multiHandle, &stillRunning);
- if (retVal != CURLM_OK)
- fprintf(stderr, "curl_multi_perform() failed!n");
+ fprintf(stderr, "curl_multi_perform()...\n");
- fprintf(stderr, "curl_multi_remove_handle()!\n");
- retVal = curl_multi_remove_handle(multiHandle, curl);
- if (retVal == CURLM_OK)
- fprintf(stderr, "curl_multi_remove_handle() was successful!\n");
+ multi_perform(multiHandle, &stillRunning);
+
+ fprintf(stderr, "curl_multi_perform() succeeded\n");
+
+ fprintf(stderr, "curl_multi_remove_handle()...\n");
+ res = (int) curl_multi_remove_handle(multiHandle, curl);
+ if(res)
+ fprintf(stderr, "curl_multi_remove_handle() failed, "
+ "with code %d\n", res);
else
- fprintf(stderr, "curl_multi_remove_handle() failed\n");
+ fprintf(stderr, "curl_multi_remove_handle() succeeded\n");
test_cleanup:
+ /* undocumented cleanup sequence - type UB */
+
curl_easy_cleanup(curl);
curl_multi_cleanup(multiHandle);
+ curl_global_cleanup();
return res;
}
diff --git a/tests/libtest/lib586.c b/tests/libtest/lib586.c
new file mode 100644
index 000000000..2cf04fe85
--- /dev/null
+++ b/tests/libtest/lib586.c
@@ -0,0 +1,246 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include <curl/mprintf.h>
+
+#include "memdebug.h"
+
+#define THREADS 2
+
+/* struct containing data of a thread */
+struct Tdata {
+ CURLSH *share;
+ char *url;
+};
+
+struct userdata {
+ char *text;
+ int counter;
+};
+
+/* lock callback */
+static void my_lock(CURL *handle, curl_lock_data data, curl_lock_access laccess,
+ void *useptr )
+{
+ const char *what;
+ struct userdata *user = (struct userdata *)useptr;
+
+ (void)handle;
+ (void)laccess;
+
+ switch ( data ) {
+ case CURL_LOCK_DATA_SHARE:
+ what = "share";
+ break;
+ case CURL_LOCK_DATA_DNS:
+ what = "dns";
+ break;
+ case CURL_LOCK_DATA_COOKIE:
+ what = "cookie";
+ break;
+ case CURL_LOCK_DATA_SSL_SESSION:
+ what = "ssl_session";
+ break;
+ default:
+ fprintf(stderr, "lock: no such data: %d\n", (int)data);
+ return;
+ }
+ printf("lock: %-6s [%s]: %d\n", what, user->text, user->counter);
+ user->counter++;
+}
+
+/* unlock callback */
+static void my_unlock(CURL *handle, curl_lock_data data, void *useptr )
+{
+ const char *what;
+ struct userdata *user = (struct userdata *)useptr;
+ (void)handle;
+ switch ( data ) {
+ case CURL_LOCK_DATA_SHARE:
+ what = "share";
+ break;
+ case CURL_LOCK_DATA_DNS:
+ what = "dns";
+ break;
+ case CURL_LOCK_DATA_COOKIE:
+ what = "cookie";
+ break;
+ case CURL_LOCK_DATA_SSL_SESSION:
+ what = "ssl_session";
+ break;
+ default:
+ fprintf(stderr, "unlock: no such data: %d\n", (int)data);
+ return;
+ }
+ printf("unlock: %-6s [%s]: %d\n", what, user->text, user->counter);
+ user->counter++;
+}
+
+/* the dummy thread function */
+static void *fire(void *ptr)
+{
+ CURLcode code;
+ struct Tdata *tdata = (struct Tdata*)ptr;
+ CURL *curl;
+ int i=0;
+
+ if ((curl = curl_easy_init()) == NULL) {
+ fprintf(stderr, "curl_easy_init() failed\n");
+ return NULL;
+ }
+
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt(curl, CURLOPT_URL, tdata->url);
+ printf( "CURLOPT_SHARE\n" );
+ curl_easy_setopt(curl, CURLOPT_SHARE, tdata->share);
+
+ printf( "PERFORM\n" );
+ code = curl_easy_perform(curl);
+ if( code != CURLE_OK ) {
+ fprintf(stderr, "perform url '%s' repeat %d failed, curlcode %d\n",
+ tdata->url, i, (int)code);
+ }
+
+ printf( "CLEANUP\n" );
+ curl_easy_cleanup(curl);
+
+ return NULL;
+}
+
+/* test function */
+int test(char *URL)
+{
+ int res;
+ CURLSHcode scode = CURLSHE_OK;
+ char *url;
+ struct Tdata tdata;
+ CURL *curl;
+ CURLSH *share;
+ int i;
+ struct userdata user;
+
+ user.text = (char *)"Pigs in space";
+ user.counter = 0;
+
+ printf( "GLOBAL_INIT\n" );
+ if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+ fprintf(stderr, "curl_global_init() failed\n");
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ /* prepare share */
+ printf( "SHARE_INIT\n" );
+ if ((share = curl_share_init()) == NULL) {
+ fprintf(stderr, "curl_share_init() failed\n");
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ if ( CURLSHE_OK == scode ) {
+ printf( "CURLSHOPT_LOCKFUNC\n" );
+ scode = curl_share_setopt( share, CURLSHOPT_LOCKFUNC, my_lock);
+ }
+ if ( CURLSHE_OK == scode ) {
+ printf( "CURLSHOPT_UNLOCKFUNC\n" );
+ scode = curl_share_setopt( share, CURLSHOPT_UNLOCKFUNC, my_unlock);
+ }
+ if ( CURLSHE_OK == scode ) {
+ printf( "CURLSHOPT_USERDATA\n" );
+ scode = curl_share_setopt( share, CURLSHOPT_USERDATA, &user);
+ }
+ if ( CURLSHE_OK == scode ) {
+ printf( "CURL_LOCK_DATA_SSL_SESSION\n" );
+ scode = curl_share_setopt( share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
+ }
+
+ if ( CURLSHE_OK != scode ) {
+ fprintf(stderr, "curl_share_setopt() failed\n");
+ curl_share_cleanup(share);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+
+ res = 0;
+
+ /* start treads */
+ for (i=1; i<=THREADS; i++ ) {
+
+ /* set thread data */
+ tdata.url = URL;
+ tdata.share = share;
+
+ /* simulate thread, direct call of "thread" function */
+ printf( "*** run %d\n",i );
+ fire( &tdata );
+ }
+
+
+ /* fetch a another one */
+ printf( "*** run %d\n", i );
+ if ((curl = curl_easy_init()) == NULL) {
+ fprintf(stderr, "curl_easy_init() failed\n");
+ curl_share_cleanup(share);
+ curl_global_cleanup();
+ return TEST_ERR_MAJOR_BAD;
+ }
+
+ url = URL;
+ test_setopt( curl, CURLOPT_URL, url );
+ printf( "CURLOPT_SHARE\n" );
+ test_setopt( curl, CURLOPT_SHARE, share );
+
+ printf( "PERFORM\n" );
+ curl_easy_perform( curl );
+
+ /* try to free share, expect to fail because share is in use*/
+ printf( "try SHARE_CLEANUP...\n" );
+ scode = curl_share_cleanup( share );
+ if ( scode==CURLSHE_OK )
+ {
+ fprintf(stderr, "curl_share_cleanup succeed but error expected\n");
+ share = NULL;
+ } else {
+ printf( "SHARE_CLEANUP failed, correct\n" );
+ }
+
+test_cleanup:
+
+ /* clean up last handle */
+ printf( "CLEANUP\n" );
+ curl_easy_cleanup( curl );
+
+ /* free share */
+ printf( "SHARE_CLEANUP\n" );
+ scode = curl_share_cleanup( share );
+ if ( scode!=CURLSHE_OK )
+ fprintf(stderr, "curl_share_cleanup failed, code errno %d\n",
+ (int)scode);
+
+ printf( "GLOBAL_CLEANUP\n" );
+ curl_global_cleanup();
+
+ return res;
+}
+
diff --git a/tests/libtest/test.h b/tests/libtest/test.h
index 33d7bed83..81c435d1f 100644
--- a/tests/libtest/test.h
+++ b/tests/libtest/test.h
@@ -33,7 +33,6 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <errno.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
@@ -51,9 +50,6 @@
# include "select.h"
#endif
-#define TEST_ERR_MAJOR_BAD 100
-#define TEST_ERR_RUNS_FOREVER 99
-
#define test_setopt(A,B,C) \
if((res = curl_easy_setopt((A),(B),(C))) != CURLE_OK) goto test_cleanup
@@ -67,8 +63,10 @@ extern char *libtest_arg3; /* set by first.c to the argv[3] or NULL */
extern int test_argc;
extern char **test_argv;
-extern int select_test(int num_fds, fd_set *rd, fd_set *wr, fd_set *exc,
- struct timeval *tv);
+extern struct timeval tv_test_start; /* for test timing */
+
+extern int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
+ struct timeval *tv);
extern int test(char *URL); /* the actual test function provided by each
individual libXXX.c file */
@@ -76,3 +74,331 @@ extern int test(char *URL); /* the actual test function provided by each
#ifdef UNITTESTS
extern int unitfail;
#endif
+
+/*
+** TEST_ERR_* values must be greater than CURL_LAST CURLcode in order
+** to avoid confusion with any CURLcode or CURLMcode. These TEST_ERR_*
+** codes are returned to signal test specific situations and should
+** not get mixed with CURLcode or CURLMcode values.
+**
+** For portability reasons TEST_ERR_* values should be less than 127.
+*/
+
+#define TEST_ERR_MAJOR_BAD 126
+#define TEST_ERR_RUNS_FOREVER 125
+#define TEST_ERR_EASY_INIT 124
+#define TEST_ERR_MULTI_INIT 123
+#define TEST_ERR_NUM_HANDLES 122
+#define TEST_ERR_SELECT 121
+#define TEST_ERR_SUCCESS 120
+#define TEST_ERR_FAILURE 119
+#define TEST_ERR_USAGE 118
+#define TEST_ERR_FOPEN 117
+#define TEST_ERR_FSTAT 116
+
+/*
+** Macros for test source code readability/maintainability.
+**
+** All of the following macros require that an int data type 'res' variable
+** exists in scope where macro is used, and that it has been initialized to
+** zero before the macro is used.
+**
+** exe_* and chk_* macros are helper macros not intended to be used from
+** outside of this header file. Arguments 'Y' and 'Z' of these represent
+** source code file and line number, while Arguments 'A', 'B', etc, are
+** the arguments used to actually call a libcurl function.
+**
+** All easy_* and multi_* macros call a libcurl function and evaluate if
+** the function has succeeded or failed. When the function succeeds 'res'
+** variable is not set nor cleared and program continues normal flow. On
+** the other hand if function fails 'res' variable is set and a jump to
+** label 'test_cleanup' is performed.
+**
+** Every easy_* and multi_* macros have a res_easy_* and res_multi_* macro
+** counterpart that operates in tha same way with the exception that no
+** jump takes place in case of failure. res_easy_* and res_multi_* macros
+** should be immediately followed by checking if 'res' variable has been
+** set.
+**
+** 'res' variable when set will hold a CURLcode, CURLMcode, or any of the
+** TEST_ERR_* values defined above. It is advisable to return this value
+** as test result.
+*/
+
+/* ---------------------------------------------------------------- */
+
+#define exe_easy_init(A,Y,Z) do { \
+ if(((A) = curl_easy_init()) == NULL) { \
+ fprintf(stderr, "%s:%d curl_easy_init() failed\n", (Y), (Z)); \
+ res = TEST_ERR_EASY_INIT; \
+ } \
+} WHILE_FALSE
+
+#define res_easy_init(A) \
+ exe_easy_init((A),(__FILE__),(__LINE__))
+
+#define chk_easy_init(A,Y,Z) do { \
+ exe_easy_init((A),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define easy_init(A) \
+ chk_easy_init((A),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_init(A,Y,Z) do { \
+ if(((A) = curl_multi_init()) == NULL) { \
+ fprintf(stderr, "%s:%d curl_multi_init() failed\n", (Y), (Z)); \
+ res = TEST_ERR_MULTI_INIT; \
+ } \
+} WHILE_FALSE
+
+#define res_multi_init(A) \
+ exe_multi_init((A),(__FILE__),(__LINE__))
+
+#define chk_multi_init(A,Y,Z) do { \
+ exe_multi_init((A),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define multi_init(A) \
+ chk_multi_init((A),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_easy_setopt(A,B,C,Y,Z) do { \
+ CURLcode ec; \
+ if((ec = curl_easy_setopt((A),(B),(C))) != CURLE_OK) { \
+ fprintf(stderr, "%s:%d curl_easy_setopt() failed, " \
+ "with code %d (%s)\n", \
+ (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
+ res = (int)ec; \
+ } \
+} WHILE_FALSE
+
+#define res_easy_setopt(A,B,C) \
+ exe_easy_setopt((A),(B),(C),(__FILE__),(__LINE__))
+
+#define chk_easy_setopt(A,B,C,Y,Z) do { \
+ exe_easy_setopt((A),(B),(C),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define easy_setopt(A,B,C) \
+ chk_easy_setopt((A),(B),(C),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_setopt(A,B,C,Y,Z) do { \
+ CURLMcode ec; \
+ if((ec = curl_multi_setopt((A),(B),(C))) != CURLM_OK) { \
+ fprintf(stderr, "%s:%d curl_multi_setopt() failed, " \
+ "with code %d (%s)\n", \
+ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
+ res = (int)ec; \
+ } \
+} WHILE_FALSE
+
+#define res_multi_setopt(A,B,C) \
+ exe_multi_setopt((A),(B),(C),(__FILE__),(__LINE__))
+
+#define chk_multi_setopt(A,B,C,Y,Z) do { \
+ exe_multi_setopt((A),(B),(C),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define multi_setopt(A,B,C) \
+ chk_multi_setopt((A),(B),(C),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_add_handle(A,B,Y,Z) do { \
+ CURLMcode ec; \
+ if((ec = curl_multi_add_handle((A),(B))) != CURLM_OK) { \
+ fprintf(stderr, "%s:%d curl_multi_add_handle() failed, " \
+ "with code %d (%s)\n", \
+ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
+ res = (int)ec; \
+ } \
+} WHILE_FALSE
+
+#define res_multi_add_handle(A,B) \
+ exe_multi_add_handle((A),(B),(__FILE__),(__LINE__))
+
+#define chk_multi_add_handle(A,B,Y,Z) do { \
+ exe_multi_add_handle((A),(B),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define multi_add_handle(A,B) \
+ chk_multi_add_handle((A),(B),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_perform(A,B,Y,Z) do { \
+ CURLMcode ec; \
+ if((ec = curl_multi_perform((A),(B))) != CURLM_OK) { \
+ fprintf(stderr, "%s:%d curl_multi_perform() failed, " \
+ "with code %d (%s)\n", \
+ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
+ res = (int)ec; \
+ } \
+ else if(*((B)) < 0) { \
+ fprintf(stderr, "%s:%d curl_multi_perform() succeeded, " \
+ "but returned invalid running_handles value (%d)\n", \
+ (Y), (Z), (int)*((B))); \
+ res = TEST_ERR_NUM_HANDLES; \
+ } \
+} WHILE_FALSE
+
+#define res_multi_perform(A,B) \
+ exe_multi_perform((A),(B),(__FILE__),(__LINE__))
+
+#define chk_multi_perform(A,B,Y,Z) do { \
+ exe_multi_perform((A),(B),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define multi_perform(A,B) \
+ chk_multi_perform((A),(B),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_fdset(A,B,C,D,E,Y,Z) do { \
+ CURLMcode ec; \
+ if((ec = curl_multi_fdset((A),(B),(C),(D),(E))) != CURLM_OK) { \
+ fprintf(stderr, "%s:%d curl_multi_fdset() failed, " \
+ "with code %d (%s)\n", \
+ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
+ res = (int)ec; \
+ } \
+ else if(*((E)) < -1) { \
+ fprintf(stderr, "%s:%d curl_multi_fdset() succeeded, " \
+ "but returned invalid max_fd value (%d)\n", \
+ (Y), (Z), (int)*((E))); \
+ res = TEST_ERR_NUM_HANDLES; \
+ } \
+} WHILE_FALSE
+
+#define res_multi_fdset(A,B,C,D,E) \
+ exe_multi_fdset((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
+
+#define chk_multi_fdset(A,B,C,D,E,Y,Z) do { \
+ exe_multi_fdset((A),(B),(C),(D),(E),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define multi_fdset(A,B,C,D,E) \
+ chk_multi_fdset((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_multi_timeout(A,B,Y,Z) do { \
+ CURLMcode ec; \
+ if((ec = curl_multi_timeout((A),(B))) != CURLM_OK) { \
+ fprintf(stderr, "%s:%d curl_multi_timeout() failed, " \
+ "with code %d (%s)\n", \
+ (Y), (Z), (int)ec, curl_multi_strerror(ec)); \
+ res = (int)ec; \
+ } \
+} WHILE_FALSE
+
+#define res_multi_timeout(A,B) \
+ exe_multi_timeout((A),(B),(__FILE__),(__LINE__))
+
+#define chk_multi_timeout(A,B,Y,Z) do { \
+ exe_multi_timeout((A),(B),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define multi_timeout(A,B) \
+ chk_multi_timeout((A),(B),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_select_test(A,B,C,D,E,Y,Z) do { \
+ int ec; \
+ if(select_wrapper((A),(B),(C),(D),(E)) == -1 ) { \
+ ec = SOCKERRNO; \
+ fprintf(stderr, "%s:%d select() failed, with " \
+ "errno %d (%s)\n", \
+ (Y), (Z), ec, strerror(ec)); \
+ res = TEST_ERR_SELECT; \
+ } \
+} WHILE_FALSE
+
+#define res_select_test(A,B,C,D,E) \
+ exe_select_test((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
+
+#define chk_select_test(A,B,C,D,E,Y,Z) do { \
+ exe_select_test((A),(B),(C),(D),(E),(Y),(Z)); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define select_test(A,B,C,D,E) \
+ chk_select_test((A),(B),(C),(D),(E),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define start_test_timing() do { \
+ tv_test_start = tutil_tvnow(); \
+} WHILE_FALSE
+
+#define exe_test_timedout(Y,Z) do { \
+ if(tutil_tvdiff(tutil_tvnow(), tv_test_start) > TEST_HANG_TIMEOUT) { \
+ fprintf(stderr, "%s:%d ABORTING TEST, since it seems " \
+ "that it would have run forever.\n", (Y), (Z)); \
+ res = TEST_ERR_RUNS_FOREVER; \
+ } \
+} WHILE_FALSE
+
+#define res_test_timedout() \
+ exe_test_timedout((__FILE__),(__LINE__))
+
+#define chk_test_timedout(Y,Z) do { \
+ exe_test_timedout(Y,Z); \
+ if(res) \
+ goto test_cleanup; \
+} WHILE_FALSE
+
+#define abort_on_test_timeout() \
+ chk_test_timedout((__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */
+
+#define exe_global_init(A,Y,Z) do { \
+ CURLcode ec; \
+ if((ec = curl_global_init((A))) != CURLE_OK) { \
+ fprintf(stderr, "%s:%d curl_global_init() failed, " \
+ "with code %d (%s)\n", \
+ (Y), (Z), (int)ec, curl_easy_strerror(ec)); \
+ res = (int)ec; \
+ } \
+} WHILE_FALSE
+
+#define res_global_init(A) \
+ exe_global_init((A),(__FILE__),(__LINE__))
+
+#define chk_global_init(A,Y,Z) do { \
+ exe_global_init((A),(Y),(Z)); \
+ if(res) \
+ return res; \
+} WHILE_FALSE
+
+/* global_init() is different than other macros. In case of
+ failure it 'return's instead of going to 'test_cleanup'. */
+
+#define global_init(A) \
+ chk_global_init((A),(__FILE__),(__LINE__))
+
+/* ---------------------------------------------------------------- */