]> git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests/start-test-stop
Limit the number of queries sent out to get NS addresses per query.
[thirdparty/pdns.git] / regression-tests / start-test-stop
1 #!/usr/bin/env bash
2 set -e
3 if [ "${PDNS_DEBUG}" = "YES" ]; then
4 set -x
5 fi
6
7 export PDNS=${PDNS:-${PWD}/../pdns/pdns_server}
8 export PDNS2=${PDNS2:-${PWD}/../pdns/pdns_server}
9 export PDNSRECURSOR=${PDNSRECURSOR:-${PWD}/../pdns/recursordist/pdns_recursor}
10 export RECCONTROL=${RECCONTROL:-${PWD}/../pdns/recursordist/rec_control}
11 export SDIG=${SDIG:-${PWD}/../pdns/sdig}
12 export NOTIFY=${NOTIFY:-${PWD}/../pdns/pdns_notify}
13 export NSEC3DIG=${NSEC3DIG:-${PWD}/../pdns/nsec3dig}
14 export SAXFR=${SAXFR:-${PWD}/../pdns/saxfr}
15 export ZONE2SQL=${ZONE2SQL:-${PWD}/../pdns/zone2sql}
16 export ZONE2LDAP=${ZONE2LDAP:-${PWD}/../pdns/zone2ldap}
17 export PDNSUTIL=${PDNSUTIL:-${PWD}/../pdns/pdnsutil}
18 export PDNSCONTROL=${PDNSCONTROL:-${PWD}/../pdns/pdns_control}
19 export RESOLVERIP=${RESOLVERIP:-8.8.8.8}
20 export FIX_TESTS=${FIX_TESTS:-NO}
21
22
23 ALGORITHM=${ALGORITHM:="hmac-md5"}
24 KEY=${KEY:="kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys="}
25
26 MAKE=${MAKE:-make}
27
28 export ALGORITHM
29 export KEY
30
31 _show_help=0
32 for arg; do
33 case "$arg" in
34 (--help|help)
35 _show_help=1
36 ;;
37 esac
38 done; unset -v arg
39 if [ "$_show_help" -eq 1 ]; then
40 grep -v '^#' << '__EOF__'
41
42 Usage: ./start-test-stop <port> [<context>] [wait|nowait] [<cachettl>] [<specifictest>]
43
44 context is one of:
45 bind bind-dnssec bind-dnssec-nsec3 bind-dnssec-nsec3-optout bind-dnssec-nsec3-narrow
46 geoip geoip-nsec3-narrow
47 gmysql-nodnssec gmysql gmysql-nsec3 gmysql-nsec3-optout gmysql-nsec3-narrow
48 godbc_mssql-nodnssec godbc_mssql godbc_mssql-nsec3 godbc_mssql-nsec3-optout godbc_mssql-nsec3-narrow
49 godbc_sqlite3-nodnssec godbc_sqlite3 godbc_sqlite3-nsec3 godbc_sqlite3-nsec3-optout godbc_sqlite3-narrow
50 gpgsql-nodnssec gpgsql gpgsql-nsec3 gpgsql-nsec3-optout gpgsql-nsec3-narrow
51 gsqlite3-nodnssec gsqlite3 gsqlite3-nsec3 gsqlite3-nsec3-optout gsqlite3-nsec3-narrow
52 lmdb-nodnssec lmdb
53 remotebackend-pipe remotebackend-unix remotebackend-http remotebackend-zeromq
54 remotebackend-pipe-dnssec remotebackend-unix-dnssec remotebackend-http-dnssec remotebackend-zeromq-dnssec
55 #remotebackend-pipe-nsec3 remotebackend-unix-nsec3 remotebackend-http-nsec3
56 #remotebackend-pipe-nsec3-narrow remotebackend-unix-nsec3-narrow remotebackend-http-nsec3-narrow
57 tinydns
58 ldap-tree ldap-simple ldap-strict
59 lua2 lua2-dnssec lua2-nsec3 lua2-nsec3-narrow
60 #ext-nsd ext-nsd-nsec ext-nsd-nsec3 ext-bind ext-bind-nsec ext-bind-nsec3
61
62 * Add -presigned to any ext-nsd, ext-bind, bind, gmysql or gsqlite3 test (except narrow)
63 to test presigned operation.
64
65 * Add -both to any bind or gmysql test (except narrow) to
66 test normal and presigned operation.
67
68 * Add 'wait' (literally) after the context to not kill
69 pdns_server immediately after testing. 'nowait' will kill it.
70
71 * A cachettl can be supplied if you want to run tests with a
72 ttl setting set. The default cachettl is 0.
73
74 * Specifictest can be used to run only one single test.
75 __EOF__
76 exit
77 fi
78 unset -v _show_help
79
80 trap "kill_process 2" EXIT INT TERM
81
82 source ../regression-tests/common
83
84 bindwait ()
85 {
86 check_process
87 configname=$1
88 domcount=$(grep -c ^zone named.conf)
89 if [ ! -x $PDNSCONTROL ]
90 then
91 echo "No pdns_control found"
92 exit
93 fi
94 loopcount=0
95
96 while [ $loopcount -lt 20 ]
97 do
98 sleep 5
99 done=$( ($PDNSCONTROL --config-name=$configname --socket-dir=. --no-config bind-domain-status || true) | grep -c 'parsed into memory' || true )
100 if [ $done = $domcount ]
101 then
102 return
103 fi
104 let loopcount=loopcount+1
105 done
106
107 if [ $done != $domcount ]
108 then
109 echo "Domain parsing failed" >> failed_tests
110 fi
111 }
112
113 securezone ()
114 {
115 local zone=$1
116 local configname=$2
117
118 if [ -n "$configname" ]
119 then
120 configname="--config-name=$configname"
121 fi
122 if [ "${zone: 0:16}" = "secure-delegated" ]
123 then
124 $PDNSUTIL --config-dir=. $configname import-zone-key $zone $zone.private ksk 2>&1
125 $PDNSUTIL --config-dir=. $configname add-zone-key $zone rsasha256 1024 zsk active 2>&1
126 $PDNSUTIL --config-dir=. $configname rectify-zone $zone 2>&1
127 $PDNSUTIL --config-dir=. $configname set-publish-cds $zone 2>&1
128 $PDNSUTIL --config-dir=. $configname set-publish-cdnskey $zone 2>&1
129 else
130 # check if PKCS#11 should be used
131 if [ "$pkcs11" -eq 1 ]; then
132 if [ "$slot" == "" ]; then
133 slot=0
134 else
135 slot=$((slot+1))
136 fi
137 sudo softhsm --init-token --slot $slot --label label$slot --pin 123$slot --so-pin 123$slot
138 kid=`$PDNSUTIL --config-dir=. $configname hsm assign $zone ecdsa256 zsk softhsm label$slot 123$slot label$slot 2>&1 | grep softhsm | awk '{ print $NF }'`
139 kid=`$PDNSUTIL --config-dir=. $configname show-zone $zone | grep 'ID =.*ZSK' | awk '{ print $3 }'`
140 $PDNSUTIL --config-dir=. $configname hsm create-key $zone $kid
141 else
142 $PDNSUTIL --config-dir=. $configname secure-zone $zone 2>&1
143 if [ "${zone: 0:20}" = "cdnskey-cds-test.com" ]; then
144 $PDNSUTIL --config-dir=. $configname set-publish-cds $zone 2>&1
145 $PDNSUTIL --config-dir=. $configname set-publish-cdnskey $zone 2>&1
146 fi
147 fi
148 fi
149 }
150
151 kill_process ()
152 {
153 set +e
154 trap - EXIT INT TERM
155
156 if [ $1 -gt 1 ]
157 then
158 echo "exitvalue$1" >> failed_tests
159 ./toxml
160 ./totar
161 fi
162
163 pids=$(cat pdns*.pid)
164
165 if [ -n "$pids" ]
166 then
167 kill $pids
168 # make sure they die.
169 loopcount=0
170 done=0
171 while [ $loopcount -lt 10 ] && [ $done -eq 0 ]
172 do
173 done=1
174 for pid in $pids
175 do
176 kill -0 $pid > /dev/null 2>&1
177 if [ $? -eq 0 ];
178 then
179 done=0
180 fi
181 done
182 let loopcount=loopcount+1
183 sleep 1
184 done
185
186 kill -9 $pids
187 fi
188
189 rm pdns*.pid
190 exit $1
191 }
192
193 if [ ! -x $PDNS ]
194 then
195 echo "$PDNS is not executable binary"
196 exit
197 fi
198
199 if [ ! -x $PDNS2 ]
200 then
201 echo "$PDNS2 is not executable binary"
202 exit
203 fi
204
205 address="${PDNS_LISTEN_ADDR:-127.0.0.1}"
206 port=$1
207 [ -z "$port" ] && port=5300
208 context=$2
209 [ -z "$context" ] && context=bind-dnssec
210 wait=$3
211 [ -z "$wait" ] && wait=nowait
212 cachettl=$4
213 [ -z "$cachettl" ] && cachettl=0
214 spectest=$5
215
216 testsdir=./tests
217
218 for prog in $SDIG $SAXFR $NOTIFY $NSEC3DIG; do
219 if `echo $prog | grep -q '\.\./pdns'`; then
220 ${MAKE} -C ../pdns ${prog##*../pdns/} || exit
221 fi
222 done
223
224 # Copy original zones because the test might modify them (well only the dyndns stuff, but let's make this work for others as well)
225 for zone in $(grep 'zone ' named.conf | cut -f2 -d\")
226 do
227 if [ -f zones/$zone.orig ]
228 then
229 cp -f zones/$zone.orig zones/$zone
230 fi
231 done
232
233 rm -f pdns*.pid
234 rm -f *_tests
235 rm -f pdns-*.conf
236
237 presigned=no
238 both=no
239
240 if [[ "$context" =~ .+-presigned.* ]]
241 then
242 presigned=yes
243 port=$((port-100))
244 eval "$(echo "$context" | sed -r 's/(.+)(-presigned)(-(.*))?/context=\1 presignedcontext=\4/')"
245 if [ -z "$presignedcontext" ]
246 then
247 presignedcontext=$context
248 fi
249 fi
250
251 if [ "${context: -5}" = "-both" ]
252 then
253 both=yes
254 port=$((port-100))
255 context=${context%-both}
256 presignedcontext=$context
257 fi
258
259 optout=0
260 pkcs11=0
261
262 if [ "${context: -13}" = "-nsec3-optout" ]
263 then
264 optout=1
265 fi
266
267 if [ "${context: -7}" = "-pkcs11" ]
268 then
269 pkcs11=1
270 context=${context:0:-7}
271 fi
272
273 # check for lua
274 if $PDNS --version 2>&1 | grep Features: | grep -q "lua"
275 then
276 lua_prequery="--lua-prequery-script=./check_stest_source"
277 skiplua=0
278 else
279 lua_prequery=""
280 skiplua=1
281 fi
282
283 source backends/common
284
285 start_master
286
287 if [ "$skiplua" == "1" ]; then
288 skipreasons="$skipreasons nolua"
289 fi
290
291 check_process
292
293 dotests () {
294 nameserver=127.0.0.1 ./runtests $spectest
295 ./toxml
296 ./totar
297
298 cat ./trustedkeys
299
300 if [ -s "./failed_tests" ]
301 then
302 for t in `cat failed_tests`
303 do
304 echo -e "\n\n$t"
305 cat ${testsdir}/$t/diff
306 done
307 if [ "${!1}" -eq 0 ]
308 then
309 eval "$1=1"
310 fi
311 fi
312 }
313
314 ## TODO: give sdig a timeout
315
316 RETVAL=0
317
318 export address
319 export port
320 export context
321 export extracontexts
322 export skipreasons
323 export testsdir
324 export optout
325
326 sleep 2
327
328 if [ $presigned = no ] || [ $both = yes ]
329 then
330 dotests RETVAL
331 fi
332
333 if [ $presigned = yes ] || [ $both = yes ]
334 then
335 start_slave
336
337 export port
338 export context
339 export skipreasons
340
341 dotests RETVAL
342 fi
343
344 if [ "$wait" = "wait" ]
345 then
346 echo tests done! push enter to terminate instance
347 read l
348 fi
349
350 trap "kill_process $RETVAL" EXIT