diff mbox

KVM-test: Add new subtest: floppy

Message ID 20110729015913.8949.49367.stgit@t (mailing list archive)
State New, archived
Headers show

Commit Message

Amos Kong July 29, 2011, 1:59 a.m. UTC
This test does some basic operation on the virtual floppy,
it supports both Linux and Windows guests.

Signed-off-by: Amos Kong <akong@redhat.com>
---
 client/tests/kvm/tests/floppy.py       |   62 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |   23 ++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/floppy.py


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Lucas Meneghel Rodrigues Aug. 2, 2011, 10:22 p.m. UTC | #1
On Thu, Jul 28, 2011 at 10:59 PM, Amos Kong <akong@redhat.com> wrote:
> This test does some basic operation on the virtual floppy,
> it supports both Linux and Windows guests.

Looks good to me. I've removed the pre command and handled the floppy
creation in the test code, please check it out:

http://autotest.kernel.org/changeset/5517

Thank you!

> Signed-off-by: Amos Kong <akong@redhat.com>
> ---
>  client/tests/kvm/tests/floppy.py       |   62 ++++++++++++++++++++++++++++++++
>  client/tests/kvm/tests_base.cfg.sample |   23 ++++++++++++
>  2 files changed, 85 insertions(+), 0 deletions(-)
>  create mode 100644 client/tests/kvm/tests/floppy.py
>
> diff --git a/client/tests/kvm/tests/floppy.py b/client/tests/kvm/tests/floppy.py
> new file mode 100644
> index 0000000..ee84df7
> --- /dev/null
> +++ b/client/tests/kvm/tests/floppy.py
> @@ -0,0 +1,62 @@
> +import logging, time
> +from autotest_lib.client.common_lib import error
> +
> +
> +@error.context_aware
> +def run_floppy(test, params, env):
> +    """
> +    Test virtual floppy of guest:
> +
> +    1)Create a floppy disk image on host
> +    2)start the guest with this floppy image.
> +    3)make a file system on guest virtual floppy
> +    4)calculate md5sum value of a file and copy it into floppy.
> +    5)verify whether the md5sum is match
> +
> +    @param test: kvm test object
> +    @param params: Dictionary with the test parameters
> +    @param env: Dictionary with test environment.
> +    """
> +    vm = env.get_vm(params["main_vm"])
> +    vm.create()
> +    timeout = int(params.get("login_timeout", 360))
> +    session = vm.wait_for_login(timeout=timeout)
> +
> +    dest_dir = params.get("mount_dir")
> +    # If mount_dir specified, treat guest as a Linux OS
> +    # Some Linux distribution does not load floppy at boot and Windows
> +    # needs time to load and init floppy driver
> +    if dest_dir:
> +        status = session.cmd("modprobe floppy")
> +    else:
> +        time.sleep(20)
> +
> +    error.context("Formating floppy disk before using it")
> +    format_cmd = params.get("format_floppy_cmd")
> +    session.cmd(format_cmd, timeout=120)
> +    logging.info("Floppy disk formatted successfully")
> +
> +    source_file = params.get("source_file")
> +    dest_file = params.get("dest_file")
> +
> +    if dest_dir:
> +        error.context("Mounting floppy")
> +        session.cmd("mount /dev/fd0 %s" % dest_dir)
> +    error.context("Testing floppy")
> +    session.cmd(params.get("test_floppy_cmd"))
> +
> +    try:
> +        error.context("Copying file to the floppy")
> +        session.cmd("%s %s %s" % (params.get("copy_cmd"), source_file,
> +                    dest_file))
> +        logging.info("Succeed to copy file '%s' into floppy disk" % source_file)
> +
> +        error.context("Checking if the file is unchanged after copy")
> +        session.cmd("%s %s %s" % (params.get("diff_file_cmd"), source_file,
> +                    dest_file))
> +    finally:
> +        clean_cmd = "%s %s" % (params.get("clean_cmd"), dest_file)
> +        session.cmd(clean_cmd)
> +        if dest_dir:
> +            session.cmd("umount %s" % dest_dir)
> +        session.close()
> diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
> index d597b52..8a816c6 100644
> --- a/client/tests/kvm/tests_base.cfg.sample
> +++ b/client/tests/kvm/tests_base.cfg.sample
> @@ -1115,6 +1115,11 @@ variants:
>         image_snapshot = yes
>         only Linux
>
> +    - floppy: install setup image_copy unattended_install.cdrom
> +        type = floppy
> +        floppy = "images/test_floppy.img"
> +        pre_cmd = "dd if=/dev/zero of=images/test_floppy.img bs=512 count=2880"
> +
>
>  # NICs
>  variants:
> @@ -1221,6 +1226,16 @@ variants:
>                  image_name_stg27 = storage27
>                  list_volume_command = cd /dev && \ls vd*
>                  re_str = "[vhs]d[a-z][^0-9]"
> +        floppy:
> +            format_floppy_cmd = mkfs -t ext3 /dev/fd0
> +            test_floppy_cmd = (dd if=/dev/urandom of=/mnt/test_floppy bs=1M count=1) && (rm -f /mnt/test_floppy)
> +            format_floppy_cmd = mkfs -t ext3 /dev/fd0
> +            source_file = /etc/passwd
> +            dest_file = /mnt/passwd
> +            clean_cmd = rm -f
> +            mount_dir = /mnt/
> +            diff_file_cmd = diff
> +            copy_cmd = cp
>
>         variants:
>             - CustomGuestLinux:
> @@ -2232,6 +2247,14 @@ variants:
>                 pre_cmd = del diskpart.script && (echo select disk 1 >> diskpart.script && echo create partition primary >> diskpart.script && echo assign >> diskpart.script) && echo select disk 0 >> diskpart.script && echo exit >> diskpart.script && diskpart /s diskpart.script
>             max_disk:
>                 pre_cmd = del diskpart.script && (for /L %i in (1 1 23) do echo select disk %i >> diskpart.script && echo create partition primary >> diskpart.script && echo assign >> diskpart.script) && echo select disk 0 >> diskpart.script && echo exit >> diskpart.script && diskpart /s diskpart.script
> +        floppy:
> +            format_floppy_cmd = echo n|format A: /Q /V:test_floppy
> +            source_file = C:\Windows\System32\cmd.exe
> +            dest_file = A:\cmd.exe
> +            clean_cmd = del
> +            diff_file_cmd = fc
> +            test_floppy_cmd = "chkdsk A:"
> +            copy_cmd = copy
>
>         variants:
>             - CustomGuestWindows:
>
> _______________________________________________
> Autotest mailing list
> Autotest@test.kernel.org
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
>
diff mbox

