diff mbox

[1/2] block: qemu-iotests - add basic ability to use binary sample images

Message ID 072dca92f6fa9125b3e8e34e07141cef06d4ff56.1379648036.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody Sept. 20, 2013, 3:48 a.m. UTC
For image formats that are not "QEMU native", but supported for
compatibility, it is useful to verify that an image created with
the 'gold standard' native tool can be read / written to successfully
by QEMU.

In addition to testing non-native images, this could also be useful to
test against image files created by older versions of QEMU.

This provides a directory to store small sample images, for use by
scripts in tests/qemu-iotests.

The MANIFEST file should be updated when a new image is added to the
directory, to give some idea about the nature of the image and the
data store therein.

Image files should be compressed with bzip2.

To use a sample image from a bash script, the _use_sample_img function
will copy and decompress the image into $TEST_DIR, and set $TEST_IMG to
be the decompressed sample image copy.  To cleanup, call
_cleanup_test_img as normal.

Signed-off-by: Jeff Cody <jcody@redhat.com>
---
 tests/qemu-iotests/common.config          | 11 +++++++++++
 tests/qemu-iotests/common.rc              |  9 +++++++++
 tests/qemu-iotests/sample_images/MANIFEST |  2 ++
 tests/qemu-iotests/sample_images/README   |  8 ++++++++
 4 files changed, 30 insertions(+)
 create mode 100644 tests/qemu-iotests/sample_images/MANIFEST
 create mode 100644 tests/qemu-iotests/sample_images/README

Comments

Stefan Hajnoczi Sept. 20, 2013, 12:32 p.m. UTC | #1
On Thu, Sep 19, 2013 at 11:48:42PM -0400, Jeff Cody wrote:
> For image formats that are not "QEMU native", but supported for
> compatibility, it is useful to verify that an image created with
> the 'gold standard' native tool can be read / written to successfully
> by QEMU.
> 
> In addition to testing non-native images, this could also be useful to
> test against image files created by older versions of QEMU.
> 
> This provides a directory to store small sample images, for use by
> scripts in tests/qemu-iotests.
> 
> The MANIFEST file should be updated when a new image is added to the
> directory, to give some idea about the nature of the image and the
> data store therein.

I'd drop the MANIFEST because metadata tends to get out-of-sync or is
ignored.  The MANIFEST file can cause patch conflicts.  Test code or the
commit message can describe the contents of the image so I don't see the
need to create another copy of this information.

> diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
> index 28b39e4..d52f344 100644
> --- a/tests/qemu-iotests/common.rc
> +++ b/tests/qemu-iotests/common.rc
> @@ -91,6 +91,14 @@ _set_default_imgopts()
>      fi
>  }
>  
> +_use_sample_img()
> +{
> +    cp $SAMPLE_IMG_DIR/"$1" $TEST_DIR
> +    bunzip2 $TEST_DIR/"$1"

bzcat?  It eliminates the temporary copy.

> @@ -158,6 +166,7 @@ _cleanup_test_img()
>              rm -f $TEST_DIR/t.$IMGFMT
>              rm -f $TEST_DIR/t.$IMGFMT.orig
>              rm -f $TEST_DIR/t.$IMGFMT.base
> +            rm -f $TEST_DIR/$SAMPLE_IMG_FILE

It seems that qemu-iotests doesn't care for paths with spaces.
Jeff Cody Sept. 20, 2013, 12:41 p.m. UTC | #2
On Fri, Sep 20, 2013 at 02:32:26PM +0200, Stefan Hajnoczi wrote:
> On Thu, Sep 19, 2013 at 11:48:42PM -0400, Jeff Cody wrote:
> > For image formats that are not "QEMU native", but supported for
> > compatibility, it is useful to verify that an image created with
> > the 'gold standard' native tool can be read / written to successfully
> > by QEMU.
> > 
> > In addition to testing non-native images, this could also be useful to
> > test against image files created by older versions of QEMU.
> > 
> > This provides a directory to store small sample images, for use by
> > scripts in tests/qemu-iotests.
> > 
> > The MANIFEST file should be updated when a new image is added to the
> > directory, to give some idea about the nature of the image and the
> > data store therein.
> 
> I'd drop the MANIFEST because metadata tends to get out-of-sync or is
> ignored.  The MANIFEST file can cause patch conflicts.  Test code or the
> commit message can describe the contents of the image so I don't see the
> need to create another copy of this information.
>

OK, good point.

> > diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
> > index 28b39e4..d52f344 100644
> > --- a/tests/qemu-iotests/common.rc
> > +++ b/tests/qemu-iotests/common.rc
> > @@ -91,6 +91,14 @@ _set_default_imgopts()
> >      fi
> >  }
> >  
> > +_use_sample_img()
> > +{
> > +    cp $SAMPLE_IMG_DIR/"$1" $TEST_DIR
> > +    bunzip2 $TEST_DIR/"$1"
> 
> bzcat?  It eliminates the temporary copy.
> 

Sure

> > @@ -158,6 +166,7 @@ _cleanup_test_img()
> >              rm -f $TEST_DIR/t.$IMGFMT
> >              rm -f $TEST_DIR/t.$IMGFMT.orig
> >              rm -f $TEST_DIR/t.$IMGFMT.base
> > +            rm -f $TEST_DIR/$SAMPLE_IMG_FILE
> 
> It seems that qemu-iotests doesn't care for paths with spaces.

For v2, I'll go through all the scripts (I think TEST_DIR is used in
some of the 0?? scripts as well) and make sure it is quoted (along
with SAMPLE_IMG_DIR).
Eric Blake Sept. 20, 2013, 12:46 p.m. UTC | #3
On 09/19/2013 09:48 PM, Jeff Cody wrote:
> For image formats that are not "QEMU native", but supported for
> compatibility, it is useful to verify that an image created with
> the 'gold standard' native tool can be read / written to successfully
> by QEMU.
> 
> In addition to testing non-native images, this could also be useful to
> test against image files created by older versions of QEMU.
> 
> This provides a directory to store small sample images, for use by
> scripts in tests/qemu-iotests.
> 
> The MANIFEST file should be updated when a new image is added to the
> directory, to give some idea about the nature of the image and the
> data store therein.
> 
> Image files should be compressed with bzip2.

