Skip to contentSkip to conversation

KVM test: support -kernel and -append command line options

PATCH Superseded Michael Goldish 1 participant 4 messages Jun 3, 2010 KVM

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#1 lore raw

PATCH 2/4 KVM test: add boolean 'testdev' VM parameter for RHEL-6 style unit tests

In reply to Michael Goldish

Should be set to "yes" to enable testdev.

---
 client/tests/kvm/kvm_vm.py |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)
client/tests/kvm/kvm_vm.py +20 -8
index f3c05f3..af45a81 100755
@@ -118,12 +118,16 @@ class VM:
 
         # Find available monitor filename
         while True:
-            # The monitor filename should be unique
+            # A unique identifier for this VM
             self.instance = (time.strftime("%Y%m%d-%H%M%S-") +
                              kvm_utils.generate_random_string(4))
-            self.monitor_file_name = os.path.join("/tmp",
-                                                  "monitor-" + self.instance)
-            if not os.path.exists(self.monitor_file_name):
+            # Monitor
+            self.monitor_file_name = "/tmp/monitor-" + self.instance
+            # Test log for unit tests
+            self.testlog_file_name = "/tmp/testlog-" + self.instance
+            # Verify uniqueness
+            if True not in map(os.path.exists, [self.monitor_file_name,
+                                                self.testlog_file_name]):
                 break
 
 
@@ -274,6 +278,10 @@ class VM:
         def add_kernel_cmdline(help, cmdline):
             return " -append %s" % cmdline
 
+        def add_testdev(help, filename):
+            return (" -chardev file,id=testlog,path=%s"
+                    " -device testdev,chardev=testlog" % filename)
+
         # End of command line option wrappers
 
         if name is None: name = self.name
@@ -393,6 +401,9 @@ class VM:
         elif params.get("uuid"):
             qemu_cmd += add_uuid(help, params.get("uuid"))
 
+        if params.get("testdev") == "yes":
+            qemu_cmd += add_testdev(help, self.testlog_file_name)
+
         # If the PCI assignment step went OK, add each one of the PCI assigned
         # devices to the qemu command line.
         if self.pci_assignable:
@@ -728,10 +739,11 @@ class VM:
                 self.pci_assignable.release_devs()
             if self.process:
                 self.process.close()
-            try:
-                os.unlink(self.monitor_file_name)
-            except OSError:
-                pass
+            for f in [self.monitor_file_name, self.testlog_file_name]:
+                try:
+                    os.unlink(f)
+                except OSError:
+                    pass
 
 
     def is_alive(self):
Signature · 1 line
1.5.4.1
#0 lore raw

PATCH 1/4 KVM test: support -kernel and -append command line options

---
 client/tests/kvm/kvm_vm.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +15 -0
index 94bacdf..f3c05f3 100755
@@ -268,6 +268,12 @@ class VM:
         def add_pcidevice(help, host):
             return " -pcidevice host=%s" % host
 
+        def add_kernel(help, filename):
+            return " -kernel %s" % filename
+
+        def add_kernel_cmdline(help, cmdline):
+            return " -append %s" % cmdline
+
         # End of command line option wrappers
 
         if name is None: name = self.name
@@ -360,6 +366,15 @@ class VM:
             tftp = kvm_utils.get_path(root_dir, tftp)
             qemu_cmd += add_tftp(help, tftp)
 
+        kernel = params.get("kernel")
+        if kernel:
+            kernel = kvm_utils.get_path(root_dir, kernel)
+            qemu_cmd += add_kernel(help, kernel)
+
+        kernel_cmdline = params.get("kernel_cmdline")
+        if kernel_cmdline:
+            qemu_cmd += add_kernel_cmdline(help, kernel_cmdline)
+
         for redir_name in kvm_utils.get_sub_dict_names(params, "redirs"):
             redir_params = kvm_utils.get_sub_dict(params, redir_name)
             guest_port = int(redir_params.get("guest_port"))
Signature · 1 line
1.5.4.1
#2 lore raw

PATCH 3/4 KVM test: add wrapper for RHEL-6 style unittests

In reply to Michael Goldish

Based on Naphtali Sprei's patches.

---
 client/tests/kvm/tests/unittest.py |   66 ++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/unittest.py
