Skip to contentSkip to conversation

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

PATCH Superseded Li Wang 2 participants 5 messages Aug 18, 2016 – Aug 31, 2016

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v3 1/2 test.sh: make the loop device size can be increased

For the purpose of satisfying specific requirements, here adding parameters to tst_acquire_device() to make the test device can be increased according to real need.

---
 testcases/lib/test.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
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
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v3 1/2 test.sh: make the loop device size can be increased

Hi!
This one looks fine.

We should also update the test-writing-guidelines in this patch since the shell version has optional parameter now.

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

PATCH v3 1/2 test.sh: make the loop device size can be increased

Quoted 4 lines · Cyril Hrubis

Hi!
This one looks fine.

We should also update the test-writing-guidelines in this patch since

ok, I ll do that.

Quoted 1 line

the shell version has optional parameter now.

I'm now hesitating whether we should keep tst_device.c as same as the shell? although we don't need it for a while.

Which something like:

const char *tst_acquire_device(void (cleanup_fn)(void), int size)

{
    int acq_dev_size;
    long long ltp_dev_size;
    char *dev;
    struct stat st;

    if (size > 0)
        acq_dev_size = size;
    else
        acq_dev_size = 150;

    if (device_acquired)
        tst_brkm(TBROK, cleanup_fn, "Device allready acquired");

    if (!tst_tmpdir_created()) {
        tst_brkm(TBROK, cleanup_fn,
                 "Cannot acquire device without tmpdir() created");
    }

    dev = getenv("LTP_DEV");

    if (dev) {
        tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev);

        SAFE_STAT(cleanup_fn, dev, &st);

        if (!S_ISBLK(st.st_mode)) {
            tst_brkm(TBROK, cleanup_fn,
                    "%s is not a block device", dev);
        }

        ltp_dev_size = (int)st.st_size/1024/1024;

        if (acq_dev_size <= ltp_dev_size) {
            if (tst_fill_file(dev, 0, 1024, 512)) {
                tst_brkm(TBROK | TERRNO, cleanup_fn,
                    "Failed to clear the first 512k of %s", dev);
            }

            return dev;
        }
    }

    if (tst_fill_file(DEV_FILE, 0, 1024, 1024 * acq_dev_size)) {
        tst_brkm(TBROK | TERRNO, cleanup_fn,
                 "Failed to create " DEV_FILE);

    }

    if (find_free_loopdev())
        return NULL;

    attach_device(cleanup_fn, dev_path, DEV_FILE);

    device_acquired = 1;

    return dev_path;
}
Signature · 3 lines
Regards,
Li Wang
Email: [email protected]
#3 lore raw

PATCH v3 1/2 test.sh: make the loop device size can be increased

Hi!

Quoted 2 lines

I'm now hesitating whether we should keep tst_device.c as same as the shell? although we don't need it for a while.

I do not care that much either way.

Quoted 13 lines

Which something like:

const char *tst_acquire_device(void (cleanup_fn)(void), int size)

{
    int acq_dev_size;
    long long ltp_dev_size;
    char *dev;
    struct stat st;

    if (size > 0)
        acq_dev_size = size;
    else
        acq_dev_size = 150;

size = size > 0 ? size : 150;

is a bit shorter.

Quoted 22 lines
    if (device_acquired)
        tst_brkm(TBROK, cleanup_fn, "Device allready acquired");

    if (!tst_tmpdir_created()) {
        tst_brkm(TBROK, cleanup_fn,
                 "Cannot acquire device without tmpdir() created");
    }

    dev = getenv("LTP_DEV");

    if (dev) {
        tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev);

        SAFE_STAT(cleanup_fn, dev, &st);

        if (!S_ISBLK(st.st_mode)) {
            tst_brkm(TBROK, cleanup_fn,
                    "%s is not a block device", dev);
        }

        ltp_dev_size = (int)st.st_size/1024/1024;
Quoted 8 lines
        if (acq_dev_size <= ltp_dev_size) {
            if (tst_fill_file(dev, 0, 1024, 512)) {
                tst_brkm(TBROK | TERRNO, cleanup_fn,
                    "Failed to clear the first 512k of %s", dev);
            }

            return dev;
        }

We should print here that the LTP_DEV was skipped because it was too small. Something as:

tst_resm(TINFO, "Skipping $LTP_DEV size %dMB, requested size %dMB",
ltp_dev_size, size);

Otherwise it would look like the $LTP_DEV was used from the test log.

Quoted 9 lines
    }

    if (tst_fill_file(DEV_FILE, 0, 1024, 1024 * acq_dev_size)) {
        tst_brkm(TBROK | TERRNO, cleanup_fn,
                 "Failed to create " DEV_FILE);

    }

    if (find_free_loopdev())