Why bzip2?  xz beats bzip2 in both compression ratio and decompression
speed; or if you are worried about portability, gzip is present on more
machines.  bzip2 will probably be around for some time, but it is no
longer the compression engine of choice.
Jeff Cody Sept. 20, 2013, 1:23 p.m. UTC | #4
On Fri, Sep 20, 2013 at 06:46:56AM -0600, Eric Blake wrote:
> On 09/19/2013 09:48 PM, Jeff Cody wrote:
> > For image formats that are not "QEMU native", but supported for
> > compatibility, it is useful to verify that an image created with
> > the 'gold standard' native tool can be read / written to successfully
> > by QEMU.
> > 
> > In addition to testing non-native images, this could also be useful to
> > test against image files created by older versions of QEMU.
> > 
> > This provides a directory to store small sample images, for use by
> > scripts in tests/qemu-iotests.
> > 
> > The MANIFEST file should be updated when a new image is added to the
> > directory, to give some idea about the nature of the image and the
> > data store therein.
> > 
> > Image files should be compressed with bzip2.
> 
> Why bzip2?  xz beats bzip2 in both compression ratio and decompression
> speed; or if you are worried about portability, gzip is present on more
> machines.  bzip2 will probably be around for some time, but it is no
> longer the compression engine of choice.
> 

iotest-dynamic-1G.vhdx compressed with gzip, xv, and bzip2:

gzip:   102548 bytes
xv:      15892 bytes
bzip2:     874 bytes

I think bzip2 is particularly well suited for image files with
hyper-repetitive consecutive bytes due to its use of RLE.  I don't
know that all sample images will have data like that, but chances are
good many will - and even if they don't, bzip2 is not horrible
compared to xz even on normal data.

-Jeff
diff mbox

Patch

diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.config
index d794e62..d90a8bc 100644
--- a/tests/qemu-iotests/common.config
+++ b/tests/qemu-iotests/common.config
@@ -125,6 +125,17 @@  fi
 
 export TEST_DIR
 
+if [ -z "$SAMPLE_IMG_DIR" ]; then
+        SAMPLE_IMG_DIR=`pwd`/sample_images
+fi
+
+if [ ! -d "$SAMPLE_IMG_DIR" ]; then
+    echo "common.config: Error: \$SAMPLE_IMG_DIR ($SAMPLE_IMG_DIR) is not a directory"
+    exit 1
+fi
+
+export SAMPLE_IMG_DIR
+
 _readlink()
 {
     if [ $# -ne 1 ]; then
diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc
index 28b39e4..d52f344 100644
--- a/tests/qemu-iotests/common.rc
+++ b/tests/qemu-iotests/common.rc
@@ -91,6 +91,14 @@  _set_default_imgopts()
     fi
 }
 
+_use_sample_img()
+{
+    cp $SAMPLE_IMG_DIR/"$1" $TEST_DIR
+    bunzip2 $TEST_DIR/"$1"
+    SAMPLE_IMG_FILE="${1%\.bz2}"
+    TEST_IMG=$TEST_DIR/$SAMPLE_IMG_FILE
+}
+
 _make_test_img()
 {
     # extra qemu-img options can be added by tests
@@ -158,6 +166,7 @@  _cleanup_test_img()
             rm -f $TEST_DIR/t.$IMGFMT
             rm -f $TEST_DIR/t.$IMGFMT.orig
             rm -f $TEST_DIR/t.$IMGFMT.base
+            rm -f $TEST_DIR/$SAMPLE_IMG_FILE
             ;;
 
         rbd)
diff --git a/tests/qemu-iotests/sample_images/MANIFEST b/tests/qemu-iotests/sample_images/MANIFEST
new file mode 100644
index 0000000..7abf287
--- /dev/null
+++ b/tests/qemu-iotests/sample_images/MANIFEST
@@ -0,0 +1,2 @@ 
+   Image Filename           |                  Description
+------------------------------------------------------------------------------
diff --git a/tests/qemu-iotests/sample_images/README b/tests/qemu-iotests/sample_images/README
new file mode 100644
index 0000000..9321b00
--- /dev/null
+++ b/tests/qemu-iotests/sample_images/README
@@ -0,0 +1,8 @@ 
+This is for small sample images to be used with qemu-iotests, intended for
+non-native formats that QEMU supports for compatibility.  The idea is to use
+the native tool to create the sample image.
+
+For instance, a VHDX image in this directory would be an image created not by
+QEMU itself, but rather created by Hyper-V.
+
+Sample images added here should be described in the MANIFEST file.