Patch

diff --git a/client/tests/kvm/tests/floppy.py b/client/tests/kvm/tests/floppy.py
new file mode 100644
index 0000000..ee84df7
--- /dev/null
+++ b/client/tests/kvm/tests/floppy.py
@@ -0,0 +1,62 @@ 
+import logging, time
+from autotest_lib.client.common_lib import error
+
+
+@error.context_aware
+def run_floppy(test, params, env):
+    """
+    Test virtual floppy of guest:
+
+    1)Create a floppy disk image on host
+    2)start the guest with this floppy image.
+    3)make a file system on guest virtual floppy
+    4)calculate md5sum value of a file and copy it into floppy.
+    5)verify whether the md5sum is match
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+    vm = env.get_vm(params["main_vm"])
+    vm.create()
+    timeout = int(params.get("login_timeout", 360))
+    session = vm.wait_for_login(timeout=timeout)
+
+    dest_dir = params.get("mount_dir")
+    # If mount_dir specified, treat guest as a Linux OS
+    # Some Linux distribution does not load floppy at boot and Windows
+    # needs time to load and init floppy driver
+    if dest_dir:
+        status = session.cmd("modprobe floppy")
+    else:
+        time.sleep(20)
+
+    error.context("Formating floppy disk before using it")
+    format_cmd = params.get("format_floppy_cmd")
+    session.cmd(format_cmd, timeout=120)
+    logging.info("Floppy disk formatted successfully")
+
+    source_file = params.get("source_file")
+    dest_file = params.get("dest_file")
+
+    if dest_dir:
+        error.context("Mounting floppy")
+        session.cmd("mount /dev/fd0 %s" % dest_dir)
+    error.context("Testing floppy")
+    session.cmd(params.get("test_floppy_cmd"))
+
+    try:
+        error.context("Copying file to the floppy")
+        session.cmd("%s %s %s" % (params.get("copy_cmd"), source_file,
+                    dest_file))
+        logging.info("Succeed to copy file '%s' into floppy disk" % source_file)
+
+        error.context("Checking if the file is unchanged after copy")
+        session.cmd("%s %s %s" % (params.get("diff_file_cmd"), source_file,
+                    dest_file))
+    finally:
+        clean_cmd = "%s %s" % (params.get("clean_cmd"), dest_file)
+        session.cmd(clean_cmd)
+        if dest_dir:
+            session.cmd("umount %s" % dest_dir)
+        session.close()
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index d597b52..8a816c6 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -1115,6 +1115,11 @@  variants:
         image_snapshot = yes
         only Linux
 
+    - floppy: install setup image_copy unattended_install.cdrom
+        type = floppy
+        floppy = "images/test_floppy.img"
+        pre_cmd = "dd if=/dev/zero of=images/test_floppy.img bs=512 count=2880"
+
 
 # NICs
 variants:
@@ -1221,6 +1226,16 @@  variants:
                  image_name_stg27 = storage27
                  list_volume_command = cd /dev && \ls vd*
                  re_str = "[vhs]d[a-z][^0-9]"
+        floppy:
+            format_floppy_cmd = mkfs -t ext3 /dev/fd0
+            test_floppy_cmd = (dd if=/dev/urandom of=/mnt/test_floppy bs=1M count=1) && (rm -f /mnt/test_floppy)
+            format_floppy_cmd = mkfs -t ext3 /dev/fd0
+            source_file = /etc/passwd
+            dest_file = /mnt/passwd
+            clean_cmd = rm -f
+            mount_dir = /mnt/
+            diff_file_cmd = diff
+            copy_cmd = cp
 
         variants:
             - CustomGuestLinux:
@@ -2232,6 +2247,14 @@  variants:
                 pre_cmd = del diskpart.script && (echo select disk 1 >> diskpart.script && echo create partition primary >> diskpart.script && echo assign >> diskpart.script) && echo select disk 0 >> diskpart.script && echo exit >> diskpart.script && diskpart /s diskpart.script
             max_disk:
                 pre_cmd = del diskpart.script && (for /L %i in (1 1 23) do echo select disk %i >> diskpart.script && echo create partition primary >> diskpart.script && echo assign >> diskpart.script) && echo select disk 0 >> diskpart.script && echo exit >> diskpart.script && diskpart /s diskpart.script
+        floppy:
+            format_floppy_cmd = echo n|format A: /Q /V:test_floppy
+            source_file = C:\Windows\System32\cmd.exe
+            dest_file = A:\cmd.exe
+            clean_cmd = del
+            diff_file_cmd = fc
+            test_floppy_cmd = "chkdsk A:"
+            copy_cmd = copy
 
         variants:
             - CustomGuestWindows: