]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add assert_int_equal() shell function
authorMichał Kępień <michal@isc.org>
Wed, 6 Nov 2019 14:22:08 +0000 (15:22 +0100)
committerMichał Kępień <michal@isc.org>
Wed, 6 Nov 2019 20:07:02 +0000 (21:07 +0100)
Add a shell function which is used in the "tcp" system test, but has
been accidentally omitted from !2425.  Make sure the function does not
change the value of "ret" itself, so that the caller can decide what to
do with the function's return value.

(cherry picked from commit 8bb7f1f2a18fb311fe4a5ceb3f54ac717c92dc1a)

bin/tests/system/conf.sh.in
bin/tests/system/conf.sh.win32
bin/tests/system/tcp/tests.sh

index 3ff4e617297eed560bf86cd0f82b25d33482572a..4ef8aec718512004c9b7efe9893eba79dbe58be6 100644 (file)
@@ -286,6 +286,24 @@ digcomp() {
 # Useful functions in test scripts
 #
 
+# assert_int_equal: compare two integer variables, $1 and $2
+#
+# If $1 and $2 are equal, return 0; if $1 and $2 are not equal, report
+# the error using the description of the tested variable provided in $3
+# and return 1.
+assert_int_equal() {
+       expected="$1"
+       found="$2"
+       description="$3"
+
+       if [ "${expected}" -ne "${found}" ]; then
+               echo_i "incorrect ${description}: expected ${expected}, got ${found}"
+               return 1
+       fi
+
+       return 0
+}
+
 # keyfile_to_keys_section: helper function for keyfile_to_*_keys() which
 # converts keyfile data into a configuration section using the supplied
 # parameters
index 527a5c8768c71752fa641db8d55b58bdf9fb389d..b38c82fce5dbae75c449c42da696f60914ca5f3e 100644 (file)
@@ -258,6 +258,24 @@ digcomp() {
 # Useful functions in test scripts
 #
 
+# assert_int_equal: compare two integer variables, $1 and $2
+#
+# If $1 and $2 are equal, return 0; if $1 and $2 are not equal, report
+# the error using the description of the tested variable provided in $3
+# and return 1.
+assert_int_equal() {
+       expected="$1"
+       found="$2"
+       description="$3"
+
+       if [ "${expected}" -ne "${found}" ]; then
+               echo_i "incorrect ${description}: expected ${expected}, got ${found}"
+               return 1
+       fi
+
+       return 0
+}
+
 # keyfile_to_keys_section: helper function for keyfile_to_*_keys() which
 # converts keyfile data into a configuration section using the supplied
 # parameters
index df9a4b6ed2bfc95840925d3fb3af7f61acaf149c..86eafcba3c36548401c15c70a298fe130f7d9685 100644 (file)
@@ -98,7 +98,7 @@ n=$((n + 1))
 echo_i "TCP high-water: check initial statistics ($n)"
 ret=0
 refresh_tcp_stats
-assert_int_equal "${TCP_CUR}" 1 "current TCP clients count"
+assert_int_equal "${TCP_CUR}" 1 "current TCP clients count" || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -111,8 +111,8 @@ OLD_TCP_CUR="${TCP_CUR}"
 TCP_ADDED=9
 open_connections "${TCP_ADDED}"
 refresh_tcp_stats
-assert_int_equal "${TCP_CUR}" $((OLD_TCP_CUR + TCP_ADDED)) "current TCP clients count"
-assert_int_equal "${TCP_HIGH}" $((OLD_TCP_CUR + TCP_ADDED)) "TCP high-water value"
+assert_int_equal "${TCP_CUR}" $((OLD_TCP_CUR + TCP_ADDED)) "current TCP clients count" || ret=1
+assert_int_equal "${TCP_HIGH}" $((OLD_TCP_CUR + TCP_ADDED)) "TCP high-water value" || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -126,8 +126,8 @@ OLD_TCP_HIGH="${TCP_HIGH}"
 TCP_REMOVED=5
 close_connections "${TCP_REMOVED}"
 refresh_tcp_stats
-assert_int_equal "${TCP_CUR}" $((OLD_TCP_CUR - TCP_REMOVED)) "current TCP clients count"
-assert_int_equal "${TCP_HIGH}" "${OLD_TCP_HIGH}" "TCP high-water value"
+assert_int_equal "${TCP_CUR}" $((OLD_TCP_CUR - TCP_REMOVED)) "current TCP clients count" || ret=1
+assert_int_equal "${TCP_HIGH}" "${OLD_TCP_HIGH}" "TCP high-water value" || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`
 
@@ -138,8 +138,8 @@ echo_i "TCP high-water: ensure tcp-clients is an upper bound ($n)"
 ret=0
 open_connections $((TCP_LIMIT + 1))
 refresh_tcp_stats
-assert_int_equal "${TCP_CUR}" "${TCP_LIMIT}" "current TCP clients count"
-assert_int_equal "${TCP_HIGH}" "${TCP_LIMIT}" "TCP high-water value"
+assert_int_equal "${TCP_CUR}" "${TCP_LIMIT}" "current TCP clients count" || ret=1
+assert_int_equal "${TCP_HIGH}" "${TCP_LIMIT}" "TCP high-water value" || ret=1
 if [ $ret != 0 ]; then echo_i "failed"; fi
 status=`expr $status + $ret`