Skip to contentSkip to conversation

test.sh: make the loop device size can be customized

PATCH Superseded Li Wang 2 participants 3 messages Jul 28, 2016 – Aug 16, 2016

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v2 2/2 test.sh: make the loop device size can be customized

The LTP_DEV default size is 150MB, but sometimes we need different (larger or smaller) size of test block device.

For the purpose of satisfying specific requirements, here adding parameters to tst_acquire_device() to make the loop device can be customized according to real needed.

---
 testcases/lib/test.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
testcases/lib/test.sh +4 -2
index 4fe2773..835ea39 100644
@@ -257,11 +257,13 @@ ROD()
 
 tst_acquire_device()
 {
+	local acq_dev_size=${1:-150}
+
 	if [ -z ${TST_TMPDIR} ]; then
 		tst_brkm "Use 'tst_tmpdir' before 'tst_acquire_device'"
 	fi
 
-	if [ -n "${LTP_DEV}" ]; then
+	if [ -n "${LTP_DEV}" ] && [ ${acq_dev_size} -eq 150 ]; 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"
@@ -274,7 +276,7 @@ tst_acquire_device()
 		return
 	fi
 
-	ROD_SILENT dd if=/dev/zero of=test_dev.img bs=1024 count=153600
+	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
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v2 2/2 test.sh: make the loop device size can be customized

Hi!

testcases/lib/test.sh ROD() · line 266

Quoted 10 lines

tst_acquire_device()
{

testcases/lib/test.sh +3 -1
+	local acq_dev_size=${1:-150}
+
 	if [ -z ${TST_TMPDIR} ]; then
 		tst_brkm "Use 'tst_tmpdir' before 'tst_acquire_device'"
 	fi
 
-	if [ -n "${LTP_DEV}" ]; then
+	if [ -n "${LTP_DEV}" ] && [ ${acq_dev_size} -eq 150 ]; then

This is, unfortunately, not as simple as this either.

The $LTP_DEV could be passed to runltp as a command line parameter and could point to a real block device backed up by a disk. So there is no guarantee that it will be 150MB in size.

What we have to do is to get the size of whatever is in $LTP_DEV here and return it if it has at least the requested size.

Quoted 12 lines
testcases/lib/test.sh +1 -1
 		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"
@@ -274,7 +276,7 @@ tst_acquire_device()
 		return
 	fi
 
-	ROD_SILENT dd if=/dev/zero of=test_dev.img bs=1024 count=153600
+	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
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH v2 2/2 test.sh: make the loop device size can be customized

Quoted 9 lines · Cyril Hrubis

Hi!

Quoted 8 lines

tst_acquire_device()
{

(quoted diff) +2 -0
+	local acq_dev_size=${1:-150}
+
 	if [ -z ${TST_TMPDIR} ]; then
 		tst_brkm "Use 'tst_tmpdir' before 'tst_acquire_device'"
 	fi
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-	if [ -n "${LTP_DEV}" ]; then
+	if [ -n "${LTP_DEV}" ] && [ ${acq_dev_size} -eq 150 ]; then

This is, unfortunately, not as simple as this either.

The $LTP_DEV could be passed to runltp as a command line parameter and could point to a real block device backed up by a disk. So there is no guarantee that it will be 150MB in size.

Thanks for reminding me, I didn't think of that.

Quoted 3 lines

What we have to do is to get the size of whatever is in $LTP_DEV here and return it if it has at least the requested size.

Good proposal.

How about make the patch like:

testcases/lib/test.sh +6 -2
index bd66109..60f8836 100644
@@ -258,11 +258,15 @@ ROD()
 
 tst_acquire_device()
 {
+       local acq_dev_size=${1:-150}
+
        if [ -z ${TST_TMPDIR} ]; then
                tst_brkm "Use 'tst_tmpdir' before 'tst_acquire_device'"
        fi
 
-       if [ -n "${LTP_DEV}" ]; then
+       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"
@@ -275,7 +279,7 @@ tst_acquire_device()
                return
        fi
 
-       ROD_SILENT dd if=/dev/zero of=test_dev.img bs=1024 count=153600
+       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

Regards,
Li Wang