[LTP] [PATCH 1/1] tst_test.sh: Create (again) loop device in $TST_TMPDIR

Petr Vorel pvorel@suse.cz
Mon Oct 10 10:59:44 CEST 2022


Before 1f6bd6e66 loop device for testing test_dev.img was created in
shell API after cd to $TST_TMPDIR, therefore automatically removed
during the cleanup in _tst_do_exit(). This got broken in 1f6bd6e66,
fix it.

Although it'd be good not relying on this order (full path could be kept
and then pass to rm), it's better to have all LTP temporary files under
$TST_TMPDIR, thus just restore the order.

Fixes: 1f6bd6e66 ("tst_test.sh: Add $TST_ALL_FILESYSTEMS")

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi,

I'm sorry for introducing yet another regression in
$TST_ALL_FILESYSTEMS.

Kind regards,
Petr

 testcases/lib/tst_test.sh | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 033491b08..5af345938 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -716,6 +716,20 @@ tst_run()
 	[ "$TST_FORMAT_DEVICE" = 1 -o "$TST_ALL_FILESYSTEMS" = 1 ] && TST_NEEDS_DEVICE=1
 	[ "$TST_NEEDS_DEVICE" = 1 ] && TST_NEEDS_TMPDIR=1
 
+	if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
+		if [ -z "$TMPDIR" ]; then
+			export TMPDIR="/tmp"
+		fi
+
+		TST_TMPDIR=$(mktemp -d "$TMPDIR/LTP_$TST_ID.XXXXXXXXXX")
+
+		chmod 777 "$TST_TMPDIR"
+
+		TST_STARTWD=$(pwd)
+		cd "$TST_TMPDIR"
+	fi
+
+	# needs to be after cd $TST_TMPDIR to keep test_dev.img under $TST_TMPDIR
 	if [ "$TST_NEEDS_DEVICE" = 1 ]; then
 		TST_DEVICE=$(tst_device acquire)
 
@@ -730,19 +744,6 @@ tst_run()
 		fi
 	fi
 
-	if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
-		if [ -z "$TMPDIR" ]; then
-			export TMPDIR="/tmp"
-		fi
-
-		TST_TMPDIR=$(mktemp -d "$TMPDIR/LTP_$TST_ID.XXXXXXXXXX")
-
-		chmod 777 "$TST_TMPDIR"
-
-		TST_STARTWD=$(pwd)
-		cd "$TST_TMPDIR"
-	fi
-
 	if [ "$TST_ALL_FILESYSTEMS" != 1 -a "$TST_SKIP_FILESYSTEMS" ]; then
 		if ! tst_supported_fs -s "$TST_SKIP_FILESYSTEMS" -d . > /dev/null; then
 			tst_brk TCONF "filesystem is not supported by the test"
-- 
2.37.3



More information about the ltp mailing list