From 629d2e34508838069db83e1082ce9e7f2c7b8ff8 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Fri, 21 Oct 2011 16:26:18 +0200 Subject: multi tests: OOM handling fixes Additionally, improved error checking and logging. --- tests/libtest/lib502.c | 100 ++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 67 deletions(-) (limited to 'tests/libtest/lib502.c') diff --git a/tests/libtest/lib502.c b/tests/libtest/lib502.c index e8bfe4744..554583ae2 100644 --- a/tests/libtest/lib502.c +++ b/tests/libtest/lib502.c @@ -25,8 +25,7 @@ #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,90 +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(); + multi_add_handle(m, c); - while (running) { - static struct timeval timeout = /* 100 ms */ { 0, 100000L }; + for(;;) { + struct timeval timeout; fd_set fdread, fdwrite, fdexcep; - int maxfd = -1; - - 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; - } + int maxfd = -99; + + timeout.tv_sec = 0; + timeout.tv_usec = 100000L; /* 100 ms */ + + multi_perform(m, &running); + + abort_on_test_timeout(); + + if(!running) + break; /* done */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); - curl_multi_fdset(m, &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. */ - - if (select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout) == -1) { - res = ~CURLM_OK; - break; - } - } - if (mp_timedout) { - fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems " - "that it would have run forever.\n"); - res = TEST_ERR_RUNS_FOREVER; + 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(); -- cgit v1.2.3