shorten the tcp system test

the tcp system test uses the 'packet.pl' test tool to send a packet
thousands of times. this took a long time because the tool was waiting
for replies and parsing them; however, for that particular test the
replies aren't relevant.

this commit uses non-blocking sockets and moves the reply parsing
outside the send loop, which speeds the system test up substantially.
This commit is contained in:
Evan Hunt
2020-09-04 10:58:47 -07:00
parent e5f31ce242
commit 1ceea908b6
2 changed files with 46 additions and 41 deletions

View File

@@ -33,10 +33,15 @@
#
# Usage: packet.pl [-a <address>] [-d] [-p <port>] [-t (udp|tcp)] [-r <repeats>] [filename]
#
# Options:
# -a <address>: specify address (XXX: no IPv6 support yet)
# -p <port>: specify port
# -t <protocol>: specify UDP or TCP
# -r <num>: send packet <num> times
# -d: dump response packets
#
# If not specified, address defaults to 127.0.0.1, port to 53, protocol
# to udp, and file to stdin.
#
# XXX: Doesn't support IPv6 yet
require 5.006.001;
@@ -88,6 +93,7 @@ my $output = unpack("H*", $data);
print ("sending $repeats time(s): $output\n");
my $sock = IO::Socket::INET->new(PeerAddr => $addr, PeerPort => $port,
Blocking => 0,
Proto => $proto,) or die "$!";
STDOUT->autoflush(1);
@@ -103,45 +109,48 @@ while ($repeats > 0) {
$repeats = $repeats - 1;
if ($repeats % 100 == 0) {
if ($repeats % 1000 == 0) {
print ".";
}
}
my $rin;
my $rout;
$rin = '';
vec($rin, fileno($sock), 1) = 1;
select($rout = $rin, undef, undef, 1);
if (vec($rout, fileno($sock), 1)) {
my $buf;
$sock->shutdown(SHUT_WR);
if ($proto eq "udp") {
$sock->recv($buf, 512);
my $rin;
my $rout;
$rin = '';
vec($rin, fileno($sock), 1) = 1;
select($rout = $rin, undef, undef, 1);
if (vec($rout, fileno($sock), 1)) {
my $buf;
if ($proto eq "udp") {
$sock->recv($buf, 512);
} else {
my $n = $sock->sysread($buf, 2);
last unless $n == 2;
my $len = unpack("n", $buf);
$n = $sock->sysread($buf, $len);
last unless $n == $len;
}
if (defined $options{d}) {
use Net::DNS;
use Net::DNS::Packet;
my $response;
if ($Net::DNS::VERSION > 0.68) {
$response = new Net::DNS::Packet(\$buf, 0);
$@ and die $@;
} else {
my $n = $sock->sysread($buf, 2);
last unless $n == 2;
my $len = unpack("n", $buf);
$n = $sock->sysread($buf, $len);
last unless $n == $len;
}
if (defined $options{d}) {
use Net::DNS;
use Net::DNS::Packet;
my $response;
if ($Net::DNS::VERSION > 0.68) {
$response = new Net::DNS::Packet(\$buf, 0);
$@ and die $@;
} else {
my $err;
($response, $err) = new Net::DNS::Packet(\$buf, 0);
$err and die $err;
}
$response->print;
my $err;
($response, $err) = new Net::DNS::Packet(\$buf, 0);
$err and die $err;
}
$response->print;
}
}
$sock->close;
close $file;
print ("sent $bytes bytes to $addr:$port\n");
print ("\nsent $bytes bytes to $addr:$port\n");

View File

@@ -186,13 +186,9 @@ status=$((status + ret))
n=$((n + 1))
echo_i "checking that BIND 9 doesn't crash on long TCP messages ($n)"
ret=0
if [ -z "$CI" ]; then
$PERL ../packet.pl -a "10.53.0.1" -p "${PORT}" -t tcp -r 300000 1996-alloc_dnsbuf-crash-test.pkt || ret=1
dig_with_opts +tcp @10.53.0.1 txt.example > dig.out.test$n || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
else
echo_i "skipped";
fi
{ $PERL ../packet.pl -a "10.53.0.1" -p "${PORT}" -t tcp -r 300000 1996-alloc_dnsbuf-crash-test.pkt || ret=1 ; } | cat_i
dig_with_opts +tcp @10.53.0.1 txt.example > dig.out.test$n || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=$((status + ret))
echo_i "exit status: $status"