public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Caleb Sander Mateos <csander@purestorage.com>,
	Uday Shankar <ushankar@purestorage.com>,
	Alexander Atanasov <alex@zazolabs.com>
Subject: Re: [PATCH V2 9/9] selftests: ublk: move test temp files into a sub directory
Date: Sat, 31 Jan 2026 10:43:58 +0800	[thread overview]
Message-ID: <aX1sbrLk-Vv-7rSh@fedora> (raw)
In-Reply-To: <20260129162001.3532311-10-ming.lei@redhat.com>

Hi Alexander,

On Fri, Jan 30, 2026 at 12:19:58AM +0800, Ming Lei wrote:
> From: Alexander Atanasov <alex@zazolabs.com>
> 
> 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 <alex@zazolabs.com>
> ---
>  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 dd4eff97610a..21ba51fcc7d7 100755
> --- a/tools/testing/selftests/ublk/test_common.sh
> +++ b/tools/testing/selftests/ublk/test_common.sh
> @@ -48,7 +48,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"
>  }
> @@ -65,7 +65,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"
>  }
>  
> @@ -124,7 +124,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: $*"
>  	echo "ublk selftest: $TID starting at $(date '+%F %T')" | tee /dev/kmsg
>  }
> @@ -171,6 +173,7 @@ _cleanup_test() {
>  	"${UBLK_PROG}" del -a
>  
>  	_remove_files
> +	rmdir ${UBLK_TEST_DIR}
>  	echo "ublk selftest: $TID done at $(date '+%F %T')" | tee /dev/kmsg
>  }
>  
> @@ -405,6 +408,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

I feel this patch can be simplified in the following way, what do you think
of the change?

diff --git a/tools/testing/selftests/ublk/test_common.sh b/tools/testing/selftests/ublk/test_common.sh
index 21ba51fcc7d7..1ee7a898e6bf 100755
--- a/tools/testing/selftests/ublk/test_common.sh
+++ b/tools/testing/selftests/ublk/test_common.sh
@@ -48,7 +48,7 @@ _create_backfile() {
        old_file="${UBLK_BACKFILES[$index]}"
        [ -f "$old_file" ] && rm -f "$old_file"
 
-       new_file=$(mktemp ${UBLK_TEST_DIR}/ublk_file_"${new_size}"_XXXXX)
+       new_file=$(mktemp ${TDIR}/ublk_file_"${new_size}"_XXXXX)
        truncate -s "${new_size}" "${new_file}"
        UBLK_BACKFILES["$index"]="$new_file"
 }
@@ -65,7 +65,7 @@ _remove_files() {
 _create_tmp_dir() {
        local my_file;
 
-       my_file=$(mktemp -d ${UBLK_TEST_DIR}/ublk_dir_XXXXX)
+       my_file=$(mktemp -d ${TDIR}/ublk_dir_XXXXX)
        echo "$my_file"
 }
 
@@ -125,8 +125,7 @@ _prep_test() {
        shift 1
        modprobe ublk_drv > /dev/null 2>&1
        TDIR=$(mktemp -d ${TMPDIR:-.}/ublktest-dir.XXXXXX)
-       export UBLK_TEST_DIR=${TDIR}
-       UBLK_TMP=$(mktemp ${UBLK_TEST_DIR}/ublk_test_XXXXX)
+       UBLK_TMP=$(mktemp ${TDIR}/ublk_test_XXXXX)
        [ "$UBLK_TEST_QUIET" -eq 0 ] && echo "ublk $type: $*"
        echo "ublk selftest: $TID starting at $(date '+%F %T')" | tee /dev/kmsg
 }
@@ -173,7 +172,7 @@ _cleanup_test() {
        "${UBLK_PROG}" del -a
 
        _remove_files
-       rmdir ${UBLK_TEST_DIR}
+       rmdir ${TDIR}
        echo "ublk selftest: $TID done at $(date '+%F %T')" | tee /dev/kmsg
 }
 
@@ -408,8 +407,6 @@ 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




Thanks,
Ming


  reply	other threads:[~2026-01-31  2:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29 16:19 [PATCH V2 0/9] ublk: misc improvement in driver and selftests Ming Lei
2026-01-29 16:19 ` [PATCH V2 1/9] ublk: check list membership before cancelling batch fetch command Ming Lei
2026-01-29 16:19 ` [PATCH V2 2/9] ublk: add UBLK_F_NO_AUTO_PART_SCAN feature flag Ming Lei
2026-01-29 16:19 ` [PATCH V2 3/9] selftests: ublk: derive TID automatically from script name Ming Lei
2026-01-29 16:19 ` [PATCH V2 4/9] selftests: ublk: add selftest for UBLK_F_NO_AUTO_PART_SCAN Ming Lei
2026-01-29 16:19 ` [PATCH V2 5/9] selftests: ublk: rename test_generic_15 to test_part_02 Ming Lei
2026-01-29 16:19 ` [PATCH V2 6/9] selftests: ublk: refactor test_null_04 into separate functions Ming Lei
2026-01-29 16:19 ` [PATCH V2 7/9] selftests: ublk: disable partition scan for integrity tests Ming Lei
2026-01-29 16:19 ` [PATCH V2 8/9] selftests: ublk: mark each test start and end time in dmesg Ming Lei
2026-01-29 16:19 ` [PATCH V2 9/9] selftests: ublk: move test temp files into a sub directory Ming Lei
2026-01-31  2:43   ` Ming Lei [this message]
2026-01-31 10:30     ` Alexander Atanasov
2026-01-31 13:49 ` [PATCH V2 0/9] ublk: misc improvement in driver and selftests Jens Axboe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aX1sbrLk-Vv-7rSh@fedora \
    --to=ming.lei@redhat.com \
    --cc=alex@zazolabs.com \
    --cc=axboe@kernel.dk \
    --cc=csander@purestorage.com \
    --cc=linux-block@vger.kernel.org \
    --cc=ushankar@purestorage.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox