From adaf87530dc561314a2261fa6d26c38ce999876f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 7 May 2010 23:49:29 +0200 Subject: multi interface: missed storing connection time Dirk Manske reported a regression. When connecting with the multi interface, there were situations where libcurl wouldn't store connect time correctly as it used to (and is documented to) do. Using his fine sample program we could repeat it, and I wrote up test case 573 using that code. The problem does not easily show itself using the local test suite though. The fix, also as suggested by Dirk, is a bit on the ugly side as it adds yet another call to Curl_verboseconnect() and setting the TIMER_CONNECT time. That situation is subject for some closer inspection in the future. --- tests/libtest/lib573.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/libtest/lib573.c (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c new file mode 100644 index 000000000..e08b6df46 --- /dev/null +++ b/tests/libtest/lib573.c @@ -0,0 +1,102 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include "test.h" + +#include "testutil.h" +#include "memdebug.h" + +#define MAIN_LOOP_HANG_TIMEOUT 90 * 1000 +#define MULTI_PERFORM_HANG_TIMEOUT 60 * 1000 + +/* + * Get a single URL without select(). + */ + +int test(char *URL) +{ + CURL *c; + CURLM *m = NULL; + int res = 0; + int running=1; + long connect_time = 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; + } + + if ((c = curl_easy_init()) == NULL) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } + + test_setopt(c, CURLOPT_HEADER, 1L); + test_setopt(c, CURLOPT_URL, URL); + + 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; + } + + 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; + } + + 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; + } + } + + 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; + } + + curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time); + if (connect_time==0) { + fprintf(stderr, "connect time is 0\n"); + res = TEST_ERR_MAJOR_BAD; + } + +test_cleanup: + + if(m) { + curl_multi_remove_handle(m, c); + curl_multi_cleanup(m); + } + curl_easy_cleanup(c); + curl_global_cleanup(); + + return res; +} + -- cgit v1.2.1 From 22f3b01478246687386bfcaa97e07272c8868bf3 Mon Sep 17 00:00:00 2001 From: Tor Arntsen Date: Thu, 20 May 2010 16:33:29 +0200 Subject: Test 573: Use correct type for CURLINFO_CONNECT_TIME curl_easy_getinfo() called with a pointer to long instead of double would sigbus on RISC processors (e.g. MIPS) due to wrong alignment of pointer address. --- tests/libtest/lib573.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index e08b6df46..db5889e34 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -25,7 +25,7 @@ int test(char *URL) CURLM *m = NULL; int res = 0; int running=1; - long connect_time = 0; + double connect_time = 0.0; struct timeval mp_start; char mp_timedout = FALSE; @@ -83,8 +83,8 @@ int test(char *URL) } curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time); - if (connect_time==0) { - fprintf(stderr, "connect time is 0\n"); + if (connect_time==0.0) { + fprintf(stderr, "connect time is 0.0\n"); res = TEST_ERR_MAJOR_BAD; } -- cgit v1.2.1 From eadeb5bd9a6657c77477f58f3c0caa2de116d80e Mon Sep 17 00:00:00 2001 From: Tor Arntsen Date: Thu, 27 May 2010 20:20:08 +0200 Subject: lib573: do not compare double for exact match --- tests/libtest/lib573.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index db5889e34..5edb1814a 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -83,8 +83,8 @@ int test(char *URL) } curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time); - if (connect_time==0.0) { - fprintf(stderr, "connect time is 0.0\n"); + if (connect_time <= 0.0) { + fprintf(stderr, "connect time is <=0.0\n"); res = TEST_ERR_MAJOR_BAD; } -- cgit v1.2.1 From 1aeb635cdd296c16acb375a4a83a78f13166ccab Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 10 Mar 2011 11:48:02 +0100 Subject: sources: update source headers All C and H files now (should) feature the proper project curl source code header, which includes basic info, a copyright statement and some basic disclaimers. --- tests/libtest/lib573.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index 5edb1814a..466185844 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -1,11 +1,24 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - */ + * Copyright (C) 1998 - 2011, Daniel Stenberg, , 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" -- cgit v1.2.1 From 3445fa2e3f28b359a3acd2a884f4e119b11e0a57 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Fri, 26 Aug 2011 11:10:58 +0200 Subject: tests: break busy loops in tests 502, 555, and 573 --- tests/libtest/lib573.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index 466185844..b5fafe16e 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -76,6 +76,10 @@ int test(char *URL) mp_start = tutil_tvnow(); while (running) { + static struct timeval timeout = /* 100 ms */ { 0, 100000L }; + 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) { @@ -86,11 +90,26 @@ int test(char *URL) fprintf(stderr, "nothing left running.\n"); break; } + + 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) { - if (mp_timedout) fprintf(stderr, "mp_timedout\n"); - fprintf(stderr, "ABORTING TEST, since it seems " + fprintf(stderr, "mp_timedout\nABORTING TEST, since it seems " "that it would have run forever.\n"); res = TEST_ERR_RUNS_FOREVER; } -- cgit v1.2.1 From c8ba8740b9c3e7a5054c2d7ba5689778aa26618b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 6 Sep 2011 17:47:54 +0200 Subject: test suite: libtest header inclusion cleanup Added missing memoryTracking to test cases 560 and 583. If this triggers leak detection on these, it only means that previously it was going unnoticed. --- tests/libtest/lib573.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index b5fafe16e..1d8602e1f 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -19,10 +19,10 @@ * KIND, either express or implied. * ***************************************************************************/ - #include "test.h" #include "testutil.h" +#include "warnless.h" #include "memdebug.h" #define MAIN_LOOP_HANG_TIMEOUT 90 * 1000 -- cgit v1.2.1 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/lib573.c | 100 ++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 67 deletions(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index 1d8602e1f..943f6e8c8 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.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,84 +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) { - static struct timeval timeout = /* 100 ms */ { 0, 100000L }; + 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(); } curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time); @@ -122,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(); -- cgit v1.2.1 From c482e946f7ae003ce54ee05b5cca6d6ce8172f14 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Thu, 24 Nov 2011 18:18:42 +0100 Subject: lib573.c: fix double data type variable comparison with zero --- tests/libtest/lib573.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index 943f6e8c8..50aedfa6c 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -38,6 +38,12 @@ int test(char *URL) int res = 0; int running = 1; double connect_time = 0.0; + double dbl_epsilon; + + dbl_epsilon = 1.0; + do { + dbl_epsilon /= 2.0; + } while ((double)(1.0 + (dbl_epsilon/2.0)) > (double)1.0); start_test_timing(); @@ -81,8 +87,8 @@ int test(char *URL) } curl_easy_getinfo(c, CURLINFO_CONNECT_TIME, &connect_time); - if (connect_time <= 0.0) { - fprintf(stderr, "connect time is <=0.0\n"); + if (connect_time < dbl_epsilon) { + fprintf(stderr, "connect time is < epsilon\n"); res = TEST_ERR_MAJOR_BAD; } -- cgit v1.2.1 From 24526d0c0f4209eb77c807afdb15da301c7d021b Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 17 Jan 2012 21:33:17 +0100 Subject: tests: enable time tracing on tests 500, 573 and 585 --- tests/libtest/lib573.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests/libtest/lib573.c') diff --git a/tests/libtest/lib573.c b/tests/libtest/lib573.c index 50aedfa6c..b49d26a5d 100644 --- a/tests/libtest/lib573.c +++ b/tests/libtest/lib573.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2012, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -21,6 +21,7 @@ ***************************************************************************/ #include "test.h" +#include "testtrace.h" #include "testutil.h" #include "warnless.h" #include "memdebug.h" @@ -54,6 +55,12 @@ int test(char *URL) easy_setopt(c, CURLOPT_HEADER, 1L); easy_setopt(c, CURLOPT_URL, URL); + libtest_debug_config.nohex = 1; + libtest_debug_config.tracetime = 1; + easy_setopt(c, CURLOPT_DEBUGDATA, &libtest_debug_config); + easy_setopt(c, CURLOPT_DEBUGFUNCTION, libtest_debug_cb); + easy_setopt(c, CURLOPT_VERBOSE, 1L); + multi_init(m); multi_add_handle(m, c); -- cgit v1.2.1