tests.sh revision 1.1.1.6
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# shellcheck source=conf.sh 15SYSTEMTESTTOP=.. 16. "$SYSTEMTESTTOP/conf.sh" 17 18status=0 19n=1 20 21ismap () { 22 # shellcheck disable=SC2016 23 $PERL -e 'binmode STDIN; 24 read(STDIN, $input, 8); 25 ($style, $version) = unpack("NN", $input); 26 exit 1 if ($style != 3 || $version > 1);' < "$1" 27 return $? 28} 29 30israw () { 31 # shellcheck disable=SC2016 32 $PERL -e 'binmode STDIN; 33 read(STDIN, $input, 8); 34 ($style, $version) = unpack("NN", $input); 35 exit 1 if ($style != 2 || $version > 1);' < "$1" 36 return $? 37} 38 39isfull () { 40 # there should be no whitespace at the beginning of a line 41 if grep '^[ ][ ]*' "$1" > /dev/null 2>&1; then 42 return 1 43 else 44 return 0 45 fi 46} 47 48rawversion () { 49 # shellcheck disable=SC2016 50 $PERL -e 'binmode STDIN; 51 read(STDIN, $input, 8); 52 if (length($input) < 8) { print "not raw\n"; exit 0; }; 53 ($style, $version) = unpack("NN", $input); 54 print ($style == 2 || $style == 3 ? "$version\n" : 55 "not raw or map\n");' < "$1" 56} 57 58sourceserial () { 59 # shellcheck disable=SC2016 60 $PERL -e 'binmode STDIN; 61 read(STDIN, $input, 20); 62 if (length($input) < 20) { print "UNSET\n"; exit; }; 63 ($format, $version, $dumptime, $flags, $sourceserial) = 64 unpack("NNNNN", $input); 65 if ($format != 2 || $version < 1) { print "UNSET\n"; exit; }; 66 if ($flags & 02) { 67 print $sourceserial . "\n"; 68 } else { 69 print "UNSET\n"; 70 }' < "$1" 71} 72 73stomp () { 74 # shellcheck disable=SC2016 75 $PERL -e 'open(my $file, "+<", $ARGV[0]); 76 binmode $file; 77 seek($file, $ARGV[1], 0); 78 for (my $i = 0; $i < $ARGV[2]; $i++) { 79 print $file pack("C", $ARGV[3]); 80 } 81 close($file);' "$@" 82} 83 84restart () { 85 sleep 1 86 $PERL "$SYSTEMTESTTOP/start.pl" --noclean --restart --port "${PORT}" masterformat ns3 87} 88 89dig_with_opts() { 90 "$DIG" +tcp +noauth +noadd +nosea +nostat +noquest +nocomm +nocmd -p "${PORT}" "$@" 91} 92 93rndccmd() { 94 "$RNDC" -c "$SYSTEMTESTTOP/common/rndc.conf" -p "${CONTROLPORT}" -s "$@" 95} 96 97status=0 98 99echo_i "checking that files in raw format loaded ($n)" 100ret=0 101set -- 1 2 3 102for zone in example example-explicit example-compat; do 103 for server in "$@"; do 104 for qname in ns mx a aaaa cname dname txt rrsig nsec \ 105 dnskey ds cdnskey cds; do 106 qtype="$qname" 107 dig_with_opts @10.53.0.${server} -q ${qname}.${zone}. -t ${qtype} 108 echo 109 done > dig.out.${zone}.${server}.test${n} 110 for qname in private-dnskey private-cdnskey; do 111 qtype=$(expr "$qname" : '.*-\(.*\)') 112 dig_with_opts @10.53.0.${server} -q ${qname}.${zone}. -t ${qtype} 113 done >> dig.out.${zone}.${server}.test${n} 114 done 115 digcomp dig.out.${zone}.1.test${n} dig.out.${zone}.2.test${n} || ret=1 116 if [ "$zone" = "example" ]; then 117 set -- 1 2 118 digcomp dig.out.${zone}.1.test${n} dig.out.${zone}.3.test${n} || ret=1 119 fi 120done 121n=$((n+1)) 122[ $ret -eq 0 ] || echo_i "failed" 123status=$((status+ret)) 124 125echo_i "checking raw format versions ($n)" 126ret=0 127israw ns1/example.db.raw || ret=1 128israw ns1/example.db.raw1 || ret=1 129israw ns1/example.db.compat || ret=1 130ismap ns1/example.db.map || ret=1 131[ "$(rawversion ns1/example.db.raw)" -eq 1 ] || ret=1 132[ "$(rawversion ns1/example.db.raw1)" -eq 1 ] || ret=1 133[ "$(rawversion ns1/example.db.compat)" -eq 0 ] || ret=1 134[ "$(rawversion ns1/example.db.map)" -eq 1 ] || ret=1 135n=$((n+1)) 136[ $ret -eq 0 ] || echo_i "failed" 137status=$((status+ret)) 138 139echo_i "checking source serial numbers ($n)" 140ret=0 141[ "$(sourceserial ns1/example.db.raw)" = "UNSET" ] || ret=1 142[ "$(sourceserial ns1/example.db.serial.raw)" = "3333" ] || ret=1 143n=$((n+1)) 144[ $ret -eq 0 ] || echo_i "failed" 145status=$((status+ret)) 146 147echo_i "waiting for transfers to complete" 148for i in 0 1 2 3 4 5 6 7 8 9 149do 150 test -f ns2/transfer.db.raw -a -f ns2/transfer.db.txt && break 151 sleep 1 152done 153 154echo_i "checking that secondary was saved in raw format by default ($n)" 155ret=0 156israw ns2/transfer.db.raw || ret=1 157n=$((n+1)) 158[ $ret -eq 0 ] || echo_i "failed" 159status=$((status+ret)) 160 161echo_i "checking that secondary was saved in text format when configured ($n)" 162ret=0 163israw ns2/transfer.db.txt && ret=1 164isfull ns2/transfer.db.txt && ret=1 165n=$((n+1)) 166[ $ret -eq 0 ] || echo_i "failed" 167status=$((status+ret)) 168 169echo_i "checking that secondary was saved in 'full' style when configured ($n)" 170ret=0 171isfull ns2/transfer.db.full > /dev/null 2>&1 || ret=1 172n=$((n+1)) 173[ $ret -eq 0 ] || echo_i "failed" 174status=$((status+ret)) 175 176echo_i "checking that secondary formerly in text format is now raw ($n)" 177for i in 0 1 2 3 4 5 6 7 8 9 178do 179 ret=0 180 israw ns2/formerly-text.db > /dev/null 2>&1 || ret=1 181 [ "$(rawversion ns2/formerly-text.db)" -eq 1 ] || ret=1 182 [ $ret -eq 0 ] && break 183 sleep 1 184done 185n=$((n+1)) 186[ $ret -eq 0 ] || echo_i "failed" 187status=$((status+ret)) 188 189echo_i "checking that large rdatasets loaded ($n)" 190for i in 0 1 2 3 4 5 6 7 8 9 191do 192ret=0 193for a in a b c 194do 195 $DIG +tcp txt "${a}.large" @10.53.0.2 -p "${PORT}" > "dig.out.ns2.test$n" 196 grep "status: NOERROR" "dig.out.ns2.test$n" > /dev/null || ret=1 197done 198[ $ret -eq 0 ] && break 199sleep 1 200done 201n=$((n+1)) 202[ $ret -eq 0 ] || echo_i "failed" 203status=$((status+ret)) 204 205echo_i "checking format transitions: text->raw->map->text ($n)" 206ret=0 207$CHECKZONE -D -f text -F text -o baseline.txt example.nil ns1/example.db > /dev/null 208$CHECKZONE -D -f text -F raw -o raw.1 example.nil baseline.txt > /dev/null 209$CHECKZONE -D -f raw -F map -o map.1 example.nil raw.1 > /dev/null 210$CHECKZONE -D -f map -F text -o text.1 example.nil map.1 > /dev/null 211cmp -s baseline.txt text.1 || ret=0 212n=$((n+1)) 213[ $ret -eq 0 ] || echo_i "failed" 214status=$((status+ret)) 215 216echo_i "checking format transitions: text->map->raw->text ($n)" 217ret=0 218$CHECKZONE -D -f text -F map -o map.2 example.nil baseline.txt > /dev/null 219$CHECKZONE -D -f map -F raw -o raw.2 example.nil map.2 > /dev/null 220$CHECKZONE -D -f raw -F text -o text.2 example.nil raw.2 > /dev/null 221cmp -s baseline.txt text.2 || ret=0 222n=$((n+1)) 223[ $ret -eq 0 ] || echo_i "failed" 224status=$((status+ret)) 225 226echo_i "checking map format loading with journal file rollforward ($n)" 227ret=0 228$NSUPDATE <<END > /dev/null || status=1 229server 10.53.0.3 ${PORT} 230ttl 600 231update add newtext.dynamic IN TXT "added text" 232update delete aaaa.dynamic 233send 234END 235dig_with_opts @10.53.0.3 newtext.dynamic txt > "dig.out.dynamic1.ns3.test$n" 236grep "added text" "dig.out.dynamic1.ns3.test$n" > /dev/null 2>&1 || ret=1 237dig_with_opts +comm @10.53.0.3 added.dynamic txt > "dig.out.dynamic2.ns3.test$n" 238grep "NXDOMAIN" "dig.out.dynamic2.ns3.test$n" > /dev/null 2>&1 || ret=1 239# using "rndc halt" ensures that we don't dump the zone file 240$PERL $SYSTEMTESTTOP/stop.pl --use-rndc --halt --port ${CONTROLPORT} masterformat ns3 241restart 242check_added_text() { 243 dig_with_opts @10.53.0.3 newtext.dynamic txt > "dig.out.dynamic3.ns3.test$n" || return 1 244 grep "added text" "dig.out.dynamic3.ns3.test$n" > /dev/null || return 1 245 return 0 246} 247retry_quiet 10 check_added_text || ret=1 248dig_with_opts +comm @10.53.0.3 added.dynamic txt > "dig.out.dynamic4.ns3.test$n" 249grep "NXDOMAIN" "dig.out.dynamic4.ns3.test$n" > /dev/null 2>&1 || ret=1 250n=$((n+1)) 251[ $ret -eq 0 ] || echo_i "failed" 252status=$((status+ret)) 253 254echo_i "checking map format file dumps correctly ($n)" 255ret=0 256$NSUPDATE <<END > /dev/null || status=1 257server 10.53.0.3 ${PORT} 258ttl 600 259update add moretext.dynamic IN TXT "more text" 260send 261END 262dig_with_opts @10.53.0.3 moretext.dynamic txt > "dig.out.dynamic1.ns3.test$n" 263grep "more text" "dig.out.dynamic1.ns3.test$n" > /dev/null 2>&1 || ret=1 264# using "rndc stop" will cause the zone file to flush before shutdown 265$PERL $SYSTEMTESTTOP/stop.pl --use-rndc --port ${CONTROLPORT} masterformat ns3 266rm ns3/*.jnl 267restart 268#shellcheck disable=SC2034 269for i in 0 1 2 3 4 5 6 7 8 9; do 270 lret=0 271 dig_with_opts +comm @10.53.0.3 moretext.dynamic txt > "dig.out.dynamic2.ns3.test$n" 272 grep "more text" "dig.out.dynamic2.ns3.test$n" > /dev/null 2>&1 || lret=1 273 [ $lret -eq 0 ] && break; 274done 275[ $lret -eq 1 ] && ret=1 276n=$((n+1)) 277[ $ret -eq 0 ] || echo_i "failed" 278status=$((status+ret)) 279 280# stomp on the file header 281echo_i "checking corrupt map files fail to load (bad file header) ($n)" 282ret=0 283$CHECKZONE -D -f text -F map -o map.5 example.nil baseline.txt > /dev/null 284cp map.5 badmap 285stomp badmap 0 32 99 286$CHECKZONE -D -f map -F text -o text.5 example.nil badmap > /dev/null 287[ $? = 1 ] || ret=1 288n=$((n+1)) 289[ $ret -eq 0 ] || echo_i "failed" 290status=$((status+ret)) 291 292# stomp on the file data so it hashes differently. 293# these are small and subtle changes, so that the resulting file 294# would appear to be a legitimate map file and would not trigger an 295# assertion failure if loaded into memory, but should still fail to 296# load because of a SHA1 hash mismatch. 297echo_i "checking corrupt map files fail to load (bad node header) ($n)" 298ret=0 299cp map.5 badmap 300stomp badmap 2754 2 99 301$CHECKZONE -D -f map -F text -o text.5 example.nil badmap > /dev/null 302[ $? = 1 ] || ret=1 303n=$((n+1)) 304[ $ret -eq 0 ] || echo_i "failed" 305status=$((status+ret)) 306 307echo_i "checking corrupt map files fail to load (bad node data) ($n)" 308ret=0 309cp map.5 badmap 310stomp badmap 2897 5 127 311$CHECKZONE -D -f map -F text -o text.5 example.nil badmap > /dev/null 312[ $? = 1 ] || ret=1 313n=$((n+1)) 314[ $ret -eq 0 ] || echo_i "failed" 315status=$((status+ret)) 316 317echo_i "checking map format zone is scheduled for resigning (compilezone) ($n)" 318ret=0 319rndccmd 10.53.0.1 zonestatus signed > rndc.out 2>&1 || ret=1 320grep 'next resign' rndc.out > /dev/null 2>&1 || ret=1 321n=$((n+1)) 322[ $ret -eq 0 ] || echo_i "failed" 323status=$((status+ret)) 324 325echo_i "checking map format zone is scheduled for resigning (signzone) ($n)" 326ret=0 327rndccmd 10.53.0.1 freeze signed > rndc.out 2>&1 || ret=1 328(cd ns1 || exit 1; $SIGNER -S -O map -f signed.db.map -o signed signed.db > /dev/null) 329rndc_reload ns1 10.53.0.1 signed 330rndccmd 10.53.0.1 zonestatus signed > rndc.out 2>&1 || ret=1 331grep 'next resign' rndc.out > /dev/null 2>&1 || ret=1 332n=$((n+1)) 333[ $ret -eq 0 ] || echo_i "failed" 334status=$((status+ret)) 335 336# The following test is disabled by default because it is very slow. 337# It fails on Windows, because a single read() call (specifically 338# the one in isc_file_mmap()) cannot process more than INT_MAX (2^31) 339# bytes of data. 340if [ -n "${TEST_LARGE_MAP}" ]; then 341 echo_i "checking map file size > 2GB can be loaded ($n)" 342 ret=0 343 $PERL ../../startperf/mkzonefile.pl test 9000000 > text.$n 344 # convert to map 345 $CHECKZONE -D -f text -F map -o map.$n test text.$n > /dev/null || ret=1 346 # check map file size is over 2GB to ensure the test is valid 347 size=$(ls -l map.$n | awk '{print $5}') 348 [ "$size" -gt 2147483648 ] || ret=1 349 # convert back to text 350 $CHECKZONE -f map test map.$n > /dev/null || ret=1 351 n=$((n+1)) 352 [ $ret -eq 0 ] || echo_i "failed" 353 status=$((status+ret)) 354fi 355 356echo_i "exit status: $status" 357[ $status -eq 0 ] || exit 1 358