tests.sh 8.76 KB
Newer Older
1 2
#!/bin/sh
#
3
# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
4
#
5 6 7
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 9 10
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
11

12
. ../conf.sh
13 14

status=0
15
n=0
16

Evan Hunt's avatar
Evan Hunt committed
17
RNDCOPTS="-c ../common/rndc.conf -s 10.53.0.2 -p ${CONTROLPORT}"
18
DIGOPTS="+nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm \
Evan Hunt's avatar
Evan Hunt committed
19
         +nostat @10.53.0.2 -p ${PORT}"
20 21 22 23 24 25 26

# fill the cache with nodes from flushtest.example zone
load_cache () {
        # empty all existing cache data
        $RNDC $RNDCOPTS flush

	# load the positive cache entries
27
	$DIG $DIGOPTS -f - << EOF > /dev/null 2>&1
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
txt top1.flushtest.example
txt second1.top1.flushtest.example
txt third1.second1.top1.flushtest.example
txt third2.second1.top1.flushtest.example
txt second2.top1.flushtest.example
txt second3.top1.flushtest.example
txt second1.top2.flushtest.example
txt second2.top2.flushtest.example
txt second3.top2.flushtest.example
txt top3.flushtest.example
txt second1.top3.flushtest.example
txt third1.second1.top3.flushtest.example
txt third2.second1.top3.flushtest.example
txt third1.second2.top3.flushtest.example
txt third2.second2.top3.flushtest.example
txt second3.top3.flushtest.example
EOF
45 46 47 48 49 50 51 52 53

	# load the negative cache entries
        # nxrrset:
	$DIG $DIGOPTS a third1.second1.top1.flushtest.example > /dev/null
        # nxdomain:
	$DIG $DIGOPTS txt top4.flushtest.example > /dev/null
        # empty nonterminal:
	$DIG $DIGOPTS txt second2.top3.flushtest.example > /dev/null

54 55
	# sleep 2 seconds ensure the TTLs will be lower on cached data
	sleep 2
56 57 58
}

dump_cache () {
59
        rndc_dumpdb ns2 -cache _default
60 61 62 63 64 65 66 67 68 69
}

clear_cache () {
        $RNDC $RNDCOPTS flush
}

in_cache () {
        ttl=`$DIG $DIGOPTS "$@" | awk '{print $2}'`
        [ -z "$ttl" ] && {
                ttl=`$DIG $DIGOPTS +noanswer +auth "$@" | awk '{print $2}'`
70
                [ "$ttl" -ge 3599 ] && return 1
71 72
                return 0
        }
73
        [ "$ttl" -ge 3599 ] && return 1
74 75 76
        return 0
}

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
# Extract records at and below name "$1" from the cache dump in file "$2".
filter_tree () {
	tree="$1"
	file="$2"
	perl -n -e '
		next if /^;/;
		if (/'"$tree"'/ || (/^\t/ && $print)) {
			$print = 1;
		} else {
			$print = 0;
		}
		print if $print;
	' "$file"
}

92
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
93
echo_i "check correctness of routine cache cleaning ($n)"
94
$DIG $DIGOPTS +tcp +keepopen -b 10.53.0.7 -f dig.batch > dig.out.ns2 || status=1
95

Evan Hunt's avatar
Evan Hunt committed
96
digcomp --lc dig.out.ns2 knowngood.dig.out || status=1
97

98
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
99
echo_i "only one tcp socket was used ($n)"
100
tcpclients=`awk '$3 == "client" && $5 ~ /10.53.0.7#[0-9]*:/ {print $5}' ns2/named.run | sort | uniq -c | wc -l`
101

Evan Hunt's avatar
Evan Hunt committed
102
test $tcpclients -eq 1 || { status=1; echo_i "failed"; }
103

104
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
105
echo_i "reset and check that records are correctly cached initially ($n)"
106 107 108
ret=0
load_cache
dump_cache
109
nrecords=`filter_tree flushtest.example ns2/named_dump.db.test$n | egrep '(TXT|ANY)' | wc -l`
110
[ $nrecords -eq 18 ] || { ret=1; echo_i "found $nrecords records expected 18"; }
Evan Hunt's avatar
Evan Hunt committed
111
if [ $ret != 0 ]; then echo_i "failed"; fi
112 113
status=`expr $status + $ret`

