Create and use a temporary directory for the files created during test runs. If TMPDIR environment variable is set use it as a base for the temporary directory path. TMPDIR=/mnt/scratch make run_tests and TMPDIR=/mnt/scratch ./test_generic_01.sh will place test directory under /mnt/scratch
Signed-off-by: Alexander Atanasov <[email protected]> --- tools/testing/selftests/ublk/test_common.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh index 7ff6ce79d62c..46983ccf5c1a 100755 --- a/tools/testing/selftests/ublk/test_common.sh +++ b/tools/testing/selftests/ublk/test_common.sh @@ -43,7 +43,7 @@ _create_backfile() { old_file="${UBLK_BACKFILES[$index]}" [ -f "$old_file" ] && rm -f "$old_file" - new_file=$(mktemp ublk_file_"${new_size}"_XXXXX) + new_file=$(mktemp ${UBLK_TEST_DIR}/ublk_file_"${new_size}"_XXXXX) truncate -s "${new_size}" "${new_file}" UBLK_BACKFILES["$index"]="$new_file" } @@ -60,7 +60,7 @@ _remove_files() { _create_tmp_dir() { local my_file; - my_file=$(mktemp -d ublk_dir_XXXXX) + my_file=$(mktemp -d ${UBLK_TEST_DIR}/ublk_dir_XXXXX) echo "$my_file" } @@ -119,7 +119,9 @@ _prep_test() { local type=$1 shift 1 modprobe ublk_drv > /dev/null 2>&1 - UBLK_TMP=$(mktemp ublk_test_XXXXX) + TDIR=$(mktemp -d ${TMPDIR:-.}/ublktest-dir.XXXXXX) + export UBLK_TEST_DIR=${TDIR} + UBLK_TMP=$(mktemp ${UBLK_TEST_DIR}/ublk_test_XXXXX) [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "ublk $type: $*" } @@ -165,6 +167,7 @@ _cleanup_test() { "${UBLK_PROG}" del -a _remove_files + rmdir ${UBLK_TEST_DIR} } _have_feature() @@ -398,6 +401,8 @@ UBLK_PROG=$(_ublk_test_top_dir)/kublk UBLK_TEST_QUIET=1 UBLK_TEST_SHOW_RESULT=1 UBLK_BACKFILES=() +UBLK_TEST_DIR=${TMPDIR:-.} export UBLK_PROG export UBLK_TEST_QUIET export UBLK_TEST_SHOW_RESULT +export UBLK_TEST_DIR base-commit: f46ebb910989a1db244f95bd1f937907591aa2ee -- 2.43.0
