xref: /netbsd-src/external/bsd/unbound/dist/testdata/05-asynclook.tdir/05-asynclook.test (revision 06dfa8449cb5e76c0044ec0f3badf7d5180af0f5)
1# #-- 05-asynclook.test --#
2# source the master var file when it's there
3[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
4# use .tpkg.var.test for in test variable passing
5[ -f .tpkg.var.test ] && source .tpkg.var.test
6
7PRE="../.."
8. ../common.sh
9# test if fwder is up
10echo "> dig @127.0.0.1 -p $FWD_PORT www.example.com | tee outfile"
11dig @127.0.0.1 -p $FWD_PORT www.example.com | tee outfile
12if grep "10.20.30.40" outfile; then
13	echo "fwder is up"
14else
15	cat fwd.log
16	echo "fwder not up"
17	exit 1
18fi
19rm outfile
20
21# create asynclook
22get_make
23echo "> (cd $PRE ; $MAKE asynclook)"
24(cd $PRE ; $MAKE asynclook)
25if test ! -x $PRE/asynclook; then
26	echo "cannot build asynclook test program"
27	exit 1
28fi
29(cd $PRE ; $MAKE lock-verify)
30
31# check the locks.
32function locktest() {
33	if test -x $PRE/lock-verify -a -f ublocktrace.0; then
34		$PRE/lock-verify ublocktrace.*
35		if test $? -ne 0; then
36			echo "lock-verify error"
37			exit 1
38		fi
39	fi
40}
41
42# detect if there is forking on this system.
43HAVE_FORK=yes
44if grep "undef HAVE_FORK" $PRE/config.h >/dev/null 2>&1; then
45	HAVE_FORK=no
46fi
47
48if test $HAVE_FORK = yes; then
49# test hosts reading (directed at local auth info)
50echo '> $PRE/asynclook -H 05-asynclook.hosts virtual.virtual.virtual.local 2>&1 | tee outfile'
51$PRE/asynclook -H 05-asynclook.hosts virtual.virtual.virtual.local 2>&1 | tee outfile
52if grep "virtual.virtual.virtual.local: 10.20.30.40" outfile; then
53	echo "OK"
54else
55	echo "Not OK"
56	exit 1
57fi
58locktest
59rm outfile
60
61# test async lookups (directed at testns)
62echo '> $PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com 2>&1 | tee outfile'
63$PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com 2>&1 | tee outfile
64if grep "www.example.com: 10.20.30.40" outfile; then
65	echo "OK"
66else
67	cat fwd.log
68	echo "Not OK"
69	exit 1
70fi
71locktest
72rm outfile
73
74echo '> $PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
75$PRE/asynclook -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
76if grep "www.example.com: 10.20.30.40" outfile; then
77	echo "OK"
78else
79	cat fwd.log
80	echo "Not OK"
81	exit 1
82fi
83if grep "www2.example.com: 10.20.30.42" outfile; then
84	echo "OK"
85else
86	cat fwd.log
87	echo "Not OK"
88	exit 1
89fi
90locktest
91rm outfile
92
93fi #HAVE_FORK
94
95echo '> $PRE/asynclook -t -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
96$PRE/asynclook -t -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
97if grep "www.example.com: 10.20.30.40" outfile; then
98	echo "OK"
99else
100	cat fwd.log
101	echo "Not OK"
102	exit 1
103fi
104if grep "www2.example.com: 10.20.30.42" outfile; then
105	echo "OK"
106else
107	cat fwd.log
108	echo "Not OK"
109	exit 1
110fi
111locktest
112rm outfile
113
114if test $HAVE_FORK = yes; then
115# test cancellation
116echo '> $PRE/asynclook -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
117$PRE/asynclook -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
118if grep "www.example.com: cancelled" outfile; then
119	echo "OK"
120else
121	cat fwd.log
122	echo "Not OK"
123	exit 1
124fi
125if grep "www2.example.com: cancelled" outfile; then
126	echo "OK"
127else
128	cat fwd.log
129	echo "Not OK"
130	exit 1
131fi
132locktest
133rm outfile
134fi #HAVE_FORK
135
136echo '> $PRE/asynclook -t -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
137$PRE/asynclook -t -c -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
138if grep "www.example.com: cancelled" outfile; then
139	echo "OK"
140else
141	cat fwd.log
142	echo "Not OK"
143	exit 1
144fi
145if grep "www2.example.com: cancelled" outfile; then
146	echo "OK"
147else
148	cat fwd.log
149	echo "Not OK"
150	exit 1
151fi
152locktest
153rm outfile
154
155if test $HAVE_FORK = yes; then
156# test blocking mode
157echo '> $PRE/asynclook -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
158$PRE/asynclook -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
159if grep "www.example.com: 10.20.30.40" outfile; then
160	echo "OK"
161else
162	cat fwd.log
163	echo "Not OK"
164	exit 1
165fi
166if grep "www2.example.com: 10.20.30.42" outfile; then
167	echo "OK"
168else
169	cat fwd.log
170	echo "Not OK"
171	exit 1
172fi
173locktest
174rm outfile
175fi #HAVE_FORK
176
177echo '> $PRE/asynclook -t -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile'
178$PRE/asynclook -t -b -f "127.0.0.1@"$FWD_PORT www.example.com www2.example.com 2>&1 | tee outfile
179if grep "www.example.com: 10.20.30.40" outfile; then
180	echo "OK"
181else
182	cat fwd.log
183	echo "Not OK"
184	exit 1
185fi
186if grep "www2.example.com: 10.20.30.42" outfile; then
187	echo "OK"
188else
189	cat fwd.log
190	echo "Not OK"
191	exit 1
192fi
193locktest
194rm outfile
195
196echo "> cat logfiles"
197cat fwd.log
198exit 0
199