]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests/start-test-stop
Also update surrounding text as noted by phonedph1
[thirdparty/pdns.git] / regression-tests / start-test-stop
CommitLineData
cf4d037d
PD
1#!/usr/bin/env bash
2set -e
9091cf89
PL
3if [ "${PDNS_DEBUG}" = "YES" ]; then
4 set -x
5fi
7dbdd1e7 6
d9c6538e
PL
7export PDNS=${PDNS:-${PWD}/../pdns/pdns_server}
8export PDNS2=${PDNS2:-${PWD}/../pdns/pdns_server}
1cedb848
PL
9export PDNSRECURSOR=${PDNSRECURSOR:-${PWD}/../pdns/recursordist/pdns_recursor}
10export RECCONTROL=${RECCONTROL:-${PWD}/../pdns/recursordist/rec_control}
d9c6538e 11export SDIG=${SDIG:-${PWD}/../pdns/sdig}
a4437033 12export NOTIFY=${NOTIFY:-${PWD}/../pdns/pdns_notify}
d9c6538e
PL
13export NSEC3DIG=${NSEC3DIG:-${PWD}/../pdns/nsec3dig}
14export SAXFR=${SAXFR:-${PWD}/../pdns/saxfr}
15export ZONE2SQL=${ZONE2SQL:-${PWD}/../pdns/zone2sql}
8c907653 16export ZONE2LDAP=${ZONE2LDAP:-${PWD}/../pdns/zone2ldap}
fd5076c8 17export PDNSUTIL=${PDNSUTIL:-${PWD}/../pdns/pdnsutil}
d9c6538e 18export PDNSCONTROL=${PDNSCONTROL:-${PWD}/../pdns/pdns_control}
869c68a4 19export RESOLVERIP=${RESOLVERIP:-8.8.8.8}
de5841b9 20export FIX_TESTS=${FIX_TESTS:-NO}
d9c6538e 21
a48c8a6c 22
8b8c5060
KM
23ALGORITHM=${ALGORITHM:="hmac-md5"}
24KEY=${KEY:="kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys="}
25
04aaf527
PD
26MAKE=${MAKE:-make}
27
36077044
KM
28export ALGORITHM
29export KEY
30
172a6749 31_show_help=0
32for arg; do
33 case "$arg" in
34 (--help|help)
35 _show_help=1
36 ;;
37 esac
38done; unset -v arg
39if [ "$_show_help" -eq 1 ]; then
40 grep -v '^#' << '__EOF__'
41
42Usage: ./start-test-stop <port> [<context>] [wait|nowait] [<cachettl>] [<specifictest>]
43
44context is one of:
45bind bind-dnssec bind-dnssec-nsec3 bind-dnssec-nsec3-optout bind-dnssec-nsec3-narrow
46geoip geoip-nsec3-narrow
47gmysql-nodnssec gmysql gmysql-nsec3 gmysql-nsec3-optout gmysql-nsec3-narrow
48godbc_mssql-nodnssec godbc_mssql godbc_mssql-nsec3 godbc_mssql-nsec3-optout godbc_mssql-nsec3-narrow
172a6749 49godbc_sqlite3-nodnssec godbc_sqlite3 godbc_sqlite3-nsec3 godbc_sqlite3-nsec3-optout godbc_sqlite3-narrow
50gpgsql-nodnssec gpgsql gpgsql-nsec3 gpgsql-nsec3-optout gpgsql-nsec3-narrow
51gsqlite3-nodnssec gsqlite3 gsqlite3-nsec3 gsqlite3-nsec3-optout gsqlite3-nsec3-narrow
edac607a 52lmdb-nodnssec lmdb
172a6749 53remotebackend-pipe remotebackend-unix remotebackend-http remotebackend-zeromq
54remotebackend-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
57tinydns
58ldap-tree ldap-simple ldap-strict
59lua2 lua2-dnssec lua2-nsec3 lua2-nsec3-narrow
172a6749 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
77fi
78unset -v _show_help
79
5506c989
KM
80trap "kill_process 2" EXIT INT TERM
81
3adde0d2 82source ../regression-tests/common
7dbdd1e7 83
a45871d3
PD
84bindwait ()
85{
a3a4cb13 86 check_process
b563f71b 87 configname=$1
00b9f06d 88 domcount=$(grep -c ^zone named.conf)
d9c6538e 89 if [ ! -x $PDNSCONTROL ]
e08d1e35 90 then
c823f41c 91 echo "No pdns_control found"
5506c989 92 exit
2ede4134
PD
93 fi
94 loopcount=0
5837ffbc 95
e08d1e35
KM
96 while [ $loopcount -lt 20 ]
97 do
e5da48f4 98 sleep 5
d9c6538e 99 done=$( ($PDNSCONTROL --config-name=$configname --socket-dir=. --no-config bind-domain-status || true) | grep -c 'parsed into memory' || true )
e08d1e35
KM
100 if [ $done = $domcount ]
101 then
a45871d3
PD
102 return
103 fi
2ede4134 104 let loopcount=loopcount+1
a45871d3 105 done
2ede4134 106
e08d1e35
KM
107 if [ $done != $domcount ]
108 then
87d6c352 109 echo "Domain parsing failed" >> failed_tests
2ede4134 110 fi
a45871d3
PD
111}
112
b8adb30d
KM
113securezone ()
114{
115 local zone=$1
116 local configname=$2
70f0f8c4 117
b8adb30d
KM
118 if [ -n "$configname" ]
119 then
120 configname="--config-name=$configname"
121 fi
122 if [ "${zone: 0:16}" = "secure-delegated" ]
123 then
fd5076c8 124 $PDNSUTIL --config-dir=. $configname import-zone-key $zone $zone.private ksk 2>&1
e65dffd2 125 $PDNSUTIL --config-dir=. $configname add-zone-key $zone rsasha256 1024 zsk active 2>&1
fd5076c8
PL
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
b8adb30d 129 else
70f0f8c4 130 # check if PKCS#11 should be used
d372242f 131 if [ "$pkcs11" -eq 1 ]; then
70f0f8c4
AT
132 if [ "$slot" == "" ]; then
133 slot=0
134 else
135 slot=$((slot+1))
136 fi
70f0f8c4 137 sudo softhsm --init-token --slot $slot --label label$slot --pin 123$slot --so-pin 123$slot
d113baca 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 }'`
fd5076c8
PL
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
70f0f8c4 141 else
fd5076c8 142 $PDNSUTIL --config-dir=. $configname secure-zone $zone 2>&1
f889ab99
PL
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
70f0f8c4 147 fi
b8adb30d
KM
148 fi
149}
150
5506c989
KM
151kill_process ()
152{
153 set +e
154 trap - EXIT INT TERM
155
5ca4f3a0
KM
156 if [ $1 -gt 1 ]
157 then
158 echo "exitvalue$1" >> failed_tests
159 ./toxml
160 ./totar
161 fi
162
5506c989
KM
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
a3a4cb13
AT
191}
192
e08d1e35
KM
193if [ ! -x $PDNS ]
194 then
c823f41c 195 echo "$PDNS is not executable binary"
5506c989 196 exit
a3a4cb13
AT
197fi
198
e08d1e35
KM
199if [ ! -x $PDNS2 ]
200then
c823f41c 201 echo "$PDNS2 is not executable binary"
5506c989 202 exit
a3a4cb13
AT
203fi
204
3293ac22 205address="${PDNS_LISTEN_ADDR:-127.0.0.1}"
e65a021a
PD
206port=$1
207[ -z "$port" ] && port=5300
7dbdd1e7 208context=$2
c5f8ef18 209[ -z "$context" ] && context=bind-dnssec
8659dbcf 210wait=$3
388cdf7a
RA
211[ -z "$wait" ] && wait=nowait
212cachettl=$4
213[ -z "$cachettl" ] && cachettl=0
214spectest=$5
7dbdd1e7 215
905057ba 216testsdir=./tests
53f66707 217
6e038794 218for prog in $SDIG $SAXFR $NOTIFY $NSEC3DIG; do
dbbaa337 219 if `echo $prog | grep -q '\.\./pdns'`; then
e55a07c9 220 ${MAKE} -C ../pdns ${prog##*../pdns/} || exit
d9c6538e
PL
221 fi
222done
223
d5d97c2f 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)
905057ba 225for zone in $(grep 'zone ' named.conf | cut -f2 -d\")
388cdf7a 226do
905057ba 227 if [ -f zones/$zone.orig ]
d5d97c2f 228 then
905057ba 229 cp -f zones/$zone.orig zones/$zone
d5d97c2f 230 fi
388cdf7a 231done
8e9c4415 232
794c2f92 233rm -f pdns*.pid
dff32e09 234rm -f *_tests
52011cd7 235rm -f pdns-*.conf
794c2f92
PD
236
237presigned=no
e5da48f4 238both=no
794c2f92 239
3a68d5f4 240if [[ "$context" =~ .+-presigned.* ]]
794c2f92
PD
241then
242 presigned=yes
243 port=$((port-100))
3a68d5f4
KM
244 eval "$(echo "$context" | sed -r 's/(.+)(-presigned)(-(.*))?/context=\1 presignedcontext=\4/')"
245 if [ -z "$presignedcontext" ]
246 then
247 presignedcontext=$context
248 fi
794c2f92
PD
249fi
250
e5da48f4
KM
251if [ "${context: -5}" = "-both" ]
252then
253 both=yes
254 port=$((port-100))
255 context=${context%-both}
3a68d5f4 256 presignedcontext=$context
e5da48f4
KM
257fi
258
b8adb30d 259optout=0
70f0f8c4 260pkcs11=0
b8adb30d
KM
261
262if [ "${context: -13}" = "-nsec3-optout" ]
263then
264 optout=1
265fi
266
70f0f8c4
AT
267if [ "${context: -7}" = "-pkcs11" ]
268then
d372242f 269 pkcs11=1
70f0f8c4
AT
270 context=${context:0:-7}
271fi
272
95302209 273# check for lua
de9a69a9 274if $PDNS --version 2>&1 | grep Features: | grep -q "lua"
95302209
AT
275then
276 lua_prequery="--lua-prequery-script=./check_stest_source"
277 skiplua=0
278else
279 lua_prequery=""
280 skiplua=1
281fi
282
905057ba 283source backends/common
db167258 284
905057ba 285start_master
a3a4cb13 286
95302209 287if [ "$skiplua" == "1" ]; then
7eb7ac3d 288 skipreasons="$skipreasons nolua"
95302209
AT
289fi
290
a3a4cb13
AT
291check_process
292
e5da48f4
KM
293dotests () {
294 nameserver=127.0.0.1 ./runtests $spectest
295 ./toxml
296 ./totar
297
bd71d3e3
KM
298 cat ./trustedkeys
299
e5da48f4
KM
300 if [ -s "./failed_tests" ]
301 then
302 for t in `cat failed_tests`
303 do
304 echo -e "\n\n$t"
7c85cf48 305 cat ${testsdir}/$t/diff
e5da48f4 306 done
dcdd4fb7
KM
307 if [ "${!1}" -eq 0 ]
308 then
309 eval "$1=1"
310 fi
e5da48f4
KM
311 fi
312}
794c2f92 313
7dbdd1e7 314## TODO: give sdig a timeout
e5da48f4
KM
315
316RETVAL=0
317
98e8981c 318export address
e5da48f4
KM
319export port
320export context
321export extracontexts
322export skipreasons
323export testsdir
324export optout
325
dcdd4fb7 326sleep 2
e5da48f4
KM
327
328if [ $presigned = no ] || [ $both = yes ]
329then
55b3da69 330 dotests RETVAL
e5da48f4
KM
331fi
332
333if [ $presigned = yes ] || [ $both = yes ]
334then
905057ba 335 start_slave
e5da48f4
KM
336
337 export port
338 export context
339 export skipreasons
340
55b3da69 341 dotests RETVAL
e5da48f4
KM
342fi
343
8659dbcf
PD
344if [ "$wait" = "wait" ]
345then
c823f41c 346 echo tests done! push enter to terminate instance
8659dbcf
PD
347 read l
348fi
e5da48f4 349
5506c989 350trap "kill_process $RETVAL" EXIT