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