From: Kirill Isakov Date: Fri, 23 Jul 2021 12:41:51 +0000 (+0600) Subject: Add tests to cover some of the fixed leaks. X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=7e09765003114ba37fed2851d9126924d0f813f1;p=tinc Add tests to cover some of the fixed leaks. --- diff --git a/test/commandline.test b/test/commandline.test index 241cb25f..4bd91f45 100755 --- a/test/commandline.test +++ b/test/commandline.test @@ -46,3 +46,19 @@ must_fail tinc foo -n foo get somethingreallyunknown must_fail tinc foo --net must_fail tinc foo --net get name must_fail tinc foo foo + +# Most of these should fail with ASAN. Some leaks are only detected by Valgrind. +echo [STEP] Trigger previously known memory leaks + +tincd foo -c . -c . --help +tincd foo -n net -n net --help +tincd foo -n net -o FakeOpt=42 --help +tincd foo --logfile=one --logfile=two --help +tincd foo --pidfile=one --pidfile=two --help +expect_code "$EXIT_FAILURE" tincd foo -n net -o Compression= --help +expect_code "$EXIT_FAILURE" tincd foo -c fakedir -n 'n/e\t' + +tinc foo -c conf -c conf --help +tinc foo -n net -n net --help +tinc foo --pidfile=pid --pidfile=pid --help +expect_code "$EXIT_FAILURE" tinc foo -c conf -n 'n/e\t' diff --git a/test/testlib.sh.in b/test/testlib.sh.in index 224ab4f9..ec8f400f 100644 --- a/test/testlib.sh.in +++ b/test/testlib.sh.in @@ -26,6 +26,8 @@ SPTPS_KEYPAIR=$(realdir "../src/sptps_keypair@EXEEXT@") # Exit status list # shellcheck disable=SC2034 +EXIT_FAILURE=1 +# shellcheck disable=SC2034 EXIT_SKIP_TEST=77 # The list of the environment variables that tinc injects into the scripts it calls. @@ -98,6 +100,19 @@ must_fail() { fi } +# Executes whatever is passed to it, checking that the resulting exit code is equal to the first argument. +expect_code() { + expected=$1 + shift + + code=0 + "$@" || code=$? + + if [ $code != "$expected" ]; then + bail "wrong exit code $code, expected $expected" + fi +} + # Runs its arguments with timeout(1) or gtimeout(1) if either are installed. # Usage: try_limit_time 10 command --with --args if type timeout >/dev/null; then