From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Gibson To: passt-dev@passt.top Subject: [PATCH v2 25/32] test: Create common state directories for temporary files Date: Thu, 08 Sep 2022 16:16:14 +1000 Message-ID: <20220908061621.2430844-26-david@gibson.dropbear.id.au> In-Reply-To: <20220908061621.2430844-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4241328413076681305==" --===============4241328413076681305== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The test scripts create a bunch of temporary files to keep track of internal state. Some are made in /tmp with individual mktemp calls, some go in the passt source directory, and some go in $LOGDIR. This can sometimes make it messy to clean up after failed test runs. Start cleaning this up by creating a single "state" directory ($STATEBASE) in /tmp for all the state or temporary files used by a single test run. Clean it up automatically in cleanup() - except when DEBUG=3D=3D1, because those files can be useful for debugging test script failures. We create subdirectories under $STATEBASE for each setup function, exposed as $STATESETUP. We also create subdirectories for each test script and expose those to the scripts as __STATEDIR__. Signed-off-by: David Gibson --- test/lib/setup | 2 ++ test/lib/term | 2 +- test/lib/test | 4 ++++ test/run | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/test/lib/setup b/test/lib/setup index 957a9cc..b0420fb 100755 --- a/test/lib/setup +++ b/test/lib/setup @@ -394,6 +394,8 @@ teardown_demo_podman() { # $*: Suffix list of setup_*() functions to be called setup() { for arg do + STATESETUP=3D"${STATEBASE}/${arg}" + mkdir -p "${STATESETUP}" eval setup_${arg} done } diff --git a/test/lib/term b/test/lib/term index ae99010..b2a45e4 100755 --- a/test/lib/term +++ b/test/lib/term @@ -639,7 +639,7 @@ pause_continue() { =20 # run_term() - Start tmux session, running entry point, with recording if ne= eded run_term() { - TMUX=3D"tmux new-session -s passt_test -ePCAP=3D$PCAP -eDEBUG=3D$DEBUG" + TMUX=3D"tmux new-session -s passt_test -eSTATEBASE=3D$STATEBASE -ePCAP=3D$P= CAP -eDEBUG=3D$DEBUG" =20 if [ ${CI} -eq 1 ]; then printf '\e[8;50;240t' diff --git a/test/lib/test b/test/lib/test index 0d06afd..3dbae0b 100755 --- a/test/lib/test +++ b/test/lib/test @@ -351,6 +351,10 @@ test_one() { [ ${CI} -eq 1 ] && video_link "${1}" =20 TEST_ONE_subs=3D"$(list_add_pair "" "__BASEPATH__" "${BASEPATH}")" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__STATESETUP__" "${STA= TESETUP}")" + STATEDIR=3D"${STATEBASE}/${1}" + mkdir -p "${STATEDIR}" + TEST_ONE_subs=3D"$(list_add_pair "${TEST_ONE_subs}" "__STATEDIR__" "${STATE= DIR}")" TEST_ONE_nok=3D-1 TEST_ONE_perf_nok=3D0 TEST_ONE_skip=3D0 diff --git a/test/run b/test/run index 9b0227b..58d9b49 100755 --- a/test/run +++ b/test/run @@ -48,6 +48,7 @@ COMMIT=3D"$(git log --oneline --no-decorate -1)" =20 # cleanup() - Remove temporary files cleanup() { + [ ${DEBUG} -eq 1 ] || rm -rf "${STATEBASE}" rm -f /tmp/.passt_test_log_pipe } =20 @@ -176,6 +177,7 @@ else rm -rf "${LOGDIR}" mkdir -p "${LOGDIR}" :> "${LOGFILE}" + STATEBASE=3D"$(mktemp -d --tmpdir passt-tests-XXXXXX)" trap "cleanup" EXIT run_term fi --=20 2.37.3 --===============4241328413076681305==--