Skip to contentSkip to conversation

tst_test: Allow priting TINFO without initialized IPC

PATCH New Cyril Hrubis 2 participants 9 messages Feb 8, 2017 – Feb 13, 2017 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 tst_test: Allow priting TINFO without initialized IPC

If we try to print TINFO messages while the shared memory to store results is not initialized we stop the test execution with TBROK.

But we do not store anything on TINFO hence it does not make much sense to exit at this point.

The motivation for this change is that test library code that prints messages with TINFO (tst_device.c for instance) cannot be used without doing full test initialization, which is unfortunate since I wanted to reuse the code to create a helper binary for shell testcases.

---
 lib/tst_test.c | 3 +++
 1 file changed, 3 insertions(+)
lib/tst_test.c +3 -0
index e78b412..b8d10ee 100644
@@ -146,6 +146,9 @@ void tst_reinit(void)
 
 static void update_results(const char *file, unsigned int lineno, int ttype)
 {
+	if (ttype == TINFO)
+		return;
+
 	if (!results) {
 		tst_brk(TBROK,
 		        "%s: %d: Results IPC not initialized!", file, lineno);
Signature · 1 line
2.10.2
#1 lore raw

PATCH 2/6 tst_device: Split the tst_acquire_device code again

This splits the tst_acquire_device code into two parts so that the function with two underscores returns exit value rather than calling tst_brkm() with a cleanup pointer.

Once this is done we can reuse the code in shell helper binary so that we have all the device related code in a single place.

---
 include/old/old_device.h |   4 +-
 lib/tst_device.c         | 121 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 88 insertions(+), 37 deletions(-)
include/old/old_device.h +3 -1
index aabc617..4dbb3ff 100644
@@ -44,6 +44,8 @@ const char *tst_dev_fs_type(void);
  */
 const char *tst_acquire_device_(void (cleanup_fn)(void), unsigned int size);
 
+const char *tst_acquire_device__(unsigned int size);
+
 static inline const char *tst_acquire_device(void (cleanup_fn)(void))
 {
 	return tst_acquire_device_(cleanup_fn, 0);
@@ -52,7 +54,7 @@ static inline const char *tst_acquire_device(void (cleanup_fn)(void))
 /*
  * @dev: device path returned by the tst_acquire_device()
  */
-void tst_release_device(const char *dev);
+int tst_release_device(const char *dev);
 
 /*
  * Just like umount() but retries several times on failure.
lib/tst_device.c +85 -36

211 lines not on this page · raw message

Signature · 1 line
2.10.2
#2 lore raw

PATCH 3/6 lib: Add new tst_device for shell

In reply to Cyril Hrubis

The motivation is to have a single place where we handle device creation/deletion.

---
 testcases/lib/.gitignore   |   1 +
 testcases/lib/Makefile     |   3 +-
 testcases/lib/tst_device.c | 106 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 testcases/lib/tst_device.c
testcases/lib/.gitignore +1 -0
index 77acb57..920817c 100644
@@ -3,3 +3,4 @@ tst_random
 tst_checkpoint
 tst_rod
 tst_kvcmp
+tst_device
testcases/lib/Makefile +2 -1
index 0bb0bce..6282578 100644
@@ -26,6 +26,7 @@ include $(top_srcdir)/include/mk/testcases.mk
 
 INSTALL_TARGETS		:= *.sh
 
-MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp
+MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
+			   tst_device
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/lib/tst_device.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
2.10.2
#3 lore raw

PATCH 4/6 test.sh: Remove tst_{acquire, release}_device, tst_mkfs

In reply to Cyril Hrubis

There are not used by any test that uses test.sh library.

---
 testcases/lib/test.sh | 72 ---------------------------------------------------
 1 file changed, 72 deletions(-)
testcases/lib/test.sh +0 -72
index 48172d3..71dd611 100644
@@ -288,78 +288,6 @@ EXPECT_FAIL()
 	fi
 }
 
-tst_acquire_device()
-{
-	local acq_dev_size=${1:-150}
-
-	if [ -z ${TST_TMPDIR} ]; then
-		tst_brkm "Use 'tst_tmpdir' before 'tst_acquire_device'"
-	fi
-
-	ltp_dev_size=$((`blockdev --getsize64 $LTP_DEV`/1024/1024))
-
-	if [ -n "${LTP_DEV}" ] && [ ${acq_dev_size} -le ${ltp_dev_size} ]; then
-		tst_resm TINFO "Using test device LTP_DEV='${LTP_DEV}'"
-		if [ ! -b ${LTP_DEV} ]; then
-			tst_brkm TBROK "${LTP_DEV} is not a block device"
-		fi
-
-		ROD_SILENT dd if=/dev/zero of="${LTP_DEV}" bs=1024 count=512
-
-		TST_DEVICE=${LTP_DEV}
-		TST_DEVICE_FLAG=0
-		return
-	fi
-
-	ROD_SILENT dd if=/dev/zero of=test_dev.img bs=1024 count=$((1024*$acq_dev_size))
-
-	TST_DEVICE=$(losetup -f)
-	if [ $? -ne 0 ]; then
-		tst_brkm TBROK "Couldn't find free loop device"
-	fi
-
-	tst_resm TINFO "Found free device '${TST_DEVICE}'"
-
-	ROD_SILENT losetup ${TST_DEVICE} test_dev.img
-
-	TST_DEVICE_FLAG=1
-}
-
-tst_release_device()
-{
-	if [ ${TST_DEVICE_FLAG} -eq 0 ]; then
-		return
-	fi
-
-	losetup -a | grep -q ${TST_DEVICE}
-	if [ $? -eq 0 ]; then
-		losetup -d ${TST_DEVICE}
-		if [ $? -ne 0 ];then
-			tst_resm TWARN "'losetup -d ${TST_DEVICE}' failed"
-		fi
-	fi
-}
-
-tst_mkfs()
-{
-	local fs_type=$1
-	local device=$2
-	shift 2
-	local fs_opts="$@"
-
-	if [ -z "$fs_type" ]; then
-		tst_brkm TBROK "No fs_type specified"
-	fi
-
-	if [ -z "$device" ]; then
-		tst_brkm TBROK "No device specified"
-	fi
-
-	tst_resm TINFO "Formatting $device with $fs_type extra opts='$fs_opts'"
-
-	ROD_SILENT mkfs.$fs_type $fs_opts $device
-}
-
 tst_umount()
 {
 	local device="$1"
Signature · 1 line
2.10.2
#4 lore raw

PATCH 4/6 test.sh: Remove tst_{acquire, release}_device, tst_mkfs

----- Original Message -----

Quoted 6 lines

From: "Cyril Hrubis" <[email protected]>
To: [email protected]
Sent: Wednesday, 8 February, 2017 12:02:53 PM
Subject: [LTP] [PATCH 4/6] test.sh: Remove tst_{acquire, release}_device, tst_mkfs

There are not used by any test that uses test.sh library.

Not even this one? ./testcases/kernel/fs/fs_readonly/test_robind.sh It sources test.sh and calls tst_mkfs.

Other than that, I think we agreed to drop/replace 1/6, and skip update_results() if ipc has not been set up.

The rest looks good to me.

Regards,
Jan

Quoted 6 lines
---
 testcases/lib/test.sh | 72
 ---------------------------------------------------
 1 file changed, 72 deletions(-)
#5 lore raw

PATCH 4/6 test.sh: Remove tst_{acquire, release}_device, tst_mkfs

Hi!

Quoted 4 lines
Quoted 1 line

There are not used by any test that uses test.sh library.

Not even this one? ./testcases/kernel/fs/fs_readonly/test_robind.sh It sources test.sh and calls tst_mkfs.

Ah, missed that one. So tst_mkfs() has to stay in test.sh.

Quoted 2 lines

Other than that, I think we agreed to drop/replace 1/6, and skip update_results() if ipc has not been set up.

I have that change in my my tree already.

Quoted 1 line

The rest looks good to me.

Ok.

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH 4/6 test.sh: Remove tst_{acquire, release}_device, tst_mkfs

In reply to Jan Stancek

Hi!

Quoted 4 lines
Quoted 1 line

There are not used by any test that uses test.sh library.

Not even this one? ./testcases/kernel/fs/fs_readonly/test_robind.sh It sources test.sh and calls tst_mkfs.

I've readded the tst_mkfs() to that patch but forget to update the commit message, sorry. (that is what you get for pushing patches at the end of the day)

Anyway, the patchset is pushed, I will continue to work on the safe macros in cleanup tomorrow.

Signature · 2 lines
Cyril Hrubis
[email protected]
#7 lore raw

PATCH 5/6 tst_test.sh: Make use of tst_device helper

In reply to Cyril Hrubis
---
 testcases/lib/tst_test.sh | 31 +++++--------------------------
 1 file changed, 5 insertions(+), 26 deletions(-)
testcases/lib/tst_test.sh +5 -26
index b9ac938..087adda 100644
@@ -41,12 +41,8 @@ tst_do_exit()
 	fi
 
 	if [ "$TST_NEEDS_DEVICE" = 1 -a "$TST_DEVICE_FLAG" = 1 ]; then
-		losetup -a | grep -q "$TST_DEVICE"
-		if [ $? -eq 0 ]; then
-			losetup -d "$TST_DEVICE"
-			if [ $? -ne 0 ]; then
-				tst_res TWARN "'losetup -d $TST_DEVICE' failed"
-			fi
+		if ! tst_device release "$TST_DEVICE"; then
+			tst_res TWARN "Failed to release device '$TST_DEVICE'"
 		fi
 	fi
 
@@ -309,29 +305,12 @@ tst_run()
 			tst_brk "Use TST_NEEDS_TMPDIR must be set for TST_NEEDS_DEVICE"
 		fi
 
-		if [ -n "${LTP_DEV}" ]; then
-			tst_res TINFO "Using test device LTP_DEV='${LTP_DEV}'"
-			if [ ! -b ${LTP_DEV} ]; then
-				tst_brkm TBROK "${LTP_DEV} is not a block device"
-			fi
-
-			ROD_SILENT dd if=/dev/zero of="${LTP_DEV}" bs=1024 count=512
-
-			TST_DEVICE=${LTP_DEV}
-			TST_DEVICE_FLAG=0
-			return
-		fi
-
-		ROD_SILENT dd if=/dev/zero of=test_dev.img bs=1024 count=153600
+		TST_DEVICE=$(tst_device acquire)
 
-		TST_DEVICE=$(losetup -f)
-		if [ $? -ne 0 ]; then
-			tst_brk TBROK "Couldn't find free loop device"
+		if [ -z "$TST_DEVICE" ]; then
+			tst_brk "Failed to acquire device"
 		fi
 
-		tst_res TINFO "Found free device '${TST_DEVICE}'"
-
-		ROD_SILENT losetup ${TST_DEVICE} test_dev.img
 		TST_DEVICE_FLAG=1
 	fi
 
Signature · 1 line
2.10.2
#8 lore raw

PATCH 6/6 runltp, tst_device: Bump minimal device size to 256MB

In reply to Cyril Hrubis
---
 lib/tst_device.c | 3 ++-
 runltp           | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
lib/tst_device.c +2 -1
index 24e8c6f..4cefd60 100644
@@ -41,6 +41,7 @@
 #define LOOP_CONTROL_FILE "/dev/loop-control"
 
 #define DEV_FILE "test_dev.img"
+#define DEV_SIZE_MB 256
 
 static char dev_path[1024];
 static int device_acquired;
@@ -204,7 +205,7 @@ const char *tst_acquire_device__(unsigned int size)
 	unsigned int acq_dev_size;
 	uint64_t ltp_dev_size;
 
-	acq_dev_size = size > 150 ? size : 150;
+	acq_dev_size = size > DEV_SIZE_MB ? size : DEV_SIZE_MB;
 
 	dev = getenv("LTP_DEV");
 
runltp +1 -1
index f347f55..f081805 100755
@@ -986,7 +986,7 @@ main()
 create_block()
 {
     #create a block device
-    dd if=/dev/zero of=${TMP}/test.img bs=1024 count=153600 >/dev/null 2>&1
+    dd if=/dev/zero of=${TMP}/test.img bs=1024 count=262144 >/dev/null 2>&1
     if [ $? -ne 0 ]; then
         echo "Failed to create loopback device image, please check disk space and re-run"
         return 1
Signature · 1 line
2.10.2