]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Wait for test instance of named to exit before completing subtest.
authorMark Andrews <marka@isc.org>
Mon, 31 Aug 2020 03:54:12 +0000 (13:54 +1000)
committerMark Andrews <marka@isc.org>
Thu, 10 Sep 2020 10:41:00 +0000 (20:41 +1000)
(cherry picked from commit dda5b7b0b86ca3250bcc3e6a4e3f931fdd253561)

bin/tests/system/runtime/clean.sh
bin/tests/system/runtime/tests.sh

index 896e20f5027b5668b4e90bf8b9f59a08a3de9b35..4be2070e3060b5c01c107e688859b57e41f8b3b0 100644 (file)
@@ -9,13 +9,16 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-rm -f ns2/named.conf ns2/named-alt*.conf
-rm -f */named.memstats
+[ -d ns2/nope ] && chmod 755 ns2/nope
+
+rm -f *.pid
 rm -f */named*.run
+rm -f */named.memstats
+rm -f kill*.out
+rm -f ns*/managed-keys.bind*
 rm -f ns*/named.lock ns*/named*.pid ns*/other.lock
-rm -f *.pid
+rm -f ns2/named.conf ns2/named-alt*.conf
 rm -f rndc.out*
-[ -d ns2/nope ] && chmod 755 ns2/nope
 rm -rf ns2/nope
 rm -f ns2/dir ns2/nopedir ns2/mkd ns2/nopemkd
 rm -rf ns2/tmp.*
index a3318cd9eea2decdab2cb93780152fb790d351bb..33b6ba0e225d81772d4d8f14a4f886649e893ec1 100644 (file)
@@ -16,6 +16,7 @@ SYSTEMTESTTOP=..
 set -e
 
 RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
