From 2bee7aeb3433198870ead651d75884899b73205a Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 29 Sep 2023 16:32:48 -0700 Subject: [PATCH] tests: propagate errors in libtests Use the test macros to automatically propagate some errors, and check and log others while running the tests. This can help in debugging exactly why a test has failed. --- tests/data/test2306 | 8 ++++ tests/libtest/lib1510.c | 2 + tests/libtest/lib1512.c | 5 ++- tests/libtest/lib1518.c | 2 +- tests/libtest/lib1522.c | 4 +- tests/libtest/lib1533.c | 2 +- tests/libtest/lib1540.c | 6 +-- tests/libtest/lib1551.c | 6 ++- tests/libtest/lib1554.c | 19 +++++---- tests/libtest/lib1567.c | 13 ++++-- tests/libtest/lib1569.c | 23 ++++++----- tests/libtest/lib1903.c | 25 ++++++------ tests/libtest/lib1906.c | 43 ++++++++++++-------- tests/libtest/lib1907.c | 10 ++--- tests/libtest/lib1915.c | 57 ++++++++++++++------------- tests/libtest/lib1919.c | 35 +++++++++-------- tests/libtest/lib1940.c | 55 +++++++++++++------------- tests/libtest/lib1945.c | 42 ++++++++++---------- tests/libtest/lib1947.c | 87 +++++++++++++++++++++-------------------- tests/libtest/lib1948.c | 49 ++++++++++++----------- tests/libtest/lib2306.c | 18 +++++---- tests/libtest/lib519.c | 2 + tests/libtest/lib541.c | 4 +- tests/libtest/lib552.c | 1 - tests/libtest/lib586.c | 6 +-- tests/libtest/lib589.c | 2 + tests/libtest/lib677.c | 47 +++++++++++++--------- 27 files changed, 315 insertions(+), 258 deletions(-) diff --git a/tests/data/test2306 b/tests/data/test2306 index 620f7b5ecc..da2f25a213 100644 --- a/tests/data/test2306 +++ b/tests/data/test2306 @@ -54,6 +54,14 @@ http://%HOSTIP:%HTTPPORT/%TESTNUMBER http://%HOSTIP:%HTTPPORT/%TESTNUMBER0002 # # Verify data after the test has been "shot" +# hyper doesn't like the bad header in the second request + +%if hyper +1 +%else +0 +%endif + GET /%TESTNUMBER HTTP/1.1 Host: %HOSTIP:%HTTPPORT diff --git a/tests/libtest/lib1510.c b/tests/libtest/lib1510.c index 7b0e12ce94..927927e492 100644 --- a/tests/libtest/lib1510.c +++ b/tests/libtest/lib1510.c @@ -83,6 +83,8 @@ int test(char *URL) easy_setopt(curl, CURLOPT_URL, target_url); res = curl_easy_perform(curl); + if(res) + goto test_cleanup; abort_on_test_timeout(); } diff --git a/tests/libtest/lib1512.c b/tests/libtest/lib1512.c index 2ca0fe6205..6707819827 100644 --- a/tests/libtest/lib1512.c +++ b/tests/libtest/lib1512.c @@ -80,8 +80,11 @@ int test(char *URL) easy_setopt(curl[0], CURLOPT_RESOLVE, slist); /* run NUM_HANDLES transfers */ - for(i = 0; (i < NUM_HANDLES) && !res; i++) + for(i = 0; (i < NUM_HANDLES) && !res; i++) { res = curl_easy_perform(curl[i]); + if(res) + goto test_cleanup; + } test_cleanup: diff --git a/tests/libtest/lib1518.c b/tests/libtest/lib1518.c index 9805a2206b..aa0de41550 100644 --- a/tests/libtest/lib1518.c +++ b/tests/libtest/lib1518.c @@ -81,7 +81,7 @@ int test(char *URL) curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount); curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl); curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl); - res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb); + test_setopt(curl, CURLOPT_WRITEFUNCTION, writecb); printf("res %d\n" "status %d\n" diff --git a/tests/libtest/lib1522.c b/tests/libtest/lib1522.c index 1fbd7b92ce..f5e87e014f 100644 --- a/tests/libtest/lib1522.c +++ b/tests/libtest/lib1522.c @@ -51,7 +51,7 @@ static int sockopt_callback(void *clientp, curl_socket_t curlfd, int test(char *URL) { - CURLcode code; + CURLcode code = TEST_ERR_MAJOR_BAD; CURLcode res; struct curl_slist *pHeaderList = NULL; CURL *curl = curl_easy_init(); @@ -97,5 +97,5 @@ test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); - return 0; + return (int)code; } diff --git a/tests/libtest/lib1533.c b/tests/libtest/lib1533.c index 555fb962b5..0c9f8fa95a 100644 --- a/tests/libtest/lib1533.c +++ b/tests/libtest/lib1533.c @@ -106,7 +106,7 @@ static int perform_and_check_connections(CURL *curl, const char *description, res = curl_easy_perform(curl); if(res != CURLE_OK) { - fprintf(stderr, "curl_easy_perform() failed\n"); + fprintf(stderr, "curl_easy_perform() failed with %d\n", (int)res); return TEST_ERR_MAJOR_BAD; } diff --git a/tests/libtest/lib1540.c b/tests/libtest/lib1540.c index 8ea82a2634..4786e47928 100644 --- a/tests/libtest/lib1540.c +++ b/tests/libtest/lib1540.c @@ -84,7 +84,6 @@ static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp) int test(char *URL) { CURL *curls = NULL; - int i = 0; int res = 0; struct transfer_status st; @@ -114,8 +113,5 @@ test_cleanup: curl_easy_cleanup(curls); curl_global_cleanup(); - if(res) - i = res; - - return i; /* return the final return code */ + return (int)res; /* return the final return code */ } diff --git a/tests/libtest/lib1551.c b/tests/libtest/lib1551.c index f693cb1fd1..784113aaf3 100644 --- a/tests/libtest/lib1551.c +++ b/tests/libtest/lib1551.c @@ -39,11 +39,15 @@ int test(char *URL) curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); res = curl_easy_perform(curl); + if(res) + goto test_cleanup; fprintf(stderr, "****************************** Do it again\n"); res = curl_easy_perform(curl); - curl_easy_cleanup(curl); } + +test_cleanup: + curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } diff --git a/tests/libtest/lib1554.c b/tests/libtest/lib1554.c index b0e94b8fba..181044d057 100644 --- a/tests/libtest/lib1554.c +++ b/tests/libtest/lib1554.c @@ -46,7 +46,7 @@ static void my_unlock(CURL *handle, curl_lock_data data, void *useptr) int test(char *URL) { CURLcode res = CURLE_OK; - CURLSH *share; + CURLSH *share = NULL; int i; global_init(CURL_GLOBAL_ALL); @@ -54,8 +54,7 @@ int test(char *URL) share = curl_share_init(); if(!share) { fprintf(stderr, "curl_share_init() failed\n"); - curl_global_cleanup(); - return TEST_ERR_MAJOR_BAD; + goto test_cleanup; } curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT); @@ -75,18 +74,22 @@ int test(char *URL) /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); - /* Check for errors */ - if(res != CURLE_OK) - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(res)); /* always cleanup */ curl_easy_cleanup(curl); + + /* Check for errors */ + if(res != CURLE_OK) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); + goto test_cleanup; + } } } +test_cleanup: curl_share_cleanup(share); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1567.c b/tests/libtest/lib1567.c index 82f2f014ac..26b438dd09 100644 --- a/tests/libtest/lib1567.c +++ b/tests/libtest/lib1567.c @@ -29,26 +29,31 @@ int test(char *URL) { - CURL *curl; + CURL *curl = NULL; CURLcode res = CURLE_OK; + CURLU *u = NULL; global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { - CURLU *u = curl_url(); + u = curl_url(); if(u) { curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_url_set(u, CURLUPART_URL, URL, 0); curl_easy_setopt(curl, CURLOPT_CURLU, u); res = curl_easy_perform(curl); + if(res) + goto test_cleanup; fprintf(stderr, "****************************** Do it again\n"); res = curl_easy_perform(curl); - curl_url_cleanup(u); } - curl_easy_cleanup(curl); } + +test_cleanup: + curl_url_cleanup(u); + curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } diff --git a/tests/libtest/lib1569.c b/tests/libtest/lib1569.c index 941bcc26d4..e24a387e33 100644 --- a/tests/libtest/lib1569.c +++ b/tests/libtest/lib1569.c @@ -28,21 +28,24 @@ int test(char *URL) { - CURLcode ret; + CURLcode res = CURLE_OK; CURL *hnd; - curl_global_init(CURL_GLOBAL_ALL); + global_init(CURL_GLOBAL_ALL); - hnd = curl_easy_init(); - curl_easy_setopt(hnd, CURLOPT_URL, URL); - curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(hnd, CURLOPT_HEADER, 1L); + easy_init(hnd); + easy_setopt(hnd, CURLOPT_URL, URL); + easy_setopt(hnd, CURLOPT_VERBOSE, 1L); + easy_setopt(hnd, CURLOPT_HEADER, 1L); - ret = curl_easy_perform(hnd); + res = curl_easy_perform(hnd); + if(res) + goto test_cleanup; curl_easy_setopt(hnd, CURLOPT_URL, libtest_arg2); - ret = curl_easy_perform(hnd); - curl_easy_cleanup(hnd); + res = curl_easy_perform(hnd); +test_cleanup: + curl_easy_cleanup(hnd); curl_global_cleanup(); - return (int)ret; + return (int)res; } diff --git a/tests/libtest/lib1903.c b/tests/libtest/lib1903.c index 79baa17dd3..a8a767e5c0 100644 --- a/tests/libtest/lib1903.c +++ b/tests/libtest/lib1903.c @@ -30,26 +30,27 @@ int test(char *URL) { + CURLcode res = CURLE_OK; CURL *ch = NULL; - curl_global_init(CURL_GLOBAL_ALL); + global_init(CURL_GLOBAL_ALL); - ch = curl_easy_init(); - if(!ch) - goto cleanup; + easy_init(ch); - curl_easy_setopt(ch, CURLOPT_URL, URL); - curl_easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2); - curl_easy_perform(ch); + easy_setopt(ch, CURLOPT_URL, URL); + easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2); + res = curl_easy_perform(ch); + if(res) + goto test_cleanup; curl_easy_reset(ch); - curl_easy_setopt(ch, CURLOPT_URL, URL); - curl_easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2); - curl_easy_perform(ch); + easy_setopt(ch, CURLOPT_URL, URL); + easy_setopt(ch, CURLOPT_COOKIEFILE, libtest_arg2); + res = curl_easy_perform(ch); -cleanup: +test_cleanup: curl_easy_cleanup(ch); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1906.c b/tests/libtest/lib1906.c index c0d485f69e..02e8a31a72 100644 --- a/tests/libtest/lib1906.c +++ b/tests/libtest/lib1906.c @@ -29,46 +29,55 @@ int test(char *URL) { - char *url_after; + CURLcode res = CURLE_OK; + char *url_after = NULL; CURLU *curlu = curl_url(); - CURL *curl = curl_easy_init(); - CURLcode curl_code; char error_buffer[CURL_ERROR_SIZE] = ""; + CURL *curl; + + easy_init(curl); curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME); - curl_easy_setopt(curl, CURLOPT_CURLU, curlu); - curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + easy_setopt(curl, CURLOPT_CURLU, curlu); + easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer); + easy_setopt(curl, CURLOPT_VERBOSE, 1L); /* set a port number that makes this request fail */ - curl_easy_setopt(curl, CURLOPT_PORT, 1L); - curl_code = curl_easy_perform(curl); - if(!curl_code) + easy_setopt(curl, CURLOPT_PORT, 1L); + res = curl_easy_perform(curl); + if(res != CURLE_COULDNT_CONNECT && res != CURLE_OPERATION_TIMEDOUT) { fprintf(stderr, "failure expected, " - "curl_easy_perform returned %ld: <%s>, <%s>\n", - (long) curl_code, curl_easy_strerror(curl_code), error_buffer); + "curl_easy_perform returned %d: <%s>, <%s>\n", + (int) res, curl_easy_strerror(res), error_buffer); + if(res == CURLE_OK) + res = TEST_ERR_MAJOR_BAD; /* force an error return */ + goto test_cleanup; + } + res = CURLE_OK; /* reset for next use */ /* print the used url */ curl_url_get(curlu, CURLUPART_URL, &url_after, 0); fprintf(stderr, "curlu now: <%s>\n", url_after); curl_free(url_after); + url_after = NULL; /* now reset CURLOP_PORT to go back to originally set port number */ - curl_easy_setopt(curl, CURLOPT_PORT, 0L); + easy_setopt(curl, CURLOPT_PORT, 0L); - curl_code = curl_easy_perform(curl); - if(curl_code) + res = curl_easy_perform(curl); + if(res) fprintf(stderr, "success expected, " "curl_easy_perform returned %ld: <%s>, <%s>\n", - (long) curl_code, curl_easy_strerror(curl_code), error_buffer); + (long) res, curl_easy_strerror(res), error_buffer); /* print url */ curl_url_get(curlu, CURLUPART_URL, &url_after, 0); fprintf(stderr, "curlu now: <%s>\n", url_after); - curl_free(url_after); +test_cleanup: + curl_free(url_after); curl_easy_cleanup(curl); curl_url_cleanup(curlu); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1907.c b/tests/libtest/lib1907.c index d0876dc581..41cea379e0 100644 --- a/tests/libtest/lib1907.c +++ b/tests/libtest/lib1907.c @@ -31,7 +31,7 @@ int test(char *URL) { char *url_after; CURL *curl; - CURLcode curl_code; + CURLcode res = CURLE_OK; char error_buffer[CURL_ERROR_SIZE] = ""; curl_global_init(CURL_GLOBAL_DEFAULT); @@ -39,11 +39,11 @@ int test(char *URL) curl_easy_setopt(curl, CURLOPT_URL, URL); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - curl_code = curl_easy_perform(curl); - if(!curl_code) + res = curl_easy_perform(curl); + if(!res) fprintf(stderr, "failure expected, " "curl_easy_perform returned %ld: <%s>, <%s>\n", - (long) curl_code, curl_easy_strerror(curl_code), error_buffer); + (long) res, curl_easy_strerror(res), error_buffer); /* print the used url */ if(!curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url_after)) @@ -52,5 +52,5 @@ int test(char *URL) curl_easy_cleanup(curl); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1915.c b/tests/libtest/lib1915.c index 290212fdcc..0672c70d64 100644 --- a/tests/libtest/lib1915.c +++ b/tests/libtest/lib1915.c @@ -98,36 +98,39 @@ static CURLSTScode hstswrite(CURL *easy, struct curl_hstsentry *e, int test(char *URL) { - CURLcode ret = CURLE_OK; + CURLcode res = CURLE_OK; CURL *hnd; struct state st = {0}; - curl_global_init(CURL_GLOBAL_ALL); + global_init(CURL_GLOBAL_ALL); - hnd = curl_easy_init(); - if(hnd) { - curl_easy_setopt(hnd, CURLOPT_URL, URL); - curl_easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsread); - curl_easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st); - curl_easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite); - curl_easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st); - curl_easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE); - ret = curl_easy_perform(hnd); - curl_easy_cleanup(hnd); - printf("First request returned %d\n", (int)ret); - } - hnd = curl_easy_init(); - if(hnd) { - curl_easy_setopt(hnd, CURLOPT_URL, URL); - curl_easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsreadfail); - curl_easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st); - curl_easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite); - curl_easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st); - curl_easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE); - ret = curl_easy_perform(hnd); - curl_easy_cleanup(hnd); - printf("Second request returned %d\n", (int)ret); - } + easy_init(hnd); + easy_setopt(hnd, CURLOPT_URL, URL); + easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsread); + easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st); + easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite); + easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st); + easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE); + res = curl_easy_perform(hnd); + curl_easy_cleanup(hnd); + hnd = NULL; + printf("First request returned %d\n", (int)res); + res = CURLE_OK; + + easy_init(hnd); + easy_setopt(hnd, CURLOPT_URL, URL); + easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsreadfail); + easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st); + easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite); + easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st); + easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE); + res = curl_easy_perform(hnd); + curl_easy_cleanup(hnd); + hnd = NULL; + printf("Second request returned %d\n", (int)res); + +test_cleanup: + curl_easy_cleanup(hnd); curl_global_cleanup(); - return (int)ret; + return (int)res; } diff --git a/tests/libtest/lib1919.c b/tests/libtest/lib1919.c index 39ba1d96c4..37457c0682 100644 --- a/tests/libtest/lib1919.c +++ b/tests/libtest/lib1919.c @@ -29,25 +29,28 @@ int test(char *URL) { + CURLcode res = CURLE_OK; CURL *curl; - curl_global_init(CURL_GLOBAL_ALL); + int i; - curl = curl_easy_init(); - if(curl) { - int i; - curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER); - curl_easy_setopt(curl, CURLOPT_XOAUTH2_BEARER, - "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca1"); - curl_easy_setopt(curl, CURLOPT_SASL_AUTHZID, - "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca2"); - curl_easy_setopt(curl, CURLOPT_URL, URL); + global_init(CURL_GLOBAL_ALL); + easy_init(curl); + easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_BEARER); + easy_setopt(curl, CURLOPT_XOAUTH2_BEARER, + "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca1"); + easy_setopt(curl, CURLOPT_SASL_AUTHZID, + "c4e448d652a961fda0ab64f882c8c161d5985f805d45d80c9ddca2"); + easy_setopt(curl, CURLOPT_URL, URL); - for(i = 0; i < 2; i++) - /* the second request needs to do connection reuse */ - curl_easy_perform(curl); - - curl_easy_cleanup(curl); + for(i = 0; i < 2; i++) { + /* the second request needs to do connection reuse */ + res = curl_easy_perform(curl); + if(res) + goto test_cleanup; } + +test_cleanup: + curl_easy_cleanup(curl); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1940.c b/tests/libtest/lib1940.c index 5e90f6a366..8bc0943621 100644 --- a/tests/libtest/lib1940.c +++ b/tests/libtest/lib1940.c @@ -83,37 +83,36 @@ static size_t write_cb(char *data, size_t n, size_t l, void *userp) } int test(char *URL) { - CURL *easy; + CURL *easy = NULL; + CURLcode res = CURLE_OK; - curl_global_init(CURL_GLOBAL_DEFAULT); + global_init(CURL_GLOBAL_DEFAULT); + easy_init(easy); + easy_setopt(easy, CURLOPT_URL, URL); + easy_setopt(easy, CURLOPT_VERBOSE, 1L); + easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); + /* ignores any content */ + easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb); - easy = curl_easy_init(); - if(easy) { - CURLcode res; - curl_easy_setopt(easy, CURLOPT_URL, URL); - curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); - /* ignores any content */ - curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb); + /* if there's a proxy set, use it */ + if(libtest_arg2 && *libtest_arg2) { + easy_setopt(easy, CURLOPT_PROXY, libtest_arg2); + easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L); + } + res = curl_easy_perform(easy); + if(res) + goto test_cleanup; - /* if there's a proxy set, use it */ - if(libtest_arg2 && *libtest_arg2) { - curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2); - curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L); - } - res = curl_easy_perform(easy); - if(res) { - printf("badness: %d\n", (int)res); - } - showem(easy, CURLH_HEADER); - if(libtest_arg2 && *libtest_arg2) { - /* now show connect headers only */ - showem(easy, CURLH_CONNECT); - } - showem(easy, CURLH_1XX); - showem(easy, CURLH_TRAILER); - curl_easy_cleanup(easy); + showem(easy, CURLH_HEADER); + if(libtest_arg2 && *libtest_arg2) { + /* now show connect headers only */ + showem(easy, CURLH_CONNECT); } + showem(easy, CURLH_1XX); + showem(easy, CURLH_TRAILER); + +test_cleanup: + curl_easy_cleanup(easy); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1945.c b/tests/libtest/lib1945.c index 1b658b0916..2483402f41 100644 --- a/tests/libtest/lib1945.c +++ b/tests/libtest/lib1945.c @@ -52,30 +52,30 @@ static size_t write_cb(char *data, size_t n, size_t l, void *userp) int test(char *URL) { CURL *easy; + CURLcode res = CURLE_OK; - curl_global_init(CURL_GLOBAL_DEFAULT); + global_init(CURL_GLOBAL_DEFAULT); - easy = curl_easy_init(); - if(easy) { - CURLcode res; - curl_easy_setopt(easy, CURLOPT_URL, URL); - curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); - /* ignores any content */ - curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb); + easy_init(easy); + curl_easy_setopt(easy, CURLOPT_URL, URL); + curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); + /* ignores any content */ + curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb); - /* if there's a proxy set, use it */ - if(libtest_arg2 && *libtest_arg2) { - curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2); - curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L); - } - res = curl_easy_perform(easy); - if(res) { - printf("badness: %d\n", (int)res); - } - showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX); - curl_easy_cleanup(easy); + /* if there's a proxy set, use it */ + if(libtest_arg2 && *libtest_arg2) { + curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2); + curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L); } + res = curl_easy_perform(easy); + if(res) { + printf("badness: %d\n", (int)res); + } + showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX); + +test_cleanup: + curl_easy_cleanup(easy); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1947.c b/tests/libtest/lib1947.c index b9b40079e3..b7a013127a 100644 --- a/tests/libtest/lib1947.c +++ b/tests/libtest/lib1947.c @@ -36,54 +36,57 @@ static size_t writecb(char *data, size_t n, size_t l, void *userp) int test(char *URL) { CURL *curl; - CURLcode res; + CURLcode res = CURLE_OK; + struct curl_header *h; + int count = 0; + int origins; - curl_global_init(CURL_GLOBAL_DEFAULT); + global_init(CURL_GLOBAL_DEFAULT); - curl = curl_easy_init(); - if(curl) { - struct curl_header *h; - int count = 0; - int origins; + easy_init(curl); - /* perform a request that involves redirection */ - curl_easy_setopt(curl, CURLOPT_URL, URL); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - res = curl_easy_perform(curl); - if(res) - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(res)); - - /* count the number of requests by reading the first header of each - request. */ - origins = (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT| - CURLH_1XX|CURLH_PSEUDO); - do { - h = curl_easy_nextheader(curl, origins, count, NULL); - if(h) - count++; - } while(h); - printf("count = %u\n", count); + /* perform a request that involves redirection */ + easy_setopt(curl, CURLOPT_URL, URL); + easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb); + easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + res = curl_easy_perform(curl); + if(res) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); + goto test_cleanup; + } - /* perform another request - without redirect */ - curl_easy_setopt(curl, CURLOPT_URL, libtest_arg2); - res = curl_easy_perform(curl); - if(res) - fprintf(stderr, "curl_easy_perform() failed: %s\n", - curl_easy_strerror(res)); + /* count the number of requests by reading the first header of each + request. */ + origins = (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT| + CURLH_1XX|CURLH_PSEUDO); + do { + h = curl_easy_nextheader(curl, origins, count, NULL); + if(h) + count++; + } while(h); + printf("count = %u\n", count); - /* count the number of requests again. */ - count = 0; - do { - h = curl_easy_nextheader(curl, origins, count, NULL); - if(h) - count++; - } while(h); - printf("count = %u\n", count); - curl_easy_cleanup(curl); + /* perform another request - without redirect */ + easy_setopt(curl, CURLOPT_URL, libtest_arg2); + res = curl_easy_perform(curl); + if(res) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); + goto test_cleanup; } + /* count the number of requests again. */ + count = 0; + do { + h = curl_easy_nextheader(curl, origins, count, NULL); + if(h) + count++; + } while(h); + printf("count = %u\n", count); + +test_cleanup: + curl_easy_cleanup(curl); curl_global_cleanup(); - return 0; + return (int)res; } diff --git a/tests/libtest/lib1948.c b/tests/libtest/lib1948.c index 4ee565e29d..a30244c27e 100644 --- a/tests/libtest/lib1948.c +++ b/tests/libtest/lib1948.c @@ -44,36 +44,35 @@ static size_t put_callback(char *ptr, size_t size, size_t nmemb, void *stream) int test(char *URL) { CURL *curl; - CURLcode res = CURLE_OUT_OF_MEMORY; + CURLcode res = CURLE_OK; + const char *testput = "This is test PUT data\n"; + put_buffer pbuf; curl_global_init(CURL_GLOBAL_DEFAULT); - curl = curl_easy_init(); - if(curl) { - const char *testput = "This is test PUT data\n"; - put_buffer pbuf; + easy_init(curl); - /* PUT */ - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); - curl_easy_setopt(curl, CURLOPT_HEADER, 1L); - curl_easy_setopt(curl, CURLOPT_READFUNCTION, put_callback); - pbuf.buf = (char *)testput; - pbuf.len = strlen(testput); - curl_easy_setopt(curl, CURLOPT_READDATA, &pbuf); - curl_easy_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testput)); - res = curl_easy_setopt(curl, CURLOPT_URL, URL); - if(!res) - res = curl_easy_perform(curl); - if(!res) { - /* POST */ - curl_easy_setopt(curl, CURLOPT_POST, 1L); - curl_easy_setopt(curl, CURLOPT_POSTFIELDS, testput); - curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(testput)); - res = curl_easy_perform(curl); - } - curl_easy_cleanup(curl); - } + /* PUT */ + easy_setopt(curl, CURLOPT_UPLOAD, 1L); + easy_setopt(curl, CURLOPT_HEADER, 1L); + easy_setopt(curl, CURLOPT_READFUNCTION, put_callback); + pbuf.buf = (char *)testput; + pbuf.len = strlen(testput); + easy_setopt(curl, CURLOPT_READDATA, &pbuf); + easy_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testput)); + easy_setopt(curl, CURLOPT_URL, URL); + res = curl_easy_perform(curl); + if(res) + goto test_cleanup; + /* POST */ + easy_setopt(curl, CURLOPT_POST, 1L); + easy_setopt(curl, CURLOPT_POSTFIELDS, testput); + easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(testput)); + res = curl_easy_perform(curl); + +test_cleanup: + curl_easy_cleanup(curl); curl_global_cleanup(); return (int)res; } diff --git a/tests/libtest/lib2306.c b/tests/libtest/lib2306.c index 1831b331c4..839bdcc0a6 100644 --- a/tests/libtest/lib2306.c +++ b/tests/libtest/lib2306.c @@ -33,18 +33,22 @@ int test(char *URL) { /* first a fine GET response, then a bad one */ CURL *cl; - int res = 0; + CURLcode res = CURLE_OK; global_init(CURL_GLOBAL_ALL); - cl = curl_easy_init(); - curl_easy_setopt(cl, CURLOPT_URL, URL); - curl_easy_setopt(cl, CURLOPT_VERBOSE, 1L); - curl_easy_perform(cl); + easy_init(cl); + easy_setopt(cl, CURLOPT_URL, URL); + easy_setopt(cl, CURLOPT_VERBOSE, 1L); + res = curl_easy_perform(cl); + if(res) + goto test_cleanup; /* reuse handle, do a second transfer */ - curl_easy_setopt(cl, CURLOPT_URL, URL2); - curl_easy_perform(cl); + easy_setopt(cl, CURLOPT_URL, URL2); + res = curl_easy_perform(cl); + +test_cleanup: curl_easy_cleanup(cl); curl_global_cleanup(); return res; diff --git a/tests/libtest/lib519.c b/tests/libtest/lib519.c index a4abba0807..bf950bd456 100644 --- a/tests/libtest/lib519.c +++ b/tests/libtest/lib519.c @@ -49,6 +49,8 @@ int test(char *URL) /* get first page */ res = curl_easy_perform(curl); + if(res) + goto test_cleanup; test_setopt(curl, CURLOPT_USERPWD, "anothermonster:inwardrobe"); diff --git a/tests/libtest/lib541.c b/tests/libtest/lib541.c index fdddae2c75..75c74fbff8 100644 --- a/tests/libtest/lib541.c +++ b/tests/libtest/lib541.c @@ -99,7 +99,9 @@ int test(char *URL) test_setopt(curl, CURLOPT_READDATA, hd_src); /* Now run off and do what you've been told! */ - curl_easy_perform(curl); + res = curl_easy_perform(curl); + if(res) + goto test_cleanup; /* and now upload the exact same again, but without rewinding so it already is at end of file */ diff --git a/tests/libtest/lib552.c b/tests/libtest/lib552.c index 8b70231b76..13726c6b48 100644 --- a/tests/libtest/lib552.c +++ b/tests/libtest/lib552.c @@ -213,7 +213,6 @@ int test(char *URL) test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY); res = curl_easy_perform(curl); - fprintf(stderr, "curl_easy_perform = %d\n", (int)res); test_cleanup: diff --git a/tests/libtest/lib586.c b/tests/libtest/lib586.c index 90d180070d..f6e6077377 100644 --- a/tests/libtest/lib586.c +++ b/tests/libtest/lib586.c @@ -131,7 +131,7 @@ static void *fire(void *ptr) /* test function */ int test(char *URL) { - int res; + CURLcode res = CURLE_OK; CURLSHcode scode = CURLSHE_OK; char *url; struct Tdata tdata; @@ -184,8 +184,6 @@ int test(char *URL) } - res = 0; - /* start treads */ for(i = 1; i <= THREADS; i++) { @@ -215,7 +213,7 @@ int test(char *URL) test_setopt(curl, CURLOPT_SHARE, share); printf("PERFORM\n"); - curl_easy_perform(curl); + res = curl_easy_perform(curl); /* try to free share, expect to fail because share is in use */ printf("try SHARE_CLEANUP...\n"); diff --git a/tests/libtest/lib589.c b/tests/libtest/lib589.c index 5fe56dbba8..3a17e31c6b 100644 --- a/tests/libtest/lib589.c +++ b/tests/libtest/lib589.c @@ -56,6 +56,8 @@ int test(char *URL) test_setopt(curl, CURLOPT_MIMEPOST, mime); res = curl_easy_perform(curl); curl_mime_free(mime); + if(res) + goto test_cleanup; } #endif diff --git a/tests/libtest/lib677.c b/tests/libtest/lib677.c index b4ca93e1af..6dc7e8e177 100644 --- a/tests/libtest/lib677.c +++ b/tests/libtest/lib677.c @@ -39,27 +39,22 @@ int test(char *URL) time_t start = time(NULL); int state = 0; ssize_t pos = 0; + int res = 0; - curl_global_init(CURL_GLOBAL_DEFAULT); - mcurl = curl_multi_init(); - if(!mcurl) - goto fail; - curl = curl_easy_init(); - if(!curl) - goto fail; + global_init(CURL_GLOBAL_DEFAULT); + multi_init(mcurl); + easy_init(curl); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - if(curl_easy_setopt(curl, CURLOPT_URL, URL)) - goto fail; - curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); + easy_setopt(curl, CURLOPT_VERBOSE, 1L); + easy_setopt(curl, CURLOPT_URL, URL); + easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L); if(curl_multi_add_handle(mcurl, curl)) - goto fail; + goto test_cleanup; while(time(NULL) - start < 5) { struct curl_waitfd waitfd; - if(curl_multi_perform(mcurl, &mrun)) - goto fail; + multi_perform(mcurl, &mrun); for(;;) { int i; struct CURLMsg *m = curl_multi_info_read(mcurl, &i); @@ -69,7 +64,7 @@ int test(char *URL) if(m->msg == CURLMSG_DONE && m->easy_handle == curl) { curl_easy_getinfo(curl, CURLINFO_ACTIVESOCKET, &sock); if(sock == CURL_SOCKET_BAD) - goto fail; + goto test_cleanup; printf("Connected fine, extracted socket. Moving on\n"); } } @@ -86,7 +81,14 @@ int test(char *URL) size_t len = 0; if(!state) { - curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len); + CURLcode ec; + ec = curl_easy_send(curl, cmd + pos, sizeof(cmd) - 1 - pos, &len); + if(ec != CURLE_OK) { + fprintf(stderr, "curl_easy_send() failed, with code %d (%s)\n", + (int)ec, curl_easy_strerror(ec)); + res = ec; + goto test_cleanup; + } if(len > 0) pos += len; else @@ -97,7 +99,14 @@ int test(char *URL) } } else if(pos < (ssize_t)sizeof(buf)) { - curl_easy_recv(curl, buf + pos, sizeof(buf) - pos, &len); + CURLcode ec; + ec = curl_easy_recv(curl, buf + pos, sizeof(buf) - pos, &len); + if(ec != CURLE_OK) { + fprintf(stderr, "curl_easy_recv() failed, with code %d (%s)\n", + (int)ec, curl_easy_strerror(ec)); + res = ec; + goto test_cleanup; + } if(len > 0) pos += len; } @@ -112,10 +121,10 @@ int test(char *URL) } curl_multi_remove_handle(mcurl, curl); -fail: +test_cleanup: curl_easy_cleanup(curl); curl_multi_cleanup(mcurl); curl_global_cleanup(); - return 0; + return res; } -- 2.47.3