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