Quoted 8 lines
        return NULL;

    attach_device(cleanup_fn, dev_path, DEV_FILE);

    device_acquired = 1;

    return dev_path;
}

Otherwise this looks fine.

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

PATCH v3 1/2 test.sh: make the loop device size can be increased

Thanks for your opinion. From myself testing, a little problem was found in this patch.

Quoted 15 lines · Cyril Hrubis

Hi!

Quoted 2 lines

I'm now hesitating whether we should keep tst_device.c as same as the shell? although we don't need it for a while.

I do not care that much either way.

Quoted 9 lines

Which something like:

const char *tst_acquire_device(void (cleanup_fn)(void), int size)

{
    int acq_dev_size;
    long long ltp_dev_size;
    char *dev;
    struct stat st;
Quoted 30 lines
Quoted 4 lines
    if (size > 0)
        acq_dev_size = size;
    else
        acq_dev_size = 150;

size = size > 0 ? size : 150;

is a bit shorter.

Quoted 21 lines
    if (device_acquired)
        tst_brkm(TBROK, cleanup_fn, "Device allready acquired");

    if (!tst_tmpdir_created()) {
        tst_brkm(TBROK, cleanup_fn,
                 "Cannot acquire device without tmpdir() created");
    }

    dev = getenv("LTP_DEV");

    if (dev) {
        tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev);

        SAFE_STAT(cleanup_fn, dev, &st);

        if (!S_ISBLK(st.st_mode)) {
            tst_brkm(TBROK, cleanup_fn,
                    "%s is not a block device", dev);
        }

        ltp_dev_size = (int)st.st_size/1024/1024;

Seems like stat(); can not get the block device size correctly. I tried many times but always failed with "st.st_size = 0" here. So I have to use ioctl(); for replacement.

...

               fd = SAFE_OPEN(cleanup_fn, dev, O_RDONLY);
               SAFE_IOCTL(cleanup_fn, fd, BLKGETSIZE64, &ltp_dev_size);
               SAFE_CLOSE(cleanup_fn, fd);
               ltp_dev_size = ltp_dev_size/1024/1024;

...

See:
http://www.microhowto.info/howto/get_the_size_of_a_linux_block_special_device_in_c.html

Quoted 30 lines
Quoted 9 lines
        if (acq_dev_size <= ltp_dev_size) {
            if (tst_fill_file(dev, 0, 1024, 512)) {
                tst_brkm(TBROK | TERRNO, cleanup_fn,
                    "Failed to clear the first 512k of %s", dev);
            }

            return dev;
        }

We should print here that the LTP_DEV was skipped because it was too small. Something as:

tst_resm(TINFO, "Skipping $LTP_DEV size %dMB, requested size %dMB",
ltp_dev_size, size);

Otherwise it would look like the $LTP_DEV was used from the test log.

Quoted 11 lines
    }

    if (tst_fill_file(DEV_FILE, 0, 1024, 1024 * acq_dev_size)) {
        tst_brkm(TBROK | TERRNO, cleanup_fn,
                 "Failed to create " DEV_FILE);

    }

    if (find_free_loopdev())
        return NULL;
Quoted 8 lines
Quoted 6 lines
    attach_device(cleanup_fn, dev_path, DEV_FILE);

    device_acquired = 1;

    return dev_path;
}

Otherwise this looks fine.

Thanks, Patch V4 is coming.

Signature · 3 lines
Regards,
Li Wang
Email: [email protected]