Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / tests / runtests.pl
blob7bba5a5e036805a88ed4de28e6a82b5dcbfd1057
1 #!/usr/bin/env perl
2 #***************************************************************************
3 # _ _ ____ _
4 # Project ___| | | | _ \| |
5 # / __| | | | |_) | |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://curl.haxx.se/docs/copyright.html.
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 # $Id: runtests.pl,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
23 ###########################################################################
25 # Experimental hooks are available to run tests remotely on machines that
26 # are able to run curl but are unable to run the test harness.
27 # The following sections need to be modified:
29 # $HOSTIP, $HOST6IP - Set to the address of the host running the test suite
30 # $CLIENTIP, $CLIENT6IP - Set to the address of the host running curl
31 # runclient, runclientoutput - Modify to copy all the files in the log/
32 # directory to the system running curl, run the given command remotely
33 # and save the return code or returned stdout (respectively), then
34 # copy all the files from the remote system's log/ directory back to
35 # the host running the test suite. This can be done a few ways, such
36 # as using scp & ssh, rsync & telnet, or using a NFS shared directory
37 # and ssh.
39 # 'make && make test' needs to be done on both machines before making the
40 # above changes and running runtests.pl manually. In the shared NFS case,
41 # the contents of the tests/server/ directory must be from the host
42 # running the test suite, while the rest must be from the host running curl.
44 # Note that even with these changes a number of tests will still fail (mainly
45 # to do with cookies, those that set environment variables, or those that
46 # do more than touch the file system in a <precheck> or <postcheck>
47 # section). These can be added to the $TESTCASES line below,
48 # e.g. $TESTCASES="!8 !31 !63 !cookies..."
50 # Finally, to properly support -g and -n, checktestcmd needs to change
51 # to check the remote system's PATH, and the places in the code where
52 # the curl binary is read directly to determine its type also need to be
53 # fixed. As long as the -g option is never given, and the -n is always
54 # given, this won't be a problem.
57 # These should be the only variables that might be needed to get edited:
59 BEGIN {
60 @INC=(@INC, $ENV{'srcdir'}, ".");
63 use strict;
64 #use Time::HiRes qw( gettimeofday );
65 #use warnings;
66 use Cwd;
68 # Variables and subs imported from sshhelp module
69 use sshhelp qw(
70 $sshdexe
71 $sshexe
72 $sftpexe
73 $sshconfig
74 $sftpconfig
75 $sshlog
76 $sftplog
77 $sftpcmds
78 display_sshdconfig
79 display_sshconfig
80 display_sftpconfig
81 display_sshdlog
82 display_sshlog
83 display_sftplog
84 find_sshd
85 find_ssh
86 find_sftp
87 sshversioninfo
90 require "getpart.pm"; # array functions
91 require "valgrind.pm"; # valgrind report parser
92 require "ftp.pm";
94 my $HOSTIP="127.0.0.1"; # address on which the test server listens
95 my $HOST6IP="[::1]"; # address on which the test server listens
96 my $CLIENTIP="127.0.0.1"; # address which curl uses for incoming connections
97 my $CLIENT6IP="[::1]"; # address which curl uses for incoming connections
99 my $base = 8990; # base port number
101 my $HTTPPORT; # HTTP server port
102 my $HTTP6PORT; # HTTP IPv6 server port
103 my $HTTPSPORT; # HTTPS server port
104 my $FTPPORT; # FTP server port
105 my $FTP2PORT; # FTP server 2 port
106 my $FTPSPORT; # FTPS server port
107 my $FTP6PORT; # FTP IPv6 server port
108 my $TFTPPORT; # TFTP
109 my $TFTP6PORT; # TFTP
110 my $SSHPORT; # SCP/SFTP
111 my $SOCKSPORT; # SOCKS4/5 port
113 my $srcdir = $ENV{'srcdir'} || '.';
114 my $CURL="../src/curl"; # what curl executable to run on the tests
115 my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
116 my $LOGDIR="log";
117 my $TESTDIR="$srcdir/data";
118 my $LIBDIR="./libtest";
119 my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
120 my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
121 my $CURLLOG="$LOGDIR/curl.log"; # all command lines run
122 my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
123 my $SERVERLOGS_LOCK="$LOGDIR/serverlogs.lock"; # server logs advisor read lock
125 # Normally, all test cases should be run, but at times it is handy to
126 # simply run a particular one:
127 my $TESTCASES="all";
129 # To run specific test cases, set them like:
130 # $TESTCASES="1 2 3 7 8";
132 #######################################################################
133 # No variables below this point should need to be modified
136 my $HTTPPIDFILE=".http.pid";
137 my $HTTP6PIDFILE=".http6.pid";
138 my $HTTPSPIDFILE=".https.pid";
139 my $FTPPIDFILE=".ftp.pid";
140 my $FTP6PIDFILE=".ftp6.pid";
141 my $FTP2PIDFILE=".ftp2.pid";
142 my $FTPSPIDFILE=".ftps.pid";
143 my $TFTPPIDFILE=".tftpd.pid";
144 my $TFTP6PIDFILE=".tftp6.pid";
145 my $SSHPIDFILE=".ssh.pid";
146 my $SOCKSPIDFILE=".socks.pid";
148 # invoke perl like this:
149 my $perl="perl -I$srcdir";
150 my $server_response_maxtime=13;
152 # this gets set if curl is compiled with debugging:
153 my $curl_debug=0;
154 my $libtool;
156 # name of the file that the memory debugging creates:
157 my $memdump="$LOGDIR/memdump";
159 # the path to the script that analyzes the memory debug output file:
160 my $memanalyze="$perl $srcdir/memanalyze.pl";
162 my $pwd = getcwd(); # current working directory
164 my $start;
165 my $forkserver=0;
166 my $ftpchecktime; # time it took to verify our test FTP server
168 my $stunnel = checkcmd("stunnel4") || checkcmd("stunnel");
169 my $valgrind = checktestcmd("valgrind");
170 my $valgrind_logfile="--logfile";
171 my $valgrind_tool;
172 my $gdb = checktestcmd("gdb");
174 my $ssl_version; # set if libcurl is built with SSL support
175 my $large_file; # set if libcurl is built with large file support
176 my $has_idn; # set if libcurl is built with IDN support
177 my $http_ipv6; # set if HTTP server has IPv6 support
178 my $ftp_ipv6; # set if FTP server has IPv6 support
179 my $tftp_ipv6; # set if TFTP server has IPv6 support
180 my $has_ipv6; # set if libcurl is built with IPv6 support
181 my $has_libz; # set if libcurl is built with libz support
182 my $has_getrlimit; # set if system has getrlimit()
183 my $has_ntlm; # set if libcurl is built with NTLM support
185 my $has_openssl; # built with a lib using an OpenSSL-like API
186 my $has_gnutls; # built with GnuTLS
187 my $has_nss; # built with NSS
188 my $has_yassl; # built with yassl
190 my $ssllib; # name of the lib we use (for human presentation)
191 my $has_crypto; # set if libcurl is built with cryptographic support
192 my $has_textaware; # set if running on a system that has a text mode concept
193 # on files. Windows for example
194 my @protocols; # array of supported protocols
196 my $skipped=0; # number of tests skipped; reported in main loop
197 my %skipped; # skipped{reason}=counter, reasons for skip
198 my @teststat; # teststat[testnum]=reason, reasons for skip
199 my %disabled_keywords; # key words of tests to skip
200 my %enabled_keywords; # key words of tests to run
202 my $sshdid; # for socks server, ssh daemon version id
203 my $sshdvernum; # for socks server, ssh daemon version number
204 my $sshdverstr; # for socks server, ssh daemon version string
205 my $sshderror; # for socks server, ssh daemon version error
207 my $defserverlogslocktimeout = 20; # timeout to await server logs lock removal
208 my $defpostcommanddelay = 0; # delay between command and postcheck sections
210 #######################################################################
211 # variables the command line options may set
214 my $short;
215 my $verbose;
216 my $debugprotocol;
217 my $anyway;
218 my $gdbthis; # run test case with gdb debugger
219 my $keepoutfiles; # keep stdout and stderr files after tests
220 my $listonly; # only list the tests
221 my $postmortem; # display detailed info about failed tests
223 my %run; # running server
224 my %doesntrun; # servers that don't work, identified by pidfile
226 # torture test variables
227 my $torture;
228 my $tortnum;
229 my $tortalloc;
231 # open and close each time to allow removal at any time
232 sub logmsg {
233 # uncomment the Time::HiRes usage for this
234 # my ($seconds, $microseconds) = gettimeofday;
235 # my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
236 # localtime($seconds);
237 my $t;
238 if(1) {
239 # $t = sprintf ("%02d:%02d:%02d.%06d ", $hour, $min, $sec,
240 # $microseconds);
242 for(@_) {
243 print "${t}$_";
247 # get the name of the current user
248 my $USER = $ENV{USER}; # Linux
249 if (!$USER) {
250 $USER = $ENV{USERNAME}; # Windows
251 if (!$USER) {
252 $USER = $ENV{LOGNAME}; # Some UNIX (I think)
256 # enable memory debugging if curl is compiled with it
257 $ENV{'CURL_MEMDEBUG'} = $memdump;
258 $ENV{'HOME'}=$pwd;
260 sub catch_zap {
261 my $signame = shift;
262 logmsg "runtests.pl received SIG$signame, exiting\n";
263 stopservers(1);
264 die "Somebody sent me a SIG$signame";
266 $SIG{INT} = \&catch_zap;
267 $SIG{KILL} = \&catch_zap;
269 ##########################################################################
270 # Clear all possible '*_proxy' environment variables for various protocols
271 # to prevent them to interfere with our testing!
273 my $protocol;
274 foreach $protocol (('ftp', 'http', 'ftps', 'https', 'no')) {
275 my $proxy = "${protocol}_proxy";
276 # clear lowercase version
277 $ENV{$proxy}=undef;
278 # clear uppercase version
279 $ENV{uc($proxy)}=undef;
282 # make sure we don't get affected by other variables that control our
283 # behaviour
285 $ENV{'SSL_CERT_DIR'}=undef;
286 $ENV{'SSL_CERT_PATH'}=undef;
287 $ENV{'CURL_CA_BUNDLE'}=undef;
289 #######################################################################
290 # Check if a given child process has just died. Reaps it if so.
292 sub checkdied {
293 use POSIX ":sys_wait_h";
294 my $pid = $_[0];
295 if(not defined $pid || $pid <= 0) {
296 return 0;
298 my $rc = waitpid($pid, &WNOHANG);
299 return ($rc == $pid)?1:0;
302 #######################################################################
303 # Start a new thread/process and run the given command line in there.
304 # Return the pids (yes plural) of the new child process to the parent.
306 sub startnew {
307 my ($cmd, $pidfile, $timeout, $fake)=@_;
309 logmsg "startnew: $cmd\n" if ($verbose);
311 my $child = fork();
312 my $pid2 = 0;
314 if(not defined $child) {
315 logmsg "startnew: fork() failure detected\n";
316 return (-1,-1);
319 if(0 == $child) {
320 # Here we are the child. Run the given command.
322 # Put an "exec" in front of the command so that the child process
323 # keeps this child's process ID.
324 exec("exec $cmd") || die "Can't exec() $cmd: $!";
326 # exec() should never return back here to this process. We protect
327 # ourselves by calling die() just in case something goes really bad.
328 die "error: exec() has returned";
331 # Ugly hack but ssh client doesn't support pid files
332 if ($fake) {
333 if(open(OUT, ">$pidfile")) {
334 print OUT $child . "\n";
335 close(OUT);
336 logmsg "startnew: $pidfile faked with pid=$child\n" if($verbose);
338 else {
339 logmsg "startnew: failed to write fake $pidfile with pid=$child\n";
341 # could/should do a while connect fails sleep a bit and loop
342 sleep $timeout;
343 if (checkdied($child)) {
344 logmsg "startnew: child process has failed to start\n" if($verbose);
345 return (-1,-1);
349 my $count = $timeout;
350 while($count--) {
351 if(-f $pidfile && -s $pidfile && open(PID, "<$pidfile")) {
352 $pid2 = 0 + <PID>;
353 close(PID);
354 if(($pid2 > 0) && kill(0, $pid2)) {
355 # if $pid2 is valid, then make sure this pid is alive, as
356 # otherwise it is just likely to be the _previous_ pidfile or
357 # similar!
358 last;
360 # invalidate $pid2 if not actually alive
361 $pid2 = 0;
363 if (checkdied($child)) {
364 logmsg "startnew: child process has died, server might start up\n"
365 if($verbose);
366 # We can't just abort waiting for the server with a
367 # return (-1,-1);
368 # because the server might have forked and could still start
369 # up normally. Instead, just reduce the amount of time we remain
370 # waiting.
371 $count >>= 2;
373 sleep(1);
376 # Return two PIDs, the one for the child process we spawned and the one
377 # reported by the server itself (in case it forked again on its own).
378 # Both (potentially) need to be killed at the end of the test.
379 return ($child, $pid2);
383 #######################################################################
384 # Check for a command in the PATH of the test server.
386 sub checkcmd {
387 my ($cmd)=@_;
388 my @paths=(split(":", $ENV{'PATH'}), "/usr/sbin", "/usr/local/sbin",
389 "/sbin", "/usr/bin", "/usr/local/bin" );
390 for(@paths) {
391 if( -x "$_/$cmd" && ! -d "$_/$cmd") {
392 # executable bit but not a directory!
393 return "$_/$cmd";
398 #######################################################################
399 # Check for a command in the PATH of the machine running curl.
401 sub checktestcmd {
402 my ($cmd)=@_;
403 return checkcmd($cmd);
406 #######################################################################
407 # Run the application under test and return its return code
409 sub runclient {
410 my ($cmd)=@_;
411 return system($cmd);
413 # This is one way to test curl on a remote machine
414 # my $out = system("ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'");
415 # sleep 2; # time to allow the NFS server to be updated
416 # return $out;
419 #######################################################################
420 # Run the application under test and return its stdout
422 sub runclientoutput {
423 my ($cmd)=@_;
424 return `$cmd`;
426 # This is one way to test curl on a remote machine
427 # my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`;
428 # sleep 2; # time to allow the NFS server to be updated
429 # return @out;
432 #######################################################################
433 # Memory allocation test and failure torture testing.
435 sub torture {
436 my $testcmd = shift;
437 my $gdbline = shift;
439 # remove memdump first to be sure we get a new nice and clean one
440 unlink($memdump);
442 # First get URL from test server, ignore the output/result
443 runclient($testcmd);
445 logmsg " CMD: $testcmd\n" if($verbose);
447 # memanalyze -v is our friend, get the number of allocations made
448 my $count=0;
449 my @out = `$memanalyze -v $memdump`;
450 for(@out) {
451 if(/^Allocations: (\d+)/) {
452 $count = $1;
453 last;
456 if(!$count) {
457 logmsg " found no allocs to make fail\n";
458 return 0;
461 logmsg " $count allocations to make fail\n";
463 for ( 1 .. $count ) {
464 my $limit = $_;
465 my $fail;
466 my $dumped_core;
468 if($tortalloc && ($tortalloc != $limit)) {
469 next;
472 logmsg "Fail alloc no: $limit\r" if($verbose);
474 # make the memory allocation function number $limit return failure
475 $ENV{'CURL_MEMLIMIT'} = $limit;
477 # remove memdump first to be sure we get a new nice and clean one
478 unlink($memdump);
480 logmsg "**> Alloc number $limit is now set to fail <**\n" if($gdbthis);
482 my $ret;
483 if($gdbthis) {
484 runclient($gdbline)
486 else {
487 $ret = runclient($testcmd);
490 # Now clear the variable again
491 $ENV{'CURL_MEMLIMIT'} = undef;
493 if(-r "core") {
494 # there's core file present now!
495 logmsg " core dumped\n";
496 $dumped_core = 1;
497 $fail = 2;
500 # verify that it returns a proper error code, doesn't leak memory
501 # and doesn't core dump
502 if($ret & 255) {
503 logmsg " system() returned $ret\n";
504 $fail=1;
506 else {
507 my @memdata=`$memanalyze $memdump`;
508 my $leak=0;
509 for(@memdata) {
510 if($_ ne "") {
511 # well it could be other memory problems as well, but
512 # we call it leak for short here
513 $leak=1;
516 if($leak) {
517 logmsg "** MEMORY FAILURE\n";
518 logmsg @memdata;
519 logmsg `$memanalyze -l $memdump`;
520 $fail = 1;
523 if($fail) {
524 logmsg " Failed on alloc number $limit in test.\n",
525 " invoke with -t$limit to repeat this single case.\n";
526 stopservers($verbose);
527 return 1;
531 logmsg "torture OK\n";
532 return 0;
535 #######################################################################
536 # stop the given test server (pid)
538 sub stopserver {
539 my ($pid) = @_;
541 if(not defined $pid || $pid <= 0) {
542 return; # whad'da'ya wanna'da with no pid ?
545 # It might be more than one pid
546 # Send each one a SIGTERM to gracefully kill it
548 my @killed;
549 my @pids = split(/\s+/, $pid);
550 for (@pids) {
551 chomp($_);
552 if($_ =~ /^(\d+)$/) {
553 if(($1 > 0) && kill(0, $1)) {
554 if($verbose) {
555 logmsg "RUN: Test server pid $1 signalled to die\n";
557 kill(15, $1); # die!
558 push @killed, $1;
563 # Give each process killed up to a few seconds to die, then send
564 # a SIGKILL to finish it off for good.
565 for (@killed) {
566 my $count = 5; # wait for this many seconds for server to die
567 while($count--) {
568 if (!kill(0, $_) || checkdied($_)) {
569 last;
571 sleep(1);
573 if ($count < 0) {
574 logmsg "RUN: forcing pid $_ to die with SIGKILL\n";
575 kill(9, $_); # die!
580 #######################################################################
581 # Verify that the server that runs on $ip, $port is our server. This also
582 # implies that we can speak with it, as there might be occasions when the
583 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
584 # assign requested address" #
586 sub verifyhttp {
587 my ($proto, $ip, $port) = @_;
588 my $cmd = "$CURL --max-time $server_response_maxtime --output $LOGDIR/verifiedserver --insecure --silent --verbose --globoff \"$proto://$ip:$port/verifiedserver\" 2>$LOGDIR/verifyhttp";
589 my $pid;
591 # verify if our/any server is running on this port
592 logmsg "CMD; $cmd\n" if ($verbose);
593 my $res = runclient($cmd);
595 $res >>= 8; # rotate the result
596 my $data;
598 if($res && $verbose) {
599 open(ERR, "<$LOGDIR/verifyhttp");
600 my @e = <ERR>;
601 close(ERR);
602 logmsg "RUN: curl command returned $res\n";
603 for(@e) {
604 if($_ !~ /^([ \t]*)$/) {
605 logmsg "RUN: $_";
609 open(FILE, "<$LOGDIR/verifiedserver");
610 my @file=<FILE>;
611 close(FILE);
612 $data=$file[0]; # first line
614 if ( $data =~ /WE ROOLZ: (\d+)/ ) {
615 $pid = 0+$1;
617 elsif($res == 6) {
618 # curl: (6) Couldn't resolve host '::1'
619 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
620 return -1;
622 elsif($data || ($res != 7)) {
623 logmsg "RUN: Unknown server is running on port $port\n";
624 return -1;
626 return $pid;
629 #######################################################################
630 # Verify that the server that runs on $ip, $port is our server. This also
631 # implies that we can speak with it, as there might be occasions when the
632 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
633 # assign requested address" #
635 sub verifyftp {
636 my ($proto, $ip, $port) = @_;
637 my $pid;
638 my $time=time();
639 my $extra;
640 if($proto eq "ftps") {
641 $extra = "--insecure --ftp-ssl-control ";
643 my $cmd="$CURL --max-time $server_response_maxtime --silent --verbose --globoff $extra\"$proto://$ip:$port/verifiedserver\" 2>$LOGDIR/verifyftp";
644 # check if this is our server running on this port:
645 my @data=runclientoutput($cmd);
646 logmsg "RUN: $cmd\n" if($verbose);
647 my $line;
649 foreach $line (@data) {
650 if ( $line =~ /WE ROOLZ: (\d+)/ ) {
651 # this is our test server with a known pid!
652 $pid = 0+$1;
653 last;
656 if($pid <= 0 && $data[0]) {
657 # this is not a known server
658 logmsg "RUN: Unknown server on our FTP port: $port\n";
659 return 0;
661 # we can/should use the time it took to verify the FTP server as a measure
662 # on how fast/slow this host/FTP is.
663 my $took = time()-$time;
665 if($verbose) {
666 logmsg "RUN: Verifying our test FTP server took $took seconds\n";
668 $ftpchecktime = $took?$took:1; # make sure it never is zero
670 return $pid;
673 #######################################################################
674 # Verify that the ssh server has written out its pidfile, recovering
675 # the pid from the file and returning it if a process with that pid is
676 # actually alive.
678 sub verifyssh {
679 my ($proto, $ip, $port) = @_;
680 my $pid = 0;
681 if(open(FILE, "<$SSHPIDFILE")) {
682 $pid=0+<FILE>;
683 close(FILE);
685 if($pid > 0) {
686 # if we have a pid it is actually our ssh server,
687 # since runsshserver() unlinks previous pidfile
688 if(!kill(0, $pid)) {
689 logmsg "RUN: SSH server has died after starting up\n";
690 checkdied($pid);
691 unlink($SSHPIDFILE);
692 $pid = -1;
695 return $pid;
698 #######################################################################
699 # Verify that we can connect to the sftp server, properly authenticate
700 # with generated config and key files and run a simple remote pwd.
702 sub verifysftp {
703 my ($proto, $ip, $port) = @_;
704 my $verified = 0;
705 # Find out sftp client canonical file name
706 my $sftp = find_sftp();
707 if(!$sftp) {
708 logmsg "RUN: SFTP server cannot find $sftpexe\n";
709 return -1;
711 # Find out ssh client canonical file name
712 my $ssh = find_ssh();
713 if(!$ssh) {
714 logmsg "RUN: SFTP server cannot find $sshexe\n";
715 return -1;
717 # Connect to sftp server, authenticate and run a remote pwd
718 # command using our generated configuration and key files
719 my $cmd = "$sftp -b $sftpcmds -F $sftpconfig -S $ssh $ip > $sftplog 2>&1";
720 my $res = runclient($cmd);
721 # Search for pwd command response in log file
722 if(open(SFTPLOGFILE, "<$sftplog")) {
723 while(<SFTPLOGFILE>) {
724 if(/^Remote working directory: /) {
725 $verified = 1;
726 last;
729 close(SFTPLOGFILE);
731 return $verified;
735 #######################################################################
736 # STUB for verifying socks
738 sub verifysocks {
739 my ($proto, $ip, $port) = @_;
740 my $pid = 0;
741 if(open(FILE, "<$SOCKSPIDFILE")) {
742 $pid=0+<FILE>;
743 close(FILE);
745 if($pid > 0) {
746 # if we have a pid it is actually our socks server,
747 # since runsocksserver() unlinks previous pidfile
748 if(!kill(0, $pid)) {
749 logmsg "RUN: SOCKS server has died after starting up\n";
750 checkdied($pid);
751 unlink($SOCKSPIDFILE);
752 $pid = -1;
755 return $pid;
758 #######################################################################
759 # Verify that the server that runs on $ip, $port is our server.
760 # Retry over several seconds before giving up. The ssh server in
761 # particular can take a long time to start if it needs to generate
762 # keys on a slow or loaded host.
765 my %protofunc = ('http' => \&verifyhttp,
766 'https' => \&verifyhttp,
767 'ftp' => \&verifyftp,
768 'ftps' => \&verifyftp,
769 'tftp' => \&verifyftp,
770 'ssh' => \&verifyssh,
771 'socks' => \&verifysocks);
773 sub verifyserver {
774 my ($proto, $ip, $port) = @_;
776 my $count = 30; # try for this many seconds
777 my $pid;
779 while($count--) {
780 my $fun = $protofunc{$proto};
782 $pid = &$fun($proto, $ip, $port);
784 if($pid > 0) {
785 last;
787 elsif($pid < 0) {
788 # a real failure, stop trying and bail out
789 return 0;
791 sleep(1);
793 return $pid;
798 #######################################################################
799 # start the http server
801 sub runhttpserver {
802 my ($verbose, $ipv6) = @_;
803 my $RUNNING;
804 my $pidfile = $HTTPPIDFILE;
805 my $port = $HTTPPORT;
806 my $ip = $HOSTIP;
807 my $nameext;
808 my $fork = $forkserver?"--fork":"";
810 if($ipv6) {
811 # if IPv6, use a different setup
812 $pidfile = $HTTP6PIDFILE;
813 $port = $HTTP6PORT;
814 $ip = $HOST6IP;
815 $nameext="-ipv6";
818 # don't retry if the server doesn't work
819 if ($doesntrun{$pidfile}) {
820 return (0,0);
823 my $pid = checkserver($pidfile);
824 if($pid > 0) {
825 stopserver($pid);
827 unlink($pidfile);
829 my $flag=$debugprotocol?"-v ":"";
830 my $dir=$ENV{'srcdir'};
831 if($dir) {
832 $flag .= "-d \"$dir\" ";
835 my $cmd="$perl $srcdir/httpserver.pl -p $pidfile $fork$flag $port $ipv6";
836 my ($httppid, $pid2) =
837 startnew($cmd, $pidfile, 15, 0); # start the server in a new process
839 if($httppid <= 0 || !kill(0, $httppid)) {
840 # it is NOT alive
841 logmsg "RUN: failed to start the HTTP$nameext server\n";
842 stopserver("$pid2");
843 $doesntrun{$pidfile} = 1;
844 return (0,0);
847 # Server is up. Verify that we can speak to it.
848 my $pid3 = verifyserver("http", $ip, $port);
849 if(!$pid3) {
850 logmsg "RUN: HTTP$nameext server failed verification\n";
851 # failed to talk to it properly. Kill the server and return failure
852 stopserver("$httppid $pid2");
853 $doesntrun{$pidfile} = 1;
854 return (0,0);
856 $pid2 = $pid3;
858 if($verbose) {
859 logmsg "RUN: HTTP$nameext server is now running PID $httppid\n";
862 sleep(1);
864 return ($httppid, $pid2);
867 #######################################################################
868 # start the https server (or rather, tunnel)
870 sub runhttpsserver {
871 my ($verbose, $ipv6) = @_;
872 my $STATUS;
873 my $RUNNING;
874 my $ip = $HOSTIP;
875 my $pidfile = $HTTPSPIDFILE;
877 if(!$stunnel) {
878 return 0;
881 if($ipv6) {
882 # not complete yet
883 $ip = $HOST6IP;
886 # don't retry if the server doesn't work
887 if ($doesntrun{$pidfile}) {
888 return (0,0);
891 my $pid = checkserver($pidfile);
892 if($pid > 0) {
893 # kill previous stunnel!
894 stopserver($pid);
896 unlink($pidfile);
898 my $flag=$debugprotocol?"-v ":"";
899 my $cmd="$perl $srcdir/httpsserver.pl $flag -p https -s \"$stunnel\" -d $srcdir -r $HTTPPORT $HTTPSPORT";
901 my ($httpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
903 if($httpspid <= 0 || !kill(0, $httpspid)) {
904 # it is NOT alive
905 logmsg "RUN: failed to start the HTTPS server\n";
906 stopservers($verbose);
907 $doesntrun{$pidfile} = 1;
908 return(0,0);
911 # Server is up. Verify that we can speak to it.
912 my $pid3 = verifyserver("https", $ip, $HTTPSPORT);
913 if(!$pid3) {
914 logmsg "RUN: HTTPS server failed verification\n";
915 # failed to talk to it properly. Kill the server and return failure
916 stopserver("$httpspid $pid2");
917 $doesntrun{$pidfile} = 1;
918 return (0,0);
920 # Here pid3 is actually the pid returned by the unsecure-http server.
922 if($verbose) {
923 logmsg "RUN: HTTPS server is now running PID $httpspid\n";
926 sleep(1);
928 return ($httpspid, $pid2);
931 #######################################################################
932 # start the ftp server
934 sub runftpserver {
935 my ($id, $verbose, $ipv6) = @_;
936 my $STATUS;
937 my $RUNNING;
938 my $port = $id?$FTP2PORT:$FTPPORT;
939 # check for pidfile
940 my $pidfile = $id?$FTP2PIDFILE:$FTPPIDFILE;
941 my $ip=$HOSTIP;
942 my $nameext;
943 my $cmd;
945 if($ipv6) {
946 # if IPv6, use a different setup
947 $pidfile = $FTP6PIDFILE;
948 $port = $FTP6PORT;
949 $ip = $HOST6IP;
950 $nameext="-ipv6";
953 # don't retry if the server doesn't work
954 if ($doesntrun{$pidfile}) {
955 return (0,0);
958 my $pid = checkserver($pidfile);
959 if($pid > 0) {
960 stopserver($pid);
962 unlink($pidfile);
964 # start our server:
965 my $flag=$debugprotocol?"-v ":"";
966 $flag .= "-s \"$srcdir\" ";
967 my $addr;
968 if($id) {
969 $flag .="--id $id ";
971 if($ipv6) {
972 $flag .="--ipv6 ";
973 $addr = $HOST6IP;
974 } else {
975 $addr = $HOSTIP;
978 $cmd="$perl $srcdir/ftpserver.pl --pidfile $pidfile $flag --port $port --addr \"$addr\"";
979 my ($ftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
981 if($ftppid <= 0 || !kill(0, $ftppid)) {
982 # it is NOT alive
983 logmsg "RUN: failed to start the FTP$id$nameext server\n";
984 stopserver("$pid2");
985 $doesntrun{$pidfile} = 1;
986 return (0,0);
989 # Server is up. Verify that we can speak to it.
990 my $pid3 = verifyserver("ftp", $ip, $port);
991 if(!$pid3) {
992 logmsg "RUN: FTP$id$nameext server failed verification\n";
993 # failed to talk to it properly. Kill the server and return failure
994 stopserver("$ftppid $pid2");
995 $doesntrun{$pidfile} = 1;
996 return (0,0);
998 $pid2 = $pid3;
1000 if($verbose) {
1001 logmsg "RUN: FTP$id$nameext server is now running PID $ftppid\n";
1004 sleep(1);
1006 return ($pid2, $ftppid);
1009 #######################################################################
1010 # start the ftps server (or rather, tunnel)
1012 sub runftpsserver {
1013 my ($verbose, $ipv6) = @_;
1014 my $STATUS;
1015 my $RUNNING;
1016 my $ip = $HOSTIP;
1017 my $pidfile = $FTPSPIDFILE;
1019 if(!$stunnel) {
1020 return 0;
1023 if($ipv6) {
1024 # not complete yet
1025 $ip = $HOST6IP;
1028 # don't retry if the server doesn't work
1029 if ($doesntrun{$pidfile}) {
1030 return (0,0);
1033 my $pid = checkserver($pidfile);
1034 if($pid > 0) {
1035 # kill previous stunnel!
1036 stopserver($pid);
1038 unlink($pidfile);
1040 my $flag=$debugprotocol?"-v ":"";
1041 my $cmd="$perl $srcdir/httpsserver.pl $flag -p ftps -s \"$stunnel\" -d $srcdir -r $FTPPORT $FTPSPORT";
1043 my ($ftpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1045 if($ftpspid <= 0 || !kill(0, $ftpspid)) {
1046 # it is NOT alive
1047 logmsg "RUN: failed to start the FTPS server\n";
1048 stopservers($verbose);
1049 $doesntrun{$pidfile} = 1;
1050 return(0,0);
1053 # Server is up. Verify that we can speak to it.
1054 my $pid3 = verifyserver("ftps", $ip, $FTPSPORT);
1055 if(!$pid3) {
1056 logmsg "RUN: FTPS server failed verification\n";
1057 # failed to talk to it properly. Kill the server and return failure
1058 stopserver("$ftpspid $pid2");
1059 $doesntrun{$pidfile} = 1;
1060 return (0,0);
1062 # Here pid3 is actually the pid returned by the unsecure-ftp server.
1064 if($verbose) {
1065 logmsg "RUN: FTPS server is now running PID $ftpspid\n";
1068 sleep(1);
1070 return ($ftpspid, $pid2);
1073 #######################################################################
1074 # start the tftp server
1076 sub runtftpserver {
1077 my ($id, $verbose, $ipv6) = @_;
1078 my $STATUS;
1079 my $RUNNING;
1080 my $port = $TFTPPORT;
1081 # check for pidfile
1082 my $pidfile = $TFTPPIDFILE;
1083 my $ip=$HOSTIP;
1084 my $nameext;
1085 my $cmd;
1087 if($ipv6) {
1088 # if IPv6, use a different setup
1089 $pidfile = $TFTP6PIDFILE;
1090 $port = $TFTP6PORT;
1091 $ip = $HOST6IP;
1092 $nameext="-ipv6";
1095 # don't retry if the server doesn't work
1096 if ($doesntrun{$pidfile}) {
1097 return (0,0);
1100 my $pid = checkserver($pidfile);
1101 if($pid > 0) {
1102 stopserver($pid);
1104 unlink($pidfile);
1106 # start our server:
1107 my $flag=$debugprotocol?"-v ":"";
1108 $flag .= "-s \"$srcdir\" ";
1109 if($id) {
1110 $flag .="--id $id ";
1112 if($ipv6) {
1113 $flag .="--ipv6 ";
1116 $cmd="./server/tftpd --pidfile $pidfile $flag $port";
1117 my ($tftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1119 if($tftppid <= 0 || !kill(0, $tftppid)) {
1120 # it is NOT alive
1121 logmsg "RUN: failed to start the TFTP$id$nameext server\n";
1122 stopserver("$pid2");
1123 $doesntrun{$pidfile} = 1;
1124 return (0,0);
1127 # Server is up. Verify that we can speak to it.
1128 my $pid3 = verifyserver("tftp", $ip, $port);
1129 if(!$pid3) {
1130 logmsg "RUN: TFTP$id$nameext server failed verification\n";
1131 # failed to talk to it properly. Kill the server and return failure
1132 stopserver("$tftppid $pid2");
1133 $doesntrun{$pidfile} = 1;
1134 return (0,0);
1136 $pid2 = $pid3;
1138 if($verbose) {
1139 logmsg "RUN: TFTP$id$nameext server is now running PID $tftppid\n";
1142 sleep(1);
1144 return ($pid2, $tftppid);
1148 #######################################################################
1149 # Start the scp/sftp server
1151 sub runsshserver {
1152 my ($id, $verbose, $ipv6) = @_;
1153 my $ip=$HOSTIP;
1154 my $port = $SSHPORT;
1155 my $socksport = $SOCKSPORT;
1156 my $pidfile = $SSHPIDFILE;
1158 # don't retry if the server doesn't work
1159 if ($doesntrun{$pidfile}) {
1160 return (0,0);
1163 my $pid = checkserver($pidfile);
1164 if($pid > 0) {
1165 stopserver($pid);
1167 unlink($pidfile);
1169 my $flag=$verbose?'-v ':'';
1170 $flag .= '-d ' if($debugprotocol);
1172 my $cmd="$perl $srcdir/sshserver.pl ${flag}-u $USER -l $ip -p $port -s $socksport";
1173 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 60, 0);
1175 # on loaded systems sshserver start up can take longer than the timeout
1176 # passed to startnew, when this happens startnew completes without being
1177 # able to read the pidfile and consequently returns a zero pid2 above.
1179 if($sshpid <= 0 || !kill(0, $sshpid)) {
1180 # it is NOT alive
1181 logmsg "RUN: failed to start the SSH server\n";
1182 stopserver("$pid2");
1183 $doesntrun{$pidfile} = 1;
1184 return (0,0);
1187 # ssh server verification allows some extra time for the server to start up
1188 # and gives us the opportunity of recovering the pid from the pidfile, when
1189 # this verification succeeds the recovered pid is assigned to pid2.
1191 my $pid3 = verifyserver("ssh",$ip,$port);
1192 if(!$pid3) {
1193 logmsg "RUN: SSH server failed verification\n";
1194 # failed to fetch server pid. Kill the server and return failure
1195 stopserver("$sshpid $pid2");
1196 $doesntrun{$pidfile} = 1;
1197 return (0,0);
1199 $pid2 = $pid3;
1201 # once it is known that the ssh server is alive, sftp server verification
1202 # is performed actually connecting to it, authenticating and performing a
1203 # very simple remote command. This verification is tried only one time.
1205 if(verifysftp("sftp",$ip,$port) < 1) {
1206 logmsg "RUN: SFTP server failed verification\n";
1207 # failed to talk to it properly. Kill the server and return failure
1208 display_sftplog();
1209 display_sftpconfig();
1210 display_sshdlog();
1211 display_sshdconfig();
1212 stopserver("$sshpid $pid2");
1213 $doesntrun{$pidfile} = 1;
1214 return (0,0);
1217 if($verbose) {
1218 logmsg "RUN: SSH server is now running PID $pid2\n";
1221 return ($pid2, $sshpid);
1224 #######################################################################
1225 # Start the socks server
1227 sub runsocksserver {
1228 my ($id, $verbose, $ipv6) = @_;
1229 my $ip=$HOSTIP;
1230 my $port = $SOCKSPORT;
1231 my $pidfile = $SOCKSPIDFILE;
1233 # don't retry if the server doesn't work
1234 if ($doesntrun{$pidfile}) {
1235 return (0,0);
1238 my $pid = checkserver($pidfile);
1239 if($pid > 0) {
1240 stopserver($pid);
1242 unlink($pidfile);
1244 # The ssh server must be already running
1245 if(!$run{'ssh'}) {
1246 logmsg "RUN: SOCKS server cannot find running SSH server\n";
1247 $doesntrun{$pidfile} = 1;
1248 return (0,0);
1251 # Find out ssh daemon canonical file name
1252 my $sshd = find_sshd();
1253 if(!$sshd) {
1254 logmsg "RUN: SOCKS server cannot find $sshdexe\n";
1255 $doesntrun{$pidfile} = 1;
1256 return (0,0);
1259 # Find out ssh daemon version info
1260 ($sshdid, $sshdvernum, $sshdverstr, $sshderror) = sshversioninfo($sshd);
1261 if(!$sshdid) {
1262 # Not an OpenSSH or SunSSH ssh daemon
1263 logmsg "$sshderror\n" if($verbose);
1264 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
1265 $doesntrun{$pidfile} = 1;
1266 return (0,0);
1268 logmsg "ssh server found $sshd is $sshdverstr\n" if($verbose);
1270 # Find out ssh client canonical file name
1271 my $ssh = find_ssh();
1272 if(!$ssh) {
1273 logmsg "RUN: SOCKS server cannot find $sshexe\n";
1274 $doesntrun{$pidfile} = 1;
1275 return (0,0);
1278 # Find out ssh client version info
1279 my ($sshid, $sshvernum, $sshverstr, $ssherror) = sshversioninfo($ssh);
1280 if(!$sshid) {
1281 # Not an OpenSSH or SunSSH ssh client
1282 logmsg "$ssherror\n" if($verbose);
1283 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
1284 $doesntrun{$pidfile} = 1;
1285 return (0,0);
1288 # Verify minimum ssh client version
1289 if((($sshid =~ /OpenSSH/) && ($sshvernum < 299)) ||
1290 (($sshid =~ /SunSSH/) && ($sshvernum < 100))) {
1291 logmsg "ssh client found $ssh is $sshverstr\n";
1292 logmsg "SCP, SFTP and SOCKS tests require OpenSSH 2.9.9 or later\n";
1293 $doesntrun{$pidfile} = 1;
1294 return (0,0);
1296 logmsg "ssh client found $ssh is $sshverstr\n" if($verbose);
1298 # Verify if ssh client and ssh daemon versions match
1299 if(($sshdid ne $sshid) || ($sshdvernum != $sshvernum)) {
1300 # Our test harness might work with slightly mismatched versions
1301 logmsg "Warning: version mismatch: sshd $sshdverstr - ssh $sshverstr\n"
1302 if($verbose);
1305 # Config file options for ssh client are previously set from sshserver.pl
1306 if(! -e $sshconfig) {
1307 logmsg "RUN: SOCKS server cannot find $sshconfig\n";
1308 $doesntrun{$pidfile} = 1;
1309 return (0,0);
1312 # start our socks server
1313 my $cmd="$ssh -N -F $sshconfig $ip > $sshlog 2>&1";
1314 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 30, 1);
1316 if($sshpid <= 0 || !kill(0, $sshpid)) {
1317 # it is NOT alive
1318 logmsg "RUN: failed to start the SOCKS server\n";
1319 display_sshlog();
1320 display_sshconfig();
1321 display_sshdlog();
1322 display_sshdconfig();
1323 stopserver("$pid2");
1324 $doesntrun{$pidfile} = 1;
1325 return (0,0);
1328 # Ugly hack but ssh doesn't support pid files
1329 my $pid3 = verifyserver("socks",$ip,$port);
1330 if(!$pid3) {
1331 logmsg "RUN: SOCKS server failed verification\n";
1332 # failed to talk to it properly. Kill the server and return failure
1333 stopserver("$sshpid $pid2");
1334 $doesntrun{$pidfile} = 1;
1335 return (0,0);
1337 $pid2 = $pid3;
1339 if($verbose) {
1340 logmsg "RUN: SOCKS server is now running PID $pid2\n";
1343 return ($pid2, $sshpid);
1346 #######################################################################
1347 # Remove all files in the specified directory
1349 sub cleardir {
1350 my $dir = $_[0];
1351 my $count;
1352 my $file;
1354 # Get all files
1355 opendir(DIR, $dir) ||
1356 return 0; # can't open dir
1357 while($file = readdir(DIR)) {
1358 if($file !~ /^\./) {
1359 unlink("$dir/$file");
1360 $count++;
1363 closedir DIR;
1364 return $count;
1367 #######################################################################
1368 # filter out the specified pattern from the given input file and store the
1369 # results in the given output file
1371 sub filteroff {
1372 my $infile=$_[0];
1373 my $filter=$_[1];
1374 my $ofile=$_[2];
1376 open(IN, "<$infile")
1377 || return 1;
1379 open(OUT, ">$ofile")
1380 || return 1;
1382 # logmsg "FILTER: off $filter from $infile to $ofile\n";
1384 while(<IN>) {
1385 $_ =~ s/$filter//;
1386 print OUT $_;
1388 close(IN);
1389 close(OUT);
1390 return 0;
1393 #######################################################################
1394 # compare test results with the expected output, we might filter off
1395 # some pattern that is allowed to differ, output test results
1398 sub compare {
1399 # filter off patterns _before_ this comparison!
1400 my ($subject, $firstref, $secondref)=@_;
1402 my $result = compareparts($firstref, $secondref);
1404 if($result) {
1405 if(!$short) {
1406 logmsg "\n $subject FAILED:\n";
1407 logmsg showdiff($LOGDIR, $firstref, $secondref);
1409 else {
1410 logmsg "FAILED\n";
1413 return $result;
1416 #######################################################################
1417 # display information about curl and the host the test suite runs on
1419 sub checksystem {
1421 unlink($memdump); # remove this if there was one left
1423 my $feat;
1424 my $curl;
1425 my $libcurl;
1426 my $versretval;
1427 my $versnoexec;
1428 my @version=();
1430 my $curlverout="$LOGDIR/curlverout.log";
1431 my $curlvererr="$LOGDIR/curlvererr.log";
1432 my $versioncmd="$CURL --version 1>$curlverout 2>$curlvererr";
1434 unlink($curlverout);
1435 unlink($curlvererr);
1437 $versretval = runclient($versioncmd);
1438 $versnoexec = $!;
1440 open(VERSOUT, "<$curlverout");
1441 @version = <VERSOUT>;
1442 close(VERSOUT);
1444 for(@version) {
1445 chomp;
1447 if($_ =~ /^curl/) {
1448 $curl = $_;
1449 $curl =~ s/^(.*)(libcurl.*)/$1/g;
1451 $libcurl = $2;
1452 if($curl =~ /mingw32/) {
1453 # This is a windows minw32 build, we need to translate the
1454 # given path to the "actual" windows path.
1456 my @m = `mount`;
1457 my $matchlen;
1458 my $bestmatch;
1459 my $mount;
1461 # example mount output:
1462 # C:\DOCUME~1\Temp on /tmp type user (binmode,noumount)
1463 # c:\ActiveState\perl on /perl type user (binmode)
1464 # C:\msys\1.0\bin on /usr/bin type user (binmode,cygexec,noumount)
1465 # C:\msys\1.0\bin on /bin type user (binmode,cygexec,noumount)
1467 foreach $mount (@m) {
1468 if( $mount =~ /(.*) on ([^ ]*) type /) {
1469 my ($mingw, $real)=($2, $1);
1470 if($pwd =~ /^$mingw/) {
1471 # the path we got from pwd starts with the path
1472 # we found on this line in the mount output
1474 my $len = length($real);
1475 if($len > $matchlen) {
1476 # we remember the match that is the longest
1477 $matchlen = $len;
1478 $bestmatch = $real;
1483 if(!$matchlen) {
1484 logmsg "Serious error, can't find our \"real\" path\n";
1486 else {
1487 # now prepend the prefix from the mount command to build
1488 # our "actual path"
1489 $pwd = "$bestmatch$pwd";
1491 $pwd =~ s#\\#/#g;
1493 elsif ($curl =~ /win32/) {
1494 # Native Windows builds don't understand the
1495 # output of cygwin's pwd. It will be
1496 # something like /cygdrive/c/<some path>.
1498 # Use the cygpath utility to convert the
1499 # working directory to a Windows friendly
1500 # path. The -m option converts to use drive
1501 # letter:, but it uses / instead \. Forward
1502 # slashes (/) are easier for us. We don't
1503 # have to escape them to get them to curl
1504 # through a shell.
1505 chomp($pwd = `cygpath -m $pwd`);
1507 elsif ($libcurl =~ /openssl/i) {
1508 $has_openssl=1;
1509 $ssllib="OpenSSL";
1511 elsif ($libcurl =~ /gnutls/i) {
1512 $has_gnutls=1;
1513 $ssllib="GnuTLS";
1515 elsif ($libcurl =~ /nss/i) {
1516 $has_nss=1;
1517 $ssllib="NSS";
1519 elsif ($libcurl =~ /yassl/i) {
1520 $has_yassl=1;
1521 $has_openssl=1;
1522 $ssllib="yassl";
1525 elsif($_ =~ /^Protocols: (.*)/i) {
1526 # these are the protocols compiled in to this libcurl
1527 @protocols = split(' ', $1);
1529 # Generate a "proto-ipv6" version of each protocol to match the
1530 # IPv6 <server> name. This works even if IPv6 support isn't
1531 # compiled in because the <features> test will fail.
1532 push @protocols, map($_ . "-ipv6", @protocols);
1534 # 'none' is used in test cases to mean no server
1535 push @protocols, ('none');
1537 elsif($_ =~ /^Features: (.*)/i) {
1538 $feat = $1;
1539 if($feat =~ /debug/i) {
1540 # debug is a listed "feature", use that knowledge
1541 $curl_debug = 1;
1542 # set the NETRC debug env
1543 $ENV{'CURL_DEBUG_NETRC'} = "$LOGDIR/netrc";
1545 if($feat =~ /SSL/i) {
1546 # ssl enabled
1547 $ssl_version=1;
1549 if($feat =~ /Largefile/i) {
1550 # large file support
1551 $large_file=1;
1553 if($feat =~ /IDN/i) {
1554 # IDN support
1555 $has_idn=1;
1557 if($feat =~ /IPv6/i) {
1558 $has_ipv6 = 1;
1560 if($feat =~ /libz/i) {
1561 $has_libz = 1;
1563 if($feat =~ /NTLM/i) {
1564 # NTLM enabled
1565 $has_ntlm=1;
1569 if(!$curl) {
1570 logmsg "unable to get curl's version, further details are:\n";
1571 logmsg "issued command: \n";
1572 logmsg "$versioncmd \n";
1573 if ($versretval == -1) {
1574 logmsg "command failed with: \n";
1575 logmsg "$versnoexec \n";
1577 elsif ($versretval & 127) {
1578 logmsg sprintf("command died with signal %d, and %s coredump.\n",
1579 ($versretval & 127), ($versretval & 128)?"a":"no");
1581 else {
1582 logmsg sprintf("command exited with value %d \n", $versretval >> 8);
1584 logmsg "contents of $curlverout: \n";
1585 displaylogcontent("$curlverout");
1586 logmsg "contents of $curlvererr: \n";
1587 displaylogcontent("$curlvererr");
1588 die "couldn't get curl's version";
1591 if(-r "../lib/config.h") {
1592 open(CONF, "<../lib/config.h");
1593 while(<CONF>) {
1594 if($_ =~ /^\#define HAVE_GETRLIMIT/) {
1595 $has_getrlimit = 1;
1598 close(CONF);
1601 if($has_ipv6) {
1602 # client has ipv6 support
1604 # check if the HTTP server has it!
1605 my @sws = `server/sws --version`;
1606 if($sws[0] =~ /IPv6/) {
1607 # HTTP server has ipv6 support!
1608 $http_ipv6 = 1;
1611 # check if the FTP server has it!
1612 @sws = `server/sockfilt --version`;
1613 if($sws[0] =~ /IPv6/) {
1614 # FTP server has ipv6 support!
1615 $ftp_ipv6 = 1;
1619 if(!$curl_debug && $torture) {
1620 die "can't run torture tests since curl was not build with debug";
1623 # curl doesn't list cryptographic support separately, so assume it's
1624 # always available
1625 $has_crypto=1;
1627 my $hostname=join(' ', runclientoutput("hostname"));
1628 my $hosttype=join(' ', runclientoutput("uname -a"));
1630 logmsg ("********* System characteristics ******** \n",
1631 "* $curl\n",
1632 "* $libcurl\n",
1633 "* Features: $feat\n",
1634 "* Host: $hostname",
1635 "* System: $hosttype");
1637 logmsg sprintf("* Server SSL: %s\n", $stunnel?"ON":"OFF");
1638 logmsg sprintf("* libcurl SSL: %s\n", $ssl_version?"ON":"OFF");
1639 logmsg sprintf("* libcurl debug: %s\n", $curl_debug?"ON":"OFF");
1640 logmsg sprintf("* valgrind: %s\n", $valgrind?"ON":"OFF");
1641 logmsg sprintf("* HTTP IPv6 %s\n", $http_ipv6?"ON":"OFF");
1642 logmsg sprintf("* FTP IPv6 %s\n", $ftp_ipv6?"ON":"OFF");
1644 logmsg sprintf("* HTTP port: %d\n", $HTTPPORT);
1645 logmsg sprintf("* FTP port: %d\n", $FTPPORT);
1646 logmsg sprintf("* FTP port 2: %d\n", $FTP2PORT);
1647 if($stunnel) {
1648 logmsg sprintf("* FTPS port: %d\n", $FTPSPORT);
1649 logmsg sprintf("* HTTPS port: %d\n", $HTTPSPORT);
1651 if($http_ipv6) {
1652 logmsg sprintf("* HTTP IPv6 port: %d\n", $HTTP6PORT);
1654 if($ftp_ipv6) {
1655 logmsg sprintf("* FTP IPv6 port: %d\n", $FTP6PORT);
1657 logmsg sprintf("* TFTP port: %d\n", $TFTPPORT);
1658 if($tftp_ipv6) {
1659 logmsg sprintf("* TFTP IPv6 port: %d\n", $TFTP6PORT);
1661 logmsg sprintf("* SCP/SFTP port: %d\n", $SSHPORT);
1662 logmsg sprintf("* SOCKS port: %d\n", $SOCKSPORT);
1664 if($ssl_version) {
1665 logmsg sprintf("* SSL library: %s\n", $ssllib);
1668 $has_textaware = ($^O eq 'MSWin32') || ($^O eq 'msys');
1670 logmsg sprintf("* Libtool lib: %s\n", $libtool?"ON":"OFF");
1671 logmsg "***************************************** \n";
1674 #######################################################################
1675 # substitute the variable stuff into either a joined up file or
1676 # a command, in either case passed by reference
1678 sub subVariables {
1679 my ($thing) = @_;
1680 $$thing =~ s/%HOSTIP/$HOSTIP/g;
1681 $$thing =~ s/%HTTPPORT/$HTTPPORT/g;
1682 $$thing =~ s/%HOST6IP/$HOST6IP/g;
1683 $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
1684 $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
1685 $$thing =~ s/%FTPPORT/$FTPPORT/g;
1686 $$thing =~ s/%FTP6PORT/$FTP6PORT/g;
1687 $$thing =~ s/%FTP2PORT/$FTP2PORT/g;
1688 $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
1689 $$thing =~ s/%SRCDIR/$srcdir/g;
1690 $$thing =~ s/%PWD/$pwd/g;
1691 $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
1692 $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
1693 $$thing =~ s/%SSHPORT/$SSHPORT/g;
1694 $$thing =~ s/%SOCKSPORT/$SOCKSPORT/g;
1695 $$thing =~ s/%CURL/$CURL/g;
1696 $$thing =~ s/%USER/$USER/g;
1697 $$thing =~ s/%CLIENTIP/$CLIENTIP/g;
1698 $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
1700 # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
1701 # used for time-out tests and that whould work on most hosts as these
1702 # adjust for the startup/check time for this particular host. We needed
1703 # to do this to make the test suite run better on very slow hosts.
1705 my $ftp2 = $ftpchecktime * 2;
1706 my $ftp3 = $ftpchecktime * 3;
1708 $$thing =~ s/%FTPTIME2/$ftp2/g;
1709 $$thing =~ s/%FTPTIME3/$ftp3/g;
1712 sub fixarray {
1713 my @in = @_;
1715 for(@in) {
1716 subVariables \$_;
1718 return @in;
1721 #######################################################################
1722 # Run a single specified test case
1725 sub singletest {
1726 my ($testnum, $count, $total)=@_;
1728 my @what;
1729 my $why;
1730 my %feature;
1731 my $cmd;
1733 # load the test case file definition
1734 if(loadtest("${TESTDIR}/test${testnum}")) {
1735 if($verbose) {
1736 # this is not a test
1737 logmsg "RUN: $testnum doesn't look like a test case\n";
1739 $why = "no test";
1741 else {
1742 @what = getpart("client", "features");
1745 for(@what) {
1746 my $f = $_;
1747 $f =~ s/\s//g;
1749 $feature{$f}=$f; # we require this feature
1751 if($f eq "SSL") {
1752 if($ssl_version) {
1753 next;
1756 elsif($f eq "OpenSSL") {
1757 if($has_openssl) {
1758 next;
1761 elsif($f eq "GnuTLS") {
1762 if($has_gnutls) {
1763 next;
1766 elsif($f eq "NSS") {
1767 if($has_nss) {
1768 next;
1771 elsif($f eq "netrc_debug") {
1772 if($curl_debug) {
1773 next;
1776 elsif($f eq "large_file") {
1777 if($large_file) {
1778 next;
1781 elsif($f eq "idn") {
1782 if($has_idn) {
1783 next;
1786 elsif($f eq "ipv6") {
1787 if($has_ipv6) {
1788 next;
1791 elsif($f eq "libz") {
1792 if($has_libz) {
1793 next;
1796 elsif($f eq "NTLM") {
1797 if($has_ntlm) {
1798 next;
1801 elsif($f eq "getrlimit") {
1802 if($has_getrlimit) {
1803 next;
1806 elsif($f eq "crypto") {
1807 if($has_crypto) {
1808 next;
1811 elsif($f eq "socks") {
1812 next;
1814 # See if this "feature" is in the list of supported protocols
1815 elsif (grep /^$f$/, @protocols) {
1816 next;
1819 $why = "curl lacks $f support";
1820 last;
1823 if(!$why) {
1824 my @keywords = getpart("info", "keywords");
1825 my $match;
1826 my $k;
1827 for $k (@keywords) {
1828 chomp $k;
1829 if ($disabled_keywords{$k}) {
1830 $why = "disabled by keyword";
1831 } elsif ($enabled_keywords{$k}) {
1832 $match = 1;
1836 if(!$why && !$match && %enabled_keywords) {
1837 $why = "disabled by missing keyword";
1841 if(!$why) {
1842 $why = serverfortest($testnum);
1845 if(!$why) {
1846 my @precheck = getpart("client", "precheck");
1847 $cmd = $precheck[0];
1848 chomp $cmd;
1849 subVariables \$cmd;
1850 if($cmd) {
1851 my @o = `$cmd 2>/dev/null`;
1852 if($o[0]) {
1853 $why = $o[0];
1854 chomp $why;
1856 logmsg "prechecked $cmd\n" if($verbose);
1860 if($why && !$listonly) {
1861 # there's a problem, count it as "skipped"
1862 $skipped++;
1863 $skipped{$why}++;
1864 $teststat[$testnum]=$why; # store reason for this test case
1866 if(!$short) {
1867 printf "test %03d SKIPPED: $why\n", $testnum;
1870 return -1;
1872 logmsg sprintf("test %03d...", $testnum);
1874 # extract the reply data
1875 my @reply = getpart("reply", "data");
1876 my @replycheck = getpart("reply", "datacheck");
1878 if (@replycheck) {
1879 # we use this file instead to check the final output against
1881 my %hash = getpartattr("reply", "datacheck");
1882 if($hash{'nonewline'}) {
1883 # Yes, we must cut off the final newline from the final line
1884 # of the datacheck
1885 chomp($replycheck[$#replycheck]);
1888 @reply=@replycheck;
1891 # curl command to run
1892 my @curlcmd= fixarray ( getpart("client", "command") );
1894 # this is the valid protocol blurb curl should generate
1895 my @protocol= fixarray ( getpart("verify", "protocol") );
1897 # redirected stdout/stderr to these files
1898 $STDOUT="$LOGDIR/stdout$testnum";
1899 $STDERR="$LOGDIR/stderr$testnum";
1901 # if this section exists, we verify that the stdout contained this:
1902 my @validstdout = fixarray ( getpart("verify", "stdout") );
1904 # if this section exists, we verify upload
1905 my @upload = getpart("verify", "upload");
1907 # if this section exists, it might be FTP server instructions:
1908 my @ftpservercmd = getpart("reply", "servercmd");
1910 my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
1912 # name of the test
1913 my @testname= getpart("client", "name");
1915 if(!$short) {
1916 my $name = $testname[0];
1917 $name =~ s/\n//g;
1918 logmsg "[$name]\n";
1921 if($listonly) {
1922 return 0; # look successful
1925 my @codepieces = getpart("client", "tool");
1927 my $tool="";
1928 if(@codepieces) {
1929 $tool = $codepieces[0];
1930 chomp $tool;
1933 # remove server output logfiles
1934 unlink($SERVERIN);
1935 unlink($SERVER2IN);
1937 if(@ftpservercmd) {
1938 # write the instructions to file
1939 writearray($FTPDCMD, \@ftpservercmd);
1942 my (@setenv)= getpart("client", "setenv");
1943 my @envs;
1945 my $s;
1946 for $s (@setenv) {
1947 chomp $s; # cut off the newline
1949 subVariables \$s;
1951 if($s =~ /([^=]*)=(.*)/) {
1952 my ($var, $content)=($1, $2);
1953 $ENV{$var}=$content;
1954 # remember which, so that we can clear them afterwards!
1955 push @envs, $var;
1959 # get the command line options to use
1960 my @blaha;
1961 ($cmd, @blaha)= getpart("client", "command");
1963 # make some nice replace operations
1964 $cmd =~ s/\n//g; # no newlines please
1966 # substitute variables in the command line
1967 subVariables \$cmd;
1969 if($curl_debug) {
1970 unlink($memdump);
1973 # create a (possibly-empty) file before starting the test
1974 my @inputfile=getpart("client", "file");
1975 my %fileattr = getpartattr("client", "file");
1976 my $filename=$fileattr{'name'};
1977 if(@inputfile || $filename) {
1978 if(!$filename) {
1979 logmsg "ERROR: section client=>file has no name attribute\n";
1980 return -1;
1982 my $fileContent = join('', @inputfile);
1983 subVariables \$fileContent;
1984 # logmsg "DEBUG: writing file " . $filename . "\n";
1985 open(OUTFILE, ">$filename");
1986 binmode OUTFILE; # for crapage systems, use binary
1987 print OUTFILE $fileContent;
1988 close(OUTFILE);
1991 my %cmdhash = getpartattr("client", "command");
1993 my $out="";
1995 if($cmdhash{'option'} !~ /no-output/) {
1996 #We may slap on --output!
1997 if (!@validstdout) {
1998 $out=" --output $CURLOUT ";
2002 my $serverlogslocktimeout = $defserverlogslocktimeout;
2003 if($cmdhash{'timeout'}) {
2004 # test is allowed to override default server logs lock timeout
2005 if($cmdhash{'timeout'} =~ /(\d+)/) {
2006 $serverlogslocktimeout = $1 if($1 >= 0);
2010 my $postcommanddelay = $defpostcommanddelay;
2011 if($cmdhash{'delay'}) {
2012 # test is allowed to specify a delay after command is executed
2013 if($cmdhash{'delay'} =~ /(\d+)/) {
2014 $postcommanddelay = $1 if($1 > 0);
2018 my $cmdargs;
2019 if(!$tool) {
2020 # run curl, add --verbose for debug information output
2021 $cmdargs ="$out --include --verbose --trace-time $cmd";
2023 else {
2024 $cmdargs = " $cmd"; # $cmd is the command line for the test file
2025 $CURLOUT = $STDOUT; # sends received data to stdout
2028 my @stdintest = getpart("client", "stdin");
2030 if(@stdintest) {
2031 my $stdinfile="$LOGDIR/stdin-for-$testnum";
2032 writearray($stdinfile, \@stdintest);
2034 $cmdargs .= " <$stdinfile";
2036 my $CMDLINE;
2038 if(!$tool) {
2039 $CMDLINE="$CURL";
2041 else {
2042 $CMDLINE="$LIBDIR/$tool";
2043 if(! -f $CMDLINE) {
2044 print "The tool set in the test case for this: '$tool' does not exist\n";
2045 return -1;
2047 $DBGCURL=$CMDLINE;
2050 my $usevalgrind = $valgrind && ((getpart("verify", "valgrind"))[0] !~ /disable/);
2051 if($usevalgrind) {
2052 $CMDLINE = "$valgrind ".$valgrind_tool."--leak-check=yes --num-callers=16 ${valgrind_logfile}=$LOGDIR/valgrind$testnum $CMDLINE";
2055 $CMDLINE .= "$cmdargs >>$STDOUT 2>>$STDERR";
2057 if($verbose) {
2058 logmsg "$CMDLINE\n";
2061 print CMDLOG "$CMDLINE\n";
2063 unlink("core");
2065 my $dumped_core;
2066 my $cmdres;
2068 # Apr 2007: precommand isn't being used and could be removed
2069 my @precommand= getpart("client", "precommand");
2070 if($precommand[0]) {
2071 # this is pure perl to eval!
2072 my $code = join("", @precommand);
2073 eval $code;
2074 if($@) {
2075 logmsg "perl: $code\n";
2076 logmsg "precommand: $@";
2077 stopservers($verbose);
2078 return -1;
2082 if($gdbthis) {
2083 open(GDBCMD, ">$LOGDIR/gdbcmd");
2084 print GDBCMD "set args $cmdargs\n";
2085 print GDBCMD "show args\n";
2086 close(GDBCMD);
2088 # run the command line we built
2089 if ($torture) {
2090 $cmdres = torture($CMDLINE,
2091 "$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
2093 elsif($gdbthis) {
2094 runclient("$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
2095 $cmdres=0; # makes it always continue after a debugged run
2097 else {
2098 $cmdres = runclient("$CMDLINE");
2099 my $signal_num = $cmdres & 127;
2100 $dumped_core = $cmdres & 128;
2102 if(!$anyway && ($signal_num || $dumped_core)) {
2103 $cmdres = 1000;
2105 else {
2106 $cmdres /= 256;
2109 if(!$dumped_core) {
2110 if(-r "core") {
2111 # there's core file present now!
2112 $dumped_core = 1;
2116 if($dumped_core) {
2117 logmsg "core dumped\n";
2118 if(0 && $gdb) {
2119 logmsg "running gdb for post-mortem analysis:\n";
2120 open(GDBCMD, ">$LOGDIR/gdbcmd2");
2121 print GDBCMD "bt\n";
2122 close(GDBCMD);
2123 runclient("$gdb --directory libtest -x $LOGDIR/gdbcmd2 -batch $DBGCURL core ");
2124 # unlink("$LOGDIR/gdbcmd2");
2128 # If a server logs advisor read lock file exists, it is an indication
2129 # that the server has not yet finished writing out all its log files,
2130 # including server request log files used for protocol verification.
2131 # So, if the lock file exists the script waits here a certain amount
2132 # of time until the server removes it, or the given time expires.
2134 if($serverlogslocktimeout) {
2135 my $lockretry = $serverlogslocktimeout * 4;
2136 while((-f $SERVERLOGS_LOCK) && $lockretry--) {
2137 select(undef, undef, undef, 0.25);
2139 if(($lockretry < 0) &&
2140 ($serverlogslocktimeout >= $defserverlogslocktimeout)) {
2141 logmsg "Warning: server logs lock timeout ",
2142 "($serverlogslocktimeout seconds) expired\n";
2146 # Test harness ssh server does not have this synchronization mechanism,
2147 # this implies that some ssh server based tests might need a small delay
2148 # once that the client command has run to avoid false test failures.
2150 sleep($postcommanddelay) if($postcommanddelay);
2152 # run the postcheck command
2153 my @postcheck= getpart("client", "postcheck");
2154 $cmd = $postcheck[0];
2155 chomp $cmd;
2156 subVariables \$cmd;
2157 if($cmd) {
2158 logmsg "postcheck $cmd\n" if($verbose);
2159 my $rc = runclient("$cmd");
2160 # Must run the postcheck command in torture mode in order
2161 # to clean up, but the result can't be relied upon.
2162 if($rc != 0 && !$torture) {
2163 logmsg " postcheck FAILED\n";
2164 return 1;
2168 # remove the special FTP command file after each test!
2169 unlink($FTPDCMD);
2171 my $e;
2172 for $e (@envs) {
2173 $ENV{$e}=""; # clean up
2176 # Skip all the verification on torture tests
2177 if ($torture) {
2178 if(!$cmdres && !$keepoutfiles) {
2179 cleardir($LOGDIR);
2181 return $cmdres;
2184 my @err = getpart("verify", "errorcode");
2185 my $errorcode = $err[0] || "0";
2186 my $ok="";
2187 my $res;
2188 if (@validstdout) {
2189 # verify redirected stdout
2190 my @actual = loadarray($STDOUT);
2192 # variable-replace in the stdout we have from the test case file
2193 @validstdout = fixarray(@validstdout);
2195 # get all attributes
2196 my %hash = getpartattr("verify", "stdout");
2198 # get the mode attribute
2199 my $filemode=$hash{'mode'};
2200 if(($filemode eq "text") && $has_textaware) {
2201 # text mode when running on windows: fix line endings
2202 map s/\r\n/\n/g, @actual;
2205 if($hash{'nonewline'}) {
2206 # Yes, we must cut off the final newline from the final line
2207 # of the protocol data
2208 chomp($validstdout[$#validstdout]);
2211 $res = compare("stdout", \@actual, \@validstdout);
2212 if($res) {
2213 return 1;
2215 $ok .= "s";
2217 else {
2218 $ok .= "-"; # stdout not checked
2221 my %replyattr = getpartattr("reply", "data");
2222 if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
2223 # verify the received data
2224 my @out = loadarray($CURLOUT);
2225 my %hash = getpartattr("reply", "data");
2226 # get the mode attribute
2227 my $filemode=$hash{'mode'};
2228 if(($filemode eq "text") && $has_textaware) {
2229 # text mode when running on windows: fix line endings
2230 map s/\r\n/\n/g, @out;
2233 $res = compare("data", \@out, \@reply);
2234 if ($res) {
2235 return 1;
2237 $ok .= "d";
2239 else {
2240 $ok .= "-"; # data not checked
2243 if(@upload) {
2244 # verify uploaded data
2245 my @out = loadarray("$LOGDIR/upload.$testnum");
2246 $res = compare("upload", \@out, \@upload);
2247 if ($res) {
2248 return 1;
2250 $ok .= "u";
2252 else {
2253 $ok .= "-"; # upload not checked
2256 if(@protocol) {
2257 # Verify the sent request
2258 my @out = loadarray($SERVERIN);
2260 # what to cut off from the live protocol sent by curl
2261 my @strip = getpart("verify", "strip");
2263 my @protstrip=@protocol;
2265 # check if there's any attributes on the verify/protocol section
2266 my %hash = getpartattr("verify", "protocol");
2268 if($hash{'nonewline'}) {
2269 # Yes, we must cut off the final newline from the final line
2270 # of the protocol data
2271 chomp($protstrip[$#protstrip]);
2274 for(@strip) {
2275 # strip off all lines that match the patterns from both arrays
2276 chomp $_;
2277 @out = striparray( $_, \@out);
2278 @protstrip= striparray( $_, \@protstrip);
2281 # what parts to cut off from the protocol
2282 my @strippart = getpart("verify", "strippart");
2283 my $strip;
2284 for $strip (@strippart) {
2285 chomp $strip;
2286 for(@out) {
2287 eval $strip;
2291 $res = compare("protocol", \@out, \@protstrip);
2292 if($res) {
2293 return 1;
2296 $ok .= "p";
2299 else {
2300 $ok .= "-"; # protocol not checked
2303 my @outfile=getpart("verify", "file");
2304 if(@outfile) {
2305 # we're supposed to verify a dynamically generated file!
2306 my %hash = getpartattr("verify", "file");
2308 my $filename=$hash{'name'};
2309 if(!$filename) {
2310 logmsg "ERROR: section verify=>file has no name attribute\n";
2311 stopservers($verbose);
2312 return -1;
2314 my @generated=loadarray($filename);
2316 # what parts to cut off from the file
2317 my @stripfile = getpart("verify", "stripfile");
2319 my $filemode=$hash{'mode'};
2320 if(($filemode eq "text") && $has_textaware) {
2321 # text mode when running on windows means adding an extra
2322 # strip expression
2323 push @stripfile, "s/\r\n/\n/";
2326 my $strip;
2327 for $strip (@stripfile) {
2328 chomp $strip;
2329 for(@generated) {
2330 eval $strip;
2334 @outfile = fixarray(@outfile);
2336 $res = compare("output", \@generated, \@outfile);
2337 if($res) {
2338 return 1;
2341 $ok .= "o";
2343 else {
2344 $ok .= "-"; # output not checked
2347 # accept multiple comma-separated error codes
2348 my @splerr = split(/ *, */, $errorcode);
2349 my $errok;
2350 foreach $e (@splerr) {
2351 if($e == $cmdres) {
2352 # a fine error code
2353 $errok = 1;
2354 last;
2358 if($errok) {
2359 $ok .= "e";
2361 else {
2362 if(!$short) {
2363 printf "\ncurl returned $cmdres, %d was expected\n", $errorcode;
2365 logmsg " exit FAILED\n";
2366 return 1;
2369 @what = getpart("client", "killserver");
2370 for(@what) {
2371 my $serv = $_;
2372 chomp $serv;
2373 if($serv =~ /^ftp(\d*)(-ipv6|)/) {
2374 my ($id, $ext) = ($1, $2);
2375 #print STDERR "SERV $serv $id $ext\n";
2376 ftpkillslave($id, $ext, $verbose);
2378 if($run{$serv}) {
2379 stopserver($run{$serv}); # the pid file is in the hash table
2380 $run{$serv}=0; # clear pid
2382 else {
2383 logmsg "RUN: The $serv server is not running\n";
2387 if($curl_debug) {
2388 if(! -f $memdump) {
2389 logmsg "\n** ALERT! memory debugging with no output file?\n";
2391 else {
2392 my @memdata=`$memanalyze $memdump`;
2393 my $leak=0;
2394 for(@memdata) {
2395 if($_ ne "") {
2396 # well it could be other memory problems as well, but
2397 # we call it leak for short here
2398 $leak=1;
2401 if($leak) {
2402 logmsg "\n** MEMORY FAILURE\n";
2403 logmsg @memdata;
2404 return 1;
2406 else {
2407 $ok .= "m";
2411 else {
2412 $ok .= "-"; # memory not checked
2415 if($valgrind) {
2416 # this is the valid protocol blurb curl should generate
2417 if($usevalgrind) {
2419 opendir(DIR, "log") ||
2420 return 0; # can't open log dir
2421 my @files = readdir(DIR);
2422 closedir(DIR);
2423 my $f;
2424 my $l;
2425 foreach $f (@files) {
2426 if($f =~ /^valgrind$testnum\.pid/) {
2427 $l = $f;
2428 last;
2431 my $src=$ENV{'srcdir'};
2432 if(!$src) {
2433 $src=".";
2435 my @e = valgrindparse($src, $feature{'SSL'}, "$LOGDIR/$l");
2436 if($e[0]) {
2437 logmsg " valgrind ERROR ";
2438 logmsg @e;
2439 return 1;
2441 $ok .= "v";
2443 else {
2444 if(!$short) {
2445 logmsg " valgrind SKIPPED\n";
2447 $ok .= "-"; # skipped
2450 else {
2451 $ok .= "-"; # valgrind not checked
2454 logmsg "$ok " if(!$short);
2456 my $sofar= time()-$start;
2457 my $esttotal = $sofar/$count * $total;
2458 my $estleft = $esttotal - $sofar;
2459 my $left=sprintf("remaining: %02d:%02d",
2460 $estleft/60,
2461 $estleft%60);
2462 printf "OK (%-3d out of %-3d, %s)\n", $count, $total, $left;
2464 # the test succeeded, remove all log files
2465 if(!$keepoutfiles) {
2466 cleardir($LOGDIR);
2469 unlink($FTPDCMD); # remove the instructions for this test
2471 return 0;
2474 #######################################################################
2475 # Stop all running test servers
2476 sub stopservers {
2477 my ($verbose)=@_;
2478 for(keys %run) {
2479 my $server = $_;
2480 my $pids=$run{$server};
2481 my $pid;
2482 my $prev;
2484 foreach $pid (split(" ", $pids)) {
2485 if($pid != $prev) {
2486 # no need to kill same pid twice!
2487 logmsg sprintf("* kill pid for %s => %d\n",
2488 $server, $pid) if($verbose);
2489 stopserver($pid);
2491 $prev = $pid;
2493 delete $run{$server};
2495 ftpkillslaves($verbose);
2498 #######################################################################
2499 # startservers() starts all the named servers
2501 # Returns: string with error reason or blank for success
2503 sub startservers {
2504 my @what = @_;
2505 my ($pid, $pid2);
2506 for(@what) {
2507 my $what = lc($_);
2508 $what =~ s/[^a-z0-9-]//g;
2509 if($what eq "ftp") {
2510 if(!$run{'ftp'}) {
2511 ($pid, $pid2) = runftpserver("", $verbose);
2512 if($pid <= 0) {
2513 return "failed starting FTP server";
2515 printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
2516 $run{'ftp'}="$pid $pid2";
2519 elsif($what eq "ftp2") {
2520 if(!$run{'ftp2'}) {
2521 ($pid, $pid2) = runftpserver("2", $verbose);
2522 if($pid <= 0) {
2523 return "failed starting FTP2 server";
2525 printf ("* pid ftp2 => %d %d\n", $pid, $pid2) if($verbose);
2526 $run{'ftp2'}="$pid $pid2";
2529 elsif($what eq "ftp-ipv6") {
2530 if(!$run{'ftp-ipv6'}) {
2531 ($pid, $pid2) = runftpserver("", $verbose, "ipv6");
2532 if($pid <= 0) {
2533 return "failed starting FTP-IPv6 server";
2535 logmsg sprintf("* pid ftp-ipv6 => %d %d\n", $pid,
2536 $pid2) if($verbose);
2537 $run{'ftp-ipv6'}="$pid $pid2";
2540 elsif($what eq "http") {
2541 if(!$run{'http'}) {
2542 ($pid, $pid2) = runhttpserver($verbose);
2543 if($pid <= 0) {
2544 return "failed starting HTTP server";
2546 printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
2547 $run{'http'}="$pid $pid2";
2550 elsif($what eq "http-ipv6") {
2551 if(!$run{'http-ipv6'}) {
2552 ($pid, $pid2) = runhttpserver($verbose, "IPv6");
2553 if($pid <= 0) {
2554 return "failed starting HTTP-IPv6 server";
2556 logmsg sprintf("* pid http-ipv6 => %d %d\n", $pid, $pid2)
2557 if($verbose);
2558 $run{'http-ipv6'}="$pid $pid2";
2561 elsif($what eq "ftps") {
2562 if(!$stunnel) {
2563 # we can't run ftps tests without stunnel
2564 return "no stunnel";
2566 if(!$ssl_version) {
2567 # we can't run ftps tests if libcurl is SSL-less
2568 return "curl lacks SSL support";
2571 if(!$run{'ftp'}) {
2572 ($pid, $pid2) = runftpserver("", $verbose);
2573 if($pid <= 0) {
2574 return "failed starting FTP server";
2576 printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
2577 $run{'ftp'}="$pid $pid2";
2579 if(!$run{'ftps'}) {
2580 ($pid, $pid2) = runftpsserver($verbose);
2581 if($pid <= 0) {
2582 return "failed starting FTPS server (stunnel)";
2584 logmsg sprintf("* pid ftps => %d %d\n", $pid, $pid2)
2585 if($verbose);
2586 $run{'ftps'}="$pid $pid2";
2589 elsif($what eq "file") {
2590 # we support it but have no server!
2592 elsif($what eq "https") {
2593 if(!$stunnel) {
2594 # we can't run ftps tests without stunnel
2595 return "no stunnel";
2597 if(!$ssl_version) {
2598 # we can't run ftps tests if libcurl is SSL-less
2599 return "curl lacks SSL support";
2602 if(!$run{'http'}) {
2603 ($pid, $pid2) = runhttpserver($verbose);
2604 if($pid <= 0) {
2605 return "failed starting HTTP server";
2607 printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
2608 $run{'http'}="$pid $pid2";
2610 if(!$run{'https'}) {
2611 ($pid, $pid2) = runhttpsserver($verbose);
2612 if($pid <= 0) {
2613 return "failed starting HTTPS server (stunnel)";
2615 logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
2616 if($verbose);
2617 $run{'https'}="$pid $pid2";
2620 elsif($what eq "tftp") {
2621 if(!$run{'tftp'}) {
2622 ($pid, $pid2) = runtftpserver("", $verbose);
2623 if($pid <= 0) {
2624 return "failed starting TFTP server";
2626 printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
2627 $run{'tftp'}="$pid $pid2";
2630 elsif($what eq "tftp-ipv6") {
2631 if(!$run{'tftp-ipv6'}) {
2632 ($pid, $pid2) = runtftpserver("", $verbose, "IPv6");
2633 if($pid <= 0) {
2634 return "failed starting TFTP-IPv6 server";
2636 printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
2637 $run{'tftp-ipv6'}="$pid $pid2";
2640 elsif($what eq "sftp" || $what eq "scp" || $what eq "socks4" || $what eq "socks5" ) {
2641 if(!$run{'ssh'}) {
2642 ($pid, $pid2) = runsshserver("", $verbose);
2643 if($pid <= 0) {
2644 return "failed starting SSH server";
2646 printf ("* pid ssh => %d %d\n", $pid, $pid2) if($verbose);
2647 $run{'ssh'}="$pid $pid2";
2649 if($what eq "socks4" || $what eq "socks5") {
2650 if(!$run{'socks'}) {
2651 ($pid, $pid2) = runsocksserver("", $verbose);
2652 if($pid <= 0) {
2653 return "failed starting socks server";
2655 printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
2656 $run{'socks'}="$pid $pid2";
2659 if($what eq "socks5") {
2660 if(!$sshdid) {
2661 # Not an OpenSSH or SunSSH ssh daemon
2662 logmsg "Not OpenSSH or SunSSH; socks5 tests need at least OpenSSH 3.7\n";
2663 return "failed starting socks5 server";
2665 elsif(($sshdid =~ /OpenSSH/) && ($sshdvernum < 370)) {
2666 # Need OpenSSH 3.7 for socks5 - http://www.openssh.com/txt/release-3.7
2667 logmsg "$sshdverstr insufficient; socks5 tests need at least OpenSSH 3.7\n";
2668 return "failed starting socks5 server";
2670 elsif(($sshdid =~ /SunSSH/) && ($sshdvernum < 100)) {
2671 # Need SunSSH 1.0 for socks5
2672 logmsg "$sshdverstr insufficient; socks5 tests need at least SunSSH 1.0\n";
2673 return "failed starting socks5 server";
2677 elsif($what eq "none") {
2678 logmsg "* starts no server\n" if ($verbose);
2680 else {
2681 warn "we don't support a server for $what";
2682 return "no server for $what";
2685 return 0;
2688 ##############################################################################
2689 # This function makes sure the right set of server is running for the
2690 # specified test case. This is a useful design when we run single tests as not
2691 # all servers need to run then!
2693 # Returns: a string, blank if everything is fine or a reason why it failed
2696 sub serverfortest {
2697 my ($testnum)=@_;
2699 my @what = getpart("client", "server");
2701 if(!$what[0]) {
2702 warn "Test case $testnum has no server(s) specified";
2703 return "no server specified";
2706 for (@what) {
2707 my $proto = lc($_);
2708 chomp $proto;
2709 if (! grep /^$proto$/, @protocols) {
2710 if (substr($proto,0,5) ne "socks") {
2711 return "curl lacks $proto support";
2716 return &startservers(@what);
2719 #######################################################################
2720 # Check options to this test program
2723 my $number=0;
2724 my $fromnum=-1;
2725 my @testthis;
2726 my %disabled;
2727 while(@ARGV) {
2728 if ($ARGV[0] eq "-v") {
2729 # verbose output
2730 $verbose=1;
2732 elsif($ARGV[0] =~ /^-b(.*)/) {
2733 my $portno=$1;
2734 if($portno =~ s/(\d+)$//) {
2735 $base = int $1;
2738 elsif ($ARGV[0] eq "-c") {
2739 # use this path to curl instead of default
2740 $DBGCURL=$CURL=$ARGV[1];
2741 shift @ARGV;
2743 elsif ($ARGV[0] eq "-d") {
2744 # have the servers display protocol output
2745 $debugprotocol=1;
2747 elsif ($ARGV[0] eq "-f") {
2748 # run fork-servers, which makes the server fork for all new
2749 # connections This is NOT what you wanna do without knowing exactly
2750 # why and for what
2751 $forkserver=1;
2753 elsif ($ARGV[0] eq "-g") {
2754 # run this test with gdb
2755 $gdbthis=1;
2757 elsif($ARGV[0] eq "-s") {
2758 # short output
2759 $short=1;
2761 elsif($ARGV[0] eq "-n") {
2762 # no valgrind
2763 undef $valgrind;
2765 elsif($ARGV[0] =~ /^-t(.*)/) {
2766 # torture
2767 $torture=1;
2768 my $xtra = $1;
2770 if($xtra =~ s/(\d+)$//) {
2771 $tortalloc = $1;
2773 # we undef valgrind to make this fly in comparison
2774 undef $valgrind;
2776 elsif($ARGV[0] eq "-a") {
2777 # continue anyway, even if a test fail
2778 $anyway=1;
2780 elsif($ARGV[0] eq "-p") {
2781 $postmortem=1;
2783 elsif($ARGV[0] eq "-l") {
2784 # lists the test case names only
2785 $listonly=1;
2787 elsif($ARGV[0] eq "-k") {
2788 # keep stdout and stderr files after tests
2789 $keepoutfiles=1;
2791 elsif($ARGV[0] eq "-h") {
2792 # show help text
2793 print <<EOHELP
2794 Usage: runtests.pl [options] [test selection(s)]
2795 -a continue even if a test fails
2796 -bN use base port number N for test servers (default $base)
2797 -c path use this curl executable
2798 -d display server debug info
2799 -g run the test case with gdb
2800 -h this help text
2801 -k keep stdout and stderr files present after tests
2802 -l list all test case names/descriptions
2803 -n no valgrind
2804 -p print log file contents when a test fails
2805 -s short output
2806 -t[N] torture (simulate memory alloc failures); N means fail Nth alloc
2807 -v verbose output
2808 [num] like "5 6 9" or " 5 to 22 " to run those tests only
2809 [!num] like "!5 !6 !9" to disable those tests
2810 [keyword] like "IPv6" to select only tests containing the key word
2811 [!keyword] like "!cookies" to disable any tests containing the key word
2812 EOHELP
2814 exit;
2816 elsif($ARGV[0] =~ /^(\d+)/) {
2817 $number = $1;
2818 if($fromnum >= 0) {
2819 for($fromnum .. $number) {
2820 push @testthis, $_;
2822 $fromnum = -1;
2824 else {
2825 push @testthis, $1;
2828 elsif($ARGV[0] =~ /^to$/i) {
2829 $fromnum = $number+1;
2831 elsif($ARGV[0] =~ /^!(\d+)/) {
2832 $fromnum = -1;
2833 $disabled{$1}=$1;
2835 elsif($ARGV[0] =~ /^!(.+)/) {
2836 $disabled_keywords{$1}=$1;
2838 elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
2839 $enabled_keywords{$1}=$1;
2841 else {
2842 print "Unknown option: $ARGV[0]\n";
2843 exit;
2845 shift @ARGV;
2848 if($testthis[0] ne "") {
2849 $TESTCASES=join(" ", @testthis);
2852 if($valgrind) {
2853 # we have found valgrind on the host, use it
2855 # verify that we can invoke it fine
2856 my $code = runclient("valgrind >/dev/null 2>&1");
2858 if(($code>>8) != 1) {
2859 #logmsg "Valgrind failure, disable it\n";
2860 undef $valgrind;
2861 } else {
2863 # since valgrind 2.1.x, '--tool' option is mandatory
2864 # use it, if it is supported by the version installed on the system
2865 runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
2866 if (($? >> 8)==0) {
2867 $valgrind_tool="--tool=memcheck ";
2869 open(C, "<$CURL");
2870 my $l = <C>;
2871 if($l =~ /^\#\!/) {
2872 # A shell script. This is typically when built with libtool,
2873 $valgrind="../libtool --mode=execute $valgrind";
2875 close(C);
2877 # valgrind 3 renamed the --logfile option to --log-file!!!
2878 my $ver=join(' ', runclientoutput("valgrind --version"));
2879 # cut off all but digits and dots
2880 $ver =~ s/[^0-9.]//g;
2882 if($ver >= 3) {
2883 $valgrind_logfile="--log-file";
2888 if ($gdbthis) {
2889 # open the executable curl and read the first 4 bytes of it
2890 open(CHECK, "<$CURL");
2891 my $c;
2892 sysread CHECK, $c, 4;
2893 close(CHECK);
2894 if($c eq "#! /") {
2895 # A shell script. This is typically when built with libtool,
2896 $libtool = 1;
2897 $gdb = "libtool --mode=execute gdb";
2901 $HTTPPORT = $base + 0; # HTTP server port
2902 $HTTPSPORT = $base + 1; # HTTPS server port
2903 $FTPPORT = $base + 2; # FTP server port
2904 $FTPSPORT = $base + 3; # FTPS server port
2905 $HTTP6PORT = $base + 4; # HTTP IPv6 server port (different IP protocol
2906 # but we follow the same port scheme anyway)
2907 $FTP2PORT = $base + 5; # FTP server 2 port
2908 $FTP6PORT = $base + 6; # FTP IPv6 port
2909 $TFTPPORT = $base + 7; # TFTP (UDP) port
2910 $TFTP6PORT = $base + 8; # TFTP IPv6 (UDP) port
2911 $SSHPORT = $base + 9; # SSH (SCP/SFTP) port
2912 $SOCKSPORT = $base + 10; # SOCKS port
2914 #######################################################################
2915 # clear and create logging directory:
2918 cleardir($LOGDIR);
2919 mkdir($LOGDIR, 0777);
2921 #######################################################################
2922 # Output curl version and host info being tested
2925 if(!$listonly) {
2926 checksystem();
2929 #######################################################################
2930 # If 'all' tests are requested, find out all test numbers
2933 if ( $TESTCASES eq "all") {
2934 # Get all commands and find out their test numbers
2935 opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
2936 my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
2937 closedir(DIR);
2939 open(D, "<$TESTDIR/DISABLED");
2940 while(<D>) {
2941 if(/^ *\#/) {
2942 # allow comments
2943 next;
2945 if($_ =~ /(\d+)/) {
2946 $disabled{$1}=$1; # disable this test number
2949 close(D);
2951 $TESTCASES=""; # start with no test cases
2953 # cut off everything but the digits
2954 for(@cmds) {
2955 $_ =~ s/[a-z\/\.]*//g;
2957 # sort the numbers from low to high
2958 foreach my $n (sort { $a <=> $b } @cmds) {
2959 if($disabled{$n}) {
2960 # skip disabled test cases
2961 my $why = "configured as DISABLED";
2962 $skipped++;
2963 $skipped{$why}++;
2964 $teststat[$n]=$why; # store reason for this test case
2965 next;
2967 $TESTCASES .= " $n";
2971 #######################################################################
2972 # Start the command line log
2974 open(CMDLOG, ">$CURLLOG") ||
2975 logmsg "can't log command lines to $CURLLOG\n";
2977 #######################################################################
2979 # Display the contents of the given file. Line endings are canonicalized
2980 # and excessively long files are elided
2981 sub displaylogcontent {
2982 my ($file)=@_;
2983 if(open(SINGLE, "<$file")) {
2984 my $linecount = 0;
2985 my $truncate;
2986 my @tail;
2987 while(my $string = <SINGLE>) {
2988 $string =~ s/\r\n/\n/g;
2989 $string =~ s/[\r\f\032]/\n/g;
2990 $string .= "\n" unless ($string =~ /\n$/);
2991 $string =~ tr/\n//;
2992 for my $line (split("\n", $string)) {
2993 $line =~ s/\s*\!$//;
2994 if ($truncate) {
2995 push @tail, " $line\n";
2996 } else {
2997 logmsg " $line\n";
2999 $linecount++;
3000 $truncate = $linecount > 1000;
3003 if (@tail) {
3004 logmsg "=== File too long: lines here were removed\n";
3005 # This won't work properly if time stamps are enabled in logmsg
3006 logmsg join('',@tail[$#tail-200..$#tail]);
3008 close(SINGLE);
3012 sub displaylogs {
3013 my ($testnum)=@_;
3014 opendir(DIR, "$LOGDIR") ||
3015 die "can't open dir: $!";
3016 my @logs = readdir(DIR);
3017 closedir(DIR);
3019 logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
3020 foreach my $log (sort @logs) {
3021 if($log =~ /\.(\.|)$/) {
3022 next; # skip "." and ".."
3024 if($log =~ /^\.nfs/) {
3025 next; # skip ".nfs"
3027 if(($log eq "memdump") || ($log eq "core")) {
3028 next; # skip "memdump" and "core"
3030 if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
3031 next; # skip directory and empty files
3033 if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
3034 next; # skip stdoutNnn of other tests
3036 if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
3037 next; # skip stderrNnn of other tests
3039 if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
3040 next; # skip uploadNnn of other tests
3042 if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
3043 next; # skip curlNnn.out of other tests
3045 if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
3046 next; # skip testNnn.txt of other tests
3048 if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
3049 next; # skip fileNnn.txt of other tests
3051 if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum/)) {
3052 next; # skip valgrindNnn of other tests
3054 logmsg "=== Start of file $log\n";
3055 displaylogcontent("$LOGDIR/$log");
3056 logmsg "=== End of file $log\n";
3060 #######################################################################
3061 # The main test-loop
3064 my $failed;
3065 my $testnum;
3066 my $ok=0;
3067 my $total=0;
3068 my $lasttest;
3069 my @at = split(" ", $TESTCASES);
3070 my $count=0;
3072 $start = time();
3074 foreach $testnum (@at) {
3076 $lasttest = $testnum if($testnum > $lasttest);
3077 $count++;
3079 my $error = singletest($testnum, $count, scalar(@at));
3080 if($error < 0) {
3081 # not a test we can run
3082 next;
3085 $total++; # number of tests we've run
3087 if($error>0) {
3088 $failed.= "$testnum ";
3089 if($postmortem) {
3090 # display all files in log/ in a nice way
3091 displaylogs($testnum);
3093 if(!$anyway) {
3094 # a test failed, abort
3095 logmsg "\n - abort tests\n";
3096 last;
3099 elsif(!$error) {
3100 $ok++; # successful test counter
3103 # loop for next test
3106 #######################################################################
3107 # Close command log
3109 close(CMDLOG);
3111 # Tests done, stop the servers
3112 stopservers($verbose);
3114 unlink($SOCKSPIDFILE);
3116 my $all = $total + $skipped;
3118 if($total) {
3119 logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
3120 $ok/$total*100);
3122 if($ok != $total) {
3123 logmsg "TESTFAIL: These test cases failed: $failed\n";
3126 else {
3127 logmsg "TESTFAIL: No tests were performed\n";
3130 if($all) {
3131 my $sofar = time()-$start;
3132 logmsg "TESTDONE: $all tests were considered during $sofar seconds.\n";
3135 if($skipped) {
3136 my $s=0;
3137 logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
3139 for(keys %skipped) {
3140 my $r = $_;
3141 printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
3143 # now show all test case numbers that had this reason for being
3144 # skipped
3145 my $c=0;
3146 for(0 .. scalar @teststat) {
3147 my $t = $_;
3148 if($teststat[$_] eq $r) {
3149 logmsg ", " if($c);
3150 logmsg $_;
3151 $c++;
3154 logmsg ")\n";
3158 if($total && ($ok != $total)) {
3159 exit 1;