2013-02-15 05:50:45 -05:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2019-03-05 07:51:30 -05:00
|
|
|
* Copyright (C) 2013 - 2019, Linus Nielsen Feltzing, <linus@haxx.se>
|
2013-02-15 05:50:45 -05:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-02 18:19:02 -05:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2013-02-15 05:50:45 -05:00
|
|
|
*
|
|
|
|
* 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 "testutil.h"
|
|
|
|
#include "warnless.h"
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
|
|
|
#define TEST_HANG_TIMEOUT 60 * 1000
|
|
|
|
#define MAX_URLS 200
|
|
|
|
#define MAX_BLACKLIST 20
|
|
|
|
|
2017-05-01 06:55:09 -04:00
|
|
|
static int urltime[MAX_URLS];
|
|
|
|
static char *urlstring[MAX_URLS];
|
|
|
|
static CURL *handles[MAX_URLS];
|
|
|
|
static char *site_blacklist[MAX_BLACKLIST];
|
|
|
|
static char *server_blacklist[MAX_BLACKLIST];
|
|
|
|
static int num_handles;
|
|
|
|
static int blacklist_num_servers;
|
|
|
|
static int blacklist_num_sites;
|
2013-02-15 05:50:45 -05:00
|
|
|
|
|
|
|
static size_t
|
|
|
|
write_callback(void *contents, size_t size, size_t nmemb, void *userp)
|
|
|
|
{
|
|
|
|
size_t realsize = size * nmemb;
|
|
|
|
(void)contents;
|
|
|
|
(void)userp;
|
|
|
|
|
|
|
|
return realsize;
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:14:35 -05:00
|
|
|
static int parse_url_file(const char *filename)
|
2013-02-15 05:50:45 -05:00
|
|
|
{
|
|
|
|
FILE *f;
|
2013-03-20 19:32:48 -04:00
|
|
|
int filetime;
|
2013-02-15 05:50:45 -05:00
|
|
|
char buf[200];
|
|
|
|
|
|
|
|
num_handles = 0;
|
|
|
|
blacklist_num_sites = 0;
|
|
|
|
blacklist_num_servers = 0;
|
|
|
|
|
|
|
|
f = fopen(filename, "rb");
|
|
|
|
if(!f)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while(!feof(f)) {
|
2018-06-02 16:52:56 -04:00
|
|
|
if(fscanf(f, "%d %199s\n", &filetime, buf)) {
|
2013-03-20 19:32:48 -04:00
|
|
|
urltime[num_handles] = filetime;
|
2013-02-15 05:50:45 -05:00
|
|
|
urlstring[num_handles] = strdup(buf);
|
|
|
|
num_handles++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-06-02 16:52:56 -04:00
|
|
|
if(fscanf(f, "blacklist_site %199s\n", buf)) {
|
2013-02-15 05:50:45 -05:00
|
|
|
site_blacklist[blacklist_num_sites] = strdup(buf);
|
|
|
|
blacklist_num_sites++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
site_blacklist[blacklist_num_sites] = NULL;
|
|
|
|
server_blacklist[blacklist_num_servers] = NULL;
|
|
|
|
return num_handles;
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:14:35 -05:00
|
|
|
static void free_urls(void)
|
2013-02-15 05:50:45 -05:00
|
|
|
{
|
|
|
|
int i;
|
2017-09-11 03:27:06 -04:00
|
|
|
for(i = 0; i < num_handles; i++) {
|
2014-01-28 18:14:35 -05:00
|
|
|
Curl_safefree(urlstring[i]);
|
2013-02-15 05:50:45 -05:00
|
|
|
}
|
2017-09-11 03:27:06 -04:00
|
|
|
for(i = 0; i < blacklist_num_servers; i++) {
|
2014-01-28 18:14:35 -05:00
|
|
|
Curl_safefree(server_blacklist[i]);
|
2013-02-15 05:50:45 -05:00
|
|
|
}
|
2017-09-11 03:27:06 -04:00
|
|
|
for(i = 0; i < blacklist_num_sites; i++) {
|
2014-01-28 18:14:35 -05:00
|
|
|
Curl_safefree(site_blacklist[i]);
|
2013-02-15 05:50:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:14:35 -05:00
|
|
|
static int create_handles(void)
|
2013-02-15 05:50:45 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-09-11 03:27:06 -04:00
|
|
|
for(i = 0; i < num_handles; i++) {
|
2013-02-15 05:50:45 -05:00
|
|
|
handles[i] = curl_easy_init();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:14:35 -05:00
|
|
|
static void setup_handle(char *base_url, CURLM *m, int handlenum)
|
2013-02-15 05:50:45 -05:00
|
|
|
{
|
|
|
|
char urlbuf[256];
|
|
|
|
|
2018-11-22 03:01:24 -05:00
|
|
|
msnprintf(urlbuf, sizeof(urlbuf), "%s%s", base_url, urlstring[handlenum]);
|
2013-02-15 05:50:45 -05:00
|
|
|
curl_easy_setopt(handles[handlenum], CURLOPT_URL, urlbuf);
|
|
|
|
curl_easy_setopt(handles[handlenum], CURLOPT_VERBOSE, 1L);
|
|
|
|
curl_easy_setopt(handles[handlenum], CURLOPT_FAILONERROR, 1L);
|
|
|
|
curl_easy_setopt(handles[handlenum], CURLOPT_WRITEFUNCTION, write_callback);
|
|
|
|
curl_easy_setopt(handles[handlenum], CURLOPT_WRITEDATA, NULL);
|
|
|
|
curl_multi_add_handle(m, handles[handlenum]);
|
|
|
|
}
|
|
|
|
|
2014-01-28 18:14:35 -05:00
|
|
|
static void remove_handles(void)
|
2013-02-15 05:50:45 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2017-09-11 03:27:06 -04:00
|
|
|
for(i = 0; i < num_handles; i++) {
|
2013-02-15 05:50:45 -05:00
|
|
|
if(handles[i])
|
|
|
|
curl_easy_cleanup(handles[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
CURLM *m = NULL;
|
|
|
|
CURLMsg *msg; /* for picking up messages with the transfer status */
|
|
|
|
int msgs_left; /* how many messages are left */
|
2019-03-05 07:51:30 -05:00
|
|
|
int running = 0;
|
2013-02-15 05:50:45 -05:00
|
|
|
int handlenum = 0;
|
|
|
|
struct timeval last_handle_add;
|
|
|
|
|
2017-05-09 13:49:17 -04:00
|
|
|
if(parse_url_file(libtest_arg2) <= 0)
|
2013-02-15 05:50:45 -05:00
|
|
|
goto test_cleanup;
|
|
|
|
|
|
|
|
start_test_timing();
|
|
|
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
2014-01-28 18:14:35 -05:00
|
|
|
multi_init(m);
|
2013-02-15 05:50:45 -05:00
|
|
|
|
|
|
|
create_handles();
|
|
|
|
|
|
|
|
multi_setopt(m, CURLMOPT_PIPELINING, 1L);
|
|
|
|
multi_setopt(m, CURLMOPT_MAX_HOST_CONNECTIONS, 2L);
|
|
|
|
multi_setopt(m, CURLMOPT_MAX_PIPELINE_LENGTH, 3L);
|
|
|
|
multi_setopt(m, CURLMOPT_CONTENT_LENGTH_PENALTY_SIZE, 15000L);
|
|
|
|
multi_setopt(m, CURLMOPT_CHUNK_LENGTH_PENALTY_SIZE, 10000L);
|
|
|
|
|
|
|
|
multi_setopt(m, CURLMOPT_PIPELINING_SITE_BL, site_blacklist);
|
|
|
|
multi_setopt(m, CURLMOPT_PIPELINING_SERVER_BL, server_blacklist);
|
|
|
|
|
2013-06-11 18:04:03 -04:00
|
|
|
last_handle_add = tutil_tvnow();
|
2013-02-15 05:50:45 -05:00
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
struct timeval interval;
|
|
|
|
struct timeval now;
|
|
|
|
fd_set rd, wr, exc;
|
|
|
|
int maxfd = -99;
|
|
|
|
long timeout;
|
|
|
|
|
|
|
|
interval.tv_sec = 1;
|
|
|
|
interval.tv_usec = 0;
|
|
|
|
|
|
|
|
if(handlenum < num_handles) {
|
2013-06-11 18:04:03 -04:00
|
|
|
now = tutil_tvnow();
|
2017-05-20 13:39:51 -04:00
|
|
|
if(tutil_tvdiff(now, last_handle_add) >= urltime[handlenum]) {
|
2013-02-15 05:50:45 -05:00
|
|
|
fprintf(stdout, "Adding handle %d\n", handlenum);
|
|
|
|
setup_handle(URL, m, handlenum);
|
|
|
|
last_handle_add = now;
|
|
|
|
handlenum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
curl_multi_perform(m, &running);
|
|
|
|
|
|
|
|
abort_on_test_timeout();
|
|
|
|
|
|
|
|
/* See how the transfers went */
|
2017-07-16 07:44:54 -04:00
|
|
|
do {
|
|
|
|
msg = curl_multi_info_read(m, &msgs_left);
|
|
|
|
if(msg && msg->msg == CURLMSG_DONE) {
|
2018-06-02 16:52:56 -04:00
|
|
|
int i;
|
2013-02-15 05:50:45 -05:00
|
|
|
|
|
|
|
/* Find out which handle this message is about */
|
2016-04-03 05:57:34 -04:00
|
|
|
for(i = 0; i < num_handles; i++) {
|
2018-06-02 16:52:56 -04:00
|
|
|
int found = (msg->easy_handle == handles[i]);
|
2013-02-15 05:50:45 -05:00
|
|
|
if(found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Handle %d Completed with status %d\n", i, msg->data.result);
|
|
|
|
curl_multi_remove_handle(m, handles[i]);
|
|
|
|
}
|
2017-07-16 07:44:54 -04:00
|
|
|
} while(msg);
|
2013-02-15 05:50:45 -05:00
|
|
|
|
|
|
|
if(handlenum == num_handles && !running) {
|
|
|
|
break; /* done */
|
|
|
|
}
|
|
|
|
|
|
|
|
FD_ZERO(&rd);
|
|
|
|
FD_ZERO(&wr);
|
|
|
|
FD_ZERO(&exc);
|
|
|
|
|
|
|
|
curl_multi_fdset(m, &rd, &wr, &exc, &maxfd);
|
|
|
|
|
|
|
|
/* At this point, maxfd is guaranteed to be greater or equal than -1. */
|
|
|
|
|
|
|
|
curl_multi_timeout(m, &timeout);
|
|
|
|
|
|
|
|
if(timeout < 0)
|
|
|
|
timeout = 1;
|
|
|
|
|
|
|
|
interval.tv_sec = timeout / 1000;
|
|
|
|
interval.tv_usec = (timeout % 1000) * 1000;
|
|
|
|
|
|
|
|
interval.tv_sec = 0;
|
|
|
|
interval.tv_usec = 1000;
|
|
|
|
|
2017-09-09 17:55:08 -04:00
|
|
|
select_test(maxfd + 1, &rd, &wr, &exc, &interval);
|
2013-02-15 05:50:45 -05:00
|
|
|
|
|
|
|
abort_on_test_timeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
test_cleanup:
|
|
|
|
|
|
|
|
remove_handles();
|
|
|
|
|
|
|
|
/* undocumented cleanup sequence - type UB */
|
|
|
|
|
|
|
|
curl_multi_cleanup(m);
|
|
|
|
curl_global_cleanup();
|
|
|
|
|
|
|
|
free_urls();
|
|
|
|
return res;
|
|
|
|
}
|