From: Tom Krizek Date: Fri, 9 Jun 2023 08:57:34 +0000 (+0200) Subject: Make $? compatible with set -e in system tests X-Git-Tag: v9.19.16~45^2~28 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=837c190d9ef1113976863c295b4650adc203bcaf;p=thirdparty%2Fbind9.git Make $? compatible with set -e in system tests Ensure handling of return code from previous command doesn't cause the script to halt if that code is non-zero when running with `set -e`. --- diff --git a/bin/tests/system/autosign/tests.sh b/bin/tests/system/autosign/tests.sh index 36dbd26ff85..40136edafdc 100755 --- a/bin/tests/system/autosign/tests.sh +++ b/bin/tests/system/autosign/tests.sh @@ -1191,8 +1191,8 @@ check_interval () { if (int(x) > int(interval)) exit (1); } - END { if (int(x) > int(interval) || int(x) < int(interval-10)) exit(1) }' interval=$2 - return $? + END { if (int(x) > int(interval) || int(x) < int(interval-10)) exit(1) }' interval=$2 || return $? + return 0 } echo_i "checking automatic key reloading interval ($n)" @@ -1404,11 +1404,11 @@ $RNDCCMD 10.53.0.3 signing -nsec3param 1 1 10 12345678 delzsk.example. > signing for i in 0 1 2 3 4 5 6 7 8 9; do _ret=1 $DIG $DIGOPTS delzsk.example NSEC3PARAM @10.53.0.3 > dig.out.ns3.1.test$n 2>&1 || ret=1 - grep "NSEC3PARAM.*12345678" dig.out.ns3.1.test$n > /dev/null 2>&1 - if [ $? -eq 0 ]; then + { grep "NSEC3PARAM.*12345678" dig.out.ns3.1.test$n > /dev/null 2>&1; rc=$?; } || true + if [ $rc -eq 0 ]; then $RNDCCMD 10.53.0.3 signing -list delzsk.example > signing.out.2.test$n 2>&1 - grep "Creating NSEC3 chain " signing.out.2.test$n > /dev/null 2>&1 - if [ $? -ne 0 ]; then + { grep "Creating NSEC3 chain " signing.out.2.test$n > /dev/null 2>&1; rc=$?; } || true + if [ $rc -ne 0 ]; then _ret=0 break fi @@ -1427,8 +1427,8 @@ $SETTIME -D now-1h $file > settime.out.test$n || ret=1 for i in 0 1 2 3 4 5 6 7 8 9; do _ret=1 $RNDCCMD 10.53.0.3 signing -list delzsk.example > signing.out.3.test$n 2>&1 - grep "Signing " signing.out.3.test$n > /dev/null 2>&1 - if [ $? -ne 0 ]; then + { grep "Signing " signing.out.3.test$n > /dev/null 2>&1; rc=$?; } || true + if [ $rc -ne 0 ]; then if [ $(grep "Done signing " signing.out.3.test$n | wc -l) -eq 2 ]; then _ret=0 break diff --git a/bin/tests/system/cds/tests.sh b/bin/tests/system/cds/tests.sh index 312197ace51..2eb092f4b43 100644 --- a/bin/tests/system/cds/tests.sh +++ b/bin/tests/system/cds/tests.sh @@ -23,8 +23,7 @@ fail() { } runcmd() { - "$@" 1> out.$n 2> err.$n - echo $? + ("$@" 1> out.$n 2> err.$n; echo $?) || true } testcase() { diff --git a/bin/tests/system/checkconf/tests.sh b/bin/tests/system/checkconf/tests.sh index 559d5b32dd2..114958c1ebd 100644 --- a/bin/tests/system/checkconf/tests.sh +++ b/bin/tests/system/checkconf/tests.sh @@ -55,8 +55,8 @@ do n=$((n + 1)) echo_i "checking that named-checkconf detects error in $bad ($n)" ret=0 - $CHECKCONF $bad > checkconf.out$n 2>&1 - if [ $? -ne 1 ]; then ret=1; fi + { $CHECKCONF $bad > checkconf.out$n 2>&1; rc=$?; } || true + if [ $rc -ne 1 ]; then ret=1; fi grep "^$bad:[0-9]*: " < checkconf.out$n > /dev/null || ret=1 case $bad in bad-update-policy[123].conf) @@ -88,8 +88,8 @@ do good-dot-*.conf) continue;; esac fi - $CHECKCONF $good > checkconf.out$n 2>&1 - if [ $? -ne 0 ]; then echo_i "failed"; ret=1; fi + { $CHECKCONF $good > checkconf.out$n 2>&1; rc=$?; } || true + if [ $rc -ne 0 ]; then echo_i "failed"; ret=1; fi status=$((status + ret)) done @@ -98,15 +98,14 @@ do n=$((n + 1)) ret=0 - $FEATURETEST --with-lmdb - if [ $? -eq 0 ]; then + if $FEATURETEST --with-lmdb; then echo_i "checking that named-checkconf detects no error in $lmdb ($n)" - $CHECKCONF $lmdb > checkconf.out$n 2>&1 - if [ $? -ne 0 ]; then echo_i "failed"; ret=1; fi + { $CHECKCONF $lmdb > checkconf.out$n 2>&1; rc=$?; } || true + if [ $rc -ne 0 ]; then echo_i "failed"; ret=1; fi else echo_i "checking that named-checkconf detects error in $lmdb ($n)" - $CHECKCONF $lmdb > checkconf.out$n 2>&1 - if [ $? -eq 0 ]; then echo_i "failed"; ret=1; fi + { $CHECKCONF $lmdb > checkconf.out$n 2>&1; rc=$?; } || true + if [ $rc -eq 0 ]; then echo_i "failed"; ret=1; fi fi status=$((status + ret)) done @@ -202,15 +201,15 @@ options { $field 0; }; EOF - $CHECKCONF badzero.conf > checkconf.out$n.1 2>&1 - [ $? -eq 1 ] || { echo_i "options $field failed" ; ret=1; } + { $CHECKCONF badzero.conf > checkconf.out$n.1 2>&1; rc=$?; } || true + [ $rc -eq 1 ] || { echo_i "options $field failed" ; ret=1; } cat > badzero.conf << EOF view dummy { $field 0; }; EOF - $CHECKCONF badzero.conf > checkconf.out$n.2 2>&1 - [ $? -eq 1 ] || { echo_i "view $field failed" ; ret=1; } + { $CHECKCONF badzero.conf > checkconf.out$n.2 2>&1; rc=$?; } || true + [ $rc -eq 1 ] || { echo_i "view $field failed" ; ret=1; } cat > badzero.conf << EOF options { $field 0; @@ -218,8 +217,8 @@ options { view dummy { }; EOF - $CHECKCONF badzero.conf > checkconf.out$n.3 2>&1 - [ $? -eq 1 ] || { echo_i "options + view $field failed" ; ret=1; } + { $CHECKCONF badzero.conf > checkconf.out$n.3 2>&1; rc=$?; } || true + [ $rc -eq 1 ] || { echo_i "options + view $field failed" ; ret=1; } cat > badzero.conf << EOF zone dummy { type secondary; @@ -227,8 +226,8 @@ zone dummy { $field 0; }; EOF - $CHECKCONF badzero.conf > checkconf.out$n.4 2>&1 - [ $? -eq 1 ] || { echo_i "zone $field failed" ; ret=1; } + { $CHECKCONF badzero.conf > checkconf.out$n.4 2>&1; rc=$?; } || true + [ $rc -eq 1 ] || { echo_i "zone $field failed" ; ret=1; } done if [ $ret -ne 0 ]; then echo_i "failed"; fi status=$((status + ret)) diff --git a/bin/tests/system/conf.sh.common b/bin/tests/system/conf.sh.common index 1262a9a940e..696f6c24541 100644 --- a/bin/tests/system/conf.sh.common +++ b/bin/tests/system/conf.sh.common @@ -239,8 +239,7 @@ cat_d() { } digcomp() { - output=`$PERL $TOP_SRCDIR/bin/tests/system/digcomp.pl "$@"` - result=$? + { output=`$PERL $TOP_SRCDIR/bin/tests/system/digcomp.pl "$@"`; result=$?; } || true [ -n "$output" ] && { echo "digcomp failed:"; echo "$output"; } | cat_i return $result } diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index 9a392d377d2..39f6299e988 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -42,14 +42,13 @@ check_ttl_range() { case "$pos" in "3") - awk -v rrtype="$2" -v ttl="$3" '($4 == "IN" || $4 == "CLASS1" ) && $5 == rrtype { if ($3 <= ttl) { ok=1 } } END { exit(ok?0:1) }' < $file + { awk -v rrtype="$2" -v ttl="$3" '($4 == "IN" || $4 == "CLASS1" ) && $5 == rrtype { if ($3 <= ttl) { ok=1 } } END { exit(ok?0:1) }' < $file; result=$?; } || true ;; *) - awk -v rrtype="$2" -v ttl="$3" '($3 == "IN" || $3 == "CLASS1" ) && $4 == rrtype { if ($2 <= ttl) { ok=1 } } END { exit(ok?0:1) }' < $file + { awk -v rrtype="$2" -v ttl="$3" '($3 == "IN" || $3 == "CLASS1" ) && $4 == rrtype { if ($2 <= ttl) { ok=1 } } END { exit(ok?0:1) }' < $file; result=$?; } || true ;; esac - result=$? [ $result -eq 0 ] || echo_i "ttl check failed" return $result } diff --git a/bin/tests/system/dnssec/tests.sh b/bin/tests/system/dnssec/tests.sh index 5e272ac1ace..01d7924b86c 100644 --- a/bin/tests/system/dnssec/tests.sh +++ b/bin/tests/system/dnssec/tests.sh @@ -83,8 +83,7 @@ israw0 () { < "$1" $PERL -e 'binmode STDIN; read(STDIN, $input, 8); ($style, $version) = unpack("NN", $input); - exit 1 if ($style != 2 || $version != 0);' - return $? + exit 1 if ($style != 2 || $version != 0);' || return $? } # check that a zone file is raw format, version 1 @@ -93,8 +92,7 @@ israw1 () { < "$1" $PERL -e 'binmode STDIN; read(STDIN, $input, 8); ($style, $version) = unpack("NN", $input); - exit 1 if ($style != 2 || $version != 1);' - return $? + exit 1 if ($style != 2 || $version != 1);' || return $? } # strip NS and RRSIG NS from input @@ -113,8 +111,7 @@ check_secroots_layout () { /Start view/ { if (!empty) exit(1) } /Secure roots:/ { if (empty) exit(1) } /Negative trust anchors:/ { if (!empty) exit(1) } - { empty=0 }' $1 - return $? + { empty=0 }' $1 || return $? } # Check that for a query against a validating resolver where the @@ -2646,8 +2643,8 @@ if $PERL -e 'use Net::DNS;' 2>/dev/null then echo_i "running DNSSEC update test" ret=0 - output=$($PERL dnssec_update_test.pl -s 10.53.0.3 -p "$PORT" dynamic.example.) - test "$?" -eq 0 || ret=1 + { output=$($PERL dnssec_update_test.pl -s 10.53.0.3 -p "$PORT" dynamic.example.); rc=$?; } || true + test "$rc" -eq 0 || ret=1 echo "$output" | cat_i [ $ret -eq 1 ] && status=1 else diff --git a/bin/tests/system/dnstap/tests.sh b/bin/tests/system/dnstap/tests.sh index 6034c830ff1..c7965445d02 100644 --- a/bin/tests/system/dnstap/tests.sh +++ b/bin/tests/system/dnstap/tests.sh @@ -42,8 +42,8 @@ for bad in bad-*.conf do ret=0 echo_i "checking that named-checkconf detects error in $bad" - $CHECKCONF $bad > /dev/null 2>&1 - if [ $? != 1 ]; then echo_i "failed"; ret=1; fi + { $CHECKCONF $bad > /dev/null 2>&1; rc=$?; } || true + if [ $rc != 1 ]; then echo_i "failed"; ret=1; fi status=$((status + ret)) done @@ -51,8 +51,8 @@ for good in good-*.conf do ret=0 echo_i "checking that named-checkconf detects no error in $good" - $CHECKCONF $good > /dev/null 2>&1 - if [ $? != 0 ]; then echo_i "failed"; ret=1; fi + { $CHECKCONF $good > /dev/null 2>&1; rc=$?; } || true + if [ $rc != 0 ]; then echo_i "failed"; ret=1; fi status=$((status + ret)) done diff --git a/bin/tests/system/doth/tests.sh b/bin/tests/system/doth/tests.sh index 59908ce4c39..3a84a30efa6 100644 --- a/bin/tests/system/doth/tests.sh +++ b/bin/tests/system/doth/tests.sh @@ -845,8 +845,7 @@ n=$((n + 1)) echo_i "checking server quotas for both encrypted and unencrypted HTTP ($n)" ret=0 if [ -x "$PYTHON" ]; then - BINDHOST="10.53.0.1" "$PYTHON" "$TOP_SRCDIR/bin/tests/system/doth/stress_http_quota.py" - ret=$? + BINDHOST="10.53.0.1" "$PYTHON" "$TOP_SRCDIR/bin/tests/system/doth/stress_http_quota.py" || ret=$? else echo_i "Python is not available. Skipping the test..." fi diff --git a/bin/tests/system/idna/tests.sh b/bin/tests/system/idna/tests.sh index 594cb053b4d..03c85a83044 100644 --- a/bin/tests/system/idna/tests.sh +++ b/bin/tests/system/idna/tests.sh @@ -93,8 +93,8 @@ idna_test() { echo_i "$description ($n)" ret=0 - $DIGCMD $2 $3 > dig.out.$n 2>&1 - if [ $? -ne 0 ]; then + { $DIGCMD $2 $3 > dig.out.$n 2>&1; rc=$?; } || true + if [ $rc -ne 0 ]; then echo_i "failed: dig command returned non-zero status" ret=1 else @@ -122,8 +122,8 @@ idna_fail() { echo_i "$description ($n)" ret=0 - $DIGCMD $2 $3 > dig.out.$n 2>&1 - if [ $? -eq 0 ]; then + { $DIGCMD $2 $3 > dig.out.$n 2>&1; rc=$?; } || true + if [ $rc -eq 0 ]; then echo_i "failed: dig command unexpectedly succeeded" ret=1 fi @@ -378,8 +378,7 @@ idna_disabled_test() { # Main test begins here -$FEATURETEST --with-libidn2 -if [ $? -eq 0 ]; then +if $FEATURETEST --with-libidn2; then idna_enabled_test else idna_disabled_test diff --git a/bin/tests/system/inline/tests.sh b/bin/tests/system/inline/tests.sh index 423cfc64fe4..b157d640c51 100755 --- a/bin/tests/system/inline/tests.sh +++ b/bin/tests/system/inline/tests.sh @@ -878,8 +878,8 @@ $RNDCCMD 10.53.0.7 retransfer $zone for i in 1 2 3 4 5 6 7 8 9 0 do ret=1 - grep "ns2.$zone. . 10 20 20 1814400 3600" ns7/named.run > /dev/null 2>&1 - [ $? -eq 0 ] && ret=0 && break + { grep "ns2.$zone. . 10 20 20 1814400 3600" ns7/named.run > /dev/null 2>&1; rc=$?; } || true + [ $rc -eq 0 ] && ret=0 && break sleep 1 done if [ $ret != 0 ]; then echo_i "failed"; fi diff --git a/bin/tests/system/ixfr/tests.sh b/bin/tests/system/ixfr/tests.sh index 3c798bda9d5..a4a604f8973 100644 --- a/bin/tests/system/ixfr/tests.sh +++ b/bin/tests/system/ixfr/tests.sh @@ -208,8 +208,8 @@ status=$((status+ret)) n=$((n+1)) echo_i "testing ixfr-from-differences option ($n)" # ns3 is primary; ns4 is secondary -$CHECKZONE test. ns3/mytest.db > /dev/null 2>&1 -if [ $? -ne 0 ] +{ $CHECKZONE test. ns3/mytest.db > /dev/null 2>&1; rc=$?; } || true +if [ $rc -ne 0 ] then echo_i "named-checkzone returned failure on ns3/mytest.db" fi diff --git a/bin/tests/system/masterformat/tests.sh b/bin/tests/system/masterformat/tests.sh index 1bcddd60dec..da9ec87ebf3 100755 --- a/bin/tests/system/masterformat/tests.sh +++ b/bin/tests/system/masterformat/tests.sh @@ -24,8 +24,7 @@ israw () { $PERL -e 'binmode STDIN; read(STDIN, $input, 8); ($style, $version) = unpack("NN", $input); - exit 1 if ($style != 2 || $version > 1);' < "$1" - return $? + exit 1 if ($style != 2 || $version > 1);' < "$1" || return $? } isfull () { diff --git a/bin/tests/system/names/tests.sh b/bin/tests/system/names/tests.sh index 1d6f6308473..f8768a84c92 100644 --- a/bin/tests/system/names/tests.sh +++ b/bin/tests/system/names/tests.sh @@ -32,8 +32,7 @@ cat dig.compdis.test |grep -v ';;' |sort > dig.compdis.sorted.test # the compression disabled message should be at least twice as large as with # compression disabled, but the content should be the same echo_i "Checking if responses are identical other than in message size" -diff dig.compdis.sorted.test dig.compen.sorted.test >/dev/null -ret=$? +{ diff dig.compdis.sorted.test dig.compen.sorted.test >/dev/null; ret=$?; } || true if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status + ret)) diff --git a/bin/tests/system/nsupdate/tests.sh b/bin/tests/system/nsupdate/tests.sh index 9fefe34fb0a..b8e476dda28 100755 --- a/bin/tests/system/nsupdate/tests.sh +++ b/bin/tests/system/nsupdate/tests.sh @@ -765,13 +765,13 @@ echo_i "check command list ($n)" ( while read cmd do - echo "$cmd" | $NSUPDATE > /dev/null 2>&1 - if test $? -gt 1 ; then + { echo "$cmd" | $NSUPDATE > /dev/null 2>&1; rc=$?; } || true + if test $rc -gt 1 ; then echo_i "failed ($cmd)" ret=1 fi - echo "$cmd " | $NSUPDATE > /dev/null 2>&1 - if test $? -gt 1 ; then + { echo "$cmd " | $NSUPDATE > /dev/null 2>&1; rc=$?; } || true + if test $rc -gt 1 ; then echo_i "failed ($cmd)" ret=1 fi diff --git a/bin/tests/system/rndc/tests.sh b/bin/tests/system/rndc/tests.sh index 379a2c17665..2be9594debf 100644 --- a/bin/tests/system/rndc/tests.sh +++ b/bin/tests/system/rndc/tests.sh @@ -519,8 +519,8 @@ do echo_i "testing rndc buffer size limits (size=${i}) ($n)" ret=0 $RNDC -s 10.53.0.4 -p ${EXTRAPORT6} -c ns4/key6.conf testgen ${i} 2>&1 > rndc.out.$i.test$n || ret=1 - actual_size=`$GENCHECK rndc.out.$i.test$n` - if [ "$?" = "0" ]; then + { actual_size=`$GENCHECK rndc.out.$i.test$n`; rc=$?; } || true + if [ "$rc" = "0" ]; then expected_size=$((i+1)) if [ $actual_size != $expected_size ]; then ret=1; fi else diff --git a/bin/tests/system/rpzrecurse/tests.sh b/bin/tests/system/rpzrecurse/tests.sh index 62a5f1ee8fd..052d62c1293 100644 --- a/bin/tests/system/rpzrecurse/tests.sh +++ b/bin/tests/system/rpzrecurse/tests.sh @@ -238,8 +238,7 @@ for mode in native dnsrps; do for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \ 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 do - run_query 4$n $i - c=`expr $c + $?` + run_query 4$n $i || c=$((c + 1)) done skipped=$((33-c)) if [ $skipped != $ni ]; then diff --git a/bin/tests/system/runtime/tests.sh b/bin/tests/system/runtime/tests.sh index 99650619b1f..ac55f250a8e 100644 --- a/bin/tests/system/runtime/tests.sh +++ b/bin/tests/system/runtime/tests.sh @@ -225,8 +225,8 @@ n=$((n+1)) echo_i "verifying that named switches UID ($n)" if [ "$(id -u)" -eq 0 ]; then ret=0 - TEMP_NAMED_DIR=$(mktemp -d "$(pwd)/ns2/tmp.XXXXXXXX") - if [ "$?" -eq 0 ]; then + { TEMP_NAMED_DIR=$(mktemp -d "$(pwd)/ns2/tmp.XXXXXXXX"); rc=$?; } || true + if [ "$rc" -eq 0 ]; then copy_setports ns2/named-alt9.conf.in "${TEMP_NAMED_DIR}/named-alt9.conf" chown -R nobody: "${TEMP_NAMED_DIR}" chmod 0700 "${TEMP_NAMED_DIR}" diff --git a/bin/tests/system/statschannel/tests.sh b/bin/tests/system/statschannel/tests.sh index aba4a6976b7..1e3a28da169 100644 --- a/bin/tests/system/statschannel/tests.sh +++ b/bin/tests/system/statschannel/tests.sh @@ -59,8 +59,7 @@ getzones() { esac file=`$PERL fetch.pl -p ${EXTRAPORT1} $path` cp $file $file.$1.$3 - $PERL zones-${1}.pl $file $2 2>/dev/null | sort > zones.out.$3 - result=$? + { $PERL zones-${1}.pl $file $2 2>/dev/null | sort > zones.out.$3; result=$?; } || true return $result } diff --git a/bin/tests/system/tools/tests.sh b/bin/tests/system/tools/tests.sh index 5730a801b96..c96871cd8e3 100644 --- a/bin/tests/system/tools/tests.sh +++ b/bin/tests/system/tools/tests.sh @@ -16,7 +16,8 @@ status=0 checkout() { - case $? in + rc=$1 + case $rc in 0) : ok ;; *) echo_i "failed" status=$((status + 1)) @@ -36,12 +37,12 @@ algo=1 flags=0 iters=12 salt="aabbccdd" while read name hash do echo_i "checking $NSEC3HASH $name" - out=`$NSEC3HASH $salt $algo $iters $name` - checkout + { out=`$NSEC3HASH $salt $algo $iters $name`; rc=$?; } || true + checkout $rc echo_i "checking $NSEC3HASH -r $name" - out=`$NSEC3HASH -r $algo $flags $iters $salt $name` - checkout + { out=`$NSEC3HASH -r $algo $flags $iters $salt $name`; rc=$?; } || true + checkout $rc done <&1` -checkfail +{ out=`$NSEC3HASH 00 1 0 2>&1`; rc=$?; } || true +checkfail $rc echo_i "checking $NSEC3HASH extra args" -out=`$NSEC3HASH 00 1 0 two names 2>&1` -checkfail +{ out=`$NSEC3HASH 00 1 0 two names 2>&1`; rc=$?; } || true +checkfail $rc echo_i "checking $NSEC3HASH bad option" -out=`$NSEC3HASH -? 2>&1` -checkfail +{ out=`$NSEC3HASH -? 2>&1`; rc=$?; } || true +checkfail $rc echo_i "exit status: $status" [ $status -eq 0 ] || exit 1