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
144 my $HTTPUNIXPATH; # HTTP server Unix domain socket path
146 my $srcdir = $ENV{'srcdir'} || '.';
147 my $CURL="../src/curl".exe_ext(); # what curl executable to run on the tests
148 my $VCURL=$CURL; # what curl binary to use to verify the servers with
149 # VCURL is handy to set to the system one when the one you
150 # just built hangs or crashes and thus prevent verification
151 my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
153 my $TESTDIR="$srcdir/data";
154 my $LIBDIR="./libtest";
155 my $UNITDIR="./unit";
156 # TODO: change this to use server_inputfilename()
157 my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
158 my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
159 my $PROXYIN="$LOGDIR/proxy.input"; # what curl sent the proxy
160 my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
161 my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
162 my $SERVERLOGS_LOCK="$LOGDIR/serverlogs.lock"; # server logs advisor read lock
163 my $CURLCONFIG="../curl-config"; # curl-config from current build
165 # Normally, all test cases should be run, but at times it is handy to
166 # simply run a particular one:
169 # To run specific test cases, set them like:
170 # $TESTCASES="1 2 3 7 8";
172 #######################################################################
173 # No variables below this point should need to be modified
176 # invoke perl like this:
177 my $perl="perl -I$srcdir";
178 my $server_response_maxtime=13;
180 my $debug_build=0; # built debug enabled (--enable-debug)
181 my $has_memory_tracking=0; # built with memory tracking (--enable-curldebug)
184 # name of the file that the memory debugging creates:
185 my $memdump="$LOGDIR/memdump";
187 # the path to the script that analyzes the memory debug output file:
188 my $memanalyze="$perl $srcdir/memanalyze.pl";
190 my $pwd = getcwd(); # current working directory
193 my $ftpchecktime=1; # time it took to verify our test FTP server
195 my $stunnel = checkcmd("stunnel4") || checkcmd("tstunnel") || checkcmd("stunnel");
196 my $valgrind = checktestcmd("valgrind");
197 my $valgrind_logfile="--logfile";
199 my $gdb = checktestcmd("gdb");
200 my $httptlssrv = find_httptlssrv();
202 my $ssl_version; # set if libcurl is built with SSL support
203 my $large_file; # set if libcurl is built with large file support
204 my $has_idn; # set if libcurl is built with IDN support
205 my $http_ipv6; # set if HTTP server has IPv6 support
206 my $http_unix; # set if HTTP server has Unix sockets support
207 my $ftp_ipv6; # set if FTP server has IPv6 support
208 my $tftp_ipv6; # set if TFTP server has IPv6 support
209 my $gopher_ipv6; # set if Gopher server has IPv6 support
210 my $has_ipv6; # set if libcurl is built with IPv6 support
211 my $has_unix; # set if libcurl is built with Unix sockets support
212 my $has_libz; # set if libcurl is built with libz support
213 my $has_getrlimit; # set if system has getrlimit()
214 my $has_ntlm; # set if libcurl is built with NTLM support
215 my $has_ntlm_wb; # set if libcurl is built with NTLM delegation to winbind
216 my $has_sspi; # set if libcurl is built with Windows SSPI
217 my $has_gssapi; # set if libcurl is built with a GSS-API library
218 my $has_kerberos; # set if libcurl is built with Kerberos support
219 my $has_spnego; # set if libcurl is built with SPNEGO support
220 my $has_charconv; # set if libcurl is built with CharConv support
221 my $has_tls_srp; # set if libcurl is built with TLS-SRP support
222 my $has_metalink; # set if curl is built with Metalink support
223 my $has_http2; # set if libcurl is built with HTTP2 support
224 my $has_crypto; # set if libcurl is built with cryptographic support
225 my $has_cares; # set if built with c-ares
226 my $has_threadedres;# set if built with threaded resolver
228 # this version is decided by the particular nghttp2 library that is being used
229 my $h2cver = "h2c-14";
231 my $has_openssl; # built with a lib using an OpenSSL-like API
232 my $has_gnutls; # built with GnuTLS
233 my $has_nss; # built with NSS
234 my $has_yassl; # built with yassl
235 my $has_polarssl; # built with polarssl
236 my $has_axtls; # built with axTLS
237 my $has_winssl; # built with WinSSL (Secure Channel aka Schannel)
238 my $has_darwinssl; # build with DarwinSSL (Secure Transport)
240 my $has_sslpinning; # built with a TLS backend that supports pinning
242 my $has_shared = "unknown"; # built shared
244 my $resolver; # name of the resolver backend (for human presentation)
245 my $ssllib; # name of the SSL library we use (for human presentation)
247 my $has_textaware; # set if running on a system that has a text mode concept
248 # on files. Windows for example
250 my @protocols; # array of lowercase supported protocol servers
252 my $skipped=0; # number of tests skipped; reported in main loop
253 my %skipped; # skipped{reason}=counter, reasons for skip
254 my @teststat; # teststat[testnum]=reason, reasons for skip
255 my %disabled_keywords; # key words of tests to skip
256 my %enabled_keywords; # key words of tests to run
257 my %disabled; # disabled test cases
259 my $sshdid; # for socks server, ssh daemon version id
260 my $sshdvernum; # for socks server, ssh daemon version number
261 my $sshdverstr; # for socks server, ssh daemon version string
262 my $sshderror; # for socks server, ssh daemon version error
264 my $defserverlogslocktimeout = 20; # timeout to await server logs lock removal
265 my $defpostcommanddelay = 0; # delay between command and postcheck sections
267 my $timestats; # time stamping and stats generation
268 my $fullstats; # show time stats for every single test
269 my %timeprepini; # timestamp for each test preparation start
270 my %timesrvrini; # timestamp for each test required servers verification start
271 my %timesrvrend; # timestamp for each test required servers verification end
272 my %timetoolini; # timestamp for each test command run starting
273 my %timetoolend; # timestamp for each test command run stopping
274 my %timesrvrlog; # timestamp for each test server logs lock removal
275 my %timevrfyend; # timestamp for each test result verification end
277 my $testnumcheck; # test number, set in singletest sub.
280 #######################################################################
281 # variables that command line options may set
289 my $gdbthis; # run test case with gdb debugger
290 my $gdbxwin; # use windowed gdb when using gdb
291 my $keepoutfiles; # keep stdout and stderr files after tests
292 my $listonly; # only list the tests
293 my $postmortem; # display detailed info about failed tests
294 my $run_event_based; # run curl with --test-event to test the event API
296 my %run; # running server
297 my %doesntrun; # servers that don't work, identified by pidfile
298 my %serverpidfile;# all server pid file names, identified by server id
299 my %runcert; # cert file currently in use by an ssl running server
301 # torture test variables
306 #######################################################################
307 # logmsg is our general message logging subroutine.
315 # get the name of the current user
316 my $USER = $ENV{USER}; # Linux
318 $USER = $ENV{USERNAME}; # Windows
320 $USER = $ENV{LOGNAME}; # Some Unix (I think)
324 # enable memory debugging if curl is compiled with it
325 $ENV{'CURL_MEMDEBUG'} = $memdump;
326 $ENV{'CURL_ENTROPY'}="12345678";
327 $ENV{'CURL_FORCETIME'}=1; # for debug NTLM magic
332 logmsg "runtests.pl received SIG$signame, exiting\n";
333 stopservers($verbose);
334 die "Somebody sent me a SIG$signame";
336 $SIG{INT} = \&catch_zap;
337 $SIG{TERM} = \&catch_zap;
339 ##########################################################################
340 # Clear all possible '*_proxy' environment variables for various protocols
341 # to prevent them to interfere with our testing!
344 foreach $protocol (('ftp', 'http', 'ftps', 'https', 'no', 'all')) {
345 my $proxy = "${protocol}_proxy";
346 # clear lowercase version
347 delete $ENV{$proxy} if($ENV{$proxy});
348 # clear uppercase version
349 delete $ENV{uc($proxy)} if($ENV{uc($proxy)});
352 # make sure we don't get affected by other variables that control our
355 delete $ENV{'SSL_CERT_DIR'} if($ENV{'SSL_CERT_DIR'});
356 delete $ENV{'SSL_CERT_PATH'} if($ENV{'SSL_CERT_PATH'});
357 delete $ENV{'CURL_CA_BUNDLE'} if($ENV{'CURL_CA_BUNDLE'});
359 #######################################################################
360 # Load serverpidfile hash with pidfile names for all possible servers.
362 sub init_serverpidfile_hash {
363 for my $proto (('ftp', 'http', 'imap', 'pop3', 'smtp')) {
364 for my $ssl (('', 's')) {
365 for my $ipvnum ((4, 6)) {
366 for my $idnum ((1, 2, 3)) {
367 my $serv = servername_id("$proto$ssl", $ipvnum, $idnum);
368 my $pidf = server_pidfilename("$proto$ssl", $ipvnum, $idnum);
369 $serverpidfile{$serv} = $pidf;
374 for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'gopher', 'httptls')) {
375 for my $ipvnum ((4, 6)) {
376 for my $idnum ((1, 2)) {
377 my $serv = servername_id($proto, $ipvnum, $idnum);
378 my $pidf = server_pidfilename($proto, $ipvnum, $idnum);
379 $serverpidfile{$serv} = $pidf;
383 for my $proto (('http', 'imap', 'pop3', 'smtp')) {
384 for my $ssl (('', 's')) {
385 my $serv = servername_id("$proto$ssl", "unix", 1);
386 my $pidf = server_pidfilename("$proto$ssl", "unix", 1);
387 $serverpidfile{$serv} = $pidf;
392 #######################################################################
393 # Check if a given child process has just died. Reaps it if so.
396 use POSIX ":sys_wait_h";
398 if(not defined $pid || $pid <= 0) {
401 my $rc = waitpid($pid, &WNOHANG);
402 return ($rc == $pid)?1:0;
405 #######################################################################
406 # Start a new thread/process and run the given command line in there.
407 # Return the pids (yes plural) of the new child process to the parent.
410 my ($cmd, $pidfile, $timeout, $fake)=@_;
412 logmsg "startnew: $cmd\n" if ($verbose);
417 if(not defined $child) {
418 logmsg "startnew: fork() failure detected\n";
423 # Here we are the child. Run the given command.
425 # Put an "exec" in front of the command so that the child process
426 # keeps this child's process ID.
427 exec("exec $cmd") || die "Can't exec() $cmd: $!";
429 # exec() should never return back here to this process. We protect
430 # ourselves by calling die() just in case something goes really bad.
431 die "error: exec() has returned";
434 # Ugly hack but ssh client and gnutls-serv don't support pid files
436 if(open(OUT, ">$pidfile")) {
437 print OUT $child . "\n";
439 logmsg "startnew: $pidfile faked with pid=$child\n" if($verbose);
442 logmsg "startnew: failed to write fake $pidfile with pid=$child\n";
444 # could/should do a while connect fails sleep a bit and loop
446 if (checkdied($child)) {
447 logmsg "startnew: child process has failed to start\n" if($verbose);
452 my $count = $timeout;
454 if(-f $pidfile && -s $pidfile && open(PID, "<$pidfile")) {
457 if(($pid2 > 0) && pidexists($pid2)) {
458 # if $pid2 is valid, then make sure this pid is alive, as
459 # otherwise it is just likely to be the _previous_ pidfile or
463 # invalidate $pid2 if not actually alive
466 if (checkdied($child)) {
467 logmsg "startnew: child process has died, server might start up\n"
469 # We can't just abort waiting for the server with a
471 # because the server might have forked and could still start
472 # up normally. Instead, just reduce the amount of time we remain
479 # Return two PIDs, the one for the child process we spawned and the one
480 # reported by the server itself (in case it forked again on its own).
481 # Both (potentially) need to be killed at the end of the test.
482 return ($child, $pid2);
486 #######################################################################
487 # Check for a command in the PATH of the test server.
491 my @paths=(split(":", $ENV{'PATH'}), "/usr/sbin", "/usr/local/sbin",
492 "/sbin", "/usr/bin", "/usr/local/bin",
493 "./libtest/.libs", "./libtest");
495 if( -x "$_/$cmd" && ! -d "$_/$cmd") {
496 # executable bit but not a directory!
502 #######################################################################
503 # Get the list of tests that the tests/data/Makefile.am knows about!
507 my @dist = `cd data && make show`;
508 $disttests = join("", @dist);
511 #######################################################################
512 # Check for a command in the PATH of the machine running curl.
516 return checkcmd($cmd);
519 #######################################################################
520 # Run the application under test and return its return code
524 my $ret = system($cmd);
525 print "CMD ($ret): $cmd\n" if($verbose && !$torture);
528 # This is one way to test curl on a remote machine
529 # my $out = system("ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'");
530 # sleep 2; # time to allow the NFS server to be updated
534 #######################################################################
535 # Run the application under test and return its stdout
537 sub runclientoutput {
541 # This is one way to test curl on a remote machine
542 # my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`;
543 # sleep 2; # time to allow the NFS server to be updated
547 #######################################################################
548 # Memory allocation test and failure torture testing.
554 # remove memdump first to be sure we get a new nice and clean one
557 # First get URL from test server, ignore the output/result
560 logmsg " CMD: $testcmd\n" if($verbose);
562 # memanalyze -v is our friend, get the number of allocations made
564 my @out = `$memanalyze -v $memdump`;
566 if(/^Allocations: (\d+)/) {
572 logmsg " found no allocs to make fail\n";
576 logmsg " $count allocations to make fail\n";
578 for ( 1 .. $count ) {
583 if($tortalloc && ($tortalloc != $limit)) {
588 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
590 my $now = sprintf("%02d:%02d:%02d ", $hour, $min, $sec);
591 logmsg "Fail alloc no: $limit at $now\r";
594 # make the memory allocation function number $limit return failure
595 $ENV{'CURL_MEMLIMIT'} = $limit;
597 # remove memdump first to be sure we get a new nice and clean one
600 logmsg "*** Alloc number $limit is now set to fail ***\n" if($gdbthis);
607 $ret = runclient($testcmd);
609 #logmsg "$_ Returned " . ($ret >> 8) . "\n";
611 # Now clear the variable again
612 delete $ENV{'CURL_MEMLIMIT'} if($ENV{'CURL_MEMLIMIT'});
615 # there's core file present now!
616 logmsg " core dumped\n";
621 # verify that it returns a proper error code, doesn't leak memory
622 # and doesn't core dump
623 if(($ret & 255) || ($ret >> 8) >= 128) {
624 logmsg " system() returned $ret\n";
628 my @memdata=`$memanalyze $memdump`;
632 # well it could be other memory problems as well, but
633 # we call it leak for short here
638 logmsg "** MEMORY FAILURE\n";
640 logmsg `$memanalyze -l $memdump`;
645 logmsg " Failed on alloc number $limit in test.\n",
646 " invoke with \"-t$limit\" to repeat this single case.\n";
647 stopservers($verbose);
652 logmsg "torture OK\n";
656 #######################################################################
657 # Stop a test server along with pids which aren't in the %run hash yet.
658 # This also stops all servers which are relative to the given one.
661 my ($server, $pidlist) = @_;
663 # kill sockfilter processes for pingpong relative server
665 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
667 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
668 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
669 killsockfilters($proto, $ipvnum, $idnum, $verbose);
672 # All servers relative to the given one must be stopped also
675 if($server =~ /^(ftp|http|imap|pop3|smtp|httppipe)s((\d*)(-ipv6|-unix|))$/) {
676 # given a stunnel based ssl server, also kill non-ssl underlying one
677 push @killservers, "${1}${2}";
679 elsif($server =~ /^(ftp|http|imap|pop3|smtp|httppipe)((\d*)(-ipv6|-unix|))$/) {
680 # given a non-ssl server, also kill stunnel based ssl piggybacking one
681 push @killservers, "${1}s${2}";
683 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
684 # given a socks server, also kill ssh underlying one
685 push @killservers, "ssh${2}";
687 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
688 # given a ssh server, also kill socks piggybacking one
689 push @killservers, "socks${2}";
691 push @killservers, $server;
693 # kill given pids and server relative ones clearing them in %run hash
695 foreach my $server (@killservers) {
697 # we must prepend a space since $pidlist may already contain a pid
698 $pidlist .= " $run{$server}";
701 $runcert{$server} = 0 if($runcert{$server});
703 killpid($verbose, $pidlist);
705 # cleanup server pid files
707 foreach my $server (@killservers) {
708 my $pidfile = $serverpidfile{$server};
709 my $pid = processexists($pidfile);
711 logmsg "Warning: $server server unexpectedly alive\n";
712 killpid($verbose, $pid);
714 unlink($pidfile) if(-f $pidfile);
718 #######################################################################
719 # Verify that the server that runs on $ip, $port is our server. This also
720 # implies that we can speak with it, as there might be occasions when the
721 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
722 # assign requested address")
725 my ($proto, $ipvnum, $idnum, $ip, $port_or_path) = @_;
726 my $server = servername_id($proto, $ipvnum, $idnum);
729 # $port_or_path contains a path for Unix sockets, sws ignores the port
730 my $port = ($ipvnum eq "unix") ? 80 : $port_or_path;
732 my $verifyout = "$LOGDIR/".
733 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
734 unlink($verifyout) if(-f $verifyout);
736 my $verifylog = "$LOGDIR/".
737 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
738 unlink($verifylog) if(-f $verifylog);
740 if($proto eq "gopher") {
745 my $flags = "--max-time $server_response_maxtime ";
746 $flags .= "--output $verifyout ";
747 $flags .= "--silent ";
748 $flags .= "--verbose ";
749 $flags .= "--globoff ";
750 $flags .= "--unix-socket '$port_or_path' " if $ipvnum eq "unix";
751 $flags .= "-1 " if($has_axtls);
752 $flags .= "--insecure " if($proto eq 'https');
753 $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\"";
755 my $cmd = "$VCURL $flags 2>$verifylog";
757 # verify if our/any server is running on this port
758 logmsg "RUN: $cmd\n" if($verbose);
759 my $res = runclient($cmd);
761 $res >>= 8; # rotate the result
763 logmsg "RUN: curl command died with a coredump\n";
767 if($res && $verbose) {
768 logmsg "RUN: curl command returned $res\n";
769 if(open(FILE, "<$verifylog")) {
770 while(my $string = <FILE>) {
771 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
778 if(open(FILE, "<$verifyout")) {
779 while(my $string = <FILE>) {
781 last; # only want first line
786 if($data && ($data =~ /WE ROOLZ: (\d+)/)) {
790 # curl: (6) Couldn't resolve host '::1'
791 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
794 elsif($data || ($res && ($res != 7))) {
795 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
801 #######################################################################
802 # Verify that the server that runs on $ip, $port is our server. This also
803 # implies that we can speak with it, as there might be occasions when the
804 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
805 # assign requested address")
808 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
809 my $server = servername_id($proto, $ipvnum, $idnum);
814 my $verifylog = "$LOGDIR/".
815 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
816 unlink($verifylog) if(-f $verifylog);
818 if($proto eq "ftps") {
819 $extra .= "--insecure --ftp-ssl-control ";
822 my $flags = "--max-time $server_response_maxtime ";
823 $flags .= "--silent ";
824 $flags .= "--verbose ";
825 $flags .= "--globoff ";
827 $flags .= "\"$proto://$ip:$port/verifiedserver\"";
829 my $cmd = "$VCURL $flags 2>$verifylog";
831 # check if this is our server running on this port:
832 logmsg "RUN: $cmd\n" if($verbose);
833 my @data = runclientoutput($cmd);
835 my $res = $? >> 8; # rotate the result
837 logmsg "RUN: curl command died with a coredump\n";
841 foreach my $line (@data) {
842 if($line =~ /WE ROOLZ: (\d+)/) {
843 # this is our test server with a known pid!
848 if($pid <= 0 && @data && $data[0]) {
849 # this is not a known server
850 logmsg "RUN: Unknown server on our $server port: $port\n";
853 # we can/should use the time it took to verify the FTP server as a measure
854 # on how fast/slow this host/FTP is.
855 my $took = int(0.5+time()-$time);
858 logmsg "RUN: Verifying our test $server server took $took seconds\n";
860 $ftpchecktime = $took>=1?$took:1; # make sure it never is below 1
865 #######################################################################
866 # Verify that the server that runs on $ip, $port is our server. This also
867 # implies that we can speak with it, as there might be occasions when the
868 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
869 # assign requested address")
872 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
873 my $server = servername_id($proto, $ipvnum, $idnum);
876 my $verifyout = "$LOGDIR/".
877 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
878 unlink($verifyout) if(-f $verifyout);
880 my $verifylog = "$LOGDIR/".
881 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
882 unlink($verifylog) if(-f $verifylog);
884 my $flags = "--max-time $server_response_maxtime ";
885 $flags .= "--output $verifyout ";
886 $flags .= "--silent ";
887 $flags .= "--verbose ";
888 $flags .= "--globoff ";
889 # currently verification is done using http
890 $flags .= "\"http://$ip:$port/verifiedserver\"";
892 my $cmd = "$VCURL $flags 2>$verifylog";
894 # verify if our/any server is running on this port
895 logmsg "RUN: $cmd\n" if($verbose);
896 my $res = runclient($cmd);
898 $res >>= 8; # rotate the result
900 logmsg "RUN: curl command died with a coredump\n";
904 if($res && $verbose) {
905 logmsg "RUN: curl command returned $res\n";
906 if(open(FILE, "<$verifylog")) {
907 while(my $string = <FILE>) {
908 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
915 if(open(FILE, "<$verifyout")) {
916 while(my $string = <FILE>) {
918 last; # only want first line
923 if($data && ($data =~ /RTSP_SERVER WE ROOLZ: (\d+)/)) {
927 # curl: (6) Couldn't resolve host '::1'
928 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
931 elsif($data || ($res != 7)) {
932 logmsg "RUN: Unknown server on our $server port: $port\n";
938 #######################################################################
939 # Verify that the ssh server has written out its pidfile, recovering
940 # the pid from the file and returning it if a process with that pid is
944 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
945 my $server = servername_id($proto, $ipvnum, $idnum);
946 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
948 if(open(FILE, "<$pidfile")) {
953 # if we have a pid it is actually our ssh server,
954 # since runsshserver() unlinks previous pidfile
955 if(!pidexists($pid)) {
956 logmsg "RUN: SSH server has died after starting up\n";
965 #######################################################################
966 # Verify that we can connect to the sftp server, properly authenticate
967 # with generated config and key files and run a simple remote pwd.
970 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
971 my $server = servername_id($proto, $ipvnum, $idnum);
973 # Find out sftp client canonical file name
974 my $sftp = find_sftp();
976 logmsg "RUN: SFTP server cannot find $sftpexe\n";
979 # Find out ssh client canonical file name
980 my $ssh = find_ssh();
982 logmsg "RUN: SFTP server cannot find $sshexe\n";
985 # Connect to sftp server, authenticate and run a remote pwd
986 # command using our generated configuration and key files
987 my $cmd = "\"$sftp\" -b $sftpcmds -F $sftpconfig -S \"$ssh\" $ip > $sftplog 2>&1";
988 my $res = runclient($cmd);
989 # Search for pwd command response in log file
990 if(open(SFTPLOGFILE, "<$sftplog")) {
991 while(<SFTPLOGFILE>) {
992 if(/^Remote working directory: /) {
1002 #######################################################################
1003 # Verify that the non-stunnel HTTP TLS extensions capable server that runs
1004 # on $ip, $port is our server. This also implies that we can speak with it,
1005 # as there might be occasions when the server runs fine but we cannot talk
1006 # to it ("Failed to connect to ::1: Can't assign requested address")
1009 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1010 my $server = servername_id($proto, $ipvnum, $idnum);
1011 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
1014 my $verifyout = "$LOGDIR/".
1015 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
1016 unlink($verifyout) if(-f $verifyout);
1018 my $verifylog = "$LOGDIR/".
1019 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
1020 unlink($verifylog) if(-f $verifylog);
1022 my $flags = "--max-time $server_response_maxtime ";
1023 $flags .= "--output $verifyout ";
1024 $flags .= "--verbose ";
1025 $flags .= "--globoff ";
1026 $flags .= "--insecure ";
1027 $flags .= "--tlsauthtype SRP ";
1028 $flags .= "--tlsuser jsmith ";
1029 $flags .= "--tlspassword abc ";
1030 $flags .= "\"https://$ip:$port/verifiedserver\"";
1032 my $cmd = "$VCURL $flags 2>$verifylog";
1034 # verify if our/any server is running on this port
1035 logmsg "RUN: $cmd\n" if($verbose);
1036 my $res = runclient($cmd);
1038 $res >>= 8; # rotate the result
1040 logmsg "RUN: curl command died with a coredump\n";
1044 if($res && $verbose) {
1045 logmsg "RUN: curl command returned $res\n";
1046 if(open(FILE, "<$verifylog")) {
1047 while(my $string = <FILE>) {
1048 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
1055 if(open(FILE, "<$verifyout")) {
1056 while(my $string = <FILE>) {
1062 if($data && ($data =~ /(GNUTLS|GnuTLS)/) && open(FILE, "<$pidfile")) {
1066 # if we have a pid it is actually our httptls server,
1067 # since runhttptlsserver() unlinks previous pidfile
1068 if(!pidexists($pid)) {
1069 logmsg "RUN: $server server has died after starting up\n";
1078 # curl: (6) Couldn't resolve host '::1'
1079 logmsg "RUN: failed to resolve host (https://$ip:$port/verifiedserver)\n";
1082 elsif($data || ($res && ($res != 7))) {
1083 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
1089 #######################################################################
1090 # STUB for verifying socks
1093 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1094 my $server = servername_id($proto, $ipvnum, $idnum);
1095 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
1097 if(open(FILE, "<$pidfile")) {
1102 # if we have a pid it is actually our socks server,
1103 # since runsocksserver() unlinks previous pidfile
1104 if(!pidexists($pid)) {
1105 logmsg "RUN: SOCKS server has died after starting up\n";
1114 #######################################################################
1115 # Verify that the server that runs on $ip, $port is our server.
1116 # Retry over several seconds before giving up. The ssh server in
1117 # particular can take a long time to start if it needs to generate
1118 # keys on a slow or loaded host.
1120 # Just for convenience, test harness uses 'https' and 'httptls' literals
1121 # as values for 'proto' variable in order to differentiate different
1122 # servers. 'https' literal is used for stunnel based https test servers,
1123 # and 'httptls' is used for non-stunnel https test servers.
1126 my %protofunc = ('http' => \&verifyhttp,
1127 'https' => \&verifyhttp,
1128 'rtsp' => \&verifyrtsp,
1129 'ftp' => \&verifyftp,
1130 'pop3' => \&verifyftp,
1131 'imap' => \&verifyftp,
1132 'smtp' => \&verifyftp,
1133 'httppipe' => \&verifyhttp,
1134 'ftps' => \&verifyftp,
1135 'tftp' => \&verifyftp,
1136 'ssh' => \&verifyssh,
1137 'socks' => \&verifysocks,
1138 'gopher' => \&verifyhttp,
1139 'httptls' => \&verifyhttptls);
1142 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1144 my $count = 30; # try for this many seconds
1148 my $fun = $protofunc{$proto};
1150 $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1156 # a real failure, stop trying and bail out
1164 #######################################################################
1165 # Single shot server responsiveness test. This should only be used
1166 # to verify that a server present in %run hash is still functional
1168 sub responsiveserver {
1169 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1170 my $prev_verbose = $verbose;
1173 my $fun = $protofunc{$proto};
1174 my $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1175 $verbose = $prev_verbose;
1178 return 1; # responsive
1181 my $srvrname = servername_str($proto, $ipvnum, $idnum);
1182 logmsg " server precheck FAILED (unresponsive $srvrname server)\n";
1186 #######################################################################
1187 # start the http server
1190 my ($proto, $verbose, $alt, $port_or_path) = @_;
1199 my $exe = "$perl $srcdir/httpserver.pl";
1200 my $verbose_flag = "--verbose ";
1202 if($alt eq "ipv6") {
1203 # if IPv6, use a different setup
1207 elsif($alt eq "proxy") {
1208 # basically the same, but another ID
1211 elsif($alt eq "pipe") {
1212 # basically the same, but another ID
1214 $exe = "python $srcdir/http_pipe.py";
1215 $verbose_flag .= "1 ";
1217 elsif($alt eq "unix") {
1218 # IP (protocol) is mutually exclusive with Unix sockets
1222 $server = servername_id($proto, $ipvnum, $idnum);
1224 $pidfile = $serverpidfile{$server};
1226 # don't retry if the server doesn't work
1227 if ($doesntrun{$pidfile}) {
1231 my $pid = processexists($pidfile);
1233 stopserver($server, "$pid");
1235 unlink($pidfile) if(-f $pidfile);
1237 $srvrname = servername_str($proto, $ipvnum, $idnum);
1239 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1241 $flags .= "--gopher " if($proto eq "gopher");
1242 $flags .= "--connect $HOSTIP " if($alt eq "proxy");
1243 $flags .= $verbose_flag if($debugprotocol);
1244 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1245 $flags .= "--id $idnum " if($idnum > 1);
1246 if($ipvnum eq "unix") {
1247 $flags .= "--unix-socket '$port_or_path' ";
1249 $flags .= "--ipv$ipvnum --port $port_or_path ";
1251 $flags .= "--srcdir \"$srcdir\"";
1253 my $cmd = "$exe $flags";
1254 my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1256 if($httppid <= 0 || !pidexists($httppid)) {
1258 logmsg "RUN: failed to start the $srvrname server\n";
1259 stopserver($server, "$pid2");
1260 displaylogs($testnumcheck);
1261 $doesntrun{$pidfile} = 1;
1265 # Server is up. Verify that we can speak to it.
1266 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port_or_path);
1268 logmsg "RUN: $srvrname server failed verification\n";
1269 # failed to talk to it properly. Kill the server and return failure
1270 stopserver($server, "$httppid $pid2");
1271 displaylogs($testnumcheck);
1272 $doesntrun{$pidfile} = 1;
1278 logmsg "RUN: $srvrname server is now running PID $httppid\n";
1283 return ($httppid, $pid2);
1286 #######################################################################
1287 # start the http server
1289 sub runhttp_pipeserver {
1290 my ($proto, $verbose, $alt, $port) = @_;
1300 if($alt eq "ipv6") {
1304 $server = servername_id($proto, $ipvnum, $idnum);
1306 $pidfile = $serverpidfile{$server};
1308 # don't retry if the server doesn't work
1309 if ($doesntrun{$pidfile}) {
1313 my $pid = processexists($pidfile);
1315 stopserver($server, "$pid");
1317 unlink($pidfile) if(-f $pidfile);
1319 $srvrname = servername_str($proto, $ipvnum, $idnum);
1321 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1323 $flags .= "--verbose 1 " if($debugprotocol);
1324 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1325 $flags .= "--id $idnum " if($idnum > 1);
1326 $flags .= "--port $port --srcdir \"$srcdir\"";
1328 my $cmd = "$srcdir/http_pipe.py $flags";
1329 my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1331 if($httppid <= 0 || !pidexists($httppid)) {
1333 logmsg "RUN: failed to start the $srvrname server\n";
1334 stopserver($server, "$pid2");
1335 displaylogs($testnumcheck);
1336 $doesntrun{$pidfile} = 1;
1340 # Server is up. Verify that we can speak to it.
1341 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1343 logmsg "RUN: $srvrname server failed verification\n";
1344 # failed to talk to it properly. Kill the server and return failure
1345 stopserver($server, "$httppid $pid2");
1346 displaylogs($testnumcheck);
1347 $doesntrun{$pidfile} = 1;
1353 logmsg "RUN: $srvrname server is now running PID $httppid\n";
1358 return ($httppid, $pid2);
1361 #######################################################################
1362 # start the https stunnel based server
1364 sub runhttpsserver {
1365 my ($verbose, $ipv6, $certfile) = @_;
1366 my $proto = 'https';
1367 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1368 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1380 $server = servername_id($proto, $ipvnum, $idnum);
1382 $pidfile = $serverpidfile{$server};
1384 # don't retry if the server doesn't work
1385 if ($doesntrun{$pidfile}) {
1389 my $pid = processexists($pidfile);
1391 stopserver($server, "$pid");
1393 unlink($pidfile) if(-f $pidfile);
1395 $srvrname = servername_str($proto, $ipvnum, $idnum);
1397 $certfile = 'stunnel.pem' unless($certfile);
1399 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1401 $flags .= "--verbose " if($debugprotocol);
1402 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1403 $flags .= "--id $idnum " if($idnum > 1);
1404 $flags .= "--ipv$ipvnum --proto $proto ";
1405 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1406 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1407 $flags .= "--connect $HTTPPORT --accept $HTTPSPORT";
1409 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1410 my ($httpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1412 if($httpspid <= 0 || !pidexists($httpspid)) {
1414 logmsg "RUN: failed to start the $srvrname server\n";
1415 stopserver($server, "$pid2");
1416 displaylogs($testnumcheck);
1417 $doesntrun{$pidfile} = 1;
1421 # Server is up. Verify that we can speak to it.
1422 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $HTTPSPORT);
1424 logmsg "RUN: $srvrname server failed verification\n";
1425 # failed to talk to it properly. Kill the server and return failure
1426 stopserver($server, "$httpspid $pid2");
1427 displaylogs($testnumcheck);
1428 $doesntrun{$pidfile} = 1;
1431 # Here pid3 is actually the pid returned by the unsecure-http server.
1433 $runcert{$server} = $certfile;
1436 logmsg "RUN: $srvrname server is now running PID $httpspid\n";
1441 return ($httpspid, $pid2);
1444 #######################################################################
1445 # start the non-stunnel HTTP TLS extensions capable server
1447 sub runhttptlsserver {
1448 my ($verbose, $ipv6) = @_;
1449 my $proto = "httptls";
1450 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
1451 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1452 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1464 $server = servername_id($proto, $ipvnum, $idnum);
1466 $pidfile = $serverpidfile{$server};
1468 # don't retry if the server doesn't work
1469 if ($doesntrun{$pidfile}) {
1473 my $pid = processexists($pidfile);
1475 stopserver($server, "$pid");
1477 unlink($pidfile) if(-f $pidfile);
1479 $srvrname = servername_str($proto, $ipvnum, $idnum);
1481 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1483 $flags .= "--http ";
1484 $flags .= "--debug 1 " if($debugprotocol);
1485 $flags .= "--port $port ";
1486 $flags .= "--priority NORMAL:+SRP ";
1487 $flags .= "--srppasswd $srcdir/certs/srp-verifier-db ";
1488 $flags .= "--srppasswdconf $srcdir/certs/srp-verifier-conf";
1490 my $cmd = "$httptlssrv $flags > $logfile 2>&1";
1491 my ($httptlspid, $pid2) = startnew($cmd, $pidfile, 10, 1); # fake pidfile
1493 if($httptlspid <= 0 || !pidexists($httptlspid)) {
1495 logmsg "RUN: failed to start the $srvrname server\n";
1496 stopserver($server, "$pid2");
1497 displaylogs($testnumcheck);
1498 $doesntrun{$pidfile} = 1;
1502 # Server is up. Verify that we can speak to it. PID is from fake pidfile
1503 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1505 logmsg "RUN: $srvrname server failed verification\n";
1506 # failed to talk to it properly. Kill the server and return failure
1507 stopserver($server, "$httptlspid $pid2");
1508 displaylogs($testnumcheck);
1509 $doesntrun{$pidfile} = 1;
1515 logmsg "RUN: $srvrname server is now running PID $httptlspid\n";
1520 return ($httptlspid, $pid2);
1523 #######################################################################
1524 # start the pingpong server (FTP, POP3, IMAP, SMTP)
1526 sub runpingpongserver {
1527 my ($proto, $id, $verbose, $ipv6) = @_;
1529 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1530 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1531 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1538 if($proto eq "ftp") {
1539 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
1542 # if IPv6, use a different setup
1546 elsif($proto eq "pop3") {
1547 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
1549 elsif($proto eq "imap") {
1550 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
1552 elsif($proto eq "smtp") {
1553 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
1556 print STDERR "Unsupported protocol $proto!!\n";
1560 $server = servername_id($proto, $ipvnum, $idnum);
1562 $pidfile = $serverpidfile{$server};
1564 # don't retry if the server doesn't work
1565 if ($doesntrun{$pidfile}) {
1569 my $pid = processexists($pidfile);
1571 stopserver($server, "$pid");
1573 unlink($pidfile) if(-f $pidfile);
1575 $srvrname = servername_str($proto, $ipvnum, $idnum);
1577 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1579 $flags .= "--verbose " if($debugprotocol);
1580 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1581 $flags .= "--srcdir \"$srcdir\" --proto $proto ";
1582 $flags .= "--id $idnum " if($idnum > 1);
1583 $flags .= "--ipv$ipvnum --port $port --addr \"$ip\"";
1585 my $cmd = "$perl $srcdir/ftpserver.pl $flags";
1586 my ($ftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1588 if($ftppid <= 0 || !pidexists($ftppid)) {
1590 logmsg "RUN: failed to start the $srvrname server\n";
1591 stopserver($server, "$pid2");
1592 displaylogs($testnumcheck);
1593 $doesntrun{$pidfile} = 1;
1597 # Server is up. Verify that we can speak to it.
1598 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1600 logmsg "RUN: $srvrname server failed verification\n";
1601 # failed to talk to it properly. Kill the server and return failure
1602 stopserver($server, "$ftppid $pid2");
1603 displaylogs($testnumcheck);
1604 $doesntrun{$pidfile} = 1;
1611 logmsg "RUN: $srvrname server is now running PID $ftppid\n";
1616 return ($pid2, $ftppid);
1619 #######################################################################
1620 # start the ftps server (or rather, tunnel)
1623 my ($verbose, $ipv6, $certfile) = @_;
1625 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1626 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1638 $server = servername_id($proto, $ipvnum, $idnum);
1640 $pidfile = $serverpidfile{$server};
1642 # don't retry if the server doesn't work
1643 if ($doesntrun{$pidfile}) {
1647 my $pid = processexists($pidfile);
1649 stopserver($server, "$pid");
1651 unlink($pidfile) if(-f $pidfile);
1653 $srvrname = servername_str($proto, $ipvnum, $idnum);
1655 $certfile = 'stunnel.pem' unless($certfile);
1657 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1659 $flags .= "--verbose " if($debugprotocol);
1660 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1661 $flags .= "--id $idnum " if($idnum > 1);
1662 $flags .= "--ipv$ipvnum --proto $proto ";
1663 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1664 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1665 $flags .= "--connect $FTPPORT --accept $FTPSPORT";
1667 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1668 my ($ftpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1670 if($ftpspid <= 0 || !pidexists($ftpspid)) {
1672 logmsg "RUN: failed to start the $srvrname server\n";
1673 stopserver($server, "$pid2");
1674 displaylogs($testnumcheck);
1675 $doesntrun{$pidfile} = 1;
1679 # Server is up. Verify that we can speak to it.
1680 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $FTPSPORT);
1682 logmsg "RUN: $srvrname server failed verification\n";
1683 # failed to talk to it properly. Kill the server and return failure
1684 stopserver($server, "$ftpspid $pid2");
1685 displaylogs($testnumcheck);
1686 $doesntrun{$pidfile} = 1;
1689 # Here pid3 is actually the pid returned by the unsecure-ftp server.
1691 $runcert{$server} = $certfile;
1694 logmsg "RUN: $srvrname server is now running PID $ftpspid\n";
1699 return ($ftpspid, $pid2);
1702 #######################################################################
1703 # start the tftp server
1706 my ($id, $verbose, $ipv6) = @_;
1707 my $port = $TFTPPORT;
1711 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1719 # if IPv6, use a different setup
1725 $server = servername_id($proto, $ipvnum, $idnum);
1727 $pidfile = $serverpidfile{$server};
1729 # don't retry if the server doesn't work
1730 if ($doesntrun{$pidfile}) {
1734 my $pid = processexists($pidfile);
1736 stopserver($server, "$pid");
1738 unlink($pidfile) if(-f $pidfile);
1740 $srvrname = servername_str($proto, $ipvnum, $idnum);
1742 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1744 $flags .= "--verbose " if($debugprotocol);
1745 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1746 $flags .= "--id $idnum " if($idnum > 1);
1747 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1749 my $cmd = "$perl $srcdir/tftpserver.pl $flags";
1750 my ($tftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1752 if($tftppid <= 0 || !pidexists($tftppid)) {
1754 logmsg "RUN: failed to start the $srvrname server\n";
1755 stopserver($server, "$pid2");
1756 displaylogs($testnumcheck);
1757 $doesntrun{$pidfile} = 1;
1761 # Server is up. Verify that we can speak to it.
1762 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1764 logmsg "RUN: $srvrname server failed verification\n";
1765 # failed to talk to it properly. Kill the server and return failure
1766 stopserver($server, "$tftppid $pid2");
1767 displaylogs($testnumcheck);
1768 $doesntrun{$pidfile} = 1;
1774 logmsg "RUN: $srvrname server is now running PID $tftppid\n";
1779 return ($pid2, $tftppid);
1783 #######################################################################
1784 # start the rtsp server
1787 my ($verbose, $ipv6) = @_;
1788 my $port = $RTSPPORT;
1800 # if IPv6, use a different setup
1806 $server = servername_id($proto, $ipvnum, $idnum);
1808 $pidfile = $serverpidfile{$server};
1810 # don't retry if the server doesn't work
1811 if ($doesntrun{$pidfile}) {
1815 my $pid = processexists($pidfile);
1817 stopserver($server, "$pid");
1819 unlink($pidfile) if(-f $pidfile);
1821 $srvrname = servername_str($proto, $ipvnum, $idnum);
1823 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1825 $flags .= "--verbose " if($debugprotocol);
1826 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1827 $flags .= "--id $idnum " if($idnum > 1);
1828 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1830 my $cmd = "$perl $srcdir/rtspserver.pl $flags";
1831 my ($rtsppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1833 if($rtsppid <= 0 || !pidexists($rtsppid)) {
1835 logmsg "RUN: failed to start the $srvrname server\n";
1836 stopserver($server, "$pid2");
1837 displaylogs($testnumcheck);
1838 $doesntrun{$pidfile} = 1;
1842 # Server is up. Verify that we can speak to it.
1843 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1845 logmsg "RUN: $srvrname server failed verification\n";
1846 # failed to talk to it properly. Kill the server and return failure
1847 stopserver($server, "$rtsppid $pid2");
1848 displaylogs($testnumcheck);
1849 $doesntrun{$pidfile} = 1;
1855 logmsg "RUN: $srvrname server is now running PID $rtsppid\n";
1860 return ($rtsppid, $pid2);
1864 #######################################################################
1865 # Start the ssh (scp/sftp) server
1868 my ($id, $verbose, $ipv6) = @_;
1870 my $port = $SSHPORT;
1871 my $socksport = $SOCKSPORT;
1874 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1881 $server = servername_id($proto, $ipvnum, $idnum);
1883 $pidfile = $serverpidfile{$server};
1885 # don't retry if the server doesn't work
1886 if ($doesntrun{$pidfile}) {
1890 my $pid = processexists($pidfile);
1892 stopserver($server, "$pid");
1894 unlink($pidfile) if(-f $pidfile);
1896 $srvrname = servername_str($proto, $ipvnum, $idnum);
1898 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1900 $flags .= "--verbose " if($verbose);
1901 $flags .= "--debugprotocol " if($debugprotocol);
1902 $flags .= "--pidfile \"$pidfile\" ";
1903 $flags .= "--id $idnum " if($idnum > 1);
1904 $flags .= "--ipv$ipvnum --addr \"$ip\" ";
1905 $flags .= "--sshport $port --socksport $socksport ";
1906 $flags .= "--user \"$USER\"";
1908 my $cmd = "$perl $srcdir/sshserver.pl $flags";
1909 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 60, 0);
1911 # on loaded systems sshserver start up can take longer than the timeout
1912 # passed to startnew, when this happens startnew completes without being
1913 # able to read the pidfile and consequently returns a zero pid2 above.
1915 if($sshpid <= 0 || !pidexists($sshpid)) {
1917 logmsg "RUN: failed to start the $srvrname server\n";
1918 stopserver($server, "$pid2");
1919 $doesntrun{$pidfile} = 1;
1923 # ssh server verification allows some extra time for the server to start up
1924 # and gives us the opportunity of recovering the pid from the pidfile, when
1925 # this verification succeeds the recovered pid is assigned to pid2.
1927 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1929 logmsg "RUN: $srvrname server failed verification\n";
1930 # failed to fetch server pid. Kill the server and return failure
1931 stopserver($server, "$sshpid $pid2");
1932 $doesntrun{$pidfile} = 1;
1937 # once it is known that the ssh server is alive, sftp server verification
1938 # is performed actually connecting to it, authenticating and performing a
1939 # very simple remote command. This verification is tried only one time.
1941 $sshdlog = server_logfilename($LOGDIR, 'ssh', $ipvnum, $idnum);
1942 $sftplog = server_logfilename($LOGDIR, 'sftp', $ipvnum, $idnum);
1944 if(verifysftp('sftp', $ipvnum, $idnum, $ip, $port) < 1) {
1945 logmsg "RUN: SFTP server failed verification\n";
1946 # failed to talk to it properly. Kill the server and return failure
1948 display_sftpconfig();
1950 display_sshdconfig();
1951 stopserver($server, "$sshpid $pid2");
1952 $doesntrun{$pidfile} = 1;
1957 logmsg "RUN: $srvrname server is now running PID $pid2\n";
1960 return ($pid2, $sshpid);
1963 #######################################################################
1964 # Start the socks server
1966 sub runsocksserver {
1967 my ($id, $verbose, $ipv6) = @_;
1969 my $port = $SOCKSPORT;
1970 my $proto = 'socks';
1972 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1979 $server = servername_id($proto, $ipvnum, $idnum);
1981 $pidfile = $serverpidfile{$server};
1983 # don't retry if the server doesn't work
1984 if ($doesntrun{$pidfile}) {
1988 my $pid = processexists($pidfile);
1990 stopserver($server, "$pid");
1992 unlink($pidfile) if(-f $pidfile);
1994 $srvrname = servername_str($proto, $ipvnum, $idnum);
1996 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1998 # The ssh server must be already running
2000 logmsg "RUN: SOCKS server cannot find running SSH server\n";
2001 $doesntrun{$pidfile} = 1;
2005 # Find out ssh daemon canonical file name
2006 my $sshd = find_sshd();
2008 logmsg "RUN: SOCKS server cannot find $sshdexe\n";
2009 $doesntrun{$pidfile} = 1;
2013 # Find out ssh daemon version info
2014 ($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd);
2016 # Not an OpenSSH or SunSSH ssh daemon
2017 logmsg "$sshderror\n" if($verbose);
2018 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
2019 $doesntrun{$pidfile} = 1;
2022 logmsg "ssh server found $sshd is $sshdverstr\n" if($verbose);
2024 # Find out ssh client canonical file name
2025 my $ssh = find_ssh();
2027 logmsg "RUN: SOCKS server cannot find $sshexe\n";
2028 $doesntrun{$pidfile} = 1;
2032 # Find out ssh client version info
2033 my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh);
2035 # Not an OpenSSH or SunSSH ssh client
2036 logmsg "$ssherror\n" if($verbose);
2037 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
2038 $doesntrun{$pidfile} = 1;
2042 # Verify minimum ssh client version
2043 if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
2044 (($sshid =~ /SunSSH/) && ($sshvernum < 100))) {
2045 logmsg "ssh client found $ssh is $sshverstr\n";
2046 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
2047 $doesntrun{$pidfile} = 1;
2050 logmsg "ssh client found $ssh is $sshverstr\n" if($verbose);
2052 # Verify if ssh client and ssh daemon versions match
2053 if(($sshdid ne $sshid) || ($sshdvernum != $sshvernum)) {
2054 # Our test harness might work with slightly mismatched versions
2055 logmsg "Warning: version mismatch: sshd $sshdverstr - ssh $sshverstr\n"
2059 # Config file options for ssh client are previously set from sshserver.pl
2060 if(! -e $sshconfig) {
2061 logmsg "RUN: SOCKS server cannot find $sshconfig\n";
2062 $doesntrun{$pidfile} = 1;
2066 $sshlog = server_logfilename($LOGDIR, 'socks', $ipvnum, $idnum);
2068 # start our socks server
2069 my $cmd="\"$ssh\" -N -F $sshconfig $ip > $sshlog 2>&1";
2070 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 30, 1); # fake pidfile
2072 if($sshpid <= 0 || !pidexists($sshpid)) {
2074 logmsg "RUN: failed to start the $srvrname server\n";
2076 display_sshconfig();
2078 display_sshdconfig();
2079 stopserver($server, "$pid2");
2080 $doesntrun{$pidfile} = 1;
2084 # Ugly hack but ssh doesn't support pid files. PID is from fake pidfile.
2085 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2087 logmsg "RUN: $srvrname server failed verification\n";
2088 # failed to talk to it properly. Kill the server and return failure
2089 stopserver($server, "$sshpid $pid2");
2090 $doesntrun{$pidfile} = 1;
2096 logmsg "RUN: $srvrname server is now running PID $pid2\n";
2099 return ($pid2, $sshpid);
2102 #######################################################################
2103 # Single shot http and gopher server responsiveness test. This should only
2104 # be used to verify that a server present in %run hash is still functional
2106 sub responsive_http_server {
2107 my ($proto, $verbose, $alt, $port_or_path) = @_;
2112 if($alt eq "ipv6") {
2113 # if IPv6, use a different setup
2117 elsif($alt eq "proxy") {
2120 elsif($alt eq "unix") {
2121 # IP (protocol) is mutually exclusive with Unix sockets
2125 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port_or_path);
2128 #######################################################################
2129 # Single shot pingpong server responsiveness test. This should only be
2130 # used to verify that a server present in %run hash is still functional
2132 sub responsive_pingpong_server {
2133 my ($proto, $id, $verbose, $ipv6) = @_;
2135 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2136 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2137 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2139 if($proto eq "ftp") {
2140 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
2143 # if IPv6, use a different setup
2147 elsif($proto eq "pop3") {
2148 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
2150 elsif($proto eq "imap") {
2151 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
2153 elsif($proto eq "smtp") {
2154 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
2157 print STDERR "Unsupported protocol $proto!!\n";
2161 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2164 #######################################################################
2165 # Single shot rtsp server responsiveness test. This should only be
2166 # used to verify that a server present in %run hash is still functional
2168 sub responsive_rtsp_server {
2169 my ($verbose, $ipv6) = @_;
2170 my $port = $RTSPPORT;
2177 # if IPv6, use a different setup
2183 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2186 #######################################################################
2187 # Single shot tftp server responsiveness test. This should only be
2188 # used to verify that a server present in %run hash is still functional
2190 sub responsive_tftp_server {
2191 my ($id, $verbose, $ipv6) = @_;
2192 my $port = $TFTPPORT;
2196 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2199 # if IPv6, use a different setup
2205 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2208 #######################################################################
2209 # Single shot non-stunnel HTTP TLS extensions capable server
2210 # responsiveness test. This should only be used to verify that a
2211 # server present in %run hash is still functional
2213 sub responsive_httptls_server {
2214 my ($verbose, $ipv6) = @_;
2215 my $proto = "httptls";
2216 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
2217 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2218 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2221 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2224 #######################################################################
2225 # Remove all files in the specified directory
2233 opendir(DIR, $dir) ||
2234 return 0; # can't open dir
2235 while($file = readdir(DIR)) {
2236 if($file !~ /^\./) {
2237 unlink("$dir/$file");
2245 #######################################################################
2246 # compare test results with the expected output, we might filter off
2247 # some pattern that is allowed to differ, output test results
2250 my ($testnum, $testname, $subject, $firstref, $secondref)=@_;
2252 my $result = compareparts($firstref, $secondref);
2255 # timestamp test result verification end
2256 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
2259 logmsg "\n $testnum: $subject FAILED:\n";
2260 logmsg showdiff($LOGDIR, $firstref, $secondref);
2262 elsif(!$automakestyle) {
2267 logmsg "FAIL: $testnum - $testname - $subject\n";
2273 #######################################################################
2274 # display information about curl and the host the test suite runs on
2278 unlink($memdump); # remove this if there was one left
2287 my $curlverout="$LOGDIR/curlverout.log";
2288 my $curlvererr="$LOGDIR/curlvererr.log";
2289 my $versioncmd="$CURL --version 1>$curlverout 2>$curlvererr";
2291 unlink($curlverout);
2292 unlink($curlvererr);
2294 $versretval = runclient($versioncmd);
2297 open(VERSOUT, "<$curlverout");
2298 @version = <VERSOUT>;
2307 $curl =~ s/^(.*)(libcurl.*)/$1/g;
2310 if($curl =~ /mingw32/) {
2311 # This is a windows minw32 build, we need to translate the
2312 # given path to the "actual" windows path. The MSYS shell
2313 # has a builtin 'pwd -W' command which converts the path.
2314 $pwd = `sh -c "echo \$(pwd -W)"`;
2317 elsif ($curl =~ /win32/) {
2318 # Native Windows builds don't understand the
2319 # output of cygwin's pwd. It will be
2320 # something like /cygdrive/c/<some path>.
2322 # Use the cygpath utility to convert the
2323 # working directory to a Windows friendly
2324 # path. The -m option converts to use drive
2325 # letter:, but it uses / instead \. Forward
2326 # slashes (/) are easier for us. We don't
2327 # have to escape them to get them to curl
2329 chomp($pwd = `cygpath -m $pwd`);
2331 if ($libcurl =~ /winssl/i) {
2335 elsif ($libcurl =~ /openssl/i) {
2340 elsif ($libcurl =~ /gnutls/i) {
2345 elsif ($libcurl =~ /nss/i) {
2349 elsif ($libcurl =~ /yassl/i) {
2353 elsif ($libcurl =~ /polarssl/i) {
2357 elsif ($libcurl =~ /axtls/i) {
2361 elsif ($libcurl =~ /securetransport/i) {
2363 $ssllib="DarwinSSL";
2365 if ($libcurl =~ /ares/i) {
2370 elsif($_ =~ /^Protocols: (.*)/i) {
2371 # these are the protocols compiled in to this libcurl
2372 @protocols = split(' ', lc($1));
2374 # Generate a "proto-ipv6" version of each protocol to match the
2375 # IPv6 <server> name and a "proto-unix" to match the variant which
2376 # uses Unix domain sockets. This works even if support isn't
2377 # compiled in because the <features> test will fail.
2378 push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);
2380 # 'http-proxy' is used in test cases to do CONNECT through
2381 push @protocols, 'http-proxy';
2383 # 'http-pipe' is the special server for testing pipelining
2384 push @protocols, 'http-pipe';
2386 # 'none' is used in test cases to mean no server
2387 push @protocols, 'none';
2389 elsif($_ =~ /^Features: (.*)/i) {
2391 if($feat =~ /TrackMemory/i) {
2392 # built with memory tracking support (--enable-curldebug)
2393 $has_memory_tracking = 1;
2395 if($feat =~ /debug/i) {
2396 # curl was built with --enable-debug
2399 if($feat =~ /SSL/i) {
2403 if($feat =~ /Largefile/i) {
2404 # large file support
2407 if($feat =~ /IDN/i) {
2411 if($feat =~ /IPv6/i) {
2414 if($feat =~ /UnixSockets/i) {
2417 if($feat =~ /libz/i) {
2420 if($feat =~ /NTLM/i) {
2424 # Use this as a proxy for any cryptographic authentication
2427 if($feat =~ /NTLM_WB/i) {
2428 # NTLM delegation to winbind daemon ntlm_auth helper enabled
2431 if($feat =~ /SSPI/i) {
2435 if($feat =~ /GSS-API/i) {
2439 if($feat =~ /Kerberos/i) {
2443 # Use this as a proxy for any cryptographic authentication
2446 if($feat =~ /SPNEGO/i) {
2450 # Use this as a proxy for any cryptographic authentication
2453 if($feat =~ /CharConv/i) {
2457 if($feat =~ /TLS-SRP/i) {
2461 if($feat =~ /Metalink/i) {
2465 if($feat =~ /AsynchDNS/i) {
2467 # this means threaded resolver
2469 $resolver="threaded";
2472 if($feat =~ /HTTP2/) {
2478 # Test harness currently uses a non-stunnel server in order to
2479 # run HTTP TLS-SRP tests required when curl is built with https
2480 # protocol support and TLS-SRP feature enabled. For convenience
2481 # 'httptls' may be included in the test harness protocols array
2482 # to differentiate this from classic stunnel based 'https' test
2488 if($_ =~ /^https(-ipv6|)$/) {
2493 if($add_httptls && (! grep /^httptls$/, @protocols)) {
2494 push @protocols, 'httptls';
2495 push @protocols, 'httptls-ipv6';
2500 logmsg "unable to get curl's version, further details are:\n";
2501 logmsg "issued command: \n";
2502 logmsg "$versioncmd \n";
2503 if ($versretval == -1) {
2504 logmsg "command failed with: \n";
2505 logmsg "$versnoexec \n";
2507 elsif ($versretval & 127) {
2508 logmsg sprintf("command died with signal %d, and %s coredump.\n",
2509 ($versretval & 127), ($versretval & 128)?"a":"no");
2512 logmsg sprintf("command exited with value %d \n", $versretval >> 8);
2514 logmsg "contents of $curlverout: \n";
2515 displaylogcontent("$curlverout");
2516 logmsg "contents of $curlvererr: \n";
2517 displaylogcontent("$curlvererr");
2518 die "couldn't get curl's version";
2521 if(-r "../lib/curl_config.h") {
2522 open(CONF, "<../lib/curl_config.h");
2524 if($_ =~ /^\#define HAVE_GETRLIMIT/) {
2532 # client has IPv6 support
2534 # check if the HTTP server has it!
2535 my @sws = `server/sws --version`;
2536 if($sws[0] =~ /IPv6/) {
2537 # HTTP server has IPv6 support!
2542 # check if the FTP server has it!
2543 @sws = `server/sockfilt --version`;
2544 if($sws[0] =~ /IPv6/) {
2545 # FTP server has IPv6 support!
2551 # client has Unix sockets support, check whether the HTTP server has it
2552 my @sws = `server/sws --version`;
2553 $http_unix = 1 if($sws[0] =~ /unix/);
2556 if(!$has_memory_tracking && $torture) {
2557 die "can't run torture tests since curl was built without ".
2558 "TrackMemory feature (--enable-curldebug)";
2561 $has_shared = `sh $CURLCONFIG --built-shared`;
2564 my $hostname=join(' ', runclientoutput("hostname"));
2565 my $hosttype=join(' ', runclientoutput("uname -a"));
2567 logmsg ("********* System characteristics ******** \n",
2570 "* Features: $feat\n",
2571 "* Host: $hostname",
2572 "* System: $hosttype");
2574 if($has_memory_tracking && $has_threadedres) {
2575 $has_memory_tracking = 0;
2577 "*** DISABLES memory tracking when using threaded resolver\n",
2581 logmsg sprintf("* Server SSL: %8s", $stunnel?"ON ":"OFF");
2582 logmsg sprintf(" libcurl SSL: %s\n", $ssl_version?"ON ":"OFF");
2583 logmsg sprintf("* debug build: %8s", $debug_build?"ON ":"OFF");
2584 logmsg sprintf(" track memory: %s\n", $has_memory_tracking?"ON ":"OFF");
2585 logmsg sprintf("* valgrind: %8s", $valgrind?"ON ":"OFF");
2586 logmsg sprintf(" HTTP IPv6 %s\n", $http_ipv6?"ON ":"OFF");
2587 logmsg sprintf("* HTTP Unix %s\n", $http_unix?"ON ":"OFF");
2588 logmsg sprintf("* FTP IPv6 %8s", $ftp_ipv6?"ON ":"OFF");
2589 logmsg sprintf(" Libtool lib: %s\n", $libtool?"ON ":"OFF");
2590 logmsg sprintf("* Shared build: %-3s", $has_shared);
2591 logmsg sprintf(" Resolver: %s\n", $resolver);
2593 logmsg sprintf("* SSL library: %13s\n", $ssllib);
2596 logmsg "* Ports:\n";
2598 logmsg sprintf("* HTTP/%d ", $HTTPPORT);
2599 logmsg sprintf("FTP/%d ", $FTPPORT);
2600 logmsg sprintf("FTP2/%d ", $FTP2PORT);
2601 logmsg sprintf("RTSP/%d ", $RTSPPORT);
2603 logmsg sprintf("FTPS/%d ", $FTPSPORT);
2604 logmsg sprintf("HTTPS/%d ", $HTTPSPORT);
2606 logmsg sprintf("\n* TFTP/%d ", $TFTPPORT);
2608 logmsg sprintf("HTTP-IPv6/%d ", $HTTP6PORT);
2609 logmsg sprintf("RTSP-IPv6/%d ", $RTSP6PORT);
2612 logmsg sprintf("FTP-IPv6/%d ", $FTP6PORT);
2615 logmsg sprintf("TFTP-IPv6/%d ", $TFTP6PORT);
2617 logmsg sprintf("\n* GOPHER/%d ", $GOPHERPORT);
2619 logmsg sprintf("GOPHER-IPv6/%d", $GOPHERPORT);
2621 logmsg sprintf("\n* SSH/%d ", $SSHPORT);
2622 logmsg sprintf("SOCKS/%d ", $SOCKSPORT);
2623 logmsg sprintf("POP3/%d ", $POP3PORT);
2624 logmsg sprintf("IMAP/%d ", $IMAPPORT);
2625 logmsg sprintf("SMTP/%d\n", $SMTPPORT);
2627 logmsg sprintf("* POP3-IPv6/%d ", $POP36PORT);
2628 logmsg sprintf("IMAP-IPv6/%d ", $IMAP6PORT);
2629 logmsg sprintf("SMTP-IPv6/%d\n", $SMTP6PORT);
2632 logmsg sprintf("* HTTPTLS/%d ", $HTTPTLSPORT);
2634 logmsg sprintf("HTTPTLS-IPv6/%d ", $HTTPTLS6PORT);
2638 logmsg sprintf("* HTTP-PIPE/%d \n", $HTTPPIPEPORT);
2641 logmsg "* Unix socket paths:\n";
2643 logmsg sprintf("* HTTP-Unix:%s\n", $HTTPUNIXPATH);
2647 $has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
2649 logmsg "***************************************** \n";
2652 #######################################################################
2653 # substitute the variable stuff into either a joined up file or
2654 # a command, in either case passed by reference
2661 $$thing =~ s/%FTP6PORT/$FTP6PORT/g;
2662 $$thing =~ s/%FTP2PORT/$FTP2PORT/g;
2663 $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
2664 $$thing =~ s/%FTPPORT/$FTPPORT/g;
2666 $$thing =~ s/%GOPHER6PORT/$GOPHER6PORT/g;
2667 $$thing =~ s/%GOPHERPORT/$GOPHERPORT/g;
2669 $$thing =~ s/%HTTPTLS6PORT/$HTTPTLS6PORT/g;
2670 $$thing =~ s/%HTTPTLSPORT/$HTTPTLSPORT/g;
2671 $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
2672 $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
2673 $$thing =~ s/%HTTPPORT/$HTTPPORT/g;
2674 $$thing =~ s/%HTTPPIPEPORT/$HTTPPIPEPORT/g;
2675 $$thing =~ s/%PROXYPORT/$HTTPPROXYPORT/g;
2677 $$thing =~ s/%IMAP6PORT/$IMAP6PORT/g;
2678 $$thing =~ s/%IMAPPORT/$IMAPPORT/g;
2680 $$thing =~ s/%POP36PORT/$POP36PORT/g;
2681 $$thing =~ s/%POP3PORT/$POP3PORT/g;
2683 $$thing =~ s/%RTSP6PORT/$RTSP6PORT/g;
2684 $$thing =~ s/%RTSPPORT/$RTSPPORT/g;
2686 $$thing =~ s/%SMTP6PORT/$SMTP6PORT/g;
2687 $$thing =~ s/%SMTPPORT/$SMTPPORT/g;
2689 $$thing =~ s/%SOCKSPORT/$SOCKSPORT/g;
2690 $$thing =~ s/%SSHPORT/$SSHPORT/g;
2692 $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
2693 $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
2695 # server Unix domain socket paths
2697 $$thing =~ s/%HTTPUNIXPATH/$HTTPUNIXPATH/g;
2699 # client IP addresses
2701 $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
2702 $$thing =~ s/%CLIENTIP/$CLIENTIP/g;
2704 # server IP addresses
2706 $$thing =~ s/%HOST6IP/$HOST6IP/g;
2707 $$thing =~ s/%HOSTIP/$HOSTIP/g;
2711 $$thing =~ s/%CURL/$CURL/g;
2712 $$thing =~ s/%PWD/$pwd/g;
2713 $$thing =~ s/%SRCDIR/$srcdir/g;
2714 $$thing =~ s/%USER/$USER/g;
2716 # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
2717 # used for time-out tests and that whould work on most hosts as these
2718 # adjust for the startup/check time for this particular host. We needed
2719 # to do this to make the test suite run better on very slow hosts.
2721 my $ftp2 = $ftpchecktime * 2;
2722 my $ftp3 = $ftpchecktime * 3;
2724 $$thing =~ s/%FTPTIME2/$ftp2/g;
2725 $$thing =~ s/%FTPTIME3/$ftp3/g;
2729 $$thing =~ s/%H2CVER/$h2cver/g;
2741 #######################################################################
2742 # Provide time stamps for single test skipped events
2744 sub timestampskippedevents {
2745 my $testnum = $_[0];
2747 return if((not defined($testnum)) || ($testnum < 1));
2751 if($timevrfyend{$testnum}) {
2754 elsif($timesrvrlog{$testnum}) {
2755 $timevrfyend{$testnum} = $timesrvrlog{$testnum};
2758 elsif($timetoolend{$testnum}) {
2759 $timevrfyend{$testnum} = $timetoolend{$testnum};
2760 $timesrvrlog{$testnum} = $timetoolend{$testnum};
2762 elsif($timetoolini{$testnum}) {
2763 $timevrfyend{$testnum} = $timetoolini{$testnum};
2764 $timesrvrlog{$testnum} = $timetoolini{$testnum};
2765 $timetoolend{$testnum} = $timetoolini{$testnum};
2767 elsif($timesrvrend{$testnum}) {
2768 $timevrfyend{$testnum} = $timesrvrend{$testnum};
2769 $timesrvrlog{$testnum} = $timesrvrend{$testnum};
2770 $timetoolend{$testnum} = $timesrvrend{$testnum};
2771 $timetoolini{$testnum} = $timesrvrend{$testnum};
2773 elsif($timesrvrini{$testnum}) {
2774 $timevrfyend{$testnum} = $timesrvrini{$testnum};
2775 $timesrvrlog{$testnum} = $timesrvrini{$testnum};
2776 $timetoolend{$testnum} = $timesrvrini{$testnum};
2777 $timetoolini{$testnum} = $timesrvrini{$testnum};
2778 $timesrvrend{$testnum} = $timesrvrini{$testnum};
2780 elsif($timeprepini{$testnum}) {
2781 $timevrfyend{$testnum} = $timeprepini{$testnum};
2782 $timesrvrlog{$testnum} = $timeprepini{$testnum};
2783 $timetoolend{$testnum} = $timeprepini{$testnum};
2784 $timetoolini{$testnum} = $timeprepini{$testnum};
2785 $timesrvrend{$testnum} = $timeprepini{$testnum};
2786 $timesrvrini{$testnum} = $timeprepini{$testnum};
2791 #######################################################################
2792 # Run a single specified test case
2795 my ($evbased, # 1 means switch on if possible (and "curl" is tested)
2796 # returns "not a test" if it can't be used for this test
2805 my $disablevalgrind;
2807 # copy test number to a global scope var, this allows
2808 # testnum checking when starting test harness servers.
2809 $testnumcheck = $testnum;
2811 # timestamp test preparation start
2812 $timeprepini{$testnum} = Time::HiRes::time() if($timestats);
2814 if($disttests !~ /test$testnum\W/ ) {
2815 logmsg "Warning: test$testnum not present in tests/data/Makefile.inc\n";
2817 if($disabled{$testnum}) {
2818 logmsg "Warning: test$testnum is explicitly disabled\n";
2821 # load the test case file definition
2822 if(loadtest("${TESTDIR}/test${testnum}")) {
2824 # this is not a test
2825 logmsg "RUN: $testnum doesn't look like a test case\n";
2830 @what = getpart("client", "features");
2833 # We require a feature to be present
2838 if($f =~ /^([^!].*)$/) {
2839 # Store the feature for later
2847 elsif($1 eq "SSLpinning") {
2848 if($has_sslpinning) {
2852 elsif($1 eq "OpenSSL") {
2857 elsif($1 eq "GnuTLS") {
2862 elsif($1 eq "NSS") {
2867 elsif($1 eq "axTLS") {
2872 elsif($1 eq "WinSSL") {
2877 elsif($1 eq "DarwinSSL") {
2878 if($has_darwinssl) {
2882 elsif($1 eq "unittest") {
2887 elsif($1 eq "debug") {
2892 elsif($1 eq "TrackMemory") {
2893 if($has_memory_tracking) {
2897 elsif($1 eq "large_file") {
2902 elsif($1 eq "idn") {
2907 elsif($1 eq "ipv6") {
2912 elsif($1 eq "libz") {
2917 elsif($1 eq "NTLM") {
2922 elsif($1 eq "NTLM_WB") {
2927 elsif($1 eq "SSPI") {
2932 elsif($1 eq "GSS-API") {
2937 elsif($1 eq "Kerberos") {
2942 elsif($1 eq "SPNEGO") {
2947 elsif($1 eq "getrlimit") {
2948 if($has_getrlimit) {
2952 elsif($1 eq "crypto") {
2957 elsif($1 eq "TLS-SRP") {
2962 elsif($1 eq "Metalink") {
2967 elsif($1 eq "http2") {
2972 elsif($1 eq "socks") {
2975 elsif($1 eq "unix-sockets") {
2978 # See if this "feature" is in the list of supported protocols
2979 elsif (grep /^\Q$1\E$/i, @protocols) {
2983 $why = "curl lacks $1 support";
2988 # We require a feature to not be present
2994 if($f =~ /^!(.*)$/) {
3000 elsif($1 eq "OpenSSL") {
3005 elsif($1 eq "GnuTLS") {
3010 elsif($1 eq "NSS") {
3015 elsif($1 eq "axTLS") {
3020 elsif($1 eq "WinSSL") {
3025 elsif($1 eq "DarwinSSL") {
3026 if(!$has_darwinssl) {
3030 elsif($1 eq "TrackMemory") {
3031 if(!$has_memory_tracking) {
3035 elsif($1 eq "large_file") {
3040 elsif($1 eq "idn") {
3045 elsif($1 eq "ipv6") {
3050 elsif($1 eq "unix-sockets") {
3053 elsif($1 eq "libz") {
3058 elsif($1 eq "NTLM") {
3063 elsif($1 eq "NTLM_WB") {
3068 elsif($1 eq "SSPI") {
3073 elsif($1 eq "GSS-API") {
3078 elsif($1 eq "Kerberos") {
3079 if(!$has_kerberos) {
3083 elsif($1 eq "SPNEGO") {
3088 elsif($1 eq "getrlimit") {
3089 if(!$has_getrlimit) {
3093 elsif($1 eq "crypto") {
3098 elsif($1 eq "TLS-SRP") {
3103 elsif($1 eq "Metalink") {
3104 if(!$has_metalink) {
3116 $why = "curl has $1 support";
3122 my @keywords = getpart("info", "keywords");
3127 $why = "missing the <keywords> section!";
3130 for $k (@keywords) {
3132 if ($disabled_keywords{$k}) {
3133 $why = "disabled by keyword";
3134 } elsif ($enabled_keywords{$k}) {
3139 if(!$why && !$match && %enabled_keywords) {
3140 $why = "disabled by missing keyword";
3144 # test definition may instruct to (un)set environment vars
3145 # this is done this early, so that the precheck can use environment
3146 # variables and still bail out fine on errors
3148 # restore environment variables that were modified in a previous run
3149 foreach my $var (keys %oldenv) {
3150 if($oldenv{$var} eq 'notset') {
3151 delete $ENV{$var} if($ENV{$var});
3154 $ENV{$var} = $oldenv{$var};
3156 delete $oldenv{$var};
3159 # remove test server commands file before servers are started/verified
3160 unlink($FTPDCMD) if(-f $FTPDCMD);
3162 # timestamp required servers verification start
3163 $timesrvrini{$testnum} = Time::HiRes::time() if($timestats);
3166 $why = serverfortest($testnum);
3169 # timestamp required servers verification end
3170 $timesrvrend{$testnum} = Time::HiRes::time() if($timestats);
3172 my @setenv = getpart("client", "setenv");
3174 foreach my $s (@setenv) {
3177 if($s =~ /([^=]*)=(.*)/) {
3178 my ($var, $content) = ($1, $2);
3179 # remember current setting, to restore it once test runs
3180 $oldenv{$var} = ($ENV{$var})?"$ENV{$var}":'notset';
3183 delete $ENV{$var} if($ENV{$var});
3186 if($var =~ /^LD_PRELOAD/) {
3187 if(exe_ext() && (exe_ext() eq '.exe')) {
3188 # print "Skipping LD_PRELOAD due to lack of OS support\n";
3191 if($debug_build || ($has_shared ne "yes")) {
3192 # print "Skipping LD_PRELOAD due to no release shared build\n";
3196 $ENV{$var} = "$content";
3204 # Add a precheck cache. If a precheck command was already invoked
3205 # exactly like this, then use the previous result to speed up
3206 # successive test invokes!
3208 my @precheck = getpart("client", "precheck");
3210 $cmd = $precheck[0];
3214 my @p = split(/ /, $cmd);
3216 # the first word, the command, does not contain a slash so
3217 # we will scan the "improved" PATH to find the command to
3219 my $fullp = checktestcmd($p[0]);
3224 $cmd = join(" ", @p);
3227 my @o = `$cmd 2>/dev/null`;
3232 $why = "precheck command error";
3234 logmsg "prechecked $cmd\n" if($verbose);
3239 if($why && !$listonly) {
3240 # there's a problem, count it as "skipped"
3243 $teststat[$testnum]=$why; # store reason for this test case
3246 if($skipped{$why} <= 3) {
3247 # show only the first three skips for each reason
3248 logmsg sprintf("test %04d SKIPPED: $why\n", $testnum);
3252 timestampskippedevents($testnum);
3255 logmsg sprintf("test %04d...", $testnum) if(!$automakestyle);
3257 # extract the reply data
3258 my @reply = getpart("reply", "data");
3259 my @replycheck = getpart("reply", "datacheck");
3261 my %replyattr = getpartattr("reply", "data");
3262 my %replycheckattr = getpartattr("reply", "datacheck");
3265 # we use this file instead to check the final output against
3267 if($replycheckattr{'nonewline'}) {
3268 # Yes, we must cut off the final newline from the final line
3270 chomp($replycheck[$#replycheck]);
3272 if($replycheckattr{'mode'}) {
3273 $replyattr{'mode'} = $replycheckattr{'mode'};
3279 # this is the valid protocol blurb curl should generate
3280 my @protocol= fixarray ( getpart("verify", "protocol") );
3282 # this is the valid protocol blurb curl should generate to a proxy
3283 my @proxyprot = fixarray ( getpart("verify", "proxy") );
3285 # redirected stdout/stderr to these files
3286 $STDOUT="$LOGDIR/stdout$testnum";
3287 $STDERR="$LOGDIR/stderr$testnum";
3289 # if this section exists, we verify that the stdout contained this:
3290 my @validstdout = fixarray ( getpart("verify", "stdout") );
3292 # if this section exists, we verify upload
3293 my @upload = getpart("verify", "upload");
3295 # if this section exists, it might be FTP server instructions:
3296 my @ftpservercmd = getpart("reply", "servercmd");
3298 my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
3301 my @testname= getpart("client", "name");
3302 my $testname = $testname[0];
3303 $testname =~ s/\n//g;
3304 logmsg "[$testname]\n" if(!$short);
3307 timestampskippedevents($testnum);
3308 return 0; # look successful
3311 my @codepieces = getpart("client", "tool");
3315 $tool = $codepieces[0];
3319 # remove server output logfile
3325 # write the instructions to file
3326 writearray($FTPDCMD, \@ftpservercmd);
3329 # get the command line options to use
3331 ($cmd, @blaha)= getpart("client", "command");
3334 # make some nice replace operations
3335 $cmd =~ s/\n//g; # no newlines please
3336 # substitute variables in the command line
3340 # there was no command given, use something silly
3343 if($has_memory_tracking) {
3347 # create a (possibly-empty) file before starting the test
3348 my @inputfile=getpart("client", "file");
3349 my %fileattr = getpartattr("client", "file");
3350 my $filename=$fileattr{'name'};
3351 if(@inputfile || $filename) {
3353 logmsg "ERROR: section client=>file has no name attribute\n";
3354 timestampskippedevents($testnum);
3357 my $fileContent = join('', @inputfile);
3358 subVariables \$fileContent;
3359 # logmsg "DEBUG: writing file " . $filename . "\n";
3360 open(OUTFILE, ">$filename");
3361 binmode OUTFILE; # for crapage systems, use binary
3362 print OUTFILE $fileContent;
3366 my %cmdhash = getpartattr("client", "command");
3370 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-output/)) {
3371 #We may slap on --output!
3372 if (!@validstdout) {
3373 $out=" --output $CURLOUT ";
3377 my $serverlogslocktimeout = $defserverlogslocktimeout;
3378 if($cmdhash{'timeout'}) {
3379 # test is allowed to override default server logs lock timeout
3380 if($cmdhash{'timeout'} =~ /(\d+)/) {
3381 $serverlogslocktimeout = $1 if($1 >= 0);
3385 my $postcommanddelay = $defpostcommanddelay;
3386 if($cmdhash{'delay'}) {
3387 # test is allowed to specify a delay after command is executed
3388 if($cmdhash{'delay'} =~ /(\d+)/) {
3389 $postcommanddelay = $1 if($1 > 0);
3395 my $cmdtype = $cmdhash{'type'} || "default";
3396 my $fail_due_event_based = $evbased;
3397 if($cmdtype eq "perl") {
3398 # run the command line prepended with "perl"
3404 elsif($cmdtype eq "shell") {
3405 # run the command line prepended with "/bin/sh"
3407 $CMDLINE = "/bin/sh ";
3412 # run curl, add suitable command line options
3413 $cmd = "-1 ".$cmd if(exists $feature{"SSL"} && ($has_axtls));
3416 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-include/)) {
3417 $inc = " --include";
3420 $cmdargs = "$out$inc ";
3421 $cmdargs .= "--trace-ascii log/trace$testnum ";
3422 $cmdargs .= "--trace-time ";
3424 $cmdargs .= "--test-event ";
3425 $fail_due_event_based--;
3430 $cmdargs = " $cmd"; # $cmd is the command line for the test file
3431 $CURLOUT = $STDOUT; # sends received data to stdout
3433 if($tool =~ /^lib/) {
3434 $CMDLINE="$LIBDIR/$tool";
3436 elsif($tool =~ /^unit/) {
3437 $CMDLINE="$UNITDIR/$tool";
3441 logmsg "The tool set in the test case for this: '$tool' does not exist\n";
3442 timestampskippedevents($testnum);
3449 # gdb is incompatible with valgrind, so disable it when debugging
3450 # Perhaps a better approach would be to run it under valgrind anyway
3451 # with --db-attach=yes or --vgdb=yes.
3455 if($fail_due_event_based) {
3456 logmsg "This test cannot run event based\n";
3460 my @stdintest = getpart("client", "stdin");
3463 my $stdinfile="$LOGDIR/stdin-for-$testnum";
3465 my %hash = getpartattr("client", "stdin");
3466 if($hash{'nonewline'}) {
3467 # cut off the final newline from the final line of the stdin data
3468 chomp($stdintest[$#stdintest]);
3471 writearray($stdinfile, \@stdintest);
3473 $cmdargs .= " <$stdinfile";
3481 if($valgrind && !$disablevalgrind) {
3482 my @valgrindoption = getpart("verify", "valgrind");
3483 if((!@valgrindoption) || ($valgrindoption[0] !~ /disable/)) {
3485 my $valgrindcmd = "$valgrind ";
3486 $valgrindcmd .= "$valgrind_tool " if($valgrind_tool);
3487 $valgrindcmd .= "--leak-check=yes ";
3488 $valgrindcmd .= "--suppressions=$srcdir/valgrind.supp ";
3489 # $valgrindcmd .= "--gen-suppressions=all ";
3490 $valgrindcmd .= "--num-callers=16 ";
3491 $valgrindcmd .= "${valgrind_logfile}=$LOGDIR/valgrind$testnum";
3492 $CMDLINE = "$valgrindcmd $CMDLINE";
3496 $CMDLINE .= "$cmdargs >$STDOUT 2>$STDERR";
3499 logmsg "$CMDLINE\n";
3502 print CMDLOG "$CMDLINE\n";
3509 # Apr 2007: precommand isn't being used and could be removed
3510 my @precommand= getpart("client", "precommand");
3511 if($precommand[0]) {
3512 # this is pure perl to eval!
3513 my $code = join("", @precommand);
3516 logmsg "perl: $code\n";
3517 logmsg "precommand: $@";
3518 stopservers($verbose);
3519 timestampskippedevents($testnum);
3525 my $gdbinit = "$TESTDIR/gdbinit$testnum";
3526 open(GDBCMD, ">$LOGDIR/gdbcmd");
3527 print GDBCMD "set args $cmdargs\n";
3528 print GDBCMD "show args\n";
3529 print GDBCMD "source $gdbinit\n" if -e $gdbinit;
3533 # timestamp starting of test command
3534 $timetoolini{$testnum} = Time::HiRes::time() if($timestats);
3536 # run the command line we built
3538 $cmdres = torture($CMDLINE,
3539 "$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
3542 my $GDBW = ($gdbxwin) ? "-w" : "";
3543 runclient("$gdb --directory libtest $DBGCURL $GDBW -x $LOGDIR/gdbcmd");
3544 $cmdres=0; # makes it always continue after a debugged run
3547 $cmdres = runclient("$CMDLINE");
3548 my $signal_num = $cmdres & 127;
3549 $dumped_core = $cmdres & 128;
3551 if(!$anyway && ($signal_num || $dumped_core)) {
3556 $cmdres = (2000 + $signal_num) if($signal_num && !$cmdres);
3560 # timestamp finishing of test command
3561 $timetoolend{$testnum} = Time::HiRes::time() if($timestats);
3565 # there's core file present now!
3571 logmsg "core dumped\n";
3573 logmsg "running gdb for post-mortem analysis:\n";
3574 open(GDBCMD, ">$LOGDIR/gdbcmd2");
3575 print GDBCMD "bt\n";
3577 runclient("$gdb --directory libtest -x $LOGDIR/gdbcmd2 -batch $DBGCURL core ");
3578 # unlink("$LOGDIR/gdbcmd2");
3582 # If a server logs advisor read lock file exists, it is an indication
3583 # that the server has not yet finished writing out all its log files,
3584 # including server request log files used for protocol verification.
3585 # So, if the lock file exists the script waits here a certain amount
3586 # of time until the server removes it, or the given time expires.
3588 if($serverlogslocktimeout) {
3589 my $lockretry = $serverlogslocktimeout * 20;
3590 while((-f $SERVERLOGS_LOCK) && $lockretry--) {
3591 select(undef, undef, undef, 0.05);
3593 if(($lockretry < 0) &&
3594 ($serverlogslocktimeout >= $defserverlogslocktimeout)) {
3595 logmsg "Warning: server logs lock timeout ",
3596 "($serverlogslocktimeout seconds) expired\n";
3600 # Test harness ssh server does not have this synchronization mechanism,
3601 # this implies that some ssh server based tests might need a small delay
3602 # once that the client command has run to avoid false test failures.
3604 # gnutls-serv also lacks this synchronization mechanism, so gnutls-serv
3605 # based tests might need a small delay once that the client command has
3606 # run to avoid false test failures.
3608 sleep($postcommanddelay) if($postcommanddelay);
3610 # timestamp removal of server logs advisor read lock
3611 $timesrvrlog{$testnum} = Time::HiRes::time() if($timestats);
3613 # test definition might instruct to stop some servers
3614 # stop also all servers relative to the given one
3616 my @killtestservers = getpart("client", "killserver");
3617 if(@killtestservers) {
3619 # All servers relative to the given one must be stopped also
3622 foreach my $server (@killtestservers) {
3624 if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
3625 # given a stunnel ssl server, also kill non-ssl underlying one
3626 push @killservers, "${1}${2}";
3628 elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|-unix|))$/) {
3629 # given a non-ssl server, also kill stunnel piggybacking one
3630 push @killservers, "${1}s${2}";
3632 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
3633 # given a socks server, also kill ssh underlying one
3634 push @killservers, "ssh${2}";
3636 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
3637 # given a ssh server, also kill socks piggybacking one
3638 push @killservers, "socks${2}";
3640 push @killservers, $server;
3643 # kill sockfilter processes for pingpong relative servers
3645 foreach my $server (@killservers) {
3646 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
3648 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
3649 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
3650 killsockfilters($proto, $ipvnum, $idnum, $verbose);
3654 # kill server relative pids clearing them in %run hash
3657 foreach my $server (@killservers) {
3659 $pidlist .= "$run{$server} ";
3662 $runcert{$server} = 0 if($runcert{$server});
3664 killpid($verbose, $pidlist);
3666 # cleanup server pid files
3668 foreach my $server (@killservers) {
3669 my $pidfile = $serverpidfile{$server};
3670 my $pid = processexists($pidfile);
3672 logmsg "Warning: $server server unexpectedly alive\n";
3673 killpid($verbose, $pid);
3675 unlink($pidfile) if(-f $pidfile);
3679 # remove the test server commands file after each test
3680 unlink($FTPDCMD) if(-f $FTPDCMD);
3682 # run the postcheck command
3683 my @postcheck= getpart("client", "postcheck");
3685 $cmd = $postcheck[0];
3689 logmsg "postcheck $cmd\n" if($verbose);
3690 my $rc = runclient("$cmd");
3691 # Must run the postcheck command in torture mode in order
3692 # to clean up, but the result can't be relied upon.
3693 if($rc != 0 && !$torture) {
3694 logmsg " postcheck FAILED\n";
3695 # timestamp test result verification end
3696 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3702 # restore environment variables that were modified
3704 foreach my $var (keys %oldenv) {
3705 if($oldenv{$var} eq 'notset') {
3706 delete $ENV{$var} if($ENV{$var});
3709 $ENV{$var} = "$oldenv{$var}";
3714 # Skip all the verification on torture tests
3716 if(!$cmdres && !$keepoutfiles) {
3719 # timestamp test result verification end
3720 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3724 my @err = getpart("verify", "errorcode");
3725 my $errorcode = $err[0] || "0";
3730 # verify redirected stdout
3731 my @actual = loadarray($STDOUT);
3733 # variable-replace in the stdout we have from the test case file
3734 @validstdout = fixarray(@validstdout);
3736 # get all attributes
3737 my %hash = getpartattr("verify", "stdout");
3739 # get the mode attribute
3740 my $filemode=$hash{'mode'};
3741 if($filemode && ($filemode eq "text") && $has_textaware) {
3742 # text mode when running on windows: fix line endings
3743 map s/\r\n/\n/g, @validstdout;
3744 map s/\n/\r\n/g, @validstdout;
3747 if($hash{'nonewline'}) {
3748 # Yes, we must cut off the final newline from the final line
3749 # of the protocol data
3750 chomp($validstdout[$#validstdout]);
3753 $res = compare($testnum, $testname, "stdout", \@actual, \@validstdout);
3760 $ok .= "-"; # stdout not checked
3764 # Verify the sent request
3765 my @out = loadarray($SERVERIN);
3767 # what to cut off from the live protocol sent by curl
3768 my @strip = getpart("verify", "strip");
3770 my @protstrip=@protocol;
3772 # check if there's any attributes on the verify/protocol section
3773 my %hash = getpartattr("verify", "protocol");
3775 if($hash{'nonewline'}) {
3776 # Yes, we must cut off the final newline from the final line
3777 # of the protocol data
3778 chomp($protstrip[$#protstrip]);
3782 # strip off all lines that match the patterns from both arrays
3784 @out = striparray( $_, \@out);
3785 @protstrip= striparray( $_, \@protstrip);
3788 # what parts to cut off from the protocol
3789 my @strippart = getpart("verify", "strippart");
3791 for $strip (@strippart) {
3798 $res = compare($testnum, $testname, "protocol", \@out, \@protstrip);
3807 $ok .= "-"; # protocol not checked
3810 if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
3811 # verify the received data
3812 my @out = loadarray($CURLOUT);
3813 # get the mode attribute
3814 my $filemode=$replyattr{'mode'};
3815 if($filemode && ($filemode eq "text") && $has_textaware) {
3816 # text mode when running on windows: fix line endings
3817 map s/\r\n/\n/g, @reply;
3818 map s/\n/\r\n/g, @reply;
3821 $res = compare($testnum, $testname, "data", \@out, \@reply);
3828 $ok .= "-"; # data not checked
3832 # verify uploaded data
3833 my @out = loadarray("$LOGDIR/upload.$testnum");
3834 $res = compare($testnum, $testname, "upload", \@out, \@upload);
3841 $ok .= "-"; # upload not checked
3845 # Verify the sent proxy request
3846 my @out = loadarray($PROXYIN);
3848 # what to cut off from the live protocol sent by curl, we use the
3849 # same rules as for <protocol>
3850 my @strip = getpart("verify", "strip");
3852 my @protstrip=@proxyprot;
3854 # check if there's any attributes on the verify/protocol section
3855 my %hash = getpartattr("verify", "proxy");
3857 if($hash{'nonewline'}) {
3858 # Yes, we must cut off the final newline from the final line
3859 # of the protocol data
3860 chomp($protstrip[$#protstrip]);
3864 # strip off all lines that match the patterns from both arrays
3866 @out = striparray( $_, \@out);
3867 @protstrip= striparray( $_, \@protstrip);
3870 # what parts to cut off from the protocol
3871 my @strippart = getpart("verify", "strippart");
3873 for $strip (@strippart) {
3880 $res = compare($testnum, $testname, "proxy", \@out, \@protstrip);
3889 $ok .= "-"; # protocol not checked
3893 for my $partsuffix (('', '1', '2', '3', '4')) {
3894 my @outfile=getpart("verify", "file".$partsuffix);
3895 if(@outfile || partexists("verify", "file".$partsuffix) ) {
3896 # we're supposed to verify a dynamically generated file!
3897 my %hash = getpartattr("verify", "file".$partsuffix);
3899 my $filename=$hash{'name'};
3901 logmsg "ERROR: section verify=>file$partsuffix ".
3902 "has no name attribute\n";
3903 stopservers($verbose);
3904 # timestamp test result verification end
3905 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3908 my @generated=loadarray($filename);
3910 # what parts to cut off from the file
3911 my @stripfile = getpart("verify", "stripfile".$partsuffix);
3913 my $filemode=$hash{'mode'};
3914 if($filemode && ($filemode eq "text") && $has_textaware) {
3915 # text mode when running on windows: fix line endings
3916 map s/\r\n/\n/g, @outfile;
3917 map s/\n/\r\n/g, @outfile;
3921 for $strip (@stripfile) {
3930 # this is to get rid of array entries that vanished (zero
3931 # length) because of replacements
3932 @generated = @newgen;
3935 @outfile = fixarray(@outfile);
3937 $res = compare($testnum, $testname, "output ($filename)",
3938 \@generated, \@outfile);
3943 $outputok = 1; # output checked
3946 $ok .= ($outputok) ? "o" : "-"; # output checked or not
3948 # accept multiple comma-separated error codes
3949 my @splerr = split(/ *, */, $errorcode);
3951 foreach my $e (@splerr) {
3964 logmsg sprintf("\n%s returned $cmdres, when expecting %s\n",
3965 (!$tool)?"curl":$tool, $errorcode);
3967 logmsg " exit FAILED\n";
3968 # timestamp test result verification end
3969 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
3973 if($has_memory_tracking) {
3975 logmsg "\n** ALERT! memory tracking with no output file?\n"
3976 if(!$cmdtype eq "perl");
3979 my @memdata=`$memanalyze $memdump`;
3983 # well it could be other memory problems as well, but
3984 # we call it leak for short here
3989 logmsg "\n** MEMORY FAILURE\n";
3991 # timestamp test result verification end
3992 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
4001 $ok .= "-"; # memory not checked
4006 unless(opendir(DIR, "$LOGDIR")) {
4007 logmsg "ERROR: unable to read $LOGDIR\n";
4008 # timestamp test result verification end
4009 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
4012 my @files = readdir(DIR);
4015 foreach my $file (@files) {
4016 if($file =~ /^valgrind$testnum(\..*|)$/) {
4022 logmsg "ERROR: valgrind log file missing for test $testnum\n";
4023 # timestamp test result verification end
4024 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
4027 my @e = valgrindparse($srcdir, $feature{'SSL'}, "$LOGDIR/$vgfile");
4029 if($automakestyle) {
4030 logmsg "FAIL: $testnum - $testname - valgrind\n";
4033 logmsg " valgrind ERROR ";
4036 # timestamp test result verification end
4037 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
4043 if(!$short && !$disablevalgrind) {
4044 logmsg " valgrind SKIPPED\n";
4046 $ok .= "-"; # skipped
4050 $ok .= "-"; # valgrind not checked
4052 # add 'E' for event-based
4053 $ok .= $evbased ? "E" : "-";
4055 logmsg "$ok " if(!$short);
4057 my $sofar= time()-$start;
4058 my $esttotal = $sofar/$count * $total;
4059 my $estleft = $esttotal - $sofar;
4060 my $left=sprintf("remaining: %02d:%02d",
4064 if(!$automakestyle) {
4065 logmsg sprintf("OK (%-3d out of %-3d, %s)\n", $count, $total, $left);
4068 logmsg "PASS: $testnum - $testname\n";
4071 # the test succeeded, remove all log files
4072 if(!$keepoutfiles) {
4076 # timestamp test result verification end
4077 $timevrfyend{$testnum} = Time::HiRes::time() if($timestats);
4082 #######################################################################
4083 # Stop all running test servers
4086 my $verbose = $_[0];
4088 # kill sockfilter processes for all pingpong servers
4090 killallsockfilters($verbose);
4092 # kill all server pids from %run hash clearing them
4095 foreach my $server (keys %run) {
4099 my $pids = $run{$server};
4100 foreach my $pid (split(' ', $pids)) {
4102 logmsg sprintf("* kill pid for %s => %d\n",
4108 $pidlist .= "$run{$server} ";
4111 $runcert{$server} = 0 if($runcert{$server});
4113 killpid($verbose, $pidlist);
4115 # cleanup all server pid files
4117 foreach my $server (keys %serverpidfile) {
4118 my $pidfile = $serverpidfile{$server};
4119 my $pid = processexists($pidfile);
4121 logmsg "Warning: $server server unexpectedly alive\n";
4122 killpid($verbose, $pid);
4124 unlink($pidfile) if(-f $pidfile);
4128 #######################################################################
4129 # startservers() starts all the named servers
4131 # Returns: string with error reason or blank for success
4137 my (@whatlist) = split(/\s+/,$_);
4138 my $what = lc($whatlist[0]);
4139 $what =~ s/[^a-z0-9-]//g;
4142 if($what =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
4143 $certfile = ($whatlist[1]) ? $whatlist[1] : 'stunnel.pem';
4146 if(($what eq "pop3") ||
4148 ($what eq "imap") ||
4149 ($what eq "smtp")) {
4150 if($torture && $run{$what} &&
4151 !responsive_pingpong_server($what, "", $verbose)) {
4155 ($pid, $pid2) = runpingpongserver($what, "", $verbose);
4157 return "failed starting ". uc($what) ." server";
4159 printf ("* pid $what => %d %d\n", $pid, $pid2) if($verbose);
4160 $run{$what}="$pid $pid2";
4163 elsif($what eq "ftp2") {
4164 if($torture && $run{'ftp2'} &&
4165 !responsive_pingpong_server("ftp", "2", $verbose)) {
4169 ($pid, $pid2) = runpingpongserver("ftp", "2", $verbose);
4171 return "failed starting FTP2 server";
4173 printf ("* pid ftp2 => %d %d\n", $pid, $pid2) if($verbose);
4174 $run{'ftp2'}="$pid $pid2";
4177 elsif($what eq "ftp-ipv6") {
4178 if($torture && $run{'ftp-ipv6'} &&
4179 !responsive_pingpong_server("ftp", "", $verbose, "ipv6")) {
4180 stopserver('ftp-ipv6');
4182 if(!$run{'ftp-ipv6'}) {
4183 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose, "ipv6");
4185 return "failed starting FTP-IPv6 server";
4187 logmsg sprintf("* pid ftp-ipv6 => %d %d\n", $pid,
4188 $pid2) if($verbose);
4189 $run{'ftp-ipv6'}="$pid $pid2";
4192 elsif($what eq "gopher") {
4193 if($torture && $run{'gopher'} &&
4194 !responsive_http_server("gopher", $verbose, 0, $GOPHERPORT)) {
4195 stopserver('gopher');
4197 if(!$run{'gopher'}) {
4198 ($pid, $pid2) = runhttpserver("gopher", $verbose, 0,
4201 return "failed starting GOPHER server";
4203 logmsg sprintf ("* pid gopher => %d %d\n", $pid, $pid2)
4205 $run{'gopher'}="$pid $pid2";
4208 elsif($what eq "gopher-ipv6") {
4209 if($torture && $run{'gopher-ipv6'} &&
4210 !responsive_http_server("gopher", $verbose, "ipv6",
4212 stopserver('gopher-ipv6');
4214 if(!$run{'gopher-ipv6'}) {
4215 ($pid, $pid2) = runhttpserver("gopher", $verbose, "ipv6",
4218 return "failed starting GOPHER-IPv6 server";
4220 logmsg sprintf("* pid gopher-ipv6 => %d %d\n", $pid,
4221 $pid2) if($verbose);
4222 $run{'gopher-ipv6'}="$pid $pid2";
4225 elsif($what eq "http") {
4226 if($torture && $run{'http'} &&
4227 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4231 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4234 return "failed starting HTTP server";
4236 logmsg sprintf ("* pid http => %d %d\n", $pid, $pid2)
4238 $run{'http'}="$pid $pid2";
4241 elsif($what eq "http-proxy") {
4242 if($torture && $run{'http-proxy'} &&
4243 !responsive_http_server("http", $verbose, "proxy",
4245 stopserver('http-proxy');
4247 if(!$run{'http-proxy'}) {
4248 ($pid, $pid2) = runhttpserver("http", $verbose, "proxy",
4251 return "failed starting HTTP-proxy server";
4253 logmsg sprintf ("* pid http-proxy => %d %d\n", $pid, $pid2)
4255 $run{'http-proxy'}="$pid $pid2";
4258 elsif($what eq "http-ipv6") {
4259 if($torture && $run{'http-ipv6'} &&
4260 !responsive_http_server("http", $verbose, "ipv6", $HTTP6PORT)) {
4261 stopserver('http-ipv6');
4263 if(!$run{'http-ipv6'}) {
4264 ($pid, $pid2) = runhttpserver("http", $verbose, "ipv6",
4267 return "failed starting HTTP-IPv6 server";
4269 logmsg sprintf("* pid http-ipv6 => %d %d\n", $pid, $pid2)
4271 $run{'http-ipv6'}="$pid $pid2";
4274 elsif($what eq "http-pipe") {
4275 if($torture && $run{'http-pipe'} &&
4276 !responsive_http_server("http", $verbose, "pipe",
4278 stopserver('http-pipe');
4280 if(!$run{'http-pipe'}) {
4281 ($pid, $pid2) = runhttpserver("http", $verbose, "pipe",
4284 return "failed starting HTTP-pipe server";
4286 logmsg sprintf ("* pid http-pipe => %d %d\n", $pid, $pid2)
4288 $run{'http-pipe'}="$pid $pid2";
4291 elsif($what eq "rtsp") {
4292 if($torture && $run{'rtsp'} &&
4293 !responsive_rtsp_server($verbose)) {
4297 ($pid, $pid2) = runrtspserver($verbose);
4299 return "failed starting RTSP server";
4301 printf ("* pid rtsp => %d %d\n", $pid, $pid2) if($verbose);
4302 $run{'rtsp'}="$pid $pid2";
4305 elsif($what eq "rtsp-ipv6") {
4306 if($torture && $run{'rtsp-ipv6'} &&
4307 !responsive_rtsp_server($verbose, "ipv6")) {
4308 stopserver('rtsp-ipv6');
4310 if(!$run{'rtsp-ipv6'}) {
4311 ($pid, $pid2) = runrtspserver($verbose, "ipv6");
4313 return "failed starting RTSP-IPv6 server";
4315 logmsg sprintf("* pid rtsp-ipv6 => %d %d\n", $pid, $pid2)
4317 $run{'rtsp-ipv6'}="$pid $pid2";
4320 elsif($what eq "ftps") {
4322 # we can't run ftps tests without stunnel
4323 return "no stunnel";
4326 # we can't run ftps tests if libcurl is SSL-less
4327 return "curl lacks SSL support";
4329 if($runcert{'ftps'} && ($runcert{'ftps'} ne $certfile)) {
4330 # stop server when running and using a different cert
4333 if($torture && $run{'ftp'} &&
4334 !responsive_pingpong_server("ftp", "", $verbose)) {
4338 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose);
4340 return "failed starting FTP server";
4342 printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
4343 $run{'ftp'}="$pid $pid2";
4346 ($pid, $pid2) = runftpsserver($verbose, "", $certfile);
4348 return "failed starting FTPS server (stunnel)";
4350 logmsg sprintf("* pid ftps => %d %d\n", $pid, $pid2)
4352 $run{'ftps'}="$pid $pid2";
4355 elsif($what eq "file") {
4356 # we support it but have no server!
4358 elsif($what eq "https") {
4360 # we can't run https tests without stunnel
4361 return "no stunnel";
4364 # we can't run https tests if libcurl is SSL-less
4365 return "curl lacks SSL support";
4367 if($runcert{'https'} && ($runcert{'https'} ne $certfile)) {
4368 # stop server when running and using a different cert
4369 stopserver('https');
4371 if($torture && $run{'http'} &&
4372 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4376 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4379 return "failed starting HTTP server";
4381 printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
4382 $run{'http'}="$pid $pid2";
4384 if(!$run{'https'}) {
4385 ($pid, $pid2) = runhttpsserver($verbose, "", $certfile);
4387 return "failed starting HTTPS server (stunnel)";
4389 logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
4391 $run{'https'}="$pid $pid2";
4394 elsif($what eq "httptls") {
4396 # for now, we can't run http TLS-EXT tests without gnutls-serv
4397 return "no gnutls-serv";
4399 if($torture && $run{'httptls'} &&
4400 !responsive_httptls_server($verbose, "IPv4")) {
4401 stopserver('httptls');
4403 if(!$run{'httptls'}) {
4404 ($pid, $pid2) = runhttptlsserver($verbose, "IPv4");
4406 return "failed starting HTTPTLS server (gnutls-serv)";
4408 logmsg sprintf("* pid httptls => %d %d\n", $pid, $pid2)
4410 $run{'httptls'}="$pid $pid2";
4413 elsif($what eq "httptls-ipv6") {
4415 # for now, we can't run http TLS-EXT tests without gnutls-serv
4416 return "no gnutls-serv";
4418 if($torture && $run{'httptls-ipv6'} &&
4419 !responsive_httptls_server($verbose, "ipv6")) {
4420 stopserver('httptls-ipv6');
4422 if(!$run{'httptls-ipv6'}) {
4423 ($pid, $pid2) = runhttptlsserver($verbose, "ipv6");
4425 return "failed starting HTTPTLS-IPv6 server (gnutls-serv)";
4427 logmsg sprintf("* pid httptls-ipv6 => %d %d\n", $pid, $pid2)
4429 $run{'httptls-ipv6'}="$pid $pid2";
4432 elsif($what eq "tftp") {
4433 if($torture && $run{'tftp'} &&
4434 !responsive_tftp_server("", $verbose)) {
4438 ($pid, $pid2) = runtftpserver("", $verbose);
4440 return "failed starting TFTP server";
4442 printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
4443 $run{'tftp'}="$pid $pid2";
4446 elsif($what eq "tftp-ipv6") {
4447 if($torture && $run{'tftp-ipv6'} &&
4448 !responsive_tftp_server("", $verbose, "ipv6")) {
4449 stopserver('tftp-ipv6');
4451 if(!$run{'tftp-ipv6'}) {
4452 ($pid, $pid2) = runtftpserver("", $verbose, "ipv6");
4454 return "failed starting TFTP-IPv6 server";
4456 printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
4457 $run{'tftp-ipv6'}="$pid $pid2";
4460 elsif($what eq "sftp" || $what eq "scp" || $what eq "socks4" || $what eq "socks5" ) {
4462 ($pid, $pid2) = runsshserver("", $verbose);
4464 return "failed starting SSH server";
4466 printf ("* pid ssh => %d %d\n", $pid, $pid2) if($verbose);
4467 $run{'ssh'}="$pid $pid2";
4469 if($what eq "socks4" || $what eq "socks5") {
4470 if(!$run{'socks'}) {
4471 ($pid, $pid2) = runsocksserver("", $verbose);
4473 return "failed starting socks server";
4475 printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
4476 $run{'socks'}="$pid $pid2";
4479 if($what eq "socks5") {
4481 # Not an OpenSSH or SunSSH ssh daemon
4482 logmsg "Not OpenSSH or SunSSH; socks5 tests need at least OpenSSH 3.7\n";
4483 return "failed starting socks5 server";
4485 elsif(($sshdid =~ /OpenSSH/) && ($sshdvernum < 370)) {
4486 # Need OpenSSH 3.7 for socks5 - http://www.openssh.com/txt/release-3.7
4487 logmsg "$sshdverstr insufficient; socks5 tests need at least OpenSSH 3.7\n";
4488 return "failed starting socks5 server";
4490 elsif(($sshdid =~ /SunSSH/) && ($sshdvernum < 100)) {
4491 # Need SunSSH 1.0 for socks5
4492 logmsg "$sshdverstr insufficient; socks5 tests need at least SunSSH 1.0\n";
4493 return "failed starting socks5 server";
4497 elsif($what eq "http-unix") {
4498 if($torture && $run{'http-unix'} &&
4499 !responsive_http_server("http", $verbose, "unix", $HTTPUNIXPATH)) {
4500 stopserver('http-unix');
4502 if(!$run{'http-unix'}) {
4503 ($pid, $pid2) = runhttpserver("http", $verbose, "unix",
4506 return "failed starting HTTP-unix server";
4508 logmsg sprintf("* pid http-unix => %d %d\n", $pid, $pid2)
4510 $run{'http-unix'}="$pid $pid2";
4513 elsif($what eq "none") {
4514 logmsg "* starts no server\n" if ($verbose);
4517 warn "we don't support a server for $what";
4518 return "no server for $what";
4524 ##############################################################################
4525 # This function makes sure the right set of server is running for the
4526 # specified test case. This is a useful design when we run single tests as not
4527 # all servers need to run then!
4529 # Returns: a string, blank if everything is fine or a reason why it failed
4534 my @what = getpart("client", "server");
4537 warn "Test case $testnum has no server(s) specified";
4538 return "no server specified";
4541 for(my $i = scalar(@what) - 1; $i >= 0; $i--) {
4542 my $srvrline = $what[$i];
4543 chomp $srvrline if($srvrline);
4544 if($srvrline =~ /^(\S+)((\s*)(.*))/) {
4545 my $server = "${1}";
4546 my $lnrest = "${2}";
4548 if($server =~ /^(httptls)(\+)(ext|srp)(\d*)(-ipv6|)$/) {
4549 $server = "${1}${4}${5}";
4550 $tlsext = uc("TLS-${3}");
4552 if(! grep /^\Q$server\E$/, @protocols) {
4553 if(substr($server,0,5) ne "socks") {
4555 return "curl lacks $tlsext support";
4558 return "curl lacks $server server support";
4562 $what[$i] = "$server$lnrest" if($tlsext);
4566 return &startservers(@what);
4569 #######################################################################
4570 # runtimestats displays test-suite run time statistics
4573 my $lasttest = $_[0];
4575 return if(not $timestats);
4577 logmsg "\nTest suite total running time breakdown per task...\n\n";
4585 my $timesrvrtot = 0.0;
4586 my $timepreptot = 0.0;
4587 my $timetooltot = 0.0;
4588 my $timelocktot = 0.0;
4589 my $timevrfytot = 0.0;
4590 my $timetesttot = 0.0;
4593 for my $testnum (1 .. $lasttest) {
4594 if($timesrvrini{$testnum}) {
4595 $timesrvrtot += $timesrvrend{$testnum} - $timesrvrini{$testnum};
4597 (($timetoolini{$testnum} - $timeprepini{$testnum}) -
4598 ($timesrvrend{$testnum} - $timesrvrini{$testnum}));
4599 $timetooltot += $timetoolend{$testnum} - $timetoolini{$testnum};
4600 $timelocktot += $timesrvrlog{$testnum} - $timetoolend{$testnum};
4601 $timevrfytot += $timevrfyend{$testnum} - $timesrvrlog{$testnum};
4602 $timetesttot += $timevrfyend{$testnum} - $timeprepini{$testnum};
4603 push @timesrvr, sprintf("%06.3f %04d",
4604 $timesrvrend{$testnum} - $timesrvrini{$testnum}, $testnum);
4605 push @timeprep, sprintf("%06.3f %04d",
4606 ($timetoolini{$testnum} - $timeprepini{$testnum}) -
4607 ($timesrvrend{$testnum} - $timesrvrini{$testnum}), $testnum);
4608 push @timetool, sprintf("%06.3f %04d",
4609 $timetoolend{$testnum} - $timetoolini{$testnum}, $testnum);
4610 push @timelock, sprintf("%06.3f %04d",
4611 $timesrvrlog{$testnum} - $timetoolend{$testnum}, $testnum);
4612 push @timevrfy, sprintf("%06.3f %04d",
4613 $timevrfyend{$testnum} - $timesrvrlog{$testnum}, $testnum);
4614 push @timetest, sprintf("%06.3f %04d",
4615 $timevrfyend{$testnum} - $timeprepini{$testnum}, $testnum);
4620 no warnings 'numeric';
4621 @timesrvr = sort { $b <=> $a } @timesrvr;
4622 @timeprep = sort { $b <=> $a } @timeprep;
4623 @timetool = sort { $b <=> $a } @timetool;
4624 @timelock = sort { $b <=> $a } @timelock;
4625 @timevrfy = sort { $b <=> $a } @timevrfy;
4626 @timetest = sort { $b <=> $a } @timetest;
4629 logmsg "Spent ". sprintf("%08.3f ", $timesrvrtot) .
4630 "seconds starting and verifying test harness servers.\n";
4631 logmsg "Spent ". sprintf("%08.3f ", $timepreptot) .
4632 "seconds reading definitions and doing test preparations.\n";
4633 logmsg "Spent ". sprintf("%08.3f ", $timetooltot) .
4634 "seconds actually running test tools.\n";
4635 logmsg "Spent ". sprintf("%08.3f ", $timelocktot) .
4636 "seconds awaiting server logs lock removal.\n";
4637 logmsg "Spent ". sprintf("%08.3f ", $timevrfytot) .
4638 "seconds verifying test results.\n";
4639 logmsg "Spent ". sprintf("%08.3f ", $timetesttot) .
4640 "seconds doing all of the above.\n";
4643 logmsg "\nTest server starting and verification time per test ".
4644 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4645 logmsg "-time- test\n";
4646 logmsg "------ ----\n";
4647 foreach my $txt (@timesrvr) {
4648 last if((not $fullstats) && (not $counter--));
4653 logmsg "\nTest definition reading and preparation time per test ".
4654 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4655 logmsg "-time- test\n";
4656 logmsg "------ ----\n";
4657 foreach my $txt (@timeprep) {
4658 last if((not $fullstats) && (not $counter--));
4663 logmsg "\nTest tool execution time per test ".
4664 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4665 logmsg "-time- test\n";
4666 logmsg "------ ----\n";
4667 foreach my $txt (@timetool) {
4668 last if((not $fullstats) && (not $counter--));
4673 logmsg "\nTest server logs lock removal time per test ".
4674 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4675 logmsg "-time- test\n";
4676 logmsg "------ ----\n";
4677 foreach my $txt (@timelock) {
4678 last if((not $fullstats) && (not $counter--));
4683 logmsg "\nTest results verification time per test ".
4684 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4685 logmsg "-time- test\n";
4686 logmsg "------ ----\n";
4687 foreach my $txt (@timevrfy) {
4688 last if((not $fullstats) && (not $counter--));
4693 logmsg "\nTotal time per test ".
4694 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4695 logmsg "-time- test\n";
4696 logmsg "------ ----\n";
4697 foreach my $txt (@timetest) {
4698 last if((not $fullstats) && (not $counter--));
4705 #######################################################################
4706 # Check options to this test program
4713 if ($ARGV[0] eq "-v") {
4717 elsif($ARGV[0] =~ /^-b(.*)/) {
4719 if($portno =~ s/(\d+)$//) {
4723 elsif ($ARGV[0] eq "-c") {
4724 # use this path to curl instead of default
4725 $DBGCURL=$CURL=$ARGV[1];
4728 elsif ($ARGV[0] eq "-vc") {
4729 # use this path to a curl used to verify servers
4731 # Particularly useful when you introduce a crashing bug somewhere in
4732 # the development version as then it won't be able to run any tests
4733 # since it can't verify the servers!
4738 elsif ($ARGV[0] eq "-d") {
4739 # have the servers display protocol output
4742 elsif ($ARGV[0] eq "-g") {
4743 # run this test with gdb
4746 elsif ($ARGV[0] eq "-gw") {
4747 # run this test with windowed gdb
4751 elsif($ARGV[0] eq "-s") {
4755 elsif($ARGV[0] eq "-am") {
4756 # automake-style output
4760 elsif($ARGV[0] eq "-n") {
4764 elsif($ARGV[0] =~ /^-t(.*)/) {
4769 if($xtra =~ s/(\d+)$//) {
4772 # we undef valgrind to make this fly in comparison
4775 elsif($ARGV[0] eq "-a") {
4776 # continue anyway, even if a test fail
4779 elsif($ARGV[0] eq "-e") {
4780 # run the tests cases event based if possible
4783 elsif($ARGV[0] eq "-p") {
4786 elsif($ARGV[0] eq "-l") {
4787 # lists the test case names only
4790 elsif($ARGV[0] eq "-k") {
4791 # keep stdout and stderr files after tests
4794 elsif($ARGV[0] eq "-r") {
4795 # run time statistics needs Time::HiRes
4796 if($Time::HiRes::VERSION) {
4797 keys(%timeprepini) = 1000;
4798 keys(%timesrvrini) = 1000;
4799 keys(%timesrvrend) = 1000;
4800 keys(%timetoolini) = 1000;
4801 keys(%timetoolend) = 1000;
4802 keys(%timesrvrlog) = 1000;
4803 keys(%timevrfyend) = 1000;
4808 elsif($ARGV[0] eq "-rf") {
4809 # run time statistics needs Time::HiRes
4810 if($Time::HiRes::VERSION) {
4811 keys(%timeprepini) = 1000;
4812 keys(%timesrvrini) = 1000;
4813 keys(%timesrvrend) = 1000;
4814 keys(%timetoolini) = 1000;
4815 keys(%timetoolend) = 1000;
4816 keys(%timesrvrlog) = 1000;
4817 keys(%timevrfyend) = 1000;
4822 elsif(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) {
4825 Usage: runtests.pl [options] [test selection(s)]
4826 -a continue even if a test fails
4827 -bN use base port number N for test servers (default $base)
4828 -c path use this curl executable
4829 -d display server debug info
4830 -g run the test case with gdb
4831 -gw run the test case with gdb as a windowed application
4833 -k keep stdout and stderr files present after tests
4834 -l list all test case names/descriptions
4836 -p print log file contents when a test fails
4837 -r run time statistics
4838 -rf full run time statistics
4840 -am automake style output PASS/FAIL: [number] [name]
4841 -t[N] torture (simulate memory alloc failures); N means fail Nth alloc
4843 -vc path use this curl only to verify the existing servers
4844 [num] like "5 6 9" or " 5 to 22 " to run those tests only
4845 [!num] like "!5 !6 !9" to disable those tests
4846 [keyword] like "IPv6" to select only tests containing the key word
4847 [!keyword] like "!cookies" to disable any tests containing the key word
4852 elsif($ARGV[0] =~ /^(\d+)/) {
4855 for($fromnum .. $number) {
4864 elsif($ARGV[0] =~ /^to$/i) {
4865 $fromnum = $number+1;
4867 elsif($ARGV[0] =~ /^!(\d+)/) {
4871 elsif($ARGV[0] =~ /^!(.+)/) {
4872 $disabled_keywords{$1}=$1;
4874 elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
4875 $enabled_keywords{$1}=$1;
4878 print "Unknown option: $ARGV[0]\n";
4884 if(@testthis && ($testthis[0] ne "")) {
4885 $TESTCASES=join(" ", @testthis);
4889 # we have found valgrind on the host, use it
4891 # verify that we can invoke it fine
4892 my $code = runclient("valgrind >/dev/null 2>&1");
4894 if(($code>>8) != 1) {
4895 #logmsg "Valgrind failure, disable it\n";
4899 # since valgrind 2.1.x, '--tool' option is mandatory
4900 # use it, if it is supported by the version installed on the system
4901 runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
4903 $valgrind_tool="--tool=memcheck";
4908 # A shell script. This is typically when built with libtool,
4909 $valgrind="../libtool --mode=execute $valgrind";
4913 # valgrind 3 renamed the --logfile option to --log-file!!!
4914 my $ver=join(' ', runclientoutput("valgrind --version"));
4915 # cut off all but digits and dots
4916 $ver =~ s/[^0-9.]//g;
4918 if($ver =~ /^(\d+)/) {
4921 $valgrind_logfile="--log-file";
4928 # open the executable curl and read the first 4 bytes of it
4929 open(CHECK, "<$CURL");
4931 sysread CHECK, $c, 4;
4934 # A shell script. This is typically when built with libtool,
4936 $gdb = "../libtool --mode=execute gdb";
4940 $HTTPPORT = $base++; # HTTP server port
4941 $HTTPSPORT = $base++; # HTTPS (stunnel) server port
4942 $FTPPORT = $base++; # FTP server port
4943 $FTPSPORT = $base++; # FTPS (stunnel) server port
4944 $HTTP6PORT = $base++; # HTTP IPv6 server port
4945 $FTP2PORT = $base++; # FTP server 2 port
4946 $FTP6PORT = $base++; # FTP IPv6 port
4947 $TFTPPORT = $base++; # TFTP (UDP) port
4948 $TFTP6PORT = $base++; # TFTP IPv6 (UDP) port
4949 $SSHPORT = $base++; # SSH (SCP/SFTP) port
4950 $SOCKSPORT = $base++; # SOCKS port
4951 $POP3PORT = $base++; # POP3 server port
4952 $POP36PORT = $base++; # POP3 IPv6 server port
4953 $IMAPPORT = $base++; # IMAP server port
4954 $IMAP6PORT = $base++; # IMAP IPv6 server port
4955 $SMTPPORT = $base++; # SMTP server port
4956 $SMTP6PORT = $base++; # SMTP IPv6 server port
4957 $RTSPPORT = $base++; # RTSP server port
4958 $RTSP6PORT = $base++; # RTSP IPv6 server port
4959 $GOPHERPORT = $base++; # Gopher IPv4 server port
4960 $GOPHER6PORT = $base++; # Gopher IPv6 server port
4961 $HTTPTLSPORT = $base++; # HTTP TLS (non-stunnel) server port
4962 $HTTPTLS6PORT = $base++; # HTTP TLS (non-stunnel) IPv6 server port
4963 $HTTPPROXYPORT = $base++; # HTTP proxy port, when using CONNECT
4964 $HTTPPIPEPORT = $base++; # HTTP pipelining port
4965 $HTTPUNIXPATH = 'http.sock'; # HTTP server Unix domain socket path
4967 #######################################################################
4968 # clear and create logging directory:
4972 mkdir($LOGDIR, 0777);
4974 #######################################################################
4975 # initialize some variables
4979 init_serverpidfile_hash();
4981 #######################################################################
4982 # Output curl version and host info being tested
4989 #######################################################################
4990 # Fetch all disabled tests, if there are any
4993 if(open(D, "<$TESTDIR/DISABLED")) {
5000 $disabled{$1}=$1; # disable this test number
5006 #######################################################################
5007 # If 'all' tests are requested, find out all test numbers
5010 if ( $TESTCASES eq "all") {
5011 # Get all commands and find out their test numbers
5012 opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
5013 my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
5016 $TESTCASES=""; # start with no test cases
5018 # cut off everything but the digits
5020 $_ =~ s/[a-z\/\.]*//g;
5022 # sort the numbers from low to high
5023 foreach my $n (sort { $a <=> $b } @cmds) {
5025 # skip disabled test cases
5026 my $why = "configured as DISABLED";
5029 $teststat[$n]=$why; # store reason for this test case
5032 $TESTCASES .= " $n";
5038 if (-e "$TESTDIR/test$_") {
5041 } split(" ", $TESTCASES);
5042 if($verified eq "") {
5043 print "No existing test cases were specified\n";
5046 $TESTCASES = $verified;
5049 #######################################################################
5050 # Start the command line log
5052 open(CMDLOG, ">$CURLLOG") ||
5053 logmsg "can't log command lines to $CURLLOG\n";
5055 #######################################################################
5057 # Display the contents of the given file. Line endings are canonicalized
5058 # and excessively long files are elided
5059 sub displaylogcontent {
5061 if(open(SINGLE, "<$file")) {
5065 while(my $string = <SINGLE>) {
5066 $string =~ s/\r\n/\n/g;
5067 $string =~ s/[\r\f\032]/\n/g;
5068 $string .= "\n" unless ($string =~ /\n$/);
5070 for my $line (split("\n", $string)) {
5071 $line =~ s/\s*\!$//;
5073 push @tail, " $line\n";
5078 $truncate = $linecount > 1000;
5084 my $tailtotal = scalar @tail;
5085 if($tailtotal > $tailshow) {
5086 $tailskip = $tailtotal - $tailshow;
5087 logmsg "=== File too long: $tailskip lines omitted here\n";
5089 for($tailskip .. $tailtotal-1) {
5099 opendir(DIR, "$LOGDIR") ||
5100 die "can't open dir: $!";
5101 my @logs = readdir(DIR);
5104 logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
5105 foreach my $log (sort @logs) {
5106 if($log =~ /\.(\.|)$/) {
5107 next; # skip "." and ".."
5109 if($log =~ /^\.nfs/) {
5112 if(($log eq "memdump") || ($log eq "core")) {
5113 next; # skip "memdump" and "core"
5115 if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
5116 next; # skip directory and empty files
5118 if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
5119 next; # skip stdoutNnn of other tests
5121 if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
5122 next; # skip stderrNnn of other tests
5124 if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
5125 next; # skip uploadNnn of other tests
5127 if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
5128 next; # skip curlNnn.out of other tests
5130 if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
5131 next; # skip testNnn.txt of other tests
5133 if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
5134 next; # skip fileNnn.txt of other tests
5136 if(($log =~ /^netrc\d+/) && ($log !~ /^netrc$testnum/)) {
5137 next; # skip netrcNnn of other tests
5139 if(($log =~ /^trace\d+/) && ($log !~ /^trace$testnum/)) {
5140 next; # skip traceNnn of other tests
5142 if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(\..*|)$/)) {
5143 next; # skip valgrindNnn of other tests
5145 logmsg "=== Start of file $log\n";
5146 displaylogcontent("$LOGDIR/$log");
5147 logmsg "=== End of file $log\n";
5151 #######################################################################
5152 # The main test-loop
5160 my @at = split(" ", $TESTCASES);
5165 foreach $testnum (@at) {
5167 $lasttest = $testnum if($testnum > $lasttest);
5170 my $error = singletest($run_event_based, $testnum, $count, scalar(@at));
5172 # not a test we can run
5176 $total++; # number of tests we've run
5179 $failed.= "$testnum ";
5181 # display all files in log/ in a nice way
5182 displaylogs($testnum);
5185 # a test failed, abort
5186 logmsg "\n - abort tests\n";
5191 $ok++; # successful test counter
5194 # loop for next test
5197 my $sofar = time() - $start;
5199 #######################################################################
5204 # Tests done, stop the servers
5205 stopservers($verbose);
5207 my $all = $total + $skipped;
5209 runtimestats($lasttest);
5212 logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
5216 logmsg "TESTFAIL: These test cases failed: $failed\n";
5220 logmsg "TESTFAIL: No tests were performed\n";
5224 logmsg "TESTDONE: $all tests were considered during ".
5225 sprintf("%.0f", $sofar) ." seconds.\n";
5228 if($skipped && !$short) {
5230 logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
5232 for(keys %skipped) {
5234 printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
5236 # now show all test case numbers that had this reason for being
5240 for(0 .. scalar @teststat) {
5242 if($teststat[$_] && ($teststat[$_] eq $r)) {
5251 logmsg " and ".($c-$max)." more";
5257 if($total && ($ok != $total)) {