2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2014, 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 $resolver; # string to hold the resolver backend
230 my $has_cares; # if built with c-ares
231 my $has_threadedres; # if built with threaded resolver
233 my $ssllib; # name of the lib we use (for human presentation)
234 my $has_crypto; # set if libcurl is built with cryptographic support
235 my $has_textaware; # set if running on a system that has a text mode concept
236 # on files. Windows for example
238 my @protocols; # array of lowercase supported protocol servers
240 my $skipped=0; # number of tests skipped; reported in main loop
241 my %skipped; # skipped{reason}=counter, reasons for skip
242 my @teststat; # teststat[testnum]=reason, reasons for skip
243 my %disabled_keywords; # key words of tests to skip
244 my %enabled_keywords; # key words of tests to run
245 my %disabled; # disabled test cases
247 my $sshdid; # for socks server, ssh daemon version id
248 my $sshdvernum; # for socks server, ssh daemon version number
249 my $sshdverstr; # for socks server, ssh daemon version string
250 my $sshderror; # for socks server, ssh daemon version error
252 my $defserverlogslocktimeout = 20; # timeout to await server logs lock removal
253 my $defpostcommanddelay = 0; # delay between command and postcheck sections
255 my $timestats; # time stamping and stats generation
256 my $fullstats; # show time stats for every single test
257 my %timeprepini; # timestamp for each test preparation start
258 my %timesrvrini; # timestamp for each test required servers verification start
259 my %timesrvrend; # timestamp for each test required servers verification end
260 my %timetoolini; # timestamp for each test command run starting
261 my %timetoolend; # timestamp for each test command run stopping
262 my %timesrvrlog; # timestamp for each test server logs lock removal
263 my %timevrfyend; # timestamp for each test result verification end
265 my $testnumcheck; # test number, set in singletest sub.
268 #######################################################################
269 # variables that command line options may set
277 my $gdbthis; # run test case with gdb debugger
278 my $gdbxwin; # use windowed gdb when using gdb
279 my $keepoutfiles; # keep stdout and stderr files after tests
280 my $listonly; # only list the tests
281 my $postmortem; # display detailed info about failed tests
282 my $run_event_based; # run curl with --test-event to test the event API
284 my %run; # running server
285 my %doesntrun; # servers that don't work, identified by pidfile
286 my %serverpidfile;# all server pid file names, identified by server id
287 my %runcert; # cert file currently in use by an ssl running server
289 # torture test variables
294 #######################################################################
295 # logmsg is our general message logging subroutine.
303 # get the name of the current user
304 my $USER = $ENV{USER}; # Linux
306 $USER = $ENV{USERNAME}; # Windows
308 $USER = $ENV{LOGNAME}; # Some UNIX (I think)
312 # enable memory debugging if curl is compiled with it
313 $ENV{'CURL_MEMDEBUG'} = $memdump;
318 logmsg "runtests.pl received SIG$signame, exiting\n";
319 stopservers($verbose);
320 die "Somebody sent me a SIG$signame";
322 $SIG{INT} = \&catch_zap;
323 $SIG{TERM} = \&catch_zap;
325 ##########################################################################
326 # Clear all possible '*_proxy' environment variables for various protocols
327 # to prevent them to interfere with our testing!
330 foreach $protocol (('ftp', 'http', 'ftps', 'https', 'no', 'all')) {
331 my $proxy = "${protocol}_proxy";
332 # clear lowercase version
333 delete $ENV{$proxy} if($ENV{$proxy});
334 # clear uppercase version
335 delete $ENV{uc($proxy)} if($ENV{uc($proxy)});
338 # make sure we don't get affected by other variables that control our
341 delete $ENV{'SSL_CERT_DIR'} if($ENV{'SSL_CERT_DIR'});
342 delete $ENV{'SSL_CERT_PATH'} if($ENV{'SSL_CERT_PATH'});
343 delete $ENV{'CURL_CA_BUNDLE'} if($ENV{'CURL_CA_BUNDLE'});
345 #######################################################################
346 # Load serverpidfile hash with pidfile names for all possible servers.
348 sub init_serverpidfile_hash {
349 for my $proto (('ftp', 'http', 'imap', 'pop3', 'smtp', 'http')) {
350 for my $ssl (('', 's')) {
351 for my $ipvnum ((4, 6)) {
352 for my $idnum ((1, 2, 3)) {
353 my $serv = servername_id("$proto$ssl", $ipvnum, $idnum);
354 my $pidf = server_pidfilename("$proto$ssl", $ipvnum, $idnum);
355 $serverpidfile{$serv} = $pidf;
360 for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'gopher', 'httptls')) {
361 for my $ipvnum ((4, 6)) {
362 for my $idnum ((1, 2)) {
363 my $serv = servername_id($proto, $ipvnum, $idnum);
364 my $pidf = server_pidfilename($proto, $ipvnum, $idnum);
365 $serverpidfile{$serv} = $pidf;
371 #######################################################################
372 # Check if a given child process has just died. Reaps it if so.
375 use POSIX ":sys_wait_h";
377 if(not defined $pid || $pid <= 0) {
380 my $rc = waitpid($pid, &WNOHANG);
381 return ($rc == $pid)?1:0;
384 #######################################################################
385 # Start a new thread/process and run the given command line in there.
386 # Return the pids (yes plural) of the new child process to the parent.
389 my ($cmd, $pidfile, $timeout, $fake)=@_;
391 logmsg "startnew: $cmd\n" if ($verbose);
396 if(not defined $child) {
397 logmsg "startnew: fork() failure detected\n";
402 # Here we are the child. Run the given command.
404 # Put an "exec" in front of the command so that the child process
405 # keeps this child's process ID.
406 exec("exec $cmd") || die "Can't exec() $cmd: $!";
408 # exec() should never return back here to this process. We protect
409 # ourselves by calling die() just in case something goes really bad.
410 die "error: exec() has returned";
413 # Ugly hack but ssh client and gnutls-serv don't support pid files
415 if(open(OUT, ">$pidfile")) {
416 print OUT $child . "\n";
418 logmsg "startnew: $pidfile faked with pid=$child\n" if($verbose);
421 logmsg "startnew: failed to write fake $pidfile with pid=$child\n";
423 # could/should do a while connect fails sleep a bit and loop
425 if (checkdied($child)) {
426 logmsg "startnew: child process has failed to start\n" if($verbose);
431 my $count = $timeout;
433 if(-f $pidfile && -s $pidfile && open(PID, "<$pidfile")) {
436 if(($pid2 > 0) && pidexists($pid2)) {
437 # if $pid2 is valid, then make sure this pid is alive, as
438 # otherwise it is just likely to be the _previous_ pidfile or
442 # invalidate $pid2 if not actually alive
445 if (checkdied($child)) {
446 logmsg "startnew: child process has died, server might start up\n"
448 # We can't just abort waiting for the server with a
450 # because the server might have forked and could still start
451 # up normally. Instead, just reduce the amount of time we remain
458 # Return two PIDs, the one for the child process we spawned and the one
459 # reported by the server itself (in case it forked again on its own).
460 # Both (potentially) need to be killed at the end of the test.
461 return ($child, $pid2);
465 #######################################################################
466 # Check for a command in the PATH of the test server.
470 my @paths=(split(":", $ENV{'PATH'}), "/usr/sbin", "/usr/local/sbin",
471 "/sbin", "/usr/bin", "/usr/local/bin",
472 "./libtest/.libs", "./libtest");
474 if( -x "$_/$cmd" && ! -d "$_/$cmd") {
475 # executable bit but not a directory!
481 #######################################################################
482 # Get the list of tests that the tests/data/Makefile.am knows about!
486 my @dist = `cd data && make show`;
487 $disttests = join("", @dist);
490 #######################################################################
491 # Check for a command in the PATH of the machine running curl.
495 return checkcmd($cmd);
498 #######################################################################
499 # Run the application under test and return its return code
503 my $ret = system($cmd);
504 print "CMD ($ret): $cmd\n" if($verbose && !$torture);
507 # This is one way to test curl on a remote machine
508 # my $out = system("ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'");
509 # sleep 2; # time to allow the NFS server to be updated
513 #######################################################################
514 # Run the application under test and return its stdout
516 sub runclientoutput {
520 # This is one way to test curl on a remote machine
521 # my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`;
522 # sleep 2; # time to allow the NFS server to be updated
526 #######################################################################
527 # Memory allocation test and failure torture testing.
533 # remove memdump first to be sure we get a new nice and clean one
536 # First get URL from test server, ignore the output/result
539 logmsg " CMD: $testcmd\n" if($verbose);
541 # memanalyze -v is our friend, get the number of allocations made
543 my @out = `$memanalyze -v $memdump`;
545 if(/^Allocations: (\d+)/) {
551 logmsg " found no allocs to make fail\n";
555 logmsg " $count allocations to make fail\n";
557 for ( 1 .. $count ) {
562 if($tortalloc && ($tortalloc != $limit)) {
567 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
569 my $now = sprintf("%02d:%02d:%02d ", $hour, $min, $sec);
570 logmsg "Fail alloc no: $limit at $now\r";
573 # make the memory allocation function number $limit return failure
574 $ENV{'CURL_MEMLIMIT'} = $limit;
576 # remove memdump first to be sure we get a new nice and clean one
579 logmsg "*** Alloc number $limit is now set to fail ***\n" if($gdbthis);
586 $ret = runclient($testcmd);
588 #logmsg "$_ Returned " . $ret >> 8 . "\n";
590 # Now clear the variable again
591 delete $ENV{'CURL_MEMLIMIT'} if($ENV{'CURL_MEMLIMIT'});
594 # there's core file present now!
595 logmsg " core dumped\n";
600 # verify that it returns a proper error code, doesn't leak memory
601 # and doesn't core dump
603 logmsg " system() returned $ret\n";
607 my @memdata=`$memanalyze $memdump`;
611 # well it could be other memory problems as well, but
612 # we call it leak for short here
617 logmsg "** MEMORY FAILURE\n";
619 logmsg `$memanalyze -l $memdump`;
624 logmsg " Failed on alloc number $limit in test.\n",
625 " invoke with \"-t$limit\" to repeat this single case.\n";
626 stopservers($verbose);
631 logmsg "torture OK\n";
635 #######################################################################
636 # Stop a test server along with pids which aren't in the %run hash yet.
637 # This also stops all servers which are relative to the given one.
640 my ($server, $pidlist) = @_;
642 # kill sockfilter processes for pingpong relative server
644 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
646 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
647 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
648 killsockfilters($proto, $ipvnum, $idnum, $verbose);
651 # All servers relative to the given one must be stopped also
654 if($server =~ /^(ftp|http|imap|pop3|smtp|httppipe)s((\d*)(-ipv6|))$/) {
655 # given a stunnel based ssl server, also kill non-ssl underlying one
656 push @killservers, "${1}${2}";
658 elsif($server =~ /^(ftp|http|imap|pop3|smtp|httppipe)((\d*)(-ipv6|))$/) {
659 # given a non-ssl server, also kill stunnel based ssl piggybacking one
660 push @killservers, "${1}s${2}";
662 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
663 # given a socks server, also kill ssh underlying one
664 push @killservers, "ssh${2}";
666 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
667 # given a ssh server, also kill socks piggybacking one
668 push @killservers, "socks${2}";
670 push @killservers, $server;
672 # kill given pids and server relative ones clearing them in %run hash
674 foreach my $server (@killservers) {
676 # we must prepend a space since $pidlist may already contain a pid
677 $pidlist .= " $run{$server}";
680 $runcert{$server} = 0 if($runcert{$server});
682 killpid($verbose, $pidlist);
684 # cleanup server pid files
686 foreach my $server (@killservers) {
687 my $pidfile = $serverpidfile{$server};
688 my $pid = processexists($pidfile);
690 logmsg "Warning: $server server unexpectedly alive\n";
691 killpid($verbose, $pid);
693 unlink($pidfile) if(-f $pidfile);
697 #######################################################################
698 # Verify that the server that runs on $ip, $port is our server. This also
699 # implies that we can speak with it, as there might be occasions when the
700 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
701 # assign requested address")
704 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
705 my $server = servername_id($proto, $ipvnum, $idnum);
709 my $verifyout = "$LOGDIR/".
710 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
711 unlink($verifyout) if(-f $verifyout);
713 my $verifylog = "$LOGDIR/".
714 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
715 unlink($verifylog) if(-f $verifylog);
717 if($proto eq "gopher") {
722 my $flags = "--max-time $server_response_maxtime ";
723 $flags .= "--output $verifyout ";
724 $flags .= "--silent ";
725 $flags .= "--verbose ";
726 $flags .= "--globoff ";
727 $flags .= "-1 " if($has_axtls);
728 $flags .= "--insecure " if($proto eq 'https');
729 $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\"";
731 my $cmd = "$VCURL $flags 2>$verifylog";
733 # verify if our/any server is running on this port
734 logmsg "RUN: $cmd\n" if($verbose);
735 my $res = runclient($cmd);
737 $res >>= 8; # rotate the result
739 logmsg "RUN: curl command died with a coredump\n";
743 if($res && $verbose) {
744 logmsg "RUN: curl command returned $res\n";
745 if(open(FILE, "<$verifylog")) {
746 while(my $string = <FILE>) {
747 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
754 if(open(FILE, "<$verifyout")) {
755 while(my $string = <FILE>) {
757 last; # only want first line
762 if($data && ($data =~ /WE ROOLZ: (\d+)/)) {
766 # curl: (6) Couldn't resolve host '::1'
767 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
770 elsif($data || ($res && ($res != 7))) {
771 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
777 #######################################################################
778 # Verify that the server that runs on $ip, $port is our server. This also
779 # implies that we can speak with it, as there might be occasions when the
780 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
781 # assign requested address")
784 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
785 my $server = servername_id($proto, $ipvnum, $idnum);
790 my $verifylog = "$LOGDIR/".
791 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
792 unlink($verifylog) if(-f $verifylog);
794 if($proto eq "ftps") {
795 $extra .= "--insecure --ftp-ssl-control ";
798 my $flags = "--max-time $server_response_maxtime ";
799 $flags .= "--silent ";
800 $flags .= "--verbose ";
801 $flags .= "--globoff ";
803 $flags .= "\"$proto://$ip:$port/verifiedserver\"";
805 my $cmd = "$VCURL $flags 2>$verifylog";
807 # check if this is our server running on this port:
808 logmsg "RUN: $cmd\n" if($verbose);
809 my @data = runclientoutput($cmd);
811 my $res = $? >> 8; # rotate the result
813 logmsg "RUN: curl command died with a coredump\n";
817 foreach my $line (@data) {
818 if($line =~ /WE ROOLZ: (\d+)/) {
819 # this is our test server with a known pid!
824 if($pid <= 0 && @data && $data[0]) {
825 # this is not a known server
826 logmsg "RUN: Unknown server on our $server port: $port\n";
829 # we can/should use the time it took to verify the FTP server as a measure
830 # on how fast/slow this host/FTP is.
831 my $took = int(0.5+time()-$time);
834 logmsg "RUN: Verifying our test $server server took $took seconds\n";
836 $ftpchecktime = $took>=1?$took:1; # make sure it never is below 1
841 #######################################################################
842 # Verify that the server that runs on $ip, $port is our server. This also
843 # implies that we can speak with it, as there might be occasions when the
844 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
845 # assign requested address")
848 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
849 my $server = servername_id($proto, $ipvnum, $idnum);
852 my $verifyout = "$LOGDIR/".
853 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
854 unlink($verifyout) if(-f $verifyout);
856 my $verifylog = "$LOGDIR/".
857 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
858 unlink($verifylog) if(-f $verifylog);
860 my $flags = "--max-time $server_response_maxtime ";
861 $flags .= "--output $verifyout ";
862 $flags .= "--silent ";
863 $flags .= "--verbose ";
864 $flags .= "--globoff ";
865 # currently verification is done using http
866 $flags .= "\"http://$ip:$port/verifiedserver\"";
868 my $cmd = "$VCURL $flags 2>$verifylog";
870 # verify if our/any server is running on this port
871 logmsg "RUN: $cmd\n" if($verbose);
872 my $res = runclient($cmd);
874 $res >>= 8; # rotate the result
876 logmsg "RUN: curl command died with a coredump\n";
880 if($res && $verbose) {
881 logmsg "RUN: curl command returned $res\n";
882 if(open(FILE, "<$verifylog")) {
883 while(my $string = <FILE>) {
884 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
891 if(open(FILE, "<$verifyout")) {
892 while(my $string = <FILE>) {
894 last; # only want first line
899 if($data && ($data =~ /RTSP_SERVER WE ROOLZ: (\d+)/)) {
903 # curl: (6) Couldn't resolve host '::1'
904 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
907 elsif($data || ($res != 7)) {
908 logmsg "RUN: Unknown server on our $server port: $port\n";
914 #######################################################################
915 # Verify that the ssh server has written out its pidfile, recovering
916 # the pid from the file and returning it if a process with that pid is
920 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
921 my $server = servername_id($proto, $ipvnum, $idnum);
922 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
924 if(open(FILE, "<$pidfile")) {
929 # if we have a pid it is actually our ssh server,
930 # since runsshserver() unlinks previous pidfile
931 if(!pidexists($pid)) {
932 logmsg "RUN: SSH server has died after starting up\n";
941 #######################################################################
942 # Verify that we can connect to the sftp server, properly authenticate
943 # with generated config and key files and run a simple remote pwd.
946 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
947 my $server = servername_id($proto, $ipvnum, $idnum);
949 # Find out sftp client canonical file name
950 my $sftp = find_sftp();
952 logmsg "RUN: SFTP server cannot find $sftpexe\n";
955 # Find out ssh client canonical file name
956 my $ssh = find_ssh();
958 logmsg "RUN: SFTP server cannot find $sshexe\n";
961 # Connect to sftp server, authenticate and run a remote pwd
962 # command using our generated configuration and key files
963 my $cmd = "$sftp -b $sftpcmds -F $sftpconfig -S $ssh $ip > $sftplog 2>&1";
964 my $res = runclient($cmd);
965 # Search for pwd command response in log file
966 if(open(SFTPLOGFILE, "<$sftplog")) {
967 while(<SFTPLOGFILE>) {
968 if(/^Remote working directory: /) {
978 #######################################################################
979 # Verify that the non-stunnel HTTP TLS extensions capable server that runs
980 # on $ip, $port is our server. This also implies that we can speak with it,
981 # as there might be occasions when the server runs fine but we cannot talk
982 # to it ("Failed to connect to ::1: Can't assign requested address")
985 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
986 my $server = servername_id($proto, $ipvnum, $idnum);
987 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
990 my $verifyout = "$LOGDIR/".
991 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
992 unlink($verifyout) if(-f $verifyout);
994 my $verifylog = "$LOGDIR/".
995 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
996 unlink($verifylog) if(-f $verifylog);
998 my $flags = "--max-time $server_response_maxtime ";
999 $flags .= "--output $verifyout ";
1000 $flags .= "--verbose ";
1001 $flags .= "--globoff ";
1002 $flags .= "--insecure ";
1003 $flags .= "--tlsauthtype SRP ";
1004 $flags .= "--tlsuser jsmith ";
1005 $flags .= "--tlspassword abc ";
1006 $flags .= "\"https://$ip:$port/verifiedserver\"";
1008 my $cmd = "$VCURL $flags 2>$verifylog";
1010 # verify if our/any server is running on this port
1011 logmsg "RUN: $cmd\n" if($verbose);
1012 my $res = runclient($cmd);
1014 $res >>= 8; # rotate the result
1016 logmsg "RUN: curl command died with a coredump\n";
1020 if($res && $verbose) {
1021 logmsg "RUN: curl command returned $res\n";
1022 if(open(FILE, "<$verifylog")) {
1023 while(my $string = <FILE>) {
1024 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
1031 if(open(FILE, "<$verifyout")) {
1032 while(my $string = <FILE>) {
1038 if($data && ($data =~ /GNUTLS/) && open(FILE, "<$pidfile")) {
1042 # if we have a pid it is actually our httptls server,
1043 # since runhttptlsserver() unlinks previous pidfile
1044 if(!pidexists($pid)) {
1045 logmsg "RUN: $server server has died after starting up\n";
1054 # curl: (6) Couldn't resolve host '::1'
1055 logmsg "RUN: failed to resolve host (https://$ip:$port/verifiedserver)\n";
1058 elsif($data || ($res && ($res != 7))) {
1059 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
1065 #######################################################################
1066 # STUB for verifying socks
1069 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1070 my $server = servername_id($proto, $ipvnum, $idnum);
1071 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
1073 if(open(FILE, "<$pidfile")) {
1078 # if we have a pid it is actually our socks server,
1079 # since runsocksserver() unlinks previous pidfile
1080 if(!pidexists($pid)) {
1081 logmsg "RUN: SOCKS server has died after starting up\n";
1090 #######################################################################
1091 # Verify that the server that runs on $ip, $port is our server.
1092 # Retry over several seconds before giving up. The ssh server in
1093 # particular can take a long time to start if it needs to generate
1094 # keys on a slow or loaded host.
1096 # Just for convenience, test harness uses 'https' and 'httptls' literals
1097 # as values for 'proto' variable in order to differentiate different
1098 # servers. 'https' literal is used for stunnel based https test servers,
1099 # and 'httptls' is used for non-stunnel https test servers.
1102 my %protofunc = ('http' => \&verifyhttp,
1103 'https' => \&verifyhttp,
1104 'rtsp' => \&verifyrtsp,
1105 'ftp' => \&verifyftp,
1106 'pop3' => \&verifyftp,
1107 'imap' => \&verifyftp,
1108 'smtp' => \&verifyftp,
1109 'httppipe' => \&verifyhttp,
1110 'ftps' => \&verifyftp,
1111 'tftp' => \&verifyftp,
1112 'ssh' => \&verifyssh,
1113 'socks' => \&verifysocks,
1114 'gopher' => \&verifyhttp,
1115 'httptls' => \&verifyhttptls);
1118 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1120 my $count = 30; # try for this many seconds
1124 my $fun = $protofunc{$proto};
1126 $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1132 # a real failure, stop trying and bail out
1140 #######################################################################
1141 # Single shot server responsiveness test. This should only be used
1142 # to verify that a server present in %run hash is still functional
1144 sub responsiveserver {
1145 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1146 my $prev_verbose = $verbose;
1149 my $fun = $protofunc{$proto};
1150 my $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1151 $verbose = $prev_verbose;
1154 return 1; # responsive
1157 my $srvrname = servername_str($proto, $ipvnum, $idnum);
1158 logmsg " server precheck FAILED (unresponsive $srvrname server)\n";
1162 #######################################################################
1163 # start the http server
1166 my ($proto, $verbose, $alt, $port) = @_;
1175 my $exe = "$perl $srcdir/httpserver.pl";
1176 my $verbose_flag = "--verbose ";
1178 if($alt eq "ipv6") {
1179 # if IPv6, use a different setup
1183 elsif($alt eq "proxy") {
1184 # basically the same, but another ID
1187 elsif($alt eq "pipe") {
1188 # basically the same, but another ID
1190 $exe = "python $srcdir/http_pipe.py";
1191 $verbose_flag .= "1 ";
1194 $server = servername_id($proto, $ipvnum, $idnum);
1196 $pidfile = $serverpidfile{$server};
1198 # don't retry if the server doesn't work
1199 if ($doesntrun{$pidfile}) {
1203 my $pid = processexists($pidfile);
1205 stopserver($server, "$pid");
1207 unlink($pidfile) if(-f $pidfile);
1209 $srvrname = servername_str($proto, $ipvnum, $idnum);
1211 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1213 $flags .= "--gopher " if($proto eq "gopher");
1214 $flags .= "--connect $HOSTIP " if($alt eq "proxy");
1215 $flags .= $verbose_flag if($debugprotocol);
1216 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1217 $flags .= "--id $idnum " if($idnum > 1);
1218 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1220 my $cmd = "$exe $flags";
1221 my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1223 if($httppid <= 0 || !pidexists($httppid)) {
1225 logmsg "RUN: failed to start the $srvrname server\n";
1226 stopserver($server, "$pid2");
1227 displaylogs($testnumcheck);
1228 $doesntrun{$pidfile} = 1;
1232 # Server is up. Verify that we can speak to it.
1233 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1235 logmsg "RUN: $srvrname server failed verification\n";
1236 # failed to talk to it properly. Kill the server and return failure
1237 stopserver($server, "$httppid $pid2");
1238 displaylogs($testnumcheck);
1239 $doesntrun{$pidfile} = 1;
1245 logmsg "RUN: $srvrname server is now running PID $httppid\n";
1250 return ($httppid, $pid2);
1253 #######################################################################
1254 # start the http server
1256 sub runhttp_pipeserver {
1257 my ($proto, $verbose, $alt, $port) = @_;
1267 if($alt eq "ipv6") {
1271 $server = servername_id($proto, $ipvnum, $idnum);
1273 $pidfile = $serverpidfile{$server};
1275 # don't retry if the server doesn't work
1276 if ($doesntrun{$pidfile}) {
1280 my $pid = processexists($pidfile);
1282 stopserver($server, "$pid");
1284 unlink($pidfile) if(-f $pidfile);
1286 $srvrname = servername_str($proto, $ipvnum, $idnum);
1288 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1290 $flags .= "--verbose 1 " if($debugprotocol);
1291 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1292 $flags .= "--id $idnum " if($idnum > 1);
1293 $flags .= "--port $port --srcdir \"$srcdir\"";
1295 my $cmd = "$srcdir/http_pipe.py $flags";
1296 my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1298 if($httppid <= 0 || !pidexists($httppid)) {
1300 logmsg "RUN: failed to start the $srvrname server\n";
1301 stopserver($server, "$pid2");
1302 displaylogs($testnumcheck);
1303 $doesntrun{$pidfile} = 1;
1307 # Server is up. Verify that we can speak to it.
1308 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1310 logmsg "RUN: $srvrname server failed verification\n";
1311 # failed to talk to it properly. Kill the server and return failure
1312 stopserver($server, "$httppid $pid2");
1313 displaylogs($testnumcheck);
1314 $doesntrun{$pidfile} = 1;
1320 logmsg "RUN: $srvrname server is now running PID $httppid\n";
1325 return ($httppid, $pid2);
1328 #######################################################################
1329 # start the https stunnel based server
1331 sub runhttpsserver {
1332 my ($verbose, $ipv6, $certfile) = @_;
1333 my $proto = 'https';
1334 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1335 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1347 $server = servername_id($proto, $ipvnum, $idnum);
1349 $pidfile = $serverpidfile{$server};
1351 # don't retry if the server doesn't work
1352 if ($doesntrun{$pidfile}) {
1356 my $pid = processexists($pidfile);
1358 stopserver($server, "$pid");
1360 unlink($pidfile) if(-f $pidfile);
1362 $srvrname = servername_str($proto, $ipvnum, $idnum);
1364 $certfile = 'stunnel.pem' unless($certfile);
1366 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1368 $flags .= "--verbose " if($debugprotocol);
1369 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1370 $flags .= "--id $idnum " if($idnum > 1);
1371 $flags .= "--ipv$ipvnum --proto $proto ";
1372 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1373 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1374 $flags .= "--connect $HTTPPORT --accept $HTTPSPORT";
1376 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1377 my ($httpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1379 if($httpspid <= 0 || !pidexists($httpspid)) {
1381 logmsg "RUN: failed to start the $srvrname server\n";
1382 stopserver($server, "$pid2");
1383 displaylogs($testnumcheck);
1384 $doesntrun{$pidfile} = 1;
1388 # Server is up. Verify that we can speak to it.
1389 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $HTTPSPORT);
1391 logmsg "RUN: $srvrname server failed verification\n";
1392 # failed to talk to it properly. Kill the server and return failure
1393 stopserver($server, "$httpspid $pid2");
1394 displaylogs($testnumcheck);
1395 $doesntrun{$pidfile} = 1;
1398 # Here pid3 is actually the pid returned by the unsecure-http server.
1400 $runcert{$server} = $certfile;
1403 logmsg "RUN: $srvrname server is now running PID $httpspid\n";
1408 return ($httpspid, $pid2);
1411 #######################################################################
1412 # start the non-stunnel HTTP TLS extensions capable server
1414 sub runhttptlsserver {
1415 my ($verbose, $ipv6) = @_;
1416 my $proto = "httptls";
1417 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
1418 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1419 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1431 $server = servername_id($proto, $ipvnum, $idnum);
1433 $pidfile = $serverpidfile{$server};
1435 # don't retry if the server doesn't work
1436 if ($doesntrun{$pidfile}) {
1440 my $pid = processexists($pidfile);
1442 stopserver($server, "$pid");
1444 unlink($pidfile) if(-f $pidfile);
1446 $srvrname = servername_str($proto, $ipvnum, $idnum);
1448 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1450 $flags .= "--http ";
1451 $flags .= "--debug 1 " if($debugprotocol);
1452 $flags .= "--port $port ";
1453 $flags .= "--srppasswd $srcdir/certs/srp-verifier-db ";
1454 $flags .= "--srppasswdconf $srcdir/certs/srp-verifier-conf";
1456 my $cmd = "$httptlssrv $flags > $logfile 2>&1";
1457 my ($httptlspid, $pid2) = startnew($cmd, $pidfile, 10, 1); # fake pidfile
1459 if($httptlspid <= 0 || !pidexists($httptlspid)) {
1461 logmsg "RUN: failed to start the $srvrname server\n";
1462 stopserver($server, "$pid2");
1463 displaylogs($testnumcheck);
1464 $doesntrun{$pidfile} = 1;
1468 # Server is up. Verify that we can speak to it. PID is from fake pidfile
1469 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1471 logmsg "RUN: $srvrname server failed verification\n";
1472 # failed to talk to it properly. Kill the server and return failure
1473 stopserver($server, "$httptlspid $pid2");
1474 displaylogs($testnumcheck);
1475 $doesntrun{$pidfile} = 1;
1481 logmsg "RUN: $srvrname server is now running PID $httptlspid\n";
1486 return ($httptlspid, $pid2);
1489 #######################################################################
1490 # start the pingpong server (FTP, POP3, IMAP, SMTP)
1492 sub runpingpongserver {
1493 my ($proto, $id, $verbose, $ipv6) = @_;
1495 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1496 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1497 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1504 if($proto eq "ftp") {
1505 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
1508 # if IPv6, use a different setup
1512 elsif($proto eq "pop3") {
1513 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
1515 elsif($proto eq "imap") {
1516 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
1518 elsif($proto eq "smtp") {
1519 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
1522 print STDERR "Unsupported protocol $proto!!\n";
1526 $server = servername_id($proto, $ipvnum, $idnum);
1528 $pidfile = $serverpidfile{$server};
1530 # don't retry if the server doesn't work
1531 if ($doesntrun{$pidfile}) {
1535 my $pid = processexists($pidfile);
1537 stopserver($server, "$pid");
1539 unlink($pidfile) if(-f $pidfile);
1541 $srvrname = servername_str($proto, $ipvnum, $idnum);
1543 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1545 $flags .= "--verbose " if($debugprotocol);
1546 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1547 $flags .= "--srcdir \"$srcdir\" --proto $proto ";
1548 $flags .= "--id $idnum " if($idnum > 1);
1549 $flags .= "--ipv$ipvnum --port $port --addr \"$ip\"";
1551 my $cmd = "$perl $srcdir/ftpserver.pl $flags";
1552 my ($ftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1554 if($ftppid <= 0 || !pidexists($ftppid)) {
1556 logmsg "RUN: failed to start the $srvrname server\n";
1557 stopserver($server, "$pid2");
1558 displaylogs($testnumcheck);
1559 $doesntrun{$pidfile} = 1;
1563 # Server is up. Verify that we can speak to it.
1564 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1566 logmsg "RUN: $srvrname server failed verification\n";
1567 # failed to talk to it properly. Kill the server and return failure
1568 stopserver($server, "$ftppid $pid2");
1569 displaylogs($testnumcheck);
1570 $doesntrun{$pidfile} = 1;
1577 logmsg "RUN: $srvrname server is now running PID $ftppid\n";
1582 return ($pid2, $ftppid);
1585 #######################################################################
1586 # start the ftps server (or rather, tunnel)
1589 my ($verbose, $ipv6, $certfile) = @_;
1591 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1592 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1604 $server = servername_id($proto, $ipvnum, $idnum);
1606 $pidfile = $serverpidfile{$server};
1608 # don't retry if the server doesn't work
1609 if ($doesntrun{$pidfile}) {
1613 my $pid = processexists($pidfile);
1615 stopserver($server, "$pid");
1617 unlink($pidfile) if(-f $pidfile);
1619 $srvrname = servername_str($proto, $ipvnum, $idnum);
1621 $certfile = 'stunnel.pem' unless($certfile);
1623 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1625 $flags .= "--verbose " if($debugprotocol);
1626 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1627 $flags .= "--id $idnum " if($idnum > 1);
1628 $flags .= "--ipv$ipvnum --proto $proto ";
1629 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1630 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1631 $flags .= "--connect $FTPPORT --accept $FTPSPORT";
1633 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1634 my ($ftpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1636 if($ftpspid <= 0 || !pidexists($ftpspid)) {
1638 logmsg "RUN: failed to start the $srvrname server\n";
1639 stopserver($server, "$pid2");
1640 displaylogs($testnumcheck);
1641 $doesntrun{$pidfile} = 1;
1645 # Server is up. Verify that we can speak to it.
1646 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $FTPSPORT);
1648 logmsg "RUN: $srvrname server failed verification\n";
1649 # failed to talk to it properly. Kill the server and return failure
1650 stopserver($server, "$ftpspid $pid2");
1651 displaylogs($testnumcheck);
1652 $doesntrun{$pidfile} = 1;
1655 # Here pid3 is actually the pid returned by the unsecure-ftp server.
1657 $runcert{$server} = $certfile;
1660 logmsg "RUN: $srvrname server is now running PID $ftpspid\n";
1665 return ($ftpspid, $pid2);
1668 #######################################################################
1669 # start the tftp server
1672 my ($id, $verbose, $ipv6) = @_;
1673 my $port = $TFTPPORT;
1677 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1685 # if IPv6, use a different setup
1691 $server = servername_id($proto, $ipvnum, $idnum);
1693 $pidfile = $serverpidfile{$server};
1695 # don't retry if the server doesn't work
1696 if ($doesntrun{$pidfile}) {
1700 my $pid = processexists($pidfile);
1702 stopserver($server, "$pid");
1704 unlink($pidfile) if(-f $pidfile);
1706 $srvrname = servername_str($proto, $ipvnum, $idnum);
1708 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1710 $flags .= "--verbose " if($debugprotocol);
1711 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1712 $flags .= "--id $idnum " if($idnum > 1);
1713 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1715 my $cmd = "$perl $srcdir/tftpserver.pl $flags";
1716 my ($tftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1718 if($tftppid <= 0 || !pidexists($tftppid)) {
1720 logmsg "RUN: failed to start the $srvrname server\n";
1721 stopserver($server, "$pid2");
1722 displaylogs($testnumcheck);
1723 $doesntrun{$pidfile} = 1;
1727 # Server is up. Verify that we can speak to it.
1728 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1730 logmsg "RUN: $srvrname server failed verification\n";
1731 # failed to talk to it properly. Kill the server and return failure
1732 stopserver($server, "$tftppid $pid2");
1733 displaylogs($testnumcheck);
1734 $doesntrun{$pidfile} = 1;
1740 logmsg "RUN: $srvrname server is now running PID $tftppid\n";
1745 return ($pid2, $tftppid);
1749 #######################################################################
1750 # start the rtsp server
1753 my ($verbose, $ipv6) = @_;
1754 my $port = $RTSPPORT;
1766 # if IPv6, use a different setup
1772 $server = servername_id($proto, $ipvnum, $idnum);
1774 $pidfile = $serverpidfile{$server};
1776 # don't retry if the server doesn't work
1777 if ($doesntrun{$pidfile}) {
1781 my $pid = processexists($pidfile);
1783 stopserver($server, "$pid");
1785 unlink($pidfile) if(-f $pidfile);
1787 $srvrname = servername_str($proto, $ipvnum, $idnum);
1789 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1791 $flags .= "--verbose " if($debugprotocol);
1792 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1793 $flags .= "--id $idnum " if($idnum > 1);
1794 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1796 my $cmd = "$perl $srcdir/rtspserver.pl $flags";
1797 my ($rtsppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1799 if($rtsppid <= 0 || !pidexists($rtsppid)) {
1801 logmsg "RUN: failed to start the $srvrname server\n";
1802 stopserver($server, "$pid2");
1803 displaylogs($testnumcheck);
1804 $doesntrun{$pidfile} = 1;
1808 # Server is up. Verify that we can speak to it.
1809 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1811 logmsg "RUN: $srvrname server failed verification\n";
1812 # failed to talk to it properly. Kill the server and return failure
1813 stopserver($server, "$rtsppid $pid2");
1814 displaylogs($testnumcheck);
1815 $doesntrun{$pidfile} = 1;
1821 logmsg "RUN: $srvrname server is now running PID $rtsppid\n";
1826 return ($rtsppid, $pid2);
1830 #######################################################################
1831 # Start the ssh (scp/sftp) server
1834 my ($id, $verbose, $ipv6) = @_;
1836 my $port = $SSHPORT;
1837 my $socksport = $SOCKSPORT;
1840 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1847 $server = servername_id($proto, $ipvnum, $idnum);
1849 $pidfile = $serverpidfile{$server};
1851 # don't retry if the server doesn't work
1852 if ($doesntrun{$pidfile}) {
1856 my $pid = processexists($pidfile);
1858 stopserver($server, "$pid");
1860 unlink($pidfile) if(-f $pidfile);
1862 $srvrname = servername_str($proto, $ipvnum, $idnum);
1864 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1866 $flags .= "--verbose " if($verbose);
1867 $flags .= "--debugprotocol " if($debugprotocol);
1868 $flags .= "--pidfile \"$pidfile\" ";
1869 $flags .= "--id $idnum " if($idnum > 1);
1870 $flags .= "--ipv$ipvnum --addr \"$ip\" ";
1871 $flags .= "--sshport $port --socksport $socksport ";
1872 $flags .= "--user \"$USER\"";
1874 my $cmd = "$perl $srcdir/sshserver.pl $flags";
1875 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 60, 0);
1877 # on loaded systems sshserver start up can take longer than the timeout
1878 # passed to startnew, when this happens startnew completes without being
1879 # able to read the pidfile and consequently returns a zero pid2 above.
1881 if($sshpid <= 0 || !pidexists($sshpid)) {
1883 logmsg "RUN: failed to start the $srvrname server\n";
1884 stopserver($server, "$pid2");
1885 $doesntrun{$pidfile} = 1;
1889 # ssh server verification allows some extra time for the server to start up
1890 # and gives us the opportunity of recovering the pid from the pidfile, when
1891 # this verification succeeds the recovered pid is assigned to pid2.
1893 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1895 logmsg "RUN: $srvrname server failed verification\n";
1896 # failed to fetch server pid. Kill the server and return failure
1897 stopserver($server, "$sshpid $pid2");
1898 $doesntrun{$pidfile} = 1;
1903 # once it is known that the ssh server is alive, sftp server verification
1904 # is performed actually connecting to it, authenticating and performing a
1905 # very simple remote command. This verification is tried only one time.
1907 $sshdlog = server_logfilename($LOGDIR, 'ssh', $ipvnum, $idnum);
1908 $sftplog = server_logfilename($LOGDIR, 'sftp', $ipvnum, $idnum);
1910 if(verifysftp('sftp', $ipvnum, $idnum, $ip, $port) < 1) {
1911 logmsg "RUN: SFTP server failed verification\n";
1912 # failed to talk to it properly. Kill the server and return failure
1914 display_sftpconfig();
1916 display_sshdconfig();
1917 stopserver($server, "$sshpid $pid2");
1918 $doesntrun{$pidfile} = 1;
1923 logmsg "RUN: $srvrname server is now running PID $pid2\n";
1926 return ($pid2, $sshpid);
1929 #######################################################################
1930 # Start the socks server
1932 sub runsocksserver {
1933 my ($id, $verbose, $ipv6) = @_;
1935 my $port = $SOCKSPORT;
1936 my $proto = 'socks';
1938 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1945 $server = servername_id($proto, $ipvnum, $idnum);
1947 $pidfile = $serverpidfile{$server};
1949 # don't retry if the server doesn't work
1950 if ($doesntrun{$pidfile}) {
1954 my $pid = processexists($pidfile);
1956 stopserver($server, "$pid");
1958 unlink($pidfile) if(-f $pidfile);
1960 $srvrname = servername_str($proto, $ipvnum, $idnum);
1962 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1964 # The ssh server must be already running
1966 logmsg "RUN: SOCKS server cannot find running SSH server\n";
1967 $doesntrun{$pidfile} = 1;
1971 # Find out ssh daemon canonical file name
1972 my $sshd = find_sshd();
1974 logmsg "RUN: SOCKS server cannot find $sshdexe\n";
1975 $doesntrun{$pidfile} = 1;
1979 # Find out ssh daemon version info
1980 ($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd);
1982 # Not an OpenSSH or SunSSH ssh daemon
1983 logmsg "$sshderror\n" if($verbose);
1984 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
1985 $doesntrun{$pidfile} = 1;
1988 logmsg "ssh server found $sshd is $sshdverstr\n" if($verbose);
1990 # Find out ssh client canonical file name
1991 my $ssh = find_ssh();
1993 logmsg "RUN: SOCKS server cannot find $sshexe\n";
1994 $doesntrun{$pidfile} = 1;
1998 # Find out ssh client version info
1999 my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh);
2001 # Not an OpenSSH or SunSSH ssh client
2002 logmsg "$ssherror\n" if($verbose);
2003 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
2004 $doesntrun{$pidfile} = 1;
2008 # Verify minimum ssh client version
2009 if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
2010 (($sshid =~ /SunSSH/) && ($sshvernum < 100))) {
2011 logmsg "ssh client found $ssh is $sshverstr\n";
2012 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
2013 $doesntrun{$pidfile} = 1;
2016 logmsg "ssh client found $ssh is $sshverstr\n" if($verbose);
2018 # Verify if ssh client and ssh daemon versions match
2019 if(($sshdid ne $sshid) || ($sshdvernum != $sshvernum)) {
2020 # Our test harness might work with slightly mismatched versions
2021 logmsg "Warning: version mismatch: sshd $sshdverstr - ssh $sshverstr\n"
2025 # Config file options for ssh client are previously set from sshserver.pl
2026 if(! -e $sshconfig) {
2027 logmsg "RUN: SOCKS server cannot find $sshconfig\n";
2028 $doesntrun{$pidfile} = 1;
2032 $sshlog = server_logfilename($LOGDIR, 'socks', $ipvnum, $idnum);
2034 # start our socks server
2035 my $cmd="$ssh -N -F $sshconfig $ip > $sshlog 2>&1";
2036 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 30, 1); # fake pidfile
2038 if($sshpid <= 0 || !pidexists($sshpid)) {
2040 logmsg "RUN: failed to start the $srvrname server\n";
2042 display_sshconfig();
2044 display_sshdconfig();
2045 stopserver($server, "$pid2");
2046 $doesntrun{$pidfile} = 1;
2050 # Ugly hack but ssh doesn't support pid files. PID is from fake pidfile.
2051 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2053 logmsg "RUN: $srvrname server failed verification\n";
2054 # failed to talk to it properly. Kill the server and return failure
2055 stopserver($server, "$sshpid $pid2");
2056 $doesntrun{$pidfile} = 1;
2062 logmsg "RUN: $srvrname server is now running PID $pid2\n";
2065 return ($pid2, $sshpid);
2068 #######################################################################
2069 # Single shot http and gopher server responsiveness test. This should only
2070 # be used to verify that a server present in %run hash is still functional
2072 sub responsive_http_server {
2073 my ($proto, $verbose, $alt, $port) = @_;
2078 if($alt eq "ipv6") {
2079 # if IPv6, use a different setup
2083 elsif($alt eq "proxy") {
2087 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2090 #######################################################################
2091 # Single shot pingpong server responsiveness test. This should only be
2092 # used to verify that a server present in %run hash is still functional
2094 sub responsive_pingpong_server {
2095 my ($proto, $id, $verbose, $ipv6) = @_;
2097 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2098 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2099 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2101 if($proto eq "ftp") {
2102 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
2105 # if IPv6, use a different setup
2109 elsif($proto eq "pop3") {
2110 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
2112 elsif($proto eq "imap") {
2113 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
2115 elsif($proto eq "smtp") {
2116 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
2119 print STDERR "Unsupported protocol $proto!!\n";
2123 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2126 #######################################################################
2127 # Single shot rtsp server responsiveness test. This should only be
2128 # used to verify that a server present in %run hash is still functional
2130 sub responsive_rtsp_server {
2131 my ($verbose, $ipv6) = @_;
2132 my $port = $RTSPPORT;
2139 # if IPv6, use a different setup
2145 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2148 #######################################################################
2149 # Single shot tftp server responsiveness test. This should only be
2150 # used to verify that a server present in %run hash is still functional
2152 sub responsive_tftp_server {
2153 my ($id, $verbose, $ipv6) = @_;
2154 my $port = $TFTPPORT;
2158 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2161 # if IPv6, use a different setup
2167 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2170 #######################################################################
2171 # Single shot non-stunnel HTTP TLS extensions capable server
2172 # responsiveness test. This should only be used to verify that a
2173 # server present in %run hash is still functional
2175 sub responsive_httptls_server {
2176 my ($verbose, $ipv6) = @_;
2177 my $proto = "httptls";
2178 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
2179 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2180 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2183 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2186 #######################################################################
2187 # Remove all files in the specified directory
2195 opendir(DIR, $dir) ||
2196 return 0; # can't open dir
2197 while($file = readdir(DIR)) {
2198 if($file !~ /^\./) {
2199 unlink("$dir/$file");
2207 #######################################################################
2208 # filter out the specified pattern from the given input file and store the
2209 # results in the given output file
2216 open(IN, "<$infile")
2219 open(OUT, ">$ofile")
2222 # logmsg "FILTER: off $filter from $infile to $ofile\n";
2233 #######################################################################
2234 # compare test results with the expected output, we might filter off
2235 # some pattern that is allowed to differ, output test results
2238 # filter off patterns _before_ this comparison!
2239 my ($testnum, $testname, $subject, $firstref, $secondref)=@_;
2241 my $result = compareparts($firstref, $secondref);
2244 # timestamp test result verification end
2245 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
2248 logmsg "\n $testnum: $subject FAILED:\n";
2249 logmsg showdiff($LOGDIR, $firstref, $secondref);
2251 elsif(!$automakestyle) {
2256 logmsg "FAIL: $testnum - $testname - $subject\n";
2262 #######################################################################
2263 # display information about curl and the host the test suite runs on
2267 unlink($memdump); # remove this if there was one left
2276 my $curlverout="$LOGDIR/curlverout.log";
2277 my $curlvererr="$LOGDIR/curlvererr.log";
2278 my $versioncmd="$CURL --version 1>$curlverout 2>$curlvererr";
2280 unlink($curlverout);
2281 unlink($curlvererr);
2283 $versretval = runclient($versioncmd);
2286 open(VERSOUT, "<$curlverout");
2287 @version = <VERSOUT>;
2296 $curl =~ s/^(.*)(libcurl.*)/$1/g;
2299 if($curl =~ /mingw32/) {
2300 # This is a windows minw32 build, we need to translate the
2301 # given path to the "actual" windows path. The MSYS shell
2302 # has a builtin 'pwd -W' command which converts the path.
2303 $pwd = `sh -c "echo \$(pwd -W)"`;
2306 elsif ($curl =~ /win32/) {
2307 # Native Windows builds don't understand the
2308 # output of cygwin's pwd. It will be
2309 # something like /cygdrive/c/<some path>.
2311 # Use the cygpath utility to convert the
2312 # working directory to a Windows friendly
2313 # path. The -m option converts to use drive
2314 # letter:, but it uses / instead \. Forward
2315 # slashes (/) are easier for us. We don't
2316 # have to escape them to get them to curl
2318 chomp($pwd = `cygpath -m $pwd`);
2320 if ($libcurl =~ /winssl/i) {
2324 elsif ($libcurl =~ /openssl/i) {
2328 elsif ($libcurl =~ /gnutls/i) {
2332 elsif ($libcurl =~ /nss/i) {
2336 elsif ($libcurl =~ /yassl/i) {
2340 elsif ($libcurl =~ /polarssl/i) {
2344 elsif ($libcurl =~ /axtls/i) {
2348 elsif ($libcurl =~ /securetransport/i) {
2350 $ssllib="DarwinSSL";
2352 if ($libcurl =~ /ares/i) {
2357 elsif($_ =~ /^Protocols: (.*)/i) {
2358 # these are the protocols compiled in to this libcurl
2359 @protocols = split(' ', lc($1));
2361 # Generate a "proto-ipv6" version of each protocol to match the
2362 # IPv6 <server> name. This works even if IPv6 support isn't
2363 # compiled in because the <features> test will fail.
2364 push @protocols, map($_ . '-ipv6', @protocols);
2366 # 'http-proxy' is used in test cases to do CONNECT through
2367 push @protocols, 'http-proxy';
2369 # 'http-pipe' is the special server for testing pipelining
2370 push @protocols, 'http-pipe';
2372 # 'none' is used in test cases to mean no server
2373 push @protocols, 'none';
2375 elsif($_ =~ /^Features: (.*)/i) {
2377 if($feat =~ /TrackMemory/i) {
2378 # built with memory tracking support (--enable-curldebug)
2379 $has_memory_tracking = 1;
2381 if($feat =~ /debug/i) {
2382 # curl was built with --enable-debug
2385 if($feat =~ /SSL/i) {
2389 if($feat =~ /Largefile/i) {
2390 # large file support
2393 if($feat =~ /IDN/i) {
2397 if($feat =~ /IPv6/i) {
2400 if($feat =~ /libz/i) {
2403 if($feat =~ /NTLM/i) {
2406 # Use this as a proxy for any cryptographic authentication
2409 if($feat =~ /NTLM_WB/i) {
2410 # NTLM delegation to winbind daemon ntlm_auth helper enabled
2413 if($feat =~ /SSPI/i) {
2417 if($feat =~ /CharConv/i) {
2421 if($feat =~ /TLS-SRP/i) {
2425 if($feat =~ /Metalink/i) {
2429 if($feat =~ /AsynchDNS/i) {
2431 # this means threaded resolver
2433 $resolver="threaded";
2438 # Test harness currently uses a non-stunnel server in order to
2439 # run HTTP TLS-SRP tests required when curl is built with https
2440 # protocol support and TLS-SRP feature enabled. For convenience
2441 # 'httptls' may be included in the test harness protocols array
2442 # to differentiate this from classic stunnel based 'https' test
2448 if($_ =~ /^https(-ipv6|)$/) {
2453 if($add_httptls && (! grep /^httptls$/, @protocols)) {
2454 push @protocols, 'httptls';
2455 push @protocols, 'httptls-ipv6';
2460 logmsg "unable to get curl's version, further details are:\n";
2461 logmsg "issued command: \n";
2462 logmsg "$versioncmd \n";
2463 if ($versretval == -1) {
2464 logmsg "command failed with: \n";
2465 logmsg "$versnoexec \n";
2467 elsif ($versretval & 127) {
2468 logmsg sprintf("command died with signal %d, and %s coredump.\n",
2469 ($versretval & 127), ($versretval & 128)?"a":"no");
2472 logmsg sprintf("command exited with value %d \n", $versretval >> 8);
2474 logmsg "contents of $curlverout: \n";
2475 displaylogcontent("$curlverout");
2476 logmsg "contents of $curlvererr: \n";
2477 displaylogcontent("$curlvererr");
2478 die "couldn't get curl's version";
2481 if(-r "../lib/curl_config.h") {
2482 open(CONF, "<../lib/curl_config.h");
2484 if($_ =~ /^\#define HAVE_GETRLIMIT/) {
2492 # client has ipv6 support
2494 # check if the HTTP server has it!
2495 my @sws = `server/sws --version`;
2496 if($sws[0] =~ /IPv6/) {
2497 # HTTP server has ipv6 support!
2502 # check if the FTP server has it!
2503 @sws = `server/sockfilt --version`;
2504 if($sws[0] =~ /IPv6/) {
2505 # FTP server has ipv6 support!
2510 if(!$has_memory_tracking && $torture) {
2511 die "can't run torture tests since curl was built without ".
2512 "TrackMemory feature (--enable-curldebug)";
2515 $has_shared = `sh $CURLCONFIG --built-shared`;
2518 my $hostname=join(' ', runclientoutput("hostname"));
2519 my $hosttype=join(' ', runclientoutput("uname -a"));
2521 logmsg ("********* System characteristics ******** \n",
2524 "* Features: $feat\n",
2525 "* Host: $hostname",
2526 "* System: $hosttype");
2528 if($has_memory_tracking && $has_threadedres) {
2529 $has_memory_tracking = 0;
2531 "*** DISABLES memory tracking when using threaded resolver\n",
2535 logmsg sprintf("* Server SSL: %8s", $stunnel?"ON ":"OFF");
2536 logmsg sprintf(" libcurl SSL: %s\n", $ssl_version?"ON ":"OFF");
2537 logmsg sprintf("* debug build: %8s", $debug_build?"ON ":"OFF");
2538 logmsg sprintf(" track memory: %s\n", $has_memory_tracking?"ON ":"OFF");
2539 logmsg sprintf("* valgrind: %8s", $valgrind?"ON ":"OFF");
2540 logmsg sprintf(" HTTP IPv6 %s\n", $http_ipv6?"ON ":"OFF");
2541 logmsg sprintf("* FTP IPv6 %8s", $ftp_ipv6?"ON ":"OFF");
2542 logmsg sprintf(" Libtool lib: %s\n", $libtool?"ON ":"OFF");
2543 logmsg sprintf("* Shared build: %-3s", $has_shared);
2544 logmsg sprintf(" Resolver: %s\n", $resolver);
2546 logmsg sprintf("* SSL library: %13s\n", $ssllib);
2549 logmsg "* Ports:\n";
2551 logmsg sprintf("* HTTP/%d ", $HTTPPORT);
2552 logmsg sprintf("FTP/%d ", $FTPPORT);
2553 logmsg sprintf("FTP2/%d ", $FTP2PORT);
2554 logmsg sprintf("RTSP/%d ", $RTSPPORT);
2556 logmsg sprintf("FTPS/%d ", $FTPSPORT);
2557 logmsg sprintf("HTTPS/%d ", $HTTPSPORT);
2559 logmsg sprintf("\n* TFTP/%d ", $TFTPPORT);
2561 logmsg sprintf("HTTP-IPv6/%d ", $HTTP6PORT);
2562 logmsg sprintf("RTSP-IPv6/%d ", $RTSP6PORT);
2565 logmsg sprintf("FTP-IPv6/%d ", $FTP6PORT);
2568 logmsg sprintf("TFTP-IPv6/%d ", $TFTP6PORT);
2570 logmsg sprintf("\n* GOPHER/%d ", $GOPHERPORT);
2572 logmsg sprintf("GOPHER-IPv6/%d", $GOPHERPORT);
2574 logmsg sprintf("\n* SSH/%d ", $SSHPORT);
2575 logmsg sprintf("SOCKS/%d ", $SOCKSPORT);
2576 logmsg sprintf("POP3/%d ", $POP3PORT);
2577 logmsg sprintf("IMAP/%d ", $IMAPPORT);
2578 logmsg sprintf("SMTP/%d\n", $SMTPPORT);
2580 logmsg sprintf("* POP3-IPv6/%d ", $POP36PORT);
2581 logmsg sprintf("IMAP-IPv6/%d ", $IMAP6PORT);
2582 logmsg sprintf("SMTP-IPv6/%d\n", $SMTP6PORT);
2585 logmsg sprintf("* HTTPTLS/%d ", $HTTPTLSPORT);
2587 logmsg sprintf("HTTPTLS-IPv6/%d ", $HTTPTLS6PORT);
2591 logmsg sprintf("* HTTP-PIPE/%d \n", $HTTPPIPEPORT);
2593 $has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
2595 logmsg "***************************************** \n";
2598 #######################################################################
2599 # substitute the variable stuff into either a joined up file or
2600 # a command, in either case passed by reference
2607 $$thing =~ s/%FTP6PORT/$FTP6PORT/g;
2608 $$thing =~ s/%FTP2PORT/$FTP2PORT/g;
2609 $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
2610 $$thing =~ s/%FTPPORT/$FTPPORT/g;
2612 $$thing =~ s/%GOPHER6PORT/$GOPHER6PORT/g;
2613 $$thing =~ s/%GOPHERPORT/$GOPHERPORT/g;
2615 $$thing =~ s/%HTTPTLS6PORT/$HTTPTLS6PORT/g;
2616 $$thing =~ s/%HTTPTLSPORT/$HTTPTLSPORT/g;
2617 $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
2618 $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
2619 $$thing =~ s/%HTTPPORT/$HTTPPORT/g;
2620 $$thing =~ s/%HTTPPIPEPORT/$HTTPPIPEPORT/g;
2621 $$thing =~ s/%PROXYPORT/$HTTPPROXYPORT/g;
2623 $$thing =~ s/%IMAP6PORT/$IMAP6PORT/g;
2624 $$thing =~ s/%IMAPPORT/$IMAPPORT/g;
2626 $$thing =~ s/%POP36PORT/$POP36PORT/g;
2627 $$thing =~ s/%POP3PORT/$POP3PORT/g;
2629 $$thing =~ s/%RTSP6PORT/$RTSP6PORT/g;
2630 $$thing =~ s/%RTSPPORT/$RTSPPORT/g;
2632 $$thing =~ s/%SMTP6PORT/$SMTP6PORT/g;
2633 $$thing =~ s/%SMTPPORT/$SMTPPORT/g;
2635 $$thing =~ s/%SOCKSPORT/$SOCKSPORT/g;
2636 $$thing =~ s/%SSHPORT/$SSHPORT/g;
2638 $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
2639 $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
2641 # client IP addresses
2643 $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
2644 $$thing =~ s/%CLIENTIP/$CLIENTIP/g;
2646 # server IP addresses
2648 $$thing =~ s/%HOST6IP/$HOST6IP/g;
2649 $$thing =~ s/%HOSTIP/$HOSTIP/g;
2653 $$thing =~ s/%CURL/$CURL/g;
2654 $$thing =~ s/%PWD/$pwd/g;
2655 $$thing =~ s/%SRCDIR/$srcdir/g;
2656 $$thing =~ s/%USER/$USER/g;
2658 # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
2659 # used for time-out tests and that whould work on most hosts as these
2660 # adjust for the startup/check time for this particular host. We needed
2661 # to do this to make the test suite run better on very slow hosts.
2663 my $ftp2 = $ftpchecktime * 2;
2664 my $ftp3 = $ftpchecktime * 3;
2666 $$thing =~ s/%FTPTIME2/$ftp2/g;
2667 $$thing =~ s/%FTPTIME3/$ftp3/g;
2679 #######################################################################
2680 # Provide time stamps for single test skipped events
2682 sub timestampskippedevents {
2683 my $testnum = $_[0];
2685 return if((not defined($testnum)) || ($testnum < 1));
2689 if($timevrfyend{$testnum}) {
2692 elsif($timesrvrlog{$testnum}) {
2693 $timevrfyend{$testnum} = $timesrvrlog{$testnum};
2696 elsif($timetoolend{$testnum}) {
2697 $timevrfyend{$testnum} = $timetoolend{$testnum};
2698 $timesrvrlog{$testnum} = $timetoolend{$testnum};
2700 elsif($timetoolini{$testnum}) {
2701 $timevrfyend{$testnum} = $timetoolini{$testnum};
2702 $timesrvrlog{$testnum} = $timetoolini{$testnum};
2703 $timetoolend{$testnum} = $timetoolini{$testnum};
2705 elsif($timesrvrend{$testnum}) {
2706 $timevrfyend{$testnum} = $timesrvrend{$testnum};
2707 $timesrvrlog{$testnum} = $timesrvrend{$testnum};
2708 $timetoolend{$testnum} = $timesrvrend{$testnum};
2709 $timetoolini{$testnum} = $timesrvrend{$testnum};
2711 elsif($timesrvrini{$testnum}) {
2712 $timevrfyend{$testnum} = $timesrvrini{$testnum};
2713 $timesrvrlog{$testnum} = $timesrvrini{$testnum};
2714 $timetoolend{$testnum} = $timesrvrini{$testnum};
2715 $timetoolini{$testnum} = $timesrvrini{$testnum};
2716 $timesrvrend{$testnum} = $timesrvrini{$testnum};
2718 elsif($timeprepini{$testnum}) {
2719 $timevrfyend{$testnum} = $timeprepini{$testnum};
2720 $timesrvrlog{$testnum} = $timeprepini{$testnum};
2721 $timetoolend{$testnum} = $timeprepini{$testnum};
2722 $timetoolini{$testnum} = $timeprepini{$testnum};
2723 $timesrvrend{$testnum} = $timeprepini{$testnum};
2724 $timesrvrini{$testnum} = $timeprepini{$testnum};
2729 #######################################################################
2730 # Run a single specified test case
2733 my ($evbased, # 1 means switch on if possible (and "curl" is tested)
2734 # returns "not a test" if it can't be used for this test
2743 my $disablevalgrind;
2745 # copy test number to a global scope var, this allows
2746 # testnum checking when starting test harness servers.
2747 $testnumcheck = $testnum;
2749 # timestamp test preparation start
2750 $timeprepini{$testnum} = Time::HiRes::time() if($timestats);
2752 if($disttests !~ /test$testnum\W/ ) {
2753 logmsg "Warning: test$testnum not present in tests/data/Makefile.am\n";
2755 if($disabled{$testnum}) {
2756 logmsg "Warning: test$testnum is explicitly disabled\n";
2759 # load the test case file definition
2760 if(loadtest("${TESTDIR}/test${testnum}")) {
2762 # this is not a test
2763 logmsg "RUN: $testnum doesn't look like a test case\n";
2768 @what = getpart("client", "features");
2771 # We require a feature to be present
2776 if($f =~ /^([^!].*)$/) {
2777 # Store the feature for later
2785 elsif($1 eq "OpenSSL") {
2790 elsif($1 eq "GnuTLS") {
2795 elsif($1 eq "NSS") {
2800 elsif($1 eq "axTLS") {
2805 elsif($1 eq "WinSSL") {
2810 elsif($1 eq "DarwinSSL") {
2811 if($has_darwinssl) {
2815 elsif($1 eq "unittest") {
2820 elsif($1 eq "debug") {
2825 elsif($1 eq "TrackMemory") {
2826 if($has_memory_tracking) {
2830 elsif($1 eq "large_file") {
2835 elsif($1 eq "idn") {
2840 elsif($1 eq "ipv6") {
2845 elsif($1 eq "libz") {
2850 elsif($1 eq "NTLM") {
2855 elsif($1 eq "NTLM_WB") {
2860 elsif($1 eq "SSPI") {
2865 elsif($1 eq "getrlimit") {
2866 if($has_getrlimit) {
2870 elsif($1 eq "crypto") {
2875 elsif($1 eq "TLS-SRP") {
2880 elsif($1 eq "Metalink") {
2885 elsif($1 eq "socks") {
2888 # See if this "feature" is in the list of supported protocols
2889 elsif (grep /^\Q$1\E$/i, @protocols) {
2893 $why = "curl lacks $1 support";
2898 # We require a feature to not be present
2904 if($f =~ /^!(.*)$/) {
2910 elsif($1 eq "OpenSSL") {
2915 elsif($1 eq "GnuTLS") {
2920 elsif($1 eq "NSS") {
2925 elsif($1 eq "axTLS") {
2930 elsif($1 eq "WinSSL") {
2935 elsif($1 eq "DarwinSSL") {
2936 if(!$has_darwinssl) {
2940 elsif($1 eq "TrackMemory") {
2941 if(!$has_memory_tracking) {
2945 elsif($1 eq "large_file") {
2950 elsif($1 eq "idn") {
2955 elsif($1 eq "ipv6") {
2960 elsif($1 eq "libz") {
2965 elsif($1 eq "NTLM") {
2970 elsif($1 eq "NTLM_WB") {
2975 elsif($1 eq "SSPI") {
2980 elsif($1 eq "getrlimit") {
2981 if(!$has_getrlimit) {
2985 elsif($1 eq "crypto") {
2990 elsif($1 eq "TLS-SRP") {
2995 elsif($1 eq "Metalink") {
2996 if(!$has_metalink) {
3008 $why = "curl has $1 support";
3014 my @keywords = getpart("info", "keywords");
3017 for $k (@keywords) {
3019 if ($disabled_keywords{$k}) {
3020 $why = "disabled by keyword";
3021 } elsif ($enabled_keywords{$k}) {
3026 if(!$why && !$match && %enabled_keywords) {
3027 $why = "disabled by missing keyword";
3031 # test definition may instruct to (un)set environment vars
3032 # this is done this early, so that the precheck can use environment
3033 # variables and still bail out fine on errors
3035 # restore environment variables that were modified in a previous run
3036 foreach my $var (keys %oldenv) {
3037 if($oldenv{$var} eq 'notset') {
3038 delete $ENV{$var} if($ENV{$var});
3041 $ENV{$var} = $oldenv{$var};
3043 delete $oldenv{$var};
3046 # remove test server commands file before servers are started/verified
3047 unlink($FTPDCMD) if(-f $FTPDCMD);
3049 # timestamp required servers verification start
3050 $timesrvrini{$testnum} = Time::HiRes::time() if($timestats);
3053 $why = serverfortest($testnum);
3056 # timestamp required servers verification end
3057 $timesrvrend{$testnum} = Time::HiRes::time() if($timestats);
3059 my @setenv = getpart("client", "setenv");
3061 foreach my $s (@setenv) {
3064 if($s =~ /([^=]*)=(.*)/) {
3065 my ($var, $content) = ($1, $2);
3066 # remember current setting, to restore it once test runs
3067 $oldenv{$var} = ($ENV{$var})?"$ENV{$var}":'notset';
3070 delete $ENV{$var} if($ENV{$var});
3073 if($var =~ /^LD_PRELOAD/) {
3074 if(exe_ext() && (exe_ext() eq '.exe')) {
3075 # print "Skipping LD_PRELOAD due to lack of OS support\n";
3078 if($debug_build || ($has_shared ne "yes")) {
3079 # print "Skipping LD_PRELOAD due to no release shared build\n";
3083 $ENV{$var} = "$content";
3091 # Add a precheck cache. If a precheck command was already invoked
3092 # exactly like this, then use the previous result to speed up
3093 # successive test invokes!
3095 my @precheck = getpart("client", "precheck");
3097 $cmd = $precheck[0];
3101 my @p = split(/ /, $cmd);
3103 # the first word, the command, does not contain a slash so
3104 # we will scan the "improved" PATH to find the command to
3106 my $fullp = checktestcmd($p[0]);
3111 $cmd = join(" ", @p);
3114 my @o = `$cmd 2>/dev/null`;
3119 $why = "precheck command error";
3121 logmsg "prechecked $cmd\n" if($verbose);
3126 if($why && !$listonly) {
3127 # there's a problem, count it as "skipped"
3130 $teststat[$testnum]=$why; # store reason for this test case
3133 if($skipped{$why} <= 3) {
3134 # show only the first three skips for each reason
3135 logmsg sprintf("test %03d SKIPPED: $why\n", $testnum);
3139 timestampskippedevents($testnum);
3142 logmsg sprintf("test %03d...", $testnum) if(!$automakestyle);
3144 # extract the reply data
3145 my @reply = getpart("reply", "data");
3146 my @replycheck = getpart("reply", "datacheck");
3148 my %replyattr = getpartattr("reply", "data");
3149 my %replycheckattr = getpartattr("reply", "datacheck");
3152 # we use this file instead to check the final output against
3154 if($replycheckattr{'nonewline'}) {
3155 # Yes, we must cut off the final newline from the final line
3157 chomp($replycheck[$#replycheck]);
3159 if($replycheckattr{'mode'}) {
3160 $replyattr{'mode'} = $replycheckattr{'mode'};
3166 # this is the valid protocol blurb curl should generate
3167 my @protocol= fixarray ( getpart("verify", "protocol") );
3169 # this is the valid protocol blurb curl should generate to a proxy
3170 my @proxyprot = fixarray ( getpart("verify", "proxy") );
3172 # redirected stdout/stderr to these files
3173 $STDOUT="$LOGDIR/stdout$testnum";
3174 $STDERR="$LOGDIR/stderr$testnum";
3176 # if this section exists, we verify that the stdout contained this:
3177 my @validstdout = fixarray ( getpart("verify", "stdout") );
3179 # if this section exists, we verify upload
3180 my @upload = getpart("verify", "upload");
3182 # if this section exists, it might be FTP server instructions:
3183 my @ftpservercmd = getpart("reply", "servercmd");
3185 my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
3188 my @testname= getpart("client", "name");
3189 my $testname = $testname[0];
3190 $testname =~ s/\n//g;
3191 logmsg "[$testname]\n" if(!$short);
3194 timestampskippedevents($testnum);
3195 return 0; # look successful
3198 my @codepieces = getpart("client", "tool");
3202 $tool = $codepieces[0];
3206 # remove server output logfile
3212 # write the instructions to file
3213 writearray($FTPDCMD, \@ftpservercmd);
3216 # get the command line options to use
3218 ($cmd, @blaha)= getpart("client", "command");
3221 # make some nice replace operations
3222 $cmd =~ s/\n//g; # no newlines please
3223 # substitute variables in the command line
3227 # there was no command given, use something silly
3230 if($has_memory_tracking) {
3234 # create a (possibly-empty) file before starting the test
3235 my @inputfile=getpart("client", "file");
3236 my %fileattr = getpartattr("client", "file");
3237 my $filename=$fileattr{'name'};
3238 if(@inputfile || $filename) {
3240 logmsg "ERROR: section client=>file has no name attribute\n";
3241 timestampskippedevents($testnum);
3244 my $fileContent = join('', @inputfile);
3245 subVariables \$fileContent;
3246 # logmsg "DEBUG: writing file " . $filename . "\n";
3247 open(OUTFILE, ">$filename");
3248 binmode OUTFILE; # for crapage systems, use binary
3249 print OUTFILE $fileContent;
3253 my %cmdhash = getpartattr("client", "command");
3257 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-output/)) {
3258 #We may slap on --output!
3259 if (!@validstdout) {
3260 $out=" --output $CURLOUT ";
3264 my $serverlogslocktimeout = $defserverlogslocktimeout;
3265 if($cmdhash{'timeout'}) {
3266 # test is allowed to override default server logs lock timeout
3267 if($cmdhash{'timeout'} =~ /(\d+)/) {
3268 $serverlogslocktimeout = $1 if($1 >= 0);
3272 my $postcommanddelay = $defpostcommanddelay;
3273 if($cmdhash{'delay'}) {
3274 # test is allowed to specify a delay after command is executed
3275 if($cmdhash{'delay'} =~ /(\d+)/) {
3276 $postcommanddelay = $1 if($1 > 0);
3282 my $cmdtype = $cmdhash{'type'} || "default";
3283 my $fail_due_event_based = $evbased;
3284 if($cmdtype eq "perl") {
3285 # run the command line prepended with "perl"
3291 elsif($cmdtype eq "shell") {
3292 # run the command line prepended with "/bin/sh"
3294 $CMDLINE = "/bin/sh ";
3299 # run curl, add suitable command line options
3300 $cmd = "-1 ".$cmd if(exists $feature{"SSL"} && ($has_axtls));
3303 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-include/)) {
3304 $inc = " --include";
3307 $cmdargs = "$out$inc ";
3308 $cmdargs .= "--trace-ascii log/trace$testnum ";
3309 $cmdargs .= "--trace-time ";
3311 $cmdargs .= "--test-event ";
3312 $fail_due_event_based--;
3317 $cmdargs = " $cmd"; # $cmd is the command line for the test file
3318 $CURLOUT = $STDOUT; # sends received data to stdout
3320 if($tool =~ /^lib/) {
3321 $CMDLINE="$LIBDIR/$tool";
3323 elsif($tool =~ /^unit/) {
3324 $CMDLINE="$UNITDIR/$tool";
3328 logmsg "The tool set in the test case for this: '$tool' does not exist\n";
3329 timestampskippedevents($testnum);
3336 # gdb is incompatible with valgrind, so disable it when debugging
3337 # Perhaps a better approach would be to run it under valgrind anyway
3338 # with --db-attach=yes or --vgdb=yes.
3342 if($fail_due_event_based) {
3343 logmsg "This test cannot run event based\n";
3347 my @stdintest = getpart("client", "stdin");
3350 my $stdinfile="$LOGDIR/stdin-for-$testnum";
3352 my %hash = getpartattr("client", "stdin");
3353 if($hash{'nonewline'}) {
3354 # cut off the final newline from the final line of the stdin data
3355 chomp($stdintest[$#stdintest]);
3358 writearray($stdinfile, \@stdintest);
3360 $cmdargs .= " <$stdinfile";
3368 if($valgrind && !$disablevalgrind) {
3369 my @valgrindoption = getpart("verify", "valgrind");
3370 if((!@valgrindoption) || ($valgrindoption[0] !~ /disable/)) {
3372 my $valgrindcmd = "$valgrind ";
3373 $valgrindcmd .= "$valgrind_tool " if($valgrind_tool);
3374 $valgrindcmd .= "--leak-check=yes ";
3375 $valgrindcmd .= "--suppressions=$srcdir/valgrind.supp ";
3376 # $valgrindcmd .= "--gen-suppressions=all ";
3377 $valgrindcmd .= "--num-callers=16 ";
3378 $valgrindcmd .= "${valgrind_logfile}=$LOGDIR/valgrind$testnum";
3379 $CMDLINE = "$valgrindcmd $CMDLINE";
3383 $CMDLINE .= "$cmdargs >$STDOUT 2>$STDERR";
3386 logmsg "$CMDLINE\n";
3389 print CMDLOG "$CMDLINE\n";
3396 # Apr 2007: precommand isn't being used and could be removed
3397 my @precommand= getpart("client", "precommand");
3398 if($precommand[0]) {
3399 # this is pure perl to eval!
3400 my $code = join("", @precommand);
3403 logmsg "perl: $code\n";
3404 logmsg "precommand: $@";
3405 stopservers($verbose);
3406 timestampskippedevents($testnum);
3412 my $gdbinit = "$TESTDIR/gdbinit$testnum";
3413 open(GDBCMD, ">$LOGDIR/gdbcmd");
3414 print GDBCMD "set args $cmdargs\n";
3415 print GDBCMD "show args\n";
3416 print GDBCMD "source $gdbinit\n" if -e $gdbinit;
3420 # timestamp starting of test command
3421 $timetoolini{$testnum} = Time::HiRes::time() if($timestats);
3423 # run the command line we built
3425 $cmdres = torture($CMDLINE,
3426 "$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
3429 my $GDBW = ($gdbxwin) ? "-w" : "";
3430 runclient("$gdb --directory libtest $DBGCURL $GDBW -x $LOGDIR/gdbcmd");
3431 $cmdres=0; # makes it always continue after a debugged run
3434 $cmdres = runclient("$CMDLINE");
3435 my $signal_num = $cmdres & 127;
3436 $dumped_core = $cmdres & 128;
3438 if(!$anyway && ($signal_num || $dumped_core)) {
3443 $cmdres = (2000 + $signal_num) if($signal_num && !$cmdres);
3447 # timestamp finishing of test command
3448 $timetoolend{$testnum} = Time::HiRes::time() if($timestats);
3452 # there's core file present now!
3458 logmsg "core dumped\n";
3460 logmsg "running gdb for post-mortem analysis:\n";
3461 open(GDBCMD, ">$LOGDIR/gdbcmd2");
3462 print GDBCMD "bt\n";
3464 runclient("$gdb --directory libtest -x $LOGDIR/gdbcmd2 -batch $DBGCURL core ");
3465 # unlink("$LOGDIR/gdbcmd2");
3469 # If a server logs advisor read lock file exists, it is an indication
3470 # that the server has not yet finished writing out all its log files,
3471 # including server request log files used for protocol verification.
3472 # So, if the lock file exists the script waits here a certain amount
3473 # of time until the server removes it, or the given time expires.
3475 if($serverlogslocktimeout) {
3476 my $lockretry = $serverlogslocktimeout * 20;
3477 while((-f $SERVERLOGS_LOCK) && $lockretry--) {
3478 select(undef, undef, undef, 0.05);
3480 if(($lockretry < 0) &&
3481 ($serverlogslocktimeout >= $defserverlogslocktimeout)) {
3482 logmsg "Warning: server logs lock timeout ",
3483 "($serverlogslocktimeout seconds) expired\n";
3487 # Test harness ssh server does not have this synchronization mechanism,
3488 # this implies that some ssh server based tests might need a small delay
3489 # once that the client command has run to avoid false test failures.
3491 # gnutls-serv also lacks this synchronization mechanism, so gnutls-serv
3492 # based tests might need a small delay once that the client command has
3493 # run to avoid false test failures.
3495 sleep($postcommanddelay) if($postcommanddelay);
3497 # timestamp removal of server logs advisor read lock
3498 $timesrvrlog{$testnum} = Time::HiRes::time() if($timestats);
3500 # test definition might instruct to stop some servers
3501 # stop also all servers relative to the given one
3503 my @killtestservers = getpart("client", "killserver");
3504 if(@killtestservers) {
3506 # All servers relative to the given one must be stopped also
3509 foreach my $server (@killtestservers) {
3511 if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|))$/) {
3512 # given a stunnel ssl server, also kill non-ssl underlying one
3513 push @killservers, "${1}${2}";
3515 elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|))$/) {
3516 # given a non-ssl server, also kill stunnel piggybacking one
3517 push @killservers, "${1}s${2}";
3519 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
3520 # given a socks server, also kill ssh underlying one
3521 push @killservers, "ssh${2}";
3523 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
3524 # given a ssh server, also kill socks piggybacking one
3525 push @killservers, "socks${2}";
3527 push @killservers, $server;
3530 # kill sockfilter processes for pingpong relative servers
3532 foreach my $server (@killservers) {
3533 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
3535 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
3536 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
3537 killsockfilters($proto, $ipvnum, $idnum, $verbose);
3541 # kill server relative pids clearing them in %run hash
3544 foreach my $server (@killservers) {
3546 $pidlist .= "$run{$server} ";
3549 $runcert{$server} = 0 if($runcert{$server});
3551 killpid($verbose, $pidlist);
3553 # cleanup server pid files
3555 foreach my $server (@killservers) {
3556 my $pidfile = $serverpidfile{$server};
3557 my $pid = processexists($pidfile);
3559 logmsg "Warning: $server server unexpectedly alive\n";
3560 killpid($verbose, $pid);
3562 unlink($pidfile) if(-f $pidfile);
3566 # remove the test server commands file after each test
3567 unlink($FTPDCMD) if(-f $FTPDCMD);
3569 # run the postcheck command
3570 my @postcheck= getpart("client", "postcheck");
3572 $cmd = $postcheck[0];
3576 logmsg "postcheck $cmd\n" if($verbose);
3577 my $rc = runclient("$cmd");
3578 # Must run the postcheck command in torture mode in order
3579 # to clean up, but the result can't be relied upon.
3580 if($rc != 0 && !$torture) {
3581 logmsg " postcheck FAILED\n";
3582 # timestamp test result verification end
3583 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3589 # restore environment variables that were modified
3591 foreach my $var (keys %oldenv) {
3592 if($oldenv{$var} eq 'notset') {
3593 delete $ENV{$var} if($ENV{$var});
3596 $ENV{$var} = "$oldenv{$var}";
3601 # Skip all the verification on torture tests
3603 if(!$cmdres && !$keepoutfiles) {
3606 # timestamp test result verification end
3607 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3611 my @err = getpart("verify", "errorcode");
3612 my $errorcode = $err[0] || "0";
3617 # verify redirected stdout
3618 my @actual = loadarray($STDOUT);
3620 # variable-replace in the stdout we have from the test case file
3621 @validstdout = fixarray(@validstdout);
3623 # get all attributes
3624 my %hash = getpartattr("verify", "stdout");
3626 # get the mode attribute
3627 my $filemode=$hash{'mode'};
3628 if($filemode && ($filemode eq "text") && $has_textaware) {
3629 # text mode when running on windows: fix line endings
3630 map s/\r\n/\n/g, @validstdout;
3631 map s/\n/\r\n/g, @validstdout;
3634 if($hash{'nonewline'}) {
3635 # Yes, we must cut off the final newline from the final line
3636 # of the protocol data
3637 chomp($validstdout[$#validstdout]);
3640 $res = compare($testnum, $testname, "stdout", \@actual, \@validstdout);
3647 $ok .= "-"; # stdout not checked
3650 if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
3651 # verify the received data
3652 my @out = loadarray($CURLOUT);
3653 # get the mode attribute
3654 my $filemode=$replyattr{'mode'};
3655 if($filemode && ($filemode eq "text") && $has_textaware) {
3656 # text mode when running on windows: fix line endings
3657 map s/\r\n/\n/g, @reply;
3658 map s/\n/\r\n/g, @reply;
3661 $res = compare($testnum, $testname, "data", \@out, \@reply);
3668 $ok .= "-"; # data not checked
3672 # verify uploaded data
3673 my @out = loadarray("$LOGDIR/upload.$testnum");
3674 $res = compare($testnum, $testname, "upload", \@out, \@upload);
3681 $ok .= "-"; # upload not checked
3685 # Verify the sent request
3686 my @out = loadarray($SERVERIN);
3688 # what to cut off from the live protocol sent by curl
3689 my @strip = getpart("verify", "strip");
3691 my @protstrip=@protocol;
3693 # check if there's any attributes on the verify/protocol section
3694 my %hash = getpartattr("verify", "protocol");
3696 if($hash{'nonewline'}) {
3697 # Yes, we must cut off the final newline from the final line
3698 # of the protocol data
3699 chomp($protstrip[$#protstrip]);
3703 # strip off all lines that match the patterns from both arrays
3705 @out = striparray( $_, \@out);
3706 @protstrip= striparray( $_, \@protstrip);
3709 # what parts to cut off from the protocol
3710 my @strippart = getpart("verify", "strippart");
3712 for $strip (@strippart) {
3719 $res = compare($testnum, $testname, "protocol", \@out, \@protstrip);
3728 $ok .= "-"; # protocol not checked
3732 # Verify the sent proxy request
3733 my @out = loadarray($PROXYIN);
3735 # what to cut off from the live protocol sent by curl, we use the
3736 # same rules as for <protocol>
3737 my @strip = getpart("verify", "strip");
3739 my @protstrip=@proxyprot;
3741 # check if there's any attributes on the verify/protocol section
3742 my %hash = getpartattr("verify", "proxy");
3744 if($hash{'nonewline'}) {
3745 # Yes, we must cut off the final newline from the final line
3746 # of the protocol data
3747 chomp($protstrip[$#protstrip]);
3751 # strip off all lines that match the patterns from both arrays
3753 @out = striparray( $_, \@out);
3754 @protstrip= striparray( $_, \@protstrip);
3757 # what parts to cut off from the protocol
3758 my @strippart = getpart("verify", "strippart");
3760 for $strip (@strippart) {
3767 $res = compare($testnum, $testname, "proxy", \@out, \@protstrip);
3776 $ok .= "-"; # protocol not checked
3780 for my $partsuffix (('', '1', '2', '3', '4')) {
3781 my @outfile=getpart("verify", "file".$partsuffix);
3782 if(@outfile || partexists("verify", "file".$partsuffix) ) {
3783 # we're supposed to verify a dynamically generated file!
3784 my %hash = getpartattr("verify", "file".$partsuffix);
3786 my $filename=$hash{'name'};
3788 logmsg "ERROR: section verify=>file$partsuffix ".
3789 "has no name attribute\n";
3790 stopservers($verbose);
3791 # timestamp test result verification end
3792 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3795 my @generated=loadarray($filename);
3797 # what parts to cut off from the file
3798 my @stripfile = getpart("verify", "stripfile".$partsuffix);
3800 my $filemode=$hash{'mode'};
3801 if($filemode && ($filemode eq "text") && $has_textaware) {
3802 # text mode when running on windows: fix line endings
3803 map s/\r\n/\n/g, @outfile;
3804 map s/\n/\r\n/g, @outfile;
3808 for $strip (@stripfile) {
3817 # this is to get rid of array entries that vanished (zero
3818 # length) because of replacements
3819 @generated = @newgen;
3822 @outfile = fixarray(@outfile);
3824 $res = compare($testnum, $testname, "output ($filename)",
3825 \@generated, \@outfile);
3830 $outputok = 1; # output checked
3833 $ok .= ($outputok) ? "o" : "-"; # output checked or not
3835 # accept multiple comma-separated error codes
3836 my @splerr = split(/ *, */, $errorcode);
3838 foreach my $e (@splerr) {
3851 logmsg sprintf("\n%s returned $cmdres, when expecting %s\n",
3852 (!$tool)?"curl":$tool, $errorcode);
3854 logmsg " exit FAILED\n";
3855 # timestamp test result verification end
3856 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3860 if($has_memory_tracking) {
3862 logmsg "\n** ALERT! memory tracking with no output file?\n"
3863 if(!$cmdtype eq "perl");
3866 my @memdata=`$memanalyze $memdump`;
3870 # well it could be other memory problems as well, but
3871 # we call it leak for short here
3876 logmsg "\n** MEMORY FAILURE\n";
3878 # timestamp test result verification end
3879 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3888 $ok .= "-"; # memory not checked
3893 unless(opendir(DIR, "$LOGDIR")) {
3894 logmsg "ERROR: unable to read $LOGDIR\n";
3895 # timestamp test result verification end
3896 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3899 my @files = readdir(DIR);
3902 foreach my $file (@files) {
3903 if($file =~ /^valgrind$testnum(\..*|)$/) {
3909 logmsg "ERROR: valgrind log file missing for test $testnum\n";
3910 # timestamp test result verification end
3911 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3914 my @e = valgrindparse($srcdir, $feature{'SSL'}, "$LOGDIR/$vgfile");
3916 if($automakestyle) {
3917 logmsg "FAIL: $testnum - $testname - valgrind\n";
3920 logmsg " valgrind ERROR ";
3923 # timestamp test result verification end
3924 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3930 if(!$short && !$disablevalgrind) {
3931 logmsg " valgrind SKIPPED\n";
3933 $ok .= "-"; # skipped
3937 $ok .= "-"; # valgrind not checked
3939 # add 'E' for event-based
3940 $ok .= $evbased ? "E" : "-";
3942 logmsg "$ok " if(!$short);
3944 my $sofar= time()-$start;
3945 my $esttotal = $sofar/$count * $total;
3946 my $estleft = $esttotal - $sofar;
3947 my $left=sprintf("remaining: %02d:%02d",
3951 if(!$automakestyle) {
3952 logmsg sprintf("OK (%-3d out of %-3d, %s)\n", $count, $total, $left);
3955 logmsg "PASS: $testnum - $testname\n";
3958 # the test succeeded, remove all log files
3959 if(!$keepoutfiles) {
3963 # timestamp test result verification end
3964 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3969 #######################################################################
3970 # Stop all running test servers
3973 my $verbose = $_[0];
3975 # kill sockfilter processes for all pingpong servers
3977 killallsockfilters($verbose);
3979 # kill all server pids from %run hash clearing them
3982 foreach my $server (keys %run) {
3986 my $pids = $run{$server};
3987 foreach my $pid (split(' ', $pids)) {
3989 logmsg sprintf("* kill pid for %s => %d\n",
3995 $pidlist .= "$run{$server} ";
3998 $runcert{$server} = 0 if($runcert{$server});
4000 killpid($verbose, $pidlist);
4002 # cleanup all server pid files
4004 foreach my $server (keys %serverpidfile) {
4005 my $pidfile = $serverpidfile{$server};
4006 my $pid = processexists($pidfile);
4008 logmsg "Warning: $server server unexpectedly alive\n";
4009 killpid($verbose, $pid);
4011 unlink($pidfile) if(-f $pidfile);
4015 #######################################################################
4016 # startservers() starts all the named servers
4018 # Returns: string with error reason or blank for success
4024 my (@whatlist) = split(/\s+/,$_);
4025 my $what = lc($whatlist[0]);
4026 $what =~ s/[^a-z0-9-]//g;
4029 if($what =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|))$/) {
4030 $certfile = ($whatlist[1]) ? $whatlist[1] : 'stunnel.pem';
4033 if(($what eq "pop3") ||
4035 ($what eq "imap") ||
4036 ($what eq "smtp")) {
4037 if($torture && $run{$what} &&
4038 !responsive_pingpong_server($what, "", $verbose)) {
4042 ($pid, $pid2) = runpingpongserver($what, "", $verbose);
4044 return "failed starting ". uc($what) ." server";
4046 printf ("* pid $what => %d %d\n", $pid, $pid2) if($verbose);
4047 $run{$what}="$pid $pid2";
4050 elsif($what eq "ftp2") {
4051 if($torture && $run{'ftp2'} &&
4052 !responsive_pingpong_server("ftp", "2", $verbose)) {
4056 ($pid, $pid2) = runpingpongserver("ftp", "2", $verbose);
4058 return "failed starting FTP2 server";
4060 printf ("* pid ftp2 => %d %d\n", $pid, $pid2) if($verbose);
4061 $run{'ftp2'}="$pid $pid2";
4064 elsif($what eq "ftp-ipv6") {
4065 if($torture && $run{'ftp-ipv6'} &&
4066 !responsive_pingpong_server("ftp", "", $verbose, "ipv6")) {
4067 stopserver('ftp-ipv6');
4069 if(!$run{'ftp-ipv6'}) {
4070 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose, "ipv6");
4072 return "failed starting FTP-IPv6 server";
4074 logmsg sprintf("* pid ftp-ipv6 => %d %d\n", $pid,
4075 $pid2) if($verbose);
4076 $run{'ftp-ipv6'}="$pid $pid2";
4079 elsif($what eq "gopher") {
4080 if($torture && $run{'gopher'} &&
4081 !responsive_http_server("gopher", $verbose, 0, $GOPHERPORT)) {
4082 stopserver('gopher');
4084 if(!$run{'gopher'}) {
4085 ($pid, $pid2) = runhttpserver("gopher", $verbose, 0,
4088 return "failed starting GOPHER server";
4090 logmsg sprintf ("* pid gopher => %d %d\n", $pid, $pid2)
4092 $run{'gopher'}="$pid $pid2";
4095 elsif($what eq "gopher-ipv6") {
4096 if($torture && $run{'gopher-ipv6'} &&
4097 !responsive_http_server("gopher", $verbose, "ipv6",
4099 stopserver('gopher-ipv6');
4101 if(!$run{'gopher-ipv6'}) {
4102 ($pid, $pid2) = runhttpserver("gopher", $verbose, "ipv6",
4105 return "failed starting GOPHER-IPv6 server";
4107 logmsg sprintf("* pid gopher-ipv6 => %d %d\n", $pid,
4108 $pid2) if($verbose);
4109 $run{'gopher-ipv6'}="$pid $pid2";
4112 elsif($what eq "http") {
4113 if($torture && $run{'http'} &&
4114 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4118 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4121 return "failed starting HTTP server";
4123 logmsg sprintf ("* pid http => %d %d\n", $pid, $pid2)
4125 $run{'http'}="$pid $pid2";
4128 elsif($what eq "http-proxy") {
4129 if($torture && $run{'http-proxy'} &&
4130 !responsive_http_server("http", $verbose, "proxy",
4132 stopserver('http-proxy');
4134 if(!$run{'http-proxy'}) {
4135 ($pid, $pid2) = runhttpserver("http", $verbose, "proxy",
4138 return "failed starting HTTP-proxy server";
4140 logmsg sprintf ("* pid http-proxy => %d %d\n", $pid, $pid2)
4142 $run{'http-proxy'}="$pid $pid2";
4145 elsif($what eq "http-ipv6") {
4146 if($torture && $run{'http-ipv6'} &&
4147 !responsive_http_server("http", $verbose, "IPv6", $HTTP6PORT)) {
4148 stopserver('http-ipv6');
4150 if(!$run{'http-ipv6'}) {
4151 ($pid, $pid2) = runhttpserver("http", $verbose, "ipv6",
4154 return "failed starting HTTP-IPv6 server";
4156 logmsg sprintf("* pid http-ipv6 => %d %d\n", $pid, $pid2)
4158 $run{'http-ipv6'}="$pid $pid2";
4161 elsif($what eq "http-pipe") {
4162 if($torture && $run{'http-pipe'} &&
4163 !responsive_http_server("http", $verbose, "pipe",
4165 stopserver('http-pipe');
4167 if(!$run{'http-pipe'}) {
4168 ($pid, $pid2) = runhttpserver("http", $verbose, "pipe",
4171 return "failed starting HTTP-pipe server";
4173 logmsg sprintf ("* pid http-pipe => %d %d\n", $pid, $pid2)
4175 $run{'http-pipe'}="$pid $pid2";
4178 elsif($what eq "rtsp") {
4179 if($torture && $run{'rtsp'} &&
4180 !responsive_rtsp_server($verbose)) {
4184 ($pid, $pid2) = runrtspserver($verbose);
4186 return "failed starting RTSP server";
4188 printf ("* pid rtsp => %d %d\n", $pid, $pid2) if($verbose);
4189 $run{'rtsp'}="$pid $pid2";
4192 elsif($what eq "rtsp-ipv6") {
4193 if($torture && $run{'rtsp-ipv6'} &&
4194 !responsive_rtsp_server($verbose, "IPv6")) {
4195 stopserver('rtsp-ipv6');
4197 if(!$run{'rtsp-ipv6'}) {
4198 ($pid, $pid2) = runrtspserver($verbose, "IPv6");
4200 return "failed starting RTSP-IPv6 server";
4202 logmsg sprintf("* pid rtsp-ipv6 => %d %d\n", $pid, $pid2)
4204 $run{'rtsp-ipv6'}="$pid $pid2";
4207 elsif($what eq "ftps") {
4209 # we can't run ftps tests without stunnel
4210 return "no stunnel";
4213 # we can't run ftps tests if libcurl is SSL-less
4214 return "curl lacks SSL support";
4216 if($runcert{'ftps'} && ($runcert{'ftps'} ne $certfile)) {
4217 # stop server when running and using a different cert
4220 if($torture && $run{'ftp'} &&
4221 !responsive_pingpong_server("ftp", "", $verbose)) {
4225 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose);
4227 return "failed starting FTP server";
4229 printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
4230 $run{'ftp'}="$pid $pid2";
4233 ($pid, $pid2) = runftpsserver($verbose, "", $certfile);
4235 return "failed starting FTPS server (stunnel)";
4237 logmsg sprintf("* pid ftps => %d %d\n", $pid, $pid2)
4239 $run{'ftps'}="$pid $pid2";
4242 elsif($what eq "file") {
4243 # we support it but have no server!
4245 elsif($what eq "https") {
4247 # we can't run https tests without stunnel
4248 return "no stunnel";
4251 # we can't run https tests if libcurl is SSL-less
4252 return "curl lacks SSL support";
4254 if($runcert{'https'} && ($runcert{'https'} ne $certfile)) {
4255 # stop server when running and using a different cert
4256 stopserver('https');
4258 if($torture && $run{'http'} &&
4259 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4263 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4266 return "failed starting HTTP server";
4268 printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
4269 $run{'http'}="$pid $pid2";
4271 if(!$run{'https'}) {
4272 ($pid, $pid2) = runhttpsserver($verbose, "", $certfile);
4274 return "failed starting HTTPS server (stunnel)";
4276 logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
4278 $run{'https'}="$pid $pid2";
4281 elsif($what eq "httptls") {
4283 # for now, we can't run http TLS-EXT tests without gnutls-serv
4284 return "no gnutls-serv";
4286 if($torture && $run{'httptls'} &&
4287 !responsive_httptls_server($verbose, "IPv4")) {
4288 stopserver('httptls');
4290 if(!$run{'httptls'}) {
4291 ($pid, $pid2) = runhttptlsserver($verbose, "IPv4");
4293 return "failed starting HTTPTLS server (gnutls-serv)";
4295 logmsg sprintf("* pid httptls => %d %d\n", $pid, $pid2)
4297 $run{'httptls'}="$pid $pid2";
4300 elsif($what eq "httptls-ipv6") {
4302 # for now, we can't run http TLS-EXT tests without gnutls-serv
4303 return "no gnutls-serv";
4305 if($torture && $run{'httptls-ipv6'} &&
4306 !responsive_httptls_server($verbose, "IPv6")) {
4307 stopserver('httptls-ipv6');
4309 if(!$run{'httptls-ipv6'}) {
4310 ($pid, $pid2) = runhttptlsserver($verbose, "IPv6");
4312 return "failed starting HTTPTLS-IPv6 server (gnutls-serv)";
4314 logmsg sprintf("* pid httptls-ipv6 => %d %d\n", $pid, $pid2)
4316 $run{'httptls-ipv6'}="$pid $pid2";
4319 elsif($what eq "tftp") {
4320 if($torture && $run{'tftp'} &&
4321 !responsive_tftp_server("", $verbose)) {
4325 ($pid, $pid2) = runtftpserver("", $verbose);
4327 return "failed starting TFTP server";
4329 printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
4330 $run{'tftp'}="$pid $pid2";
4333 elsif($what eq "tftp-ipv6") {
4334 if($torture && $run{'tftp-ipv6'} &&
4335 !responsive_tftp_server("", $verbose, "IPv6")) {
4336 stopserver('tftp-ipv6');
4338 if(!$run{'tftp-ipv6'}) {
4339 ($pid, $pid2) = runtftpserver("", $verbose, "IPv6");
4341 return "failed starting TFTP-IPv6 server";
4343 printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
4344 $run{'tftp-ipv6'}="$pid $pid2";
4347 elsif($what eq "sftp" || $what eq "scp" || $what eq "socks4" || $what eq "socks5" ) {
4349 ($pid, $pid2) = runsshserver("", $verbose);
4351 return "failed starting SSH server";
4353 printf ("* pid ssh => %d %d\n", $pid, $pid2) if($verbose);
4354 $run{'ssh'}="$pid $pid2";
4356 if($what eq "socks4" || $what eq "socks5") {
4357 if(!$run{'socks'}) {
4358 ($pid, $pid2) = runsocksserver("", $verbose);
4360 return "failed starting socks server";
4362 printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
4363 $run{'socks'}="$pid $pid2";
4366 if($what eq "socks5") {
4368 # Not an OpenSSH or SunSSH ssh daemon
4369 logmsg "Not OpenSSH or SunSSH; socks5 tests need at least OpenSSH 3.7\n";
4370 return "failed starting socks5 server";
4372 elsif(($sshdid =~ /OpenSSH/) && ($sshdvernum < 370)) {
4373 # Need OpenSSH 3.7 for socks5 - http://www.openssh.com/txt/release-3.7
4374 logmsg "$sshdverstr insufficient; socks5 tests need at least OpenSSH 3.7\n";
4375 return "failed starting socks5 server";
4377 elsif(($sshdid =~ /SunSSH/) && ($sshdvernum < 100)) {
4378 # Need SunSSH 1.0 for socks5
4379 logmsg "$sshdverstr insufficient; socks5 tests need at least SunSSH 1.0\n";
4380 return "failed starting socks5 server";
4384 elsif($what eq "none") {
4385 logmsg "* starts no server\n" if ($verbose);
4388 warn "we don't support a server for $what";
4389 return "no server for $what";
4395 ##############################################################################
4396 # This function makes sure the right set of server is running for the
4397 # specified test case. This is a useful design when we run single tests as not
4398 # all servers need to run then!
4400 # Returns: a string, blank if everything is fine or a reason why it failed
4405 my @what = getpart("client", "server");
4408 warn "Test case $testnum has no server(s) specified";
4409 return "no server specified";
4412 for(my $i = scalar(@what) - 1; $i >= 0; $i--) {
4413 my $srvrline = $what[$i];
4414 chomp $srvrline if($srvrline);
4415 if($srvrline =~ /^(\S+)((\s*)(.*))/) {
4416 my $server = "${1}";
4417 my $lnrest = "${2}";
4419 if($server =~ /^(httptls)(\+)(ext|srp)(\d*)(-ipv6|)$/) {
4420 $server = "${1}${4}${5}";
4421 $tlsext = uc("TLS-${3}");
4423 if(! grep /^\Q$server\E$/, @protocols) {
4424 if(substr($server,0,5) ne "socks") {
4426 return "curl lacks $tlsext support";
4429 return "curl lacks $server server support";
4433 $what[$i] = "$server$lnrest" if($tlsext);
4437 return &startservers(@what);
4440 #######################################################################
4441 # runtimestats displays test-suite run time statistics
4444 my $lasttest = $_[0];
4446 return if(not $timestats);
4448 logmsg "\nTest suite total running time breakdown per task...\n\n";
4456 my $timesrvrtot = 0.0;
4457 my $timepreptot = 0.0;
4458 my $timetooltot = 0.0;
4459 my $timelocktot = 0.0;
4460 my $timevrfytot = 0.0;
4461 my $timetesttot = 0.0;
4464 for my $testnum (1 .. $lasttest) {
4465 if($timesrvrini{$testnum}) {
4466 $timesrvrtot += $timesrvrend{$testnum} - $timesrvrini{$testnum};
4468 (($timetoolini{$testnum} - $timeprepini{$testnum}) -
4469 ($timesrvrend{$testnum} - $timesrvrini{$testnum}));
4470 $timetooltot += $timetoolend{$testnum} - $timetoolini{$testnum};
4471 $timelocktot += $timesrvrlog{$testnum} - $timetoolend{$testnum};
4472 $timevrfytot += $timevrfyend{$testnum} - $timesrvrlog{$testnum};
4473 $timetesttot += $timevrfyend{$testnum} - $timeprepini{$testnum};
4474 push @timesrvr, sprintf("%06.3f %04d",
4475 $timesrvrend{$testnum} - $timesrvrini{$testnum}, $testnum);
4476 push @timeprep, sprintf("%06.3f %04d",
4477 ($timetoolini{$testnum} - $timeprepini{$testnum}) -
4478 ($timesrvrend{$testnum} - $timesrvrini{$testnum}), $testnum);
4479 push @timetool, sprintf("%06.3f %04d",
4480 $timetoolend{$testnum} - $timetoolini{$testnum}, $testnum);
4481 push @timelock, sprintf("%06.3f %04d",
4482 $timesrvrlog{$testnum} - $timetoolend{$testnum}, $testnum);
4483 push @timevrfy, sprintf("%06.3f %04d",
4484 $timevrfyend{$testnum} - $timesrvrlog{$testnum}, $testnum);
4485 push @timetest, sprintf("%06.3f %04d",
4486 $timevrfyend{$testnum} - $timeprepini{$testnum}, $testnum);
4491 no warnings 'numeric';
4492 @timesrvr = sort { $b <=> $a } @timesrvr;
4493 @timeprep = sort { $b <=> $a } @timeprep;
4494 @timetool = sort { $b <=> $a } @timetool;
4495 @timelock = sort { $b <=> $a } @timelock;
4496 @timevrfy = sort { $b <=> $a } @timevrfy;
4497 @timetest = sort { $b <=> $a } @timetest;
4500 logmsg "Spent ". sprintf("%08.3f ", $timesrvrtot) .
4501 "seconds starting and verifying test harness servers.\n";
4502 logmsg "Spent ". sprintf("%08.3f ", $timepreptot) .
4503 "seconds reading definitions and doing test preparations.\n";
4504 logmsg "Spent ". sprintf("%08.3f ", $timetooltot) .
4505 "seconds actually running test tools.\n";
4506 logmsg "Spent ". sprintf("%08.3f ", $timelocktot) .
4507 "seconds awaiting server logs lock removal.\n";
4508 logmsg "Spent ". sprintf("%08.3f ", $timevrfytot) .
4509 "seconds verifying test results.\n";
4510 logmsg "Spent ". sprintf("%08.3f ", $timetesttot) .
4511 "seconds doing all of the above.\n";
4514 logmsg "\nTest server starting and verification time per test ".
4515 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4516 logmsg "-time- test\n";
4517 logmsg "------ ----\n";
4518 foreach my $txt (@timesrvr) {
4519 last if((not $fullstats) && (not $counter--));
4524 logmsg "\nTest definition reading and preparation time per test ".
4525 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4526 logmsg "-time- test\n";
4527 logmsg "------ ----\n";
4528 foreach my $txt (@timeprep) {
4529 last if((not $fullstats) && (not $counter--));
4534 logmsg "\nTest tool execution time per test ".
4535 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4536 logmsg "-time- test\n";
4537 logmsg "------ ----\n";
4538 foreach my $txt (@timetool) {
4539 last if((not $fullstats) && (not $counter--));
4544 logmsg "\nTest server logs lock removal time per test ".
4545 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4546 logmsg "-time- test\n";
4547 logmsg "------ ----\n";
4548 foreach my $txt (@timelock) {
4549 last if((not $fullstats) && (not $counter--));
4554 logmsg "\nTest results verification time per test ".
4555 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4556 logmsg "-time- test\n";
4557 logmsg "------ ----\n";
4558 foreach my $txt (@timevrfy) {
4559 last if((not $fullstats) && (not $counter--));
4564 logmsg "\nTotal time per test ".
4565 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4566 logmsg "-time- test\n";
4567 logmsg "------ ----\n";
4568 foreach my $txt (@timetest) {
4569 last if((not $fullstats) && (not $counter--));
4576 #######################################################################
4577 # Check options to this test program
4584 if ($ARGV[0] eq "-v") {
4588 elsif($ARGV[0] =~ /^-b(.*)/) {
4590 if($portno =~ s/(\d+)$//) {
4594 elsif ($ARGV[0] eq "-c") {
4595 # use this path to curl instead of default
4596 $DBGCURL=$CURL=$ARGV[1];
4599 elsif ($ARGV[0] eq "-vc") {
4600 # use this path to a curl used to verify servers
4602 # Particularly useful when you introduce a crashing bug somewhere in
4603 # the development version as then it won't be able to run any tests
4604 # since it can't verify the servers!
4609 elsif ($ARGV[0] eq "-d") {
4610 # have the servers display protocol output
4613 elsif ($ARGV[0] eq "-g") {
4614 # run this test with gdb
4617 elsif ($ARGV[0] eq "-gw") {
4618 # run this test with windowed gdb
4622 elsif($ARGV[0] eq "-s") {
4626 elsif($ARGV[0] eq "-am") {
4627 # automake-style output
4631 elsif($ARGV[0] eq "-n") {
4635 elsif($ARGV[0] =~ /^-t(.*)/) {
4640 if($xtra =~ s/(\d+)$//) {
4643 # we undef valgrind to make this fly in comparison
4646 elsif($ARGV[0] eq "-a") {
4647 # continue anyway, even if a test fail
4650 elsif($ARGV[0] eq "-e") {
4651 # run the tests cases event based if possible
4654 elsif($ARGV[0] eq "-p") {
4657 elsif($ARGV[0] eq "-l") {
4658 # lists the test case names only
4661 elsif($ARGV[0] eq "-k") {
4662 # keep stdout and stderr files after tests
4665 elsif($ARGV[0] eq "-r") {
4666 # run time statistics needs Time::HiRes
4667 if($Time::HiRes::VERSION) {
4668 keys(%timeprepini) = 1000;
4669 keys(%timesrvrini) = 1000;
4670 keys(%timesrvrend) = 1000;
4671 keys(%timetoolini) = 1000;
4672 keys(%timetoolend) = 1000;
4673 keys(%timesrvrlog) = 1000;
4674 keys(%timevrfyend) = 1000;
4679 elsif($ARGV[0] eq "-rf") {
4680 # run time statistics needs Time::HiRes
4681 if($Time::HiRes::VERSION) {
4682 keys(%timeprepini) = 1000;
4683 keys(%timesrvrini) = 1000;
4684 keys(%timesrvrend) = 1000;
4685 keys(%timetoolini) = 1000;
4686 keys(%timetoolend) = 1000;
4687 keys(%timesrvrlog) = 1000;
4688 keys(%timevrfyend) = 1000;
4693 elsif(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) {
4696 Usage: runtests.pl [options] [test selection(s)]
4697 -a continue even if a test fails
4698 -bN use base port number N for test servers (default $base)
4699 -c path use this curl executable
4700 -d display server debug info
4701 -g run the test case with gdb
4702 -gw run the test case with gdb as a windowed application
4704 -k keep stdout and stderr files present after tests
4705 -l list all test case names/descriptions
4707 -p print log file contents when a test fails
4708 -r run time statistics
4709 -rf full run time statistics
4711 -am automake style output PASS/FAIL: [number] [name]
4712 -t[N] torture (simulate memory alloc failures); N means fail Nth alloc
4714 -vc path use this curl only to verify the existing servers
4715 [num] like "5 6 9" or " 5 to 22 " to run those tests only
4716 [!num] like "!5 !6 !9" to disable those tests
4717 [keyword] like "IPv6" to select only tests containing the key word
4718 [!keyword] like "!cookies" to disable any tests containing the key word
4723 elsif($ARGV[0] =~ /^(\d+)/) {
4726 for($fromnum .. $number) {
4735 elsif($ARGV[0] =~ /^to$/i) {
4736 $fromnum = $number+1;
4738 elsif($ARGV[0] =~ /^!(\d+)/) {
4742 elsif($ARGV[0] =~ /^!(.+)/) {
4743 $disabled_keywords{$1}=$1;
4745 elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
4746 $enabled_keywords{$1}=$1;
4749 print "Unknown option: $ARGV[0]\n";
4755 if(@testthis && ($testthis[0] ne "")) {
4756 $TESTCASES=join(" ", @testthis);
4760 # we have found valgrind on the host, use it
4762 # verify that we can invoke it fine
4763 my $code = runclient("valgrind >/dev/null 2>&1");
4765 if(($code>>8) != 1) {
4766 #logmsg "Valgrind failure, disable it\n";
4770 # since valgrind 2.1.x, '--tool' option is mandatory
4771 # use it, if it is supported by the version installed on the system
4772 runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
4774 $valgrind_tool="--tool=memcheck";
4779 # A shell script. This is typically when built with libtool,
4780 $valgrind="../libtool --mode=execute $valgrind";
4784 # valgrind 3 renamed the --logfile option to --log-file!!!
4785 my $ver=join(' ', runclientoutput("valgrind --version"));
4786 # cut off all but digits and dots
4787 $ver =~ s/[^0-9.]//g;
4789 if($ver =~ /^(\d+)/) {
4792 $valgrind_logfile="--log-file";
4799 # open the executable curl and read the first 4 bytes of it
4800 open(CHECK, "<$CURL");
4802 sysread CHECK, $c, 4;
4805 # A shell script. This is typically when built with libtool,
4807 $gdb = "libtool --mode=execute gdb";
4811 $HTTPPORT = $base++; # HTTP server port
4812 $HTTPSPORT = $base++; # HTTPS (stunnel) server port
4813 $FTPPORT = $base++; # FTP server port
4814 $FTPSPORT = $base++; # FTPS (stunnel) server port
4815 $HTTP6PORT = $base++; # HTTP IPv6 server port
4816 $FTP2PORT = $base++; # FTP server 2 port
4817 $FTP6PORT = $base++; # FTP IPv6 port
4818 $TFTPPORT = $base++; # TFTP (UDP) port
4819 $TFTP6PORT = $base++; # TFTP IPv6 (UDP) port
4820 $SSHPORT = $base++; # SSH (SCP/SFTP) port
4821 $SOCKSPORT = $base++; # SOCKS port
4822 $POP3PORT = $base++; # POP3 server port
4823 $POP36PORT = $base++; # POP3 IPv6 server port
4824 $IMAPPORT = $base++; # IMAP server port
4825 $IMAP6PORT = $base++; # IMAP IPv6 server port
4826 $SMTPPORT = $base++; # SMTP server port
4827 $SMTP6PORT = $base++; # SMTP IPv6 server port
4828 $RTSPPORT = $base++; # RTSP server port
4829 $RTSP6PORT = $base++; # RTSP IPv6 server port
4830 $GOPHERPORT = $base++; # Gopher IPv4 server port
4831 $GOPHER6PORT = $base++; # Gopher IPv6 server port
4832 $HTTPTLSPORT = $base++; # HTTP TLS (non-stunnel) server port
4833 $HTTPTLS6PORT = $base++; # HTTP TLS (non-stunnel) IPv6 server port
4834 $HTTPPROXYPORT = $base++; # HTTP proxy port, when using CONNECT
4835 $HTTPPIPEPORT = $base++; # HTTP pipelining port
4837 #######################################################################
4838 # clear and create logging directory:
4842 mkdir($LOGDIR, 0777);
4844 #######################################################################
4845 # initialize some variables
4849 init_serverpidfile_hash();
4851 #######################################################################
4852 # Output curl version and host info being tested
4859 #######################################################################
4860 # Fetch all disabled tests
4863 open(D, "<$TESTDIR/DISABLED");
4870 $disabled{$1}=$1; # disable this test number
4875 #######################################################################
4876 # If 'all' tests are requested, find out all test numbers
4879 if ( $TESTCASES eq "all") {
4880 # Get all commands and find out their test numbers
4881 opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
4882 my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
4885 $TESTCASES=""; # start with no test cases
4887 # cut off everything but the digits
4889 $_ =~ s/[a-z\/\.]*//g;
4891 # sort the numbers from low to high
4892 foreach my $n (sort { $a <=> $b } @cmds) {
4894 # skip disabled test cases
4895 my $why = "configured as DISABLED";
4898 $teststat[$n]=$why; # store reason for this test case
4901 $TESTCASES .= " $n";
4907 if (-e "$TESTDIR/test$_") {
4910 } split(" ", $TESTCASES);
4911 if($verified eq "") {
4912 print "No existing test cases were specified\n";
4915 $TESTCASES = $verified;
4918 #######################################################################
4919 # Start the command line log
4921 open(CMDLOG, ">$CURLLOG") ||
4922 logmsg "can't log command lines to $CURLLOG\n";
4924 #######################################################################
4926 # Display the contents of the given file. Line endings are canonicalized
4927 # and excessively long files are elided
4928 sub displaylogcontent {
4930 if(open(SINGLE, "<$file")) {
4934 while(my $string = <SINGLE>) {
4935 $string =~ s/\r\n/\n/g;
4936 $string =~ s/[\r\f\032]/\n/g;
4937 $string .= "\n" unless ($string =~ /\n$/);
4939 for my $line (split("\n", $string)) {
4940 $line =~ s/\s*\!$//;
4942 push @tail, " $line\n";
4947 $truncate = $linecount > 1000;
4953 my $tailtotal = scalar @tail;
4954 if($tailtotal > $tailshow) {
4955 $tailskip = $tailtotal - $tailshow;
4956 logmsg "=== File too long: $tailskip lines omitted here\n";
4958 for($tailskip .. $tailtotal-1) {
4968 opendir(DIR, "$LOGDIR") ||
4969 die "can't open dir: $!";
4970 my @logs = readdir(DIR);
4973 logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
4974 foreach my $log (sort @logs) {
4975 if($log =~ /\.(\.|)$/) {
4976 next; # skip "." and ".."
4978 if($log =~ /^\.nfs/) {
4981 if(($log eq "memdump") || ($log eq "core")) {
4982 next; # skip "memdump" and "core"
4984 if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
4985 next; # skip directory and empty files
4987 if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
4988 next; # skip stdoutNnn of other tests
4990 if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
4991 next; # skip stderrNnn of other tests
4993 if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
4994 next; # skip uploadNnn of other tests
4996 if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
4997 next; # skip curlNnn.out of other tests
4999 if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
5000 next; # skip testNnn.txt of other tests
5002 if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
5003 next; # skip fileNnn.txt of other tests
5005 if(($log =~ /^netrc\d+/) && ($log !~ /^netrc$testnum/)) {
5006 next; # skip netrcNnn of other tests
5008 if(($log =~ /^trace\d+/) && ($log !~ /^trace$testnum/)) {
5009 next; # skip traceNnn of other tests
5011 if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(\..*|)$/)) {
5012 next; # skip valgrindNnn of other tests
5014 logmsg "=== Start of file $log\n";
5015 displaylogcontent("$LOGDIR/$log");
5016 logmsg "=== End of file $log\n";
5020 #######################################################################
5021 # The main test-loop
5029 my @at = split(" ", $TESTCASES);
5034 foreach $testnum (@at) {
5036 $lasttest = $testnum if($testnum > $lasttest);
5039 my $error = singletest($run_event_based, $testnum, $count, scalar(@at));
5041 # not a test we can run
5045 $total++; # number of tests we've run
5048 $failed.= "$testnum ";
5050 # display all files in log/ in a nice way
5051 displaylogs($testnum);
5054 # a test failed, abort
5055 logmsg "\n - abort tests\n";
5060 $ok++; # successful test counter
5063 # loop for next test
5066 my $sofar = time() - $start;
5068 #######################################################################
5073 # Tests done, stop the servers
5074 stopservers($verbose);
5076 my $all = $total + $skipped;
5078 runtimestats($lasttest);
5081 logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
5085 logmsg "TESTFAIL: These test cases failed: $failed\n";
5089 logmsg "TESTFAIL: No tests were performed\n";
5093 logmsg "TESTDONE: $all tests were considered during ".
5094 sprintf("%.0f", $sofar) ." seconds.\n";
5097 if($skipped && !$short) {
5099 logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
5101 for(keys %skipped) {
5103 printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
5105 # now show all test case numbers that had this reason for being
5109 for(0 .. scalar @teststat) {
5111 if($teststat[$_] && ($teststat[$_] eq $r)) {
5120 logmsg " and ".($c-$max)." more";
5126 if($total && ($ok != $total)) {