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`.

(cherry picked from commit 837c190d9e)
This commit is contained in:
Tom Krizek 2023-06-09 10:57:34 +02:00
parent e577b1eca7
commit b04181224f
No known key found for this signature in database
GPG key ID: 01623B9B652A20A7
19 changed files with 89 additions and 99 deletions

View file

@ -1373,8 +1373,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)"
@ -1586,11 +1586,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
@ -1609,8 +1609,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

View file

@ -23,8 +23,7 @@ fail() {
}
runcmd() {
"$@" 1> out.$n 2> err.$n
echo $?
("$@" 1> out.$n 2> err.$n; echo $?) || true
}
testcase() {

View file

@ -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
@ -205,15 +204,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;
@ -221,8 +220,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;
@ -230,8 +229,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))

View file

@ -246,8 +246,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
}

View file

@ -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
}

View file

@ -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
@ -2428,8 +2425,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

View file

@ -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

View file

@ -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

View file

@ -104,8 +104,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
@ -133,8 +133,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
@ -384,8 +384,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

View file

@ -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

View file

@ -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

View file

@ -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 () {

View file

@ -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))

View file

@ -823,13 +823,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

View file

@ -518,8 +518,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

View file

@ -220,8 +220,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

View file

@ -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}"

View file

@ -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
}

View file

@ -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 <<EOF
*.w.example R53BQ7CC2UVMUBFU5OCMM6PERS9TK9EN
@ -60,45 +61,47 @@ EOF
# test empty salt
checkempty() {
hash=CK0POJMG874LJREF7EFN8430QVIT8BSM checkout &&
hash=- checkout
rc=$1
hash=CK0POJMG874LJREF7EFN8430QVIT8BSM checkout $rc &&
hash=- checkout $rc
}
name=com algo=1 flags=1 iters=0
echo_i "checking $NSEC3HASH '' $name"
out=`$NSEC3HASH '' $algo $iters $name`
checkempty
{ out=`$NSEC3HASH '' $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH - $name"
out=`$NSEC3HASH - $algo $iters $name`
checkempty
{ out=`$NSEC3HASH - $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -- '' $name"
out=`$NSEC3HASH -- '' $algo $iters $name`
checkempty
{ out=`$NSEC3HASH -- '' $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -- - $name"
out=`$NSEC3HASH -- - $algo $iters $name`
checkempty
{ out=`$NSEC3HASH -- - $algo $iters $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -r '' $name"
out=`$NSEC3HASH -r $algo $flags $iters '' $name`
checkempty
{ out=`$NSEC3HASH -r $algo $flags $iters '' $name`; rc=$?; } || true
checkempty $rc
echo_i "checking $NSEC3HASH -r - $name"
out=`$NSEC3HASH -r $algo $flags $iters - $name`
checkempty
{ out=`$NSEC3HASH -r $algo $flags $iters - $name`; rc=$?; } || true
checkempty $rc
checkfail() {
case $? in
rc=$1
case $rc in
0) echo_i "failed to fail"
status=$((status + 1))
return 1 ;;
esac
}
echo_i "checking $NSEC3HASH missing args"
out=`$NSEC3HASH 00 1 0 2>&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