Debian Codegraph @

deps/curl/tests/runtests.pl

raw
1 #!/usr/bin/env perl
2 #***************************************************************************
3 # _ _ ____ _
4 # Project ___| | | | _ \| |
5 # / __| | | | |_) | |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
8 #
9 # Copyright (C) 1998 - 2020, Daniel Stenberg, <[email protected]>, et al.
10 #
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 https://curl.haxx.se/docs/copyright.html.
14 #
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.
18 #
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
21 #
22 ###########################################################################
23
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:
27 #
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
36 # and ssh.
37 #
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.
42 #
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..."
48 #
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.
54
55
56 # These should be the only variables that might be needed to get edited:
57
58 BEGIN {
59 push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
60 push(@INC, ".");
61 # run time statistics needs Time::HiRes
62 eval {
63 no warnings "all";
64 require Time::HiRes;
65 import Time::HiRes qw( time );
66 }
67 }
68
69 use strict;
70 use warnings;
71 use Cwd;
72 use Digest::MD5 qw(md5);
73
74 # Subs imported from serverhelp module
75 use serverhelp qw(
76 serverfactors
77 servername_id
78 servername_str
79 servername_canon
80 server_pidfilename
81 server_logfilename
82 );
83
84 # Variables and subs imported from sshhelp module
85 use sshhelp qw(
86 $sshdexe
87 $sshexe
88 $sftpexe
89 $sshconfig
90 $sftpconfig
91 $sshdlog
92 $sshlog
93 $sftplog
94 $sftpcmds
95 display_sshdconfig
96 display_sshconfig
97 display_sftpconfig
98 display_sshdlog
99 display_sshlog
100 display_sftplog
101 exe_ext
102 find_sshd
103 find_ssh
104 find_sftp
105 find_httptlssrv
106 sshversioninfo
107 );
108
109 use pathhelp;
110
111 require "getpart.pm"; # array functions
112 require "valgrind.pm"; # valgrind report parser
113 require "ftp.pm";
114 require "azure.pm";
115 require "appveyor.pm";
116
117 my $HOSTIP="127.0.0.1"; # address on which the test server listens
118 my $HOST6IP="[::1]"; # address on which the test server listens
119 my $CLIENTIP="127.0.0.1"; # address which curl uses for incoming connections
120 my $CLIENT6IP="[::1]"; # address which curl uses for incoming connections
121
122 my $base = 8990; # base port number
123
124 my $HTTPPORT; # HTTP server port
125 my $HTTP6PORT; # HTTP IPv6 server port
126 my $HTTPSPORT; # HTTPS (stunnel) server port
127 my $FTPPORT; # FTP server port
128 my $FTP2PORT; # FTP server 2 port
129 my $FTPSPORT; # FTPS (stunnel) server port
130 my $FTP6PORT; # FTP IPv6 server port
131 my $TFTPPORT; # TFTP
132 my $TFTP6PORT; # TFTP
133 my $SSHPORT; # SCP/SFTP
134 my $SOCKSPORT; # SOCKS4/5 port
135 my $POP3PORT; # POP3
136 my $POP36PORT; # POP3 IPv6 server port
137 my $IMAPPORT; # IMAP
138 my $IMAP6PORT; # IMAP IPv6 server port
139 my $SMTPPORT; # SMTP
140 my $SMTP6PORT; # SMTP IPv6 server port
141 my $RTSPPORT; # RTSP
142 my $RTSP6PORT; # RTSP IPv6 server port
143 my $GOPHERPORT; # Gopher
144 my $GOPHER6PORT; # Gopher IPv6 server port
145 my $HTTPTLSPORT; # HTTP TLS (non-stunnel) server port
146 my $HTTPTLS6PORT; # HTTP TLS (non-stunnel) IPv6 server port
147 my $HTTPPROXYPORT; # HTTP proxy port, when using CONNECT
148 my $HTTPUNIXPATH; # HTTP server Unix domain socket path
149 my $HTTP2PORT; # HTTP/2 server port
150 my $DICTPORT; # DICT server port
151 my $SMBPORT; # SMB server port
152 my $SMBSPORT; # SMBS server port
153 my $NEGTELNETPORT; # TELNET server port with negotiation
154
155 my $srcdir = $ENV{'srcdir'} || '.';
156 my $CURL="../src/curl".exe_ext('TOOL'); # what curl executable to run on the tests
157 my $VCURL=$CURL; # what curl binary to use to verify the servers with
158 # VCURL is handy to set to the system one when the one you
159 # just built hangs or crashes and thus prevent verification
160 my $DBGCURL=$CURL; #"../src/.libs/curl"; # alternative for debugging
161 my $LOGDIR="log";
162 my $TESTDIR="$srcdir/data";
163 my $LIBDIR="./libtest";
164 my $UNITDIR="./unit";
165 # TODO: change this to use server_inputfilename()
166 my $SERVERIN="$LOGDIR/server.input"; # what curl sent the server
167 my $SERVER2IN="$LOGDIR/server2.input"; # what curl sent the second server
168 my $PROXYIN="$LOGDIR/proxy.input"; # what curl sent the proxy
169 my $CURLLOG="commands.log"; # all command lines run
170 my $FTPDCMD="$LOGDIR/ftpserver.cmd"; # copy ftp server instructions here
171 my $SERVERLOGS_LOCK="$LOGDIR/serverlogs.lock"; # server logs advisor read lock
172 my $CURLCONFIG="../curl-config"; # curl-config from current build
173
174 # Normally, all test cases should be run, but at times it is handy to
175 # simply run a particular one:
176 my $TESTCASES="all";
177
178 # To run specific test cases, set them like:
179 # $TESTCASES="1 2 3 7 8";
180
181 #######################################################################
182 # No variables below this point should need to be modified
183 #
184
185 # invoke perl like this:
186 my $perl="perl -I$srcdir";
187 my $server_response_maxtime=13;
188
189 my $debug_build=0; # built debug enabled (--enable-debug)
190 my $has_memory_tracking=0; # built with memory tracking (--enable-curldebug)
191 my $libtool;
192 my $repeat = 0;
193
194 # name of the file that the memory debugging creates:
195 my $memdump="$LOGDIR/memdump";
196
197 # the path to the script that analyzes the memory debug output file:
198 my $memanalyze="$perl $srcdir/memanalyze.pl";
199
200 my $pwd = getcwd(); # current working directory
201 my $posix_pwd = $pwd;
202
203 my $start;
204 my $ftpchecktime=1; # time it took to verify our test FTP server
205 my $scrambleorder;
206 my $stunnel = checkcmd("stunnel4") || checkcmd("tstunnel") || checkcmd("stunnel");
207 my $valgrind = checktestcmd("valgrind");
208 my $valgrind_logfile="--logfile";
209 my $valgrind_tool;
210 my $gdb = checktestcmd("gdb");
211 my $httptlssrv = find_httptlssrv();
212
213 my $uname_release = `uname -r`;
214 my $is_wsl = $uname_release =~ /Microsoft$/;
215
216 my $has_ssl; # set if libcurl is built with SSL support
217 my $has_largefile; # set if libcurl is built with large file support
218 my $has_idn; # set if libcurl is built with IDN support
219 my $http_ipv6; # set if HTTP server has IPv6 support
220 my $http_unix; # set if HTTP server has Unix sockets support
221 my $ftp_ipv6; # set if FTP server has IPv6 support
222 my $tftp_ipv6; # set if TFTP server has IPv6 support
223 my $gopher_ipv6; # set if Gopher server has IPv6 support
224 my $has_ipv6; # set if libcurl is built with IPv6 support
225 my $has_unix; # set if libcurl is built with Unix sockets support
226 my $has_libz; # set if libcurl is built with libz support
227 my $has_brotli; # set if libcurl is built with brotli support
228 my $has_getrlimit; # set if system has getrlimit()
229 my $has_ntlm; # set if libcurl is built with NTLM support
230 my $has_ntlm_wb; # set if libcurl is built with NTLM delegation to winbind
231 my $has_sspi; # set if libcurl is built with Windows SSPI
232 my $has_gssapi; # set if libcurl is built with a GSS-API library
233 my $has_kerberos; # set if libcurl is built with Kerberos support
234 my $has_spnego; # set if libcurl is built with SPNEGO support
235 my $has_charconv; # set if libcurl is built with CharConv support
236 my $has_tls_srp; # set if libcurl is built with TLS-SRP support
237 my $has_metalink; # set if curl is built with Metalink support
238 my $has_http2; # set if libcurl is built with HTTP2 support
239 my $has_crypto; # set if libcurl is built with cryptographic support
240 my $has_cares; # set if built with c-ares
241 my $has_threadedres;# set if built with threaded resolver
242 my $has_psl; # set if libcurl is built with PSL support
243 my $has_altsvc; # set if libcurl is built with alt-svc support
244 my $has_ldpreload; # set if curl is built for systems supporting LD_PRELOAD
245 my $has_multissl; # set if curl is build with MultiSSL support
246 my $has_manual; # set if curl is built with built-in manual
247 my $has_win32; # set if curl is built for Windows
248
249 # this version is decided by the particular nghttp2 library that is being used
250 my $h2cver = "h2c";
251
252 my $has_openssl; # built with a lib using an OpenSSL-like API
253 my $has_gnutls; # built with GnuTLS
254 my $has_nss; # built with NSS
255 my $has_wolfssl; # built with wolfSSL
256 my $has_polarssl; # built with polarssl
257 my $has_winssl; # built with WinSSL (Secure Channel aka Schannel)
258 my $has_darwinssl; # built with DarwinSSL (Secure Transport)
259 my $has_boringssl; # built with BoringSSL
260 my $has_libressl; # built with libressl
261 my $has_mbedtls; # built with mbedTLS
262 my $has_mesalink; # built with MesaLink
263
264 my $has_sslpinning; # built with a TLS backend that supports pinning
265
266 my $has_shared = "unknown"; # built shared
267
268 my $resolver; # name of the resolver backend (for human presentation)
269
270 my $has_textaware; # set if running on a system that has a text mode concept
271 # on files. Windows for example
272
273 my @protocols; # array of lowercase supported protocol servers
274
275 my $skipped=0; # number of tests skipped; reported in main loop
276 my %skipped; # skipped{reason}=counter, reasons for skip
277 my @teststat; # teststat[testnum]=reason, reasons for skip
278 my %disabled_keywords; # key words of tests to skip
279 my %ignored_keywords; # key words of tests to ignore results
280 my %enabled_keywords; # key words of tests to run
281 my %disabled; # disabled test cases
282 my %ignored; # ignored results of test cases
283
284 my $sshdid; # for socks server, ssh daemon version id
285 my $sshdvernum; # for socks server, ssh daemon version number
286 my $sshdverstr; # for socks server, ssh daemon version string
287 my $sshderror; # for socks server, ssh daemon version error
288
289 my $defserverlogslocktimeout = 2; # timeout to await server logs lock removal
290 my $defpostcommanddelay = 0; # delay between command and postcheck sections
291
292 my $timestats; # time stamping and stats generation
293 my $fullstats; # show time stats for every single test
294 my %timeprepini; # timestamp for each test preparation start
295 my %timesrvrini; # timestamp for each test required servers verification start
296 my %timesrvrend; # timestamp for each test required servers verification end
297 my %timetoolini; # timestamp for each test command run starting
298 my %timetoolend; # timestamp for each test command run stopping
299 my %timesrvrlog; # timestamp for each test server logs lock removal
300 my %timevrfyend; # timestamp for each test result verification end
301
302 my $testnumcheck; # test number, set in singletest sub.
303 my %oldenv;
304 my %feature; # array of enabled features
305 my %keywords; # array of keywords from the test spec
306
307 #######################################################################
308 # variables that command line options may set
309 #
310
311 my $short;
312 my $automakestyle;
313 my $verbose;
314 my $debugprotocol;
315 my $anyway;
316 my $gdbthis; # run test case with gdb debugger
317 my $gdbxwin; # use windowed gdb when using gdb
318 my $keepoutfiles; # keep stdout and stderr files after tests
319 my $listonly; # only list the tests
320 my $postmortem; # display detailed info about failed tests
321 my $run_event_based; # run curl with --test-event to test the event API
322
323 my %run; # running server
324 my %doesntrun; # servers that don't work, identified by pidfile
325 my %serverpidfile;# all server pid file names, identified by server id
326 my %runcert; # cert file currently in use by an ssl running server
327
328 # torture test variables
329 my $torture;
330 my $tortnum;
331 my $tortalloc;
332 my $shallow;
333 my $randseed = 0;
334
335 # Azure Pipelines specific variables
336 my $AZURE_RUN_ID = 0;
337 my $AZURE_RESULT_ID = 0;
338
339 #######################################################################
340 # logmsg is our general message logging subroutine.
341 #
342 sub logmsg {
343 for(@_) {
344 my $line = $_;
345 if ($is_wsl) {
346 # use \r\n for WSL shell
347 $line =~ s/\r?\n$/\r\n/g;
348 }
349 print "$line";
350 }
351 }
352
353 # get the name of the current user
354 my $USER = $ENV{USER}; # Linux
355 if (!$USER) {
356 $USER = $ENV{USERNAME}; # Windows
357 if (!$USER) {
358 $USER = $ENV{LOGNAME}; # Some Unix (I think)
359 }
360 }
361
362 # enable memory debugging if curl is compiled with it
363 $ENV{'CURL_MEMDEBUG'} = $memdump;
364 $ENV{'CURL_ENTROPY'}="12345678";
365 $ENV{'CURL_FORCETIME'}=1; # for debug NTLM magic
366 $ENV{'HOME'}=$pwd;
367 $ENV{'COLUMNS'}=79; # screen width!
368
369 sub catch_zap {
370 my $signame = shift;
371 logmsg "runtests.pl received SIG$signame, exiting\n";
372 stopservers($verbose);
373 die "Somebody sent me a SIG$signame";
374 }
375 $SIG{INT} = \&catch_zap;
376 $SIG{TERM} = \&catch_zap;
377
378 ##########################################################################
379 # Clear all possible '*_proxy' environment variables for various protocols
380 # to prevent them to interfere with our testing!
381
382 my $protocol;
383 foreach $protocol (('ftp', 'http', 'ftps', 'https', 'no', 'all')) {
384 my $proxy = "${protocol}_proxy";
385 # clear lowercase version
386 delete $ENV{$proxy} if($ENV{$proxy});
387 # clear uppercase version
388 delete $ENV{uc($proxy)} if($ENV{uc($proxy)});
389 }
390
391 # make sure we don't get affected by other variables that control our
392 # behaviour
393
394 delete $ENV{'SSL_CERT_DIR'} if($ENV{'SSL_CERT_DIR'});
395 delete $ENV{'SSL_CERT_PATH'} if($ENV{'SSL_CERT_PATH'});
396 delete $ENV{'CURL_CA_BUNDLE'} if($ENV{'CURL_CA_BUNDLE'});
397
398 #######################################################################
399 # Load serverpidfile hash with pidfile names for all possible servers.
400 #
401 sub init_serverpidfile_hash {
402 for my $proto (('ftp', 'http', 'imap', 'pop3', 'smtp', 'http/2')) {
403 for my $ssl (('', 's')) {
404 for my $ipvnum ((4, 6)) {
405 for my $idnum ((1, 2, 3)) {
406 my $serv = servername_id("$proto$ssl", $ipvnum, $idnum);
407 my $pidf = server_pidfilename("$proto$ssl", $ipvnum, $idnum);
408 $serverpidfile{$serv} = $pidf;
409 }
410 }
411 }
412 }
413 for my $proto (('tftp', 'sftp', 'socks', 'ssh', 'rtsp', 'gopher', 'httptls',
414 'dict', 'smb', 'smbs', 'telnet')) {
415 for my $ipvnum ((4, 6)) {
416 for my $idnum ((1, 2)) {
417 my $serv = servername_id($proto, $ipvnum, $idnum);
418 my $pidf = server_pidfilename($proto, $ipvnum, $idnum);
419 $serverpidfile{$serv} = $pidf;
420 }
421 }
422 }
423 for my $proto (('http', 'imap', 'pop3', 'smtp', 'http/2')) {
424 for my $ssl (('', 's')) {
425 my $serv = servername_id("$proto$ssl", "unix", 1);
426 my $pidf = server_pidfilename("$proto$ssl", "unix", 1);
427 $serverpidfile{$serv} = $pidf;
428 }
429 }
430 }
431
432 #######################################################################
433 # Check if a given child process has just died. Reaps it if so.
434 #
435 sub checkdied {
436 use POSIX ":sys_wait_h";
437 my $pid = $_[0];
438 if((not defined $pid) || $pid <= 0) {
439 return 0;
440 }
441 my $rc = waitpid($pid, &WNOHANG);
442 return ($rc == $pid)?1:0;
443 }
444
445 #######################################################################
446 # Start a new thread/process and run the given command line in there.
447 # Return the pids (yes plural) of the new child process to the parent.
448 #
449 sub startnew {
450 my ($cmd, $pidfile, $timeout, $fake)=@_;
451
452 logmsg "startnew: $cmd\n" if ($verbose);
453
454 my $child = fork();
455 my $pid2 = 0;
456
457 if(not defined $child) {
458 logmsg "startnew: fork() failure detected\n";
459 return (-1,-1);
460 }
461
462 if(0 == $child) {
463 # Here we are the child. Run the given command.
464
465 # Put an "exec" in front of the command so that the child process
466 # keeps this child's process ID.
467 exec("exec $cmd") || die "Can't exec() $cmd: $!";
468
469 # exec() should never return back here to this process. We protect
470 # ourselves by calling die() just in case something goes really bad.
471 die "error: exec() has returned";
472 }
473
474 # Ugly hack but ssh client and gnutls-serv don't support pid files
475 if ($fake) {
476 if(open(OUT, ">$pidfile")) {
477 print OUT $child . "\n";
478 close(OUT);
479 logmsg "startnew: $pidfile faked with pid=$child\n" if($verbose);
480 }
481 else {
482 logmsg "startnew: failed to write fake $pidfile with pid=$child\n";
483 }
484 # could/should do a while connect fails sleep a bit and loop
485 sleep $timeout;
486 if (checkdied($child)) {
487 logmsg "startnew: child process has failed to start\n" if($verbose);
488 return (-1,-1);
489 }
490 }
491
492 my $count = $timeout;
493 while($count--) {
494 if(-f $pidfile && -s $pidfile && open(PID, "<$pidfile")) {
495 $pid2 = 0 + <PID>;
496 close(PID);
497 if(($pid2 > 0) && pidexists($pid2)) {
498 # if $pid2 is valid, then make sure this pid is alive, as
499 # otherwise it is just likely to be the _previous_ pidfile or
500 # similar!
501 last;
502 }
503 # invalidate $pid2 if not actually alive
504 $pid2 = 0;
505 }
506 if (checkdied($child)) {
507 logmsg "startnew: child process has died, server might start up\n"
508 if($verbose);
509 # We can't just abort waiting for the server with a
510 # return (-1,-1);
511 # because the server might have forked and could still start
512 # up normally. Instead, just reduce the amount of time we remain
513 # waiting.
514 $count >>= 2;
515 }
516 sleep(1);
517 }
518
519 # Return two PIDs, the one for the child process we spawned and the one
520 # reported by the server itself (in case it forked again on its own).
521 # Both (potentially) need to be killed at the end of the test.
522 return ($child, $pid2);
523 }
524
525
526 #######################################################################
527 # Check for a command in the PATH of the test server.
528 #
529 sub checkcmd {
530 my ($cmd)=@_;
531 my @paths=(split(":", $ENV{'PATH'}), "/usr/sbin", "/usr/local/sbin",
532 "/sbin", "/usr/bin", "/usr/local/bin",
533 "./libtest/.libs", "./libtest");
534 for(@paths) {
535 if( -x "$_/$cmd" && ! -d "$_/$cmd") {
536 # executable bit but not a directory!
537 return "$_/$cmd";
538 }
539 }
540 }
541
542 #######################################################################
543 # Get the list of tests that the tests/data/Makefile.am knows about!
544 #
545 my $disttests;
546 sub get_disttests {
547 my @dist = `cd data && make show`;
548 $disttests = join("", @dist);
549 }
550
551 #######################################################################
552 # Check for a command in the PATH of the machine running curl.
553 #
554 sub checktestcmd {
555 my ($cmd)=@_;
556 return checkcmd($cmd);
557 }
558
559 #######################################################################
560 # Run the application under test and return its return code
561 #
562 sub runclient {
563 my ($cmd)=@_;
564 my $ret = system($cmd);
565 print "CMD ($ret): $cmd\n" if($verbose && !$torture);
566 return $ret;
567
568 # This is one way to test curl on a remote machine
569 # my $out = system("ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'");
570 # sleep 2; # time to allow the NFS server to be updated
571 # return $out;
572 }
573
574 #######################################################################
575 # Run the application under test and return its stdout
576 #
577 sub runclientoutput {
578 my ($cmd)=@_;
579 return `$cmd`;
580
581 # This is one way to test curl on a remote machine
582 # my @out = `ssh $CLIENTIP cd \'$pwd\' \\; \'$cmd\'`;
583 # sleep 2; # time to allow the NFS server to be updated
584 # return @out;
585 }
586
587 #######################################################################
588 # Memory allocation test and failure torture testing.
589 #
590 sub torture {
591 my ($testcmd, $testnum, $gdbline) = @_;
592
593 # remove memdump first to be sure we get a new nice and clean one
594 unlink($memdump);
595
596 # First get URL from test server, ignore the output/result
597 runclient($testcmd);
598
599 logmsg " CMD: $testcmd\n" if($verbose);
600
601 # memanalyze -v is our friend, get the number of allocations made
602 my $count=0;
603 my @out = `$memanalyze -v $memdump`;
604 for(@out) {
605 if(/^Operations: (\d+)/) {
606 $count = $1;
607 last;
608 }
609 }
610 if(!$count) {
611 logmsg " found no functions to make fail\n";
612 return 0;
613 }
614
615 my @ttests = (1 .. $count);
616 if($shallow && ($shallow < $count)) {
617 my $discard = scalar(@ttests) - $shallow;
618 my $percent = sprintf("%.2f%%", $shallow * 100 / scalar(@ttests));;
619 logmsg " $count functions found, but only fail $shallow ($percent)\n";
620 while($discard) {
621 my $rm;
622 do {
623 # find a test to discard
624 $rm = rand(scalar(@ttests));
625 } while(!$ttests[$rm]);
626 $ttests[$rm] = undef;
627 $discard--;
628 }
629 }
630 else {
631 logmsg " $count functions to make fail\n";
632 }
633
634 for (@ttests) {
635 my $limit = $_;
636 my $fail;
637 my $dumped_core;
638
639 if(!defined($limit)) {
640 # --shallow can undefine them
641 next;
642 }
643 if($tortalloc && ($tortalloc != $limit)) {
644 next;
645 }
646
647 if($verbose) {
648 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
649 localtime(time());
650 my $now = sprintf("%02d:%02d:%02d ", $hour, $min, $sec);
651 logmsg "Fail function no: $limit at $now\r";
652 }
653
654 # make the memory allocation function number $limit return failure
655 $ENV{'CURL_MEMLIMIT'} = $limit;
656
657 # remove memdump first to be sure we get a new nice and clean one
658 unlink($memdump);
659
660 my $cmd = $testcmd;
661 if($valgrind && !$gdbthis) {
662 my @valgrindoption = getpart("verify", "valgrind");
663 if((!@valgrindoption) || ($valgrindoption[0] !~ /disable/)) {
664 my $valgrindcmd = "$valgrind ";
665 $valgrindcmd .= "$valgrind_tool " if($valgrind_tool);
666 $valgrindcmd .= "--quiet --leak-check=yes ";
667 $valgrindcmd .= "--suppressions=$srcdir/valgrind.supp ";
668 # $valgrindcmd .= "--gen-suppressions=all ";
669 $valgrindcmd .= "--num-callers=16 ";
670 $valgrindcmd .= "${valgrind_logfile}=$LOGDIR/valgrind$testnum";
671 $cmd = "$valgrindcmd $testcmd";
672 }
673 }
674 logmsg "*** Function number $limit is now set to fail ***\n" if($gdbthis);
675
676 my $ret = 0;
677 if($gdbthis) {
678 runclient($gdbline);
679 }
680 else {
681 $ret = runclient($cmd);
682 }
683 #logmsg "$_ Returned " . ($ret >> 8) . "\n";
684
685 # Now clear the variable again
686 delete $ENV{'CURL_MEMLIMIT'} if($ENV{'CURL_MEMLIMIT'});
687
688 if(-r "core") {
689 # there's core file present now!
690 logmsg " core dumped\n";
691 $dumped_core = 1;
692 $fail = 2;
693 }
694
695 if($valgrind) {
696 my @e = valgrindparse("$LOGDIR/valgrind$testnum");
697 if(@e && $e[0]) {
698 if($automakestyle) {
699 logmsg "FAIL: torture $testnum - valgrind\n";
700 }
701 else {
702 logmsg " valgrind ERROR ";
703 logmsg @e;
704 }
705 $fail = 1;
706 }
707 }
708
709 # verify that it returns a proper error code, doesn't leak memory
710 # and doesn't core dump
711 if(($ret & 255) || ($ret >> 8) >= 128) {
712 logmsg " system() returned $ret\n";
713 $fail=1;
714 }
715 else {
716 my @memdata=`$memanalyze $memdump`;
717 my $leak=0;
718 for(@memdata) {
719 if($_ ne "") {
720 # well it could be other memory problems as well, but
721 # we call it leak for short here
722 $leak=1;
723 }
724 }
725 if($leak) {
726 logmsg "** MEMORY FAILURE\n";
727 logmsg @memdata;
728 logmsg `$memanalyze -l $memdump`;
729 $fail = 1;
730 }
731 }
732 if($fail) {
733 logmsg " Failed on function number $limit in test.\n",
734 " invoke with \"-t$limit\" to repeat this single case.\n";
735 stopservers($verbose);
736 return 1;
737 }
738 }
739
740 logmsg "torture OK\n";
741 return 0;
742 }
743
744 #######################################################################
745 # Stop a test server along with pids which aren't in the %run hash yet.
746 # This also stops all servers which are relative to the given one.
747 #
748 sub stopserver {
749 my ($server, $pidlist) = @_;
750 #
751 # kill sockfilter processes for pingpong relative server
752 #
753 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
754 my $proto = $1;
755 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
756 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
757 killsockfilters($proto, $ipvnum, $idnum, $verbose);
758 }
759 #
760 # All servers relative to the given one must be stopped also
761 #
762 my @killservers;
763 if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
764 # given a stunnel based ssl server, also kill non-ssl underlying one
765 push @killservers, "${1}${2}";
766 }
767 elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|-unix|))$/) {
768 # given a non-ssl server, also kill stunnel based ssl piggybacking one
769 push @killservers, "${1}s${2}";
770 }
771 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
772 # given a socks server, also kill ssh underlying one
773 push @killservers, "ssh${2}";
774 }
775 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
776 # given a ssh server, also kill socks piggybacking one
777 push @killservers, "socks${2}";
778 }
779 push @killservers, $server;
780 #
781 # kill given pids and server relative ones clearing them in %run hash
782 #
783 foreach my $server (@killservers) {
784 if($run{$server}) {
785 # we must prepend a space since $pidlist may already contain a pid
786 $pidlist .= " $run{$server}";
787 $run{$server} = 0;
788 }
789 $runcert{$server} = 0 if($runcert{$server});
790 }
791 killpid($verbose, $pidlist);
792 #
793 # cleanup server pid files
794 #
795 foreach my $server (@killservers) {
796 my $pidfile = $serverpidfile{$server};
797 my $pid = processexists($pidfile);
798 if($pid > 0) {
799 logmsg "Warning: $server server unexpectedly alive\n";
800 killpid($verbose, $pid);
801 }
802 unlink($pidfile) if(-f $pidfile);
803 }
804 }
805
806 #######################################################################
807 # Verify that the server that runs on $ip, $port is our server. This also
808 # implies that we can speak with it, as there might be occasions when the
809 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
810 # assign requested address")
811 #
812 sub verifyhttp {
813 my ($proto, $ipvnum, $idnum, $ip, $port_or_path) = @_;
814 my $server = servername_id($proto, $ipvnum, $idnum);
815 my $pid = 0;
816 my $bonus="";
817 # $port_or_path contains a path for Unix sockets, sws ignores the port
818 my $port = ($ipvnum eq "unix") ? 80 : $port_or_path;
819
820 my $verifyout = "$LOGDIR/".
821 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
822 unlink($verifyout) if(-f $verifyout);
823
824 my $verifylog = "$LOGDIR/".
825 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
826 unlink($verifylog) if(-f $verifylog);
827
828 if($proto eq "gopher") {
829 # gopher is funny
830 $bonus="1/";
831 }
832
833 my $flags = "--max-time $server_response_maxtime ";
834 $flags .= "--output $verifyout ";
835 $flags .= "--silent ";
836 $flags .= "--verbose ";
837 $flags .= "--globoff ";
838 $flags .= "--unix-socket '$port_or_path' " if $ipvnum eq "unix";
839 $flags .= "--insecure " if($proto eq 'https');
840 $flags .= "\"$proto://$ip:$port/${bonus}verifiedserver\"";
841
842 my $cmd = "$VCURL $flags 2>$verifylog";
843
844 # verify if our/any server is running on this port
845 logmsg "RUN: $cmd\n" if($verbose);
846 my $res = runclient($cmd);
847
848 $res >>= 8; # rotate the result
849 if($res & 128) {
850 logmsg "RUN: curl command died with a coredump\n";
851 return -1;
852 }
853
854 if($res && $verbose) {
855 logmsg "RUN: curl command returned $res\n";
856 if(open(FILE, "<$verifylog")) {
857 while(my $string = <FILE>) {
858 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
859 }
860 close(FILE);
861 }
862 }
863
864 my $data;
865 if(open(FILE, "<$verifyout")) {
866 while(my $string = <FILE>) {
867 $data = $string;
868 last; # only want first line
869 }
870 close(FILE);
871 }
872
873 if($data && ($data =~ /WE ROOLZ: (\d+)/)) {
874 $pid = 0+$1;
875 }
876 elsif($res == 6) {
877 # curl: (6) Couldn't resolve host '::1'
878 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
879 return -1;
880 }
881 elsif($data || ($res && ($res != 7))) {
882 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
883 return -1;
884 }
885 return $pid;
886 }
887
888 #######################################################################
889 # Verify that the server that runs on $ip, $port is our server. This also
890 # implies that we can speak with it, as there might be occasions when the
891 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
892 # assign requested address")
893 #
894 sub verifyftp {
895 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
896 my $server = servername_id($proto, $ipvnum, $idnum);
897 my $pid = 0;
898 my $time=time();
899 my $extra="";
900
901 my $verifylog = "$LOGDIR/".
902 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
903 unlink($verifylog) if(-f $verifylog);
904
905 if($proto eq "ftps") {
906 $extra .= "--insecure --ftp-ssl-control ";
907 }
908
909 my $flags = "--max-time $server_response_maxtime ";
910 $flags .= "--silent ";
911 $flags .= "--verbose ";
912 $flags .= "--globoff ";
913 $flags .= $extra;
914 $flags .= "\"$proto://$ip:$port/verifiedserver\"";
915
916 my $cmd = "$VCURL $flags 2>$verifylog";
917
918 # check if this is our server running on this port:
919 logmsg "RUN: $cmd\n" if($verbose);
920 my @data = runclientoutput($cmd);
921
922 my $res = $? >> 8; # rotate the result
923 if($res & 128) {
924 logmsg "RUN: curl command died with a coredump\n";
925 return -1;
926 }
927
928 foreach my $line (@data) {
929 if($line =~ /WE ROOLZ: (\d+)/) {
930 # this is our test server with a known pid!
931 $pid = 0+$1;
932 last;
933 }
934 }
935 if($pid <= 0 && @data && $data[0]) {
936 # this is not a known server
937 logmsg "RUN: Unknown server on our $server port: $port\n";
938 return 0;
939 }
940 # we can/should use the time it took to verify the FTP server as a measure
941 # on how fast/slow this host/FTP is.
942 my $took = int(0.5+time()-$time);
943
944 if($verbose) {
945 logmsg "RUN: Verifying our test $server server took $took seconds\n";
946 }
947 $ftpchecktime = $took>=1?$took:1; # make sure it never is below 1
948
949 return $pid;
950 }
951
952 #######################################################################
953 # Verify that the server that runs on $ip, $port is our server. This also
954 # implies that we can speak with it, as there might be occasions when the
955 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
956 # assign requested address")
957 #
958 sub verifyrtsp {
959 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
960 my $server = servername_id($proto, $ipvnum, $idnum);
961 my $pid = 0;
962
963 my $verifyout = "$LOGDIR/".
964 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
965 unlink($verifyout) if(-f $verifyout);
966
967 my $verifylog = "$LOGDIR/".
968 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
969 unlink($verifylog) if(-f $verifylog);
970
971 my $flags = "--max-time $server_response_maxtime ";
972 $flags .= "--output $verifyout ";
973 $flags .= "--silent ";
974 $flags .= "--verbose ";
975 $flags .= "--globoff ";
976 # currently verification is done using http
977 $flags .= "\"http://$ip:$port/verifiedserver\"";
978
979 my $cmd = "$VCURL $flags 2>$verifylog";
980
981 # verify if our/any server is running on this port
982 logmsg "RUN: $cmd\n" if($verbose);
983 my $res = runclient($cmd);
984
985 $res >>= 8; # rotate the result
986 if($res & 128) {
987 logmsg "RUN: curl command died with a coredump\n";
988 return -1;
989 }
990
991 if($res && $verbose) {
992 logmsg "RUN: curl command returned $res\n";
993 if(open(FILE, "<$verifylog")) {
994 while(my $string = <FILE>) {
995 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
996 }
997 close(FILE);
998 }
999 }
1000
1001 my $data;
1002 if(open(FILE, "<$verifyout")) {
1003 while(my $string = <FILE>) {
1004 $data = $string;
1005 last; # only want first line
1006 }
1007 close(FILE);
1008 }
1009
1010 if($data && ($data =~ /RTSP_SERVER WE ROOLZ: (\d+)/)) {
1011 $pid = 0+$1;
1012 }
1013 elsif($res == 6) {
1014 # curl: (6) Couldn't resolve host '::1'
1015 logmsg "RUN: failed to resolve host ($proto://$ip:$port/verifiedserver)\n";
1016 return -1;
1017 }
1018 elsif($data || ($res != 7)) {
1019 logmsg "RUN: Unknown server on our $server port: $port\n";
1020 return -1;
1021 }
1022 return $pid;
1023 }
1024
1025 #######################################################################
1026 # Verify that the ssh server has written out its pidfile, recovering
1027 # the pid from the file and returning it if a process with that pid is
1028 # actually alive.
1029 #
1030 sub verifyssh {
1031 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1032 my $server = servername_id($proto, $ipvnum, $idnum);
1033 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
1034 my $pid = 0;
1035 if(open(FILE, "<$pidfile")) {
1036 $pid=0+<FILE>;
1037 close(FILE);
1038 }
1039 if($pid > 0) {
1040 # if we have a pid it is actually our ssh server,
1041 # since runsshserver() unlinks previous pidfile
1042 if(!pidexists($pid)) {
1043 logmsg "RUN: SSH server has died after starting up\n";
1044 checkdied($pid);
1045 unlink($pidfile);
1046 $pid = -1;
1047 }
1048 }
1049 return $pid;
1050 }
1051
1052 #######################################################################
1053 # Verify that we can connect to the sftp server, properly authenticate
1054 # with generated config and key files and run a simple remote pwd.
1055 #
1056 sub verifysftp {
1057 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1058 my $server = servername_id($proto, $ipvnum, $idnum);
1059 my $verified = 0;
1060 # Find out sftp client canonical file name
1061 my $sftp = find_sftp();
1062 if(!$sftp) {
1063 logmsg "RUN: SFTP server cannot find $sftpexe\n";
1064 return -1;
1065 }
1066 # Find out ssh client canonical file name
1067 my $ssh = find_ssh();
1068 if(!$ssh) {
1069 logmsg "RUN: SFTP server cannot find $sshexe\n";
1070 return -1;
1071 }
1072 # Connect to sftp server, authenticate and run a remote pwd
1073 # command using our generated configuration and key files
1074 my $cmd = "\"$sftp\" -b $sftpcmds -F $sftpconfig -S \"$ssh\" $ip > $sftplog 2>&1";
1075 my $res = runclient($cmd);
1076 # Search for pwd command response in log file
1077 if(open(SFTPLOGFILE, "<$sftplog")) {
1078 while(<SFTPLOGFILE>) {
1079 if(/^Remote working directory: /) {
1080 $verified = 1;
1081 last;
1082 }
1083 }
1084 close(SFTPLOGFILE);
1085 }
1086 return $verified;
1087 }
1088
1089 #######################################################################
1090 # Verify that the non-stunnel HTTP TLS extensions capable server that runs
1091 # on $ip, $port is our server. This also implies that we can speak with it,
1092 # as there might be occasions when the server runs fine but we cannot talk
1093 # to it ("Failed to connect to ::1: Can't assign requested address")
1094 #
1095 sub verifyhttptls {
1096 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1097 my $server = servername_id($proto, $ipvnum, $idnum);
1098 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
1099 my $pid = 0;
1100
1101 my $verifyout = "$LOGDIR/".
1102 servername_canon($proto, $ipvnum, $idnum) .'_verify.out';
1103 unlink($verifyout) if(-f $verifyout);
1104
1105 my $verifylog = "$LOGDIR/".
1106 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
1107 unlink($verifylog) if(-f $verifylog);
1108
1109 my $flags = "--max-time $server_response_maxtime ";
1110 $flags .= "--output $verifyout ";
1111 $flags .= "--verbose ";
1112 $flags .= "--globoff ";
1113 $flags .= "--insecure ";
1114 $flags .= "--tlsauthtype SRP ";
1115 $flags .= "--tlsuser jsmith ";
1116 $flags .= "--tlspassword abc ";
1117 $flags .= "\"https://$ip:$port/verifiedserver\"";
1118
1119 my $cmd = "$VCURL $flags 2>$verifylog";
1120
1121 # verify if our/any server is running on this port
1122 logmsg "RUN: $cmd\n" if($verbose);
1123 my $res = runclient($cmd);
1124
1125 $res >>= 8; # rotate the result
1126 if($res & 128) {
1127 logmsg "RUN: curl command died with a coredump\n";
1128 return -1;
1129 }
1130
1131 if($res && $verbose) {
1132 logmsg "RUN: curl command returned $res\n";
1133 if(open(FILE, "<$verifylog")) {
1134 while(my $string = <FILE>) {
1135 logmsg "RUN: $string" if($string !~ /^([ \t]*)$/);
1136 }
1137 close(FILE);
1138 }
1139 }
1140
1141 my $data;
1142 if(open(FILE, "<$verifyout")) {
1143 while(my $string = <FILE>) {
1144 $data .= $string;
1145 }
1146 close(FILE);
1147 }
1148
1149 if($data && ($data =~ /(GNUTLS|GnuTLS)/) && open(FILE, "<$pidfile")) {
1150 $pid=0+<FILE>;
1151 close(FILE);
1152 if($pid > 0) {
1153 # if we have a pid it is actually our httptls server,
1154 # since runhttptlsserver() unlinks previous pidfile
1155 if(!pidexists($pid)) {
1156 logmsg "RUN: $server server has died after starting up\n";
1157 checkdied($pid);
1158 unlink($pidfile);
1159 $pid = -1;
1160 }
1161 }
1162 return $pid;
1163 }
1164 elsif($res == 6) {
1165 # curl: (6) Couldn't resolve host '::1'
1166 logmsg "RUN: failed to resolve host (https://$ip:$port/verifiedserver)\n";
1167 return -1;
1168 }
1169 elsif($data || ($res && ($res != 7))) {
1170 logmsg "RUN: Unknown server on our $server port: $port ($res)\n";
1171 return -1;
1172 }
1173 return $pid;
1174 }
1175
1176 #######################################################################
1177 # STUB for verifying socks
1178 #
1179 sub verifysocks {
1180 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1181 my $server = servername_id($proto, $ipvnum, $idnum);
1182 my $pidfile = server_pidfilename($proto, $ipvnum, $idnum);
1183 my $pid = 0;
1184 if(open(FILE, "<$pidfile")) {
1185 $pid=0+<FILE>;
1186 close(FILE);
1187 }
1188 if($pid > 0) {
1189 # if we have a pid it is actually our socks server,
1190 # since runsocksserver() unlinks previous pidfile
1191 if(!pidexists($pid)) {
1192 logmsg "RUN: SOCKS server has died after starting up\n";
1193 checkdied($pid);
1194 unlink($pidfile);
1195 $pid = -1;
1196 }
1197 }
1198 return $pid;
1199 }
1200
1201 #######################################################################
1202 # Verify that the server that runs on $ip, $port is our server. This also
1203 # implies that we can speak with it, as there might be occasions when the
1204 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
1205 # assign requested address")
1206 #
1207 sub verifysmb {
1208 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1209 my $server = servername_id($proto, $ipvnum, $idnum);
1210 my $pid = 0;
1211 my $time=time();
1212 my $extra="";
1213
1214 my $verifylog = "$LOGDIR/".
1215 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
1216 unlink($verifylog) if(-f $verifylog);
1217
1218 my $flags = "--max-time $server_response_maxtime ";
1219 $flags .= "--silent ";
1220 $flags .= "--verbose ";
1221 $flags .= "--globoff ";
1222 $flags .= "-u 'curltest:curltest' ";
1223 $flags .= $extra;
1224 $flags .= "\"$proto://$ip:$port/SERVER/verifiedserver\"";
1225
1226 my $cmd = "$VCURL $flags 2>$verifylog";
1227
1228 # check if this is our server running on this port:
1229 logmsg "RUN: $cmd\n" if($verbose);
1230 my @data = runclientoutput($cmd);
1231
1232 my $res = $? >> 8; # rotate the result
1233 if($res & 128) {
1234 logmsg "RUN: curl command died with a coredump\n";
1235 return -1;
1236 }
1237
1238 foreach my $line (@data) {
1239 if($line =~ /WE ROOLZ: (\d+)/) {
1240 # this is our test server with a known pid!
1241 $pid = 0+$1;
1242 last;
1243 }
1244 }
1245 if($pid <= 0 && @data && $data[0]) {
1246 # this is not a known server
1247 logmsg "RUN: Unknown server on our $server port: $port\n";
1248 return 0;
1249 }
1250 # we can/should use the time it took to verify the server as a measure
1251 # on how fast/slow this host is.
1252 my $took = int(0.5+time()-$time);
1253
1254 if($verbose) {
1255 logmsg "RUN: Verifying our test $server server took $took seconds\n";
1256 }
1257 $ftpchecktime = $took>=1?$took:1; # make sure it never is below 1
1258
1259 return $pid;
1260 }
1261
1262 #######################################################################
1263 # Verify that the server that runs on $ip, $port is our server. This also
1264 # implies that we can speak with it, as there might be occasions when the
1265 # server runs fine but we cannot talk to it ("Failed to connect to ::1: Can't
1266 # assign requested address")
1267 #
1268 sub verifytelnet {
1269 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1270 my $server = servername_id($proto, $ipvnum, $idnum);
1271 my $pid = 0;
1272 my $time=time();
1273 my $extra="";
1274
1275 my $verifylog = "$LOGDIR/".
1276 servername_canon($proto, $ipvnum, $idnum) .'_verify.log';
1277 unlink($verifylog) if(-f $verifylog);
1278
1279 my $flags = "--max-time $server_response_maxtime ";
1280 $flags .= "--silent ";
1281 $flags .= "--verbose ";
1282 $flags .= "--globoff ";
1283 $flags .= "--upload-file - ";
1284 $flags .= $extra;
1285 $flags .= "\"$proto://$ip:$port\"";
1286
1287 my $cmd = "echo 'verifiedserver' | $VCURL $flags 2>$verifylog";
1288
1289 # check if this is our server running on this port:
1290 logmsg "RUN: $cmd\n" if($verbose);
1291 my @data = runclientoutput($cmd);
1292
1293 my $res = $? >> 8; # rotate the result
1294 if($res & 128) {
1295 logmsg "RUN: curl command died with a coredump\n";
1296 return -1;
1297 }
1298
1299 foreach my $line (@data) {
1300 if($line =~ /WE ROOLZ: (\d+)/) {
1301 # this is our test server with a known pid!
1302 $pid = 0+$1;
1303 last;
1304 }
1305 }
1306 if($pid <= 0 && @data && $data[0]) {
1307 # this is not a known server
1308 logmsg "RUN: Unknown server on our $server port: $port\n";
1309 return 0;
1310 }
1311 # we can/should use the time it took to verify the server as a measure
1312 # on how fast/slow this host is.
1313 my $took = int(0.5+time()-$time);
1314
1315 if($verbose) {
1316 logmsg "RUN: Verifying our test $server server took $took seconds\n";
1317 }
1318
1319 return $pid;
1320 }
1321
1322
1323 #######################################################################
1324 # Verify that the server that runs on $ip, $port is our server.
1325 # Retry over several seconds before giving up. The ssh server in
1326 # particular can take a long time to start if it needs to generate
1327 # keys on a slow or loaded host.
1328 #
1329 # Just for convenience, test harness uses 'https' and 'httptls' literals
1330 # as values for 'proto' variable in order to differentiate different
1331 # servers. 'https' literal is used for stunnel based https test servers,
1332 # and 'httptls' is used for non-stunnel https test servers.
1333 #
1334
1335 my %protofunc = ('http' => \&verifyhttp,
1336 'https' => \&verifyhttp,
1337 'rtsp' => \&verifyrtsp,
1338 'ftp' => \&verifyftp,
1339 'pop3' => \&verifyftp,
1340 'imap' => \&verifyftp,
1341 'smtp' => \&verifyftp,
1342 'ftps' => \&verifyftp,
1343 'tftp' => \&verifyftp,
1344 'ssh' => \&verifyssh,
1345 'socks' => \&verifysocks,
1346 'gopher' => \&verifyhttp,
1347 'httptls' => \&verifyhttptls,
1348 'dict' => \&verifyftp,
1349 'smb' => \&verifysmb,
1350 'telnet' => \&verifytelnet);
1351
1352 sub verifyserver {
1353 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1354
1355 my $count = 30; # try for this many seconds
1356 my $pid;
1357
1358 while($count--) {
1359 my $fun = $protofunc{$proto};
1360
1361 $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1362
1363 if($pid > 0) {
1364 last;
1365 }
1366 elsif($pid < 0) {
1367 # a real failure, stop trying and bail out
1368 return 0;
1369 }
1370 sleep(1);
1371 }
1372 return $pid;
1373 }
1374
1375 #######################################################################
1376 # Single shot server responsiveness test. This should only be used
1377 # to verify that a server present in %run hash is still functional
1378 #
1379 sub responsiveserver {
1380 my ($proto, $ipvnum, $idnum, $ip, $port) = @_;
1381 my $prev_verbose = $verbose;
1382
1383 $verbose = 0;
1384 my $fun = $protofunc{$proto};
1385 my $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port);
1386 $verbose = $prev_verbose;
1387
1388 if($pid > 0) {
1389 return 1; # responsive
1390 }
1391
1392 my $srvrname = servername_str($proto, $ipvnum, $idnum);
1393 logmsg " server precheck FAILED (unresponsive $srvrname server)\n";
1394 return 0;
1395 }
1396
1397 #######################################################################
1398 # start the http2 server
1399 #
1400 sub runhttp2server {
1401 my ($verbose, $port) = @_;
1402 my $server;
1403 my $srvrname;
1404 my $pidfile;
1405 my $logfile;
1406 my $flags = "";
1407 my $proto="http/2";
1408 my $ipvnum = 4;
1409 my $idnum = 0;
1410 my $exe = "$perl $srcdir/http2-server.pl";
1411 my $verbose_flag = "--verbose ";
1412
1413 $server = servername_id($proto, $ipvnum, $idnum);
1414
1415 $pidfile = $serverpidfile{$server};
1416
1417 # don't retry if the server doesn't work
1418 if ($doesntrun{$pidfile}) {
1419 return (0,0);
1420 }
1421
1422 my $pid = processexists($pidfile);
1423 if($pid > 0) {
1424 stopserver($server, "$pid");
1425 }
1426 unlink($pidfile) if(-f $pidfile);
1427
1428 $srvrname = servername_str($proto, $ipvnum, $idnum);
1429
1430 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1431
1432 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1433 $flags .= "--port $HTTP2PORT ";
1434 $flags .= "--connect $HOSTIP:$HTTPPORT ";
1435 $flags .= $verbose_flag if($debugprotocol);
1436
1437 my $cmd = "$exe $flags";
1438 my ($http2pid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1439
1440 if($http2pid <= 0 || !pidexists($http2pid)) {
1441 # it is NOT alive
1442 logmsg "RUN: failed to start the $srvrname server\n";
1443 stopserver($server, "$pid2");
1444 $doesntrun{$pidfile} = 1;
1445 return (0,0);
1446 }
1447
1448 if($verbose) {
1449 logmsg "RUN: $srvrname server is now running PID $http2pid\n";
1450 }
1451
1452 return ($http2pid, $pid2);
1453 }
1454
1455 #######################################################################
1456 # start the http server
1457 #
1458 sub runhttpserver {
1459 my ($proto, $verbose, $alt, $port_or_path) = @_;
1460 my $ip = $HOSTIP;
1461 my $ipvnum = 4;
1462 my $idnum = 1;
1463 my $server;
1464 my $srvrname;
1465 my $pidfile;
1466 my $logfile;
1467 my $flags = "";
1468 my $exe = "$perl $srcdir/httpserver.pl";
1469 my $verbose_flag = "--verbose ";
1470
1471 if($alt eq "ipv6") {
1472 # if IPv6, use a different setup
1473 $ipvnum = 6;
1474 $ip = $HOST6IP;
1475 }
1476 elsif($alt eq "proxy") {
1477 # basically the same, but another ID
1478 $idnum = 2;
1479 }
1480 elsif($alt eq "unix") {
1481 # IP (protocol) is mutually exclusive with Unix sockets
1482 $ipvnum = "unix";
1483 }
1484
1485 $server = servername_id($proto, $ipvnum, $idnum);
1486
1487 $pidfile = $serverpidfile{$server};
1488
1489 # don't retry if the server doesn't work
1490 if ($doesntrun{$pidfile}) {
1491 return (0,0);
1492 }
1493
1494 my $pid = processexists($pidfile);
1495 if($pid > 0) {
1496 stopserver($server, "$pid");
1497 }
1498 unlink($pidfile) if(-f $pidfile);
1499
1500 $srvrname = servername_str($proto, $ipvnum, $idnum);
1501
1502 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1503
1504 $flags .= "--gopher " if($proto eq "gopher");
1505 $flags .= "--connect $HOSTIP " if($alt eq "proxy");
1506 $flags .= $verbose_flag if($debugprotocol);
1507 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1508 $flags .= "--id $idnum " if($idnum > 1);
1509 if($ipvnum eq "unix") {
1510 $flags .= "--unix-socket '$port_or_path' ";
1511 } else {
1512 $flags .= "--ipv$ipvnum --port $port_or_path ";
1513 }
1514 $flags .= "--srcdir \"$srcdir\"";
1515
1516 my $cmd = "$exe $flags";
1517 my ($httppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1518
1519 if($httppid <= 0 || !pidexists($httppid)) {
1520 # it is NOT alive
1521 logmsg "RUN: failed to start the $srvrname server\n";
1522 stopserver($server, "$pid2");
1523 displaylogs($testnumcheck);
1524 $doesntrun{$pidfile} = 1;
1525 return (0,0);
1526 }
1527
1528 # Server is up. Verify that we can speak to it.
1529 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port_or_path);
1530 if(!$pid3) {
1531 logmsg "RUN: $srvrname server failed verification\n";
1532 # failed to talk to it properly. Kill the server and return failure
1533 stopserver($server, "$httppid $pid2");
1534 displaylogs($testnumcheck);
1535 $doesntrun{$pidfile} = 1;
1536 return (0,0);
1537 }
1538 $pid2 = $pid3;
1539
1540 if($verbose) {
1541 logmsg "RUN: $srvrname server is now running PID $httppid\n";
1542 }
1543
1544 sleep(1);
1545
1546 return ($httppid, $pid2);
1547 }
1548
1549 #######################################################################
1550 # start the https stunnel based server
1551 #
1552 sub runhttpsserver {
1553 my ($verbose, $ipv6, $certfile) = @_;
1554 my $proto = 'https';
1555 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1556 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1557 my $idnum = 1;
1558 my $server;
1559 my $srvrname;
1560 my $pidfile;
1561 my $logfile;
1562 my $flags = "";
1563
1564 if(!$stunnel) {
1565 return (0,0);
1566 }
1567
1568 $server = servername_id($proto, $ipvnum, $idnum);
1569
1570 $pidfile = $serverpidfile{$server};
1571
1572 # don't retry if the server doesn't work
1573 if ($doesntrun{$pidfile}) {
1574 return (0,0);
1575 }
1576
1577 my $pid = processexists($pidfile);
1578 if($pid > 0) {
1579 stopserver($server, "$pid");
1580 }
1581 unlink($pidfile) if(-f $pidfile);
1582
1583 $srvrname = servername_str($proto, $ipvnum, $idnum);
1584
1585 $certfile = 'stunnel.pem' unless($certfile);
1586
1587 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1588
1589 $flags .= "--verbose " if($debugprotocol);
1590 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1591 $flags .= "--id $idnum " if($idnum > 1);
1592 $flags .= "--ipv$ipvnum --proto $proto ";
1593 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1594 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1595 $flags .= "--connect $HTTPPORT --accept $HTTPSPORT";
1596
1597 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1598 my ($httpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1599
1600 if($httpspid <= 0 || !pidexists($httpspid)) {
1601 # it is NOT alive
1602 logmsg "RUN: failed to start the $srvrname server\n";
1603 stopserver($server, "$pid2");
1604 displaylogs($testnumcheck);
1605 $doesntrun{$pidfile} = 1;
1606 return(0,0);
1607 }
1608
1609 # Server is up. Verify that we can speak to it.
1610 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $HTTPSPORT);
1611 if(!$pid3) {
1612 logmsg "RUN: $srvrname server failed verification\n";
1613 # failed to talk to it properly. Kill the server and return failure
1614 stopserver($server, "$httpspid $pid2");
1615 displaylogs($testnumcheck);
1616 $doesntrun{$pidfile} = 1;
1617 return (0,0);
1618 }
1619 # Here pid3 is actually the pid returned by the unsecure-http server.
1620
1621 $runcert{$server} = $certfile;
1622
1623 if($verbose) {
1624 logmsg "RUN: $srvrname server is now running PID $httpspid\n";
1625 }
1626
1627 sleep(1);
1628
1629 return ($httpspid, $pid2);
1630 }
1631
1632 #######################################################################
1633 # start the non-stunnel HTTP TLS extensions capable server
1634 #
1635 sub runhttptlsserver {
1636 my ($verbose, $ipv6) = @_;
1637 my $proto = "httptls";
1638 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
1639 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1640 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1641 my $idnum = 1;
1642 my $server;
1643 my $srvrname;
1644 my $pidfile;
1645 my $logfile;
1646 my $flags = "";
1647
1648 if(!$httptlssrv) {
1649 return (0,0);
1650 }
1651
1652 $server = servername_id($proto, $ipvnum, $idnum);
1653
1654 $pidfile = $serverpidfile{$server};
1655
1656 # don't retry if the server doesn't work
1657 if ($doesntrun{$pidfile}) {
1658 return (0,0);
1659 }
1660
1661 my $pid = processexists($pidfile);
1662 if($pid > 0) {
1663 stopserver($server, "$pid");
1664 }
1665 unlink($pidfile) if(-f $pidfile);
1666
1667 $srvrname = servername_str($proto, $ipvnum, $idnum);
1668
1669 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1670
1671 $flags .= "--http ";
1672 $flags .= "--debug 1 " if($debugprotocol);
1673 $flags .= "--port $port ";
1674 $flags .= "--priority NORMAL:+SRP ";
1675 $flags .= "--srppasswd $srcdir/certs/srp-verifier-db ";
1676 $flags .= "--srppasswdconf $srcdir/certs/srp-verifier-conf";
1677
1678 my $cmd = "$httptlssrv $flags > $logfile 2>&1";
1679 my ($httptlspid, $pid2) = startnew($cmd, $pidfile, 10, 1); # fake pidfile
1680
1681 if($httptlspid <= 0 || !pidexists($httptlspid)) {
1682 # it is NOT alive
1683 logmsg "RUN: failed to start the $srvrname server\n";
1684 stopserver($server, "$pid2");
1685 displaylogs($testnumcheck);
1686 $doesntrun{$pidfile} = 1;
1687 return (0,0);
1688 }
1689
1690 # Server is up. Verify that we can speak to it. PID is from fake pidfile
1691 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1692 if(!$pid3) {
1693 logmsg "RUN: $srvrname server failed verification\n";
1694 # failed to talk to it properly. Kill the server and return failure
1695 stopserver($server, "$httptlspid $pid2");
1696 displaylogs($testnumcheck);
1697 $doesntrun{$pidfile} = 1;
1698 return (0,0);
1699 }
1700 $pid2 = $pid3;
1701
1702 if($verbose) {
1703 logmsg "RUN: $srvrname server is now running PID $httptlspid\n";
1704 }
1705
1706 sleep(1);
1707
1708 return ($httptlspid, $pid2);
1709 }
1710
1711 #######################################################################
1712 # start the pingpong server (FTP, POP3, IMAP, SMTP)
1713 #
1714 sub runpingpongserver {
1715 my ($proto, $id, $verbose, $ipv6) = @_;
1716 my $port;
1717 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1718 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1719 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1720 my $server;
1721 my $srvrname;
1722 my $pidfile;
1723 my $logfile;
1724 my $flags = "";
1725
1726 if($proto eq "ftp") {
1727 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
1728
1729 if($ipvnum==6) {
1730 # if IPv6, use a different setup
1731 $port = $FTP6PORT;
1732 }
1733 }
1734 elsif($proto eq "pop3") {
1735 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
1736 }
1737 elsif($proto eq "imap") {
1738 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
1739 }
1740 elsif($proto eq "smtp") {
1741 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
1742 }
1743 else {
1744 print STDERR "Unsupported protocol $proto!!\n";
1745 return 0;
1746 }
1747
1748 $server = servername_id($proto, $ipvnum, $idnum);
1749
1750 $pidfile = $serverpidfile{$server};
1751
1752 # don't retry if the server doesn't work
1753 if ($doesntrun{$pidfile}) {
1754 return (0,0);
1755 }
1756
1757 my $pid = processexists($pidfile);
1758 if($pid > 0) {
1759 stopserver($server, "$pid");
1760 }
1761 unlink($pidfile) if(-f $pidfile);
1762
1763 $srvrname = servername_str($proto, $ipvnum, $idnum);
1764
1765 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1766
1767 $flags .= "--verbose " if($debugprotocol);
1768 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1769 $flags .= "--srcdir \"$srcdir\" --proto $proto ";
1770 $flags .= "--id $idnum " if($idnum > 1);
1771 $flags .= "--ipv$ipvnum --port $port --addr \"$ip\"";
1772
1773 my $cmd = "$perl $srcdir/ftpserver.pl $flags";
1774 my ($ftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1775
1776 if($ftppid <= 0 || !pidexists($ftppid)) {
1777 # it is NOT alive
1778 logmsg "RUN: failed to start the $srvrname server\n";
1779 stopserver($server, "$pid2");
1780 displaylogs($testnumcheck);
1781 $doesntrun{$pidfile} = 1;
1782 return (0,0);
1783 }
1784
1785 # Server is up. Verify that we can speak to it.
1786 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1787 if(!$pid3) {
1788 logmsg "RUN: $srvrname server failed verification\n";
1789 # failed to talk to it properly. Kill the server and return failure
1790 stopserver($server, "$ftppid $pid2");
1791 displaylogs($testnumcheck);
1792 $doesntrun{$pidfile} = 1;
1793 return (0,0);
1794 }
1795
1796 $pid2 = $pid3;
1797
1798 if($verbose) {
1799 logmsg "RUN: $srvrname server is now running PID $ftppid\n";
1800 }
1801
1802 sleep(1);
1803
1804 return ($pid2, $ftppid);
1805 }
1806
1807 #######################################################################
1808 # start the ftps server (or rather, tunnel)
1809 #
1810 sub runftpsserver {
1811 my ($verbose, $ipv6, $certfile) = @_;
1812 my $proto = 'ftps';
1813 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
1814 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
1815 my $idnum = 1;
1816 my $server;
1817 my $srvrname;
1818 my $pidfile;
1819 my $logfile;
1820 my $flags = "";
1821
1822 if(!$stunnel) {
1823 return (0,0);
1824 }
1825
1826 $server = servername_id($proto, $ipvnum, $idnum);
1827
1828 $pidfile = $serverpidfile{$server};
1829
1830 # don't retry if the server doesn't work
1831 if ($doesntrun{$pidfile}) {
1832 return (0,0);
1833 }
1834
1835 my $pid = processexists($pidfile);
1836 if($pid > 0) {
1837 stopserver($server, "$pid");
1838 }
1839 unlink($pidfile) if(-f $pidfile);
1840
1841 $srvrname = servername_str($proto, $ipvnum, $idnum);
1842
1843 $certfile = 'stunnel.pem' unless($certfile);
1844
1845 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1846
1847 $flags .= "--verbose " if($debugprotocol);
1848 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1849 $flags .= "--id $idnum " if($idnum > 1);
1850 $flags .= "--ipv$ipvnum --proto $proto ";
1851 $flags .= "--certfile \"$certfile\" " if($certfile ne 'stunnel.pem');
1852 $flags .= "--stunnel \"$stunnel\" --srcdir \"$srcdir\" ";
1853 $flags .= "--connect $FTPPORT --accept $FTPSPORT";
1854
1855 my $cmd = "$perl $srcdir/secureserver.pl $flags";
1856 my ($ftpspid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1857
1858 if($ftpspid <= 0 || !pidexists($ftpspid)) {
1859 # it is NOT alive
1860 logmsg "RUN: failed to start the $srvrname server\n";
1861 stopserver($server, "$pid2");
1862 displaylogs($testnumcheck);
1863 $doesntrun{$pidfile} = 1;
1864 return(0,0);
1865 }
1866
1867 # Server is up. Verify that we can speak to it.
1868 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $FTPSPORT);
1869 if(!$pid3) {
1870 logmsg "RUN: $srvrname server failed verification\n";
1871 # failed to talk to it properly. Kill the server and return failure
1872 stopserver($server, "$ftpspid $pid2");
1873 displaylogs($testnumcheck);
1874 $doesntrun{$pidfile} = 1;
1875 return (0,0);
1876 }
1877 # Here pid3 is actually the pid returned by the unsecure-ftp server.
1878
1879 $runcert{$server} = $certfile;
1880
1881 if($verbose) {
1882 logmsg "RUN: $srvrname server is now running PID $ftpspid\n";
1883 }
1884
1885 sleep(1);
1886
1887 return ($ftpspid, $pid2);
1888 }
1889
1890 #######################################################################
1891 # start the tftp server
1892 #
1893 sub runtftpserver {
1894 my ($id, $verbose, $ipv6) = @_;
1895 my $port = $TFTPPORT;
1896 my $ip = $HOSTIP;
1897 my $proto = 'tftp';
1898 my $ipvnum = 4;
1899 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
1900 my $server;
1901 my $srvrname;
1902 my $pidfile;
1903 my $logfile;
1904 my $flags = "";
1905
1906 if($ipv6) {
1907 # if IPv6, use a different setup
1908 $ipvnum = 6;
1909 $port = $TFTP6PORT;
1910 $ip = $HOST6IP;
1911 }
1912
1913 $server = servername_id($proto, $ipvnum, $idnum);
1914
1915 $pidfile = $serverpidfile{$server};
1916
1917 # don't retry if the server doesn't work
1918 if ($doesntrun{$pidfile}) {
1919 return (0,0);
1920 }
1921
1922 my $pid = processexists($pidfile);
1923 if($pid > 0) {
1924 stopserver($server, "$pid");
1925 }
1926 unlink($pidfile) if(-f $pidfile);
1927
1928 $srvrname = servername_str($proto, $ipvnum, $idnum);
1929
1930 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
1931
1932 $flags .= "--verbose " if($debugprotocol);
1933 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
1934 $flags .= "--id $idnum " if($idnum > 1);
1935 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
1936
1937 my $cmd = "$perl $srcdir/tftpserver.pl $flags";
1938 my ($tftppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
1939
1940 if($tftppid <= 0 || !pidexists($tftppid)) {
1941 # it is NOT alive
1942 logmsg "RUN: failed to start the $srvrname server\n";
1943 stopserver($server, "$pid2");
1944 displaylogs($testnumcheck);
1945 $doesntrun{$pidfile} = 1;
1946 return (0,0);
1947 }
1948
1949 # Server is up. Verify that we can speak to it.
1950 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
1951 if(!$pid3) {
1952 logmsg "RUN: $srvrname server failed verification\n";
1953 # failed to talk to it properly. Kill the server and return failure
1954 stopserver($server, "$tftppid $pid2");
1955 displaylogs($testnumcheck);
1956 $doesntrun{$pidfile} = 1;
1957 return (0,0);
1958 }
1959 $pid2 = $pid3;
1960
1961 if($verbose) {
1962 logmsg "RUN: $srvrname server is now running PID $tftppid\n";
1963 }
1964
1965 sleep(1);
1966
1967 return ($pid2, $tftppid);
1968 }
1969
1970
1971 #######################################################################
1972 # start the rtsp server
1973 #
1974 sub runrtspserver {
1975 my ($verbose, $ipv6) = @_;
1976 my $port = $RTSPPORT;
1977 my $ip = $HOSTIP;
1978 my $proto = 'rtsp';
1979 my $ipvnum = 4;
1980 my $idnum = 1;
1981 my $server;
1982 my $srvrname;
1983 my $pidfile;
1984 my $logfile;
1985 my $flags = "";
1986
1987 if($ipv6) {
1988 # if IPv6, use a different setup
1989 $ipvnum = 6;
1990 $port = $RTSP6PORT;
1991 $ip = $HOST6IP;
1992 }
1993
1994 $server = servername_id($proto, $ipvnum, $idnum);
1995
1996 $pidfile = $serverpidfile{$server};
1997
1998 # don't retry if the server doesn't work
1999 if ($doesntrun{$pidfile}) {
2000 return (0,0);
2001 }
2002
2003 my $pid = processexists($pidfile);
2004 if($pid > 0) {
2005 stopserver($server, "$pid");
2006 }
2007 unlink($pidfile) if(-f $pidfile);
2008
2009 $srvrname = servername_str($proto, $ipvnum, $idnum);
2010
2011 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
2012
2013 $flags .= "--verbose " if($debugprotocol);
2014 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
2015 $flags .= "--id $idnum " if($idnum > 1);
2016 $flags .= "--ipv$ipvnum --port $port --srcdir \"$srcdir\"";
2017
2018 my $cmd = "$perl $srcdir/rtspserver.pl $flags";
2019 my ($rtsppid, $pid2) = startnew($cmd, $pidfile, 15, 0);
2020
2021 if($rtsppid <= 0 || !pidexists($rtsppid)) {
2022 # it is NOT alive
2023 logmsg "RUN: failed to start the $srvrname server\n";
2024 stopserver($server, "$pid2");
2025 displaylogs($testnumcheck);
2026 $doesntrun{$pidfile} = 1;
2027 return (0,0);
2028 }
2029
2030 # Server is up. Verify that we can speak to it.
2031 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2032 if(!$pid3) {
2033 logmsg "RUN: $srvrname server failed verification\n";
2034 # failed to talk to it properly. Kill the server and return failure
2035 stopserver($server, "$rtsppid $pid2");
2036 displaylogs($testnumcheck);
2037 $doesntrun{$pidfile} = 1;
2038 return (0,0);
2039 }
2040 $pid2 = $pid3;
2041
2042 if($verbose) {
2043 logmsg "RUN: $srvrname server is now running PID $rtsppid\n";
2044 }
2045
2046 sleep(1);
2047
2048 return ($rtsppid, $pid2);
2049 }
2050
2051
2052 #######################################################################
2053 # Start the ssh (scp/sftp) server
2054 #
2055 sub runsshserver {
2056 my ($id, $verbose, $ipv6) = @_;
2057 my $ip=$HOSTIP;
2058 my $port = $SSHPORT;
2059 my $proto = 'ssh';
2060 my $ipvnum = 4;
2061 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2062 my $server;
2063 my $srvrname;
2064 my $pidfile;
2065 my $logfile;
2066 my $flags = "";
2067
2068 $server = servername_id($proto, $ipvnum, $idnum);
2069
2070 $pidfile = $serverpidfile{$server};
2071
2072 # don't retry if the server doesn't work
2073 if ($doesntrun{$pidfile}) {
2074 return (0,0);
2075 }
2076
2077 my $pid = processexists($pidfile);
2078 if($pid > 0) {
2079 stopserver($server, "$pid");
2080 }
2081 unlink($pidfile) if(-f $pidfile);
2082
2083 $srvrname = servername_str($proto, $ipvnum, $idnum);
2084
2085 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
2086
2087 $flags .= "--verbose " if($verbose);
2088 $flags .= "--debugprotocol " if($debugprotocol);
2089 $flags .= "--pidfile \"$pidfile\" ";
2090 $flags .= "--id $idnum " if($idnum > 1);
2091 $flags .= "--ipv$ipvnum --addr \"$ip\" ";
2092 $flags .= "--sshport $port ";
2093 $flags .= "--user \"$USER\"";
2094
2095 my $cmd = "$perl $srcdir/sshserver.pl $flags";
2096 my ($sshpid, $pid2) = startnew($cmd, $pidfile, 60, 0);
2097
2098 # on loaded systems sshserver start up can take longer than the timeout
2099 # passed to startnew, when this happens startnew completes without being
2100 # able to read the pidfile and consequently returns a zero pid2 above.
2101
2102 if($sshpid <= 0 || !pidexists($sshpid)) {
2103 # it is NOT alive
2104 logmsg "RUN: failed to start the $srvrname server\n";
2105 stopserver($server, "$pid2");
2106 $doesntrun{$pidfile} = 1;
2107 return (0,0);
2108 }
2109
2110 # ssh server verification allows some extra time for the server to start up
2111 # and gives us the opportunity of recovering the pid from the pidfile, when
2112 # this verification succeeds the recovered pid is assigned to pid2.
2113
2114 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2115 if(!$pid3) {
2116 logmsg "RUN: $srvrname server failed verification\n";
2117 # failed to fetch server pid. Kill the server and return failure
2118 stopserver($server, "$sshpid $pid2");
2119 $doesntrun{$pidfile} = 1;
2120 return (0,0);
2121 }
2122 $pid2 = $pid3;
2123
2124 # once it is known that the ssh server is alive, sftp server verification
2125 # is performed actually connecting to it, authenticating and performing a
2126 # very simple remote command. This verification is tried only one time.
2127
2128 $sshdlog = server_logfilename($LOGDIR, 'ssh', $ipvnum, $idnum);
2129 $sftplog = server_logfilename($LOGDIR, 'sftp', $ipvnum, $idnum);
2130
2131 if(verifysftp('sftp', $ipvnum, $idnum, $ip, $port) < 1) {
2132 logmsg "RUN: SFTP server failed verification\n";
2133 # failed to talk to it properly. Kill the server and return failure
2134 display_sftplog();
2135 display_sftpconfig();
2136 display_sshdlog();
2137 display_sshdconfig();
2138 stopserver($server, "$sshpid $pid2");
2139 $doesntrun{$pidfile} = 1;
2140 return (0,0);
2141 }
2142
2143 if($verbose) {
2144 logmsg "RUN: $srvrname server is now running PID $pid2\n";
2145 }
2146
2147 return ($pid2, $sshpid);
2148 }
2149
2150 #######################################################################
2151 # Start the socks server
2152 #
2153 sub runsocksserver {
2154 my ($id, $verbose, $ipv6) = @_;
2155 my $ip=$HOSTIP;
2156 my $port = $SOCKSPORT;
2157 my $proto = 'socks';
2158 my $ipvnum = 4;
2159 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2160 my $server;
2161 my $srvrname;
2162 my $pidfile;
2163 my $logfile;
2164 my $flags = "";
2165
2166 $server = servername_id($proto, $ipvnum, $idnum);
2167
2168 $pidfile = $serverpidfile{$server};
2169
2170 # don't retry if the server doesn't work
2171 if ($doesntrun{$pidfile}) {
2172 return (0,0);
2173 }
2174
2175 my $pid = processexists($pidfile);
2176 if($pid > 0) {
2177 stopserver($server, "$pid");
2178 }
2179 unlink($pidfile) if(-f $pidfile);
2180
2181 $srvrname = servername_str($proto, $ipvnum, $idnum);
2182
2183 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
2184
2185 # start our socks server, get commands from the FTP cmd file
2186 my $cmd="server/socksd".
2187 " --port $port ".
2188 " --pidfile $pidfile".
2189 " --backend $HOSTIP".
2190 " --config $FTPDCMD";
2191 my ($sockspid, $pid2) = startnew($cmd, $pidfile, 30, 0);
2192
2193 if($sockspid <= 0 || !pidexists($sockspid)) {
2194 # it is NOT alive
2195 logmsg "RUN: failed to start the $srvrname server\n";
2196 stopserver($server, "$pid2");
2197 $doesntrun{$pidfile} = 1;
2198 return (0,0);
2199 }
2200
2201 if($verbose) {
2202 logmsg "RUN: $srvrname server is now running PID $pid2\n";
2203 }
2204
2205 return ($pid2, $sockspid);
2206 }
2207
2208 #######################################################################
2209 # start the dict server
2210 #
2211 sub rundictserver {
2212 my ($verbose, $alt, $port) = @_;
2213 my $proto = "dict";
2214 my $ip = $HOSTIP;
2215 my $ipvnum = 4;
2216 my $idnum = 1;
2217 my $server;
2218 my $srvrname;
2219 my $pidfile;
2220 my $logfile;
2221 my $flags = "";
2222
2223 if($alt eq "ipv6") {
2224 # No IPv6
2225 }
2226
2227 $server = servername_id($proto, $ipvnum, $idnum);
2228
2229 $pidfile = $serverpidfile{$server};
2230
2231 # don't retry if the server doesn't work
2232 if ($doesntrun{$pidfile}) {
2233 return (0,0);
2234 }
2235
2236 my $pid = processexists($pidfile);
2237 if($pid > 0) {
2238 stopserver($server, "$pid");
2239 }
2240 unlink($pidfile) if(-f $pidfile);
2241
2242 $srvrname = servername_str($proto, $ipvnum, $idnum);
2243
2244 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
2245
2246 $flags .= "--verbose 1 " if($debugprotocol);
2247 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
2248 $flags .= "--id $idnum " if($idnum > 1);
2249 $flags .= "--port $port --srcdir \"$srcdir\" ";
2250 $flags .= "--host $HOSTIP";
2251
2252 my $cmd = "$srcdir/dictserver.py $flags";
2253 my ($dictpid, $pid2) = startnew($cmd, $pidfile, 15, 0);
2254
2255 if($dictpid <= 0 || !pidexists($dictpid)) {
2256 # it is NOT alive
2257 logmsg "RUN: failed to start the $srvrname server\n";
2258 stopserver($server, "$pid2");
2259 displaylogs($testnumcheck);
2260 $doesntrun{$pidfile} = 1;
2261 return (0,0);
2262 }
2263
2264 # Server is up. Verify that we can speak to it.
2265 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2266 if(!$pid3) {
2267 logmsg "RUN: $srvrname server failed verification\n";
2268 # failed to talk to it properly. Kill the server and return failure
2269 stopserver($server, "$dictpid $pid2");
2270 displaylogs($testnumcheck);
2271 $doesntrun{$pidfile} = 1;
2272 return (0,0);
2273 }
2274 $pid2 = $pid3;
2275
2276 if($verbose) {
2277 logmsg "RUN: $srvrname server is now running PID $dictpid\n";
2278 }
2279
2280 sleep(1);
2281
2282 return ($dictpid, $pid2);
2283 }
2284
2285 #######################################################################
2286 # start the SMB server
2287 #
2288 sub runsmbserver {
2289 my ($verbose, $alt, $port) = @_;
2290 my $proto = "smb";
2291 my $ip = $HOSTIP;
2292 my $ipvnum = 4;
2293 my $idnum = 1;
2294 my $server;
2295 my $srvrname;
2296 my $pidfile;
2297 my $logfile;
2298 my $flags = "";
2299
2300 if($alt eq "ipv6") {
2301 # No IPv6
2302 }
2303
2304 $server = servername_id($proto, $ipvnum, $idnum);
2305
2306 $pidfile = $serverpidfile{$server};
2307
2308 # don't retry if the server doesn't work
2309 if ($doesntrun{$pidfile}) {
2310 return (0,0);
2311 }
2312
2313 my $pid = processexists($pidfile);
2314 if($pid > 0) {
2315 stopserver($server, "$pid");
2316 }
2317 unlink($pidfile) if(-f $pidfile);
2318
2319 $srvrname = servername_str($proto, $ipvnum, $idnum);
2320
2321 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
2322
2323 $flags .= "--verbose 1 " if($debugprotocol);
2324 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
2325 $flags .= "--id $idnum " if($idnum > 1);
2326 $flags .= "--port $port --srcdir \"$srcdir\" ";
2327 $flags .= "--host $HOSTIP";
2328
2329 my $cmd = "$srcdir/smbserver.py $flags";
2330 my ($smbpid, $pid2) = startnew($cmd, $pidfile, 15, 0);
2331
2332 if($smbpid <= 0 || !pidexists($smbpid)) {
2333 # it is NOT alive
2334 logmsg "RUN: failed to start the $srvrname server\n";
2335 stopserver($server, "$pid2");
2336 displaylogs($testnumcheck);
2337 $doesntrun{$pidfile} = 1;
2338 return (0,0);
2339 }
2340
2341 # Server is up. Verify that we can speak to it.
2342 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2343 if(!$pid3) {
2344 logmsg "RUN: $srvrname server failed verification\n";
2345 # failed to talk to it properly. Kill the server and return failure
2346 stopserver($server, "$smbpid $pid2");
2347 displaylogs($testnumcheck);
2348 $doesntrun{$pidfile} = 1;
2349 return (0,0);
2350 }
2351 $pid2 = $pid3;
2352
2353 if($verbose) {
2354 logmsg "RUN: $srvrname server is now running PID $smbpid\n";
2355 }
2356
2357 sleep(1);
2358
2359 return ($smbpid, $pid2);
2360 }
2361
2362 #######################################################################
2363 # start the telnet server
2364 #
2365 sub runnegtelnetserver {
2366 my ($verbose, $alt, $port) = @_;
2367 my $proto = "telnet";
2368 my $ip = $HOSTIP;
2369 my $ipvnum = 4;
2370 my $idnum = 1;
2371 my $server;
2372 my $srvrname;
2373 my $pidfile;
2374 my $logfile;
2375 my $flags = "";
2376
2377 if($alt eq "ipv6") {
2378 # No IPv6
2379 }
2380
2381 $server = servername_id($proto, $ipvnum, $idnum);
2382
2383 $pidfile = $serverpidfile{$server};
2384
2385 # don't retry if the server doesn't work
2386 if ($doesntrun{$pidfile}) {
2387 return (0,0);
2388 }
2389
2390 my $pid = processexists($pidfile);
2391 if($pid > 0) {
2392 stopserver($server, "$pid");
2393 }
2394 unlink($pidfile) if(-f $pidfile);
2395
2396 $srvrname = servername_str($proto, $ipvnum, $idnum);
2397
2398 $logfile = server_logfilename($LOGDIR, $proto, $ipvnum, $idnum);
2399
2400 $flags .= "--verbose 1 " if($debugprotocol);
2401 $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
2402 $flags .= "--id $idnum " if($idnum > 1);
2403 $flags .= "--port $port --srcdir \"$srcdir\"";
2404
2405 my $cmd = "$srcdir/negtelnetserver.py $flags";
2406 my ($ntelpid, $pid2) = startnew($cmd, $pidfile, 15, 0);
2407
2408 if($ntelpid <= 0 || !pidexists($ntelpid)) {
2409 # it is NOT alive
2410 logmsg "RUN: failed to start the $srvrname server\n";
2411 stopserver($server, "$pid2");
2412 displaylogs($testnumcheck);
2413 $doesntrun{$pidfile} = 1;
2414 return (0,0);
2415 }
2416
2417 # Server is up. Verify that we can speak to it.
2418 my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
2419 if(!$pid3) {
2420 logmsg "RUN: $srvrname server failed verification\n";
2421 # failed to talk to it properly. Kill the server and return failure
2422 stopserver($server, "$ntelpid $pid2");
2423 displaylogs($testnumcheck);
2424 $doesntrun{$pidfile} = 1;
2425 return (0,0);
2426 }
2427 $pid2 = $pid3;
2428
2429 if($verbose) {
2430 logmsg "RUN: $srvrname server is now running PID $ntelpid\n";
2431 }
2432
2433 sleep(1);
2434
2435 return ($ntelpid, $pid2);
2436 }
2437
2438
2439 #######################################################################
2440 # Single shot http and gopher server responsiveness test. This should only
2441 # be used to verify that a server present in %run hash is still functional
2442 #
2443 sub responsive_http_server {
2444 my ($proto, $verbose, $alt, $port_or_path) = @_;
2445 my $ip = $HOSTIP;
2446 my $ipvnum = 4;
2447 my $idnum = 1;
2448
2449 if($alt eq "ipv6") {
2450 # if IPv6, use a different setup
2451 $ipvnum = 6;
2452 $ip = $HOST6IP;
2453 }
2454 elsif($alt eq "proxy") {
2455 $idnum = 2;
2456 }
2457 elsif($alt eq "unix") {
2458 # IP (protocol) is mutually exclusive with Unix sockets
2459 $ipvnum = "unix";
2460 }
2461
2462 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port_or_path);
2463 }
2464
2465 #######################################################################
2466 # Single shot pingpong server responsiveness test. This should only be
2467 # used to verify that a server present in %run hash is still functional
2468 #
2469 sub responsive_pingpong_server {
2470 my ($proto, $id, $verbose, $ipv6) = @_;
2471 my $port;
2472 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2473 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2474 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2475
2476 if($proto eq "ftp") {
2477 $port = ($idnum>1)?$FTP2PORT:$FTPPORT;
2478
2479 if($ipvnum==6) {
2480 # if IPv6, use a different setup
2481 $port = $FTP6PORT;
2482 }
2483 }
2484 elsif($proto eq "pop3") {
2485 $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT;
2486 }
2487 elsif($proto eq "imap") {
2488 $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT;
2489 }
2490 elsif($proto eq "smtp") {
2491 $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT;
2492 }
2493 else {
2494 print STDERR "Unsupported protocol $proto!!\n";
2495 return 0;
2496 }
2497
2498 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2499 }
2500
2501 #######################################################################
2502 # Single shot rtsp server responsiveness test. This should only be
2503 # used to verify that a server present in %run hash is still functional
2504 #
2505 sub responsive_rtsp_server {
2506 my ($verbose, $ipv6) = @_;
2507 my $port = $RTSPPORT;
2508 my $ip = $HOSTIP;
2509 my $proto = 'rtsp';
2510 my $ipvnum = 4;
2511 my $idnum = 1;
2512
2513 if($ipv6) {
2514 # if IPv6, use a different setup
2515 $ipvnum = 6;
2516 $port = $RTSP6PORT;
2517 $ip = $HOST6IP;
2518 }
2519
2520 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2521 }
2522
2523 #######################################################################
2524 # Single shot tftp server responsiveness test. This should only be
2525 # used to verify that a server present in %run hash is still functional
2526 #
2527 sub responsive_tftp_server {
2528 my ($id, $verbose, $ipv6) = @_;
2529 my $port = $TFTPPORT;
2530 my $ip = $HOSTIP;
2531 my $proto = 'tftp';
2532 my $ipvnum = 4;
2533 my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1;
2534
2535 if($ipv6) {
2536 # if IPv6, use a different setup
2537 $ipvnum = 6;
2538 $port = $TFTP6PORT;
2539 $ip = $HOST6IP;
2540 }
2541
2542 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2543 }
2544
2545 #######################################################################
2546 # Single shot non-stunnel HTTP TLS extensions capable server
2547 # responsiveness test. This should only be used to verify that a
2548 # server present in %run hash is still functional
2549 #
2550 sub responsive_httptls_server {
2551 my ($verbose, $ipv6) = @_;
2552 my $proto = "httptls";
2553 my $port = ($ipv6 && ($ipv6 =~ /6$/)) ? $HTTPTLS6PORT : $HTTPTLSPORT;
2554 my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP";
2555 my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4;
2556 my $idnum = 1;
2557
2558 return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port);
2559 }
2560
2561 #######################################################################
2562 # Remove all files in the specified directory
2563 #
2564 sub cleardir {
2565 my $dir = $_[0];
2566 my $count;
2567 my $file;
2568
2569 # Get all files
2570 opendir(DIR, $dir) ||
2571 return 0; # can't open dir
2572 while($file = readdir(DIR)) {
2573 if(($file !~ /^\./)) {
2574 unlink("$dir/$file");
2575 $count++;
2576 }
2577 }
2578 closedir DIR;
2579 return $count;
2580 }
2581
2582 #######################################################################
2583 # compare test results with the expected output, we might filter off
2584 # some pattern that is allowed to differ, output test results
2585 #
2586 sub compare {
2587 my ($testnum, $testname, $subject, $firstref, $secondref)=@_;
2588
2589 my $result = compareparts($firstref, $secondref);
2590
2591 if($result) {
2592 # timestamp test result verification end
2593 $timevrfyend{$testnum} = Time::HiRes::time();
2594
2595 if(!$short) {
2596 logmsg "\n $testnum: $subject FAILED:\n";
2597 logmsg showdiff($LOGDIR, $firstref, $secondref);
2598 }
2599 elsif(!$automakestyle) {
2600 logmsg "FAILED\n";
2601 }
2602 else {
2603 # automakestyle
2604 logmsg "FAIL: $testnum - $testname - $subject\n";
2605 }
2606 }
2607 return $result;
2608 }
2609
2610 sub setupfeatures {
2611 $feature{"SSL"} = $has_ssl;
2612 $feature{"MultiSSL"} = $has_multissl;
2613 $feature{"SSLpinning"} = $has_sslpinning;
2614 $feature{"OpenSSL"} = $has_openssl;
2615 $feature{"GnuTLS"} = $has_gnutls;
2616 $feature{"NSS"} = $has_nss;
2617 $feature{"WinSSL"} = $has_winssl;
2618 $feature{"Schannel"} = $has_winssl; # alias
2619 $feature{"sectransp"} = $has_darwinssl;
2620 $feature{"DarwinSSL"} = $has_darwinssl; # alias
2621 $feature{"ld_preload"} = ($has_ldpreload && !$debug_build);
2622 $feature{"unittest"} = $debug_build;
2623 $feature{"debug"} = $debug_build;
2624 $feature{"TrackMemory"} = $has_memory_tracking;
2625 $feature{"large_file"} = $has_largefile;
2626 $feature{"idn"} = $has_idn;
2627 $feature{"ipv6"} = $has_ipv6;
2628 $feature{"libz"} = $has_libz;
2629 $feature{"brotli"} = $has_brotli;
2630 $feature{"NTLM"} = $has_ntlm;
2631 $feature{"NTLM_WB"} = $has_ntlm_wb;
2632 $feature{"SSPI"} = $has_sspi;
2633 $feature{"GSS-API"} = $has_gssapi;
2634 $feature{"Kerberos"} = $has_kerberos;
2635 $feature{"SPNEGO"} = $has_spnego;
2636 $feature{"getrlimit"} = $has_getrlimit;
2637 $feature{"crypto"} = $has_crypto;
2638 $feature{"TLS-SRP"} = $has_tls_srp;
2639 $feature{"Metalink"} = $has_metalink;
2640 $feature{"http/2"} = $has_http2;
2641 $feature{"threaded-resolver"} = $has_threadedres;
2642 $feature{"PSL"} = $has_psl;
2643 $feature{"alt-svc"} = $has_altsvc;
2644 $feature{"manual"} = $has_manual;
2645 $feature{"unix-sockets"} = $has_unix;
2646 $feature{"win32"} = $has_win32;
2647
2648 # make each protocol an enabled "feature"
2649 for my $p (@protocols) {
2650 $feature{$p} = 1;
2651 }
2652 # 'socks' was once here but is now removed
2653
2654 #
2655 # strings that must match the names used in server/disabled.c
2656 #
2657 $feature{"cookies"} = 1;
2658 $feature{"DoH"} = 1;
2659 $feature{"HTTP-auth"} = 1;
2660 $feature{"Mime"} = 1;
2661 $feature{"netrc"} = 1;
2662 $feature{"parsedate"} = 1;
2663 $feature{"proxy"} = 1;
2664 $feature{"shuffle-dns"} = 1;
2665 $feature{"typecheck"} = 1;
2666 $feature{"verbose-strings"} = 1;
2667
2668 }
2669
2670 #######################################################################
2671 # display information about curl and the host the test suite runs on
2672 #
2673 sub checksystem {
2674
2675 unlink($memdump); # remove this if there was one left
2676
2677 my $feat;
2678 my $curl;
2679 my $libcurl;
2680 my $versretval;
2681 my $versnoexec;
2682 my @version=();
2683 my @disabled;
2684 my $dis = "";
2685
2686 my $curlverout="$LOGDIR/curlverout.log";
2687 my $curlvererr="$LOGDIR/curlvererr.log";
2688 my $versioncmd="$CURL --version 1>$curlverout 2>$curlvererr";
2689
2690 unlink($curlverout);
2691 unlink($curlvererr);
2692
2693 $versretval = runclient($versioncmd);
2694 $versnoexec = $!;
2695
2696 open(VERSOUT, "<$curlverout");
2697 @version = <VERSOUT>;
2698 close(VERSOUT);
2699
2700 open(DISABLED, "server/disabled|");
2701 @disabled = <DISABLED>;
2702 close(DISABLED);
2703
2704 if($disabled[0]) {
2705 map s/[\r\n]//g, @disabled;
2706 $dis = join(", ", @disabled);
2707 }
2708
2709 $resolver="stock";
2710 for(@version) {
2711 chomp;
2712
2713 if($_ =~ /^curl/) {
2714 $curl = $_;
2715 $curl =~ s/^(.*)(libcurl.*)/$1/g;
2716
2717 $libcurl = $2;
2718 if($curl =~ /linux|bsd|solaris/) {
2719 $has_ldpreload = 1;
2720 }
2721 if($curl =~ /win32|Windows|mingw(32|64)/) {
2722 # This is a Windows MinGW build or native build, we need to use
2723 # Win32-style path.
2724 $pwd = pathhelp::sys_native_current_path();
2725 $has_textaware = 1;
2726 $has_win32 = 1;
2727 }
2728 if ($libcurl =~ /(winssl|schannel)/i) {
2729 $has_winssl=1;
2730 $has_sslpinning=1;
2731 }
2732 elsif ($libcurl =~ /openssl/i) {
2733 $has_openssl=1;
2734 $has_sslpinning=1;
2735 }
2736 elsif ($libcurl =~ /gnutls/i) {
2737 $has_gnutls=1;
2738 $has_sslpinning=1;
2739 }
2740 elsif ($libcurl =~ /nss/i) {
2741 $has_nss=1;
2742 $has_sslpinning=1;
2743 }
2744 elsif ($libcurl =~ /wolfssl/i) {
2745 $has_wolfssl=1;
2746 $has_sslpinning=1;
2747 }
2748 elsif ($libcurl =~ /polarssl/i) {
2749 $has_polarssl=1;
2750 $has_sslpinning=1;
2751 }
2752 elsif ($libcurl =~ /securetransport/i) {
2753 $has_darwinssl=1;
2754 $has_sslpinning=1;
2755 }
2756 elsif ($libcurl =~ /BoringSSL/i) {
2757 $has_boringssl=1;
2758 $has_sslpinning=1;
2759 }
2760 elsif ($libcurl =~ /libressl/i) {
2761 $has_libressl=1;
2762 $has_sslpinning=1;
2763 }
2764 elsif ($libcurl =~ /mbedTLS/i) {
2765 $has_mbedtls=1;
2766 $has_sslpinning=1;
2767 }
2768 if ($libcurl =~ /ares/i) {
2769 $has_cares=1;
2770 $resolver="c-ares";
2771 }
2772 if ($libcurl =~ /mesalink/i) {
2773 $has_mesalink=1;
2774 }
2775 }
2776 elsif($_ =~ /^Protocols: (.*)/i) {
2777 # these are the protocols compiled in to this libcurl
2778 @protocols = split(' ', lc($1));
2779
2780 # Generate a "proto-ipv6" version of each protocol to match the
2781 # IPv6 <server> name and a "proto-unix" to match the variant which
2782 # uses Unix domain sockets. This works even if support isn't
2783 # compiled in because the <features> test will fail.
2784 push @protocols, map(("$_-ipv6", "$_-unix"), @protocols);
2785
2786 # 'http-proxy' is used in test cases to do CONNECT through
2787 push @protocols, 'http-proxy';
2788
2789 # 'none' is used in test cases to mean no server
2790 push @protocols, 'none';
2791 }
2792 elsif($_ =~ /^Features: (.*)/i) {
2793 $feat = $1;
2794 if($feat =~ /TrackMemory/i) {
2795 # built with memory tracking support (--enable-curldebug)
2796 $has_memory_tracking = 1;
2797 }
2798 if($feat =~ /debug/i) {
2799 # curl was built with --enable-debug
2800 $debug_build = 1;
2801 }
2802 if($feat =~ /SSL/i) {
2803 # ssl enabled
2804 $has_ssl=1;
2805 }
2806 if($feat =~ /MultiSSL/i) {
2807 # multiple ssl backends available.
2808 $has_multissl=1;
2809 }
2810 if($feat =~ /Largefile/i) {
2811 # large file support
2812 $has_largefile=1;
2813 }
2814 if($feat =~ /IDN/i) {
2815 # IDN support
2816 $has_idn=1;
2817 }
2818 if($feat =~ /IPv6/i) {
2819 $has_ipv6 = 1;
2820 }
2821 if($feat =~ /UnixSockets/i) {
2822 $has_unix = 1;
2823 }
2824 if($feat =~ /libz/i) {
2825 $has_libz = 1;
2826 }
2827 if($feat =~ /brotli/i) {
2828 $has_brotli = 1;
2829 }
2830 if($feat =~ /NTLM/i) {
2831 # NTLM enabled
2832 $has_ntlm=1;
2833
2834 # Use this as a proxy for any cryptographic authentication
2835 $has_crypto=1;
2836 }
2837 if($feat =~ /NTLM_WB/i) {
2838 # NTLM delegation to winbind daemon ntlm_auth helper enabled
2839 $has_ntlm_wb=1;
2840 }
2841 if($feat =~ /SSPI/i) {
2842 # SSPI enabled
2843 $has_sspi=1;
2844 }
2845 if($feat =~ /GSS-API/i) {
2846 # GSS-API enabled
2847 $has_gssapi=1;
2848 }
2849 if($feat =~ /Kerberos/i) {
2850 # Kerberos enabled
2851 $has_kerberos=1;
2852
2853 # Use this as a proxy for any cryptographic authentication
2854 $has_crypto=1;
2855 }
2856 if($feat =~ /SPNEGO/i) {
2857 # SPNEGO enabled
2858 $has_spnego=1;
2859
2860 # Use this as a proxy for any cryptographic authentication
2861 $has_crypto=1;
2862 }
2863 if($feat =~ /CharConv/i) {
2864 # CharConv enabled
2865 $has_charconv=1;
2866 }
2867 if($feat =~ /TLS-SRP/i) {
2868 # TLS-SRP enabled
2869 $has_tls_srp=1;
2870 }
2871 if($feat =~ /Metalink/i) {
2872 # Metalink enabled
2873 $has_metalink=1;
2874 }
2875 if($feat =~ /PSL/i) {
2876 # PSL enabled
2877 $has_psl=1;
2878 }
2879 if($feat =~ /alt-svc/i) {
2880 # alt-svc enabled
2881 $has_altsvc=1;
2882 }
2883 if($feat =~ /AsynchDNS/i) {
2884 if(!$has_cares) {
2885 # this means threaded resolver
2886 $has_threadedres=1;
2887 $resolver="threaded";
2888 }
2889 }
2890 if($feat =~ /HTTP2/) {
2891 # http2 enabled
2892 $has_http2=1;
2893
2894 push @protocols, 'http/2';
2895 }
2896 }
2897 #
2898 # Test harness currently uses a non-stunnel server in order to
2899 # run HTTP TLS-SRP tests required when curl is built with https
2900 # protocol support and TLS-SRP feature enabled. For convenience
2901 # 'httptls' may be included in the test harness protocols array
2902 # to differentiate this from classic stunnel based 'https' test
2903 # harness server.
2904 #
2905 if($has_tls_srp) {
2906 my $add_httptls;
2907 for(@protocols) {
2908 if($_ =~ /^https(-ipv6|)$/) {
2909 $add_httptls=1;
2910 last;
2911 }
2912 }
2913 if($add_httptls && (! grep /^httptls$/, @protocols)) {
2914 push @protocols, 'httptls';
2915 push @protocols, 'httptls-ipv6';
2916 }
2917 }
2918 }
2919 if(!$curl) {
2920 logmsg "unable to get curl's version, further details are:\n";
2921 logmsg "issued command: \n";
2922 logmsg "$versioncmd \n";
2923 if ($versretval == -1) {
2924 logmsg "command failed with: \n";
2925 logmsg "$versnoexec \n";
2926 }
2927 elsif ($versretval & 127) {
2928 logmsg sprintf("command died with signal %d, and %s coredump.\n",
2929 ($versretval & 127), ($versretval & 128)?"a":"no");
2930 }
2931 else {
2932 logmsg sprintf("command exited with value %d \n", $versretval >> 8);
2933 }
2934 logmsg "contents of $curlverout: \n";
2935 displaylogcontent("$curlverout");
2936 logmsg "contents of $curlvererr: \n";
2937 displaylogcontent("$curlvererr");
2938 die "couldn't get curl's version";
2939 }
2940
2941 if(-r "../lib/curl_config.h") {
2942 open(CONF, "<../lib/curl_config.h");
2943 while(<CONF>) {
2944 if($_ =~ /^\#define HAVE_GETRLIMIT/) {
2945 $has_getrlimit = 1;
2946 }
2947 }
2948 close(CONF);
2949 }
2950
2951 if($has_ipv6) {
2952 # client has IPv6 support
2953
2954 # check if the HTTP server has it!
2955 my $cmd = "server/sws".exe_ext('SRV')." --version";
2956 my @sws = `$cmd`;
2957 if($sws[0] =~ /IPv6/) {
2958 # HTTP server has IPv6 support!
2959 $http_ipv6 = 1;
2960 $gopher_ipv6 = 1;
2961 }
2962
2963 # check if the FTP server has it!
2964 $cmd = "server/sockfilt".exe_ext('SRV')." --version";
2965 @sws = `$cmd`;
2966 if($sws[0] =~ /IPv6/) {
2967 # FTP server has IPv6 support!
2968 $ftp_ipv6 = 1;
2969 }
2970 }
2971
2972 if($has_unix) {
2973 # client has Unix sockets support, check whether the HTTP server has it
2974 my $cmd = "server/sws".exe_ext('SRV')." --version";
2975 my @sws = `$cmd`;
2976 $http_unix = 1 if($sws[0] =~ /unix/);
2977 }
2978
2979 if(!$has_memory_tracking && $torture) {
2980 die "can't run torture tests since curl was built without ".
2981 "TrackMemory feature (--enable-curldebug)";
2982 }
2983
2984 open(M, "$CURL -M 2>&1|");
2985 while(my $s = <M>) {
2986 if($s =~ /built-in manual was disabled at build-time/) {
2987 $has_manual = 0;
2988 last;
2989 }
2990 $has_manual = 1;
2991 last;
2992 }
2993 close(M);
2994
2995 $has_shared = `sh $CURLCONFIG --built-shared`;
2996 chomp $has_shared;
2997
2998 my $hostname=join(' ', runclientoutput("hostname"));
2999 my $hosttype=join(' ', runclientoutput("uname -a"));
3000
3001 logmsg ("********* System characteristics ******** \n",
3002 "* $curl\n",
3003 "* $libcurl\n",
3004 "* Features: $feat\n",
3005 "* Disabled: $dis\n",
3006 "* Host: $hostname",
3007 "* System: $hosttype");
3008
3009 if($has_memory_tracking && $has_threadedres) {
3010 $has_memory_tracking = 0;
3011 logmsg("*\n",
3012 "*** DISABLES memory tracking when using threaded resolver\n",
3013 "*\n");
3014 }
3015
3016 logmsg sprintf("* Servers: %s", $stunnel?"SSL ":"");
3017 logmsg sprintf("%s", $http_ipv6?"HTTP-IPv6 ":"");
3018 logmsg sprintf("%s", $http_unix?"HTTP-unix ":"");
3019 logmsg sprintf("%s\n", $ftp_ipv6?"FTP-IPv6 ":"");
3020
3021 logmsg sprintf("* Env: %s%s", $valgrind?"Valgrind ":"",
3022 $run_event_based?"event-based ":"");
3023 logmsg sprintf("%s\n", $libtool?"Libtool ":"");
3024 logmsg ("* Seed: $randseed\n");
3025
3026 if($verbose) {
3027 logmsg "* Ports:\n";
3028
3029 logmsg sprintf("* HTTP/%d ", $HTTPPORT);
3030 logmsg sprintf("FTP/%d ", $FTPPORT);
3031 logmsg sprintf("FTP2/%d ", $FTP2PORT);
3032 logmsg sprintf("RTSP/%d ", $RTSPPORT);
3033 if($stunnel) {
3034 logmsg sprintf("FTPS/%d ", $FTPSPORT);
3035 logmsg sprintf("HTTPS/%d ", $HTTPSPORT);
3036 }
3037 logmsg sprintf("\n* TFTP/%d ", $TFTPPORT);
3038 if($http_ipv6) {
3039 logmsg sprintf("HTTP-IPv6/%d ", $HTTP6PORT);
3040 logmsg sprintf("RTSP-IPv6/%d ", $RTSP6PORT);
3041 }
3042 if($ftp_ipv6) {
3043 logmsg sprintf("FTP-IPv6/%d ", $FTP6PORT);
3044 }
3045 if($tftp_ipv6) {
3046 logmsg sprintf("TFTP-IPv6/%d ", $TFTP6PORT);
3047 }
3048 logmsg sprintf("\n* GOPHER/%d ", $GOPHERPORT);
3049 if($gopher_ipv6) {
3050 logmsg sprintf("GOPHER-IPv6/%d", $GOPHER6PORT);
3051 }
3052 logmsg sprintf("\n* SSH/%d ", $SSHPORT);
3053 logmsg sprintf("SOCKS/%d ", $SOCKSPORT);
3054 logmsg sprintf("POP3/%d ", $POP3PORT);
3055 logmsg sprintf("IMAP/%d ", $IMAPPORT);
3056 logmsg sprintf("SMTP/%d\n", $SMTPPORT);
3057 if($ftp_ipv6) {
3058 logmsg sprintf("* POP3-IPv6/%d ", $POP36PORT);
3059 logmsg sprintf("IMAP-IPv6/%d ", $IMAP6PORT);
3060 logmsg sprintf("SMTP-IPv6/%d\n", $SMTP6PORT);
3061 }
3062 if($httptlssrv) {
3063 logmsg sprintf("* HTTPTLS/%d ", $HTTPTLSPORT);
3064 if($has_ipv6) {
3065 logmsg sprintf("HTTPTLS-IPv6/%d ", $HTTPTLS6PORT);
3066 }
3067 logmsg "\n";
3068 }
3069
3070 if($has_unix) {
3071 logmsg "* Unix socket paths:\n";
3072 if($http_unix) {
3073 logmsg sprintf("* HTTP-Unix:%s\n", $HTTPUNIXPATH);
3074 }
3075 }
3076 }
3077
3078 logmsg "***************************************** \n";
3079
3080 setupfeatures();
3081 # toggle off the features that were disabled in the build
3082 for my $d(@disabled) {
3083 $feature{$d} = 0;
3084 }
3085 }
3086
3087 #######################################################################
3088 # substitute the variable stuff into either a joined up file or
3089 # a command, in either case passed by reference
3090 #
3091 sub subVariables {
3092 my ($thing) = @_;
3093
3094 # ports
3095
3096 $$thing =~ s/%FTP6PORT/$FTP6PORT/g;
3097 $$thing =~ s/%FTP2PORT/$FTP2PORT/g;
3098 $$thing =~ s/%FTPSPORT/$FTPSPORT/g;
3099 $$thing =~ s/%FTPPORT/$FTPPORT/g;
3100
3101 $$thing =~ s/%GOPHER6PORT/$GOPHER6PORT/g;
3102 $$thing =~ s/%GOPHERPORT/$GOPHERPORT/g;
3103
3104 $$thing =~ s/%HTTPTLS6PORT/$HTTPTLS6PORT/g;
3105 $$thing =~ s/%HTTPTLSPORT/$HTTPTLSPORT/g;
3106 $$thing =~ s/%HTTP6PORT/$HTTP6PORT/g;
3107 $$thing =~ s/%HTTPSPORT/$HTTPSPORT/g;
3108 $$thing =~ s/%HTTP2PORT/$HTTP2PORT/g;
3109 $$thing =~ s/%HTTPPORT/$HTTPPORT/g;
3110 $$thing =~ s/%PROXYPORT/$HTTPPROXYPORT/g;
3111
3112 $$thing =~ s/%IMAP6PORT/$IMAP6PORT/g;
3113 $$thing =~ s/%IMAPPORT/$IMAPPORT/g;
3114
3115 $$thing =~ s/%POP36PORT/$POP36PORT/g;
3116 $$thing =~ s/%POP3PORT/$POP3PORT/g;
3117
3118 $$thing =~ s/%RTSP6PORT/$RTSP6PORT/g;
3119 $$thing =~ s/%RTSPPORT/$RTSPPORT/g;
3120
3121 $$thing =~ s/%SMTP6PORT/$SMTP6PORT/g;
3122 $$thing =~ s/%SMTPPORT/$SMTPPORT/g;
3123
3124 $$thing =~ s/%SOCKSPORT/$SOCKSPORT/g;
3125 $$thing =~ s/%SSHPORT/$SSHPORT/g;
3126
3127 $$thing =~ s/%TFTP6PORT/$TFTP6PORT/g;
3128 $$thing =~ s/%TFTPPORT/$TFTPPORT/g;
3129
3130 $$thing =~ s/%DICTPORT/$DICTPORT/g;
3131
3132 $$thing =~ s/%SMBPORT/$SMBPORT/g;
3133 $$thing =~ s/%SMBSPORT/$SMBSPORT/g;
3134
3135 $$thing =~ s/%NEGTELNETPORT/$NEGTELNETPORT/g;
3136
3137 # server Unix domain socket paths
3138
3139 $$thing =~ s/%HTTPUNIXPATH/$HTTPUNIXPATH/g;
3140
3141 # client IP addresses
3142
3143 $$thing =~ s/%CLIENT6IP/$CLIENT6IP/g;
3144 $$thing =~ s/%CLIENTIP/$CLIENTIP/g;
3145
3146 # server IP addresses
3147
3148 $$thing =~ s/%HOST6IP/$HOST6IP/g;
3149 $$thing =~ s/%HOSTIP/$HOSTIP/g;
3150
3151 # misc
3152
3153 $$thing =~ s/%CURL/$CURL/g;
3154 $$thing =~ s/%PWD/$pwd/g;
3155 $$thing =~ s/%POSIX_PWD/$posix_pwd/g;
3156
3157 my $file_pwd = $pwd;
3158 if($file_pwd !~ /^\//) {
3159 $file_pwd = "/$file_pwd";
3160 }
3161
3162 $$thing =~ s/%FILE_PWD/$file_pwd/g;
3163 $$thing =~ s/%SRCDIR/$srcdir/g;
3164 $$thing =~ s/%USER/$USER/g;
3165
3166 # The purpose of FTPTIME2 and FTPTIME3 is to provide times that can be
3167 # used for time-out tests and that would work on most hosts as these
3168 # adjust for the startup/check time for this particular host. We needed
3169 # to do this to make the test suite run better on very slow hosts.
3170
3171 my $ftp2 = $ftpchecktime * 2;
3172 my $ftp3 = $ftpchecktime * 3;
3173
3174 $$thing =~ s/%FTPTIME2/$ftp2/g;
3175 $$thing =~ s/%FTPTIME3/$ftp3/g;
3176
3177 # HTTP2
3178
3179 $$thing =~ s/%H2CVER/$h2cver/g;
3180 }
3181
3182 sub fixarray {
3183 my @in = @_;
3184
3185 for(@in) {
3186 subVariables(\$_);
3187 }
3188 return @in;
3189 }
3190
3191 #######################################################################
3192 # Provide time stamps for single test skipped events
3193 #
3194 sub timestampskippedevents {
3195 my $testnum = $_[0];
3196
3197 return if((not defined($testnum)) || ($testnum < 1));
3198
3199 if($timestats) {
3200
3201 if($timevrfyend{$testnum}) {
3202 return;
3203 }
3204 elsif($timesrvrlog{$testnum}) {
3205 $timevrfyend{$testnum} = $timesrvrlog{$testnum};
3206 return;
3207 }
3208 elsif($timetoolend{$testnum}) {
3209 $timevrfyend{$testnum} = $timetoolend{$testnum};
3210 $timesrvrlog{$testnum} = $timetoolend{$testnum};
3211 }
3212 elsif($timetoolini{$testnum}) {
3213 $timevrfyend{$testnum} = $timetoolini{$testnum};
3214 $timesrvrlog{$testnum} = $timetoolini{$testnum};
3215 $timetoolend{$testnum} = $timetoolini{$testnum};
3216 }
3217 elsif($timesrvrend{$testnum}) {
3218 $timevrfyend{$testnum} = $timesrvrend{$testnum};
3219 $timesrvrlog{$testnum} = $timesrvrend{$testnum};
3220 $timetoolend{$testnum} = $timesrvrend{$testnum};
3221 $timetoolini{$testnum} = $timesrvrend{$testnum};
3222 }
3223 elsif($timesrvrini{$testnum}) {
3224 $timevrfyend{$testnum} = $timesrvrini{$testnum};
3225 $timesrvrlog{$testnum} = $timesrvrini{$testnum};
3226 $timetoolend{$testnum} = $timesrvrini{$testnum};
3227 $timetoolini{$testnum} = $timesrvrini{$testnum};
3228 $timesrvrend{$testnum} = $timesrvrini{$testnum};
3229 }
3230 elsif($timeprepini{$testnum}) {
3231 $timevrfyend{$testnum} = $timeprepini{$testnum};
3232 $timesrvrlog{$testnum} = $timeprepini{$testnum};
3233 $timetoolend{$testnum} = $timeprepini{$testnum};
3234 $timetoolini{$testnum} = $timeprepini{$testnum};
3235 $timesrvrend{$testnum} = $timeprepini{$testnum};
3236 $timesrvrini{$testnum} = $timeprepini{$testnum};
3237 }
3238 }
3239 }
3240
3241 #######################################################################
3242 # Run a single specified test case
3243 #
3244 sub singletest {
3245 my ($evbased, # 1 means switch on if possible (and "curl" is tested)
3246 # returns "not a test" if it can't be used for this test
3247 $testnum,
3248 $count,
3249 $total)=@_;
3250
3251 my @what;
3252 my $why;
3253 my $cmd;
3254 my $disablevalgrind;
3255 my $errorreturncode = 1; # 1 means normal error, 2 means ignored error
3256
3257 # fist, remove all lingering log files
3258 cleardir($LOGDIR);
3259
3260 # copy test number to a global scope var, this allows
3261 # testnum checking when starting test harness servers.
3262 $testnumcheck = $testnum;
3263
3264 # timestamp test preparation start
3265 $timeprepini{$testnum} = Time::HiRes::time();
3266
3267 if($disttests !~ /test$testnum\W/ ) {
3268 logmsg "Warning: test$testnum not present in tests/data/Makefile.inc\n";
3269 }
3270 if($disabled{$testnum}) {
3271 logmsg "Warning: test$testnum is explicitly disabled\n";
3272 }
3273 if($ignored{$testnum}) {
3274 logmsg "Warning: test$testnum result is ignored\n";
3275 $errorreturncode = 2;
3276 }
3277
3278 # load the test case file definition
3279 if(loadtest("${TESTDIR}/test${testnum}")) {
3280 if($verbose) {
3281 # this is not a test
3282 logmsg "RUN: $testnum doesn't look like a test case\n";
3283 }
3284 $why = "no test";
3285 }
3286 else {
3287 @what = getpart("client", "features");
3288 }
3289
3290 # We require a feature to be present
3291 for(@what) {
3292 my $f = $_;
3293 $f =~ s/\s//g;
3294
3295 if($f =~ /^([^!].*)$/) {
3296 if($feature{$1}) {
3297 next;
3298 }
3299
3300 $why = "curl lacks $1 support";
3301 last;
3302 }
3303 }
3304
3305 # We require a feature to not be present
3306 if(!$why) {
3307 for(@what) {
3308 my $f = $_;
3309 $f =~ s/\s//g;
3310
3311 if($f =~ /^!(.*)$/) {
3312 if(!$feature{$1}) {
3313 next;
3314 }
3315 }
3316 else {
3317 next;
3318 }
3319
3320 $why = "curl has $1 support";
3321 last;
3322 }
3323 }
3324
3325 if(!$why) {
3326 my @info_keywords = getpart("info", "keywords");
3327 my $match;
3328 my $k;
3329
3330 # Clear the list of keywords from the last test
3331 %keywords = ();
3332
3333 if(!$info_keywords[0]) {
3334 $why = "missing the <keywords> section!";
3335 }
3336
3337 for $k (@info_keywords) {
3338 chomp $k;
3339 if ($disabled_keywords{lc($k)}) {
3340 $why = "disabled by keyword";
3341 } elsif ($enabled_keywords{lc($k)}) {
3342 $match = 1;
3343 }
3344 if ($ignored_keywords{lc($k)}) {
3345 logmsg "Warning: test$testnum result is ignored due to $k\n";
3346 $errorreturncode = 2;
3347 }
3348
3349 $keywords{$k} = 1;
3350 }
3351
3352 if(!$why && !$match && %enabled_keywords) {
3353 $why = "disabled by missing keyword";
3354 }
3355 }
3356
3357 # test definition may instruct to (un)set environment vars
3358 # this is done this early, so that the precheck can use environment
3359 # variables and still bail out fine on errors
3360
3361 # restore environment variables that were modified in a previous run
3362 foreach my $var (keys %oldenv) {
3363 if($oldenv{$var} eq 'notset') {
3364 delete $ENV{$var} if($ENV{$var});
3365 }
3366 else {
3367 $ENV{$var} = $oldenv{$var};
3368 }
3369 delete $oldenv{$var};
3370 }
3371
3372 # get the name of the test early
3373 my @testname= getpart("client", "name");
3374 my $testname = $testname[0];
3375 $testname =~ s/\n//g;
3376
3377 # create test result in CI services
3378 if(azure_check_environment() && $AZURE_RUN_ID) {
3379 $AZURE_RESULT_ID = azure_create_test_result($AZURE_RUN_ID, $testnum, $testname);
3380 }
3381 elsif(appveyor_check_environment()) {
3382 appveyor_create_test_result($testnum, $testname);
3383 }
3384
3385 # remove test server commands file before servers are started/verified
3386 unlink($FTPDCMD) if(-f $FTPDCMD);
3387
3388 # timestamp required servers verification start
3389 $timesrvrini{$testnum} = Time::HiRes::time();
3390
3391 if(!$why) {
3392 $why = serverfortest($testnum);
3393 }
3394
3395 # timestamp required servers verification end
3396 $timesrvrend{$testnum} = Time::HiRes::time();
3397
3398 my @setenv = getpart("client", "setenv");
3399 if(@setenv) {
3400 foreach my $s (@setenv) {
3401 chomp $s;
3402 subVariables(\$s);
3403 if($s =~ /([^=]*)=(.*)/) {
3404 my ($var, $content) = ($1, $2);
3405 # remember current setting, to restore it once test runs
3406 $oldenv{$var} = ($ENV{$var})?"$ENV{$var}":'notset';
3407 # set new value
3408 if(!$content) {
3409 delete $ENV{$var} if($ENV{$var});
3410 }
3411 else {
3412 if($var =~ /^LD_PRELOAD/) {
3413 if(exe_ext('TOOL') && (exe_ext('TOOL') eq '.exe')) {
3414 # print "Skipping LD_PRELOAD due to lack of OS support\n";
3415 next;
3416 }
3417 if($debug_build || ($has_shared ne "yes")) {
3418 # print "Skipping LD_PRELOAD due to no release shared build\n";
3419 next;
3420 }
3421 }
3422 $ENV{$var} = "$content";
3423 print "setenv $var = $content\n" if($verbose);
3424 }
3425 }
3426 }
3427 }
3428
3429 if(!$why) {
3430 my @precheck = getpart("client", "precheck");
3431 if(@precheck) {
3432 $cmd = $precheck[0];
3433 chomp $cmd;
3434 subVariables \$cmd;
3435 if($cmd) {
3436 my @p = split(/ /, $cmd);
3437 if($p[0] !~ /\//) {
3438 # the first word, the command, does not contain a slash so
3439 # we will scan the "improved" PATH to find the command to
3440 # be able to run it
3441 my $fullp = checktestcmd($p[0]);
3442
3443 if($fullp) {
3444 $p[0] = $fullp;
3445 }
3446 $cmd = join(" ", @p);
3447 }
3448
3449 my @o = `$cmd 2>/dev/null`;
3450 if($o[0]) {
3451 $why = $o[0];
3452 chomp $why;
3453 } elsif($?) {
3454 $why = "precheck command error";
3455 }
3456 logmsg "prechecked $cmd\n" if($verbose);
3457 }
3458 }
3459 }
3460
3461 if($why && !$listonly) {
3462 # there's a problem, count it as "skipped"
3463 $skipped++;
3464 $skipped{$why}++;
3465 $teststat[$testnum]=$why; # store reason for this test case
3466
3467 if(!$short) {
3468 if($skipped{$why} <= 3) {
3469 # show only the first three skips for each reason
3470 logmsg sprintf("test %04d SKIPPED: $why\n", $testnum);
3471 }
3472 }
3473
3474 timestampskippedevents($testnum);
3475 return -1;
3476 }
3477 logmsg sprintf("test %04d...", $testnum) if(!$automakestyle);
3478
3479 my %replyattr = getpartattr("reply", "data");
3480 my @reply;
3481 if (partexists("reply", "datacheck")) {
3482 for my $partsuffix (('', '1', '2', '3', '4')) {
3483 my @replycheckpart = getpart("reply", "datacheck".$partsuffix);
3484 if(@replycheckpart) {
3485 my %replycheckpartattr = getpartattr("reply", "datacheck".$partsuffix);
3486 # get the mode attribute
3487 my $filemode=$replycheckpartattr{'mode'};
3488 if($filemode && ($filemode eq "text") && $has_textaware) {
3489 # text mode when running on windows: fix line endings
3490 map s/\r\n/\n/g, @replycheckpart;
3491 map s/\n/\r\n/g, @replycheckpart;
3492 }
3493 if($replycheckpartattr{'nonewline'}) {
3494 # Yes, we must cut off the final newline from the final line
3495 # of the datacheck
3496 chomp($replycheckpart[$#replycheckpart]);
3497 }
3498 push(@reply, @replycheckpart);
3499 }
3500 }
3501 }
3502 else {
3503 # check against the data section
3504 @reply = getpart("reply", "data");
3505 # get the mode attribute
3506 my $filemode=$replyattr{'mode'};
3507 if($filemode && ($filemode eq "text") && $has_textaware) {
3508 # text mode when running on windows: fix line endings
3509 map s/\r\n/\n/g, @reply;
3510 map s/\n/\r\n/g, @reply;
3511 }
3512 }
3513
3514 # this is the valid protocol blurb curl should generate
3515 my @protocol= fixarray ( getpart("verify", "protocol") );
3516
3517 # this is the valid protocol blurb curl should generate to a proxy
3518 my @proxyprot = fixarray ( getpart("verify", "proxy") );
3519
3520 # redirected stdout/stderr to these files
3521 $STDOUT="$LOGDIR/stdout$testnum";
3522 $STDERR="$LOGDIR/stderr$testnum";
3523
3524 # if this section exists, we verify that the stdout contained this:
3525 my @validstdout = fixarray ( getpart("verify", "stdout") );
3526 my @validstderr = fixarray ( getpart("verify", "stderr") );
3527
3528 # if this section exists, we verify upload
3529 my @upload = getpart("verify", "upload");
3530 if(@upload) {
3531 my %hash = getpartattr("verify", "upload");
3532 if($hash{'nonewline'}) {
3533 # cut off the final newline from the final line of the upload data
3534 chomp($upload[$#upload]);
3535 }
3536 }
3537
3538 # if this section exists, it might be FTP server instructions:
3539 my @ftpservercmd = fixarray ( getpart("reply", "servercmd") );
3540
3541 my $CURLOUT="$LOGDIR/curl$testnum.out"; # curl output if not stdout
3542
3543 # name of the test
3544 logmsg "[$testname]\n" if(!$short);
3545
3546 if($listonly) {
3547 timestampskippedevents($testnum);
3548 return 0; # look successful
3549 }
3550
3551 my @codepieces = getpart("client", "tool");
3552
3553 my $tool="";
3554 if(@codepieces) {
3555 $tool = $codepieces[0];
3556 chomp $tool;
3557 $tool .= exe_ext('TOOL');
3558 }
3559
3560 # remove server output logfile
3561 unlink($SERVERIN);
3562 unlink($SERVER2IN);
3563 unlink($PROXYIN);
3564
3565 if(@ftpservercmd) {
3566 # write the instructions to file
3567 writearray($FTPDCMD, \@ftpservercmd);
3568 }
3569
3570 # get the command line options to use
3571 my @blaha;
3572 ($cmd, @blaha)= getpart("client", "command");
3573
3574 if($cmd) {
3575 # make some nice replace operations
3576 $cmd =~ s/\n//g; # no newlines please
3577 # substitute variables in the command line
3578 subVariables \$cmd;
3579 }
3580 else {
3581 # there was no command given, use something silly
3582 $cmd="-";
3583 }
3584 if($has_memory_tracking) {
3585 unlink($memdump);
3586 }
3587
3588 # create (possibly-empty) files before starting the test
3589 for my $partsuffix (('', '1', '2', '3', '4')) {
3590 my @inputfile=getpart("client", "file".$partsuffix);
3591 my %fileattr = getpartattr("client", "file".$partsuffix);
3592 my $filename=$fileattr{'name'};
3593 if(@inputfile || $filename) {
3594 if(!$filename) {
3595 logmsg "ERROR: section client=>file has no name attribute\n";
3596 timestampskippedevents($testnum);
3597 return -1;
3598 }
3599 my $fileContent = join('', @inputfile);
3600 subVariables \$fileContent;
3601 # logmsg "DEBUG: writing file " . $filename . "\n";
3602 open(OUTFILE, ">$filename");
3603 binmode OUTFILE; # for crapage systems, use binary
3604 print OUTFILE $fileContent;
3605 close(OUTFILE);
3606 }
3607 }
3608
3609 my %cmdhash = getpartattr("client", "command");
3610
3611 my $out="";
3612
3613 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-output/)) {
3614 #We may slap on --output!
3615 if (!@validstdout ||
3616 ($cmdhash{'option'} && $cmdhash{'option'} =~ /force-output/)) {
3617 $out=" --output $CURLOUT ";
3618 }
3619 }
3620
3621 my $serverlogslocktimeout = $defserverlogslocktimeout;
3622 if($cmdhash{'timeout'}) {
3623 # test is allowed to override default server logs lock timeout
3624 if($cmdhash{'timeout'} =~ /(\d+)/) {
3625 $serverlogslocktimeout = $1 if($1 >= 0);
3626 }
3627 }
3628
3629 my $postcommanddelay = $defpostcommanddelay;
3630 if($cmdhash{'delay'}) {
3631 # test is allowed to specify a delay after command is executed
3632 if($cmdhash{'delay'} =~ /(\d+)/) {
3633 $postcommanddelay = $1 if($1 > 0);
3634 }
3635 }
3636
3637 my $CMDLINE;
3638 my $cmdargs;
3639 my $cmdtype = $cmdhash{'type'} || "default";
3640 my $fail_due_event_based = $evbased;
3641 if($cmdtype eq "perl") {
3642 # run the command line prepended with "perl"
3643 $cmdargs ="$cmd";
3644 $CMDLINE = "$perl ";
3645 $tool=$CMDLINE;
3646 $disablevalgrind=1;
3647 }
3648 elsif($cmdtype eq "shell") {
3649 # run the command line prepended with "/bin/sh"
3650 $cmdargs ="$cmd";
3651 $CMDLINE = "/bin/sh ";
3652 $tool=$CMDLINE;
3653 $disablevalgrind=1;
3654 }
3655 elsif(!$tool && !$keywords{"unittest"}) {
3656 # run curl, add suitable command line options
3657 my $inc="";
3658 if((!$cmdhash{'option'}) || ($cmdhash{'option'} !~ /no-include/)) {
3659 $inc = " --include";
3660 }
3661
3662 $cmdargs = "$out$inc ";
3663 $cmdargs .= "--trace-ascii log/trace$testnum ";
3664 $cmdargs .= "--trace-time ";
3665 if($evbased) {
3666 $cmdargs .= "--test-event ";
3667 $fail_due_event_based--;
3668 }
3669 $cmdargs .= $cmd;
3670 }
3671 else {
3672 $cmdargs = " $cmd"; # $cmd is the command line for the test file
3673 $CURLOUT = $STDOUT; # sends received data to stdout
3674
3675 # Default the tool to a unit test with the same name as the test spec
3676 if($keywords{"unittest"} && !$tool) {
3677 $tool="unit$testnum";
3678 }
3679
3680 if($tool =~ /^lib/) {
3681 $CMDLINE="$LIBDIR/$tool";
3682 }
3683 elsif($tool =~ /^unit/) {
3684 $CMDLINE="$UNITDIR/$tool";
3685 }
3686
3687 if(! -f $CMDLINE) {
3688 logmsg "The tool set in the test case for this: '$tool' does not exist\n";
3689 timestampskippedevents($testnum);
3690 return -1;
3691 }
3692 $DBGCURL=$CMDLINE;
3693 }
3694
3695 if($gdbthis) {
3696 # gdb is incompatible with valgrind, so disable it when debugging
3697 # Perhaps a better approach would be to run it under valgrind anyway
3698 # with --db-attach=yes or --vgdb=yes.
3699 $disablevalgrind=1;
3700 }
3701
3702 if($fail_due_event_based) {
3703 logmsg "This test cannot run event based\n";
3704 return -1;
3705 }
3706
3707 my @stdintest = getpart("client", "stdin");
3708
3709 if(@stdintest) {
3710 my $stdinfile="$LOGDIR/stdin-for-$testnum";
3711
3712 my %hash = getpartattr("client", "stdin");
3713 if($hash{'nonewline'}) {
3714 # cut off the final newline from the final line of the stdin data
3715 chomp($stdintest[$#stdintest]);
3716 }
3717
3718 writearray($stdinfile, \@stdintest);
3719
3720 $cmdargs .= " <$stdinfile";
3721 }
3722
3723 if(!$tool) {
3724 $CMDLINE="$CURL";
3725 }
3726
3727 my $usevalgrind;
3728 if($valgrind && !$disablevalgrind) {
3729 my @valgrindoption = getpart("verify", "valgrind");
3730 if((!@valgrindoption) || ($valgrindoption[0] !~ /disable/)) {
3731 $usevalgrind = 1;
3732 my $valgrindcmd = "$valgrind ";
3733 $valgrindcmd .= "$valgrind_tool " if($valgrind_tool);
3734 $valgrindcmd .= "--quiet --leak-check=yes ";
3735 $valgrindcmd .= "--suppressions=$srcdir/valgrind.supp ";
3736 # $valgrindcmd .= "--gen-suppressions=all ";
3737 $valgrindcmd .= "--num-callers=16 ";
3738 $valgrindcmd .= "${valgrind_logfile}=$LOGDIR/valgrind$testnum";
3739 $CMDLINE = "$valgrindcmd $CMDLINE";
3740 }
3741 }
3742
3743 $CMDLINE .= "$cmdargs >$STDOUT 2>$STDERR";
3744
3745 if($verbose) {
3746 logmsg "$CMDLINE\n";
3747 }
3748
3749 open(CMDLOG, ">", "$LOGDIR/$CURLLOG");
3750 print CMDLOG "$CMDLINE\n";
3751 close(CMDLOG);
3752
3753 unlink("core");
3754
3755 my $dumped_core;
3756 my $cmdres;
3757
3758 if($gdbthis) {
3759 my $gdbinit = "$TESTDIR/gdbinit$testnum";
3760 open(GDBCMD, ">$LOGDIR/gdbcmd");
3761 print GDBCMD "set args $cmdargs\n";
3762 print GDBCMD "show args\n";
3763 print GDBCMD "source $gdbinit\n" if -e $gdbinit;
3764 close(GDBCMD);
3765 }
3766
3767 # timestamp starting of test command
3768 $timetoolini{$testnum} = Time::HiRes::time();
3769
3770 # run the command line we built
3771 if ($torture) {
3772 $cmdres = torture($CMDLINE,
3773 $testnum,
3774 "$gdb --directory libtest $DBGCURL -x $LOGDIR/gdbcmd");
3775 }
3776 elsif($gdbthis) {
3777 my $GDBW = ($gdbxwin) ? "-w" : "";
3778 runclient("$gdb --directory libtest $DBGCURL $GDBW -x $LOGDIR/gdbcmd");
3779 $cmdres=0; # makes it always continue after a debugged run
3780 }
3781 else {
3782 $cmdres = runclient("$CMDLINE");
3783 my $signal_num = $cmdres & 127;
3784 $dumped_core = $cmdres & 128;
3785
3786 if(!$anyway && ($signal_num || $dumped_core)) {
3787 $cmdres = 1000;
3788 }
3789 else {
3790 $cmdres >>= 8;
3791 $cmdres = (2000 + $signal_num) if($signal_num && !$cmdres);
3792 }
3793 }
3794
3795 # timestamp finishing of test command
3796 $timetoolend{$testnum} = Time::HiRes::time();
3797
3798 if(!$dumped_core) {
3799 if(-r "core") {
3800 # there's core file present now!
3801 $dumped_core = 1;
3802 }
3803 }
3804
3805 if($dumped_core) {
3806 logmsg "core dumped\n";
3807 if(0 && $gdb) {
3808 logmsg "running gdb for post-mortem analysis:\n";
3809 open(GDBCMD, ">$LOGDIR/gdbcmd2");
3810 print GDBCMD "bt\n";
3811 close(GDBCMD);
3812 runclient("$gdb --directory libtest -x $LOGDIR/gdbcmd2 -batch $DBGCURL core ");
3813 # unlink("$LOGDIR/gdbcmd2");
3814 }
3815 }
3816
3817 # If a server logs advisor read lock file exists, it is an indication
3818 # that the server has not yet finished writing out all its log files,
3819 # including server request log files used for protocol verification.
3820 # So, if the lock file exists the script waits here a certain amount
3821 # of time until the server removes it, or the given time expires.
3822
3823 if($serverlogslocktimeout) {
3824 my $lockretry = $serverlogslocktimeout * 20;
3825 while((-f $SERVERLOGS_LOCK) && $lockretry--) {
3826 select(undef, undef, undef, 0.05);
3827 }
3828 if(($lockretry < 0) &&
3829 ($serverlogslocktimeout >= $defserverlogslocktimeout)) {
3830 logmsg "Warning: server logs lock timeout ",
3831 "($serverlogslocktimeout seconds) expired\n";
3832 }
3833 }
3834
3835 # Test harness ssh server does not have this synchronization mechanism,
3836 # this implies that some ssh server based tests might need a small delay
3837 # once that the client command has run to avoid false test failures.
3838 #
3839 # gnutls-serv also lacks this synchronization mechanism, so gnutls-serv
3840 # based tests might need a small delay once that the client command has
3841 # run to avoid false test failures.
3842
3843 sleep($postcommanddelay) if($postcommanddelay);
3844
3845 # timestamp removal of server logs advisor read lock
3846 $timesrvrlog{$testnum} = Time::HiRes::time();
3847
3848 # test definition might instruct to stop some servers
3849 # stop also all servers relative to the given one
3850
3851 my @killtestservers = getpart("client", "killserver");
3852 if(@killtestservers) {
3853 #
3854 # All servers relative to the given one must be stopped also
3855 #
3856 my @killservers;
3857 foreach my $server (@killtestservers) {
3858 chomp $server;
3859 if($server =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
3860 # given a stunnel ssl server, also kill non-ssl underlying one
3861 push @killservers, "${1}${2}";
3862 }
3863 elsif($server =~ /^(ftp|http|imap|pop3|smtp)((\d*)(-ipv6|-unix|))$/) {
3864 # given a non-ssl server, also kill stunnel piggybacking one
3865 push @killservers, "${1}s${2}";
3866 }
3867 elsif($server =~ /^(socks)((\d*)(-ipv6|))$/) {
3868 # given a socks server, also kill ssh underlying one
3869 push @killservers, "ssh${2}";
3870 }
3871 elsif($server =~ /^(ssh)((\d*)(-ipv6|))$/) {
3872 # given a ssh server, also kill socks piggybacking one
3873 push @killservers, "socks${2}";
3874 }
3875 push @killservers, $server;
3876 }
3877 #
3878 # kill sockfilter processes for pingpong relative servers
3879 #
3880 foreach my $server (@killservers) {
3881 if($server =~ /^(ftp|imap|pop3|smtp)s?(\d*)(-ipv6|)$/) {
3882 my $proto = $1;
3883 my $idnum = ($2 && ($2 > 1)) ? $2 : 1;
3884 my $ipvnum = ($3 && ($3 =~ /6$/)) ? 6 : 4;
3885 killsockfilters($proto, $ipvnum, $idnum, $verbose);
3886 }
3887 }
3888 #
3889 # kill server relative pids clearing them in %run hash
3890 #
3891 my $pidlist;
3892 foreach my $server (@killservers) {
3893 if($run{$server}) {
3894 $pidlist .= "$run{$server} ";
3895 $run{$server} = 0;
3896 }
3897 $runcert{$server} = 0 if($runcert{$server});
3898 }
3899 killpid($verbose, $pidlist);
3900 #
3901 # cleanup server pid files
3902 #
3903 foreach my $server (@killservers) {
3904 my $pidfile = $serverpidfile{$server};
3905 my $pid = processexists($pidfile);
3906 if($pid > 0) {
3907 logmsg "Warning: $server server unexpectedly alive\n";
3908 killpid($verbose, $pid);
3909 }
3910 unlink($pidfile) if(-f $pidfile);
3911 }
3912 }
3913
3914 # remove the test server commands file after each test
3915 unlink($FTPDCMD) if(-f $FTPDCMD);
3916
3917 # run the postcheck command
3918 my @postcheck= getpart("client", "postcheck");
3919 if(@postcheck) {
3920 $cmd = join("", @postcheck);
3921 chomp $cmd;
3922 subVariables \$cmd;
3923 if($cmd) {
3924 logmsg "postcheck $cmd\n" if($verbose);
3925 my $rc = runclient("$cmd");
3926 # Must run the postcheck command in torture mode in order
3927 # to clean up, but the result can't be relied upon.
3928 if($rc != 0 && !$torture) {
3929 logmsg " postcheck FAILED\n";
3930 # timestamp test result verification end
3931 $timevrfyend{$testnum} = Time::HiRes::time();
3932 return $errorreturncode;
3933 }
3934 }
3935 }
3936
3937 # restore environment variables that were modified
3938 if(%oldenv) {
3939 foreach my $var (keys %oldenv) {
3940 if($oldenv{$var} eq 'notset') {
3941 delete $ENV{$var} if($ENV{$var});
3942 }
3943 else {
3944 $ENV{$var} = "$oldenv{$var}";
3945 }
3946 }
3947 }
3948
3949 # Skip all the verification on torture tests
3950 if ($torture) {
3951 # timestamp test result verification end
3952 $timevrfyend{$testnum} = Time::HiRes::time();
3953 return $cmdres;
3954 }
3955
3956 my @err = getpart("verify", "errorcode");
3957 my $errorcode = $err[0] || "0";
3958 my $ok="";
3959 my $res;
3960 chomp $errorcode;
3961 if (@validstdout) {
3962 # verify redirected stdout
3963 my @actual = loadarray($STDOUT);
3964
3965 # what parts to cut off from stdout
3966 my @stripfile = getpart("verify", "stripfile");
3967
3968 foreach my $strip (@stripfile) {
3969 chomp $strip;
3970 my @newgen;
3971 for(@actual) {
3972 eval $strip;
3973 if($_) {
3974 push @newgen, $_;
3975 }
3976 }
3977 # this is to get rid of array entries that vanished (zero
3978 # length) because of replacements
3979 @actual = @newgen;
3980 }
3981
3982 # variable-replace in the stdout we have from the test case file
3983 @validstdout = fixarray(@validstdout);
3984
3985 # get all attributes
3986 my %hash = getpartattr("verify", "stdout");
3987
3988 # get the mode attribute
3989 my $filemode=$hash{'mode'};
3990 if($filemode && ($filemode eq "text") && $has_textaware) {
3991 # text mode when running on windows: fix line endings
3992 map s/\r\n/\n/g, @validstdout;
3993 map s/\n/\r\n/g, @validstdout;
3994 }
3995
3996 if($hash{'nonewline'}) {
3997 # Yes, we must cut off the final newline from the final line
3998 # of the protocol data
3999 chomp($validstdout[$#validstdout]);
4000 }
4001
4002 $res = compare($testnum, $testname, "stdout", \@actual, \@validstdout);
4003 if($res) {
4004 return $errorreturncode;
4005 }
4006 $ok .= "s";
4007 }
4008 else {
4009 $ok .= "-"; # stdout not checked
4010 }
4011
4012 if (@validstderr) {
4013 # verify redirected stderr
4014 my @actual = loadarray($STDERR);
4015
4016 # what parts to cut off from stderr
4017 my @stripfile = getpart("verify", "stripfile");
4018
4019 foreach my $strip (@stripfile) {
4020 chomp $strip;
4021 my @newgen;
4022 for(@actual) {
4023 eval $strip;
4024 if($_) {
4025 push @newgen, $_;
4026 }
4027 }
4028 # this is to get rid of array entries that vanished (zero
4029 # length) because of replacements
4030 @actual = @newgen;
4031 }
4032
4033 # variable-replace in the stderr we have from the test case file
4034 @validstderr = fixarray(@validstderr);
4035
4036 # get all attributes
4037 my %hash = getpartattr("verify", "stderr");
4038
4039 # get the mode attribute
4040 my $filemode=$hash{'mode'};
4041 if($filemode && ($filemode eq "text") && $has_textaware) {
4042 # text mode when running on windows: fix line endings
4043 map s/\r\n/\n/g, @validstderr;
4044 map s/\n/\r\n/g, @validstderr;
4045 }
4046
4047 if($hash{'nonewline'}) {
4048 # Yes, we must cut off the final newline from the final line
4049 # of the protocol data
4050 chomp($validstderr[$#validstderr]);
4051 }
4052
4053 $res = compare($testnum, $testname, "stderr", \@actual, \@validstderr);
4054 if($res) {
4055 return $errorreturncode;
4056 }
4057 $ok .= "r";
4058 }
4059 else {
4060 $ok .= "-"; # stderr not checked
4061 }
4062
4063 if(@protocol) {
4064 # Verify the sent request
4065 my @out = loadarray($SERVERIN);
4066
4067 # what to cut off from the live protocol sent by curl
4068 my @strip = getpart("verify", "strip");
4069
4070 my @protstrip=@protocol;
4071
4072 # check if there's any attributes on the verify/protocol section
4073 my %hash = getpartattr("verify", "protocol");
4074
4075 if($hash{'nonewline'}) {
4076 # Yes, we must cut off the final newline from the final line
4077 # of the protocol data
4078 chomp($protstrip[$#protstrip]);
4079 }
4080
4081 for(@strip) {
4082 # strip off all lines that match the patterns from both arrays
4083 chomp $_;
4084 @out = striparray( $_, \@out);
4085 @protstrip= striparray( $_, \@protstrip);
4086 }
4087
4088 # what parts to cut off from the protocol
4089 my @strippart = getpart("verify", "strippart");
4090 my $strip;
4091 @strippart = fixarray(@strippart);
4092 for $strip (@strippart) {
4093 chomp $strip;
4094 for(@out) {
4095 eval $strip;
4096 }
4097 }
4098
4099 $res = compare($testnum, $testname, "protocol", \@out, \@protstrip);
4100 if($res) {
4101 return $errorreturncode;
4102 }
4103
4104 $ok .= "p";
4105
4106 }
4107 else {
4108 $ok .= "-"; # protocol not checked
4109 }
4110
4111 if(!$replyattr{'nocheck'} && (@reply || $replyattr{'sendzero'})) {
4112 # verify the received data
4113 my @out = loadarray($CURLOUT);
4114 $res = compare($testnum, $testname, "data", \@out, \@reply);
4115 if ($res) {
4116 return $errorreturncode;
4117 }
4118 $ok .= "d";
4119 }
4120 else {
4121 $ok .= "-"; # data not checked
4122 }
4123
4124 if(@upload) {
4125 # verify uploaded data
4126 my @out = loadarray("$LOGDIR/upload.$testnum");
4127
4128 # what parts to cut off from the upload
4129 my @strippart = getpart("verify", "strippart");
4130 my $strip;
4131 for $strip (@strippart) {
4132 chomp $strip;
4133 for(@out) {
4134 eval $strip;
4135 }
4136 }
4137
4138 $res = compare($testnum, $testname, "upload", \@out, \@upload);
4139 if ($res) {
4140 return $errorreturncode;
4141 }
4142 $ok .= "u";
4143 }
4144 else {
4145 $ok .= "-"; # upload not checked
4146 }
4147
4148 if(@proxyprot) {
4149 # Verify the sent proxy request
4150 my @out = loadarray($PROXYIN);
4151
4152 # what to cut off from the live protocol sent by curl, we use the
4153 # same rules as for <protocol>
4154 my @strip = getpart("verify", "strip");
4155
4156 my @protstrip=@proxyprot;
4157
4158 # check if there's any attributes on the verify/protocol section
4159 my %hash = getpartattr("verify", "proxy");
4160
4161 if($hash{'nonewline'}) {
4162 # Yes, we must cut off the final newline from the final line
4163 # of the protocol data
4164 chomp($protstrip[$#protstrip]);
4165 }
4166
4167 for(@strip) {
4168 # strip off all lines that match the patterns from both arrays
4169 chomp $_;
4170 @out = striparray( $_, \@out);
4171 @protstrip= striparray( $_, \@protstrip);
4172 }
4173
4174 # what parts to cut off from the protocol
4175 my @strippart = getpart("verify", "strippart");
4176 my $strip;
4177 for $strip (@strippart) {
4178 chomp $strip;
4179 for(@out) {
4180 eval $strip;
4181 }
4182 }
4183
4184 $res = compare($testnum, $testname, "proxy", \@out, \@protstrip);
4185 if($res) {
4186 return $errorreturncode;
4187 }
4188
4189 $ok .= "P";
4190
4191 }
4192 else {
4193 $ok .= "-"; # protocol not checked
4194 }
4195
4196 my $outputok;
4197 for my $partsuffix (('', '1', '2', '3', '4')) {
4198 my @outfile=getpart("verify", "file".$partsuffix);
4199 if(@outfile || partexists("verify", "file".$partsuffix) ) {
4200 # we're supposed to verify a dynamically generated file!
4201 my %hash = getpartattr("verify", "file".$partsuffix);
4202
4203 my $filename=$hash{'name'};
4204 if(!$filename) {
4205 logmsg "ERROR: section verify=>file$partsuffix ".
4206 "has no name attribute\n";
4207 stopservers($verbose);
4208 # timestamp test result verification end
4209 $timevrfyend{$testnum} = Time::HiRes::time();
4210 return -1;
4211 }
4212 my @generated=loadarray($filename);
4213
4214 # what parts to cut off from the file
4215 my @stripfile = getpart("verify", "stripfile".$partsuffix);
4216
4217 my $filemode=$hash{'mode'};
4218 if($filemode && ($filemode eq "text") && $has_textaware) {
4219 # text mode when running on windows: fix line endings
4220 map s/\r\n/\n/g, @outfile;
4221 map s/\n/\r\n/g, @outfile;
4222 }
4223
4224 my $strip;
4225 for $strip (@stripfile) {
4226 chomp $strip;
4227 my @newgen;
4228 for(@generated) {
4229 eval $strip;
4230 if($_) {
4231 push @newgen, $_;
4232 }
4233 }
4234 # this is to get rid of array entries that vanished (zero
4235 # length) because of replacements
4236 @generated = @newgen;
4237 }
4238
4239 @outfile = fixarray(@outfile);
4240
4241 $res = compare($testnum, $testname, "output ($filename)",
4242 \@generated, \@outfile);
4243 if($res) {
4244 return $errorreturncode;
4245 }
4246
4247 $outputok = 1; # output checked
4248 }
4249 }
4250 $ok .= ($outputok) ? "o" : "-"; # output checked or not
4251
4252 # accept multiple comma-separated error codes
4253 my @splerr = split(/ *, */, $errorcode);
4254 my $errok;
4255 foreach my $e (@splerr) {
4256 if($e == $cmdres) {
4257 # a fine error code
4258 $errok = 1;
4259 last;
4260 }
4261 }
4262
4263 if($errok) {
4264 $ok .= "e";
4265 }
4266 else {
4267 if(!$short) {
4268 logmsg sprintf("\n%s returned $cmdres, when expecting %s\n",
4269 (!$tool)?"curl":$tool, $errorcode);
4270 }
4271 logmsg " exit FAILED\n";
4272 # timestamp test result verification end
4273 $timevrfyend{$testnum} = Time::HiRes::time();
4274 return $errorreturncode;
4275 }
4276
4277 if($has_memory_tracking) {
4278 if(! -f $memdump) {
4279 logmsg "\n** ALERT! memory tracking with no output file?\n"
4280 if(!$cmdtype eq "perl");
4281 }
4282 else {
4283 my @memdata=`$memanalyze $memdump`;
4284 my $leak=0;
4285 for(@memdata) {
4286 if($_ ne "") {
4287 # well it could be other memory problems as well, but
4288 # we call it leak for short here
4289 $leak=1;
4290 }
4291 }
4292 if($leak) {
4293 logmsg "\n** MEMORY FAILURE\n";
4294 logmsg @memdata;
4295 # timestamp test result verification end
4296 $timevrfyend{$testnum} = Time::HiRes::time();
4297 return $errorreturncode;
4298 }
4299 else {
4300 $ok .= "m";
4301 }
4302 }
4303 }
4304 else {
4305 $ok .= "-"; # memory not checked
4306 }
4307
4308 if($valgrind) {
4309 if($usevalgrind) {
4310 unless(opendir(DIR, "$LOGDIR")) {
4311 logmsg "ERROR: unable to read $LOGDIR\n";
4312 # timestamp test result verification end
4313 $timevrfyend{$testnum} = Time::HiRes::time();
4314 return $errorreturncode;
4315 }
4316 my @files = readdir(DIR);
4317 closedir(DIR);
4318 my $vgfile;
4319 foreach my $file (@files) {
4320 if($file =~ /^valgrind$testnum(\..*|)$/) {
4321 $vgfile = $file;
4322 last;
4323 }
4324 }
4325 if(!$vgfile) {
4326 logmsg "ERROR: valgrind log file missing for test $testnum\n";
4327 # timestamp test result verification end
4328 $timevrfyend{$testnum} = Time::HiRes::time();
4329 return $errorreturncode;
4330 }
4331 my @e = valgrindparse("$LOGDIR/$vgfile");
4332 if(@e && $e[0]) {
4333 if($automakestyle) {
4334 logmsg "FAIL: $testnum - $testname - valgrind\n";
4335 }
4336 else {
4337 logmsg " valgrind ERROR ";
4338 logmsg @e;
4339 }
4340 # timestamp test result verification end
4341 $timevrfyend{$testnum} = Time::HiRes::time();
4342 return $errorreturncode;
4343 }
4344 $ok .= "v";
4345 }
4346 else {
4347 if(!$short && !$disablevalgrind) {
4348 logmsg " valgrind SKIPPED\n";
4349 }
4350 $ok .= "-"; # skipped
4351 }
4352 }
4353 else {
4354 $ok .= "-"; # valgrind not checked
4355 }
4356 # add 'E' for event-based
4357 $ok .= $evbased ? "E" : "-";
4358
4359 logmsg "$ok " if(!$short);
4360
4361 # timestamp test result verification end
4362 $timevrfyend{$testnum} = Time::HiRes::time();
4363
4364 my $sofar= time()-$start;
4365 my $esttotal = $sofar/$count * $total;
4366 my $estleft = $esttotal - $sofar;
4367 my $left=sprintf("remaining: %02d:%02d",
4368 $estleft/60,
4369 $estleft%60);
4370 my $took = $timevrfyend{$testnum} - $timeprepini{$testnum};
4371 my $duration = sprintf("duration: %02d:%02d",
4372 $sofar/60, $sofar%60);
4373 if(!$automakestyle) {
4374 logmsg sprintf("OK (%-3d out of %-3d, %s, took %.1fs, %s)\n",
4375 $count, $total, $left, $took, $duration);
4376 }
4377 else {
4378 logmsg "PASS: $testnum - $testname\n";
4379 }
4380
4381 if($errorreturncode==2) {
4382 logmsg "Warning: test$testnum result is ignored, but passed!\n";
4383 }
4384
4385 return 0;
4386 }
4387
4388 #######################################################################
4389 # Stop all running test servers
4390 #
4391 sub stopservers {
4392 my $verbose = $_[0];
4393 #
4394 # kill sockfilter processes for all pingpong servers
4395 #
4396 killallsockfilters($verbose);
4397 #
4398 # kill all server pids from %run hash clearing them
4399 #
4400 my $pidlist;
4401 foreach my $server (keys %run) {
4402 if($run{$server}) {
4403 if($verbose) {
4404 my $prev = 0;
4405 my $pids = $run{$server};
4406 foreach my $pid (split(' ', $pids)) {
4407 if($pid != $prev) {
4408 logmsg sprintf("* kill pid for %s => %d\n",
4409 $server, $pid);
4410 $prev = $pid;
4411 }
4412 }
4413 }
4414 $pidlist .= "$run{$server} ";
4415 $run{$server} = 0;
4416 }
4417 $runcert{$server} = 0 if($runcert{$server});
4418 }
4419 killpid($verbose, $pidlist);
4420 #
4421 # cleanup all server pid files
4422 #
4423 foreach my $server (keys %serverpidfile) {
4424 my $pidfile = $serverpidfile{$server};
4425 my $pid = processexists($pidfile);
4426 if($pid > 0) {
4427 logmsg "Warning: $server server unexpectedly alive\n";
4428 killpid($verbose, $pid);
4429 }
4430 unlink($pidfile) if(-f $pidfile);
4431 }
4432 }
4433
4434 #######################################################################
4435 # startservers() starts all the named servers
4436 #
4437 # Returns: string with error reason or blank for success
4438 #
4439 sub startservers {
4440 my @what = @_;
4441 my ($pid, $pid2);
4442 for(@what) {
4443 my (@whatlist) = split(/\s+/,$_);
4444 my $what = lc($whatlist[0]);
4445 $what =~ s/[^a-z0-9\/-]//g;
4446
4447 my $certfile;
4448 if($what =~ /^(ftp|http|imap|pop3|smtp)s((\d*)(-ipv6|-unix|))$/) {
4449 $certfile = ($whatlist[1]) ? $whatlist[1] : 'stunnel.pem';
4450 }
4451
4452 if(($what eq "pop3") ||
4453 ($what eq "ftp") ||
4454 ($what eq "imap") ||
4455 ($what eq "smtp")) {
4456 if($torture && $run{$what} &&
4457 !responsive_pingpong_server($what, "", $verbose)) {
4458 stopserver($what);
4459 }
4460 if(!$run{$what}) {
4461 ($pid, $pid2) = runpingpongserver($what, "", $verbose);
4462 if($pid <= 0) {
4463 return "failed starting ". uc($what) ." server";
4464 }
4465 printf ("* pid $what => %d %d\n", $pid, $pid2) if($verbose);
4466 $run{$what}="$pid $pid2";
4467 }
4468 }
4469 elsif($what eq "ftp2") {
4470 if($torture && $run{'ftp2'} &&
4471 !responsive_pingpong_server("ftp", "2", $verbose)) {
4472 stopserver('ftp2');
4473 }
4474 if(!$run{'ftp2'}) {
4475 ($pid, $pid2) = runpingpongserver("ftp", "2", $verbose);
4476 if($pid <= 0) {
4477 return "failed starting FTP2 server";
4478 }
4479 printf ("* pid ftp2 => %d %d\n", $pid, $pid2) if($verbose);
4480 $run{'ftp2'}="$pid $pid2";
4481 }
4482 }
4483 elsif($what eq "ftp-ipv6") {
4484 if($torture && $run{'ftp-ipv6'} &&
4485 !responsive_pingpong_server("ftp", "", $verbose, "ipv6")) {
4486 stopserver('ftp-ipv6');
4487 }
4488 if(!$run{'ftp-ipv6'}) {
4489 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose, "ipv6");
4490 if($pid <= 0) {
4491 return "failed starting FTP-IPv6 server";
4492 }
4493 logmsg sprintf("* pid ftp-ipv6 => %d %d\n", $pid,
4494 $pid2) if($verbose);
4495 $run{'ftp-ipv6'}="$pid $pid2";
4496 }
4497 }
4498 elsif($what eq "gopher") {
4499 if($torture && $run{'gopher'} &&
4500 !responsive_http_server("gopher", $verbose, 0, $GOPHERPORT)) {
4501 stopserver('gopher');
4502 }
4503 if(!$run{'gopher'}) {
4504 ($pid, $pid2) = runhttpserver("gopher", $verbose, 0,
4505 $GOPHERPORT);
4506 if($pid <= 0) {
4507 return "failed starting GOPHER server";
4508 }
4509 logmsg sprintf ("* pid gopher => %d %d\n", $pid, $pid2)
4510 if($verbose);
4511 $run{'gopher'}="$pid $pid2";
4512 }
4513 }
4514 elsif($what eq "gopher-ipv6") {
4515 if($torture && $run{'gopher-ipv6'} &&
4516 !responsive_http_server("gopher", $verbose, "ipv6",
4517 $GOPHER6PORT)) {
4518 stopserver('gopher-ipv6');
4519 }
4520 if(!$run{'gopher-ipv6'}) {
4521 ($pid, $pid2) = runhttpserver("gopher", $verbose, "ipv6",
4522 $GOPHER6PORT);
4523 if($pid <= 0) {
4524 return "failed starting GOPHER-IPv6 server";
4525 }
4526 logmsg sprintf("* pid gopher-ipv6 => %d %d\n", $pid,
4527 $pid2) if($verbose);
4528 $run{'gopher-ipv6'}="$pid $pid2";
4529 }
4530 }
4531 elsif($what eq "http/2") {
4532 if(!$run{'http/2'}) {
4533 ($pid, $pid2) = runhttp2server($verbose, $HTTP2PORT);
4534 if($pid <= 0) {
4535 return "failed starting HTTP/2 server";
4536 }
4537 logmsg sprintf ("* pid http/2 => %d %d\n", $pid, $pid2)
4538 if($verbose);
4539 $run{'http/2'}="$pid $pid2";
4540 }
4541 }
4542 elsif($what eq "http") {
4543 if($torture && $run{'http'} &&
4544 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4545 stopserver('http');
4546 }
4547 if(!$run{'http'}) {
4548 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4549 $HTTPPORT);
4550 if($pid <= 0) {
4551 return "failed starting HTTP server";
4552 }
4553 logmsg sprintf ("* pid http => %d %d\n", $pid, $pid2)
4554 if($verbose);
4555 $run{'http'}="$pid $pid2";
4556 }
4557 }
4558 elsif($what eq "http-proxy") {
4559 if($torture && $run{'http-proxy'} &&
4560 !responsive_http_server("http", $verbose, "proxy",
4561 $HTTPPROXYPORT)) {
4562 stopserver('http-proxy');
4563 }
4564 if(!$run{'http-proxy'}) {
4565 ($pid, $pid2) = runhttpserver("http", $verbose, "proxy",
4566 $HTTPPROXYPORT);
4567 if($pid <= 0) {
4568 return "failed starting HTTP-proxy server";
4569 }
4570 logmsg sprintf ("* pid http-proxy => %d %d\n", $pid, $pid2)
4571 if($verbose);
4572 $run{'http-proxy'}="$pid $pid2";
4573 }
4574 }
4575 elsif($what eq "http-ipv6") {
4576 if($torture && $run{'http-ipv6'} &&
4577 !responsive_http_server("http", $verbose, "ipv6", $HTTP6PORT)) {
4578 stopserver('http-ipv6');
4579 }
4580 if(!$run{'http-ipv6'}) {
4581 ($pid, $pid2) = runhttpserver("http", $verbose, "ipv6",
4582 $HTTP6PORT);
4583 if($pid <= 0) {
4584 return "failed starting HTTP-IPv6 server";
4585 }
4586 logmsg sprintf("* pid http-ipv6 => %d %d\n", $pid, $pid2)
4587 if($verbose);
4588 $run{'http-ipv6'}="$pid $pid2";
4589 }
4590 }
4591 elsif($what eq "rtsp") {
4592 if($torture && $run{'rtsp'} &&
4593 !responsive_rtsp_server($verbose)) {
4594 stopserver('rtsp');
4595 }
4596 if(!$run{'rtsp'}) {
4597 ($pid, $pid2) = runrtspserver($verbose);
4598 if($pid <= 0) {
4599 return "failed starting RTSP server";
4600 }
4601 printf ("* pid rtsp => %d %d\n", $pid, $pid2) if($verbose);
4602 $run{'rtsp'}="$pid $pid2";
4603 }
4604 }
4605 elsif($what eq "rtsp-ipv6") {
4606 if($torture && $run{'rtsp-ipv6'} &&
4607 !responsive_rtsp_server($verbose, "ipv6")) {
4608 stopserver('rtsp-ipv6');
4609 }
4610 if(!$run{'rtsp-ipv6'}) {
4611 ($pid, $pid2) = runrtspserver($verbose, "ipv6");
4612 if($pid <= 0) {
4613 return "failed starting RTSP-IPv6 server";
4614 }
4615 logmsg sprintf("* pid rtsp-ipv6 => %d %d\n", $pid, $pid2)
4616 if($verbose);
4617 $run{'rtsp-ipv6'}="$pid $pid2";
4618 }
4619 }
4620 elsif($what eq "ftps") {
4621 if(!$stunnel) {
4622 # we can't run ftps tests without stunnel
4623 return "no stunnel";
4624 }
4625 if($runcert{'ftps'} && ($runcert{'ftps'} ne $certfile)) {
4626 # stop server when running and using a different cert
4627 stopserver('ftps');
4628 }
4629 if($torture && $run{'ftp'} &&
4630 !responsive_pingpong_server("ftp", "", $verbose)) {
4631 stopserver('ftp');
4632 }
4633 if(!$run{'ftp'}) {
4634 ($pid, $pid2) = runpingpongserver("ftp", "", $verbose);
4635 if($pid <= 0) {
4636 return "failed starting FTP server";
4637 }
4638 printf ("* pid ftp => %d %d\n", $pid, $pid2) if($verbose);
4639 $run{'ftp'}="$pid $pid2";
4640 }
4641 if(!$run{'ftps'}) {
4642 ($pid, $pid2) = runftpsserver($verbose, "", $certfile);
4643 if($pid <= 0) {
4644 return "failed starting FTPS server (stunnel)";
4645 }
4646 logmsg sprintf("* pid ftps => %d %d\n", $pid, $pid2)
4647 if($verbose);
4648 $run{'ftps'}="$pid $pid2";
4649 }
4650 }
4651 elsif($what eq "file") {
4652 # we support it but have no server!
4653 }
4654 elsif($what eq "https") {
4655 if(!$stunnel) {
4656 # we can't run https tests without stunnel
4657 return "no stunnel";
4658 }
4659 if($runcert{'https'} && ($runcert{'https'} ne $certfile)) {
4660 # stop server when running and using a different cert
4661 stopserver('https');
4662 }
4663 if($torture && $run{'http'} &&
4664 !responsive_http_server("http", $verbose, 0, $HTTPPORT)) {
4665 stopserver('http');
4666 }
4667 if(!$run{'http'}) {
4668 ($pid, $pid2) = runhttpserver("http", $verbose, 0,
4669 $HTTPPORT);
4670 if($pid <= 0) {
4671 return "failed starting HTTP server";
4672 }
4673 printf ("* pid http => %d %d\n", $pid, $pid2) if($verbose);
4674 $run{'http'}="$pid $pid2";
4675 }
4676 if(!$run{'https'}) {
4677 ($pid, $pid2) = runhttpsserver($verbose, "", $certfile);
4678 if($pid <= 0) {
4679 return "failed starting HTTPS server (stunnel)";
4680 }
4681 logmsg sprintf("* pid https => %d %d\n", $pid, $pid2)
4682 if($verbose);
4683 $run{'https'}="$pid $pid2";
4684 }
4685 }
4686 elsif($what eq "httptls") {
4687 if(!$httptlssrv) {
4688 # for now, we can't run http TLS-EXT tests without gnutls-serv
4689 return "no gnutls-serv";
4690 }
4691 if($torture && $run{'httptls'} &&
4692 !responsive_httptls_server($verbose, "IPv4")) {
4693 stopserver('httptls');
4694 }
4695 if(!$run{'httptls'}) {
4696 ($pid, $pid2) = runhttptlsserver($verbose, "IPv4");
4697 if($pid <= 0) {
4698 return "failed starting HTTPTLS server (gnutls-serv)";
4699 }
4700 logmsg sprintf("* pid httptls => %d %d\n", $pid, $pid2)
4701 if($verbose);
4702 $run{'httptls'}="$pid $pid2";
4703 }
4704 }
4705 elsif($what eq "httptls-ipv6") {
4706 if(!$httptlssrv) {
4707 # for now, we can't run http TLS-EXT tests without gnutls-serv
4708 return "no gnutls-serv";
4709 }
4710 if($torture && $run{'httptls-ipv6'} &&
4711 !responsive_httptls_server($verbose, "ipv6")) {
4712 stopserver('httptls-ipv6');
4713 }
4714 if(!$run{'httptls-ipv6'}) {
4715 ($pid, $pid2) = runhttptlsserver($verbose, "ipv6");
4716 if($pid <= 0) {
4717 return "failed starting HTTPTLS-IPv6 server (gnutls-serv)";
4718 }
4719 logmsg sprintf("* pid httptls-ipv6 => %d %d\n", $pid, $pid2)
4720 if($verbose);
4721 $run{'httptls-ipv6'}="$pid $pid2";
4722 }
4723 }
4724 elsif($what eq "tftp") {
4725 if($torture && $run{'tftp'} &&
4726 !responsive_tftp_server("", $verbose)) {
4727 stopserver('tftp');
4728 }
4729 if(!$run{'tftp'}) {
4730 ($pid, $pid2) = runtftpserver("", $verbose);
4731 if($pid <= 0) {
4732 return "failed starting TFTP server";
4733 }
4734 printf ("* pid tftp => %d %d\n", $pid, $pid2) if($verbose);
4735 $run{'tftp'}="$pid $pid2";
4736 }
4737 }
4738 elsif($what eq "tftp-ipv6") {
4739 if($torture && $run{'tftp-ipv6'} &&
4740 !responsive_tftp_server("", $verbose, "ipv6")) {
4741 stopserver('tftp-ipv6');
4742 }
4743 if(!$run{'tftp-ipv6'}) {
4744 ($pid, $pid2) = runtftpserver("", $verbose, "ipv6");
4745 if($pid <= 0) {
4746 return "failed starting TFTP-IPv6 server";
4747 }
4748 printf("* pid tftp-ipv6 => %d %d\n", $pid, $pid2) if($verbose);
4749 $run{'tftp-ipv6'}="$pid $pid2";
4750 }
4751 }
4752 elsif($what eq "sftp" || $what eq "scp") {
4753 if(!$run{'ssh'}) {
4754 ($pid, $pid2) = runsshserver("", $verbose);
4755 if($pid <= 0) {
4756 return "failed starting SSH server";
4757 }
4758 printf ("* pid ssh => %d %d\n", $pid, $pid2) if($verbose);
4759 $run{'ssh'}="$pid $pid2";
4760 }
4761 }
4762 elsif($what eq "socks4" || $what eq "socks5" ) {
4763 if(!$run{'socks'}) {
4764 ($pid, $pid2) = runsocksserver("", $verbose);
4765 if($pid <= 0) {
4766 return "failed starting socks server";
4767 }
4768 printf ("* pid socks => %d %d\n", $pid, $pid2) if($verbose);
4769 $run{'socks'}="$pid $pid2";
4770 }
4771 }
4772 elsif($what eq "http-unix") {
4773 if($torture && $run{'http-unix'} &&
4774 !responsive_http_server("http", $verbose, "unix", $HTTPUNIXPATH)) {
4775 stopserver('http-unix');
4776 }
4777 if(!$run{'http-unix'}) {
4778 ($pid, $pid2) = runhttpserver("http", $verbose, "unix",
4779 $HTTPUNIXPATH);
4780 if($pid <= 0) {
4781 return "failed starting HTTP-unix server";
4782 }
4783 logmsg sprintf("* pid http-unix => %d %d\n", $pid, $pid2)
4784 if($verbose);
4785 $run{'http-unix'}="$pid $pid2";
4786 }
4787 }
4788 elsif($what eq "dict") {
4789 if(!$run{'dict'}) {
4790 ($pid, $pid2) = rundictserver($verbose, "", $DICTPORT);
4791 if($pid <= 0) {
4792 return "failed starting DICT server";
4793 }
4794 logmsg sprintf ("* pid DICT => %d %d\n", $pid, $pid2)
4795 if($verbose);
4796 $run{'dict'}="$pid $pid2";
4797 }
4798 }
4799 elsif($what eq "smb") {
4800 if(!$run{'smb'}) {
4801 ($pid, $pid2) = runsmbserver($verbose, "", $SMBPORT);
4802 if($pid <= 0) {
4803 return "failed starting SMB server";
4804 }
4805 logmsg sprintf ("* pid SMB => %d %d\n", $pid, $pid2)
4806 if($verbose);
4807 $run{'dict'}="$pid $pid2";
4808 }
4809 }
4810 elsif($what eq "telnet") {
4811 if(!$run{'telnet'}) {
4812 ($pid, $pid2) = runnegtelnetserver($verbose,
4813 "",
4814 $NEGTELNETPORT);
4815 if($pid <= 0) {
4816 return "failed starting neg TELNET server";
4817 }
4818 logmsg sprintf ("* pid neg TELNET => %d %d\n", $pid, $pid2)
4819 if($verbose);
4820 $run{'dict'}="$pid $pid2";
4821 }
4822 }
4823 elsif($what eq "none") {
4824 logmsg "* starts no server\n" if ($verbose);
4825 }
4826 else {
4827 warn "we don't support a server for $what";
4828 return "no server for $what";
4829 }
4830 }
4831 return 0;
4832 }
4833
4834 ##############################################################################
4835 # This function makes sure the right set of server is running for the
4836 # specified test case. This is a useful design when we run single tests as not
4837 # all servers need to run then!
4838 #
4839 # Returns: a string, blank if everything is fine or a reason why it failed
4840 #
4841 sub serverfortest {
4842 my ($testnum)=@_;
4843
4844 my @what = getpart("client", "server");
4845
4846 if(!$what[0]) {
4847 warn "Test case $testnum has no server(s) specified";
4848 return "no server specified";
4849 }
4850
4851 for(my $i = scalar(@what) - 1; $i >= 0; $i--) {
4852 my $srvrline = $what[$i];
4853 chomp $srvrline if($srvrline);
4854 if($srvrline =~ /^(\S+)((\s*)(.*))/) {
4855 my $server = "${1}";
4856 my $lnrest = "${2}";
4857 my $tlsext;
4858 if($server =~ /^(httptls)(\+)(ext|srp)(\d*)(-ipv6|)$/) {
4859 $server = "${1}${4}${5}";
4860 $tlsext = uc("TLS-${3}");
4861 }
4862 if(! grep /^\Q$server\E$/, @protocols) {
4863 if(substr($server,0,5) ne "socks") {
4864 if($tlsext) {
4865 return "curl lacks $tlsext support";
4866 }
4867 else {
4868 return "curl lacks $server server support";
4869 }
4870 }
4871 }
4872 $what[$i] = "$server$lnrest" if($tlsext);
4873 }
4874 }
4875
4876 return &startservers(@what);
4877 }
4878
4879 #######################################################################
4880 # runtimestats displays test-suite run time statistics
4881 #
4882 sub runtimestats {
4883 my $lasttest = $_[0];
4884
4885 return if(not $timestats);
4886
4887 logmsg "\nTest suite total running time breakdown per task...\n\n";
4888
4889 my @timesrvr;
4890 my @timeprep;
4891 my @timetool;
4892 my @timelock;
4893 my @timevrfy;
4894 my @timetest;
4895 my $timesrvrtot = 0.0;
4896 my $timepreptot = 0.0;
4897 my $timetooltot = 0.0;
4898 my $timelocktot = 0.0;
4899 my $timevrfytot = 0.0;
4900 my $timetesttot = 0.0;
4901 my $counter;
4902
4903 for my $testnum (1 .. $lasttest) {
4904 if($timesrvrini{$testnum}) {
4905 $timesrvrtot += $timesrvrend{$testnum} - $timesrvrini{$testnum};
4906 $timepreptot +=
4907 (($timetoolini{$testnum} - $timeprepini{$testnum}) -
4908 ($timesrvrend{$testnum} - $timesrvrini{$testnum}));
4909 $timetooltot += $timetoolend{$testnum} - $timetoolini{$testnum};
4910 $timelocktot += $timesrvrlog{$testnum} - $timetoolend{$testnum};
4911 $timevrfytot += $timevrfyend{$testnum} - $timesrvrlog{$testnum};
4912 $timetesttot += $timevrfyend{$testnum} - $timeprepini{$testnum};
4913 push @timesrvr, sprintf("%06.3f %04d",
4914 $timesrvrend{$testnum} - $timesrvrini{$testnum}, $testnum);
4915 push @timeprep, sprintf("%06.3f %04d",
4916 ($timetoolini{$testnum} - $timeprepini{$testnum}) -
4917 ($timesrvrend{$testnum} - $timesrvrini{$testnum}), $testnum);
4918 push @timetool, sprintf("%06.3f %04d",
4919 $timetoolend{$testnum} - $timetoolini{$testnum}, $testnum);
4920 push @timelock, sprintf("%06.3f %04d",
4921 $timesrvrlog{$testnum} - $timetoolend{$testnum}, $testnum);
4922 push @timevrfy, sprintf("%06.3f %04d",
4923 $timevrfyend{$testnum} - $timesrvrlog{$testnum}, $testnum);
4924 push @timetest, sprintf("%06.3f %04d",
4925 $timevrfyend{$testnum} - $timeprepini{$testnum}, $testnum);
4926 }
4927 }
4928
4929 {
4930 no warnings 'numeric';
4931 @timesrvr = sort { $b <=> $a } @timesrvr;
4932 @timeprep = sort { $b <=> $a } @timeprep;
4933 @timetool = sort { $b <=> $a } @timetool;
4934 @timelock = sort { $b <=> $a } @timelock;
4935 @timevrfy = sort { $b <=> $a } @timevrfy;
4936 @timetest = sort { $b <=> $a } @timetest;
4937 }
4938
4939 logmsg "Spent ". sprintf("%08.3f ", $timesrvrtot) .
4940 "seconds starting and verifying test harness servers.\n";
4941 logmsg "Spent ". sprintf("%08.3f ", $timepreptot) .
4942 "seconds reading definitions and doing test preparations.\n";
4943 logmsg "Spent ". sprintf("%08.3f ", $timetooltot) .
4944 "seconds actually running test tools.\n";
4945 logmsg "Spent ". sprintf("%08.3f ", $timelocktot) .
4946 "seconds awaiting server logs lock removal.\n";
4947 logmsg "Spent ". sprintf("%08.3f ", $timevrfytot) .
4948 "seconds verifying test results.\n";
4949 logmsg "Spent ". sprintf("%08.3f ", $timetesttot) .
4950 "seconds doing all of the above.\n";
4951
4952 $counter = 25;
4953 logmsg "\nTest server starting and verification time per test ".
4954 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4955 logmsg "-time- test\n";
4956 logmsg "------ ----\n";
4957 foreach my $txt (@timesrvr) {
4958 last if((not $fullstats) && (not $counter--));
4959 logmsg "$txt\n";
4960 }
4961
4962 $counter = 10;
4963 logmsg "\nTest definition reading and preparation time per test ".
4964 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4965 logmsg "-time- test\n";
4966 logmsg "------ ----\n";
4967 foreach my $txt (@timeprep) {
4968 last if((not $fullstats) && (not $counter--));
4969 logmsg "$txt\n";
4970 }
4971
4972 $counter = 25;
4973 logmsg "\nTest tool execution time per test ".
4974 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4975 logmsg "-time- test\n";
4976 logmsg "------ ----\n";
4977 foreach my $txt (@timetool) {
4978 last if((not $fullstats) && (not $counter--));
4979 logmsg "$txt\n";
4980 }
4981
4982 $counter = 15;
4983 logmsg "\nTest server logs lock removal time per test ".
4984 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4985 logmsg "-time- test\n";
4986 logmsg "------ ----\n";
4987 foreach my $txt (@timelock) {
4988 last if((not $fullstats) && (not $counter--));
4989 logmsg "$txt\n";
4990 }
4991
4992 $counter = 10;
4993 logmsg "\nTest results verification time per test ".
4994 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
4995 logmsg "-time- test\n";
4996 logmsg "------ ----\n";
4997 foreach my $txt (@timevrfy) {
4998 last if((not $fullstats) && (not $counter--));
4999 logmsg "$txt\n";
5000 }
5001
5002 $counter = 50;
5003 logmsg "\nTotal time per test ".
5004 sprintf("(%s)...\n\n", (not $fullstats)?"top $counter":"full");
5005 logmsg "-time- test\n";
5006 logmsg "------ ----\n";
5007 foreach my $txt (@timetest) {
5008 last if((not $fullstats) && (not $counter--));
5009 logmsg "$txt\n";
5010 }
5011
5012 logmsg "\n";
5013 }
5014
5015 # globally disabled tests
5016 disabledtests("$TESTDIR/DISABLED");
5017
5018 # locally disabled tests, ignored by git etc
5019 disabledtests("$TESTDIR/DISABLED.local");
5020
5021 #######################################################################
5022 # Check options to this test program
5023 #
5024
5025 my $number=0;
5026 my $fromnum=-1;
5027 my @testthis;
5028 while(@ARGV) {
5029 if ($ARGV[0] eq "-v") {
5030 # verbose output
5031 $verbose=1;
5032 }
5033 elsif($ARGV[0] =~ /^-b(.*)/) {
5034 my $portno=$1;
5035 if($portno =~ s/(\d+)$//) {
5036 $base = int $1;
5037 }
5038 }
5039 elsif ($ARGV[0] eq "-c") {
5040 # use this path to curl instead of default
5041 $DBGCURL=$CURL="\"$ARGV[1]\"";
5042 shift @ARGV;
5043 }
5044 elsif ($ARGV[0] eq "-vc") {
5045 # use this path to a curl used to verify servers
5046
5047 # Particularly useful when you introduce a crashing bug somewhere in
5048 # the development version as then it won't be able to run any tests
5049 # since it can't verify the servers!
5050
5051 $VCURL="\"$ARGV[1]\"";
5052 shift @ARGV;
5053 }
5054 elsif ($ARGV[0] eq "-d") {
5055 # have the servers display protocol output
5056 $debugprotocol=1;
5057 }
5058 elsif($ARGV[0] eq "-e") {
5059 # run the tests cases event based if possible
5060 $run_event_based=1;
5061 }
5062 elsif ($ARGV[0] eq "-g") {
5063 # run this test with gdb
5064 $gdbthis=1;
5065 }
5066 elsif ($ARGV[0] eq "-gw") {
5067 # run this test with windowed gdb
5068 $gdbthis=1;
5069 $gdbxwin=1;
5070 }
5071 elsif($ARGV[0] eq "-s") {
5072 # short output
5073 $short=1;
5074 }
5075 elsif($ARGV[0] eq "-am") {
5076 # automake-style output
5077 $short=1;
5078 $automakestyle=1;
5079 }
5080 elsif($ARGV[0] eq "-n") {
5081 # no valgrind
5082 undef $valgrind;
5083 }
5084 elsif ($ARGV[0] eq "-R") {
5085 # execute in scrambled order
5086 $scrambleorder=1;
5087 }
5088 elsif($ARGV[0] =~ /^-t(.*)/) {
5089 # torture
5090 $torture=1;
5091 my $xtra = $1;
5092
5093 if($xtra =~ s/(\d+)$//) {
5094 $tortalloc = $1;
5095 }
5096 }
5097 elsif($ARGV[0] =~ /--shallow=(\d+)/) {
5098 # Fail no more than this amount per tests when running
5099 # torture.
5100 my ($num)=($1);
5101 $shallow=$num;
5102 }
5103 elsif($ARGV[0] =~ /--repeat=(\d+)/) {
5104 # Repeat-run the given tests this many times
5105 $repeat = $1;
5106 }
5107 elsif($ARGV[0] =~ /--seed=(\d+)/) {
5108 # Set a fixed random seed (used for -R and --shallow)
5109 $randseed = $1;
5110 }
5111 elsif($ARGV[0] eq "-a") {
5112 # continue anyway, even if a test fail
5113 $anyway=1;
5114 }
5115 elsif($ARGV[0] eq "-p") {
5116 $postmortem=1;
5117 }
5118 elsif($ARGV[0] eq "-l") {
5119 # lists the test case names only
5120 $listonly=1;
5121 }
5122 elsif($ARGV[0] eq "-k") {
5123 # keep stdout and stderr files after tests
5124 $keepoutfiles=1;
5125 }
5126 elsif($ARGV[0] eq "-r") {
5127 # run time statistics needs Time::HiRes
5128 if($Time::HiRes::VERSION) {
5129 keys(%timeprepini) = 1000;
5130 keys(%timesrvrini) = 1000;
5131 keys(%timesrvrend) = 1000;
5132 keys(%timetoolini) = 1000;
5133 keys(%timetoolend) = 1000;
5134 keys(%timesrvrlog) = 1000;
5135 keys(%timevrfyend) = 1000;
5136 $timestats=1;
5137 $fullstats=0;
5138 }
5139 }
5140 elsif($ARGV[0] eq "-rf") {
5141 # run time statistics needs Time::HiRes
5142 if($Time::HiRes::VERSION) {
5143 keys(%timeprepini) = 1000;
5144 keys(%timesrvrini) = 1000;
5145 keys(%timesrvrend) = 1000;
5146 keys(%timetoolini) = 1000;
5147 keys(%timetoolend) = 1000;
5148 keys(%timesrvrlog) = 1000;
5149 keys(%timevrfyend) = 1000;
5150 $timestats=1;
5151 $fullstats=1;
5152 }
5153 }
5154 elsif(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help")) {
5155 # show help text
5156 print <<EOHELP
5157 Usage: runtests.pl [options] [test selection(s)]
5158 -a continue even if a test fails
5159 -am automake style output PASS/FAIL: [number] [name]
5160 -bN use base port number N for test servers (default $base)
5161 -c path use this curl executable
5162 -d display server debug info
5163 -e event-based execution
5164 -g run the test case with gdb
5165 -gw run the test case with gdb as a windowed application
5166 -h this help text
5167 -k keep stdout and stderr files present after tests
5168 -l list all test case names/descriptions
5169 -n no valgrind
5170 -p print log file contents when a test fails
5171 -R scrambled order (uses the random seed, see --seed)
5172 -r run time statistics
5173 -rf full run time statistics
5174 -s short output
5175 --seed=[num] set the random seed to a fixed number
5176 --shallow=[num] randomly makes the torture tests "thinner"
5177 -t[N] torture (simulate function failures); N means fail Nth function
5178 -v verbose output
5179 -vc path use this curl only to verify the existing servers
5180 [num] like "5 6 9" or " 5 to 22 " to run those tests only
5181 [!num] like "!5 !6 !9" to disable those tests
5182 [~num] like "~5 ~6 ~9" to ignore the result of those tests
5183 [keyword] like "IPv6" to select only tests containing the key word
5184 [!keyword] like "!cookies" to disable any tests containing the key word
5185 [~keyword] like "~cookies" to ignore results of tests containing key word
5186 EOHELP
5187 ;
5188 exit;
5189 }
5190 elsif($ARGV[0] =~ /^(\d+)/) {
5191 $number = $1;
5192 if($fromnum >= 0) {
5193 for my $n ($fromnum .. $number) {
5194 if($disabled{$n}) {
5195 # skip disabled test cases
5196 my $why = "configured as DISABLED";
5197 $skipped++;
5198 $skipped{$why}++;
5199 $teststat[$n]=$why; # store reason for this test case
5200 }
5201 else {
5202 push @testthis, $n;
5203 }
5204 }
5205 $fromnum = -1;
5206 }
5207 else {
5208 push @testthis, $1;
5209 }
5210 }
5211 elsif($ARGV[0] =~ /^to$/i) {
5212 $fromnum = $number+1;
5213 }
5214 elsif($ARGV[0] =~ /^!(\d+)/) {
5215 $fromnum = -1;
5216 $disabled{$1}=$1;
5217 }
5218 elsif($ARGV[0] =~ /^~(\d+)/) {
5219 $fromnum = -1;
5220 $ignored{$1}=$1;
5221 }
5222 elsif($ARGV[0] =~ /^!(.+)/) {
5223 $disabled_keywords{lc($1)}=$1;
5224 }
5225 elsif($ARGV[0] =~ /^~(.+)/) {
5226 $ignored_keywords{lc($1)}=$1;
5227 }
5228 elsif($ARGV[0] =~ /^([-[{a-zA-Z].*)/) {
5229 $enabled_keywords{lc($1)}=$1;
5230 }
5231 else {
5232 print "Unknown option: $ARGV[0]\n";
5233 exit;
5234 }
5235 shift @ARGV;
5236 }
5237
5238 if(!$randseed) {
5239 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
5240 localtime(time);
5241 # seed of the month. December 2019 becomes 201912
5242 $randseed = ($year+1900)*100 + $mon+1;
5243 open(C, "$CURL --version 2>/dev/null|");
5244 my @c = <C>;
5245 close(C);
5246 # use the first line of output and get the md5 out of it
5247 my $str = md5($c[0]);
5248 $randseed += unpack('S', $str); # unsigned 16 bit value
5249 }
5250 srand $randseed;
5251
5252 if(@testthis && ($testthis[0] ne "")) {
5253 $TESTCASES=join(" ", @testthis);
5254 }
5255
5256 if($valgrind) {
5257 # we have found valgrind on the host, use it
5258
5259 # verify that we can invoke it fine
5260 my $code = runclient("valgrind >/dev/null 2>&1");
5261
5262 if(($code>>8) != 1) {
5263 #logmsg "Valgrind failure, disable it\n";
5264 undef $valgrind;
5265 } else {
5266
5267 # since valgrind 2.1.x, '--tool' option is mandatory
5268 # use it, if it is supported by the version installed on the system
5269 runclient("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
5270 if (($? >> 8)==0) {
5271 $valgrind_tool="--tool=memcheck";
5272 }
5273 open(C, "<$CURL");
5274 my $l = <C>;
5275 if($l =~ /^\#\!/) {
5276 # A shell script. This is typically when built with libtool,
5277 $valgrind="../libtool --mode=execute $valgrind";
5278 }
5279 close(C);
5280
5281 # valgrind 3 renamed the --logfile option to --log-file!!!
5282 my $ver=join(' ', runclientoutput("valgrind --version"));
5283 # cut off all but digits and dots
5284 $ver =~ s/[^0-9.]//g;
5285
5286 if($ver =~ /^(\d+)/) {
5287 $ver = $1;
5288 if($ver >= 3) {
5289 $valgrind_logfile="--log-file";
5290 }
5291 }
5292 }
5293 }
5294
5295 if ($gdbthis) {
5296 # open the executable curl and read the first 4 bytes of it
5297 open(CHECK, "<$CURL");
5298 my $c;
5299 sysread CHECK, $c, 4;
5300 close(CHECK);
5301 if($c eq "#! /") {
5302 # A shell script. This is typically when built with libtool,
5303 $libtool = 1;
5304 $gdb = "../libtool --mode=execute gdb";
5305 }
5306 }
5307
5308 $HTTPPORT = $base++; # HTTP server port
5309 $HTTPSPORT = $base++; # HTTPS (stunnel) server port
5310 $FTPPORT = $base++; # FTP server port
5311 $FTPSPORT = $base++; # FTPS (stunnel) server port
5312 $HTTP6PORT = $base++; # HTTP IPv6 server port
5313 $FTP2PORT = $base++; # FTP server 2 port
5314 $FTP6PORT = $base++; # FTP IPv6 port
5315 $TFTPPORT = $base++; # TFTP (UDP) port
5316 $TFTP6PORT = $base++; # TFTP IPv6 (UDP) port
5317 $SSHPORT = $base++; # SSH (SCP/SFTP) port
5318 $SOCKSPORT = $base++; # SOCKS port
5319 $POP3PORT = $base++; # POP3 server port
5320 $POP36PORT = $base++; # POP3 IPv6 server port
5321 $IMAPPORT = $base++; # IMAP server port
5322 $IMAP6PORT = $base++; # IMAP IPv6 server port
5323 $SMTPPORT = $base++; # SMTP server port
5324 $SMTP6PORT = $base++; # SMTP IPv6 server port
5325 $RTSPPORT = $base++; # RTSP server port
5326 $RTSP6PORT = $base++; # RTSP IPv6 server port
5327 $GOPHERPORT = $base++; # Gopher IPv4 server port
5328 $GOPHER6PORT = $base++; # Gopher IPv6 server port
5329 $HTTPTLSPORT = $base++; # HTTP TLS (non-stunnel) server port
5330 $HTTPTLS6PORT = $base++; # HTTP TLS (non-stunnel) IPv6 server port
5331 $HTTPPROXYPORT = $base++; # HTTP proxy port, when using CONNECT
5332 $HTTP2PORT = $base++; # HTTP/2 port
5333 $DICTPORT = $base++; # DICT port
5334 $SMBPORT = $base++; # SMB port
5335 $SMBSPORT = $base++; # SMBS port
5336 $NEGTELNETPORT = $base++; # TELNET port with negotiation
5337 $HTTPUNIXPATH = 'http.sock'; # HTTP server Unix domain socket path
5338
5339 #######################################################################
5340 # clear and create logging directory:
5341 #
5342
5343 cleardir($LOGDIR);
5344 mkdir($LOGDIR, 0777);
5345
5346 #######################################################################
5347 # initialize some variables
5348 #
5349
5350 get_disttests();
5351 init_serverpidfile_hash();
5352
5353 #######################################################################
5354 # Output curl version and host info being tested
5355 #
5356
5357 if(!$listonly) {
5358 checksystem();
5359 }
5360
5361 #######################################################################
5362 # Fetch all disabled tests, if there are any
5363 #
5364
5365 sub disabledtests {
5366 my ($file) = @_;
5367
5368 if(open(D, "<$file")) {
5369 while(<D>) {
5370 if(/^ *\#/) {
5371 # allow comments
5372 next;
5373 }
5374 if($_ =~ /(\d+)/) {
5375 $disabled{$1}=$1; # disable this test number
5376 }
5377 }
5378 close(D);
5379 }
5380 }
5381
5382 #######################################################################
5383 # If 'all' tests are requested, find out all test numbers
5384 #
5385
5386 if ( $TESTCASES eq "all") {
5387 # Get all commands and find out their test numbers
5388 opendir(DIR, $TESTDIR) || die "can't opendir $TESTDIR: $!";
5389 my @cmds = grep { /^test([0-9]+)$/ && -f "$TESTDIR/$_" } readdir(DIR);
5390 closedir(DIR);
5391
5392 $TESTCASES=""; # start with no test cases
5393
5394 # cut off everything but the digits
5395 for(@cmds) {
5396 $_ =~ s/[a-z\/\.]*//g;
5397 }
5398 # sort the numbers from low to high
5399 foreach my $n (sort { $a <=> $b } @cmds) {
5400 if($disabled{$n}) {
5401 # skip disabled test cases
5402 my $why = "configured as DISABLED";
5403 $skipped++;
5404 $skipped{$why}++;
5405 $teststat[$n]=$why; # store reason for this test case
5406 next;
5407 }
5408 $TESTCASES .= " $n";
5409 }
5410 }
5411 else {
5412 my $verified="";
5413 map {
5414 if (-e "$TESTDIR/test$_") {
5415 $verified.="$_ ";
5416 }
5417 } split(" ", $TESTCASES);
5418 if($verified eq "") {
5419 print "No existing test cases were specified\n";
5420 exit;
5421 }
5422 $TESTCASES = $verified;
5423 }
5424 if($repeat) {
5425 my $s;
5426 for(1 .. $repeat) {
5427 $s .= $TESTCASES;
5428 }
5429 $TESTCASES = $s;
5430 }
5431
5432 if($scrambleorder) {
5433 # scramble the order of the test cases
5434 my @rand;
5435 while($TESTCASES) {
5436 my @all = split(/ +/, $TESTCASES);
5437 if(!$all[0]) {
5438 # if the first is blank, shift away it
5439 shift @all;
5440 }
5441 my $r = rand @all;
5442 push @rand, $all[$r];
5443 $all[$r]="";
5444 $TESTCASES = join(" ", @all);
5445 }
5446 $TESTCASES = join(" ", @rand);
5447 }
5448
5449 # Display the contents of the given file. Line endings are canonicalized
5450 # and excessively long files are elided
5451 sub displaylogcontent {
5452 my ($file)=@_;
5453 if(open(SINGLE, "<$file")) {
5454 my $linecount = 0;
5455 my $truncate;
5456 my @tail;
5457 while(my $string = <SINGLE>) {
5458 $string =~ s/\r\n/\n/g;
5459 $string =~ s/[\r\f\032]/\n/g;
5460 $string .= "\n" unless ($string =~ /\n$/);
5461 $string =~ tr/\n//;
5462 for my $line (split("\n", $string)) {
5463 $line =~ s/\s*\!$//;
5464 if ($truncate) {
5465 push @tail, " $line\n";
5466 } else {
5467 logmsg " $line\n";
5468 }
5469 $linecount++;
5470 $truncate = $linecount > 1000;
5471 }
5472 }
5473 if(@tail) {
5474 my $tailshow = 200;
5475 my $tailskip = 0;
5476 my $tailtotal = scalar @tail;
5477 if($tailtotal > $tailshow) {
5478 $tailskip = $tailtotal - $tailshow;
5479 logmsg "=== File too long: $tailskip lines omitted here\n";
5480 }
5481 for($tailskip .. $tailtotal-1) {
5482 logmsg "$tail[$_]";
5483 }
5484 }
5485 close(SINGLE);
5486 }
5487 }
5488
5489 sub displaylogs {
5490 my ($testnum)=@_;
5491 opendir(DIR, "$LOGDIR") ||
5492 die "can't open dir: $!";
5493 my @logs = readdir(DIR);
5494 closedir(DIR);
5495
5496 logmsg "== Contents of files in the $LOGDIR/ dir after test $testnum\n";
5497 foreach my $log (sort @logs) {
5498 if($log =~ /\.(\.|)$/) {
5499 next; # skip "." and ".."
5500 }
5501 if($log =~ /^\.nfs/) {
5502 next; # skip ".nfs"
5503 }
5504 if(($log eq "memdump") || ($log eq "core")) {
5505 next; # skip "memdump" and "core"
5506 }
5507 if((-d "$LOGDIR/$log") || (! -s "$LOGDIR/$log")) {
5508 next; # skip directory and empty files
5509 }
5510 if(($log =~ /^stdout\d+/) && ($log !~ /^stdout$testnum/)) {
5511 next; # skip stdoutNnn of other tests
5512 }
5513 if(($log =~ /^stderr\d+/) && ($log !~ /^stderr$testnum/)) {
5514 next; # skip stderrNnn of other tests
5515 }
5516 if(($log =~ /^upload\d+/) && ($log !~ /^upload$testnum/)) {
5517 next; # skip uploadNnn of other tests
5518 }
5519 if(($log =~ /^curl\d+\.out/) && ($log !~ /^curl$testnum\.out/)) {
5520 next; # skip curlNnn.out of other tests
5521 }
5522 if(($log =~ /^test\d+\.txt/) && ($log !~ /^test$testnum\.txt/)) {
5523 next; # skip testNnn.txt of other tests
5524 }
5525 if(($log =~ /^file\d+\.txt/) && ($log !~ /^file$testnum\.txt/)) {
5526 next; # skip fileNnn.txt of other tests
5527 }
5528 if(($log =~ /^netrc\d+/) && ($log !~ /^netrc$testnum/)) {
5529 next; # skip netrcNnn of other tests
5530 }
5531 if(($log =~ /^trace\d+/) && ($log !~ /^trace$testnum/)) {
5532 next; # skip traceNnn of other tests
5533 }
5534 if(($log =~ /^valgrind\d+/) && ($log !~ /^valgrind$testnum(\..*|)$/)) {
5535 next; # skip valgrindNnn of other tests
5536 }
5537 logmsg "=== Start of file $log\n";
5538 displaylogcontent("$LOGDIR/$log");
5539 logmsg "=== End of file $log\n";
5540 }
5541 }
5542
5543 #######################################################################
5544 # Setup Azure Pipelines Test Run (if running in Azure DevOps)
5545 #
5546
5547 if(azure_check_environment()) {
5548 $AZURE_RUN_ID = azure_create_test_run();
5549 logmsg "Azure Run ID: $AZURE_RUN_ID\n" if ($verbose);
5550 }
5551
5552 #######################################################################
5553 # The main test-loop
5554 #
5555
5556 my $failed;
5557 my $testnum;
5558 my $ok=0;
5559 my $ign=0;
5560 my $total=0;
5561 my $lasttest=0;
5562 my @at = split(" ", $TESTCASES);
5563 my $count=0;
5564
5565 $start = time();
5566
5567 foreach $testnum (@at) {
5568
5569 $lasttest = $testnum if($testnum > $lasttest);
5570 $count++;
5571
5572 my $error = singletest($run_event_based, $testnum, $count, scalar(@at));
5573
5574 # update test result in CI services
5575 if(azure_check_environment() && $AZURE_RUN_ID && $AZURE_RESULT_ID) {
5576 $AZURE_RESULT_ID = azure_update_test_result($AZURE_RUN_ID, $AZURE_RESULT_ID, $testnum, $error,
5577 $timeprepini{$testnum}, $timevrfyend{$testnum});
5578 }
5579 elsif(appveyor_check_environment()) {
5580 appveyor_update_test_result($testnum, $error, $timeprepini{$testnum}, $timevrfyend{$testnum});
5581 }
5582
5583 if($error < 0) {
5584 # not a test we can run
5585 next;
5586 }
5587
5588 $total++; # number of tests we've run
5589
5590 if($error>0) {
5591 $failed.= "$testnum ";
5592 if($postmortem) {
5593 # display all files in log/ in a nice way
5594 displaylogs($testnum);
5595 }
5596 if($error==2) {
5597 $ign++; # ignored test result counter
5598 }
5599 elsif(!$anyway) {
5600 # a test failed, abort
5601 logmsg "\n - abort tests\n";
5602 last;
5603 }
5604 }
5605 elsif(!$error) {
5606 $ok++; # successful test counter
5607 }
5608
5609 # loop for next test
5610 }
5611
5612 my $sofar = time() - $start;
5613
5614 #######################################################################
5615 # Finish Azure Pipelines Test Run (if running in Azure DevOps)
5616 #
5617
5618 if(azure_check_environment() && $AZURE_RUN_ID) {
5619 $AZURE_RUN_ID = azure_update_test_run($AZURE_RUN_ID);
5620 }
5621
5622 # Tests done, stop the servers
5623 stopservers($verbose);
5624
5625 my $all = $total + $skipped;
5626
5627 runtimestats($lasttest);
5628
5629 if($total) {
5630 logmsg sprintf("TESTDONE: $ok tests out of $total reported OK: %d%%\n",
5631 $ok/$total*100);
5632
5633 if($ok != $total) {
5634 logmsg "TESTFAIL: These test cases failed: $failed\n";
5635 }
5636 }
5637 else {
5638 logmsg "TESTFAIL: No tests were performed\n";
5639 }
5640
5641 if($all) {
5642 logmsg "TESTDONE: $all tests were considered during ".
5643 sprintf("%.0f", $sofar) ." seconds.\n";
5644 }
5645
5646 if($skipped && !$short) {
5647 my $s=0;
5648 logmsg "TESTINFO: $skipped tests were skipped due to these restraints:\n";
5649
5650 for(keys %skipped) {
5651 my $r = $_;
5652 printf "TESTINFO: \"%s\" %d times (", $r, $skipped{$_};
5653
5654 # now show all test case numbers that had this reason for being
5655 # skipped
5656 my $c=0;
5657 my $max = 9;
5658 for(0 .. scalar @teststat) {
5659 my $t = $_;
5660 if($teststat[$_] && ($teststat[$_] eq $r)) {
5661 if($c < $max) {
5662 logmsg ", " if($c);
5663 logmsg $_;
5664 }
5665 $c++;
5666 }
5667 }
5668 if($c > $max) {
5669 logmsg " and ".($c-$max)." more";
5670 }
5671 logmsg ")\n";
5672 }
5673 }
5674
5675 if($total && (($ok+$ign) != $total)) {
5676 exit 1;
5677 }