1#!/bin/sh
2#
3# Copyright (C) 2006-2008, 2011, 2012  Internet Systems Consortium, Inc. ("ISC")
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15# PERFORMANCE OF THIS SOFTWARE.
16
17# Id: tests.sh,v 1.13 2012/01/04 23:46:49 tbox Exp 
18
19SYSTEMTESTTOP=..
20. $SYSTEMTESTTOP/conf.sh
21
22status=0
23
24if grep "^#define DNS_RDATASET_FIXED" $TOP/config.h > /dev/null 2>&1 ; then
25        test_fixed=true
26else
27        echo "I: Order 'fixed' disabled at compile time"
28        test_fixed=false
29fi
30
31#
32#
33#
34if $test_fixed; then
35    echo "I: Checking order fixed (master)"
36    ret=0
37    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
38    do
39    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
40	    -p 5300 @10.53.0.1 fixed.example > dig.out.fixed || ret=1
41    cmp -s dig.out.fixed dig.out.fixed.good || ret=1
42    done
43    if [ $ret != 0 ]; then echo "I:failed"; fi
44    status=`expr $status + $ret`
45fi
46
47#
48#
49#
50echo "I: Checking order cyclic (master + additional)"
51ret=0
52matches=0
53for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
54do
55    j=`expr $i % 4`
56    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
57	    -p 5300 @10.53.0.1 cyclic.example > dig.out.cyclic || ret=1
58    if [ $i -le 4 ]; then
59        cp dig.out.cyclic dig.out.$j
60    else
61        cmp -s dig.out.cyclic dig.out.$j && matches=`expr $matches + 1`
62    fi
63done
64cmp -s dig.out.0 dig.out.1 && ret=1
65cmp -s dig.out.0 dig.out.2 && ret=1
66cmp -s dig.out.0 dig.out.3 && ret=1
67cmp -s dig.out.1 dig.out.2 && ret=1
68cmp -s dig.out.1 dig.out.3 && ret=1
69cmp -s dig.out.2 dig.out.3 && ret=1
70if [ $matches -ne 16 ]; then ret=1; fi
71if [ $ret != 0 ]; then echo "I:failed"; fi
72status=`expr $status + $ret`
73
74#
75#
76#
77echo "I: Checking order cyclic (master)"
78ret=0
79matches=0
80for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
81do
82    j=`expr $i % 4`
83    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
84	    -p 5300 @10.53.0.1 cyclic2.example > dig.out.cyclic2 || ret=1
85    if [ $i -le 4 ]; then
86        cp dig.out.cyclic2 dig.out.$j
87    else
88        cmp -s dig.out.cyclic2 dig.out.$j && matches=`expr $matches + 1`
89    fi
90done
91cmp -s dig.out.0 dig.out.1 && ret=1
92cmp -s dig.out.0 dig.out.2 && ret=1
93cmp -s dig.out.0 dig.out.3 && ret=1
94cmp -s dig.out.1 dig.out.2 && ret=1
95cmp -s dig.out.1 dig.out.3 && ret=1
96cmp -s dig.out.2 dig.out.3 && ret=1
97if [ $matches -ne 16 ]; then ret=1; fi
98if [ $ret != 0 ]; then echo "I:failed"; fi
99status=`expr $status + $ret`
100echo "I: Checking order random (master)"
101ret=0
102for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
103do
104	eval match$i=0
105done
106for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9
107do
108$DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
109	-p 5300 @10.53.0.1 random.example > dig.out.random || ret=1
110	match=0
111	for j in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
112	do
113		eval "cmp -s dig.out.random dig.out.random.good$j && match$j=1 match=1"
114		if [ $match -eq 1 ]; then break; fi
115	done
116	if [ $match -eq 0 ]; then ret=1; fi
117done
118match=0
119for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
120do
121	eval "match=\`expr \$match + \$match$i\`"
122done
123echo "I: Random selection return $match of 24 possible orders in 36 samples"
124if [ $match -lt 8 ]; then echo ret=1; fi
125if [ $ret != 0 ]; then echo "I:failed"; fi
126status=`expr $status + $ret`
127
128#
129#
130#
131if $test_fixed; then
132    echo "I: Checking order fixed (slave)"
133    ret=0
134    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
135    do
136    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
137	    -p 5300 @10.53.0.2 fixed.example > dig.out.fixed || ret=1
138    cmp -s dig.out.fixed dig.out.fixed.good || ret=1
139    done
140    if [ $ret != 0 ]; then echo "I:failed"; fi
141    status=`expr $status + $ret`
142fi
143
144#
145#
146#
147echo "I: Checking order cyclic (slave + additional)"
148ret=0
149matches=0
150for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
151do
152    j=`expr $i % 4`
153    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
154	    -p 5300 @10.53.0.2 cyclic.example > dig.out.cyclic || ret=1
155    if [ $i -le 4 ]; then
156        cp dig.out.cyclic dig.out.$j
157    else
158        cmp -s dig.out.cyclic dig.out.$j && matches=`expr $matches + 1`
159    fi
160done
161cmp -s dig.out.0 dig.out.1 && ret=1
162cmp -s dig.out.0 dig.out.2 && ret=1
163cmp -s dig.out.0 dig.out.3 && ret=1
164cmp -s dig.out.1 dig.out.2 && ret=1
165cmp -s dig.out.1 dig.out.3 && ret=1
166cmp -s dig.out.2 dig.out.3 && ret=1
167if [ $matches -ne 16 ]; then ret=1; fi
168if [ $ret != 0 ]; then echo "I:failed"; fi
169status=`expr $status + $ret`
170
171#
172#
173#
174echo "I: Checking order cyclic (slave)"
175ret=0
176matches=0
177for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
178do
179    j=`expr $i % 4`
180    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
181	    -p 5300 @10.53.0.2 cyclic2.example > dig.out.cyclic2 || ret=1
182    if [ $i -le 4 ]; then
183        cp dig.out.cyclic2 dig.out.$j
184    else
185        cmp -s dig.out.cyclic2 dig.out.$j && matches=`expr $matches + 1`
186    fi
187done
188cmp -s dig.out.0 dig.out.1 && ret=1
189cmp -s dig.out.0 dig.out.2 && ret=1
190cmp -s dig.out.0 dig.out.3 && ret=1
191cmp -s dig.out.1 dig.out.2 && ret=1
192cmp -s dig.out.1 dig.out.3 && ret=1
193cmp -s dig.out.2 dig.out.3 && ret=1
194if [ $matches -ne 16 ]; then ret=1; fi
195if [ $ret != 0 ]; then echo "I:failed"; fi
196status=`expr $status + $ret`
197
198echo "I: Checking order random (slave)"
199ret=0
200for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
201do
202	eval match$i=0
203done
204for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9
205do
206$DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
207	-p 5300 @10.53.0.2 random.example > dig.out.random || ret=1
208	match=0
209	for j in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
210	do
211		eval "cmp -s dig.out.random dig.out.random.good$j && match$j=1 match=1"
212		if [ $match -eq 1 ]; then break; fi
213	done
214	if [ $match -eq 0 ]; then ret=1; fi
215done
216match=0
217for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
218do
219eval "match=\`expr \$match + \$match$i\`"
220done
221echo "I: Random selection return $match of 24 possible orders in 36 samples"
222if [ $match -lt 8 ]; then echo ret=1; fi
223if [ $ret != 0 ]; then echo "I:failed"; fi
224status=`expr $status + $ret`
225
226echo "I: Shutting down slave"
227
228(cd ..; sh stop.sh rrsetorder ns2 )
229
230echo "I: Checking for slave's on disk copy of zone"
231
232if [ ! -f ns2/root.bk ]
233then
234	echo "I:failed";
235	status=`expr $status + 1`
236fi
237
238echo "I: Re-starting slave"
239
240(cd ..; sh start.sh --noclean rrsetorder ns2 )
241
242#
243#
244#
245if $test_fixed; then
246    echo "I: Checking order fixed (slave loaded from disk)"
247    ret=0
248    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
249    do
250    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
251	    -p 5300 @10.53.0.2 fixed.example > dig.out.fixed || ret=1
252    cmp -s dig.out.fixed dig.out.fixed.good || ret=1
253    done
254    if [ $ret != 0 ]; then echo "I:failed"; fi
255    status=`expr $status + $ret`
256fi
257
258#
259#
260#
261echo "I: Checking order cyclic (slave + additional, loaded from disk)"
262ret=0
263matches=0
264for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
265do
266    j=`expr $i % 4`
267    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
268	    -p 5300 @10.53.0.2 cyclic.example > dig.out.cyclic || ret=1
269    if [ $i -le 4 ]; then
270        cp dig.out.cyclic dig.out.$j
271    else
272        cmp -s dig.out.cyclic dig.out.$j && matches=`expr $matches + 1`
273    fi
274done
275cmp -s dig.out.0 dig.out.1 && ret=1
276cmp -s dig.out.0 dig.out.2 && ret=1
277cmp -s dig.out.0 dig.out.3 && ret=1
278cmp -s dig.out.1 dig.out.2 && ret=1
279cmp -s dig.out.1 dig.out.3 && ret=1
280cmp -s dig.out.2 dig.out.3 && ret=1
281if [ $matches -ne 16 ]; then ret=1; fi
282if [ $ret != 0 ]; then echo "I:failed"; fi
283status=`expr $status + $ret`
284
285#
286#
287#
288echo "I: Checking order cyclic (slave loaded from disk)"
289ret=0
290matches=0
291for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
292do
293    j=`expr $i % 4`
294    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
295	    -p 5300 @10.53.0.2 cyclic2.example > dig.out.cyclic2 || ret=1
296    if [ $i -le 4 ]; then
297        cp dig.out.cyclic2 dig.out.$j
298    else
299        cmp -s dig.out.cyclic2 dig.out.$j && matches=`expr $matches + 1`
300    fi
301done
302cmp -s dig.out.0 dig.out.1 && ret=1
303cmp -s dig.out.0 dig.out.2 && ret=1
304cmp -s dig.out.0 dig.out.3 && ret=1
305cmp -s dig.out.1 dig.out.2 && ret=1
306cmp -s dig.out.1 dig.out.3 && ret=1
307cmp -s dig.out.2 dig.out.3 && ret=1
308if [ $matches -ne 16 ]; then ret=1; fi
309if [ $ret != 0 ]; then echo "I:failed"; fi
310status=`expr $status + $ret`
311
312echo "I: Checking order random (slave loaded from disk)"
313ret=0
314for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
315do
316	eval match$i=0
317done
318for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9
319do
320$DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
321	-p 5300 @10.53.0.2 random.example > dig.out.random || ret=1
322	match=0
323	for j in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
324	do
325		eval "cmp -s dig.out.random dig.out.random.good$j && match$j=1 match=1"
326		if [ $match -eq 1 ]; then break; fi
327	done
328	if [ $match -eq 0 ]; then ret=1; fi
329done
330match=0
331for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
332do
333eval "match=\`expr \$match + \$match$i\`"
334done
335echo "I: Random selection return $match of 24 possible orders in 36 samples"
336if [ $match -lt 8 ]; then echo ret=1; fi
337if [ $ret != 0 ]; then echo "I:failed"; fi
338status=`expr $status + $ret`
339
340#
341#
342#
343if $test_fixed; then
344    echo "I: Checking order fixed (cache)"
345    ret=0
346    for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
347    do
348    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
349	    -p 5300 @10.53.0.3 fixed.example > dig.out.fixed || ret=1
350    cmp -s dig.out.fixed dig.out.fixed.good || ret=1
351    done
352    if [ $ret != 0 ]; then echo "I:failed"; fi
353    status=`expr $status + $ret`
354fi
355
356#
357#
358#
359echo "I: Checking order cyclic (cache + additional)"
360ret=0
361# prime acache
362$DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
363	    -p 5300 @10.53.0.3 cyclic.example > dig.out.cyclic || ret=1
364matches=0
365for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
366do
367    j=`expr $i % 4`
368    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
369	    -p 5300 @10.53.0.3 cyclic.example > dig.out.cyclic || ret=1
370    if [ $i -le 4 ]; then
371        cp dig.out.cyclic dig.out.$j
372    else
373        cmp -s dig.out.cyclic dig.out.$j && matches=`expr $matches + 1`
374    fi
375done
376cmp -s dig.out.0 dig.out.1 && ret=1
377cmp -s dig.out.0 dig.out.2 && ret=1
378cmp -s dig.out.0 dig.out.3 && ret=1
379cmp -s dig.out.1 dig.out.2 && ret=1
380cmp -s dig.out.1 dig.out.3 && ret=1
381cmp -s dig.out.2 dig.out.3 && ret=1
382if [ $matches -ne 16 ]; then ret=1; fi
383if [ $ret != 0 ]; then echo "I:failed"; fi
384status=`expr $status + $ret`
385
386#
387#
388#
389echo "I: Checking order cyclic (cache)"
390ret=0
391# prime acache
392$DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
393	    -p 5300 @10.53.0.3 cyclic2.example > dig.out.cyclic2 || ret=1
394matches=0
395for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
396do
397    j=`expr $i % 4`
398    $DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
399	    -p 5300 @10.53.0.3 cyclic2.example > dig.out.cyclic2 || ret=1
400    if [ $i -le 4 ]; then
401        cp dig.out.cyclic2 dig.out.$j
402    else
403        cmp -s dig.out.cyclic2 dig.out.$j && matches=`expr $matches + 1`
404    fi
405done
406cmp -s dig.out.0 dig.out.1 && ret=1
407cmp -s dig.out.0 dig.out.2 && ret=1
408cmp -s dig.out.0 dig.out.3 && ret=1
409cmp -s dig.out.1 dig.out.2 && ret=1
410cmp -s dig.out.1 dig.out.3 && ret=1
411cmp -s dig.out.2 dig.out.3 && ret=1
412if [ $matches -ne 16 ]; then ret=1; fi
413if [ $ret != 0 ]; then echo "I:failed"; fi
414status=`expr $status + $ret`
415
416echo "I: Checking order random (cache)"
417ret=0
418for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
419do
420	eval match$i=0
421done
422for i in a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 9
423do
424$DIG +nosea +nocomm +nocmd +noquest +noadd +noauth +nocomm +nostat +short \
425	-p 5300 @10.53.0.3 random.example > dig.out.random || ret=1
426	match=0
427	for j in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
428	do
429		eval "cmp -s dig.out.random dig.out.random.good$j && match$j=1 match=1"
430		if [ $match -eq 1 ]; then break; fi
431	done
432	if [ $match -eq 0 ]; then ret=1; fi
433done
434match=0
435for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
436do
437eval "match=\`expr \$match + \$match$i\`"
438done
439echo "I: Random selection return $match of 24 possible orders in 36 samples"
440if [ $match -lt 8 ]; then echo ret=1; fi
441if [ $ret != 0 ]; then echo "I:failed"; fi
442
443status=`expr $status + $ret`
444echo "I:exit status: $status"
445exit $status
446