From 4464583a6edadfd1d337e94f358ed99be8fbae7e Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Tue, 25 Oct 2011 23:19:36 +0200 Subject: [PATCH] runtests.pl: running server checks When running torture tests, verify before each test case that required pingpong servers which are supposed to be alive are actually responsive. If found not responsive then restart them. --- tests/runtests.pl | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/runtests.pl b/tests/runtests.pl index 964e3b800..925c9ec11 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -1128,7 +1128,24 @@ sub verifyserver { return $pid; } +####################################################################### +# Single shot server responsiveness test. This should only be used +# to verify that a server present in %run hash is still functional +# +sub responsiveserver { + my ($proto, $ipvnum, $idnum, $ip, $port) = @_; + my $fun = $protofunc{$proto}; + my $pid = &$fun($proto, $ipvnum, $idnum, $ip, $port); + + if($pid > 0) { + return 1; # responsive + } + + my $srvrname = servername_str($proto, $ipvnum, $idnum); + logmsg "running server check FAILED (unresponsive $srvrname server)\n"; + return 0; +} ####################################################################### # start the http server @@ -1949,6 +1966,42 @@ sub runsocksserver { return ($pid2, $sshpid); } +####################################################################### +# Single shot pingpong server responsiveness test. This should only be +# used to verify that a server present in %run hash is still functional +# +sub responsive_pingpong_server { + my ($proto, $id, $verbose, $ipv6) = @_; + my $port; + my $ip = ($ipv6 && ($ipv6 =~ /6$/)) ? "$HOST6IP" : "$HOSTIP"; + my $ipvnum = ($ipv6 && ($ipv6 =~ /6$/)) ? 6 : 4; + my $idnum = ($id && ($id =~ /^(\d+)$/) && ($id > 1)) ? $id : 1; + + if($proto eq "ftp") { + $port = ($idnum>1)?$FTP2PORT:$FTPPORT; + + if($ipvnum==6) { + # if IPv6, use a different setup + $port = $FTP6PORT; + } + } + elsif($proto eq "pop3") { + $port = ($ipvnum==6) ? $POP36PORT : $POP3PORT; + } + elsif($proto eq "imap") { + $port = ($ipvnum==6) ? $IMAP6PORT : $IMAPPORT; + } + elsif($proto eq "smtp") { + $port = ($ipvnum==6) ? $SMTP6PORT : $SMTPPORT; + } + else { + print STDERR "Unsupported protocol $proto!!\n"; + return 0; + } + + return &responsiveserver($proto, $ipvnum, $idnum, $ip, $port); +} + ####################################################################### # Remove all files in the specified directory # @@ -3528,6 +3581,10 @@ sub startservers { ($what eq "ftp") || ($what eq "imap") || ($what eq "smtp")) { + if($torture && $run{$what} && + !responsive_pingpong_server($what, "", $verbose)) { + stopserver($what); + } if(!$run{$what}) { ($pid, $pid2) = runpingpongserver($what, "", $verbose); if($pid <= 0) { @@ -3538,6 +3595,10 @@ sub startservers { } } elsif($what eq "ftp2") { + if($torture && $run{'ftp2'} && + !responsive_pingpong_server("ftp", "2", $verbose)) { + stopserver('ftp2'); + } if(!$run{'ftp2'}) { ($pid, $pid2) = runpingpongserver("ftp", "2", $verbose); if($pid <= 0) { @@ -3548,6 +3609,10 @@ sub startservers { } } elsif($what eq "ftp-ipv6") { + if($torture && $run{'ftp-ipv6'} && + !responsive_pingpong_server("ftp", "", $verbose, "ipv6")) { + stopserver('ftp-ipv6'); + } if(!$run{'ftp-ipv6'}) { ($pid, $pid2) = runpingpongserver("ftp", "", $verbose, "ipv6"); if($pid <= 0) { @@ -3638,6 +3703,10 @@ sub startservers { # stop server when running and using a different cert stopserver('ftps'); } + if($torture && $run{'ftp'} && + !responsive_pingpong_server("ftp", "", $verbose)) { + stopserver('ftp'); + } if(!$run{'ftp'}) { ($pid, $pid2) = runpingpongserver("ftp", "", $verbose); if($pid <= 0) {