2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2006-10-25 17:20:44 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, 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.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2003-01-08 17:37:35 +08:00
|
|
|
#include "test.h"
|
2002-12-12 20:11:16 +08:00
|
|
|
|
2009-01-21 12:30:05 +08:00
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h> /* for setlocale() */
|
|
|
|
#endif
|
|
|
|
|
2003-07-05 00:37:16 +08:00
|
|
|
#ifdef CURLDEBUG
|
2008-09-20 12:26:55 +08:00
|
|
|
# define MEMDEBUG_NODEFINES
|
2013-01-04 09:50:28 +08:00
|
|
|
# include "memdebug.h"
|
2002-12-12 21:40:16 +08:00
|
|
|
#endif
|
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
|
|
|
|
struct timeval *tv)
|
2006-09-11 03:01:04 +08:00
|
|
|
{
|
2011-10-21 22:26:18 +08:00
|
|
|
if(nfds < 0) {
|
|
|
|
SET_SOCKERRNO(EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2006-10-19 05:05:40 +08:00
|
|
|
#ifdef USE_WINSOCK
|
2011-12-30 10:36:18 +08:00
|
|
|
/*
|
2011-10-21 22:26:18 +08: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-11 03:01:04 +08:00
|
|
|
*/
|
2011-10-21 22:26:18 +08:00
|
|
|
if(!nfds) {
|
2006-09-11 03:01:04 +08:00
|
|
|
Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2011-10-21 22:26:18 +08:00
|
|
|
return select(nfds, rd, wr, exc, tv);
|
2006-09-11 03:01:04 +08:00
|
|
|
}
|
|
|
|
|
2007-10-03 00:05:28 +08:00
|
|
|
char *libtest_arg2=NULL;
|
|
|
|
char *libtest_arg3=NULL;
|
2007-07-16 04:59:43 +08:00
|
|
|
int test_argc;
|
|
|
|
char **test_argv;
|
2011-05-26 02:22:46 +08:00
|
|
|
|
2011-10-21 22:26:18 +08:00
|
|
|
struct timeval tv_test_start; /* for test timing */
|
|
|
|
|
2011-05-26 02:22:46 +08:00
|
|
|
#ifdef UNITTESTS
|
2011-01-02 00:33:42 +08:00
|
|
|
int unitfail; /* for unittests */
|
2011-05-26 02:22:46 +08:00
|
|
|
#endif
|
2002-12-14 00:22:57 +08:00
|
|
|
|
2004-05-14 16:40:33 +08:00
|
|
|
#ifdef CURLDEBUG
|
2011-08-20 23:26:02 +08: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 16:40:33 +08:00
|
|
|
if(env) {
|
2005-01-28 06:40:56 +08:00
|
|
|
/* use the value as file name */
|
2011-08-20 23:26:02 +08: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 16:40:33 +08:00
|
|
|
curl_free(env);
|
2011-08-20 23:26:02 +08: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 16:40:33 +08:00
|
|
|
}
|
2011-08-20 23:26:02 +08:00
|
|
|
/* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
|
2004-05-14 16:40:33 +08:00
|
|
|
env = curl_getenv("CURL_MEMLIMIT");
|
|
|
|
if(env) {
|
2010-11-29 06:11:14 +08:00
|
|
|
char *endptr;
|
|
|
|
long num = strtol(env, &endptr, 10);
|
|
|
|
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
|
|
|
|
curl_memlimit(num);
|
2004-05-14 16:40:33 +08:00
|
|
|
curl_free(env);
|
|
|
|
}
|
2011-08-20 23:26:02 +08:00
|
|
|
}
|
|
|
|
#else
|
2011-09-03 22:06:10 +08:00
|
|
|
# define memory_tracking_init() Curl_nop_stmt
|
2004-05-14 16:40:33 +08:00
|
|
|
#endif
|
2009-01-21 12:30:05 +08:00
|
|
|
|
2011-08-20 23:26:02 +08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
char *URL;
|
|
|
|
|
|
|
|
memory_tracking_init();
|
|
|
|
|
2009-01-21 12:30:05 +08: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 20:11:16 +08:00
|
|
|
if(argc< 2 ) {
|
|
|
|
fprintf(stderr, "Pass URL as argument please\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-16 04:59:43 +08:00
|
|
|
|
|
|
|
test_argc = argc;
|
|
|
|
test_argv = argv;
|
|
|
|
|
2002-12-14 00:22:57 +08:00
|
|
|
if(argc>2)
|
2007-10-03 00:05:28 +08:00
|
|
|
libtest_arg2=argv[2];
|
2002-12-14 00:22:57 +08:00
|
|
|
|
2007-07-15 06:38:18 +08:00
|
|
|
if(argc>3)
|
2007-10-03 00:05:28 +08:00
|
|
|
libtest_arg3=argv[3];
|
2007-07-15 06:38:18 +08:00
|
|
|
|
2002-12-12 21:40:16 +08:00
|
|
|
URL = argv[1]; /* provide this to the rest */
|
|
|
|
|
|
|
|
fprintf(stderr, "URL: %s\n", URL);
|
2002-12-12 20:11:16 +08:00
|
|
|
|
2002-12-12 21:40:16 +08:00
|
|
|
return test(URL);
|
|
|
|
}
|