All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3 1/2] test.sh: make the loop device size can be increased
@ 2016-08-18 13:09 Li Wang
  2016-08-22 17:18 ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Li Wang @ 2016-08-18 13:09 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/lib/test.sh | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index bd66109..60f8836 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -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
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v3 1/2] test.sh: make the loop device size can be increased
  2016-08-18 13:09 [LTP] [PATCH v3 1/2] test.sh: make the loop device size can be increased Li Wang
@ 2016-08-22 17:18 ` Cyril Hrubis
  2016-08-23 11:03   ` Li Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2016-08-22 17:18 UTC (permalink / raw)
  To: ltp

Hi!
This one looks fine.

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

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v3 1/2] test.sh: make the loop device size can be increased
  2016-08-22 17:18 ` Cyril Hrubis
@ 2016-08-23 11:03   ` Li Wang
  2016-08-30 13:34     ` Cyril Hrubis
  0 siblings, 1 reply; 5+ messages in thread
From: Li Wang @ 2016-08-23 11:03 UTC (permalink / raw)
  To: ltp

On Tue, Aug 23, 2016 at 1:18 AM, Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
> This one looks fine.
>
> We should also update the test-writing-guidelines in this patch since

ok, I ll do that.

> 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;
}


-- 
Regards,
Li Wang
Email: liwang@redhat.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v3 1/2] test.sh: make the loop device size can be increased
  2016-08-23 11:03   ` Li Wang
@ 2016-08-30 13:34     ` Cyril Hrubis
  2016-08-31  9:12       ` Li Wang
  0 siblings, 1 reply; 5+ messages in thread
From: Cyril Hrubis @ 2016-08-30 13:34 UTC (permalink / raw)
  To: ltp

Hi!
> 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.

> 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.

>     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;
>         }

	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.

>     }
> 
>     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;
> }

Otherwise this looks fine.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v3 1/2] test.sh: make the loop device size can be increased
  2016-08-30 13:34     ` Cyril Hrubis
@ 2016-08-31  9:12       ` Li Wang
  0 siblings, 0 replies; 5+ messages in thread
From: Li Wang @ 2016-08-31  9:12 UTC (permalink / raw)
  To: ltp

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

On Tue, Aug 30, 2016 at 9:34 PM, Cyril Hrubis <chrubis@suse.cz> wrote:
> Hi!
>> 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.
>
>> 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.
>
>>     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

>>
>>         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.
>
>>     }
>>
>>     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;
>> }
>
> Otherwise this looks fine.

Thanks, Patch V4 is coming.



-- 
Regards,
Li Wang
Email: liwang@redhat.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-08-31  9:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-18 13:09 [LTP] [PATCH v3 1/2] test.sh: make the loop device size can be increased Li Wang
2016-08-22 17:18 ` Cyril Hrubis
2016-08-23 11:03   ` Li Wang
2016-08-30 13:34     ` Cyril Hrubis
2016-08-31  9:12       ` Li Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.