]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tests/shell: ensure vgdb-pipe files are deleted from "nft-valgrind-wrapper.sh"
authorThomas Haller <thaller@redhat.com>
Tue, 12 Sep 2023 22:44:50 +0000 (00:44 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 14 Sep 2023 12:26:44 +0000 (14:26 +0200)
When the valgrind process gets killed, those files can be left over.
They are located in the original $TMPDIR (usually /tmp). They should be
cleaned up.

I tried to cleanup the files from withing "nft-valgrind-wrapper.sh"
itself via a `trap`, but it doesn't work. Instead, let "run-tests.sh"
delete all files with a matching pattern.

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
tests/shell/helpers/nft-valgrind-wrapper.sh
tests/shell/run-tests.sh

index 6125dd0f30897530ab2bd52bd7bf3322169f179c..98bbdf43570eca57fc8155a16e51cb37c6b26ac0 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash -e
 
-SUFFIX="$(date "+%Y%m%d-%H%M%S.%6N.$$")"
+SUFFIX="$(date "+%H%M%S.%6N").$$"
 
 rc=0
 libtool \
@@ -12,7 +12,7 @@ libtool \
                --show-leak-kinds=all \
                --num-callers=100 \
                --error-exitcode=122 \
-               --vgdb-prefix="$NFT_TEST_TMPDIR_ORIG/vgdb-pipe-nft-test-$SUFFIX" \
+               --vgdb-prefix="$_NFT_TEST_VALGRIND_VGDB_PREFIX-$SUFFIX" \
                $NFT_TEST_VALGRIND_OPTS \
                "$NFT_REAL" \
                "$@" \
index cf17302fdc19c639cd5f000c0519b9c0fdd44605..7ac6202ca43c884e8022e15f4c18338fb09470e1 100755 (executable)
@@ -426,6 +426,8 @@ fi
 
 declare -A JOBS_PIDLIST
 
+_NFT_TEST_VALGRIND_VGDB_PREFIX=
+
 cleanup_on_exit() {
        pids_search=''
        for pid in "${!JOBS_PIDLIST[@]}" ; do
@@ -442,13 +444,17 @@ cleanup_on_exit() {
        if [ "$NFT_TEST_KEEP_LOGS" != y -a -n "$NFT_TEST_TMPDIR" ] ; then
                rm -rf "$NFT_TEST_TMPDIR"
        fi
+       if [ -n "$_NFT_TEST_VALGRIND_VGDB_PREFIX" ] ; then
+               rm -rf "$_NFT_TEST_VALGRIND_VGDB_PREFIX"* &>/dev/null
+       fi
 }
 
 trap 'exit 130' SIGINT
 trap 'exit 143' SIGTERM
 trap 'rc=$?; cleanup_on_exit; exit $rc' EXIT
 
-NFT_TEST_TMPDIR="$(mktemp --tmpdir="$_TMPDIR" -d "nft-test.$(date '+%Y%m%d-%H%M%S.%3N').XXXXXX")" ||
+TIMESTAMP=$(date '+%Y%m%d-%H%M%S.%3N')
+NFT_TEST_TMPDIR="$(mktemp --tmpdir="$_TMPDIR" -d "nft-test.$TIMESTAMP.XXXXXX")" ||
        msg_error "Failure to create temp directory in \"$_TMPDIR\""
 chmod 755 "$NFT_TEST_TMPDIR"
 
@@ -493,6 +499,8 @@ msg_info "info: NFT_TEST_TMPDIR=$(printf '%q' "$NFT_TEST_TMPDIR")"
 if [ "$VALGRIND" == "y" ]; then
        NFT="$NFT_TEST_BASEDIR/helpers/nft-valgrind-wrapper.sh"
        msg_info "info: NFT=$(printf '%q' "$NFT")"
+       _NFT_TEST_VALGRIND_VGDB_PREFIX="$NFT_TEST_TMPDIR_ORIG/vgdb-pipe-nft-test-$TIMESTAMP.$$.$RANDOM"
+       export _NFT_TEST_VALGRIND_VGDB_PREFIX
 fi
 
 kernel_cleanup() {