2011-03-10 11:48:02 +01:00
|
|
|
/***************************************************************************
|
2006-10-25 11:20:44 +02:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2014-05-09 16:48:11 +02:00
|
|
|
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-03-10 11:48:02 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2003-01-08 10:37:35 +01:00
|
|
|
#include "test.h"
|
2002-12-12 13:11:16 +01:00
|
|
|
|
2009-01-21 05:30:05 +01:00
|
|
|
#ifdef HAVE_LOCALE_H
|
2014-02-01 00:58:58 +01:00
|
|
|
# include <locale.h> /* for setlocale() */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h> /* for setmode() */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
# include <fcntl.h> /* for setmode() */
|
2009-01-21 05:30:05 +01:00
|
|
|
#endif
|
|
|
|
|
2003-07-04 18:37:16 +02:00
|
|
|
#ifdef CURLDEBUG
|
2008-09-20 06:26:55 +02:00
|
|
|
# define MEMDEBUG_NODEFINES
|
2013-01-04 02:50:28 +01:00
|
|
|
# include "memdebug.h"
|
2002-12-12 14:40:16 +01:00
|
|
|
#endif
|
|
|
|
|
2011-10-21 16:26:18 +02:00
|
|
|
int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
|
|
|
|
struct timeval *tv)
|
2006-09-10 21:01:04 +02:00
|
|
|
{
|
2011-10-21 16:26:18 +02:00
|
|
|
if(nfds < 0) {
|
|
|
|
SET_SOCKERRNO(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2006-10-18 23:05:40 +02:00
|
|
|
#ifdef USE_WINSOCK
|
2011-12-30 03:36:18 +01:00
|
|
|
/*
|
2011-10-21 16:26:18 +02:00
|
|
|
* Winsock select() requires that at least one of the three fd_set
|
|
|
|
* pointers is not NULL and points to a non-empty fdset. IOW Winsock
|
|
|
|
* select() can not be used to sleep without a single fd_set.
|
2006-09-10 21:01:04 +02:00
|
|
|
*/
|
2011-10-21 16:26:18 +02:00
|
|
|
if(!nfds) {
|
2006-09-10 21:01:04 +02:00
|
|
|
Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2011-10-21 16:26:18 +02:00
|
|
|
return select(nfds, rd, wr, exc, tv);
|
2006-09-10 21:01:04 +02:00
|
|
|
}
|
|
|
|
|
2014-05-09 16:48:11 +02:00
|
|
|
void wait_ms(int ms)
|
|
|
|
{
|
|
|
|
struct timeval t;
|
|
|
|
t.tv_sec = ms/1000;
|
|
|
|
ms -= (int)t.tv_sec * 1000;
|
|
|
|
t.tv_usec = ms * 1000;
|
|
|
|
select_wrapper(0, NULL, NULL , NULL, &t);
|
|
|
|
}
|
|
|
|
|
2007-10-02 18:05:28 +02:00
|
|
|
char *libtest_arg2=NULL;
|
|
|
|
char *libtest_arg3=NULL;
|
2007-07-15 22:59:43 +02:00
|
|
|
int test_argc;
|
|
|
|
char **test_argv;
|
2011-05-25 20:22:46 +02:00
|
|
|
|
2011-10-21 16:26:18 +02:00
|
|
|
struct timeval tv_test_start; /* for test timing */
|
|
|
|
|
2011-05-25 20:22:46 +02:00
|
|
|
#ifdef UNITTESTS
|
2011-01-01 17:33:42 +01:00
|
|
|
int unitfail; /* for unittests */
|
2011-05-25 20:22:46 +02:00
|
|
|
#endif
|
2002-12-13 17:22:57 +01:00
|
|
|
|
2004-05-14 10:40:33 +02:00
|
|
|
#ifdef CURLDEBUG
|
2011-08-20 17:26:02 +02:00
|
|
|
static void memory_tracking_init(void)
|
|
|
|
{
|
|
|
|
char *env;
|
|
|
|
/* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
|
|
|
|
env = curl_getenv("CURL_MEMDEBUG");
|
2004-05-14 10:40:33 +02:00
|
|
|
if(env) {
|
2005-01-27 23:40:56 +01:00
|
|
|
/* use the value as file name */
|
2011-08-20 17:26:02 +02:00
|
|
|
char fname[CURL_MT_LOGFNAME_BUFSIZE];
|
|
|
|
if(strlen(env) >= CURL_MT_LOGFNAME_BUFSIZE)
|
|
|
|
env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
|
|
|
|
strcpy(fname, env);
|
2004-05-14 10:40:33 +02:00
|
|
|
curl_free(env);
|
2011-08-20 17:26:02 +02:00
|
|
|
curl_memdebug(fname);
|
|
|
|
/* this weird stuff here is to make curl_free() get called
|
|
|
|
before curl_memdebug() as otherwise memory tracking will
|
|
|
|
log a free() without an alloc! */
|
2004-05-14 10:40:33 +02:00
|
|
|
}
|
2011-08-20 17:26:02 +02:00
|
|
|
/* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
|
2004-05-14 10:40:33 +02:00
|
|
|
env = curl_getenv("CURL_MEMLIMIT");
|
|
|
|
if(env) {
|
2010-11-28 23:11:14 +01:00
|
|
|
char *endptr;
|
|
|
|
long num = strtol(env, &endptr, 10);
|
|
|
|
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
|
|
|
|
curl_memlimit(num);
|
2004-05-14 10:40:33 +02:00
|
|
|
curl_free(env);
|
|
|
|
}
|
2011-08-20 17:26:02 +02:00
|
|
|
}
|
|
|
|
#else
|
2011-09-03 16:06:10 +02:00
|
|
|
# define memory_tracking_init() Curl_nop_stmt
|
2004-05-14 10:40:33 +02:00
|
|
|
#endif
|
2009-01-21 05:30:05 +01:00
|
|
|
|
2011-08-20 17:26:02 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *URL;
|
|
|
|
|
2014-02-01 00:58:58 +01:00
|
|
|
#ifdef O_BINARY
|
|
|
|
# ifdef __HIGHC__
|
|
|
|
_setmode(stdout, O_BINARY);
|
|
|
|
# else
|
|
|
|
setmode(fileno(stdout), O_BINARY);
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-08-20 17:26:02 +02:00
|
|
|
memory_tracking_init();
|
|
|
|
|
2009-01-21 05:30:05 +01:00
|
|
|
/*
|
|
|
|
* Setup proper locale from environment. This is needed to enable locale-
|
|
|
|
* specific behaviour by the C library in order to test for undesired side
|
|
|
|
* effects that could cause in libcurl.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_SETLOCALE
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
#endif
|
|
|
|
|
2002-12-12 13:11:16 +01:00
|
|
|
if(argc< 2 ) {
|
|
|
|
fprintf(stderr, "Pass URL as argument please\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-15 22:59:43 +02:00
|
|
|
|
|
|
|
test_argc = argc;
|
|
|
|
test_argv = argv;
|
|
|
|
|
2002-12-13 17:22:57 +01:00
|
|
|
if(argc>2)
|
2007-10-02 18:05:28 +02:00
|
|
|
libtest_arg2=argv[2];
|
2002-12-13 17:22:57 +01:00
|
|
|
|
2007-07-15 00:38:18 +02:00
|
|
|
if(argc>3)
|
2007-10-02 18:05:28 +02:00
|
|
|
libtest_arg3=argv[3];
|
2007-07-15 00:38:18 +02:00
|
|
|
|
2002-12-12 14:40:16 +01:00
|
|
|
URL = argv[1]; /* provide this to the rest */
|
|
|
|
|
|
|
|
fprintf(stderr, "URL: %s\n", URL);
|
2002-12-12 13:11:16 +01:00
|
|
|
|
2002-12-12 14:40:16 +01:00
|
|
|
return test(URL);
|
|
|
|
}
|