114
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
115
echo_i "check flushing of the full cache ($n)"
116 117 118
ret=0
clear_cache
dump_cache
119
nrecords=`filter_tree flushtest.example ns2/named_dump.db.test$n | wc -l`
120
[ $nrecords -eq 0 ] || ret=1
Evan Hunt's avatar
Evan Hunt committed
121
if [ $ret != 0 ]; then echo_i "failed"; fi
122 123
status=`expr $status + $ret`

124
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
125
echo_i "check flushing of individual nodes (interior node) ($n)"
126 127 128 129 130 131 132
ret=0
clear_cache
load_cache
# interior node
in_cache txt top1.flushtest.example || ret=1
$RNDC $RNDCOPTS flushname top1.flushtest.example
in_cache txt top1.flushtest.example && ret=1
Evan Hunt's avatar
Evan Hunt committed
133
if [ $ret != 0 ]; then echo_i "failed"; fi
134
status=`expr $status + $ret`
135

136
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
137
echo_i "check flushing of individual nodes (leaf node, under the interior node) ($n)"
138
ret=0
139 140 141 142
# leaf node, under the interior node (should still exist)
in_cache txt third2.second1.top1.flushtest.example || ret=1
$RNDC $RNDCOPTS flushname third2.second1.top1.flushtest.example
in_cache txt third2.second1.top1.flushtest.example && ret=1
Evan Hunt's avatar
Evan Hunt committed
143
if [ $ret != 0 ]; then echo_i "failed"; fi
144
status=`expr $status + $ret`
145

146
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
147
echo_i "check flushing of individual nodes (another leaf node, with both positive and negative cache entries) ($n)"
148
ret=0
149 150 151 152 153 154
# another leaf node, with both positive and negative cache entries
in_cache a third1.second1.top1.flushtest.example || ret=1
in_cache txt third1.second1.top1.flushtest.example || ret=1
$RNDC $RNDCOPTS flushname third1.second1.top1.flushtest.example
in_cache a third1.second1.top1.flushtest.example && ret=1
in_cache txt third1.second1.top1.flushtest.example && ret=1
Evan Hunt's avatar
Evan Hunt committed
155
if [ $ret != 0 ]; then echo_i "failed"; fi
156 157
status=`expr $status + $ret`

158
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
159
echo_i "check flushing a nonexistent name ($n)"
160 161
ret=0
$RNDC $RNDCOPTS flushname fake.flushtest.example || ret=1
Evan Hunt's avatar
Evan Hunt committed
162
if [ $ret != 0 ]; then echo_i "failed"; fi
163 164
status=`expr $status + $ret`

165
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
166
echo_i "check flushing of namespaces ($n)"
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
ret=0
clear_cache
load_cache
# flushing leaf node should leave the interior node:
in_cache txt third1.second1.top1.flushtest.example || ret=1
in_cache txt top1.flushtest.example || ret=1
$RNDC $RNDCOPTS flushtree third1.second1.top1.flushtest.example
in_cache txt third1.second1.top1.flushtest.example && ret=1
in_cache txt top1.flushtest.example || ret=1
in_cache txt second1.top1.flushtest.example || ret=1
in_cache txt third2.second1.top1.flushtest.example || ret=1
$RNDC $RNDCOPTS flushtree second1.top1.flushtest.example
in_cache txt top1.flushtest.example || ret=1
in_cache txt second1.top1.flushtest.example && ret=1
in_cache txt third2.second1.top1.flushtest.example && ret=1

# flushing from an empty node should still remove all its children
in_cache txt second1.top2.flushtest.example || ret=1
$RNDC $RNDCOPTS flushtree top2.flushtest.example
in_cache txt second1.top2.flushtest.example && ret=1
in_cache txt second2.top2.flushtest.example && ret=1
in_cache txt second3.top2.flushtest.example && ret=1
Evan Hunt's avatar
Evan Hunt committed
189
if [ $ret != 0 ]; then echo_i "failed"; fi
190 191
status=`expr $status + $ret`

192
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
193
echo_i "check flushing a nonexistent namespace ($n)"
194 195
ret=0
$RNDC $RNDCOPTS flushtree fake.flushtest.example || ret=1
Evan Hunt's avatar
Evan Hunt committed
196
if [ $ret != 0 ]; then echo_i "failed"; fi
197 198
status=`expr $status + $ret`

