runtime test: use helper function that kills named and waits for the finish

This commit is contained in:
Ondřej Surý
2019-11-16 16:33:47 +08:00
parent 2c0710d5e6
commit e9fa7b831b

View File

@@ -17,6 +17,33 @@ RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
status=0
n=0
kill_named() {
pidfile="${1}"
if [ ! -r "${pidfile}" ]; then
return 1
fi
pid=$(cat "${pidfile}" 2>/dev/null)
if test "${pid:+set}" = "set"; then
$KILL -15 "${pid}" >/dev/null 2>&1
retries=10
while [ "$retries" -gt 0 ]; do
if ! $KILL -0 "${pid}" >/dev/null 2>&1; then
break
fi
sleep 1
retries=$((retries-1))
done
# Timed-out
if [ "$retries" -eq 0 ]; then
echo_i "failed to kill named ($pidfile)"
return 1
fi
fi
rm -f "${pidfile}"
return 0
}
n=`expr $n + 1`
echo_i "verifying that named started normally ($n)"
ret=0
@@ -32,8 +59,7 @@ ret=0
(cd ns2; $NAMED -c named-alt2.conf -D runtime-ns2-extra-2 -X named.lock -m record,size,mctx -d 99 -g -U 4 >> named3.run 2>&1 & )
sleep 2
grep "another named process" ns2/named3.run > /dev/null || ret=1
pid=`cat ns2/named3.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
kill_named ns2/named3.pid && ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
@@ -43,8 +69,7 @@ ret=0
(cd ns2; $NAMED -c named-alt3.conf -D runtime-ns2-extra-3 -m record,size,mctx -d 99 -g -U 4 >> named4.run 2>&1 & )
sleep 2
grep "another named process" ns2/named4.run > /dev/null && ret=1
pid=`cat ns2/named4.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
kill_named ns2/named4.pid || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
@@ -88,12 +113,7 @@ cd ns2
$NAMED -c named-alt4.conf -D runtime-ns2-extra-4 -d 99 -g > named4.run 2>&1 &
sleep 2
grep "exiting (due to fatal error)" named4.run > /dev/null || ret=1
# pidfile could be in either place depending on whether the directory
# successfully changed.
pid=`cat named.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
pid=`cat ../named.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
kill_named named.pid && ret=1
cd ..
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
@@ -105,12 +125,7 @@ cd ns2
$NAMED -c named-alt5.conf -D runtime-ns2-extra-5 -d 99 -g > named5.run 2>&1 &
sleep 2
grep "exiting (due to fatal error)" named5.run > /dev/null || ret=1
# pidfile could be in either place depending on whether the directory
# successfully changed.
pid=`cat named.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
pid=`cat ../named.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
kill_named named.pid && ret=1
cd ..
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
@@ -125,8 +140,7 @@ cd ns2
$NAMED -c "${SPEC_DIR}/named.conf" -d 99 -g > named6.run 2>&1 &
sleep 2
grep 'running as.*\\177\\033' named6.run > /dev/null || ret=1
pid=`cat named7.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
kill_named named7.pid || ret=1
cd ..
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
@@ -141,8 +155,7 @@ cd ns2
$NAMED -c "${SPEC_DIR}/named.conf" -d 99 -g > named7.run 2>&1 &
sleep 2
grep 'running as.*\\$\\;' named7.run > /dev/null || ret=1
pid=`cat named7.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
kill_named named7.pid || ret=1
cd ..
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
@@ -152,11 +165,10 @@ echo_i "checking that named logs an ellipsis when the command line is larger tha
ret=0
SPEC_DIR=`yes | head -10000 | tr -d '\n'`
cd ns2
$NAMED -c "${SPEC_DIR}/named.conf" -d 99 -g > named8.run 2>&1 &
$NAMED -c "$SPEC_DIR/named-alt7.conf" -g > named8.run 2>&1 &
sleep 2
grep "running as.*\.\.\.$" named8.run > /dev/null || ret=1
pid=`cat named7.pid 2>/dev/null`
test "${pid:+set}" = set && $KILL -15 ${pid} >/dev/null 2>&1
kill_named named7.pid || ret=1
cd ..
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`