]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
shorten the tcp system test
authorEvan Hunt <each@isc.org>
Fri, 4 Sep 2020 17:58:47 +0000 (10:58 -0700)
committerEvan Hunt <each@isc.org>
Fri, 4 Sep 2020 21:22:53 +0000 (14:22 -0700)
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.

(cherry picked from commit 1ceea908b618f1637f8dc2d159c1e62d100081bd)

bin/tests/system/packet.pl
bin/tests/system/tcp/tests.sh

index f57cee928c75de4344e2ac2df10c2ac5f824cf2b..433c12eb30894734cec494e4858f1939434a881a 100644 (file)
 #
 # 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);
-       } 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");
index 710f1bf1511735cfa8b2a82ee69e314d736240b7..081747533cecd7a06c8f141c4de14c29560f7f57 100644 (file)
@@ -187,13 +187,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"