199
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
200
echo_i "check the number of cached records remaining ($n)"
201 202
ret=0
dump_cache
203
nrecords=`filter_tree flushtest.example ns2/named_dump.db.test$n | grep -v '^;' | egrep '(TXT|ANY)' | wc -l`
Evan Hunt's avatar
Evan Hunt committed
204 205
[ $nrecords -eq 17 ] || { ret=1; echo_i "found $nrecords records expected 17"; }
if [ $ret != 0 ]; then echo_i "failed"; fi
206 207
status=`expr $status + $ret`

208
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
209
echo_i "check the check that flushname of a partial match works ($n)"
210 211 212 213
ret=0
in_cache txt second2.top1.flushtest.example || ret=1
$RNDC $RNDCOPTS flushtree example
in_cache txt second2.top1.flushtest.example && ret=1
Evan Hunt's avatar
Evan Hunt committed
214
if [ $ret != 0 ]; then echo_i "failed"; fi
215 216
status=`expr $status + $ret`

217
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
218
echo_i "check the number of cached records remaining ($n)"
219 220
ret=0
dump_cache
221
nrecords=`filter_tree flushtest.example ns2/named_dump.db.test$n | egrep '(TXT|ANY)' | wc -l`
Evan Hunt's avatar
Evan Hunt committed
222 223
[ $nrecords -eq 1 ] || { ret=1; echo_i "found $nrecords records expected 1"; }
if [ $ret != 0 ]; then echo_i "failed"; fi
224 225
status=`expr $status + $ret`

226
n=`expr $n + 1`
Evan Hunt's avatar
Evan Hunt committed
227
echo_i "check flushtree clears adb correctly ($n)"
228 229 230
ret=0
load_cache
dump_cache
231
mv ns2/named_dump.db.test$n ns2/named_dump.db.test$n.a
232
sed -n '/plain success\/timeout/,/Unassociated entries/p' \
233
	ns2/named_dump.db.test$n.a > sed.out.$n.a
234 235 236
grep 'plain success/timeout' sed.out.$n.a > /dev/null 2>&1 || ret=1
grep 'Unassociated entries' sed.out.$n.a > /dev/null 2>&1 || ret=1
grep 'ns.flushtest.example' sed.out.$n.a > /dev/null 2>&1 || ret=1
237
$RNDC $RNDCOPTS flushtree flushtest.example || ret=1
238
dump_cache
239
mv ns2/named_dump.db.test$n ns2/named_dump.db.test$n.b
240
sed -n '/plain success\/timeout/,/Unassociated entries/p' \
241
	ns2/named_dump.db.test$n.b > sed.out.$n.b
242 243 244
grep 'plain success/timeout' sed.out.$n.b > /dev/null 2>&1 || ret=1
grep 'Unassociated entries' sed.out.$n.b > /dev/null 2>&1 || ret=1
grep 'ns.flushtest.example' sed.out.$n.b > /dev/null 2>&1 && ret=1
Evan Hunt's avatar
Evan Hunt committed
245
if [ $ret != 0 ]; then echo_i "failed"; fi
246 247
status=`expr $status + $ret`

248
n=`expr $n + 1`
249
echo_i "check expire option returned from primary zone ($n)"
250
ret=0
Evan Hunt's avatar
Evan Hunt committed
251
$DIG @10.53.0.1 -p ${PORT} +expire soa expire-test > dig.out.expire
252
grep EXPIRE: dig.out.expire > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
253
if [ $ret != 0 ]; then echo_i "failed"; fi
254 255
status=`expr $status + $ret`

256
n=`expr $n + 1`
257
echo_i "check expire option returned from secondary zone ($n)"
258
ret=0
Evan Hunt's avatar
Evan Hunt committed
259
$DIG @10.53.0.2 -p ${PORT} +expire soa expire-test > dig.out.expire
260
grep EXPIRE: dig.out.expire > /dev/null || ret=1
Evan Hunt's avatar
Evan Hunt committed
261
if [ $ret != 0 ]; then echo_i "failed"; fi
262 263
status=`expr $status + $ret`

Evan Hunt's avatar
Evan Hunt committed
264
echo_i "exit status: $status"
265
[ $status -eq 0 ] || exit 1