2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2013, 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 ###########################################################################
24 # Experimental hooks are available to run tests remotely on machines that
25 # are able to run curl but are unable to run the test harness.
26 # The following sections need to be modified:
28 # $HOSTIP, $HOST6IP - Set to the address of the host running the test suite
29 # $CLIENTIP, $CLIENT6IP - Set to the address of the host running curl
30 # runclient, runclientoutput - Modify to copy all the files in the log/
31 # directory to the system running curl, run the given command remotely
32 # and save the return code or returned stdout (respectively), then
33 # copy all the files from the remote system's log/ directory back to
34 # the host running the test suite. This can be done a few ways, such
35 # as using scp & ssh, rsync & telnet, or using a NFS shared directory
38 # 'make && make test' needs to be done on both machines before making the
39 # above changes and running runtests.pl manually. In the shared NFS case,
40 # the contents of the tests/server/ directory must be from the host
41 # running the test suite, while the rest must be from the host running curl.
43 # Note that even with these changes a number of tests will still fail (mainly
44 # to do with cookies, those that set environment variables, or those that
45 # do more than touch the file system in a <precheck> or <postcheck>
46 # section). These can be added to the $TESTCASES line below,
47 # e.g. $TESTCASES="!8 !31 !63 !cookies..."
49 # Finally, to properly support -g and -n, checktestcmd needs to change
50 # to check the remote system's PATH, and the places in the code where
51 # the curl binary is read directly to determine its type also need to be
52 # fixed. As long as the -g option is never given, and the -n is always
53 # given, this won't be a problem.
56 # These should be the only variables that might be needed to get edited:
59 push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
61 # run time statistics needs Time::HiRes
65 import Time::HiRes qw( time );
73 # Subs imported from serverhelp module
83 # Variables and subs imported from sshhelp module
108 require "getpart.pm"; # array functions
109 require "valgrind.pm"; # valgrind report parser
112 my $HOSTIP="127.0.0.1"; # address on which the test server listens
113 my $HOST6IP="[::1]"; # address on which the test server listens
114 my $CLIENTIP="127.0.0.1"; # address which curl uses for incoming connections
115 my $CLIENT6IP="[::1]"; # address which curl uses for incoming connections
117 my $base = 8990; # base port number
119 my $HTTPPORT; # HTTP server port
120 my $HTTP6PORT; # HTTP IPv6 server port
121 my $HTTPSPORT; # HTTPS (stunnel) server port
122 my $FTPPORT; # FTP server port
123 my $FTP2PORT; # FTP server 2 port
124 my $FTPSPORT; # FTPS (stunnel) server port
125 my $FTP6PORT; # FTP IPv6 server port
127 my $TFTP6PORT; # TFTP
128 my $SSHPORT; # SCP/SFTP
129 my $SOCKSPORT; # SOCKS4/5 port
131 my $POP36PORT; # POP3 IPv6 server port
133 my $IMAP6PORT; # IMAP IPv6 server port
135 my $SMTP6PORT; # SMTP IPv6 server port
137 my $RTSP6PORT; # RTSP IPv6 server port
138 my $GOPHERPORT; # Gopher
139 my $GOPHER6PORT; # Gopher IPv6 server port
140 my $HTTPTLSPORT; # HTTP TLS (non-stunnel) server port
141 my $HTTPTLS6PORT; # HTTP TLS (non-stunnel) IPv6 server port
142 my $HTTPPROXYPORT; # HTTP proxy port, when using CONNECT
143 my $HTTPPIPEPORT; # HTTP pipelining port
145 my $srcdir = $ENV{'srcdir'} || '.';
146 my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests
147 my $VCURL=$CURL; # what curl binary to use to verify the servers with
148 # VCURL is handy to set to the system one when the one you
149 # just built hangs or crashes and thus prevent verification
150 my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
152 my $TESTDIR="$srcdir/data";
153 my $LIBDIR="./libtest";
154 my $UNITDIR="./unit";
155 # TODO: change this to use server_inputfilename()
156 my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
157 my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
158 my $PROXYIN="$LOGDIR/proxy.input"; # what curl sent the proxy
159 my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
160 my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
161 my $SERVERLOGS_LOCK="$LOGDIR/serverlogs.lock"; # server logs advisor read lock
162 my $CURLCONFIG="../curl-config"; # curl-config from current build
164 # Normally, all test cases should be run, but at times it is handy to
165 # simply run a particular one:
168 # To run specific test cases, set them like:
169 # $TESTCASES="1 2 3 7 8";
171 #######################################################################
172 # No variables below this point should need to be modified
175 # invoke perl like this:
176 my $perl="perl -I$srcdir";
177 my $server_response_maxtime=13;
179 my $debug_build=0; # built debug enabled (--enable-debug)
180 my $has_memory_tracking=0; # built with memory tracking (--enable-curldebug)
183 # name of the file that the memory debugging creates:
184 my $memdump="$LOGDIR/memdump";
186 # the path to the script that analyzes the memory debug output file:
187 my $memanalyze="$perl $srcdir/memanalyze.pl";
189 my $pwd = getcwd(); # current working directory
192 my $ftpchecktime=1; # time it took to verify our test FTP server
194 my $stunnel = checkcmd("stunnel4") || checkcmd("tstunnel") || checkcmd("stunnel");
195 my $valgrind = checktestcmd("valgrind");
196 my $valgrind_logfile="--logfile";
198 my $gdb = checktestcmd("gdb");
199 my $httptlssrv = find_httptlssrv();
201 my $ssl_version; # set if libcurl is built with SSL support
202 my $large_file; # set if libcurl is built with large file support
203 my $has_idn; # set if libcurl is built with IDN support
204 my $http_ipv6; # set if HTTP server has IPv6 support
205 my $ftp_ipv6; # set if FTP server has IPv6 support
206 my $tftp_ipv6; # set if TFTP server has IPv6 support
207 my $gopher_ipv6; # set if Gopher server has IPv6 support
208 my $has_ipv6; # set if libcurl is built with IPv6 support
209 my $has_libz; # set if libcurl is built with libz support
210 my $has_getrlimit; # set if system has getrlimit()
211 my $has_ntlm; # set if libcurl is built with NTLM support
212 my $has_ntlm_wb; # set if libcurl is built with NTLM delegation to winbind
213 my $has_sspi; # set if libcurl is built with SSPI support
214 my $has_charconv;# set if libcurl is built with CharConv support
215 my $has_tls_srp; # set if libcurl is built with TLS-SRP support
216 my $has_metalink;# set if curl is built with Metalink support
218 my $has_openssl; # built with a lib using an OpenSSL-like API
219 my $has_gnutls; # built with GnuTLS
220 my $has_nss; # built with NSS
221 my $has_yassl; # built with yassl
222 my $has_polarssl; # built with polarssl
223 my $has_axtls; # built with axTLS
224 my $has_winssl; # built with WinSSL (Secure Channel aka Schannel)
225 my $has_darwinssl;# build with DarwinSSL (Secure Transport)
227 my $has_shared = "unknown"; # built shared
229 my $ssllib; # name of the lib we use (for human presentation)
230 my $has_crypto; # set if libcurl is built with cryptographic support
231 my $has_textaware; # set if running on a system that has a text mode concept
232 # on files. Windows for example
234 my @protocols; # array of lowercase supported protocol servers
236 my $skipped=0; # number of tests skipped; reported in main loop
237 my %skipped; # skipped{reason}=counter, reasons for skip
238 my @teststat; # teststat[testnum]=reason, reasons for skip
239 my %disabled_keywords; # key words of tests to skip
240 my %enabled_keywords; # key words of tests to run
241 my %disabled; # disabled test cases
243 my $sshdid; # for socks server, ssh daemon version id
244 my $sshdvernum; # for socks server, ssh daemon version number
245 my $sshdverstr; # for socks server, ssh daemon version string
246 my $sshderror; # for socks server, ssh daemon version error
248 my $defserverlogslocktimeout = 20; # timeout to await server logs lock removal
249 my $defpostcommanddelay = 0; # delay between command and postcheck sections
251 my $timestats; # time stamping and stats generation
252 my $fullstats; # show time stats for every single test
253 my %timeprepini; # timestamp for each test preparation start
254 my %timesrvrini; # timestamp for each test required servers verification start
255 my %timesrvrend; # timestamp for each test required servers verification end
256 my %timetoolini; # timestamp for each test command run starting
257 my %timetoolend; # timestamp for each test command run stopping
258 my %timesrvrlog; # timestamp for each test server logs lock removal
259 my %timevrfyend; # timestamp for each test result verification end
261 my $testnumcheck; # test number, set in singletest sub.
264 #######################################################################
265 # variables that command line options may set
273 my $gdbthis; # run test case with gdb debugger
274 my $gdbxwin; # use windowed gdb when using gdb
275 my $keepoutfiles; # keep stdout and stderr files after tests
276 my $listonly; # only list the tests
277 my $postmortem; # display detailed info about failed tests
278 my $run_event_based; # run curl with --test-event to test the event API
280 my %run; # running server
281 my %doesntrun; # servers that don't work, identified by pidfile
282 my %serverpidfile;# all server pid file names, identified by server id
283 my %runcert; # cert file currently in use by an ssl running server
285 # torture test variables
290 #######################################################################
291 # logmsg is our general message logging subroutine.
299 # get the name of the current user
300 my $USER = $ENV{USER}; # Linux
302 $USER = $ENV{USERNAME}; # Windows
304 $USER = $ENV{LOGNAME}; # Some UNIX (I think)
308 # enable memory debugging if curl is compiled with it
309 $ENV{'CURL_MEMDEBUG'} = $memdump;
314 logmsg "runtests.pl received SIG$signame, exiting\n";
315 stopservers($verbose);
316 die "Somebody sent me a SIG$signame";
318 $SIG{INT} = \&catch_zap;
319 $SIG{TERM} = \&catch_zap;
321 ##########################################################################
322 # Clear all possible '*_proxy' environment variables for various protocols
323 # to prevent them to interfere with our testing!
326 foreach $protocol (('ftp', 'http', 'ftps', 'https', 'no', 'all')) {
327 my $proxy = "${protocol}_proxy";
328 # clear lowercase version
329 delete $ENV{$proxy} if($ENV{$proxy});
330 # clear uppercase version
331 delete $ENV{uc($proxy)} if($ENV{uc($proxy)});
334 # make sure we don't get affected by other variables that control our
337 delete $ENV{'SSL_CERT_DIR'} if($ENV{'SSL_CERT_DIR'});
338 delete $ENV{'SSL_CERT_PATH'} if($ENV{'SSL_CERT_PATH'});
339 delete $ENV{'CURL_CA_BUNDLE'} if($ENV{'CURL_CA_BUNDLE'});
341 #######################################################################
342 # Load serverpidfile hash with pidfile names for all possible servers.
344 sub init_serverpidfile_hash {
345 for my $proto (('ftp', 'http', 'imap', 'pop3', 'smtp', 'http')) {
346 for my $ssl (('', 's')) {
347 for my $ipvnum ((4, 6)) {
348 for my $idnum ((1, 2, 3)) {
349 my $serv = servername_id("$proto$ssl", $ipvnum, $idnum);
350 my $pidf = server_pidfilename("$proto$ssl", $ipvnum, $idnum);
351 $serverpidfile{$serv} = $pidf;
356 for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'gopher', 'httptls')) {
357 for my $ipvnum ((4, 6)) {
358 for my $idnum ((1, 2)) {
359 my $serv = servername_id($proto, $ipvnum, $idnum);
360 my $pidf = server_pidfilename($proto, $ipvnum, $idnum);
361 $serverpidfile{$serv} = $pidf;
367 #######################################################################
368 # Check if a given child process has just died. Reaps it if so.
371 use POSIX ":sys_wait_h";
373 if(not defined $pid || $pid <= 0) {
376 my $rc = waitpid($pid, &WNOHANG);
377 return ($rc == $pid)?1:0;
380 #######################################################################
381 # Start a new thread/process and run the given command line in there.
382 # Return the pids (yes plural) of the new child process to the parent.
385 my ($cmd, $pidfile, $timeout, $fake)=@_;
387 logmsg "startnew: $cmd\n" if ($verbose);
392 if(not defined $child) {
393 logmsg "startnew: fork() failure detected\n";
398 # Here we are the child. Run the given command.
400 # Put an "exec" in front of the command so that the child process
401 # keeps this child's process ID.
402 exec("exec $cmd") || die "Can't exec() $cmd: $!";
404 # exec() should never return back here to this process. We protect
405 # ourselves by calling die() just in case something goes really bad.
406 die "error: exec() has returned";
409 # Ugly hack but ssh client and gnutls-serv don't support pid files
411 if(open(OUT, ">$pidfile")) {
412 print OUT $child . "\n";
414 logmsg "startnew: $pidfile faked with pid=$child\n" if($verbose);
417 logmsg "startnew: failed to write fake $pidfile with pid=$child\n";
419 # could/should do a while connect fails sleep a bit and loop
421 if (checkdied($child)) {
422 logmsg "startnew: child process has failed to start\n" if($verbose);
427 my $count = $timeout;
429 if(-f $pidfile && -s $pidfile && open(PID, "<$pidfile")) {
432 if(($pid2 > 0) && pidexists($pid2)) {
433 # if $pid2 is valid, then make sure this pid is alive, as
434 # otherwise it is just likely to be the _previous_ pidfile or
438 # invalidate $pid2 if not actually alive
441 if (checkdied($child)) {
442 logmsg "startnew: child process has died, server might start up\n"
444 # We can't just abort waiting for the server with a
446 # because the server might have forked and could still start
447 # up normally. Instead, just reduce the amount of time we remain
454 # Return two PIDs, the one for the child process we spawned and the one
455 # reported by the server itself (in case it forked again on its own).
456 # Both (potentially) need to be killed at the end of the test.
457 return ($child, $pid2);
461 #######################################################################
462 # Check for a command in the PATH of the test server.
466 my @paths=(split(":", $ENV{'PATH'}), "/usr/sbin", "/usr/local/sbin",
467 "/sbin", "/usr/bin", "/usr/local/bin",
468 "./libtest/.libs", "./libtest");
470 if( -x "$_/$cmd" && ! -d "$_/$cmd") {
471 # executable bit but not a directory!
477 #######################################################################
478 # Get the list of tests that the tests/data/Makefile.am knows about!
482 my @dist = `cd data && make show`;
483 $disttests = join("", @dist);
486 #######################################################################
487 # Check for a command in the PATH of the machine running curl.
491 return checkcmd($cmd);
494 #######################################################################
495 # Run the application under test and return its return code
499 my $ret = system($cmd);
500 print "CMD ($ret): $cmd\n" if($verbose);
503 # This is one way to test curl on a remote machine
504 # my $out = system("ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'");
505 # sleep 2; # time to allow the NFS server to be updated
509 #######################################################################
510 # Run the application under test and return its stdout
512 sub runclientoutput {
516 # This is one way to test curl on a remote machine
517 # my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`;
518 # sleep 2; # time to allow the NFS server to be updated
522 #######################################################################
523 # Memory allocation test and failure torture testing.
529 # remove memdump first to be sure we get a new nice and clean one
532 # First get URL from test server, ignore the output/result
535 logmsg " CMD: $testcmd\n" if($verbose);
537 # memanalyze -v is our friend, get the number of allocations made
539 my @out = `$memanalyze -v $memdump`;
541 if(/^Allocations: (\d+)/) {
547 logmsg " found no allocs to make fail\n";
551 logmsg " $count allocations to make fail\n";
553 for ( 1 .. $count ) {
558 if($tortalloc && ($tortalloc != $limit)) {
563 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
565 my $now = sprintf("%02d:%02d:%02d ", $hour, $min, $sec);
566 logmsg "Fail alloc no: $limit at $now\r";
569 # make the memory allocation function number $limit return failure
570 $ENV{'CURL_MEMLIMIT'} = $limit;
572 # remove memdump first to be sure we get a new nice and clean one
575 logmsg "*** Alloc number $limit is now set to fail ***\n" if($gdbthis);
582 $ret = runclient($testcmd);
584 #logmsg "$_ Returned " . $ret >> 8 . "\n";
586 # Now clear the variable again
587 delete $ENV{'CURL_MEMLIMIT'} if($ENV{'CURL_MEMLIMIT'});
590 # there's core file present now!
591 logmsg " core dumped\n";
596 # verify that it returns a proper error code, doesn't leak memory
597 # and doesn't core dump
599 logmsg " system() returned $ret\n";
603 my @memdata=`$memanalyze $memdump`;
607 # well it could be other memory problems as well, but
608 # we call it leak for short here
613 logmsg "** MEMORY FAILURE\n";
615 logmsg `$memanalyze -l $memdump`;
620 logmsg " Failed on alloc number $limit in test.\n",
621 " invoke with \"-t$limit\" to repeat this single case.\n";
622 stopservers($verbose);
627 logmsg "torture OK\n";
631 #######################################################################
632 # Stop a test server along with pids which aren't in the %run hash yet.
633 # This also stops all servers which are relative to the given one.
636 my ($server, $pidlist) = @_;
638 # kill sockfilter processes for pingpong relative server
640 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
642 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
643 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
644 killsockfilters($proto, $ipvnum, $idnum, $verbose);
647 # All servers relative to the given one must be stopped also
650 if($server =~ /^(ftp|http|imap|pop3|smtp|httppipe)s((\d*)(-ipv6|))$/) {
651 # given a stunnel based ssl server, also kill non-ssl underlying one
652 push @killservers, "${1}${2}";
654 elsif($server =~ /^(ftp|http|imap|pop3|smtp|httppipe)((\d*)(-ipv6|))$/) {
655 # given a non-ssl server, also kill stunnel based ssl piggybacking one
656 push @killservers, "${1}s${2}";
658 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
659 # given a socks server, also kill ssh underlying one
660 push @killservers, "ssh${2}";
662 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
663 # given a ssh server, also kill socks piggybacking one
664 push @killservers, "socks${2}";
666 push @killservers, $server;
668 # kill given pids and server relative ones clearing them in %run hash
670 foreach my $server (@killservers) {
672 # we must prepend a space since $pidlist may already contain a pid
673 $pidlist .= " $run{$server}";
676 $runcert{$server} = 0 if($runcert{$server});
678 killpid($verbose, $pidlist);
680 # cleanup server pid files
682 foreach my $server (@killservers) {
683 my $pidfile = $serverpidfile{$server};
684 my $pid = processexists($pidfile);
686 logmsg "Warning: $server server unexpectedly alive\n";
687 killpid($verbose, $pid);
689 unlink($pidfile) if(-f $pidfile);
693 #######################################################################
694 # Verify that the server that runs on $ip, $port is our server. This also
695 # implies that we can speak with it, as there might be occasions when the
696 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
697 # assign requested address")
700 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
701 my $server = servername_id($proto, $ipvnum, $idnum);
705 my $verifyout = "$LOGDIR/".
706 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
707 unlink($verifyout) if(-f $verifyout);
709 my $verifylog = "$LOGDIR/".
710 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
711 unlink($verifylog) if(-f $verifylog);
713 if($proto eq "gopher") {
718 my $flags = "--max-time $server_response_maxtime ";
719 $flags .= "--output $verifyout ";
720 $flags .= "--silent ";
721 $flags .= "--verbose ";
722 $flags .= "--globoff ";
723 $flags .= "-1 " if($has_axtls);
724 $flags .= "--insecure " if($proto eq 'https');
725 $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\"";
727 my $cmd = "$VCURL $flags 2>$verifylog";
729 # verify if our/any server is running on this port
730 logmsg "RUN: $cmd\n" if($verbose);
731 my $res = runclient($cmd);
733 $res >>= 8; # rotate the result
735 logmsg "RUN: curl command died with a coredump\n";
739 if($res && $verbose) {
740 logmsg "RUN: curl command returned $res\n";
741 if(open(FILE, "<$verifylog")) {
742 while(my $string = <FILE>) {
743 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
750 if(open(FILE, "<$verifyout")) {
751 while(my $string = <FILE>) {
753 last; # only want first line
758 if($data && ($data =~ /WE ROOLZ: (\d+)/)) {
762 # curl: (6) Couldn't resolve host '::1'
763 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
766 elsif($data || ($res && ($res != 7))) {
767 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
773 #######################################################################
774 # Verify that the server that runs on $ip, $port is our server. This also
775 # implies that we can speak with it, as there might be occasions when the
776 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
777 # assign requested address")
780 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
781 my $server = servername_id($proto, $ipvnum, $idnum);
786 my $verifylog = "$LOGDIR/".
787 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
788 unlink($verifylog) if(-f $verifylog);
790 if($proto eq "ftps") {
791 $extra .= "--insecure --ftp-ssl-control ";
794 my $flags = "--max-time $server_response_maxtime ";
795 $flags .= "--silent ";
796 $flags .= "--verbose ";
797 $flags .= "--globoff ";
799 $flags .= "\"$proto://$ip:$port/verifiedserver\"";
801 my $cmd = "$VCURL $flags 2>$verifylog";
803 # check if this is our server running on this port:
804 logmsg "RUN: $cmd\n" if($verbose);
805 my @data = runclientoutput($cmd);
807 my $res = $? >> 8; # rotate the result
809 logmsg "RUN: curl command died with a coredump\n";
813 foreach my $line (@data) {
814 if($line =~ /WE ROOLZ: (\d+)/) {
815 # this is our test server with a known pid!
820 if($pid <= 0 && @data && $data[0]) {
821 # this is not a known server
822 logmsg "RUN: Unknown server on our $server port: $port\n";
825 # we can/should use the time it took to verify the FTP server as a measure
826 # on how fast/slow this host/FTP is.
827 my $took = int(0.5+time()-$time);
830 logmsg "RUN: Verifying our test $server server took $took seconds\n";
832 $ftpchecktime = $took>=1?$took:1; # make sure it never is below 1
837 #######################################################################
838 # Verify that the server that runs on $ip, $port is our server. This also
839 # implies that we can speak with it, as there might be occasions when the
840 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
841 # assign requested address")
844 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
845 my $server = servername_id($proto, $ipvnum, $idnum);
848 my $verifyout = "$LOGDIR/".
849 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
850 unlink($verifyout) if(-f $verifyout);
852 my $verifylog = "$LOGDIR/".
853 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
854 unlink($verifylog) if(-f $verifylog);
856 my $flags = "--max-time $server_response_maxtime ";
857 $flags .= "--output $verifyout ";
858 $flags .= "--silent ";
859 $flags .= "--verbose ";
860 $flags .= "--globoff ";
861 # currently verification is done using http
862 $flags .= "\"http://$ip:$port/verifiedserver\"";
864 my $cmd = "$VCURL $flags 2>$verifylog";
866 # verify if our/any server is running on this port
867 logmsg "RUN: $cmd\n" if($verbose);
868 my $res = runclient($cmd);
870 $res >>= 8; # rotate the result
872 logmsg "RUN: curl command died with a coredump\n";
876 if($res && $verbose) {
877 logmsg "RUN: curl command returned $res\n";
878 if(open(FILE, "<$verifylog")) {
879 while(my $string = <FILE>) {
880 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
887 if(open(FILE, "<$verifyout")) {
888 while(my $string = <FILE>) {
890 last; # only want first line
895 if($data && ($data =~ /RTSP_SERVER WE ROOLZ: (\d+)/)) {
899 # curl: (6) Couldn't resolve host '::1'
900 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
903 elsif($data || ($res != 7)) {
904 logmsg "RUN: Unknown server on our $server port: $port\n";
910 #######################################################################
911 # Verify that the ssh server has written out its pidfile, recovering
912 # the pid from the file and returning it if a process with that pid is
916 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
917 my $server = servername_id($proto, $ipvnum, $idnum);
918 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
920 if(open(FILE, "<$pidfile")) {
925 # if we have a pid it is actually our ssh server,
926 # since runsshserver() unlinks previous pidfile
927 if(!pidexists($pid)) {
928 logmsg "RUN: SSH server has died after starting up\n";
937 #######################################################################
938 # Verify that we can connect to the sftp server, properly authenticate
939 # with generated config and key files and run a simple remote pwd.
942 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
943 my $server = servername_id($proto, $ipvnum, $idnum);
945 # Find out sftp client canonical file name
946 my $sftp = find_sftp();
948 logmsg "RUN: SFTP server cannot find $sftpexe\n";
951 # Find out ssh client canonical file name
952 my $ssh = find_ssh();
954 logmsg "RUN: SFTP server cannot find $sshexe\n";
957 # Connect to sftp server, authenticate and run a remote pwd
958 # command using our generated configuration and key files
959 my $cmd = "$sftp -b $sftpcmds -F $sftpconfig -S $ssh $ip > $sftplog 2>&1";
960 my $res = runclient($cmd);
961 # Search for pwd command response in log file
962 if(open(SFTPLOGFILE, "<$sftplog")) {
963 while(<SFTPLOGFILE>) {
964 if(/^Remote working directory: /) {
974 #######################################################################
975 # Verify that the non-stunnel HTTP TLS extensions capable server that runs
976 # on $ip, $port is our server. This also implies that we can speak with it,
977 # as there might be occasions when the server runs fine but we cannot talk
978 # to it ("Failed to connect to ::1: Can't assign requested address")
981 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
982 my $server = servername_id($proto, $ipvnum, $idnum);
983 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
986 my $verifyout = "$LOGDIR/".
987 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
988 unlink($verifyout) if(-f $verifyout);
990 my $verifylog = "$LOGDIR/".
991 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
992 unlink($verifylog) if(-f $verifylog);
994 my $flags = "--max-time $server_response_maxtime ";
995 $flags .= "--output $verifyout ";
996 $flags .= "--verbose ";
997 $flags .= "--globoff ";
998 $flags .= "--insecure ";
999 $flags .= "--tlsauthtype SRP ";
1000 $flags .= "--tlsuser jsmith ";
1001 $flags .= "--tlspassword abc ";
1002 $flags .= "\"https://$ip:$port/verifiedserver\"";
1004 my $cmd = "$VCURL $flags 2>$verifylog";
1006 # verify if our/any server is running on this port
1007 logmsg "RUN: $cmd\n" if($verbose);
1008 my $res = runclient($cmd);
1010 $res >>= 8; # rotate the result
1012 logmsg "RUN: curl command died with a coredump\n";
1016 if($res && $verbose) {
1017 logmsg "RUN: curl command returned $res\n";
1018 if(open(FILE, "<$verifylog")) {
1019 while(my $string = <FILE>) {
1020 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
1027 if(open(FILE, "<$verifyout")) {
1028 while(my $string = <FILE>) {
1034 if($data && ($data =~ /GNUTLS/) && open(FILE, "<$pidfile")) {
1038 # if we have a pid it is actually our httptls server,
1039 # since runhttptlsserver() unlinks previous pidfile
1040 if(!pidexists($pid)) {
1041 logmsg "RUN: $server server has died after starting up\n";
1050 # curl: (6) Couldn't resolve host '::1'
1051 logmsg "RUN: failed to resolve host (https://$ip:$port/verifiedserver)\n";
1054 elsif($data || ($res && ($res != 7))) {
1055 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
1061 #######################################################################
1062 # STUB for verifying socks
1065 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1066 my $server = servername_id($proto, $ipvnum, $idnum);
1067 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
1069 if(open(FILE, "<$pidfile")) {
1074 # if we have a pid it is actually our socks server,
1075 # since runsocksserver() unlinks previous pidfile
1076 if(!pidexists($pid)) {
1077 logmsg "RUN: SOCKS server has died after starting up\n";
1086 #######################################################################
1087 # Verify that the server that runs on $ip, $port is our server.
1088 # Retry over several seconds before giving up. The ssh server in
1089 # particular can take a long time to start if it needs to generate
1090 # keys on a slow or loaded host.
1092 # Just for convenience, test harness uses 'https' and 'httptls' literals
1093 # as values for 'proto' variable in order to differentiate different
1094 # servers. 'https' literal is used for stunnel based https test servers,
1095 # and 'httptls' is used for non-stunnel https test servers.
1098 my %protofunc = ('http' => \&verifyhttp,
1099 'https' => \&verifyhttp,
1100 'rtsp' => \&verifyrtsp,
1101 'ftp' => \&verifyftp,
1102 'pop3' => \&verifyftp,
1103 'imap' => \&verifyftp,
1104 'smtp' => \&verifyftp,
1105 'httppipe' => \&verifyhttp,
1106 'ftps' => \&verifyftp,
1107 'tftp' => \&verifyftp,
1108 'ssh' => \&verifyssh,
1109 'socks' => \&verifysocks,
1110 'gopher' => \&verifyhttp,
1111 'httptls' => \&verifyhttptls);
1114 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1116 my $count = 30; # try for this many seconds
1120 my $fun = $protofunc{$proto};
1122 $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1128 # a real failure, stop trying and bail out
1136 #######################################################################
1137 # Single shot server responsiveness test. This should only be used
1138 # to verify that a server present in %run hash is still functional
1140 sub responsiveserver {
1141 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1142 my $prev_verbose = $verbose;
1145 my $fun = $protofunc{$proto};
1146 my $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1147 $verbose = $prev_verbose;
1150 return 1; # responsive
1153 my $srvrname = servername_str($proto, $ipvnum, $idnum);
1154 logmsg " server precheck FAILED (unresponsive $srvrname server)\n";
1158 #######################################################################
1159 # start the http server
1162 my ($proto, $verbose, $alt, $port) = @_;
1171 my $exe = "$perl $srcdir/httpserver.pl";
1172 my $verbose_flag = "--verbose ";
1174 if($alt eq "ipv6") {
1175 # if IPv6, use a different setup
1179 elsif($alt eq "proxy") {
1180 # basically the same, but another ID
1183 elsif($alt eq "pipe") {
1184 # basically the same, but another ID
1186 $exe = "python $srcdir/http_pipe.py";
1187 $verbose_flag .= "1 ";
1190 $server = servername_id($proto, $ipvnum, $idnum);
1192 $pidfile = $serverpidfile{$server};
1194 # don't retry if the server doesn't work
1195 if ($doesntrun{$pidfile}) {
1199 my $pid = processexists($pidfile);
1201 stopserver($server, "$pid");
1203 unlink($pidfile) if(-f $pidfile);
1205 $srvrname = servername_str($proto, $ipvnum, $idnum);
1207 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1209 $flags .= "--gopher " if($proto eq "gopher");
1210 $flags .= "--connect $HOSTIP " if($alt eq "proxy");
1211 $flags .= $verbose_flag if($debugprotocol);
1212 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1213 $flags .= "--id $idnum " if($idnum > 1);
1214 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1216 my $cmd = "$exe $flags";
1217 my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1219 if($httppid <= 0 || !pidexists($httppid)) {
1221 logmsg "RUN: failed to start the $srvrname server\n";
1222 stopserver($server, "$pid2");
1223 displaylogs($testnumcheck);
1224 $doesntrun{$pidfile} = 1;
1228 # Server is up. Verify that we can speak to it.
1229 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1231 logmsg "RUN: $srvrname server failed verification\n";
1232 # failed to talk to it properly. Kill the server and return failure
1233 stopserver($server, "$httppid $pid2");
1234 displaylogs($testnumcheck);
1235 $doesntrun{$pidfile} = 1;
1241 logmsg "RUN: $srvrname server is now running PID $httppid\n";
1246 return ($httppid, $pid2);
1249 #######################################################################
1250 # start the http server
1252 sub runhttp_pipeserver {
1253 my ($proto, $verbose, $alt, $port) = @_;
1263 if($alt eq "ipv6") {
1267 $server = servername_id($proto, $ipvnum, $idnum);
1269 $pidfile = $serverpidfile{$server};
1271 # don't retry if the server doesn't work
1272 if ($doesntrun{$pidfile}) {
1276 my $pid = processexists($pidfile);
1278 stopserver($server, "$pid");
1280 unlink($pidfile) if(-f $pidfile);
1282 $srvrname = servername_str($proto, $ipvnum, $idnum);
1284 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1286 $flags .= "--verbose 1 " if($debugprotocol);
1287 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1288 $flags .= "--id $idnum " if($idnum > 1);
1289 $flags .= "--port $port --srcdir \"$srcdir\"";
1291 my $cmd = "$srcdir/http_pipe.py $flags";
1292 my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1294 if($httppid <= 0 || !pidexists($httppid)) {
1296 logmsg "RUN: failed to start the $srvrname server\n";
1297 stopserver($server, "$pid2");
1298 displaylogs($testnumcheck);
1299 $doesntrun{$pidfile} = 1;
1303 # Server is up. Verify that we can speak to it.
1304 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1306 logmsg "RUN: $srvrname server failed verification\n";
1307 # failed to talk to it properly. Kill the server and return failure
1308 stopserver($server, "$httppid $pid2");
1309 displaylogs($testnumcheck);
1310 $doesntrun{$pidfile} = 1;
1316 logmsg "RUN: $srvrname server is now running PID $httppid\n";
1321 return ($httppid, $pid2);
1324 #######################################################################
1325 # start the https stunnel based server
1327 sub runhttpsserver {
1328 my ($verbose, $ipv6, $certfile) = @_;
1329 my $proto = 'https';
1330 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1331 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1343 $server = servername_id($proto, $ipvnum, $idnum);
1345 $pidfile = $serverpidfile{$server};
1347 # don't retry if the server doesn't work
1348 if ($doesntrun{$pidfile}) {
1352 my $pid = processexists($pidfile);
1354 stopserver($server, "$pid");
1356 unlink($pidfile) if(-f $pidfile);
1358 $srvrname = servername_str($proto, $ipvnum, $idnum);
1360 $certfile = 'stunnel.pem' unless($certfile);
1362 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1364 $flags .= "--verbose " if($debugprotocol);
1365 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1366 $flags .= "--id $idnum " if($idnum > 1);
1367 $flags .= "--ipv$ipvnum --proto $proto ";
1368 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1369 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1370 $flags .= "--connect $HTTPPORT --accept $HTTPSPORT";
1372 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1373 my ($httpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1375 if($httpspid <= 0 || !pidexists($httpspid)) {
1377 logmsg "RUN: failed to start the $srvrname server\n";
1378 stopserver($server, "$pid2");
1379 displaylogs($testnumcheck);
1380 $doesntrun{$pidfile} = 1;
1384 # Server is up. Verify that we can speak to it.
1385 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $HTTPSPORT);
1387 logmsg "RUN: $srvrname server failed verification\n";
1388 # failed to talk to it properly. Kill the server and return failure
1389 stopserver($server, "$httpspid $pid2");
1390 displaylogs($testnumcheck);
1391 $doesntrun{$pidfile} = 1;
1394 # Here pid3 is actually the pid returned by the unsecure-http server.
1396 $runcert{$server} = $certfile;
1399 logmsg "RUN: $srvrname server is now running PID $httpspid\n";
1404 return ($httpspid, $pid2);
1407 #######################################################################
1408 # start the non-stunnel HTTP TLS extensions capable server
1410 sub runhttptlsserver {
1411 my ($verbose, $ipv6) = @_;
1412 my $proto = "httptls";
1413 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
1414 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1415 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1427 $server = servername_id($proto, $ipvnum, $idnum);
1429 $pidfile = $serverpidfile{$server};
1431 # don't retry if the server doesn't work
1432 if ($doesntrun{$pidfile}) {
1436 my $pid = processexists($pidfile);
1438 stopserver($server, "$pid");
1440 unlink($pidfile) if(-f $pidfile);
1442 $srvrname = servername_str($proto, $ipvnum, $idnum);
1444 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1446 $flags .= "--http ";
1447 $flags .= "--debug 1 " if($debugprotocol);
1448 $flags .= "--port $port ";
1449 $flags .= "--srppasswd $srcdir/certs/srp-verifier-db ";
1450 $flags .= "--srppasswdconf $srcdir/certs/srp-verifier-conf";
1452 my $cmd = "$httptlssrv $flags > $logfile 2>&1";
1453 my ($httptlspid, $pid2) = startnew($cmd, $pidfile, 10, 1); # fake pidfile
1455 if($httptlspid <= 0 || !pidexists($httptlspid)) {
1457 logmsg "RUN: failed to start the $srvrname server\n";
1458 stopserver($server, "$pid2");
1459 displaylogs($testnumcheck);
1460 $doesntrun{$pidfile} = 1;
1464 # Server is up. Verify that we can speak to it. PID is from fake pidfile
1465 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1467 logmsg "RUN: $srvrname server failed verification\n";
1468 # failed to talk to it properly. Kill the server and return failure
1469 stopserver($server, "$httptlspid $pid2");
1470 displaylogs($testnumcheck);
1471 $doesntrun{$pidfile} = 1;
1477 logmsg "RUN: $srvrname server is now running PID $httptlspid\n";
1482 return ($httptlspid, $pid2);
1485 #######################################################################
1486 # start the pingpong server (FTP, POP3, IMAP, SMTP)
1488 sub runpingpongserver {
1489 my ($proto, $id, $verbose, $ipv6) = @_;
1491 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1492 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1493 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1500 if($proto eq "ftp") {
1501 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
1504 # if IPv6, use a different setup
1508 elsif($proto eq "pop3") {
1509 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
1511 elsif($proto eq "imap") {
1512 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
1514 elsif($proto eq "smtp") {
1515 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
1518 print STDERR "Unsupported protocol $proto!!\n";
1522 $server = servername_id($proto, $ipvnum, $idnum);
1524 $pidfile = $serverpidfile{$server};
1526 # don't retry if the server doesn't work
1527 if ($doesntrun{$pidfile}) {
1531 my $pid = processexists($pidfile);
1533 stopserver($server, "$pid");
1535 unlink($pidfile) if(-f $pidfile);
1537 $srvrname = servername_str($proto, $ipvnum, $idnum);
1539 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1541 $flags .= "--verbose " if($debugprotocol);
1542 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1543 $flags .= "--srcdir \"$srcdir\" --proto $proto ";
1544 $flags .= "--id $idnum " if($idnum > 1);
1545 $flags .= "--ipv$ipvnum --port $port --addr \"$ip\"";
1547 my $cmd = "$perl $srcdir/ftpserver.pl $flags";
1548 my ($ftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1550 if($ftppid <= 0 || !pidexists($ftppid)) {
1552 logmsg "RUN: failed to start the $srvrname server\n";
1553 stopserver($server, "$pid2");
1554 displaylogs($testnumcheck);
1555 $doesntrun{$pidfile} = 1;
1559 # Server is up. Verify that we can speak to it.
1560 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1562 logmsg "RUN: $srvrname server failed verification\n";
1563 # failed to talk to it properly. Kill the server and return failure
1564 stopserver($server, "$ftppid $pid2");
1565 displaylogs($testnumcheck);
1566 $doesntrun{$pidfile} = 1;
1573 logmsg "RUN: $srvrname server is now running PID $ftppid\n";
1578 return ($pid2, $ftppid);
1581 #######################################################################
1582 # start the ftps server (or rather, tunnel)
1585 my ($verbose, $ipv6, $certfile) = @_;
1587 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1588 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1600 $server = servername_id($proto, $ipvnum, $idnum);
1602 $pidfile = $serverpidfile{$server};
1604 # don't retry if the server doesn't work
1605 if ($doesntrun{$pidfile}) {
1609 my $pid = processexists($pidfile);
1611 stopserver($server, "$pid");
1613 unlink($pidfile) if(-f $pidfile);
1615 $srvrname = servername_str($proto, $ipvnum, $idnum);
1617 $certfile = 'stunnel.pem' unless($certfile);
1619 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1621 $flags .= "--verbose " if($debugprotocol);
1622 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1623 $flags .= "--id $idnum " if($idnum > 1);
1624 $flags .= "--ipv$ipvnum --proto $proto ";
1625 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1626 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1627 $flags .= "--connect $FTPPORT --accept $FTPSPORT";
1629 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1630 my ($ftpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1632 if($ftpspid <= 0 || !pidexists($ftpspid)) {
1634 logmsg "RUN: failed to start the $srvrname server\n";
1635 stopserver($server, "$pid2");
1636 displaylogs($testnumcheck);
1637 $doesntrun{$pidfile} = 1;
1641 # Server is up. Verify that we can speak to it.
1642 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $FTPSPORT);
1644 logmsg "RUN: $srvrname server failed verification\n";
1645 # failed to talk to it properly. Kill the server and return failure
1646 stopserver($server, "$ftpspid $pid2");
1647 displaylogs($testnumcheck);
1648 $doesntrun{$pidfile} = 1;
1651 # Here pid3 is actually the pid returned by the unsecure-ftp server.
1653 $runcert{$server} = $certfile;
1656 logmsg "RUN: $srvrname server is now running PID $ftpspid\n";
1661 return ($ftpspid, $pid2);
1664 #######################################################################
1665 # start the tftp server
1668 my ($id, $verbose, $ipv6) = @_;
1669 my $port = $TFTPPORT;
1673 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1681 # if IPv6, use a different setup
1687 $server = servername_id($proto, $ipvnum, $idnum);
1689 $pidfile = $serverpidfile{$server};
1691 # don't retry if the server doesn't work
1692 if ($doesntrun{$pidfile}) {
1696 my $pid = processexists($pidfile);
1698 stopserver($server, "$pid");
1700 unlink($pidfile) if(-f $pidfile);
1702 $srvrname = servername_str($proto, $ipvnum, $idnum);
1704 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1706 $flags .= "--verbose " if($debugprotocol);
1707 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1708 $flags .= "--id $idnum " if($idnum > 1);
1709 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1711 my $cmd = "$perl $srcdir/tftpserver.pl $flags";
1712 my ($tftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1714 if($tftppid <= 0 || !pidexists($tftppid)) {
1716 logmsg "RUN: failed to start the $srvrname server\n";
1717 stopserver($server, "$pid2");
1718 displaylogs($testnumcheck);
1719 $doesntrun{$pidfile} = 1;
1723 # Server is up. Verify that we can speak to it.
1724 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1726 logmsg "RUN: $srvrname server failed verification\n";
1727 # failed to talk to it properly. Kill the server and return failure
1728 stopserver($server, "$tftppid $pid2");
1729 displaylogs($testnumcheck);
1730 $doesntrun{$pidfile} = 1;
1736 logmsg "RUN: $srvrname server is now running PID $tftppid\n";
1741 return ($pid2, $tftppid);
1745 #######################################################################
1746 # start the rtsp server
1749 my ($verbose, $ipv6) = @_;
1750 my $port = $RTSPPORT;
1762 # if IPv6, use a different setup
1768 $server = servername_id($proto, $ipvnum, $idnum);
1770 $pidfile = $serverpidfile{$server};
1772 # don't retry if the server doesn't work
1773 if ($doesntrun{$pidfile}) {
1777 my $pid = processexists($pidfile);
1779 stopserver($server, "$pid");
1781 unlink($pidfile) if(-f $pidfile);
1783 $srvrname = servername_str($proto, $ipvnum, $idnum);
1785 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1787 $flags .= "--verbose " if($debugprotocol);
1788 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1789 $flags .= "--id $idnum " if($idnum > 1);
1790 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1792 my $cmd = "$perl $srcdir/rtspserver.pl $flags";
1793 my ($rtsppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1795 if($rtsppid <= 0 || !pidexists($rtsppid)) {
1797 logmsg "RUN: failed to start the $srvrname server\n";
1798 stopserver($server, "$pid2");
1799 displaylogs($testnumcheck);
1800 $doesntrun{$pidfile} = 1;
1804 # Server is up. Verify that we can speak to it.
1805 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1807 logmsg "RUN: $srvrname server failed verification\n";
1808 # failed to talk to it properly. Kill the server and return failure
1809 stopserver($server, "$rtsppid $pid2");
1810 displaylogs($testnumcheck);
1811 $doesntrun{$pidfile} = 1;
1817 logmsg "RUN: $srvrname server is now running PID $rtsppid\n";
1822 return ($rtsppid, $pid2);
1826 #######################################################################
1827 # Start the ssh (scp/sftp) server
1830 my ($id, $verbose, $ipv6) = @_;
1832 my $port = $SSHPORT;
1833 my $socksport = $SOCKSPORT;
1836 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1843 $server = servername_id($proto, $ipvnum, $idnum);
1845 $pidfile = $serverpidfile{$server};
1847 # don't retry if the server doesn't work
1848 if ($doesntrun{$pidfile}) {
1852 my $pid = processexists($pidfile);
1854 stopserver($server, "$pid");
1856 unlink($pidfile) if(-f $pidfile);
1858 $srvrname = servername_str($proto, $ipvnum, $idnum);
1860 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1862 $flags .= "--verbose " if($verbose);
1863 $flags .= "--debugprotocol " if($debugprotocol);
1864 $flags .= "--pidfile \"$pidfile\" ";
1865 $flags .= "--id $idnum " if($idnum > 1);
1866 $flags .= "--ipv$ipvnum --addr \"$ip\" ";
1867 $flags .= "--sshport $port --socksport $socksport ";
1868 $flags .= "--user \"$USER\"";
1870 my $cmd = "$perl $srcdir/sshserver.pl $flags";
1871 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 60, 0);
1873 # on loaded systems sshserver start up can take longer than the timeout
1874 # passed to startnew, when this happens startnew completes without being
1875 # able to read the pidfile and consequently returns a zero pid2 above.
1877 if($sshpid <= 0 || !pidexists($sshpid)) {
1879 logmsg "RUN: failed to start the $srvrname server\n";
1880 stopserver($server, "$pid2");
1881 $doesntrun{$pidfile} = 1;
1885 # ssh server verification allows some extra time for the server to start up
1886 # and gives us the opportunity of recovering the pid from the pidfile, when
1887 # this verification succeeds the recovered pid is assigned to pid2.
1889 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1891 logmsg "RUN: $srvrname server failed verification\n";
1892 # failed to fetch server pid. Kill the server and return failure
1893 stopserver($server, "$sshpid $pid2");
1894 $doesntrun{$pidfile} = 1;
1899 # once it is known that the ssh server is alive, sftp server verification
1900 # is performed actually connecting to it, authenticating and performing a
1901 # very simple remote command. This verification is tried only one time.
1903 $sshdlog = server_logfilename($LOGDIR, 'ssh', $ipvnum, $idnum);
1904 $sftplog = server_logfilename($LOGDIR, 'sftp', $ipvnum, $idnum);
1906 if(verifysftp('sftp', $ipvnum, $idnum, $ip, $port) < 1) {
1907 logmsg "RUN: SFTP server failed verification\n";
1908 # failed to talk to it properly. Kill the server and return failure
1910 display_sftpconfig();
1912 display_sshdconfig();
1913 stopserver($server, "$sshpid $pid2");
1914 $doesntrun{$pidfile} = 1;
1919 logmsg "RUN: $srvrname server is now running PID $pid2\n";
1922 return ($pid2, $sshpid);
1925 #######################################################################
1926 # Start the socks server
1928 sub runsocksserver {
1929 my ($id, $verbose, $ipv6) = @_;
1931 my $port = $SOCKSPORT;
1932 my $proto = 'socks';
1934 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1941 $server = servername_id($proto, $ipvnum, $idnum);
1943 $pidfile = $serverpidfile{$server};
1945 # don't retry if the server doesn't work
1946 if ($doesntrun{$pidfile}) {
1950 my $pid = processexists($pidfile);
1952 stopserver($server, "$pid");
1954 unlink($pidfile) if(-f $pidfile);
1956 $srvrname = servername_str($proto, $ipvnum, $idnum);
1958 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1960 # The ssh server must be already running
1962 logmsg "RUN: SOCKS server cannot find running SSH server\n";
1963 $doesntrun{$pidfile} = 1;
1967 # Find out ssh daemon canonical file name
1968 my $sshd = find_sshd();
1970 logmsg "RUN: SOCKS server cannot find $sshdexe\n";
1971 $doesntrun{$pidfile} = 1;
1975 # Find out ssh daemon version info
1976 ($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd);
1978 # Not an OpenSSH or SunSSH ssh daemon
1979 logmsg "$sshderror\n" if($verbose);
1980 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
1981 $doesntrun{$pidfile} = 1;
1984 logmsg "ssh server found $sshd is $sshdverstr\n" if($verbose);
1986 # Find out ssh client canonical file name
1987 my $ssh = find_ssh();
1989 logmsg "RUN: SOCKS server cannot find $sshexe\n";
1990 $doesntrun{$pidfile} = 1;
1994 # Find out ssh client version info
1995 my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh);
1997 # Not an OpenSSH or SunSSH ssh client
1998 logmsg "$ssherror\n" if($verbose);
1999 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
2000 $doesntrun{$pidfile} = 1;
2004 # Verify minimum ssh client version
2005 if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
2006 (($sshid =~ /SunSSH/) && ($sshvernum < 100))) {
2007 logmsg "ssh client found $ssh is $sshverstr\n";
2008 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
2009 $doesntrun{$pidfile} = 1;
2012 logmsg "ssh client found $ssh is $sshverstr\n" if($verbose);
2014 # Verify if ssh client and ssh daemon versions match
2015 if(($sshdid ne $sshid) || ($sshdvernum != $sshvernum)) {
2016 # Our test harness might work with slightly mismatched versions
2017 logmsg "Warning: version mismatch: sshd $sshdverstr - ssh $sshverstr\n"
2021 # Config file options for ssh client are previously set from sshserver.pl
2022 if(! -e $sshconfig) {
2023 logmsg "RUN: SOCKS server cannot find $sshconfig\n";
2024 $doesntrun{$pidfile} = 1;
2028 $sshlog = server_logfilename($LOGDIR, 'socks', $ipvnum, $idnum);
2030 # start our socks server
2031 my $cmd="$ssh -N -F $sshconfig $ip > $sshlog 2>&1";
2032 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 30, 1); # fake pidfile
2034 if($sshpid <= 0 || !pidexists($sshpid)) {
2036 logmsg "RUN: failed to start the $srvrname server\n";
2038 display_sshconfig();
2040 display_sshdconfig();
2041 stopserver($server, "$pid2");
2042 $doesntrun{$pidfile} = 1;
2046 # Ugly hack but ssh doesn't support pid files. PID is from fake pidfile.
2047 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2049 logmsg "RUN: $srvrname server failed verification\n";
2050 # failed to talk to it properly. Kill the server and return failure
2051 stopserver($server, "$sshpid $pid2");
2052 $doesntrun{$pidfile} = 1;
2058 logmsg "RUN: $srvrname server is now running PID $pid2\n";
2061 return ($pid2, $sshpid);
2064 #######################################################################
2065 # Single shot http and gopher server responsiveness test. This should only
2066 # be used to verify that a server present in %run hash is still functional
2068 sub responsive_http_server {
2069 my ($proto, $verbose, $alt, $port) = @_;
2074 if($alt eq "ipv6") {
2075 # if IPv6, use a different setup
2079 elsif($alt eq "proxy") {
2083 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2086 #######################################################################
2087 # Single shot pingpong server responsiveness test. This should only be
2088 # used to verify that a server present in %run hash is still functional
2090 sub responsive_pingpong_server {
2091 my ($proto, $id, $verbose, $ipv6) = @_;
2093 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2094 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2095 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2097 if($proto eq "ftp") {
2098 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
2101 # if IPv6, use a different setup
2105 elsif($proto eq "pop3") {
2106 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
2108 elsif($proto eq "imap") {
2109 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
2111 elsif($proto eq "smtp") {
2112 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
2115 print STDERR "Unsupported protocol $proto!!\n";
2119 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2122 #######################################################################
2123 # Single shot rtsp server responsiveness test. This should only be
2124 # used to verify that a server present in %run hash is still functional
2126 sub responsive_rtsp_server {
2127 my ($verbose, $ipv6) = @_;
2128 my $port = $RTSPPORT;
2135 # if IPv6, use a different setup
2141 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2144 #######################################################################
2145 # Single shot tftp server responsiveness test. This should only be
2146 # used to verify that a server present in %run hash is still functional
2148 sub responsive_tftp_server {
2149 my ($id, $verbose, $ipv6) = @_;
2150 my $port = $TFTPPORT;
2154 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2157 # if IPv6, use a different setup
2163 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2166 #######################################################################
2167 # Single shot non-stunnel HTTP TLS extensions capable server
2168 # responsiveness test. This should only be used to verify that a
2169 # server present in %run hash is still functional
2171 sub responsive_httptls_server {
2172 my ($verbose, $ipv6) = @_;
2173 my $proto = "httptls";
2174 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
2175 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2176 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2179 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2182 #######################################################################
2183 # Remove all files in the specified directory
2191 opendir(DIR, $dir) ||
2192 return 0; # can't open dir
2193 while($file = readdir(DIR)) {
2194 if($file !~ /^\./) {
2195 unlink("$dir/$file");
2203 #######################################################################
2204 # filter out the specified pattern from the given input file and store the
2205 # results in the given output file
2212 open(IN, "<$infile")
2215 open(OUT, ">$ofile")
2218 # logmsg "FILTER: off $filter from $infile to $ofile\n";
2229 #######################################################################
2230 # compare test results with the expected output, we might filter off
2231 # some pattern that is allowed to differ, output test results
2234 # filter off patterns _before_ this comparison!
2235 my ($testnum, $testname, $subject, $firstref, $secondref)=@_;
2237 my $result = compareparts($firstref, $secondref);
2240 # timestamp test result verification end
2241 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
2244 logmsg "\n $testnum: $subject FAILED:\n";
2245 logmsg showdiff($LOGDIR, $firstref, $secondref);
2247 elsif(!$automakestyle) {
2252 logmsg "FAIL: $testnum - $testname - $subject\n";
2258 #######################################################################
2259 # display information about curl and the host the test suite runs on
2263 unlink($memdump); # remove this if there was one left
2272 my $curlverout="$LOGDIR/curlverout.log";
2273 my $curlvererr="$LOGDIR/curlvererr.log";
2274 my $versioncmd="$CURL --version 1>$curlverout 2>$curlvererr";
2276 unlink($curlverout);
2277 unlink($curlvererr);
2279 $versretval = runclient($versioncmd);
2282 open(VERSOUT, "<$curlverout");
2283 @version = <VERSOUT>;
2291 $curl =~ s/^(.*)(libcurl.*)/$1/g;
2294 if($curl =~ /mingw32/) {
2295 # This is a windows minw32 build, we need to translate the
2296 # given path to the "actual" windows path. The MSYS shell
2297 # has a builtin 'pwd -W' command which converts the path.
2298 $pwd = `sh -c "echo \$(pwd -W)"`;
2301 elsif ($curl =~ /win32/) {
2302 # Native Windows builds don't understand the
2303 # output of cygwin's pwd. It will be
2304 # something like /cygdrive/c/<some path>.
2306 # Use the cygpath utility to convert the
2307 # working directory to a Windows friendly
2308 # path. The -m option converts to use drive
2309 # letter:, but it uses / instead \. Forward
2310 # slashes (/) are easier for us. We don't
2311 # have to escape them to get them to curl
2313 chomp($pwd = `cygpath -m $pwd`);
2315 if ($libcurl =~ /winssl/i) {
2319 elsif ($libcurl =~ /openssl/i) {
2323 elsif ($libcurl =~ /gnutls/i) {
2327 elsif ($libcurl =~ /nss/i) {
2331 elsif ($libcurl =~ /yassl/i) {
2335 elsif ($libcurl =~ /polarssl/i) {
2339 elsif ($libcurl =~ /axtls/i) {
2343 elsif ($libcurl =~ /securetransport/i) {
2345 $ssllib="DarwinSSL";
2348 elsif($_ =~ /^Protocols: (.*)/i) {
2349 # these are the protocols compiled in to this libcurl
2350 @protocols = split(' ', lc($1));
2352 # Generate a "proto-ipv6" version of each protocol to match the
2353 # IPv6 <server> name. This works even if IPv6 support isn't
2354 # compiled in because the <features> test will fail.
2355 push @protocols, map($_ . '-ipv6', @protocols);
2357 # 'http-proxy' is used in test cases to do CONNECT through
2358 push @protocols, 'http-proxy';
2360 # 'http-pipe' is the special server for testing pipelining
2361 push @protocols, 'http-pipe';
2363 # 'none' is used in test cases to mean no server
2364 push @protocols, 'none';
2366 elsif($_ =~ /^Features: (.*)/i) {
2368 if($feat =~ /TrackMemory/i) {
2369 # built with memory tracking support (--enable-curldebug)
2370 $has_memory_tracking = 1;
2372 if($feat =~ /debug/i) {
2373 # curl was built with --enable-debug
2376 if($feat =~ /SSL/i) {
2380 if($feat =~ /Largefile/i) {
2381 # large file support
2384 if($feat =~ /IDN/i) {
2388 if($feat =~ /IPv6/i) {
2391 if($feat =~ /libz/i) {
2394 if($feat =~ /NTLM/i) {
2398 if($feat =~ /NTLM_WB/i) {
2399 # NTLM delegation to winbind daemon ntlm_auth helper enabled
2402 if($feat =~ /SSPI/i) {
2406 if($feat =~ /CharConv/i) {
2410 if($feat =~ /TLS-SRP/i) {
2414 if($feat =~ /Metalink/i) {
2420 # Test harness currently uses a non-stunnel server in order to
2421 # run HTTP TLS-SRP tests required when curl is built with https
2422 # protocol support and TLS-SRP feature enabled. For convenience
2423 # 'httptls' may be included in the test harness protocols array
2424 # to differentiate this from classic stunnel based 'https' test
2430 if($_ =~ /^https(-ipv6|)$/) {
2435 if($add_httptls && (! grep /^httptls$/, @protocols)) {
2436 push @protocols, 'httptls';
2437 push @protocols, 'httptls-ipv6';
2442 logmsg "unable to get curl's version, further details are:\n";
2443 logmsg "issued command: \n";
2444 logmsg "$versioncmd \n";
2445 if ($versretval == -1) {
2446 logmsg "command failed with: \n";
2447 logmsg "$versnoexec \n";
2449 elsif ($versretval & 127) {
2450 logmsg sprintf("command died with signal %d, and %s coredump.\n",
2451 ($versretval & 127), ($versretval & 128)?"a":"no");
2454 logmsg sprintf("command exited with value %d \n", $versretval >> 8);
2456 logmsg "contents of $curlverout: \n";
2457 displaylogcontent("$curlverout");
2458 logmsg "contents of $curlvererr: \n";
2459 displaylogcontent("$curlvererr");
2460 die "couldn't get curl's version";
2463 if(-r "../lib/curl_config.h") {
2464 open(CONF, "<../lib/curl_config.h");
2466 if($_ =~ /^\#define HAVE_GETRLIMIT/) {
2474 # client has ipv6 support
2476 # check if the HTTP server has it!
2477 my @sws = `server/sws --version`;
2478 if($sws[0] =~ /IPv6/) {
2479 # HTTP server has ipv6 support!
2484 # check if the FTP server has it!
2485 @sws = `server/sockfilt --version`;
2486 if($sws[0] =~ /IPv6/) {
2487 # FTP server has ipv6 support!
2492 if(!$has_memory_tracking && $torture) {
2493 die "can't run torture tests since curl was built without ".
2494 "TrackMemory feature (--enable-curldebug)";
2497 $has_shared = `sh $CURLCONFIG --built-shared`;
2500 # curl doesn't list cryptographic support separately, so assume it's
2504 my $hostname=join(' ', runclientoutput("hostname"));
2505 my $hosttype=join(' ', runclientoutput("uname -a"));
2507 logmsg ("********* System characteristics ******** \n",
2510 "* Features: $feat\n",
2511 "* Host: $hostname",
2512 "* System: $hosttype");
2514 logmsg sprintf("* Server SSL: %8s", $stunnel?"ON ":"OFF");
2515 logmsg sprintf(" libcurl SSL: %s\n", $ssl_version?"ON ":"OFF");
2516 logmsg sprintf("* debug build: %8s", $debug_build?"ON ":"OFF");
2517 logmsg sprintf(" track memory: %s\n", $has_memory_tracking?"ON ":"OFF");
2518 logmsg sprintf("* valgrind: %8s", $valgrind?"ON ":"OFF");
2519 logmsg sprintf(" HTTP IPv6 %s\n", $http_ipv6?"ON ":"OFF");
2520 logmsg sprintf("* FTP IPv6 %8s", $ftp_ipv6?"ON ":"OFF");
2521 logmsg sprintf(" Libtool lib: %s\n", $libtool?"ON ":"OFF");
2522 logmsg sprintf("* Shared build: %s\n", $has_shared);
2524 logmsg sprintf("* SSL library: %13s\n", $ssllib);
2527 logmsg "* Ports:\n";
2529 logmsg sprintf("* HTTP/%d ", $HTTPPORT);
2530 logmsg sprintf("FTP/%d ", $FTPPORT);
2531 logmsg sprintf("FTP2/%d ", $FTP2PORT);
2532 logmsg sprintf("RTSP/%d ", $RTSPPORT);
2534 logmsg sprintf("FTPS/%d ", $FTPSPORT);
2535 logmsg sprintf("HTTPS/%d ", $HTTPSPORT);
2537 logmsg sprintf("\n* TFTP/%d ", $TFTPPORT);
2539 logmsg sprintf("HTTP-IPv6/%d ", $HTTP6PORT);
2540 logmsg sprintf("RTSP-IPv6/%d ", $RTSP6PORT);
2543 logmsg sprintf("FTP-IPv6/%d ", $FTP6PORT);
2546 logmsg sprintf("TFTP-IPv6/%d ", $TFTP6PORT);
2548 logmsg sprintf("\n* GOPHER/%d ", $GOPHERPORT);
2550 logmsg sprintf("GOPHER-IPv6/%d", $GOPHERPORT);
2552 logmsg sprintf("\n* SSH/%d ", $SSHPORT);
2553 logmsg sprintf("SOCKS/%d ", $SOCKSPORT);
2554 logmsg sprintf("POP3/%d ", $POP3PORT);
2555 logmsg sprintf("IMAP/%d ", $IMAPPORT);
2556 logmsg sprintf("SMTP/%d\n", $SMTPPORT);
2558 logmsg sprintf("* POP3-IPv6/%d ", $POP36PORT);
2559 logmsg sprintf("IMAP-IPv6/%d ", $IMAP6PORT);
2560 logmsg sprintf("SMTP-IPv6/%d\n", $SMTP6PORT);
2563 logmsg sprintf("* HTTPTLS/%d ", $HTTPTLSPORT);
2565 logmsg sprintf("HTTPTLS-IPv6/%d ", $HTTPTLS6PORT);
2569 logmsg sprintf("* HTTP-PIPE/%d \n", $HTTPPIPEPORT);
2571 $has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
2573 logmsg "***************************************** \n";
2576 #######################################################################
2577 # substitute the variable stuff into either a joined up file or
2578 # a command, in either case passed by reference
2585 $$thing =~ s/%FTP6PORT/$FTP6PORT/g;
2586 $$thing =~ s/%FTP2PORT/$FTP2PORT/g;
2587 $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
2588 $$thing =~ s/%FTPPORT/$FTPPORT/g;
2590 $$thing =~ s/%GOPHER6PORT/$GOPHER6PORT/g;
2591 $$thing =~ s/%GOPHERPORT/$GOPHERPORT/g;
2593 $$thing =~ s/%HTTPTLS6PORT/$HTTPTLS6PORT/g;
2594 $$thing =~ s/%HTTPTLSPORT/$HTTPTLSPORT/g;
2595 $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
2596 $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
2597 $$thing =~ s/%HTTPPORT/$HTTPPORT/g;
2598 $$thing =~ s/%HTTPPIPEPORT/$HTTPPIPEPORT/g;
2599 $$thing =~ s/%PROXYPORT/$HTTPPROXYPORT/g;
2601 $$thing =~ s/%IMAP6PORT/$IMAP6PORT/g;
2602 $$thing =~ s/%IMAPPORT/$IMAPPORT/g;
2604 $$thing =~ s/%POP36PORT/$POP36PORT/g;
2605 $$thing =~ s/%POP3PORT/$POP3PORT/g;
2607 $$thing =~ s/%RTSP6PORT/$RTSP6PORT/g;
2608 $$thing =~ s/%RTSPPORT/$RTSPPORT/g;
2610 $$thing =~ s/%SMTP6PORT/$SMTP6PORT/g;
2611 $$thing =~ s/%SMTPPORT/$SMTPPORT/g;
2613 $$thing =~ s/%SOCKSPORT/$SOCKSPORT/g;
2614 $$thing =~ s/%SSHPORT/$SSHPORT/g;
2616 $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
2617 $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
2619 # client IP addresses
2621 $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
2622 $$thing =~ s/%CLIENTIP/$CLIENTIP/g;
2624 # server IP addresses
2626 $$thing =~ s/%HOST6IP/$HOST6IP/g;
2627 $$thing =~ s/%HOSTIP/$HOSTIP/g;
2631 $$thing =~ s/%CURL/$CURL/g;
2632 $$thing =~ s/%PWD/$pwd/g;
2633 $$thing =~ s/%SRCDIR/$srcdir/g;
2634 $$thing =~ s/%USER/$USER/g;
2636 # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
2637 # used for time-out tests and that whould work on most hosts as these
2638 # adjust for the startup/check time for this particular host. We needed
2639 # to do this to make the test suite run better on very slow hosts.
2641 my $ftp2 = $ftpchecktime * 2;
2642 my $ftp3 = $ftpchecktime * 3;
2644 $$thing =~ s/%FTPTIME2/$ftp2/g;
2645 $$thing =~ s/%FTPTIME3/$ftp3/g;
2657 #######################################################################
2658 # Provide time stamps for single test skipped events
2660 sub timestampskippedevents {
2661 my $testnum = $_[0];
2663 return if((not defined($testnum)) || ($testnum < 1));
2667 if($timevrfyend{$testnum}) {
2670 elsif($timesrvrlog{$testnum}) {
2671 $timevrfyend{$testnum} = $timesrvrlog{$testnum};
2674 elsif($timetoolend{$testnum}) {
2675 $timevrfyend{$testnum} = $timetoolend{$testnum};
2676 $timesrvrlog{$testnum} = $timetoolend{$testnum};
2678 elsif($timetoolini{$testnum}) {
2679 $timevrfyend{$testnum} = $timetoolini{$testnum};
2680 $timesrvrlog{$testnum} = $timetoolini{$testnum};
2681 $timetoolend{$testnum} = $timetoolini{$testnum};
2683 elsif($timesrvrend{$testnum}) {
2684 $timevrfyend{$testnum} = $timesrvrend{$testnum};
2685 $timesrvrlog{$testnum} = $timesrvrend{$testnum};
2686 $timetoolend{$testnum} = $timesrvrend{$testnum};
2687 $timetoolini{$testnum} = $timesrvrend{$testnum};
2689 elsif($timesrvrini{$testnum}) {
2690 $timevrfyend{$testnum} = $timesrvrini{$testnum};
2691 $timesrvrlog{$testnum} = $timesrvrini{$testnum};
2692 $timetoolend{$testnum} = $timesrvrini{$testnum};
2693 $timetoolini{$testnum} = $timesrvrini{$testnum};
2694 $timesrvrend{$testnum} = $timesrvrini{$testnum};
2696 elsif($timeprepini{$testnum}) {
2697 $timevrfyend{$testnum} = $timeprepini{$testnum};
2698 $timesrvrlog{$testnum} = $timeprepini{$testnum};
2699 $timetoolend{$testnum} = $timeprepini{$testnum};
2700 $timetoolini{$testnum} = $timeprepini{$testnum};
2701 $timesrvrend{$testnum} = $timeprepini{$testnum};
2702 $timesrvrini{$testnum} = $timeprepini{$testnum};
2707 #######################################################################
2708 # Run a single specified test case
2711 my ($evbased, # 1 means switch on if possible (and "curl" is tested)
2712 # returns "not a test" if it can't be used for this test
2721 my $disablevalgrind;
2723 # copy test number to a global scope var, this allows
2724 # testnum checking when starting test harness servers.
2725 $testnumcheck = $testnum;
2727 # timestamp test preparation start
2728 $timeprepini{$testnum} = Time::HiRes::time() if($timestats);
2730 if($disttests !~ /test$testnum\W/ ) {
2731 logmsg "Warning: test$testnum not present in tests/data/Makefile.am\n";
2733 if($disabled{$testnum}) {
2734 logmsg "Warning: test$testnum is explicitly disabled\n";
2737 # load the test case file definition
2738 if(loadtest("${TESTDIR}/test${testnum}")) {
2740 # this is not a test
2741 logmsg "RUN: $testnum doesn't look like a test case\n";
2746 @what = getpart("client", "features");
2749 # We require a feature to be present
2754 if($f =~ /^([^!].*)$/) {
2755 # Store the feature for later
2763 elsif($1 eq "OpenSSL") {
2768 elsif($1 eq "GnuTLS") {
2773 elsif($1 eq "NSS") {
2778 elsif($1 eq "axTLS") {
2783 elsif($1 eq "WinSSL") {
2788 elsif($1 eq "DarwinSSL") {
2789 if($has_darwinssl) {
2793 elsif($1 eq "unittest") {
2798 elsif($1 eq "debug") {
2803 elsif($1 eq "TrackMemory") {
2804 if($has_memory_tracking) {
2808 elsif($1 eq "large_file") {
2813 elsif($1 eq "idn") {
2818 elsif($1 eq "ipv6") {
2823 elsif($1 eq "libz") {
2828 elsif($1 eq "NTLM") {
2833 elsif($1 eq "NTLM_WB") {
2838 elsif($1 eq "SSPI") {
2843 elsif($1 eq "getrlimit") {
2844 if($has_getrlimit) {
2848 elsif($1 eq "crypto") {
2853 elsif($1 eq "TLS-SRP") {
2858 elsif($1 eq "Metalink") {
2863 elsif($1 eq "socks") {
2866 # See if this "feature" is in the list of supported protocols
2867 elsif (grep /^\Q$1\E$/i, @protocols) {
2871 $why = "curl lacks $1 support";
2876 # We require a feature to not be present
2882 if($f =~ /^!(.*)$/) {
2888 elsif($1 eq "OpenSSL") {
2893 elsif($1 eq "GnuTLS") {
2898 elsif($1 eq "NSS") {
2903 elsif($1 eq "axTLS") {
2908 elsif($1 eq "WinSSL") {
2913 elsif($1 eq "DarwinSSL") {
2914 if(!$has_darwinssl) {
2918 elsif($1 eq "TrackMemory") {
2919 if(!$has_memory_tracking) {
2923 elsif($1 eq "large_file") {
2928 elsif($1 eq "idn") {
2933 elsif($1 eq "ipv6") {
2938 elsif($1 eq "libz") {
2943 elsif($1 eq "NTLM") {
2948 elsif($1 eq "NTLM_WB") {
2953 elsif($1 eq "SSPI") {
2958 elsif($1 eq "getrlimit") {
2959 if(!$has_getrlimit) {
2963 elsif($1 eq "crypto") {
2968 elsif($1 eq "TLS-SRP") {
2973 elsif($1 eq "Metalink") {
2974 if(!$has_metalink) {
2986 $why = "curl has $1 support";
2992 my @keywords = getpart("info", "keywords");
2995 for $k (@keywords) {
2997 if ($disabled_keywords{$k}) {
2998 $why = "disabled by keyword";
2999 } elsif ($enabled_keywords{$k}) {
3004 if(!$why && !$match && %enabled_keywords) {
3005 $why = "disabled by missing keyword";
3009 # test definition may instruct to (un)set environment vars
3010 # this is done this early, so that the precheck can use environment
3011 # variables and still bail out fine on errors
3013 # restore environment variables that were modified in a previous run
3014 foreach my $var (keys %oldenv) {
3015 if($oldenv{$var} eq 'notset') {
3016 delete $ENV{$var} if($ENV{$var});
3019 $ENV{$var} = $oldenv{$var};
3021 delete $oldenv{$var};
3024 # remove test server commands file before servers are started/verified
3025 unlink($FTPDCMD) if(-f $FTPDCMD);
3027 # timestamp required servers verification start
3028 $timesrvrini{$testnum} = Time::HiRes::time() if($timestats);
3031 $why = serverfortest($testnum);
3034 # timestamp required servers verification end
3035 $timesrvrend{$testnum} = Time::HiRes::time() if($timestats);
3037 my @setenv = getpart("client", "setenv");
3039 foreach my $s (@setenv) {
3042 if($s =~ /([^=]*)=(.*)/) {
3043 my ($var, $content) = ($1, $2);
3044 # remember current setting, to restore it once test runs
3045 $oldenv{$var} = ($ENV{$var})?"$ENV{$var}":'notset';
3048 delete $ENV{$var} if($ENV{$var});
3051 if($var =~ /^LD_PRELOAD/) {
3052 if(exe_ext() && (exe_ext() eq '.exe')) {
3053 # print "Skipping LD_PRELOAD due to lack of OS support\n";
3056 if($debug_build || ($has_shared ne "yes")) {
3057 # print "Skipping LD_PRELOAD due to no release shared build\n";
3061 $ENV{$var} = "$content";
3069 # Add a precheck cache. If a precheck command was already invoked
3070 # exactly like this, then use the previous result to speed up
3071 # successive test invokes!
3073 my @precheck = getpart("client", "precheck");
3075 $cmd = $precheck[0];
3079 my @p = split(/ /, $cmd);
3081 # the first word, the command, does not contain a slash so
3082 # we will scan the "improved" PATH to find the command to
3084 my $fullp = checktestcmd($p[0]);
3089 $cmd = join(" ", @p);
3092 my @o = `$cmd 2>/dev/null`;
3097 $why = "precheck command error";
3099 logmsg "prechecked $cmd\n" if($verbose);
3104 if($why && !$listonly) {
3105 # there's a problem, count it as "skipped"
3108 $teststat[$testnum]=$why; # store reason for this test case
3111 if($skipped{$why} <= 3) {
3112 # show only the first three skips for each reason
3113 logmsg sprintf("test %03d SKIPPED: $why\n", $testnum);
3117 timestampskippedevents($testnum);
3120 logmsg sprintf("test %03d...", $testnum) if(!$automakestyle);
3122 # extract the reply data
3123 my @reply = getpart("reply", "data");
3124 my @replycheck = getpart("reply", "datacheck");
3127 # we use this file instead to check the final output against
3129 my %hash = getpartattr("reply", "datacheck");
3130 if($hash{'nonewline'}) {
3131 # Yes, we must cut off the final newline from the final line
3133 chomp($replycheck[$#replycheck]);
3139 # this is the valid protocol blurb curl should generate
3140 my @protocol= fixarray ( getpart("verify", "protocol") );
3142 # this is the valid protocol blurb curl should generate to a proxy
3143 my @proxyprot = fixarray ( getpart("verify", "proxy") );
3145 # redirected stdout/stderr to these files
3146 $STDOUT="$LOGDIR/stdout$testnum";
3147 $STDERR="$LOGDIR/stderr$testnum";
3149 # if this section exists, we verify that the stdout contained this:
3150 my @validstdout = fixarray ( getpart("verify", "stdout") );
3152 # if this section exists, we verify upload
3153 my @upload = getpart("verify", "upload");
3155 # if this section exists, it might be FTP server instructions:
3156 my @ftpservercmd = getpart("reply", "servercmd");
3158 my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
3161 my @testname= getpart("client", "name");
3162 my $testname = $testname[0];
3163 $testname =~ s/\n//g;
3164 logmsg "[$testname]\n" if(!$short);
3167 timestampskippedevents($testnum);
3168 return 0; # look successful
3171 my @codepieces = getpart("client", "tool");
3175 $tool = $codepieces[0];
3179 # remove server output logfile
3185 # write the instructions to file
3186 writearray($FTPDCMD, \@ftpservercmd);
3189 # get the command line options to use
3191 ($cmd, @blaha)= getpart("client", "command");
3194 # make some nice replace operations
3195 $cmd =~ s/\n//g; # no newlines please
3196 # substitute variables in the command line
3200 # there was no command given, use something silly
3203 if($has_memory_tracking) {
3207 # create a (possibly-empty) file before starting the test
3208 my @inputfile=getpart("client", "file");
3209 my %fileattr = getpartattr("client", "file");
3210 my $filename=$fileattr{'name'};
3211 if(@inputfile || $filename) {
3213 logmsg "ERROR: section client=>file has no name attribute\n";
3214 timestampskippedevents($testnum);
3217 my $fileContent = join('', @inputfile);
3218 subVariables \$fileContent;
3219 # logmsg "DEBUG: writing file " . $filename . "\n";
3220 open(OUTFILE, ">$filename");
3221 binmode OUTFILE; # for crapage systems, use binary
3222 print OUTFILE $fileContent;
3226 my %cmdhash = getpartattr("client", "command");
3230 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-output/)) {
3231 #We may slap on --output!
3232 if (!@validstdout) {
3233 $out=" --output $CURLOUT ";
3237 my $serverlogslocktimeout = $defserverlogslocktimeout;
3238 if($cmdhash{'timeout'}) {
3239 # test is allowed to override default server logs lock timeout
3240 if($cmdhash{'timeout'} =~ /(\d+)/) {
3241 $serverlogslocktimeout = $1 if($1 >= 0);
3245 my $postcommanddelay = $defpostcommanddelay;
3246 if($cmdhash{'delay'}) {
3247 # test is allowed to specify a delay after command is executed
3248 if($cmdhash{'delay'} =~ /(\d+)/) {
3249 $postcommanddelay = $1 if($1 > 0);
3255 my $cmdtype = $cmdhash{'type'} || "default";
3256 my $fail_due_event_based = $evbased;
3257 if($cmdtype eq "perl") {
3258 # run the command line prepended with "perl"
3264 elsif($cmdtype eq "shell") {
3265 # run the command line prepended with "/bin/sh"
3267 $CMDLINE = "/bin/sh ";
3272 # run curl, add suitable command line options
3273 $cmd = "-1 ".$cmd if(exists $feature{"SSL"} && ($has_axtls));
3276 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-include/)) {
3277 $inc = " --include";
3280 $cmdargs = "$out$inc ";
3281 $cmdargs .= "--trace-ascii log/trace$testnum ";
3282 $cmdargs .= "--trace-time ";
3284 $cmdargs .= "--test-event ";
3285 $fail_due_event_based--;
3290 $cmdargs = " $cmd"; # $cmd is the command line for the test file
3291 $CURLOUT = $STDOUT; # sends received data to stdout
3293 if($tool =~ /^lib/) {
3294 $CMDLINE="$LIBDIR/$tool";
3296 elsif($tool =~ /^unit/) {
3297 $CMDLINE="$UNITDIR/$tool";
3301 logmsg "The tool set in the test case for this: '$tool' does not exist\n";
3302 timestampskippedevents($testnum);
3308 if($fail_due_event_based) {
3309 logmsg "This test cannot run event based\n";
3313 my @stdintest = getpart("client", "stdin");
3316 my $stdinfile="$LOGDIR/stdin-for-$testnum";
3318 my %hash = getpartattr("client", "stdin");
3319 if($hash{'nonewline'}) {
3320 # cut off the final newline from the final line of the stdin data
3321 chomp($stdintest[$#stdintest]);
3324 writearray($stdinfile, \@stdintest);
3326 $cmdargs .= " <$stdinfile";
3334 if($valgrind && !$disablevalgrind) {
3335 my @valgrindoption = getpart("verify", "valgrind");
3336 if((!@valgrindoption) || ($valgrindoption[0] !~ /disable/)) {
3338 my $valgrindcmd = "$valgrind ";
3339 $valgrindcmd .= "$valgrind_tool " if($valgrind_tool);
3340 $valgrindcmd .= "--leak-check=yes ";
3341 $valgrindcmd .= "--suppressions=$srcdir/valgrind.supp ";
3342 $valgrindcmd .= "--num-callers=16 ";
3343 $valgrindcmd .= "${valgrind_logfile}=$LOGDIR/valgrind$testnum";
3344 $CMDLINE = "$valgrindcmd $CMDLINE";
3348 $CMDLINE .= "$cmdargs >$STDOUT 2>$STDERR";
3351 logmsg "$CMDLINE\n";
3354 print CMDLOG "$CMDLINE\n";
3361 # Apr 2007: precommand isn't being used and could be removed
3362 my @precommand= getpart("client", "precommand");
3363 if($precommand[0]) {
3364 # this is pure perl to eval!
3365 my $code = join("", @precommand);
3368 logmsg "perl: $code\n";
3369 logmsg "precommand: $@";
3370 stopservers($verbose);
3371 timestampskippedevents($testnum);
3377 my $gdbinit = "$TESTDIR/gdbinit$testnum";
3378 open(GDBCMD, ">$LOGDIR/gdbcmd");
3379 print GDBCMD "set args $cmdargs\n";
3380 print GDBCMD "show args\n";
3381 print GDBCMD "source $gdbinit\n" if -e $gdbinit;
3385 # timestamp starting of test command
3386 $timetoolini{$testnum} = Time::HiRes::time() if($timestats);
3388 # run the command line we built
3390 $cmdres = torture($CMDLINE,
3391 "$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
3394 my $GDBW = ($gdbxwin) ? "-w" : "";
3395 runclient("$gdb --directory libtest $DBGCURL $GDBW -x $LOGDIR/gdbcmd");
3396 $cmdres=0; # makes it always continue after a debugged run
3399 $cmdres = runclient("$CMDLINE");
3400 my $signal_num = $cmdres & 127;
3401 $dumped_core = $cmdres & 128;
3403 if(!$anyway && ($signal_num || $dumped_core)) {
3408 $cmdres = (2000 + $signal_num) if($signal_num && !$cmdres);
3412 # timestamp finishing of test command
3413 $timetoolend{$testnum} = Time::HiRes::time() if($timestats);
3417 # there's core file present now!
3423 logmsg "core dumped\n";
3425 logmsg "running gdb for post-mortem analysis:\n";
3426 open(GDBCMD, ">$LOGDIR/gdbcmd2");
3427 print GDBCMD "bt\n";
3429 runclient("$gdb --directory libtest -x $LOGDIR/gdbcmd2 -batch $DBGCURL core ");
3430 # unlink("$LOGDIR/gdbcmd2");
3434 # If a server logs advisor read lock file exists, it is an indication
3435 # that the server has not yet finished writing out all its log files,
3436 # including server request log files used for protocol verification.
3437 # So, if the lock file exists the script waits here a certain amount
3438 # of time until the server removes it, or the given time expires.
3440 if($serverlogslocktimeout) {
3441 my $lockretry = $serverlogslocktimeout * 20;
3442 while((-f $SERVERLOGS_LOCK) && $lockretry--) {
3443 select(undef, undef, undef, 0.05);
3445 if(($lockretry < 0) &&
3446 ($serverlogslocktimeout >= $defserverlogslocktimeout)) {
3447 logmsg "Warning: server logs lock timeout ",
3448 "($serverlogslocktimeout seconds) expired\n";
3452 # Test harness ssh server does not have this synchronization mechanism,
3453 # this implies that some ssh server based tests might need a small delay
3454 # once that the client command has run to avoid false test failures.
3456 # gnutls-serv also lacks this synchronization mechanism, so gnutls-serv
3457 # based tests might need a small delay once that the client command has
3458 # run to avoid false test failures.
3460 sleep($postcommanddelay) if($postcommanddelay);
3462 # timestamp removal of server logs advisor read lock
3463 $timesrvrlog{$testnum} = Time::HiRes::time() if($timestats);
3465 # test definition might instruct to stop some servers
3466 # stop also all servers relative to the given one
3468 my @killtestservers = getpart("client", "killserver");
3469 if(@killtestservers) {
3471 # All servers relative to the given one must be stopped also
3474 foreach my $server (@killtestservers) {
3476 if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|))$/) {
3477 # given a stunnel ssl server, also kill non-ssl underlying one
3478 push @killservers, "${1}${2}";
3480 elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|))$/) {
3481 # given a non-ssl server, also kill stunnel piggybacking one
3482 push @killservers, "${1}s${2}";
3484 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
3485 # given a socks server, also kill ssh underlying one
3486 push @killservers, "ssh${2}";
3488 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
3489 # given a ssh server, also kill socks piggybacking one
3490 push @killservers, "socks${2}";
3492 push @killservers, $server;
3495 # kill sockfilter processes for pingpong relative servers
3497 foreach my $server (@killservers) {
3498 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
3500 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
3501 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
3502 killsockfilters($proto, $ipvnum, $idnum, $verbose);
3506 # kill server relative pids clearing them in %run hash
3509 foreach my $server (@killservers) {
3511 $pidlist .= "$run{$server} ";
3514 $runcert{$server} = 0 if($runcert{$server});
3516 killpid($verbose, $pidlist);
3518 # cleanup server pid files
3520 foreach my $server (@killservers) {
3521 my $pidfile = $serverpidfile{$server};
3522 my $pid = processexists($pidfile);
3524 logmsg "Warning: $server server unexpectedly alive\n";
3525 killpid($verbose, $pid);
3527 unlink($pidfile) if(-f $pidfile);
3531 # remove the test server commands file after each test
3532 unlink($FTPDCMD) if(-f $FTPDCMD);
3534 # run the postcheck command
3535 my @postcheck= getpart("client", "postcheck");
3537 $cmd = $postcheck[0];
3541 logmsg "postcheck $cmd\n" if($verbose);
3542 my $rc = runclient("$cmd");
3543 # Must run the postcheck command in torture mode in order
3544 # to clean up, but the result can't be relied upon.
3545 if($rc != 0 && !$torture) {
3546 logmsg " postcheck FAILED\n";
3547 # timestamp test result verification end
3548 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3554 # restore environment variables that were modified
3556 foreach my $var (keys %oldenv) {
3557 if($oldenv{$var} eq 'notset') {
3558 delete $ENV{$var} if($ENV{$var});
3561 $ENV{$var} = "$oldenv{$var}";
3566 # Skip all the verification on torture tests
3568 if(!$cmdres && !$keepoutfiles) {
3571 # timestamp test result verification end
3572 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3576 my @err = getpart("verify", "errorcode");
3577 my $errorcode = $err[0] || "0";
3582 # verify redirected stdout
3583 my @actual = loadarray($STDOUT);
3585 # variable-replace in the stdout we have from the test case file
3586 @validstdout = fixarray(@validstdout);
3588 # get all attributes
3589 my %hash = getpartattr("verify", "stdout");
3591 # get the mode attribute
3592 my $filemode=$hash{'mode'};
3593 if($filemode && ($filemode eq "text") && $has_textaware) {
3594 # text mode when running on windows: fix line endings
3595 map s/\r\n/\n/g, @actual;
3598 if($hash{'nonewline'}) {
3599 # Yes, we must cut off the final newline from the final line
3600 # of the protocol data
3601 chomp($validstdout[$#validstdout]);
3604 $res = compare($testnum, $testname, "stdout", \@actual, \@validstdout);
3611 $ok .= "-"; # stdout not checked
3614 my %replyattr = getpartattr("reply", "data");
3615 if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
3616 # verify the received data
3617 my @out = loadarray($CURLOUT);
3618 my %hash = getpartattr("reply", "data");
3619 # get the mode attribute
3620 my $filemode=$hash{'mode'};
3621 if($filemode && ($filemode eq "text") && $has_textaware) {
3622 # text mode when running on windows: fix line endings
3623 map s/\r\n/\n/g, @out;
3626 $res = compare($testnum, $testname, "data", \@out, \@reply);
3633 $ok .= "-"; # data not checked
3637 # verify uploaded data
3638 my @out = loadarray("$LOGDIR/upload.$testnum");
3639 $res = compare($testnum, $testname, "upload", \@out, \@upload);
3646 $ok .= "-"; # upload not checked
3650 # Verify the sent request
3651 my @out = loadarray($SERVERIN);
3653 # what to cut off from the live protocol sent by curl
3654 my @strip = getpart("verify", "strip");
3656 my @protstrip=@protocol;
3658 # check if there's any attributes on the verify/protocol section
3659 my %hash = getpartattr("verify", "protocol");
3661 if($hash{'nonewline'}) {
3662 # Yes, we must cut off the final newline from the final line
3663 # of the protocol data
3664 chomp($protstrip[$#protstrip]);
3668 # strip off all lines that match the patterns from both arrays
3670 @out = striparray( $_, \@out);
3671 @protstrip= striparray( $_, \@protstrip);
3674 # what parts to cut off from the protocol
3675 my @strippart = getpart("verify", "strippart");
3677 for $strip (@strippart) {
3684 $res = compare($testnum, $testname, "protocol", \@out, \@protstrip);
3693 $ok .= "-"; # protocol not checked
3697 # Verify the sent proxy request
3698 my @out = loadarray($PROXYIN);
3700 # what to cut off from the live protocol sent by curl, we use the
3701 # same rules as for <protocol>
3702 my @strip = getpart("verify", "strip");
3704 my @protstrip=@proxyprot;
3706 # check if there's any attributes on the verify/protocol section
3707 my %hash = getpartattr("verify", "proxy");
3709 if($hash{'nonewline'}) {
3710 # Yes, we must cut off the final newline from the final line
3711 # of the protocol data
3712 chomp($protstrip[$#protstrip]);
3716 # strip off all lines that match the patterns from both arrays
3718 @out = striparray( $_, \@out);
3719 @protstrip= striparray( $_, \@protstrip);
3722 # what parts to cut off from the protocol
3723 my @strippart = getpart("verify", "strippart");
3725 for $strip (@strippart) {
3732 $res = compare($testnum, $testname, "proxy", \@out, \@protstrip);
3741 $ok .= "-"; # protocol not checked
3745 for my $partsuffix (('', '1', '2', '3', '4')) {
3746 my @outfile=getpart("verify", "file".$partsuffix);
3747 if(@outfile || partexists("verify", "file".$partsuffix) ) {
3748 # we're supposed to verify a dynamically generated file!
3749 my %hash = getpartattr("verify", "file".$partsuffix);
3751 my $filename=$hash{'name'};
3753 logmsg "ERROR: section verify=>file$partsuffix ".
3754 "has no name attribute\n";
3755 stopservers($verbose);
3756 # timestamp test result verification end
3757 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3760 my @generated=loadarray($filename);
3762 # what parts to cut off from the file
3763 my @stripfile = getpart("verify", "stripfile".$partsuffix);
3765 my $filemode=$hash{'mode'};
3766 if($filemode && ($filemode eq "text") && $has_textaware) {
3767 # text mode when running on windows means adding an extra
3769 push @stripfile, "s/\r\n/\n/";
3773 for $strip (@stripfile) {
3780 @outfile = fixarray(@outfile);
3782 $res = compare($testnum, $testname, "output ($filename)",
3783 \@generated, \@outfile);
3788 $outputok = 1; # output checked
3791 $ok .= ($outputok) ? "o" : "-"; # output checked or not
3793 # accept multiple comma-separated error codes
3794 my @splerr = split(/ *, */, $errorcode);
3796 foreach my $e (@splerr) {
3809 logmsg sprintf("\n%s returned $cmdres, when expecting %s\n",
3810 (!$tool)?"curl":$tool, $errorcode);
3812 logmsg " exit FAILED\n";
3813 # timestamp test result verification end
3814 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3818 if($has_memory_tracking) {
3820 logmsg "\n** ALERT! memory tracking with no output file?\n"
3821 if(!$cmdtype eq "perl");
3824 my @memdata=`$memanalyze $memdump`;
3828 # well it could be other memory problems as well, but
3829 # we call it leak for short here
3834 logmsg "\n** MEMORY FAILURE\n";
3836 # timestamp test result verification end
3837 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3846 $ok .= "-"; # memory not checked
3851 unless(opendir(DIR, "$LOGDIR")) {
3852 logmsg "ERROR: unable to read $LOGDIR\n";
3853 # timestamp test result verification end
3854 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3857 my @files = readdir(DIR);
3860 foreach my $file (@files) {
3861 if($file =~ /^valgrind$testnum(\..*|)$/) {
3867 logmsg "ERROR: valgrind log file missing for test $testnum\n";
3868 # timestamp test result verification end
3869 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3872 my @e = valgrindparse($srcdir, $feature{'SSL'}, "$LOGDIR/$vgfile");
3874 if($automakestyle) {
3875 logmsg "FAIL: $testnum - $testname - valgrind\n";
3878 logmsg " valgrind ERROR ";
3881 # timestamp test result verification end
3882 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3888 if(!$short && !$disablevalgrind) {
3889 logmsg " valgrind SKIPPED\n";
3891 $ok .= "-"; # skipped
3895 $ok .= "-"; # valgrind not checked
3897 # add 'E' for event-based
3898 $ok .= $evbased ? "E" : "-";
3900 logmsg "$ok " if(!$short);
3902 my $sofar= time()-$start;
3903 my $esttotal = $sofar/$count * $total;
3904 my $estleft = $esttotal - $sofar;
3905 my $left=sprintf("remaining: %02d:%02d",
3909 if(!$automakestyle) {
3910 logmsg sprintf("OK (%-3d out of %-3d, %s)\n", $count, $total, $left);
3913 logmsg "PASS: $testnum - $testname\n";
3916 # the test succeeded, remove all log files
3917 if(!$keepoutfiles) {
3921 # timestamp test result verification end
3922 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3927 #######################################################################
3928 # Stop all running test servers
3931 my $verbose = $_[0];
3933 # kill sockfilter processes for all pingpong servers
3935 killallsockfilters($verbose);
3937 # kill all server pids from %run hash clearing them
3940 foreach my $server (keys %run) {
3944 my $pids = $run{$server};
3945 foreach my $pid (split(' ', $pids)) {
3947 logmsg sprintf("* kill pid for %s => %d\n",
3953 $pidlist .= "$run{$server} ";
3956 $runcert{$server} = 0 if($runcert{$server});
3958 killpid($verbose, $pidlist);
3960 # cleanup all server pid files
3962 foreach my $server (keys %serverpidfile) {
3963 my $pidfile = $serverpidfile{$server};
3964 my $pid = processexists($pidfile);
3966 logmsg "Warning: $server server unexpectedly alive\n";
3967 killpid($verbose, $pid);
3969 unlink($pidfile) if(-f $pidfile);
3973 #######################################################################
3974 # startservers() starts all the named servers
3976 # Returns: string with error reason or blank for success
3982 my (@whatlist) = split(/\s+/,$_);
3983 my $what = lc($whatlist[0]);
3984 $what =~ s/[^a-z0-9-]//g;
3987 if($what =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|))$/) {
3988 $certfile = ($whatlist[1]) ? $whatlist[1] : 'stunnel.pem';
3991 if(($what eq "pop3") ||
3993 ($what eq "imap") ||
3994 ($what eq "smtp")) {
3995 if($torture && $run{$what} &&
3996 !responsive_pingpong_server($what, "", $verbose)) {
4000 ($pid, $pid2) = runpingpongserver($what, "", $verbose);
4002 return "failed starting ". uc($what) ." server";
4004 printf ("* pid $what => %d %d\n", $pid, $pid2) if($verbose);
4005 $run{$what}="$pid $pid2";
4008 elsif($what eq "ftp2") {
4009 if($torture && $run{'ftp2'} &&
4010 !responsive_pingpong_server("ftp", "2", $verbose)) {
4014 ($pid, $pid2) = runpingpongserver("ftp", "2", $verbose);
4016 return "failed starting FTP2 server";
4018 printf ("* pid ftp2 => %d %d\n", $pid, $pid2) if($verbose);
4019 $run{'ftp2'}="$pid $pid2";
4022 elsif($what eq "ftp-ipv6") {
4023 if($torture && $run{'ftp-ipv6'} &&
4024 !responsive_pingpong_server("ftp", "", $verbose, "ipv6")) {
4025 stopserver('ftp-ipv6');
4027 if(!$run{'ftp-ipv6'}) {
4028 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose, "ipv6");
4030 return "failed starting FTP-IPv6 server";
4032 logmsg sprintf("* pid ftp-ipv6 => %d %d\n", $pid,
4033 $pid2) if($verbose);
4034 $run{'ftp-ipv6'}="$pid $pid2";
4037 elsif($what eq "gopher") {
4038 if($torture && $run{'gopher'} &&
4039 !responsive_http_server("gopher", $verbose, 0, $GOPHERPORT)) {
4040 stopserver('gopher');
4042 if(!$run{'gopher'}) {
4043 ($pid, $pid2) = runhttpserver("gopher", $verbose, 0,
4046 return "failed starting GOPHER server";
4048 logmsg sprintf ("* pid gopher => %d %d\n", $pid, $pid2)
4050 $run{'gopher'}="$pid $pid2";
4053 elsif($what eq "gopher-ipv6") {
4054 if($torture && $run{'gopher-ipv6'} &&
4055 !responsive_http_server("gopher", $verbose, "ipv6",
4057 stopserver('gopher-ipv6');
4059 if(!$run{'gopher-ipv6'}) {
4060 ($pid, $pid2) = runhttpserver("gopher", $verbose, "ipv6",
4063 return "failed starting GOPHER-IPv6 server";
4065 logmsg sprintf("* pid gopher-ipv6 => %d %d\n", $pid,
4066 $pid2) if($verbose);
4067 $run{'gopher-ipv6'}="$pid $pid2";
4070 elsif($what eq "http") {
4071 if($torture && $run{'http'} &&
4072 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4076 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4079 return "failed starting HTTP server";
4081 logmsg sprintf ("* pid http => %d %d\n", $pid, $pid2)
4083 $run{'http'}="$pid $pid2";
4086 elsif($what eq "http-proxy") {
4087 if($torture && $run{'http-proxy'} &&
4088 !responsive_http_server("http", $verbose, "proxy",
4090 stopserver('http-proxy');
4092 if(!$run{'http-proxy'}) {
4093 ($pid, $pid2) = runhttpserver("http", $verbose, "proxy",
4096 return "failed starting HTTP-proxy server";
4098 logmsg sprintf ("* pid http-proxy => %d %d\n", $pid, $pid2)
4100 $run{'http-proxy'}="$pid $pid2";
4103 elsif($what eq "http-ipv6") {
4104 if($torture && $run{'http-ipv6'} &&
4105 !responsive_http_server("http", $verbose, "IPv6", $HTTP6PORT)) {
4106 stopserver('http-ipv6');
4108 if(!$run{'http-ipv6'}) {
4109 ($pid, $pid2) = runhttpserver("http", $verbose, "ipv6",
4112 return "failed starting HTTP-IPv6 server";
4114 logmsg sprintf("* pid http-ipv6 => %d %d\n", $pid, $pid2)
4116 $run{'http-ipv6'}="$pid $pid2";
4119 elsif($what eq "http-pipe") {
4120 if($torture && $run{'http-pipe'} &&
4121 !responsive_http_server("http", $verbose, "pipe",
4123 stopserver('http-pipe');
4125 if(!$run{'http-pipe'}) {
4126 ($pid, $pid2) = runhttpserver("http", $verbose, "pipe",
4129 return "failed starting HTTP-pipe server";
4131 logmsg sprintf ("* pid http-pipe => %d %d\n", $pid, $pid2)
4133 $run{'http-pipe'}="$pid $pid2";
4136 elsif($what eq "rtsp") {
4137 if($torture && $run{'rtsp'} &&
4138 !responsive_rtsp_server($verbose)) {
4142 ($pid, $pid2) = runrtspserver($verbose);
4144 return "failed starting RTSP server";
4146 printf ("* pid rtsp => %d %d\n", $pid, $pid2) if($verbose);
4147 $run{'rtsp'}="$pid $pid2";
4150 elsif($what eq "rtsp-ipv6") {
4151 if($torture && $run{'rtsp-ipv6'} &&
4152 !responsive_rtsp_server($verbose, "IPv6")) {
4153 stopserver('rtsp-ipv6');
4155 if(!$run{'rtsp-ipv6'}) {
4156 ($pid, $pid2) = runrtspserver($verbose, "IPv6");
4158 return "failed starting RTSP-IPv6 server";
4160 logmsg sprintf("* pid rtsp-ipv6 => %d %d\n", $pid, $pid2)
4162 $run{'rtsp-ipv6'}="$pid $pid2";
4165 elsif($what eq "ftps") {
4167 # we can't run ftps tests without stunnel
4168 return "no stunnel";
4171 # we can't run ftps tests if libcurl is SSL-less
4172 return "curl lacks SSL support";
4174 if($runcert{'ftps'} && ($runcert{'ftps'} ne $certfile)) {
4175 # stop server when running and using a different cert
4178 if($torture && $run{'ftp'} &&
4179 !responsive_pingpong_server("ftp", "", $verbose)) {
4183 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose);
4185 return "failed starting FTP server";
4187 printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
4188 $run{'ftp'}="$pid $pid2";
4191 ($pid, $pid2) = runftpsserver($verbose, "", $certfile);
4193 return "failed starting FTPS server (stunnel)";
4195 logmsg sprintf("* pid ftps => %d %d\n", $pid, $pid2)
4197 $run{'ftps'}="$pid $pid2";
4200 elsif($what eq "file") {
4201 # we support it but have no server!
4203 elsif($what eq "https") {
4205 # we can't run https tests without stunnel
4206 return "no stunnel";
4209 # we can't run https tests if libcurl is SSL-less
4210 return "curl lacks SSL support";
4212 if($runcert{'https'} && ($runcert{'https'} ne $certfile)) {
4213 # stop server when running and using a different cert
4214 stopserver('https');
4216 if($torture && $run{'http'} &&
4217 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4221 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4224 return "failed starting HTTP server";
4226 printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
4227 $run{'http'}="$pid $pid2";
4229 if(!$run{'https'}) {
4230 ($pid, $pid2) = runhttpsserver($verbose, "", $certfile);
4232 return "failed starting HTTPS server (stunnel)";
4234 logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
4236 $run{'https'}="$pid $pid2";
4239 elsif($what eq "httptls") {
4241 # for now, we can't run http TLS-EXT tests without gnutls-serv
4242 return "no gnutls-serv";
4244 if($torture && $run{'httptls'} &&
4245 !responsive_httptls_server($verbose, "IPv4")) {
4246 stopserver('httptls');
4248 if(!$run{'httptls'}) {
4249 ($pid, $pid2) = runhttptlsserver($verbose, "IPv4");
4251 return "failed starting HTTPTLS server (gnutls-serv)";
4253 logmsg sprintf("* pid httptls => %d %d\n", $pid, $pid2)
4255 $run{'httptls'}="$pid $pid2";
4258 elsif($what eq "httptls-ipv6") {
4260 # for now, we can't run http TLS-EXT tests without gnutls-serv
4261 return "no gnutls-serv";
4263 if($torture && $run{'httptls-ipv6'} &&
4264 !responsive_httptls_server($verbose, "IPv6")) {
4265 stopserver('httptls-ipv6');
4267 if(!$run{'httptls-ipv6'}) {
4268 ($pid, $pid2) = runhttptlsserver($verbose, "IPv6");
4270 return "failed starting HTTPTLS-IPv6 server (gnutls-serv)";
4272 logmsg sprintf("* pid httptls-ipv6 => %d %d\n", $pid, $pid2)
4274 $run{'httptls-ipv6'}="$pid $pid2";
4277 elsif($what eq "tftp") {
4278 if($torture && $run{'tftp'} &&
4279 !responsive_tftp_server("", $verbose)) {
4283 ($pid, $pid2) = runtftpserver("", $verbose);
4285 return "failed starting TFTP server";
4287 printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
4288 $run{'tftp'}="$pid $pid2";
4291 elsif($what eq "tftp-ipv6") {
4292 if($torture && $run{'tftp-ipv6'} &&
4293 !responsive_tftp_server("", $verbose, "IPv6")) {
4294 stopserver('tftp-ipv6');
4296 if(!$run{'tftp-ipv6'}) {
4297 ($pid, $pid2) = runtftpserver("", $verbose, "IPv6");
4299 return "failed starting TFTP-IPv6 server";
4301 printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
4302 $run{'tftp-ipv6'}="$pid $pid2";
4305 elsif($what eq "sftp" || $what eq "scp" || $what eq "socks4" || $what eq "socks5" ) {
4307 ($pid, $pid2) = runsshserver("", $verbose);
4309 return "failed starting SSH server";
4311 printf ("* pid ssh => %d %d\n", $pid, $pid2) if($verbose);
4312 $run{'ssh'}="$pid $pid2";
4314 if($what eq "socks4" || $what eq "socks5") {
4315 if(!$run{'socks'}) {
4316 ($pid, $pid2) = runsocksserver("", $verbose);
4318 return "failed starting socks server";
4320 printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
4321 $run{'socks'}="$pid $pid2";
4324 if($what eq "socks5") {
4326 # Not an OpenSSH or SunSSH ssh daemon
4327 logmsg "Not OpenSSH or SunSSH; socks5 tests need at least OpenSSH 3.7\n";
4328 return "failed starting socks5 server";
4330 elsif(($sshdid =~ /OpenSSH/) && ($sshdvernum < 370)) {
4331 # Need OpenSSH 3.7 for socks5 - http://www.openssh.com/txt/release-3.7
4332 logmsg "$sshdverstr insufficient; socks5 tests need at least OpenSSH 3.7\n";
4333 return "failed starting socks5 server";
4335 elsif(($sshdid =~ /SunSSH/) && ($sshdvernum < 100)) {
4336 # Need SunSSH 1.0 for socks5
4337 logmsg "$sshdverstr insufficient; socks5 tests need at least SunSSH 1.0\n";
4338 return "failed starting socks5 server";
4342 elsif($what eq "none") {
4343 logmsg "* starts no server\n" if ($verbose);
4346 warn "we don't support a server for $what";
4347 return "no server for $what";
4353 ##############################################################################
4354 # This function makes sure the right set of server is running for the
4355 # specified test case. This is a useful design when we run single tests as not
4356 # all servers need to run then!
4358 # Returns: a string, blank if everything is fine or a reason why it failed
4363 my @what = getpart("client", "server");
4366 warn "Test case $testnum has no server(s) specified";
4367 return "no server specified";
4370 for(my $i = scalar(@what) - 1; $i >= 0; $i--) {
4371 my $srvrline = $what[$i];
4372 chomp $srvrline if($srvrline);
4373 if($srvrline =~ /^(\S+)((\s*)(.*))/) {
4374 my $server = "${1}";
4375 my $lnrest = "${2}";
4377 if($server =~ /^(httptls)(\+)(ext|srp)(\d*)(-ipv6|)$/) {
4378 $server = "${1}${4}${5}";
4379 $tlsext = uc("TLS-${3}");
4381 if(! grep /^\Q$server\E$/, @protocols) {
4382 if(substr($server,0,5) ne "socks") {
4384 return "curl lacks $tlsext support";
4387 return "curl lacks $server server support";
4391 $what[$i] = "$server$lnrest" if($tlsext);
4395 return &startservers(@what);
4398 #######################################################################
4399 # runtimestats displays test-suite run time statistics
4402 my $lasttest = $_[0];
4404 return if(not $timestats);
4406 logmsg "\nTest suite total running time breakdown per task...\n\n";
4414 my $timesrvrtot = 0.0;
4415 my $timepreptot = 0.0;
4416 my $timetooltot = 0.0;
4417 my $timelocktot = 0.0;
4418 my $timevrfytot = 0.0;
4419 my $timetesttot = 0.0;
4422 for my $testnum (1 .. $lasttest) {
4423 if($timesrvrini{$testnum}) {
4424 $timesrvrtot += $timesrvrend{$testnum} - $timesrvrini{$testnum};
4426 (($timetoolini{$testnum} - $timeprepini{$testnum}) -
4427 ($timesrvrend{$testnum} - $timesrvrini{$testnum}));
4428 $timetooltot += $timetoolend{$testnum} - $timetoolini{$testnum};
4429 $timelocktot += $timesrvrlog{$testnum} - $timetoolend{$testnum};
4430 $timevrfytot += $timevrfyend{$testnum} - $timesrvrlog{$testnum};
4431 $timetesttot += $timevrfyend{$testnum} - $timeprepini{$testnum};
4432 push @timesrvr, sprintf("%06.3f %04d",
4433 $timesrvrend{$testnum} - $timesrvrini{$testnum}, $testnum);
4434 push @timeprep, sprintf("%06.3f %04d",
4435 ($timetoolini{$testnum} - $timeprepini{$testnum}) -
4436 ($timesrvrend{$testnum} - $timesrvrini{$testnum}), $testnum);
4437 push @timetool, sprintf("%06.3f %04d",
4438 $timetoolend{$testnum} - $timetoolini{$testnum}, $testnum);
4439 push @timelock, sprintf("%06.3f %04d",
4440 $timesrvrlog{$testnum} - $timetoolend{$testnum}, $testnum);
4441 push @timevrfy, sprintf("%06.3f %04d",
4442 $timevrfyend{$testnum} - $timesrvrlog{$testnum}, $testnum);
4443 push @timetest, sprintf("%06.3f %04d",
4444 $timevrfyend{$testnum} - $timeprepini{$testnum}, $testnum);
4449 no warnings 'numeric';
4450 @timesrvr = sort { $b <=> $a } @timesrvr;
4451 @timeprep = sort { $b <=> $a } @timeprep;
4452 @timetool = sort { $b <=> $a } @timetool;
4453 @timelock = sort { $b <=> $a } @timelock;
4454 @timevrfy = sort { $b <=> $a } @timevrfy;
4455 @timetest = sort { $b <=> $a } @timetest;
4458 logmsg "Spent ". sprintf("%08.3f ", $timesrvrtot) .
4459 "seconds starting and verifying test harness servers.\n";
4460 logmsg "Spent ". sprintf("%08.3f ", $timepreptot) .
4461 "seconds reading definitions and doing test preparations.\n";
4462 logmsg "Spent ". sprintf("%08.3f ", $timetooltot) .
4463 "seconds actually running test tools.\n";
4464 logmsg "Spent ". sprintf("%08.3f ", $timelocktot) .
4465 "seconds awaiting server logs lock removal.\n";
4466 logmsg "Spent ". sprintf("%08.3f ", $timevrfytot) .
4467 "seconds verifying test results.\n";
4468 logmsg "Spent ". sprintf("%08.3f ", $timetesttot) .
4469 "seconds doing all of the above.\n";
4472 logmsg "\nTest server starting and verification time per test ".
4473 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4474 logmsg "-time- test\n";
4475 logmsg "------ ----\n";
4476 foreach my $txt (@timesrvr) {
4477 last if((not $fullstats) && (not $counter--));
4482 logmsg "\nTest definition reading and preparation time per test ".
4483 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4484 logmsg "-time- test\n";
4485 logmsg "------ ----\n";
4486 foreach my $txt (@timeprep) {
4487 last if((not $fullstats) && (not $counter--));
4492 logmsg "\nTest tool execution time per test ".
4493 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4494 logmsg "-time- test\n";
4495 logmsg "------ ----\n";
4496 foreach my $txt (@timetool) {
4497 last if((not $fullstats) && (not $counter--));
4502 logmsg "\nTest server logs lock removal time per test ".
4503 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4504 logmsg "-time- test\n";
4505 logmsg "------ ----\n";
4506 foreach my $txt (@timelock) {
4507 last if((not $fullstats) && (not $counter--));
4512 logmsg "\nTest results verification time per test ".
4513 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4514 logmsg "-time- test\n";
4515 logmsg "------ ----\n";
4516 foreach my $txt (@timevrfy) {
4517 last if((not $fullstats) && (not $counter--));
4522 logmsg "\nTotal time per test ".
4523 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4524 logmsg "-time- test\n";
4525 logmsg "------ ----\n";
4526 foreach my $txt (@timetest) {
4527 last if((not $fullstats) && (not $counter--));
4534 #######################################################################
4535 # Check options to this test program
4542 if ($ARGV[0] eq "-v") {
4546 elsif($ARGV[0] =~ /^-b(.*)/) {
4548 if($portno =~ s/(\d+)$//) {
4552 elsif ($ARGV[0] eq "-c") {
4553 # use this path to curl instead of default
4554 $DBGCURL=$CURL=$ARGV[1];
4557 elsif ($ARGV[0] eq "-vc") {
4558 # use this path to a curl used to verify servers
4560 # Particularly useful when you introduce a crashing bug somewhere in
4561 # the development version as then it won't be able to run any tests
4562 # since it can't verify the servers!
4567 elsif ($ARGV[0] eq "-d") {
4568 # have the servers display protocol output
4571 elsif ($ARGV[0] eq "-g") {
4572 # run this test with gdb
4575 elsif ($ARGV[0] eq "-gw") {
4576 # run this test with windowed gdb
4580 elsif($ARGV[0] eq "-s") {
4584 elsif($ARGV[0] eq "-am") {
4585 # automake-style output
4589 elsif($ARGV[0] eq "-n") {
4593 elsif($ARGV[0] =~ /^-t(.*)/) {
4598 if($xtra =~ s/(\d+)$//) {
4601 # we undef valgrind to make this fly in comparison
4604 elsif($ARGV[0] eq "-a") {
4605 # continue anyway, even if a test fail
4608 elsif($ARGV[0] eq "-e") {
4609 # run the tests cases event based if possible
4612 elsif($ARGV[0] eq "-p") {
4615 elsif($ARGV[0] eq "-l") {
4616 # lists the test case names only
4619 elsif($ARGV[0] eq "-k") {
4620 # keep stdout and stderr files after tests
4623 elsif($ARGV[0] eq "-r") {
4624 # run time statistics needs Time::HiRes
4625 if($Time::HiRes::VERSION) {
4626 keys(%timeprepini) = 1000;
4627 keys(%timesrvrini) = 1000;
4628 keys(%timesrvrend) = 1000;
4629 keys(%timetoolini) = 1000;
4630 keys(%timetoolend) = 1000;
4631 keys(%timesrvrlog) = 1000;
4632 keys(%timevrfyend) = 1000;
4637 elsif($ARGV[0] eq "-rf") {
4638 # run time statistics needs Time::HiRes
4639 if($Time::HiRes::VERSION) {
4640 keys(%timeprepini) = 1000;
4641 keys(%timesrvrini) = 1000;
4642 keys(%timesrvrend) = 1000;
4643 keys(%timetoolini) = 1000;
4644 keys(%timetoolend) = 1000;
4645 keys(%timesrvrlog) = 1000;
4646 keys(%timevrfyend) = 1000;
4651 elsif(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) {
4654 Usage: runtests.pl [options] [test selection(s)]
4655 -a continue even if a test fails
4656 -bN use base port number N for test servers (default $base)
4657 -c path use this curl executable
4658 -d display server debug info
4659 -g run the test case with gdb
4660 -gw run the test case with gdb as a windowed application
4662 -k keep stdout and stderr files present after tests
4663 -l list all test case names/descriptions
4665 -p print log file contents when a test fails
4666 -r run time statistics
4667 -rf full run time statistics
4669 -am automake style output PASS/FAIL: [number] [name]
4670 -t[N] torture (simulate memory alloc failures); N means fail Nth alloc
4672 -vc path use this curl only to verify the existing servers
4673 [num] like "5 6 9" or " 5 to 22 " to run those tests only
4674 [!num] like "!5 !6 !9" to disable those tests
4675 [keyword] like "IPv6" to select only tests containing the key word
4676 [!keyword] like "!cookies" to disable any tests containing the key word
4681 elsif($ARGV[0] =~ /^(\d+)/) {
4684 for($fromnum .. $number) {
4693 elsif($ARGV[0] =~ /^to$/i) {
4694 $fromnum = $number+1;
4696 elsif($ARGV[0] =~ /^!(\d+)/) {
4700 elsif($ARGV[0] =~ /^!(.+)/) {
4701 $disabled_keywords{$1}=$1;
4703 elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
4704 $enabled_keywords{$1}=$1;
4707 print "Unknown option: $ARGV[0]\n";
4713 if(@testthis && ($testthis[0] ne "")) {
4714 $TESTCASES=join(" ", @testthis);
4718 # we have found valgrind on the host, use it
4720 # verify that we can invoke it fine
4721 my $code = runclient("valgrind >/dev/null 2>&1");
4723 if(($code>>8) != 1) {
4724 #logmsg "Valgrind failure, disable it\n";
4728 # since valgrind 2.1.x, '--tool' option is mandatory
4729 # use it, if it is supported by the version installed on the system
4730 runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
4732 $valgrind_tool="--tool=memcheck";
4737 # A shell script. This is typically when built with libtool,
4738 $valgrind="../libtool --mode=execute $valgrind";
4742 # valgrind 3 renamed the --logfile option to --log-file!!!
4743 my $ver=join(' ', runclientoutput("valgrind --version"));
4744 # cut off all but digits and dots
4745 $ver =~ s/[^0-9.]//g;
4747 if($ver =~ /^(\d+)/) {
4750 $valgrind_logfile="--log-file";
4757 # open the executable curl and read the first 4 bytes of it
4758 open(CHECK, "<$CURL");
4760 sysread CHECK, $c, 4;
4763 # A shell script. This is typically when built with libtool,
4765 $gdb = "libtool --mode=execute gdb";
4769 $HTTPPORT = $base++; # HTTP server port
4770 $HTTPSPORT = $base++; # HTTPS (stunnel) server port
4771 $FTPPORT = $base++; # FTP server port
4772 $FTPSPORT = $base++; # FTPS (stunnel) server port
4773 $HTTP6PORT = $base++; # HTTP IPv6 server port
4774 $FTP2PORT = $base++; # FTP server 2 port
4775 $FTP6PORT = $base++; # FTP IPv6 port
4776 $TFTPPORT = $base++; # TFTP (UDP) port
4777 $TFTP6PORT = $base++; # TFTP IPv6 (UDP) port
4778 $SSHPORT = $base++; # SSH (SCP/SFTP) port
4779 $SOCKSPORT = $base++; # SOCKS port
4780 $POP3PORT = $base++; # POP3 server port
4781 $POP36PORT = $base++; # POP3 IPv6 server port
4782 $IMAPPORT = $base++; # IMAP server port
4783 $IMAP6PORT = $base++; # IMAP IPv6 server port
4784 $SMTPPORT = $base++; # SMTP server port
4785 $SMTP6PORT = $base++; # SMTP IPv6 server port
4786 $RTSPPORT = $base++; # RTSP server port
4787 $RTSP6PORT = $base++; # RTSP IPv6 server port
4788 $GOPHERPORT = $base++; # Gopher IPv4 server port
4789 $GOPHER6PORT = $base++; # Gopher IPv6 server port
4790 $HTTPTLSPORT = $base++; # HTTP TLS (non-stunnel) server port
4791 $HTTPTLS6PORT = $base++; # HTTP TLS (non-stunnel) IPv6 server port
4792 $HTTPPROXYPORT = $base++; # HTTP proxy port, when using CONNECT
4793 $HTTPPIPEPORT = $base++; # HTTP pipelining port
4795 #######################################################################
4796 # clear and create logging directory:
4800 mkdir($LOGDIR, 0777);
4802 #######################################################################
4803 # initialize some variables
4807 init_serverpidfile_hash();
4809 #######################################################################
4810 # Output curl version and host info being tested
4817 #######################################################################
4818 # Fetch all disabled tests
4821 open(D, "<$TESTDIR/DISABLED");
4828 $disabled{$1}=$1; # disable this test number
4833 #######################################################################
4834 # If 'all' tests are requested, find out all test numbers
4837 if ( $TESTCASES eq "all") {
4838 # Get all commands and find out their test numbers
4839 opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
4840 my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
4843 $TESTCASES=""; # start with no test cases
4845 # cut off everything but the digits
4847 $_ =~ s/[a-z\/\.]*//g;
4849 # sort the numbers from low to high
4850 foreach my $n (sort { $a <=> $b } @cmds) {
4852 # skip disabled test cases
4853 my $why = "configured as DISABLED";
4856 $teststat[$n]=$why; # store reason for this test case
4859 $TESTCASES .= " $n";
4863 #######################################################################
4864 # Start the command line log
4866 open(CMDLOG, ">$CURLLOG") ||
4867 logmsg "can't log command lines to $CURLLOG\n";
4869 #######################################################################
4871 # Display the contents of the given file. Line endings are canonicalized
4872 # and excessively long files are elided
4873 sub displaylogcontent {
4875 if(open(SINGLE, "<$file")) {
4879 while(my $string = <SINGLE>) {
4880 $string =~ s/\r\n/\n/g;
4881 $string =~ s/[\r\f\032]/\n/g;
4882 $string .= "\n" unless ($string =~ /\n$/);
4884 for my $line (split("\n", $string)) {
4885 $line =~ s/\s*\!$//;
4887 push @tail, " $line\n";
4892 $truncate = $linecount > 1000;
4898 my $tailtotal = scalar @tail;
4899 if($tailtotal > $tailshow) {
4900 $tailskip = $tailtotal - $tailshow;
4901 logmsg "=== File too long: $tailskip lines omitted here\n";
4903 for($tailskip .. $tailtotal-1) {
4913 opendir(DIR, "$LOGDIR") ||
4914 die "can't open dir: $!";
4915 my @logs = readdir(DIR);
4918 logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
4919 foreach my $log (sort @logs) {
4920 if($log =~ /\.(\.|)$/) {
4921 next; # skip "." and ".."
4923 if($log =~ /^\.nfs/) {
4926 if(($log eq "memdump") || ($log eq "core")) {
4927 next; # skip "memdump" and "core"
4929 if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
4930 next; # skip directory and empty files
4932 if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
4933 next; # skip stdoutNnn of other tests
4935 if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
4936 next; # skip stderrNnn of other tests
4938 if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
4939 next; # skip uploadNnn of other tests
4941 if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
4942 next; # skip curlNnn.out of other tests
4944 if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
4945 next; # skip testNnn.txt of other tests
4947 if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
4948 next; # skip fileNnn.txt of other tests
4950 if(($log =~ /^netrc\d+/) && ($log !~ /^netrc$testnum/)) {
4951 next; # skip netrcNnn of other tests
4953 if(($log =~ /^trace\d+/) && ($log !~ /^trace$testnum/)) {
4954 next; # skip traceNnn of other tests
4956 if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(\..*|)$/)) {
4957 next; # skip valgrindNnn of other tests
4959 logmsg "=== Start of file $log\n";
4960 displaylogcontent("$LOGDIR/$log");
4961 logmsg "=== End of file $log\n";
4965 #######################################################################
4966 # The main test-loop
4974 my @at = split(" ", $TESTCASES);
4979 foreach $testnum (@at) {
4981 $lasttest = $testnum if($testnum > $lasttest);
4984 my $error = singletest($run_event_based, $testnum, $count, scalar(@at));
4986 # not a test we can run
4990 $total++; # number of tests we've run
4993 $failed.= "$testnum ";
4995 # display all files in log/ in a nice way
4996 displaylogs($testnum);
4999 # a test failed, abort
5000 logmsg "\n - abort tests\n";
5005 $ok++; # successful test counter
5008 # loop for next test
5011 my $sofar = time() - $start;
5013 #######################################################################
5018 # Tests done, stop the servers
5019 stopservers($verbose);
5021 my $all = $total + $skipped;
5023 runtimestats($lasttest);
5026 logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
5030 logmsg "TESTFAIL: These test cases failed: $failed\n";
5034 logmsg "TESTFAIL: No tests were performed\n";
5038 logmsg "TESTDONE: $all tests were considered during ".
5039 sprintf("%.0f", $sofar) ." seconds.\n";
5042 if($skipped && !$short) {
5044 logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
5046 for(keys %skipped) {
5048 printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
5050 # now show all test case numbers that had this reason for being
5054 for(0 .. scalar @teststat) {
5056 if($teststat[$_] && ($teststat[$_] eq $r)) {
5065 logmsg " and ".($c-$max)." more";
5071 if($total && ($ok != $total)) {