+NAMED_DEFAULT_ARGS="-m record,size,mctx -d 99 -g -U 4"
 
 kill_named() {
        pidfile="${1}"
@@ -44,21 +45,26 @@ kill_named() {
        return 0
 }
 
-wait_for_named() {
-       retries=10
-       while [ "$retries" -gt 0 ]; do
-               if grep "$@" >/dev/null 2>&1; then
-                       break
-               fi
-               sleep 1
-               retries=$((retries-1))
-       done
-       if [ "$retries" -eq 0 ]; then
-               return 1
-       fi
-       return 0
+check_named_log() {
+       grep "$@" >/dev/null 2>&1
 }
 
+run_named() (
+       dir="$1"
+       shift
+       run="$1"
+       shift
+       if cd "$dir" > /dev/null 2>&1
+       then
+               "${NAMED}" "$@" ${NAMED_DEFAULT_ARGS} >> "$run" 2>&1 &
+               echo $!
+       fi
+)
+
+check_pid() (
+       return $(! $KILL -0 "${1}" >/dev/null 2>&1)
+)
+
 status=0
 n=0
 
@@ -75,10 +81,12 @@ if [ ! "$CYGWIN" ]; then
     n=$((n+1))
     echo_i "verifying that named checks for conflicting listeners ($n)"
     ret=0
-    (cd ns2 && $NAMED -c named-alt1.conf -D ns2-extra-1 -X other.lock -m record,size,mctx -d 99 -g -U 4 >> named$n.run 2>&1 & )
-    wait_for_named "unable to listen on any configured interface" ns2/named$n.run || ret=1
-    wait_for_named "exiting (due to fatal error)" ns2/named$n.run || ret=1
+    testpid=$(run_named ns2 named$n.run -c named-alt1.conf -D ns2-extra-1 -X other.lock)
+    test -n "$testpid" || ret=1
+    retry_quiet 10 check_named_log "unable to listen on any configured interface" ns2/named$n.run || ret=1
+    retry_quiet 10 check_named_log "exiting (due to fatal error)" ns2/named$n.run || ret=1
     kill_named named.pid && ret=1
+    test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
     if [ $ret -ne 0 ]; then echo_i "failed"; fi
     status=$((status+ret))
 fi
@@ -86,18 +94,24 @@ fi
 n=$((n+1))
 echo_i "verifying that named checks for conflicting named processes ($n)"
 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 >> named$n.run 2>&1 & )
-wait_for_named "another named process" ns2/named$n.run || ret=1
+testpid=$(run_named ns2 named$n.run -c named-alt2.conf -D runtime-ns2-extra-2 -X named.lock)
+test -n "$testpid" || ret=1
+retry_quiet 10 check_named_log "another named process" ns2/named$n.run || ret=1
+test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
+test -n "$testpid" && $KILL -15 $testpid > kill$n.out 2>&1 && ret=1
+test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
 if [ $ret -ne 0 ]; then echo_i "failed"; fi
 status=$((status+ret))
 
 n=$((n+1))
 echo_i "verifying that 'lock-file none' disables process check ($n)"
 ret=0
-(cd ns2 && $NAMED -c named-alt3.conf -D runtime-ns2-extra-3 -m record,size,mctx -d 99 -g -U 4 >> named$n.run 2>&1 & )
-wait_for_named "running$" ns2/named$n.run || ret=1
+testpid=$(run_named ns2 named$n.run -c named-alt3.conf -D runtime-ns2-extra-3)
+test -n "$testpid" || ret=1
+retry_quiet 10 check_named_log "running$" ns2/named$n.run || ret=1
 grep "another named process" ns2/named$n.run > /dev/null && ret=1
 kill_named ns2/named-alt3.pid || ret=1
+test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
 if [ $ret -ne 0 ]; then echo_i "failed"; fi
 status=$((status+ret))
 
@@ -109,7 +123,7 @@ then
     copy_setports ns2/named-alt4.conf.in ns2/named.conf
     $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1 && ret=1
     grep "failed: permission denied" rndc.out.$n > /dev/null 2>&1 || ret=1
-    wait_for_named "managed-keys-directory '.*' is not writable" ns2/named.run || ret=1
+    retry_quiet 10 check_named_log "managed-keys-directory '.*' is not writable" ns2/named.run || ret=1
     if [ $ret -ne 0 ]; then echo_i "failed"; fi
     status=$((status+ret))
 
@@ -119,7 +133,7 @@ then
     copy_setports ns2/named-alt5.conf.in ns2/named.conf
     $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1 && ret=1
     grep "failed: permission denied" rndc.out.$n > /dev/null 2>&1 || ret=1
-    wait_for_named "working directory '.*' is not writable" ns2/named.run || ret=1
+    retry_quiet 10 check_named_log "working directory '.*' is not writable" ns2/named.run || ret=1
     if [ $ret -ne 0 ]; then echo_i "failed"; fi
     status=$((status+ret))
 
@@ -130,35 +144,41 @@ then
     $RNDCCMD 10.53.0.2 reconfig > rndc.out.$n 2>&1 || ret=1
     grep "failed: permission denied" rndc.out.$n > /dev/null 2>&1 && ret=1
     kill_named ns2/named.pid || ret=1
+    test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
     if [ $ret -ne 0 ]; then echo_i "failed"; fi
     status=$((status+ret))
 
     n=$((n+1))
     echo_i "checking that named refuses to start if managed-keys-directory is set and not writable ($n)"
     ret=0
-    (cd ns2 && $NAMED -c named-alt4.conf -D runtime-ns2-extra-4 -d 99 -g > named$n.run 2>&1 &)
-    wait_for_named "exiting (due to fatal error)" ns2/named$n.run || ret=1
+    testpid=$(run_named ns2 named$n.run -c named-alt4.conf -D runtime-ns2-extra-4)
+    retry_quiet 10 check_named_log "exiting (due to fatal error)" ns2/named$n.run || ret=1
     grep "managed-keys-directory '.*' is not writable" ns2/named$n.run > /dev/null 2>&1 || ret=1
     kill_named ns2/named.pid && ret=1
+    test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
     if [ $ret -ne 0 ]; then echo_i "failed"; fi
     status=$((status+ret))
 
     n=$((n+1))
     echo_i "checking that named refuses to start if managed-keys-directory is unset and working directory is not writable ($n)"
     ret=0
-    (cd ns2 && $NAMED -c named-alt5.conf -D runtime-ns2-extra-5 -d 99 -g > named$n.run 2>&1 &)
-    wait_for_named "exiting (due to fatal error)" ns2/named$n.run || ret=1
+    testpid=$(run_named ns2 named$n.run -c named-alt5.conf -D runtime-ns2-extra-5)
+    test -n "$testpid" || ret=1
+    retry_quiet 10 check_named_log "exiting (due to fatal error)" ns2/named$n.run || ret=1
     grep "working directory '.*' is not writable" ns2/named$n.run > /dev/null 2>&1 || ret=1
     kill_named ns2/named.pid && ret=1
+    test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
     if [ $ret -ne 0 ]; then echo_i "failed"; fi
     status=$((status+ret))
 
     n=$((n+1))
     echo_i "checking that named starts if managed-keys-directory is writable and working directory is not writable ($n)"
     ret=0
-    (cd ns2/nope && $NAMED -c ../named-alt6.conf -D runtime-ns2-extra-6 -d 99 -g > ../named$n.run 2>&1 &)
-    wait_for_named " running$" ns2/named$n.run || ret=1
+    testpid=$(run_named ns2/nope ../named$n.run -c ../named-alt6.conf -D runtime-ns2-extra-6)
+    test -n "$testpid" || ret=1
+    retry_quiet 10 check_named_log " running$" ns2/named$n.run || ret=1
     kill_named ns2/named.pid || ret=1
+    test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
     if [ $ret -ne 0 ]; then echo_i "failed"; fi
     status=$((status+ret))
 fi
@@ -175,11 +195,13 @@ if [ "`id -u`" -eq 0 ] && [ -z "$CYGWIN" ]; then
         sh -x "$TOP/bin/tests/prepare-softhsm2.sh"
         chown -R nobody: "${TEMP_NAMED_DIR}"
         chmod 0700 "${TEMP_NAMED_DIR}"
-        ( cd "${TEMP_NAMED_DIR}" && $NAMED -u nobody -c named-alt9.conf -d 99 -g -U 4 >> named$n.run 2>&1 & ) || ret=1
-        wait_for_named "running$" "${TEMP_NAMED_DIR}/named$n.run" || ret=1
+        testpid=$(run_named "${TEMP_NAMED_DIR}" named$n.run -u nobody -c named-alt9.conf)
+       test -n "$testpid" || ret=1
+        retry_quiet 10 check_named_log "running$" "${TEMP_NAMED_DIR}/named$n.run" || ret=1
         [ -s "${TEMP_NAMED_DIR}/named9.pid" ] || ret=1
         grep "loading configuration: permission denied" "${TEMP_NAMED_DIR}/named$n.run" > /dev/null && ret=1
         kill_named "${TEMP_NAMED_DIR}/named9.pid" || ret=1
+        test -n "$testpid" && retry_quiet 10 check_pid $testpid || ret=1
     else
         echo_i "mktemp failed"
         ret=1