2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://curl.haxx.se/docs/copyright.html.
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 # $Id: runtests.pl,v 1.111 2004/03/01 16:24:54 bagder Exp $
23 ###########################################################################
24 # These should be the only variables that might be needed to get edited:
29 @INC=(@INC, $ENV{'srcdir'}, ".");
31 require "getpart.pm"; # array functions
33 my $srcdir = $ENV{'srcdir'} || '.';
34 my $HOSTIP="127.0.0.1";
35 my $HOSTPORT=8999; # bad name, but this is the HTTP server port
36 my $HTTPSPORT=8433; # this is the HTTPS server port
37 my $FTPPORT=8921; # this is the FTP server port
38 my $FTPSPORT=8821; # this is the FTPS server port
39 my $CURL="../src/curl"; # what curl executable to run on the tests
40 my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
42 my $TESTDIR="$srcdir/data";
43 my $LIBDIR="./libtest";
44 my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
45 my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
46 my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
48 # Normally, all test cases should be run, but at times it is handy to
49 # simply run a particular one:
52 # To run specific test cases, set them like:
53 # $TESTCASES="1 2 3 7 8";
55 #######################################################################
56 # No variables below this point should need to be modified
59 my $HTTPPIDFILE=".http.pid";
60 my $HTTPSPIDFILE=".https.pid";
61 my $FTPPIDFILE=".ftp.pid";
62 my $FTPSPIDFILE=".ftps.pid";
64 # invoke perl like this:
65 my $perl="perl -I$srcdir";
67 # this gets set if curl is compiled with debugging:
70 # name of the file that the memory debugging creates:
71 my $memdump="memdump";
73 # the path to the script that analyzes the memory debug output file:
74 my $memanalyze="./memanalyze.pl";
76 my $stunnel = checkcmd("stunnel");
77 my $valgrind = checkcmd("valgrind");
79 my $ssl_version; # set if libcurl is built with SSL support
80 my $large_file; # set if libcurl is built with large file support
82 my $skipped=0; # number of tests skipped; reported in main loop
83 my %skipped; # skipped{reason}=counter, reasons for skip
84 my @teststat; # teststat[testnum]=reason, reasons for skip
86 #######################################################################
87 # variables the command line options may set
94 my $gdbthis; # run test case with gdb debugger
95 my $keepoutfiles; # keep stdout and stderr files after tests
96 my $listonly; # only list the tests
98 my $pwd; # current working directory
100 my %run; # running server
102 # torture test variables
109 # enable memory debugging if curl is compiled with it
110 $ENV{'CURL_MEMDEBUG'} = 1;
113 ##########################################################################
114 # Clear all possible '*_proxy' environment variables for various protocols
115 # to prevent them to interfere with our testing!
118 foreach $protocol (('ftp', 'http', 'ftps', 'https', 'gopher', 'no')) {
119 my $proxy = "${protocol}_proxy";
120 # clear lowercase version
122 # clear uppercase version
123 $ENV{uc($proxy)}=undef;
126 #######################################################################
127 # Check for a command in the PATH.
131 my @paths=("/usr/sbin", "/usr/local/sbin", "/sbin", "/usr/bin",
132 "/usr/local/bin", split(":", $ENV{'PATH'}));
140 #######################################################################
141 # Return the pid of the server as found in the given pid file
145 open(PFILE, "<$PIDFILE");
151 #######################################################################
152 # Memory allocation test and failure torture testing.
155 # start all test servers (http, https, ftp, ftps)
156 &startservers(("http", "https", "ftp", "ftps"));
159 my @test=('http://%HOSTIP:%HOSTPORT/1',
160 'ftp://%HOSTIP:%FTPPORT/');
162 # loop over the different tests commands
168 if($tortnum && ($tortnum != $c)) {
171 print "We want test $c\n";
173 my $redir=">log/torture.stdout 2>log/torture.stderr";
175 subVariables(\$cmdargs);
177 my $testcmd = "$CURL $cmdargs $redir";
179 # First get URL from test server, ignore the output/result
182 # Set up gdb-stuff if desired
184 open(GDBCMD, ">log/gdbcmd");
185 print GDBCMD "set args $cmdargs\n";
186 print GDBCMD "show args\n";
188 $testcmd = "gdb $CURL -x log/gdbcmd";
191 print "Torture test $c:\n";
192 print " CMD: $testcmd\n" if($verbose);
194 # memanalyze -v is our friend, get the number of allocations made
196 my @out = `$memanalyze -v $memdump`;
198 if(/^Allocations: (\d+)/) {
204 # hm, no allocations in this fetch, ignore and get next
205 print "BEEEP, no allocs found for test $c!!!\n";
208 print " $count allocations to excersize\n";
210 for ( 1 .. $count ) {
214 if($tortalloc && ($tortalloc != $limit)) {
218 print "Alloc no: $limit\r" if(!$gdbthis);
220 # make the memory allocation function number $limit return failure
221 $ENV{'CURL_MEMLIMIT'} = $limit;
223 # remove memdump first to be sure we get a new nice and clean one
226 print "**> Alloc number $limit is now set to fail <**\n" if($gdbthis);
228 my $ret = system($testcmd);
230 # verify that it returns a proper error code, doesn't leak memory
231 # and doesn't core dump
233 print " system() returned $ret\n";
237 my @memdata=`$memanalyze $memdump`;
241 # well it could be other memory problems as well, but
242 # we call it leak for short here
247 print "** MEMORY FAILURE\n";
249 print `$memanalyze -l $memdump`;
254 print " Failed on alloc number $limit in test $c.\n",
255 " invoke with -t$c,$limit to repeat this single case.\n";
260 print "\n torture test $c did GOOD\n";
262 # all is well, now test a different kind of URL
265 exit; # for now, we stop after these tests
268 #######################################################################
269 # stop the given test server
276 $pid = serverpid($PIDFILE);
277 unlink $PIDFILE; # server is killed
280 return; # this is not a good pid
283 my $res = kill (9, $pid); # die!
285 if($res && $verbose) {
286 print "RUN: Test server pid $pid signalled to die\n";
289 print "RUN: Test server pid $pid didn't exist\n";
293 #######################################################################
294 # check the given test server if it is still alive
302 $pid=serverpid($pidfile);
303 if ($pid ne "" && kill(0, $pid)) {
307 return -$pid; # negative means dead process
313 #######################################################################
314 # start the http server, or if it already runs, verify that it is our
315 # test server on the test-port!
322 $pid = checkserver ($HTTPPIDFILE);
324 # verify if our/any server is running on this port
325 my $cmd = "$CURL -o log/verifiedserver --silent -i $HOSTIP:$HOSTPORT/verifiedserver 2>/dev/null";
326 print "CMD; $cmd\n" if ($verbose);
327 my $res = system($cmd);
329 $res >>= 8; # rotate the result
332 print "RUN: curl command returned $res\n" if ($verbose);
334 open(FILE, "<log/verifiedserver");
337 $data=$file[0]; # first line
339 if ( $data =~ /WE ROOLZ: (\d+)/ ) {
342 elsif($data || ($res != 7)) {
343 print "RUN: Unknown HTTP server is running on port $HOSTPORT\n";
348 my $res = kill (9, $pid); # die!
350 print "RUN: Failed to kill test HTTP server, do it manually and",
351 " restart the tests.\n";
357 my $flag=$debugprotocol?"-v ":"";
358 my $dir=$ENV{'srcdir'};
360 $flag .= "-d \"$dir\" ";
362 $cmd="$perl $srcdir/httpserver.pl $flag $HOSTPORT &";
370 # verify that our server is up and running:
371 my $data=`$CURL --silent -i $HOSTIP:$HOSTPORT/verifiedserver 2>/dev/null`;
373 if ( $data =~ /WE ROOLZ: (\d+)/ ) {
380 print STDERR "RUN: Retrying HTTP server existence in 3 sec\n";
387 print STDERR "RUN: failed to start our HTTP server\n";
392 print "RUN: HTTP server is now verified to be our server\n";
398 #######################################################################
399 # start the https server (or rather, tunnel) if needed
410 my $pid=checkserver($HTTPSPIDFILE );
413 # kill previous stunnel!
415 print "RUN: kills off running stunnel at $pid\n";
417 stopserver($HTTPSPIDFILE);
420 my $flag=$debugprotocol?"-v ":"";
421 my $cmd="$perl $srcdir/httpsserver.pl $flag -s \"$stunnel\" -d $srcdir -r $HOSTPORT $HTTPSPORT &";
429 $pid=checkserver($HTTPSPIDFILE);
433 print STDERR "RUN: waiting 3 sec for HTTPS server\n";
445 #######################################################################
446 # start the ftp server if needed
453 my $pid = checkserver ($FTPPIDFILE );
456 print "RUN: Check port $FTPPORT for our own FTP server\n"
461 # check if this is our server running on this port:
462 my $data=`$CURL -m4 --silent -i ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null`;
464 # if this took more than 2 secs, we assume it "hung" on a weird server
465 my $took = time()-$time;
467 if ( $data =~ /WE ROOLZ: (\d+)/ ) {
468 # this is our test server with a known pid!
472 if($data || ($took > 2)) {
473 # this is not a known server
474 print "RUN: Unknown server on our favourite port: $FTPPORT\n";
481 print "RUN: Killing a previous server using pid $pid\n" if($verbose);
482 my $res = kill (9, $pid); # die!
484 print "RUN: Failed to kill our FTP test server, do it manually and",
485 " restart the tests.\n";
491 # now (re-)start our server:
492 my $flag=$debugprotocol?"-v ":"";
493 $flag .= "-s \"$srcdir\"";
494 my $cmd="$perl $srcdir/ftpserver.pl $flag $FTPPORT &";
502 # verify that our server is up and running:
503 my $data=`$CURL --silent -i ftp://$HOSTIP:$FTPPORT/verifiedserver 2>/dev/null`;
505 if ( $data =~ /WE ROOLZ: (\d+)/ ) {
512 print STDERR "RUN: Retrying FTP server existence in 3 sec\n";
519 warn "RUN: failed to start our FTP server\n";
524 print "RUN: FTP server is now verified to be our server\n";
530 #######################################################################
531 # start the ftps server (or rather, tunnel) if needed
541 my $pid=checkserver($FTPSPIDFILE );
544 # kill previous stunnel!
546 print "kills off running stunnel at $pid\n";
548 stopserver($FTPSPIDFILE);
551 my $flag=$debugprotocol?"-v ":"";
552 my $cmd="$perl $srcdir/ftpsserver.pl $flag -s \"$stunnel\" -d $srcdir -r $FTPPORT $FTPSPORT &";
561 $pid=checkserver($FTPSPIDFILE );
565 print STDERR "RUN: waiting 3 sec for FTPS server\n";
577 #######################################################################
578 # Remove all files in the specified directory
586 opendir(DIR, $dir) ||
587 return 0; # can't open dir
588 while($file = readdir(DIR)) {
590 unlink("$dir/$file");
598 #######################################################################
599 # filter out the specified pattern from the given input file and store the
600 # results in the given output file
613 # print "FILTER: off $filter from $infile to $ofile\n";
624 #######################################################################
625 # compare test results with the expected output, we might filter off
626 # some pattern that is allowed to differ, output test results
630 # filter off patterns _before_ this comparison!
631 my ($subject, $firstref, $secondref)=@_;
633 my $result = compareparts($firstref, $secondref);
637 print "\n $subject FAILED:\n";
638 print showdiff($firstref, $secondref);
647 #######################################################################
648 # display information about curl and the host the test suite runs on
652 unlink($memdump); # remove this if there was one left
656 my @version=`$CURL -V 2>/dev/null`;
663 $curl =~ s/^(.*)(libcurl.*)/$1/g;
666 if ($curl =~ /win32/)
668 # Native Windows builds don't understand the
669 # output of cygwin's pwd. It will be
670 # something like /cygdrive/c/<some path>.
672 # Use the cygpath utility to convert the
673 # working directory to a Windows friendly
674 # path. The -m option converts to use drive
675 # letter:, but it uses / instead \. Forward
676 # slashes (/) are easier for us. We don't
677 # have to escape them to get them to curl
679 chomp($pwd = `cygpath -m $pwd`);
682 elsif($_ =~ /^Protocols: (.*)/i) {
683 # these are the supported protocols, we don't use this knowledge
686 elsif($_ =~ /^Features: (.*)/i) {
688 if($feat =~ /debug/i) {
689 # debug is a listed "feature", use that knowledge
691 # set the NETRC debug env
692 $ENV{'CURL_DEBUG_NETRC'} = 'log/netrc';
694 if($feat =~ /SSL/i) {
698 if($feat =~ /Largefile/i) {
705 die "couldn't run curl!"
708 my $hostname=`hostname`;
709 my $hosttype=`uname -a`;
711 print "********* System characteristics ******** \n",
715 "* System: $hosttype";
717 printf("* Server SSL: %s\n", $stunnel?"ON":"OFF");
718 printf("* libcurl SSL: %s\n", $ssl_version?"ON":"OFF");
719 printf("* libcurl debug: %s\n", $curl_debug?"ON":"OFF");
720 printf("* valgrind: %s\n", $valgrind?"ON":"OFF");
721 print "***************************************** \n";
724 #######################################################################
725 # substitute the variable stuff into either a joined up file or
726 # a command, in either case passed by reference
730 $$thing =~ s/%HOSTIP/$HOSTIP/g;
731 $$thing =~ s/%HOSTPORT/$HOSTPORT/g;
732 $$thing =~ s/%HTTPPORT/$HOSTPORT/g;
733 $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
734 $$thing =~ s/%FTPPORT/$FTPPORT/g;
735 $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
736 $$thing =~ s/%SRCDIR/$srcdir/g;
737 $$thing =~ s/%PWD/$pwd/g;
740 #######################################################################
741 # Run a single specified test case
751 # load the test case file definition
752 if(loadtest("${TESTDIR}/test${testnum}")) {
755 print "RUN: $testnum doesn't look like a test case!\n";
757 $serverproblem = 100;
760 @what = getpart("client", "features");
763 printf("test %03d...", $testnum);
774 elsif($f eq "netrc_debug") {
779 elsif($f eq "large_file") {
785 $why = "curl lacks $f support";
786 $serverproblem = 15; # set it here
790 if(!$serverproblem) {
791 $serverproblem = serverfortest($testnum);
795 # there's a problem with the server, don't run
796 # this particular server, but count it as "skipped"
797 if($serverproblem == 2) {
798 $why = "server problems";
800 elsif($serverproblem == 100) {
803 elsif($serverproblem == 99) {
806 elsif($serverproblem == 15) {
807 # set above, a lacking prereq
809 elsif($serverproblem == 1) {
810 $why = "no HTTPS server";
812 elsif($serverproblem == 3) {
813 $why = "no FTPS server";
816 $why = "unfulfilled requirements";
820 $teststat[$testnum]=$why; # store reason for this test case
824 print "* Test $testnum: $why\n";
830 # extract the reply data
831 my @reply = getpart("reply", "data");
832 my @replycheck = getpart("reply", "datacheck");
835 # we use this file instead to check the final output against
837 my %hash = getpartattr("reply", "datacheck");
838 if($hash{'nonewline'}) {
839 # Yes, we must cut off the final newline from the final line
841 chomp($replycheck[$#replycheck]);
847 # curl command to run
848 my @curlcmd= getpart("client", "command");
850 # this is the valid protocol blurb curl should generate
851 my @protocol= getpart("verify", "protocol");
853 # redirected stdout/stderr to these files
854 $STDOUT="$LOGDIR/stdout$testnum";
855 $STDERR="$LOGDIR/stderr$testnum";
857 # if this section exists, we verify that the stdout contained this:
858 my @validstdout = getpart("verify", "stdout");
860 # if this section exists, we verify upload
861 my @upload = getpart("verify", "upload");
863 # if this section exists, it is FTP server instructions:
864 my @ftpservercmd = getpart("server", "instruction");
866 my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
869 my @testname= getpart("client", "name");
872 my $name = $testname[0];
878 return 0; # look successful
881 my @codepieces = getpart("client", "tool");
885 $tool = $codepieces[0];
889 # remove previous server output logfile
893 # write the instructions to file
894 writearray($FTPDCMD, \@ftpservercmd);
897 my (@setenv)= getpart("client", "setenv");
902 chomp $s; # cut off the newline
906 if($s =~ /([^=]*)=(.*)/) {
907 my ($var, $content)=($1, $2);
909 # remember which, so that we can clear them afterwards!
914 # get the command line options to use
915 my ($cmd, @blaha)= getpart("client", "command");
917 # make some nice replace operations
918 $cmd =~ s/\n//g; # no newlines please
920 # substitute variables in the command line
927 my @inputfile=getpart("client", "file");
929 # we need to generate a file before this test is invoked
930 my %hash = getpartattr("client", "file");
932 my $filename=$hash{'name'};
935 print "ERROR: section client=>file has no name attribute!\n";
938 my $fileContent = join('', @inputfile);
939 subVariables \$fileContent;
940 # print "DEBUG: writing file " . $filename . "\n";
941 open OUTFILE, ">$filename";
942 binmode OUTFILE; # for crapage systems, use binary
943 print OUTFILE $fileContent;
947 my %cmdhash = getpartattr("client", "command");
951 if($cmdhash{'option'} !~ /no-output/) {
952 #We may slap on --output!
954 $out=" --output $CURLOUT ";
960 # run curl, add -v for debug information output
961 $cmdargs ="$out --include -v $cmd";
964 $cmdargs = " $cmd"; # $cmd is the command line for the test file
965 $CURLOUT = $STDOUT; # sends received data to stdout
968 my @stdintest = getpart("client", "stdin");
971 my $stdinfile="$LOGDIR/stdin-for-$testnum";
972 writearray($stdinfile, \@stdintest);
974 $cmdargs .= " <$stdinfile";
977 $cmdargs .= " 3>log/valgrind$testnum";
985 $CMDLINE="$LIBDIR/$tool";
989 $CMDLINE .= "$cmdargs >>$STDOUT 2>>$STDERR";
995 print CMDLOG "$CMDLINE\n";
998 # run the command line we built
1000 open(GDBCMD, ">log/gdbcmd");
1001 print GDBCMD "set args $cmdargs\n";
1002 print GDBCMD "show args\n";
1004 system("gdb --directory libtest $DBGCURL -x log/gdbcmd");
1005 $cmdres=0; # makes it always continue after a debugged run
1008 $cmdres = system("$CMDLINE");
1009 my $signal_num = $cmdres & 127;
1010 my $dumped_core = $cmdres & 128;
1012 if(!$anyway && ($signal_num || $dumped_core)) {
1020 # remove the special FTP command file after each test!
1025 $ENV{$e}=""; # clean up
1028 my @err = getpart("verify", "errorcode");
1029 my $errorcode = $err[0];
1033 # verify redirected stdout
1034 my @actual = loadarray($STDOUT);
1036 $res = compare("stdout", \@actual, \@validstdout);
1045 my %replyattr = getpartattr("reply", "data");
1046 if(!$replyattr{'nocheck'} && @reply) {
1047 # verify the received data
1048 my @out = loadarray($CURLOUT);
1049 $res = compare("data", \@out, \@reply);
1059 # verify uploaded data
1060 my @out = loadarray("$LOGDIR/upload.$testnum");
1061 $res = compare("upload", \@out, \@upload);
1071 # verify the sent request
1072 my @out = loadarray($SERVERIN);
1074 # what to cut off from the live protocol sent by curl
1075 my @strip = getpart("verify", "strip");
1077 my @protstrip=@protocol;
1079 # check if there's any attributes on the verify/protocol section
1080 my %hash = getpartattr("verify", "protocol");
1082 if($hash{'nonewline'}) {
1083 # Yes, we must cut off the final newline from the final line
1084 # of the protocol data
1085 chomp($protstrip[$#protstrip]);
1089 # strip all patterns from both arrays
1090 @out = striparray( $_, \@out);
1091 @protstrip= striparray( $_, \@protstrip);
1094 $res = compare("protocol", \@out, \@protstrip);
1099 print " protocol OK";
1103 my @outfile=getpart("verify", "file");
1105 # we're supposed to verify a dynamicly generated file!
1106 my %hash = getpartattr("verify", "file");
1108 my $filename=$hash{'name'};
1110 print "ERROR: section verify=>file has no name attribute!\n";
1113 my @generated=loadarray($filename);
1115 $res = compare("output", \@generated, \@outfile);
1124 if($errorcode || $cmdres) {
1125 if($errorcode == $cmdres) {
1126 $errorcode =~ s/\n//;
1128 print " received errorcode $errorcode OK";
1136 print "curl returned $cmdres, ".(0+$errorcode)." was expected\n";
1138 print " error FAILED\n";
1143 if(!$keepoutfiles) {
1144 # remove the stdout and stderr files
1147 unlink($CURLOUT); # remove the downloaded results
1149 unlink("$LOGDIR/upload.$testnum"); # remove upload leftovers
1152 unlink($FTPDCMD); # remove the instructions for this test
1154 @what = getpart("client", "killserver");
1159 stopserver($run{$serv}); # the pid file is in the hash table
1160 $run{$serv}=0; # clear pid
1163 print STDERR "RUN: The $serv server is not running\n";
1169 print "\n** ALERT! memory debuggin without any output file?\n";
1172 my @memdata=`$memanalyze $memdump`;
1176 # well it could be other memory problems as well, but
1177 # we call it leak for short here
1182 print "\n** MEMORY FAILURE\n";
1201 #######################################################################
1202 # Stop all running test servers
1204 print "Shutting down test suite servers:\n" if ($verbose);
1206 printf ("* kill pid for %-5s => %-5d\n", $_, $run{$_}) if($verbose);
1207 stopserver($run{$_}); # the pid file is in the hash table
1211 #######################################################################
1212 # startservers() starts all the named servers
1219 $what =~ s/[^a-z]//g;
1220 if($what eq "ftp") {
1222 $pid = runftpserver($verbose);
1224 return 2; # error starting it
1226 printf ("* pid ftp => %-5d\n", $pid) if($verbose);
1230 elsif($what eq "http") {
1232 $pid = runhttpserver($verbose);
1234 return 2; # error starting
1236 printf ("* pid http => %-5d\n", $pid) if($verbose);
1240 elsif($what eq "ftps") {
1241 if(!$stunnel || !$ssl_version) {
1242 # we can't run ftps tests without stunnel
1243 # or if libcurl is SSL-less
1247 $pid = runftpserver($verbose);
1249 return 2; # error starting it
1256 $pid = runftpsserver($verbose);
1260 printf ("* pid ftps => %-5d\n", $pid) if($verbose);
1264 elsif($what eq "file") {
1265 # we support it but have no server!
1267 elsif($what eq "https") {
1268 if(!$stunnel || !$ssl_version) {
1269 # we can't run https tests without stunnel
1270 # or if libcurl is SSL-less
1274 $pid = runhttpserver($verbose);
1276 return 2; # problems starting server
1280 if(!$run{'https'}) {
1281 $pid = runhttpsserver($verbose);
1285 printf ("* pid https => %-5d\n", $pid) if($verbose);
1289 elsif($what eq "none") {
1292 warn "we don't support a server for $what";
1298 ##############################################################################
1299 # This function makes sure the right set of server is running for the
1300 # specified test case. This is a useful design when we run single tests as not
1301 # all servers need to run then!
1304 # 100 if this is not a test case
1305 # 99 if this test case has no servers specified
1306 # 3 if this test is skipped due to no FTPS server
1307 # 2 if one of the required servers couldn't be started
1308 # 1 if this test is skipped due to no HTTPS server
1313 # load the test case file definition
1314 if(loadtest("${TESTDIR}/test${testnum}")) {
1316 # this is not a test
1317 print "$testnum doesn't look like a test case!\n";
1322 my @what = getpart("client", "server");
1325 warn "Test case $testnum has no server(s) specified!";
1329 return &startservers(@what);
1332 #######################################################################
1333 # Check options to this test program
1340 if ($ARGV[0] eq "-v") {
1344 elsif ($ARGV[0] eq "-c") {
1345 # use this path to curl instead of default
1349 elsif ($ARGV[0] eq "-d") {
1350 # have the servers display protocol output
1353 elsif ($ARGV[0] eq "-g") {
1354 # run this test with gdb
1357 elsif($ARGV[0] eq "-s") {
1361 elsif($ARGV[0] eq "-n") {
1365 elsif($ARGV[0] =~ /^-t(.*)/) {
1369 if($xtra =~ s/^(\d+)//) {
1372 if($xtra =~ s/(\d+)$//) {
1376 elsif($ARGV[0] eq "-a") {
1377 # continue anyway, even if a test fail
1380 elsif($ARGV[0] eq "-l") {
1381 # lists the test case names only
1384 elsif($ARGV[0] eq "-k") {
1385 # keep stdout and stderr files after tests
1388 elsif($ARGV[0] eq "-h") {
1391 Usage: runtests.pl [options]
1392 -a continue even if a test fails
1393 -d display server debug info
1394 -g run the test case with gdb
1396 -k keep stdout and stderr files present after tests
1397 -l list all test case names/descriptions
1402 [num] like "5 6 9" or " 5 to 22 " to run those tests only
1407 elsif($ARGV[0] =~ /^(\d+)/) {
1410 for($fromnum .. $number) {
1419 elsif($ARGV[0] =~ /^to$/i) {
1420 $fromnum = $number+1;
1422 } while(shift @ARGV);
1424 if($testthis[0] ne "") {
1425 $TESTCASES=join(" ", @testthis);
1429 # we have found valgrind on the host, use it
1431 # verify that we can invoke it fine
1432 my $code = system("valgrind >/dev/null 2>&1");
1434 if(($code>>8) != 1) {
1435 #print "Valgrind failure, disable it\n";
1439 $CURL="valgrind --leak-check=yes --logfile-fd=3 -q $CURL";
1443 #######################################################################
1444 # Output curl version and host info being tested
1451 #######################################################################
1452 # clear and create logging directory:
1455 mkdir($LOGDIR, 0777);
1457 #######################################################################
1458 # If 'all' tests are requested, find out all test numbers
1461 if ( $TESTCASES eq "all") {
1462 # Get all commands and find out their test numbers
1463 opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
1464 my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
1467 $TESTCASES=""; # start with no test cases
1469 # cut off everything but the digits
1471 $_ =~ s/[a-z\/\.]*//g;
1473 # the the numbers from low to high
1474 for(sort { $a <=> $b } @cmds) {
1475 $TESTCASES .= " $_";
1479 #######################################################################
1480 # Start the command line log
1482 open(CMDLOG, ">$CURLLOG") ||
1483 print "can't log command lines to $CURLLOG\n";
1485 #######################################################################
1486 # Torture the memory allocation system and checks
1491 #######################################################################
1492 # The main test-loop
1501 foreach $testnum (split(" ", $TESTCASES)) {
1503 $lasttest = $testnum if($testnum > $lasttest);
1505 my $error = singletest($testnum);
1507 # not a test we can run
1511 $total++; # number of tests we've run
1514 $failed.= "$testnum ";
1516 # a test failed, abort
1517 print "\n - abort tests\n";
1522 $ok++; # successful test counter
1525 # loop for next test
1528 #######################################################################
1534 # Tests done, stop the servers
1537 my $all = $total + $skipped;
1540 printf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
1544 print "TESTFAIL: These test cases failed: $failed\n";
1548 print "TESTFAIL: No tests were performed!\n";
1552 print "TESTDONE: $all tests were considered.\n";
1557 print "TESTINFO: $skipped tests were skipped due to these restraints:\n";
1559 for(keys %skipped) {
1561 printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
1563 # now show all test case numbers that had this reason for being
1566 for(0 .. $lasttest) {
1568 if($teststat[$_] eq $r) {
1577 if($total && ($ok != $total)) {