runtests: move the smbserver to use a dynamic port number

Closes #5782
This commit is contained in:
Daniel Stenberg 2020-08-05 15:03:46 +02:00
parent c8ec04065a
commit 70999e6034
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -2480,7 +2480,7 @@ sub rundictserver {
# start the SMB server # start the SMB server
# #
sub runsmbserver { sub runsmbserver {
my ($verbose, $alt, $port) = @_; my ($verbose, $alt) = @_;
my $proto = "smb"; my $proto = "smb";
my $ip = $HOSTIP; my $ip = $HOSTIP;
my $ipvnum = 4; my $ipvnum = 4;
@ -2517,38 +2517,35 @@ sub runsmbserver {
$flags .= "--verbose 1 " if($debugprotocol); $flags .= "--verbose 1 " if($debugprotocol);
$flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" "; $flags .= "--pidfile \"$pidfile\" --logfile \"$logfile\" ";
$flags .= "--id $idnum " if($idnum > 1); $flags .= "--id $idnum " if($idnum > 1);
$flags .= "--port $port --srcdir \"$srcdir\" "; $flags .= "--srcdir \"$srcdir\" ";
$flags .= "--host $HOSTIP"; $flags .= "--host $HOSTIP";
my $cmd = "$srcdir/smbserver.py $flags"; my ($smbpid, $pid2);
my ($smbpid, $pid2) = startnew($cmd, $pidfile, 15, 0); my $port = 31923;
for(1 .. 10) {
$port += int(rand(760));
my $aflags = "--port $port $flags";
my $cmd = "$srcdir/smbserver.py $aflags";
($smbpid, $pid2) = startnew($cmd, $pidfile, 15, 0);
if($smbpid <= 0 || !pidexists($smbpid)) { if($smbpid <= 0 || !pidexists($smbpid)) {
# it is NOT alive # it is NOT alive
logmsg "RUN: failed to start the $srvrname server\n"; logmsg "RUN: failed to start the $srvrname server\n";
stopserver($server, "$pid2"); stopserver($server, "$pid2");
displaylogs($testnumcheck); displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1; $doesntrun{$pidfile} = 1;
return (0,0); $smbpid = $pid2 = 0;
next;
}
$doesntrun{$pidfile} = 0;
if($verbose) {
logmsg "RUN: $srvrname server PID $smbpid port $port\n";
}
last;
} }
# Server is up. Verify that we can speak to it. return ($smbpid, $pid2, $port);
my $pid3 = verifyserver($proto, $ipvnum, $idnum, $ip, $port);
if(!$pid3) {
logmsg "RUN: $srvrname server failed verification\n";
# failed to talk to it properly. Kill the server and return failure
stopserver($server, "$smbpid $pid2");
displaylogs($testnumcheck);
$doesntrun{$pidfile} = 1;
return (0,0);
}
$pid2 = $pid3;
if($verbose) {
logmsg "RUN: $srvrname server is now running PID $smbpid\n";
}
return ($smbpid, $pid2);
} }
####################################################################### #######################################################################
@ -3226,8 +3223,6 @@ sub checksystem {
logmsg ("* Port range: $minport-$maxport\n"); logmsg ("* Port range: $minport-$maxport\n");
if($verbose) { if($verbose) {
logmsg "* Ports: ";
if($has_unix) { if($has_unix) {
logmsg "* Unix socket paths:\n"; logmsg "* Unix socket paths:\n";
if($http_unix) { if($http_unix) {
@ -4979,7 +4974,7 @@ sub startservers {
} }
elsif($what eq "smb") { elsif($what eq "smb") {
if(!$run{'smb'}) { if(!$run{'smb'}) {
($pid, $pid2) = runsmbserver($verbose, "", $SMBPORT); ($pid, $pid2, $SMBPORT) = runsmbserver($verbose, "");
if($pid <= 0) { if($pid <= 0) {
return "failed starting SMB server"; return "failed starting SMB server";
} }
@ -5495,8 +5490,6 @@ if ($gdbthis) {
$minport = $base; # original base port number $minport = $base; # original base port number
$DICTPORT = $base++; # DICT port $DICTPORT = $base++; # DICT port
$SMBPORT = $base++; # SMB port
$SMBSPORT = $base++; # SMBS port
$NEGTELNETPORT = $base++; # TELNET port with negotiation $NEGTELNETPORT = $base++; # TELNET port with negotiation
$HTTPUNIXPATH = "http$$.sock"; # HTTP server Unix domain socket path $HTTPUNIXPATH = "http$$.sock"; # HTTP server Unix domain socket path