client/tests/kvm/tests/unittest.py new file +66 -0
new file mode 100644
index 0000000..c073d04
@@ -0,0 +1,66 @@
+import logging, time, select, os, difflib
+from autotest_lib.client.common_lib import error
+import kvm_subprocess, kvm_test_utils, kvm_utils
+
+
+def run_unittest(test, params, env):
+    """
+    KVM RHEL-6 style unit test:
+    1) Resume a stopped VM
+    2) Wait for VM to terminate
+    3) Compare output with reference output
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment.
+    """
+    # Get params
+    ref_output_filename = params.get("reference_output")
+    if not ref_output_filename:
+        raise error.TestError("reference_output not specified")
+    ref_output_filename = kvm_utils.get_path(test.bindir, ref_output_filename)
+    if not os.path.exists(ref_output_filename):
+        raise error.TestError("Reference file not found: %s" %
+                              ref_output_filename)
+    timeout = float(params.get("unittest_timeout", 60))
+
+    # Get VM
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    # Resume VM if stopped
+    vm.send_monitor_cmd("cont")
+
+    if params.get("log_output") == "yes":
+        # Log test output
+        f = open(vm.testlog_file_name)
+        logging.info("-------- Test output --------")
+        try:
+            end_time = time.time() + timeout
+            while time.time() < end_time:
+                dead = vm.is_dead()
+                line = f.readline()
+                if line:
+                    logging.info(line.rstrip())
+                elif dead:
+                    break
+                else:
+                    time.sleep(1)
+            else:
+                raise error.TestFail("Timeout elapsed (%ss)" % timeout)
+        finally:
+            logging.info("-------- End of test output --------")
+            f.close()
+    else:
+        # Just wait for the VM to terminate
+        logging.info("Waiting for VM to terminate...")
+        if not kvm_utils.wait_for(vm.is_dead, 0, 1, timeout):
+            raise error.TestFail("Timeout elapsed (%ss)" % timeout)
+
+    # Compare output with reference_output
+    logging.info("Comparing test output with reference output")
+    test_output = open(vm.testlog_file_name, "U").readlines()
+    ref_output = open(ref_output_filename, "U").readlines()
+    if test_output != ref_output:
+        logging.error("Difference between reference output and test output:")
+        for line in difflib.unified_diff(ref_output, test_output):
+            logging.error(line.rstrip())
+        raise error.TestFail("Test output differs from reference output")
Signature · 1 line
1.5.4.1
#3 lore raw

PATCH 4/4 KVM test: add sample RHEL-6 style unittest config file

Based on Naphtali Sprei's patches.

---
 client/tests/kvm/unittests.cfg.sample |   98 +++++++++++++++++++++++++++++++++
 1 files changed, 98 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/unittests.cfg.sample
client/tests/kvm/unittests.cfg.sample new file +98 -0
new file mode 100644
index 0000000..f214337
@@ -0,0 +1,98 @@
+# Copy this file to tests_base.cfg and edit it.
+#
+# Define the objects we'll be using
+vms = vm1
+
+# Choose the main VM
+main_vm = vm1
+
+# Some preprocessor/postprocessor params
+start_vm = yes
+kill_vm = yes
+kill_vm_gracefully = no
+
+# Screendump specific stuff
+convert_ppm_files_to_png_on_error = yes
+#keep_ppm_files = yes
+#keep_ppm_files_on_error = yes
+take_regular_screendumps = yes
+keep_screendumps_on_error = yes
+screendump_delay = 5
+screendump_quality = 30
+screendump_temp_dir = /dev/shm
+
+# Some default VM params
+qemu_binary = qemu
+qemu_img_binary = qemu-img
+smp = 1
+mem = 512
+display = vnc
+
+# Default scheduler params
+used_cpus = 1
+used_mem = 512
+
+# NIC parameters
+run_tcpdump = no
+
+# Misc
+run_kvm_stat = yes
+
+
+# Tests
+variants:
+    # (This variant is defined only in order make all test names begin with 'unittest.')
+    - unittest:
+        type = unittest
+        unittest_timeout = 600
+        log_output = yes
+        testdev = yes
+        extra_params += " -S"
+
+        # All kernels and reference output files are expected under unittests/
+        kernel = unittests/
+        reference_output = unittests/
+
+        variants:
+            - access:
+                kernel += access.flat
+                reference_output += access.log.ref
+            - apic:
+                kernel += apic.flat
+                reference_output += apic.log.ref
+            - emulator:
+                kernel += emulator.flat
+                reference_output += emulator.log.ref
+            - hypercall:
+                kernel += hypercall.flat
+                reference_output += hypercall.log.ref
+            - memtest1:
+                kernel += memtest1.flat
+                reference_output += memtest1.log.ref
+            - msr:
+                kernel += msr.flat
+                reference_output += msr.log.ref
+            - port80:
+                kernel += port80.flat
+                reference_output += port80.log.ref
+            - realmode:
+                kernel += realmode.flat
+                reference_output += realmode.log.ref
+            - sieve:
+                kernel += sieve.flat
+                reference_output += sieve.log.ref
+            - simple:
+                kernel += simple.flat
+                reference_output += simple.log.ref
+            - smptest:
+                kernel += smptest.flat
+                reference_output += smptest.log.ref
+            - stringio:
+                kernel += stringio.flat
+                reference_output += stringio.log.ref
+            - tsc:
+                kernel += tsc.flat
+                reference_output += tsc.log.ref
+            - vmexit:
+                kernel += vmexit.flat
+                reference_output += vmexit.log.ref
Signature · 1 line
1.5.4.1