summaryrefslogtreecommitdiffstats
path: root/tests/shell/run-tests.sh
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-09-06 13:52:16 +0200
committerFlorian Westphal <fw@strlen.de>2023-09-07 19:35:20 +0200
commit63739f4b7f923def1db8e2d988ad18d021a9cf2e (patch)
treedcd080a5f58f9bd47460401295a66d77cf677194 /tests/shell/run-tests.sh
parent86ccd72e589105b5277cf81f9e8dc1e208d25f45 (diff)
tests/shell: move valgrind wrapper script to separate script
Previously, in valgrind mode we would generate one script, which had "$NFT" variable and the temp directory hard coded. Soon, we will run jobs in parallel, so they would need at least different temp directories. Also, we want to put the valgrind results are inside "$NFT_TEST_TESTTMPDIR", along the test data. Extract the wrapper script to a separate script. It does not need to be generated ad-hoc, instead it uses the environment variables "$NFT_REAL" and "$NFT_TEST_TESTTMPDIR", as "run-tests.sh" prepares them. Also, add a "$NFT_REAL" variable for the actual NFT binary. We wrap the "$NFT" variable with VALGRIND=y or the user may pass "NFT='valgrind nft'". We should have access to the real binary. That might be useful for example to call `ldd "$NFT_REAL" | grep libjansson` to check for JSON support. Also, we use libtool. So quite possible the nft binary is actually a shell script. Calling valgrind on that script results in a lot of leak reports from shell (and slows down the command). Instead, use `libtool --mode=execute`. Signed-off-by: Thomas Haller <thaller@redhat.com> Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'tests/shell/run-tests.sh')
-rwxr-xr-xtests/shell/run-tests.sh41
1 files changed, 7 insertions, 34 deletions
diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index 92c63e35..b49877fe 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -61,6 +61,8 @@ usage() {
echo " it can be a command with parameters. Note that in this mode quoting"
echo " does not work, so the usage is limited and the command cannot contain"
echo " spaces."
+ echo " NFT_REAL=<CMD> : Real nft comand. Usually this is just the same as \$NFT,"
+ echo " however, you may set NFT='valgrind nft' and NFT_REAL to the real command."
echo " VERBOSE=*|y : Enable verbose output."
echo " DUMPGEN=*|y : Regenerate dump files. Dump files are only recreated if the"
echo " test completes successfully and the \"dumps\" directory for the"
@@ -262,7 +264,10 @@ NFT_TEST_TMPDIR="$(mktemp --tmpdir="$_TMPDIR" -d "nft-test.$(date '+%Y%m%d-%H%M%
msg_error "Failure to create temp directory in \"$_TMPDIR\""
chmod 755 "$NFT_TEST_TMPDIR"
+NFT_REAL="${NFT_REAL-$NFT}"
+
msg_info "conf: NFT=$(printf '%q' "$NFT")"
+msg_info "conf: NFT_REAL=$(printf '%q' "$NFT_REAL")"
msg_info "conf: VERBOSE=$(printf '%q' "$VERBOSE")"
msg_info "conf: DUMPGEN=$(printf '%q' "$DUMPGEN")"
msg_info "conf: VALGRIND=$(printf '%q' "$VALGRIND")"
@@ -311,40 +316,8 @@ kernel_cleanup() {
nft_xfrm
}
-printscript() { # (cmd, tmpd)
- cat <<EOF
-#!/bin/bash
-
-CMD="$1"
-
-# note: valgrind man page warns about --log-file with --trace-children, the
-# last child executed overwrites previous reports unless %p or %q is used.
-# Since libtool wrapper calls exec but none of the iptables tools do, this is
-# perfect for us as it effectively hides bash-related errors
-
-valgrind --log-file=$2/valgrind.log --trace-children=yes \
- --leak-check=full --show-leak-kinds=all \$CMD "\$@"
-RC=\$?
-
-# don't keep uninteresting logs
-if grep -q 'no leaks are possible' $2/valgrind.log; then
- rm $2/valgrind.log
-else
- mv $2/valgrind.log $2/valgrind_\$\$.log
-fi
-
-# drop logs for failing commands for now
-[ \$RC -eq 0 ] || rm $2/valgrind_\$\$.log
-
-exit \$RC
-EOF
-}
-
if [ "$VALGRIND" == "y" ]; then
- msg_info "writing valgrind logs to $NFT_TEST_TMPDIR"
- printscript "$NFT" "$NFT_TEST_TMPDIR" > "$NFT_TEST_TMPDIR/nft"
- chmod a+x "$NFT_TEST_TMPDIR/nft"
- NFT="$NFT_TEST_TMPDIR/nft"
+ NFT="$NFT_TEST_BASEDIR/helpers/nft-valgrind-wrapper.sh"
fi
echo ""
@@ -468,7 +441,7 @@ for testfile in "${TESTS[@]}" ; do
export NFT_TEST_TESTTMPDIR
print_test_header I "$testfile" "EXECUTING" ""
- NFT="$NFT" DIFF="$DIFF" DUMPGEN="$DUMPGEN" $NFT_TEST_UNSHARE_CMD "$NFT_TEST_BASEDIR/helpers/test-wrapper.sh" "$testfile"
+ NFT="$NFT" NFT_REAL="$NFT_REAL" DIFF="$DIFF" DUMPGEN="$DUMPGEN" $NFT_TEST_UNSHARE_CMD "$NFT_TEST_BASEDIR/helpers/test-wrapper.sh" "$testfile"
rc_got=$?
echo -en "\033[1A\033[K" # clean the [EXECUTING] foobar line