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.
This commit is contained in:
Dan Fandrich 2023-09-29 16:32:48 -07:00
parent 61c8f1edc3
commit 2bee7aeb34
27 changed files with 318 additions and 261 deletions

View file

@ -54,6 +54,14 @@ http://%HOSTIP:%HTTPPORT/%TESTNUMBER http://%HOSTIP:%HTTPPORT/%TESTNUMBER0002
#
# Verify data after the test has been "shot"
<verify>
# hyper doesn't like the bad header in the second request
<errorcode>
%if hyper
1
%else
0
%endif
</errorcode>
<protocol>
GET /%TESTNUMBER HTTP/1.1
Host: %HOSTIP:%HTTPPORT

View file

@ -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();
}

View file

@ -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:

View file

@ -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"

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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 */
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {
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);
/* 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;
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;
}

View file

@ -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;
}

View file

@ -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 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 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 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;
}
/* 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 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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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");

View file

@ -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 */

View file

@ -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:

View file

@ -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");

View file

@ -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

View file

@ -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;
}