From: Evan Hunt Date: Fri, 4 Sep 2020 17:58:47 +0000 (-0700) Subject: shorten the tcp system test X-Git-Tag: v9.17.6~71^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1ceea908b618f1637f8dc2d159c1e62d100081bd;p=thirdparty%2Fbind9.git 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. --- diff --git a/bin/tests/system/packet.pl b/bin/tests/system/packet.pl index f57cee928c7..433c12eb308 100644 --- a/bin/tests/system/packet.pl +++ b/bin/tests/system/packet.pl @@ -33,10 +33,15 @@ # # Usage: packet.pl [-a
] [-d] [-p ] [-t (udp|tcp)] [-r ] [filename] # +# Options: +# -a
: specify address (XXX: no IPv6 support yet) +# -p : specify port +# -t : specify UDP or TCP +# -r : send packet 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); - } 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; - } +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 $err; - ($response, $err) = new Net::DNS::Packet(\$buf, 0); - $err and die $err; - } - $response->print; + 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; } } + $sock->close; close $file; -print ("sent $bytes bytes to $addr:$port\n"); +print ("\nsent $bytes bytes to $addr:$port\n"); diff --git a/bin/tests/system/tcp/tests.sh b/bin/tests/system/tcp/tests.sh index 92c3555c371..85c275190b5 100644 --- a/bin/tests/system/tcp/tests.sh +++ b/bin/tests/system/tcp/tests.sh @@ -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"