Skip to content

Commit

Permalink
tests: move pidfiles and portfiles under the log directory
Browse files Browse the repository at this point in the history
This is to segregate all files written by a test process into a single
root to allow for future parallel testing.

Ref: #10818
Closes #10874
  • Loading branch information
dfandrich committed Mar 31, 2023
1 parent 9c81ecd commit b78ec13
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 69 deletions.
10 changes: 5 additions & 5 deletions tests/ftp.pm
Expand Up @@ -322,7 +322,7 @@ sub killpid {
# killsockfilters kills sockfilter processes for a given server.
#
sub killsockfilters {
my ($proto, $ipvnum, $idnum, $verbose, $which) = @_;
my ($piddir, $proto, $ipvnum, $idnum, $verbose, $which) = @_;
my $server;
my $pidfile;
my $pid;
Expand All @@ -335,7 +335,7 @@ sub killsockfilters {
$server = servername_id($proto, $ipvnum, $idnum) if($verbose);

if(!$which || ($which eq 'main')) {
$pidfile = mainsockf_pidfilename($proto, $ipvnum, $idnum);
$pidfile = mainsockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$pid = processexists($pidfile);
if($pid > 0) {
printf("* kill pid for %s-%s => %d\n", $server,
Expand All @@ -349,7 +349,7 @@ sub killsockfilters {
return if($proto ne 'ftp');

if(!$which || ($which eq 'data')) {
$pidfile = datasockf_pidfilename($proto, $ipvnum, $idnum);
$pidfile = datasockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$pid = processexists($pidfile);
if($pid > 0) {
printf("* kill pid for %s-data => %d\n", $server,
Expand All @@ -365,12 +365,12 @@ sub killsockfilters {
# killallsockfilters kills sockfilter processes for all servers.
#
sub killallsockfilters {
my $verbose = $_[0];
my ($piddir, $verbose) = @_;

for my $proto (('ftp', 'imap', 'pop3', 'smtp')) {
for my $ipvnum (('4', '6')) {
for my $idnum (('1', '2')) {
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
}
}
}
Expand Down
55 changes: 33 additions & 22 deletions tests/ftpserver.pl
Expand Up @@ -40,6 +40,9 @@
# All socket/network/TCP related stuff is done by the 'sockfilt' program.
#

use strict;
use warnings;

BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
Expand All @@ -51,10 +54,9 @@ BEGIN
}
}

use strict;
use warnings;
use IPC::Open2;
use Digest::MD5;
use File::Basename;

require "getpart.pm";
require "ftp.pm";
Expand Down Expand Up @@ -88,6 +90,7 @@ BEGIN
my $testno = 0; # test case number (read from ftpserver.cmd)
my $path = '.';
my $logdir = $path .'/log';
my $piddir;

#**********************************************************************
# global vars used for server address and primary listener port
Expand All @@ -98,8 +101,9 @@ BEGIN
#**********************************************************************
# global vars used for file names
#
my $PORTFILE="ftpserver.port"; # server port file name
my $portfile; # server port file path
my $pidfile; # server pid file name
my $portfile=".ftpserver.port"; # server port file name
my $logfile; # server log file name
my $mainsockf_pidfile; # pid file for primary connection sockfilt process
my $mainsockf_logfile; # log file for primary connection sockfilt process
Expand Down Expand Up @@ -197,7 +201,7 @@ BEGIN
sub exit_signal_handler {
my $signame = shift;
# For now, simply mimic old behavior.
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand Down Expand Up @@ -397,7 +401,7 @@ sub sysread_or_die {
logmsg "Error: $srvrname server, sysread error: $!\n";
logmsg "Exited from sysread_or_die() at $fcaller " .
"line $lcaller. $srvrname server, sysread error: $!\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand All @@ -412,7 +416,7 @@ sub sysread_or_die {
logmsg "Error: $srvrname server, read zero\n";
logmsg "Exited from sysread_or_die() at $fcaller " .
"line $lcaller. $srvrname server, read zero\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand Down Expand Up @@ -441,7 +445,7 @@ sub startsf {

if($pong !~ /^PONG/) {
logmsg "Failed sockfilt command: $mainsockfcmd\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
unlink($portfile);
if($serverlogslocked) {
Expand Down Expand Up @@ -2453,7 +2457,7 @@ sub PASV_ftp {

# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
}
datasockf_state('STOPPED');
Expand Down Expand Up @@ -2494,7 +2498,7 @@ sub PASV_ftp {
logmsg "DATA sockfilt unexpected response: $pong\n";
logmsg "DATA sockfilt for passive data channel failed\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
sendcontrol "500 no free ports!\r\n";
Expand Down Expand Up @@ -2533,7 +2537,7 @@ sub PASV_ftp {
logmsg "DATA sockfilt unknown listener port\n";
logmsg "DATA sockfilt for passive data channel failed\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
sendcontrol "500 no free ports!\r\n";
Expand Down Expand Up @@ -2603,7 +2607,7 @@ sub PASV_ftp {
"on port $pasvport\n";
logmsg "accept failed or connection not even attempted\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
return;
Expand All @@ -2627,7 +2631,7 @@ sub PORT_ftp {

# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed\n";
}
datasockf_state('STOPPED');
Expand Down Expand Up @@ -2708,7 +2712,7 @@ sub PORT_ftp {
logmsg "DATA sockfilt unexpected response: $pong\n";
logmsg "DATA sockfilt for active data channel failed\n";
logmsg "DATA sockfilt killed now\n";
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt not running\n";
datasockf_state('STOPPED');
# client shall timeout awaiting connection from server
Expand Down Expand Up @@ -3038,25 +3042,32 @@ sub customize {
# Initialize command line option dependent variables
#

if($pidfile) {
# Use our pidfile directory to store the other pidfiles
$piddir = dirname($pidfile);
}
else {
# Use the current directory to store all the pidfiles
$piddir = $path;
$pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
}
if(!$portfile) {
$portfile = $piddir . "/" . $PORTFILE;
}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
if(!$pidfile) {
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
}

$mainsockf_pidfile = "$path/".
mainsockf_pidfilename($proto, $ipvnum, $idnum);
$mainsockf_pidfile = mainsockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$mainsockf_logfile =
mainsockf_logfilename($logdir, $proto, $ipvnum, $idnum);
$serverlogs_lockfile = "$logdir/$SERVERLOGS_LOCK";

if($proto eq 'ftp') {
$datasockf_pidfile = "$path/".
datasockf_pidfilename($proto, $ipvnum, $idnum);
$datasockf_pidfile = datasockf_pidfilename($piddir, $proto, $ipvnum, $idnum);
$datasockf_logfile =
datasockf_logfilename($logdir, $proto, $ipvnum, $idnum);
}
Expand Down Expand Up @@ -3093,7 +3104,7 @@ sub customize {

# kill previous data connection sockfilt when alive
if($datasockf_runs eq 'yes') {
killsockfilters($proto, $ipvnum, $idnum, $verbose, 'data');
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose, 'data');
logmsg "DATA sockfilt for $datasockf_mode data channel killed now\n";
}
datasockf_state('STOPPED');
Expand Down Expand Up @@ -3340,7 +3351,7 @@ sub customize {
}
}

killsockfilters($proto, $ipvnum, $idnum, $verbose);
killsockfilters($piddir, $proto, $ipvnum, $idnum, $verbose);
unlink($pidfile);
if($serverlogslocked) {
$serverlogslocked = 0;
Expand Down
27 changes: 20 additions & 7 deletions tests/http-server.pl
Expand Up @@ -23,13 +23,15 @@
#
#***************************************************************************

use strict;
use warnings;

BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}

use strict;
use warnings;
use File::Basename;

use serverhelp qw(
server_pidfilename
Expand Down Expand Up @@ -57,6 +59,7 @@ BEGIN
my $flags = "";
my $path = '.';
my $logdir = $path .'/log';
my $piddir;

while(@ARGV) {
if($ARGV[0] eq '--pidfile') {
Expand Down Expand Up @@ -138,14 +141,24 @@ BEGIN
shift @ARGV;
}

if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
#***************************************************************************
# Initialize command line option dependent variables
#

if($pidfile) {
# Use our pidfile directory to store the other pidfiles
$piddir = dirname($pidfile);
}
if(!$pidfile) {
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
else {
# Use the current directory to store all the pidfiles
$piddir = $path;
$pidfile = server_pidfilename($piddir, $proto, $ipvnum, $idnum);
}
if(!$portfile) {
$portfile = "$path/". server_portfilename($proto, $ipvnum, $idnum);
$portfile = server_portfilename($piddir, $proto, $ipvnum, $idnum);
}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
Expand Down
16 changes: 10 additions & 6 deletions tests/rtspserver.pl
Expand Up @@ -23,14 +23,14 @@
#
#***************************************************************************

use strict;
use warnings;

BEGIN {
push(@INC, $ENV{'srcdir'}) if(defined $ENV{'srcdir'});
push(@INC, ".");
}

use strict;
use warnings;

use serverhelp qw(
server_pidfilename
server_logfilename
Expand Down Expand Up @@ -112,12 +112,16 @@ BEGIN
shift @ARGV;
}

#***************************************************************************
# Initialize command line option dependent variables
#

if(!$pidfile) {
$pidfile = server_pidfilename($path, $proto, $ipvnum, $idnum);
}
if(!$srcdir) {
$srcdir = $ENV{'srcdir'} || '.';
}
if(!$pidfile) {
$pidfile = "$path/". server_pidfilename($proto, $ipvnum, $idnum);
}
if(!$logfile) {
$logfile = server_logfilename($logdir, $proto, $ipvnum, $idnum);
}
Expand Down

0 comments on commit b78ec13

Please sign in to comment.