Home | History | Annotate | Line # | Download | only in dnstap
tests.sh revision 1.1.1.9
      1 #!/bin/sh
      2 
      3 # Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      4 #
      5 # SPDX-License-Identifier: MPL-2.0
      6 #
      7 # This Source Code Form is subject to the terms of the Mozilla Public
      8 # License, v. 2.0.  If a copy of the MPL was not distributed with this
      9 # file, you can obtain one at https://mozilla.org/MPL/2.0/.
     10 #
     11 # See the COPYRIGHT file distributed with this work for additional
     12 # information regarding copyright ownership.
     13 
     14 SYSTEMTESTTOP=..
     15 . $SYSTEMTESTTOP/conf.sh
     16 
     17 DIGOPTS="+short -p ${PORT}"
     18 RNDCCMD="$RNDC -p ${CONTROLPORT} -c ../common/rndc.conf"
     19 
     20 status=0
     21 
     22 # dnstap_data_ready <fstrm_capture_PID> <capture_file> <min_file_size>
     23 # Flushes capture_file and checks wheter its size is >= min_file_size.
     24 dnstap_data_ready() {
     25 	# Process id of running fstrm_capture.
     26 	fstrm_capture_pid=$1
     27 	# Output file provided to fstrm_capture via -w switch.
     28 	capture_file=$2
     29 	# Minimum expected file size.
     30 	min_size_expected=$3
     31 
     32 	kill -HUP $fstrm_capture_pid
     33 	file_size=`wc -c < "$capture_file" | tr -d ' '`
     34 	if [ $file_size -lt $min_size_expected ]; then
     35 		return 1
     36 	fi
     37 }
     38 
     39 
     40 for bad in bad-*.conf
     41 do
     42 	ret=0
     43 	echo_i "checking that named-checkconf detects error in $bad"
     44 	$CHECKCONF $bad > /dev/null 2>&1
     45 	if [ $? != 1 ]; then echo_i "failed"; ret=1; fi
     46 	status=`expr $status + $ret`
     47 done
     48 
     49 for good in good-*.conf
     50 do
     51 	ret=0
     52 	echo_i "checking that named-checkconf detects no error in $good"
     53 	$CHECKCONF $good > /dev/null 2>&1
     54 	if [ $? != 0 ]; then echo_i "failed"; ret=1; fi
     55 	status=`expr $status + $ret`
     56 done
     57 
     58 echo_i "wait for servers to finish loading"
     59 ret=0
     60 wait_for_log 20 "all zones loaded" ns1/named.run || ret=1
     61 wait_for_log 20 "all zones loaded" ns2/named.run || ret=1
     62 wait_for_log 20 "all zones loaded" ns3/named.run || ret=1
     63 wait_for_log 20 "all zones loaded" ns4/named.run || ret=1
     64 if [ $ret != 0 ]; then echo_i "failed"; fi
     65 status=`expr $status + $ret`
     66 
     67 # both the 'a.example/A' lookup and the './NS' lookup to ns1
     68 # need tocomplete before reopening/rolling for the counts to
     69 # be correct.
     70 
     71 $DIG $DIGOPTS @10.53.0.3 a.example > dig.out
     72 wait_for_log 20 "(./NS): query_reset" ns1/named.run || true
     73 
     74 # check three different dnstap reopen/roll methods:
     75 # ns1: dnstap-reopen; ns2: dnstap -reopen; ns3: dnstap -roll
     76 mv ns1/dnstap.out ns1/dnstap.out.save
     77 mv ns2/dnstap.out ns2/dnstap.out.save
     78 
     79 if [ -n "$FSTRM_CAPTURE" ] ; then
     80 	$FSTRM_CAPTURE -t protobuf:dnstap.Dnstap -u ns4/dnstap.out \
     81 		-w dnstap.out > fstrm_capture.out 2>&1 &
     82 	fstrm_capture_pid=$!
     83 fi
     84 
     85 $RNDCCMD -s 10.53.0.1 dnstap-reopen | sed 's/^/ns1 /' | cat_i
     86 $RNDCCMD -s 10.53.0.2 dnstap -reopen | sed 's/^/ns2 /' | cat_i
     87 $RNDCCMD -s 10.53.0.3 dnstap -roll | sed 's/^/ns3 /' | cat_i
     88 $RNDCCMD -s 10.53.0.4 dnstap -reopen | sed 's/^/ns4 /' | cat_i
     89 
     90 $DIG $DIGOPTS @10.53.0.3 a.example > dig.out
     91 
     92 # send an UPDATE to ns2
     93 $NSUPDATE <<- EOF
     94 server 10.53.0.2 ${PORT}
     95 zone example
     96 update add b.example 3600 in a 10.10.10.10
     97 send
     98 EOF
     99 
    100 # XXX: file output should be flushed once a second according
    101 # to the libfstrm source, but it doesn't seem to happen until
    102 # enough data has accumulated. to get all the output, we stop
    103 # the name servers, forcing a flush on shutdown. it would be
    104 # nice to find a better way to do this.
    105 $RNDCCMD -s 10.53.0.1 stop | sed 's/^/ns1 /' | cat_i
    106 $RNDCCMD -s 10.53.0.2 stop | sed 's/^/ns2 /' | cat_i
    107 $RNDCCMD -s 10.53.0.3 stop | sed 's/^/ns3 /' | cat_i
    108 
    109 sleep 1
    110 
    111 echo_i "checking initial message counts"
    112 
    113 udp1=`$DNSTAPREAD ns1/dnstap.out.save | grep "UDP " | wc -l`
    114 tcp1=`$DNSTAPREAD ns1/dnstap.out.save | grep "TCP " | wc -l`
    115 aq1=`$DNSTAPREAD ns1/dnstap.out.save | grep "AQ " | wc -l`
    116 ar1=`$DNSTAPREAD ns1/dnstap.out.save | grep "AR " | wc -l`
    117 cq1=`$DNSTAPREAD ns1/dnstap.out.save | grep "CQ " | wc -l`
    118 cr1=`$DNSTAPREAD ns1/dnstap.out.save | grep "CR " | wc -l`
    119 rq1=`$DNSTAPREAD ns1/dnstap.out.save | grep "RQ " | wc -l`
    120 rr1=`$DNSTAPREAD ns1/dnstap.out.save | grep "RR " | wc -l`
    121 uq1=`$DNSTAPREAD ns1/dnstap.out.save | grep "UQ " | wc -l`
    122 ur1=`$DNSTAPREAD ns1/dnstap.out.save | grep "UR " | wc -l`
    123 
    124 udp2=`$DNSTAPREAD ns2/dnstap.out.save | grep "UDP " | wc -l`
    125 tcp2=`$DNSTAPREAD ns2/dnstap.out.save | grep "TCP " | wc -l`
    126 aq2=`$DNSTAPREAD ns2/dnstap.out.save | grep "AQ " | wc -l`
    127 ar2=`$DNSTAPREAD ns2/dnstap.out.save | grep "AR " | wc -l`
    128 cq2=`$DNSTAPREAD ns2/dnstap.out.save | grep "CQ " | wc -l`
    129 cr2=`$DNSTAPREAD ns2/dnstap.out.save | grep "CR " | wc -l`
    130 rq2=`$DNSTAPREAD ns2/dnstap.out.save | grep "RQ " | wc -l`
    131 rr2=`$DNSTAPREAD ns2/dnstap.out.save | grep "RR " | wc -l`
    132 uq2=`$DNSTAPREAD ns2/dnstap.out.save | grep "UQ " | wc -l`
    133 ur2=`$DNSTAPREAD ns2/dnstap.out.save | grep "UR " | wc -l`
    134 
    135 mv ns3/dnstap.out.0 ns3/dnstap.out.save
    136 udp3=`$DNSTAPREAD ns3/dnstap.out.save | grep "UDP " | wc -l`
    137 tcp3=`$DNSTAPREAD ns3/dnstap.out.save | grep "TCP " | wc -l`
    138 aq3=`$DNSTAPREAD ns3/dnstap.out.save | grep "AQ " | wc -l`
    139 ar3=`$DNSTAPREAD ns3/dnstap.out.save | grep "AR " | wc -l`
    140 cq3=`$DNSTAPREAD ns3/dnstap.out.save | grep "CQ " | wc -l`
    141 cr3=`$DNSTAPREAD ns3/dnstap.out.save | grep "CR " | wc -l`
    142 rq3=`$DNSTAPREAD ns3/dnstap.out.save | grep "RQ " | wc -l`
    143 rr3=`$DNSTAPREAD ns3/dnstap.out.save | grep "RR " | wc -l`
    144 uq3=`$DNSTAPREAD ns3/dnstap.out.save | grep "UQ " | wc -l`
    145 ur3=`$DNSTAPREAD ns3/dnstap.out.save | grep "UR " | wc -l`
    146 
    147 echo_i "checking UDP message counts"
    148 ret=0
    149 [ $udp1 -eq 0 ] || {
    150 	echo_i "ns1 $udp1 expected 0"
    151 	ret=1
    152 }
    153 [ $udp2 -eq 2 ] || {
    154 	echo_i "ns2 $udp2 expected 2"
    155 	ret=1
    156 }
    157 [ $udp3 -eq 4 ] || {
    158 	echo_i "ns3 $udp3 expected 4"
    159 	ret=1
    160 }
    161 if [ $ret != 0 ]; then echo_i "failed"; fi
    162 status=`expr $status + $ret`
    163 
    164 echo_i "checking TCP message counts"
    165 ret=0
    166 [ $tcp1 -eq 6 ] || {
    167 	echo_i "ns1 $tcp1 expected 6"
    168 	ret=1
    169 }
    170 [ $tcp2 -eq 2 ] || {
    171 	echo_i "ns2 $tcp2 expected 2"
    172 	ret=1
    173 }
    174 [ $tcp3 -eq 6 ] || {
    175 	echo_i "ns3 $tcp3 expected 6"
    176 	ret=1
    177 }
    178 if [ $ret != 0 ]; then echo_i "failed"; fi
    179 status=`expr $status + $ret`
    180 
    181 echo_i "checking AUTH_QUERY message counts"
    182 ret=0
    183 [ $aq1 -eq 3 ] || {
    184 	echo_i "ns1 $aq1 exepcted 3"
    185 	ret=1
    186 }
    187 [ $aq2 -eq 2 ] || {
    188 	echo_i "ns2 $aq2 expected 2"
    189 	ret=1
    190 }
    191 [ $aq3 -eq 1 ] || {
    192 	echo_i "ns3 $aq3 expected 1"
    193 	ret=1
    194 }
    195 if [ $ret != 0 ]; then echo_i "failed"; fi
    196 status=`expr $status + $ret`
    197 
    198 echo_i "checking AUTH_RESPONSE message counts"
    199 ret=0
    200 [ $ar1 -eq 2 ] || {
    201 	echo_i "ns1 $ar1 expected 2"
    202 	ret=1
    203 }
    204 [ $ar2 -eq 1 ] || {
    205 	echo_i "ns2 $ar2 expected 1"
    206 	ret=1
    207 }
    208 [ $ar3 -eq 0 ] || {
    209 	echo_i "ns3 $ar3 expected 0"
    210 	ret=1
    211 }
    212 if [ $ret != 0 ]; then echo_i "failed"; fi
    213 status=`expr $status + $ret`
    214 
    215 echo_i "checking CLIENT_QUERY message counts"
    216 ret=0
    217 [ $cq1 -eq 0 ] || {
    218 	echo_i "ns1 $cq1 expected 0"
    219 	ret=1
    220 }
    221 [ $cq2 -eq 0 ] || {
    222 	echo_i "ns2 $cq2 expected 0"
    223 	ret=1
    224 }
    225 [ $cq3 -eq 1 ] || {
    226 	echo_i "ns3 $cq3 expected 1"
    227 	ret=1
    228 }
    229 if [ $ret != 0 ]; then echo_i "failed"; fi
    230 status=`expr $status + $ret`
    231 
    232 echo_i "checking CLIENT_RESPONSE message counts"
    233 ret=0
    234 [ $cr1 -eq 1 ] || {
    235 	echo_i "ns1 $cr1 expected 1"
    236 	ret=1
    237 }
    238 [ $cr2 -eq 1 ] || {
    239 	echo_i "ns2 $cr2 expected 1"
    240 	ret=1
    241 }
    242 [ $cr3 -eq 2 ] || {
    243 	echo_i "ns3 $cr3 expected 2"
    244 	ret=1
    245 }
    246 if [ $ret != 0 ]; then echo_i "failed"; fi
    247 status=`expr $status + $ret`
    248 
    249 echo_i "checking RESOLVER_QUERY message counts"
    250 ret=0
    251 [ $rq1 -eq 0 ] || {
    252 	echo_i "ns1 $rq1 expected 0"
    253 	ret=1
    254 }
    255 [ $rq2 -eq 0 ] || {
    256 	echo_i "ns2 $rq2 expected 0"
    257 	ret=1
    258 }
    259 [ $rq3 -eq 3 ] || {
    260 	echo_i "ns3 $rq3 expected 3"
    261 	ret=1
    262 }
    263 if [ $ret != 0 ]; then echo_i "failed"; fi
    264 status=`expr $status + $ret`
    265 
    266 echo_i "checking RESOLVER_RESPONSE message counts"
    267 ret=0
    268 [ $rr1 -eq 0 ] || {
    269 	echo_i "ns1 $rr1 expected 0"
    270 	ret=1
    271 }
    272 [ $rr2 -eq 0 ] || {
    273 	echo_i "ns2 $rr2 expected 0"
    274 	ret=1
    275 }
    276 [ $rr3 -eq 3 ] || {
    277 	echo_i "ns3 $rr3 expected 3"
    278 	ret=1
    279 }
    280 if [ $ret != 0 ]; then echo_i "failed"; fi
    281 status=`expr $status + $ret`
    282 
    283 echo_i "checking UPDATE_QUERY message counts"
    284 ret=0
    285 [ $uq1 -eq 0 ] || {
    286 	echo_i "ns1 $uq1 expected 0"
    287 	ret=1
    288 }
    289 [ $uq2 -eq 0 ] || {
    290 	echo_i "ns2 $uq2 expected 0"
    291 	ret=1
    292 }
    293 [ $uq3 -eq 0 ] || {
    294 	echo_i "ns3 $uq3 expected 0"
    295 	ret=1
    296 }
    297 if [ $ret != 0 ]; then echo_i "failed"; fi
    298 status=`expr $status + $ret`
    299 
    300 echo_i "checking UPDATE_RESPONSE message counts"
    301 ret=0
    302 [ $ur1 -eq 0 ] || {
    303 	echo_i "ns1 $ur1 expected 0"
    304 	ret=1
    305 }
    306 [ $ur2 -eq 0 ] || {
    307 	echo_i "ns2 $ur2 expected 0"
    308 	ret=1
    309 }
    310 [ $ur3 -eq 0 ] || {
    311 	echo_i "ns3 $ur3 expected 0"
    312 	ret=1
    313 }
    314 if [ $ret != 0 ]; then echo_i "failed"; fi
    315 status=`expr $status + $ret`
    316 
    317 echo_i "checking reopened message counts"
    318 
    319 udp1=`$DNSTAPREAD ns1/dnstap.out | grep "UDP " | wc -l`
    320 tcp1=`$DNSTAPREAD ns1/dnstap.out | grep "TCP " | wc -l`
    321 aq1=`$DNSTAPREAD ns1/dnstap.out | grep "AQ " | wc -l`
    322 ar1=`$DNSTAPREAD ns1/dnstap.out | grep "AR " | wc -l`
    323 cq1=`$DNSTAPREAD ns1/dnstap.out | grep "CQ " | wc -l`
    324 cr1=`$DNSTAPREAD ns1/dnstap.out | grep "CR " | wc -l`
    325 rq1=`$DNSTAPREAD ns1/dnstap.out | grep "RQ " | wc -l`
    326 rr1=`$DNSTAPREAD ns1/dnstap.out | grep "RR " | wc -l`
    327 uq1=`$DNSTAPREAD ns1/dnstap.out | grep "UQ " | wc -l`
    328 ur1=`$DNSTAPREAD ns1/dnstap.out | grep "UR " | wc -l`
    329 
    330 udp2=`$DNSTAPREAD ns2/dnstap.out | grep "UDP " | wc -l`
    331 tcp2=`$DNSTAPREAD ns2/dnstap.out | grep "TCP " | wc -l`
    332 aq2=`$DNSTAPREAD ns2/dnstap.out | grep "AQ " | wc -l`
    333 ar2=`$DNSTAPREAD ns2/dnstap.out | grep "AR " | wc -l`
    334 cq2=`$DNSTAPREAD ns2/dnstap.out | grep "CQ " | wc -l`
    335 cr2=`$DNSTAPREAD ns2/dnstap.out | grep "CR " | wc -l`
    336 rq2=`$DNSTAPREAD ns2/dnstap.out | grep "RQ " | wc -l`
    337 rr2=`$DNSTAPREAD ns2/dnstap.out | grep "RR " | wc -l`
    338 uq2=`$DNSTAPREAD ns2/dnstap.out | grep "UQ " | wc -l`
    339 ur2=`$DNSTAPREAD ns2/dnstap.out | grep "UR " | wc -l`
    340 
    341 udp3=`$DNSTAPREAD ns3/dnstap.out | grep "UDP " | wc -l`
    342 tcp3=`$DNSTAPREAD ns3/dnstap.out | grep "TCP " | wc -l`
    343 aq3=`$DNSTAPREAD ns3/dnstap.out | grep "AQ " | wc -l`
    344 ar3=`$DNSTAPREAD ns3/dnstap.out | grep "AR " | wc -l`
    345 cq3=`$DNSTAPREAD ns3/dnstap.out | grep "CQ " | wc -l`
    346 cr3=`$DNSTAPREAD ns3/dnstap.out | grep "CR " | wc -l`
    347 rq3=`$DNSTAPREAD ns3/dnstap.out | grep "RQ " | wc -l`
    348 rr3=`$DNSTAPREAD ns3/dnstap.out | grep "RR " | wc -l`
    349 uq3=`$DNSTAPREAD ns3/dnstap.out | grep "UQ " | wc -l`
    350 ur3=`$DNSTAPREAD ns3/dnstap.out | grep "UR " | wc -l`
    351 
    352 echo_i "checking UDP message counts"
    353 ret=0
    354 [ $udp1 -eq 0 ] || {
    355 	echo_i "ns1 $udp1 expected 0"
    356 	ret=1
    357 }
    358 [ $udp2 -eq 2 ] || {
    359 	echo_i "ns2 $udp2 expected 2"
    360 	ret=1
    361 }
    362 [ $udp3 -eq 2 ] || {
    363 	echo_i "ns3 $udp3 expected 2"
    364 	ret=1
    365 }
    366 if [ $ret != 0 ]; then echo_i "failed"; fi
    367 status=`expr $status + $ret`
    368 
    369 echo_i "checking TCP message counts"
    370 ret=0
    371 [ $tcp1 -eq 0 ] || {
    372 	echo_i "ns1 $tcp1 expected 0"
    373 	ret=1
    374 }
    375 [ $tcp2 -eq 0 ] || {
    376 	echo_i "ns2 $tcp2 expected 0"
    377 	ret=1
    378 }
    379 [ $tcp3 -eq 0 ] || {
    380 	echo_i "ns3 $tcp3 expected 0"
    381 	ret=1
    382 }
    383 if [ $ret != 0 ]; then echo_i "failed"; fi
    384 status=`expr $status + $ret`
    385 
    386 echo_i "checking AUTH_QUERY message counts"
    387 ret=0
    388 [ $aq1 -eq 0 ] || {
    389 	echo_i "ns1 $aq1 exepcted 0"
    390 	ret=1
    391 }
    392 [ $aq2 -eq 0 ] || {
    393 	echo_i "ns2 $aq2 expected 0"
    394 	ret=1
    395 }
    396 [ $aq3 -eq 0 ] || {
    397 	echo_i "ns3 $aq3 expected 0"
    398 	ret=1
    399 }
    400 if [ $ret != 0 ]; then echo_i "failed"; fi
    401 status=`expr $status + $ret`
    402 
    403 echo_i "checking AUTH_RESPONSE message counts"
    404 ret=0
    405 [ $ar1 -eq 0 ] || {
    406 	echo_i "ns1 $ar1 expected 0"
    407 	ret=1
    408 }
    409 [ $ar2 -eq 0 ] || {
    410 	echo_i "ns2 $ar2 expected 0"
    411 	ret=1
    412 }
    413 [ $ar3 -eq 0 ] || {
    414 	echo_i "ns3 $ar3 expected 0"
    415 	ret=1
    416 }
    417 if [ $ret != 0 ]; then echo_i "failed"; fi
    418 status=`expr $status + $ret`
    419 
    420 echo_i "checking CLIENT_QUERY message counts"
    421 ret=0
    422 [ $cq1 -eq 0 ] || {
    423 	echo_i "ns1 $cq1 expected 0"
    424 	ret=1
    425 }
    426 [ $cq2 -eq 0 ] || {
    427 	echo_i "ns2 $cq2 expected 0"
    428 	ret=1
    429 }
    430 [ $cq3 -eq 1 ] || {
    431 	echo_i "ns3 $cq3 expected 1"
    432 	ret=1
    433 }
    434 if [ $ret != 0 ]; then echo_i "failed"; fi
    435 status=`expr $status + $ret`
    436 
    437 echo_i "checking CLIENT_RESPONSE message counts"
    438 ret=0
    439 [ $cr1 -eq 0 ] || {
    440 	echo_i "ns1 $cr1 expected 0"
    441 	ret=1
    442 }
    443 [ $cr2 -eq 0 ] || {
    444 	echo_i "ns2 $cr2 expected 0"
    445 	ret=1
    446 }
    447 [ $cr3 -eq 1 ] || {
    448 	echo_i "ns3 $cr3 expected 1"
    449 	ret=1
    450 }
    451 if [ $ret != 0 ]; then echo_i "failed"; fi
    452 status=`expr $status + $ret`
    453 
    454 echo_i "checking RESOLVER_QUERY message counts"
    455 ret=0
    456 [ $rq1 -eq 0 ] || {
    457 	echo_i "ns1 $rq1 expected 0"
    458 	ret=1
    459 }
    460 [ $rq2 -eq 0 ] || {
    461 	echo_i "ns2 $rq2 expected 0"
    462 	ret=1
    463 }
    464 [ $rq3 -eq 0 ] || {
    465 	echo_i "ns3 $rq3 expected 0"
    466 	ret=1
    467 }
    468 if [ $ret != 0 ]; then echo_i "failed"; fi
    469 status=`expr $status + $ret`
    470 
    471 echo_i "checking RESOLVER_RESPONSE message counts"
    472 ret=0
    473 [ $rr1 -eq 0 ] || {
    474 	echo_i "ns1 $rr1 expected 0"
    475 	ret=1
    476 }
    477 [ $rr2 -eq 0 ] || {
    478 	echo_i "ns2 $rr2 expected 0"
    479 	ret=1
    480 }
    481 [ $rr3 -eq 0 ] || {
    482 	echo_i "ns3 $rr3 expected 0"
    483 	ret=1
    484 }
    485 if [ $ret != 0 ]; then echo_i "failed"; fi
    486 status=`expr $status + $ret`
    487 
    488 echo_i "checking UPDATE_QUERY message counts"
    489 ret=0
    490 [ $uq1 -eq 0 ] || {
    491 	echo_i "ns1 $uq1 expected 0"
    492 	ret=1
    493 }
    494 [ $uq2 -eq 1 ] || {
    495 	echo_i "ns2 $uq2 expected 1"
    496 	ret=1
    497 }
    498 [ $uq3 -eq 0 ] || {
    499 	echo_i "ns3 $uq3 expected 0"
    500 	ret=1
    501 }
    502 if [ $ret != 0 ]; then echo_i "failed"; fi
    503 status=`expr $status + $ret`
    504 
    505 echo_i "checking UPDATE_RESPONSE message counts"
    506 ret=0
    507 [ $ur1 -eq 0 ] || {
    508 	echo_i "ns1 $ur1 expected 0"
    509 	ret=1
    510 }
    511 [ $ur2 -eq 1 ] || {
    512 	echo_i "ns2 $ur2 expected 1"
    513 	ret=1
    514 }
    515 [ $ur3 -eq 0 ] || {
    516 	echo_i "ns3 $ur3 expected 0"
    517 	ret=1
    518 }
    519 if [ $ret != 0 ]; then echo_i "failed"; fi
    520 status=`expr $status + $ret`
    521 
    522 echo_i "checking whether destination UDP port is logged for client queries"
    523 ret=0
    524 $DNSTAPREAD ns3/dnstap.out.save | grep -Eq "CQ [0-9:.]+ -> 10.53.0.3:${PORT} UDP" || ret=1
    525 if [ $ret != 0 ]; then echo_i "failed"; fi
    526 status=`expr $status + $ret`
    527 
    528 HAS_PYYAML=0
    529 if [ -n "$PYTHON" ] ; then
    530 	$PYTHON -c "import yaml" 2> /dev/null && HAS_PYYAML=1
    531 fi
    532 
    533 if [ $HAS_PYYAML -ne 0 ] ; then
    534 	echo_i "checking dnstap-read YAML output"
    535 	ret=0
    536         {
    537 	  $PYTHON ydump.py "$DNSTAPREAD" "ns3/dnstap.out.save" > ydump.out || ret=1
    538         } | cat_i
    539 	if [ $ret != 0 ]; then echo_i "failed"; fi
    540 	status=`expr $status + $ret`
    541 fi
    542 
    543 echo_i "checking dnstap-read hex output"
    544 ret=0
    545 hex=`$DNSTAPREAD -x ns3/dnstap.out | tail -1`
    546 echo $hex | $WIRETEST > dnstap.hex
    547 grep 'status: NOERROR' dnstap.hex > /dev/null 2>&1 || ret=1
    548 grep 'ANSWER: 3, AUTHORITY: 1' dnstap.hex > /dev/null 2>&1 || ret=1
    549 if [ $ret != 0 ]; then echo_i "failed"; fi
    550 status=`expr $status + $ret`
    551 
    552 if [ -n "$FSTRM_CAPTURE" ] ; then
    553 	$DIG $DIGOPTS @10.53.0.4 a.example > dig.out
    554 
    555 	# send an UPDATE to ns4
    556 	$NSUPDATE <<- EOF > nsupdate.out 2>&1
    557 	server 10.53.0.4 ${PORT}
    558 	zone example
    559 	update add b.example 3600 in a 10.10.10.10
    560 	send
    561 EOF
    562 	grep "update failed: NOTAUTH" nsupdate.out > /dev/null || ret=1
    563 
    564 	echo_i "checking unix socket message counts"
    565 	sleep 2
    566 	retry_quiet 5 dnstap_data_ready $fstrm_capture_pid dnstap.out 470
    567 	kill $fstrm_capture_pid
    568 	wait
    569 	udp4=`$DNSTAPREAD dnstap.out | grep "UDP " | wc -l`
    570 	tcp4=`$DNSTAPREAD dnstap.out | grep "TCP " | wc -l`
    571 	aq4=`$DNSTAPREAD dnstap.out | grep "AQ " | wc -l`
    572 	ar4=`$DNSTAPREAD dnstap.out | grep "AR " | wc -l`
    573 	cq4=`$DNSTAPREAD dnstap.out | grep "CQ " | wc -l`
    574 	cr4=`$DNSTAPREAD dnstap.out | grep "CR " | wc -l`
    575 	rq4=`$DNSTAPREAD dnstap.out | grep "RQ " | wc -l`
    576 	rr4=`$DNSTAPREAD dnstap.out | grep "RR " | wc -l`
    577 	uq4=`$DNSTAPREAD dnstap.out | grep "UQ " | wc -l`
    578 	ur4=`$DNSTAPREAD dnstap.out | grep "UR " | wc -l`
    579 
    580 	echo_i "checking UDP message counts"
    581 	ret=0
    582 	[ $udp4 -eq 4 ] || {
    583 		echo_i "ns4 $udp4 expected 4"
    584 		ret=1
    585 	}
    586 	if [ $ret != 0 ]; then echo_i "failed"; fi
    587 	status=`expr $status + $ret`
    588 
    589 	echo_i "checking TCP message counts"
    590 	ret=0
    591 	[ $tcp4 -eq 0 ] || {
    592 		echo_i "ns4 $tcp4 expected 0"
    593 		ret=1
    594 	}
    595 	if [ $ret != 0 ]; then echo_i "failed"; fi
    596 	status=`expr $status + $ret`
    597 
    598 	echo_i "checking AUTH_QUERY message counts"
    599 	ret=0
    600 	[ $aq4 -eq 0 ] || {
    601 		echo_i "ns4 $aq4 expected 0"
    602 		ret=1
    603 	}
    604 	if [ $ret != 0 ]; then echo_i "failed"; fi
    605 	status=`expr $status + $ret`
    606 
    607 	echo_i "checking AUTH_RESPONSE message counts"
    608 	ret=0
    609 	[ $ar4 -eq 0 ] || {
    610 		echo_i "ns4 $ar4 expected 0"
    611 		ret=1
    612 	}
    613 	if [ $ret != 0 ]; then echo_i "failed"; fi
    614 	status=`expr $status + $ret`
    615 
    616 	echo_i "checking CLIENT_QUERY message counts"
    617 	ret=0
    618 	[ $cq4 -eq 1 ] || {
    619 		echo_i "ns4 $cq4 expected 1"
    620 		ret=1
    621 	}
    622 	if [ $ret != 0 ]; then echo_i "failed"; fi
    623 	status=`expr $status + $ret`
    624 
    625 	echo_i "checking CLIENT_RESPONSE message counts"
    626 	ret=0
    627 	[ $cr4 -eq 1 ] || {
    628 		echo_i "ns4 $cr4 expected 1"
    629 		ret=1
    630 	}
    631 	if [ $ret != 0 ]; then echo_i "failed"; fi
    632 	status=`expr $status + $ret`
    633 
    634 	echo_i "checking RESOLVER_QUERY message counts"
    635 	ret=0
    636 	[ $rq4 -eq 0 ] || {
    637 		echo_i "ns4 $rq4 expected 0"
    638 		ret=1
    639 	}
    640 	if [ $ret != 0 ]; then echo_i "failed"; fi
    641 	status=`expr $status + $ret`
    642 
    643 	echo_i "checking RESOLVER_RESPONSE message counts"
    644 	ret=0
    645 	[ $rr4 -eq 0 ] || {
    646 		echo_i "ns4 $rr4 expected 0"
    647 		ret=1
    648 	}
    649 
    650 	echo_i "checking UPDATE_QUERY message counts"
    651 	ret=0
    652 	[ $uq4 -eq 1 ] || {
    653 		echo_i "ns4 $uq4 expected 1"
    654 		ret=1
    655 	}
    656 	if [ $ret != 0 ]; then echo_i "failed"; fi
    657 	status=`expr $status + $ret`
    658 
    659 	echo_i "checking UPDATE_RESPONSE message counts"
    660 	ret=0
    661 	[ $ur4 -eq 1 ] || {
    662 		echo_i "ns4 $ur4 expected 1"
    663 		ret=1
    664 	}
    665 	if [ $ret != 0 ]; then echo_i "failed"; fi
    666 	status=`expr $status + $ret`
    667 
    668 	mv dnstap.out dnstap.out.save
    669 
    670 	$FSTRM_CAPTURE -t protobuf:dnstap.Dnstap -u ns4/dnstap.out \
    671 		-w dnstap.out > fstrm_capture.out 2>&1 &
    672 	fstrm_capture_pid=$!
    673 	sleep 1
    674 	$RNDCCMD -s 10.53.0.4 dnstap -reopen | sed 's/^/ns4 /' | cat_i
    675 	$DIG $DIGOPTS @10.53.0.4 a.example > dig.out
    676 
    677 	echo_i "checking reopened unix socket message counts"
    678 	sleep 2
    679 	retry_quiet 5 dnstap_data_ready $fstrm_capture_pid dnstap.out 270
    680 	kill $fstrm_capture_pid
    681 	wait
    682 	udp4=`$DNSTAPREAD dnstap.out | grep "UDP " | wc -l`
    683 	tcp4=`$DNSTAPREAD dnstap.out | grep "TCP " | wc -l`
    684 	aq4=`$DNSTAPREAD dnstap.out | grep "AQ " | wc -l`
    685 	ar4=`$DNSTAPREAD dnstap.out | grep "AR " | wc -l`
    686 	cq4=`$DNSTAPREAD dnstap.out | grep "CQ " | wc -l`
    687 	cr4=`$DNSTAPREAD dnstap.out | grep "CR " | wc -l`
    688 	rq4=`$DNSTAPREAD dnstap.out | grep "RQ " | wc -l`
    689 	rr4=`$DNSTAPREAD dnstap.out | grep "RR " | wc -l`
    690 	uq4=`$DNSTAPREAD dnstap.out | grep "UQ " | wc -l`
    691 	ur4=`$DNSTAPREAD dnstap.out | grep "UR " | wc -l`
    692 
    693 	echo_i "checking UDP message counts"
    694 	ret=0
    695 	[ $udp4 -eq 2 ] || {
    696 		echo_i "ns4 $udp4 expected 2"
    697 		ret=1
    698 	}
    699 	if [ $ret != 0 ]; then echo_i "failed"; fi
    700 	status=`expr $status + $ret`
    701 
    702 	echo_i "checking TCP message counts"
    703 	ret=0
    704 	[ $tcp4 -eq 0 ] || {
    705 		echo_i "ns4 $tcp4 expected 0"
    706 		ret=1
    707 	}
    708 	if [ $ret != 0 ]; then echo_i "failed"; fi
    709 	status=`expr $status + $ret`
    710 
    711 	echo_i "checking AUTH_QUERY message counts"
    712 	ret=0
    713 	[ $aq4 -eq 0 ] || {
    714 		echo_i "ns4 $aq4 expected 0"
    715 		ret=1
    716 	}
    717 	if [ $ret != 0 ]; then echo_i "failed"; fi
    718 	status=`expr $status + $ret`
    719 
    720 	echo_i "checking AUTH_RESPONSE message counts"
    721 	ret=0
    722 	[ $ar4 -eq 0 ] || {
    723 		echo_i "ns4 $ar4 expected 0"
    724 		ret=1
    725 	}
    726 	if [ $ret != 0 ]; then echo_i "failed"; fi
    727 	status=`expr $status + $ret`
    728 
    729 	echo_i "checking CLIENT_QUERY message counts"
    730 	ret=0
    731 	[ $cq4 -eq 1 ] || {
    732 		echo_i "ns4 $cq4 expected 1"
    733 		ret=1
    734 	}
    735 	if [ $ret != 0 ]; then echo_i "failed"; fi
    736 	status=`expr $status + $ret`
    737 
    738 	echo_i "checking CLIENT_RESPONSE message counts"
    739 	ret=0
    740 	[ $cr4 -eq 1 ] || {
    741 		echo_i "ns4 $cr4 expected 1"
    742 		ret=1
    743 	}
    744 	if [ $ret != 0 ]; then echo_i "failed"; fi
    745 	status=`expr $status + $ret`
    746 
    747 	echo_i "checking RESOLVER_QUERY message counts"
    748 	ret=0
    749 	[ $rq4 -eq 0 ] || {
    750 		echo_i "ns4 $rq4 expected 0"
    751 		ret=1
    752 	}
    753 	if [ $ret != 0 ]; then echo_i "failed"; fi
    754 	status=`expr $status + $ret`
    755 
    756 	echo_i "checking RESOLVER_RESPONSE message counts"
    757 	ret=0
    758 	[ $rr4 -eq 0 ] || {
    759 		echo_i "ns4 $rr4 expected 0"
    760 		ret=1
    761 	}
    762 
    763 	echo_i "checking UPDATE_QUERY message counts"
    764 	ret=0
    765 	[ $uq4 -eq 0 ] || {
    766 		echo_i "ns4 $uq4 expected 0"
    767 		ret=1
    768 	}
    769 	if [ $ret != 0 ]; then echo_i "failed"; fi
    770 	status=`expr $status + $ret`
    771 
    772 	echo_i "checking UPDATE_RESPONSE message counts"
    773 	ret=0
    774 	[ $ur4 -eq 0 ] || {
    775 		echo_i "ns4 $ur4 expected 0"
    776 		ret=1
    777 	}
    778 	if [ $ret != 0 ]; then echo_i "failed"; fi
    779 	status=`expr $status + $ret`
    780 fi
    781 
    782 echo_i "checking large packet printing"
    783 ret=0
    784 # Expect one occurrence of "opcode: QUERY" below "reponse_message_data" and
    785 # another one below "response_message".
    786 lines=`$DNSTAPREAD -y large-answer.fstrm | grep -c "opcode: QUERY"`
    787 [ $lines -eq 2 ] || ret=1
    788 if [ $ret != 0 ]; then echo_i "failed"; fi
    789 status=`expr $status + $ret`
    790 
    791 test_dnstap_roll() (
    792     ip="$1"
    793     ns="$2"
    794     n="$3"
    795     $RNDCCMD -s "${ip}" dnstap -roll "${n}" | sed "s/^/${ns} /" | cat_i &&
    796     files=$(find "$ns" -name "dnstap.out.[0-9]" | wc -l) &&
    797     test "$files" -le "${n}" && test "$files" -ge "1"
    798 )
    799 
    800 echo_i "checking 'rndc -roll <value>' (no versions)"
    801 ret=0
    802 start_server --noclean --restart --port "${PORT}" ns3
    803 _repeat 5 test_dnstap_roll 10.53.0.3 ns3 3 || ret=1
    804 if [ $ret != 0 ]; then echo_i "failed"; fi
    805 status=$((status+ret))
    806 
    807 echo_i "checking 'rndc -roll <value>' (versions)"
    808 ret=0
    809 start_server --noclean --restart --port "${PORT}" ns2
    810 _repeat 5 test_dnstap_roll 10.53.0.2 ns2 3 || ret=1
    811 if [ $ret != 0 ]; then echo_i "failed"; fi
    812 status=$((status+ret))
    813 
    814 echo_i "exit status: $status"
    815 [ "$status" -eq 0 ] || exit 1
    816