Skip to contentSkip to conversation

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

PATCH In review Michael Goldish 2 participants 6 messages Jun 8, 2010 – Jun 9, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v2 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
#1 lore raw

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

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
#2 lore raw

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

Based on Naphtali Sprei's patches.

Changes from v1:
- Determine success/failure by exit status instead of output
- Restructure loop so that vm.is_dead() is called less often
- Copy test log to debugdir/unittest.log
- Change parameters passed to wait_for()

---
 client/tests/kvm/tests/unittest.py |   65 ++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/unittest.py
client/tests/kvm/tests/unittest.py new file +65 -0
new file mode 100644
index 0000000..4570096
@@ -0,0 +1,65 @@
+import logging, time, os, shutil
+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) Make sure qemu's exit status is 0
+
+    @param test: kvm test object
+    @param params: Dictionary with the test parameters
+    @param env: Dictionary with test environment
+    """
+    # Get VM
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    # Resume VM if stopped
+    vm.send_monitor_cmd("cont")
+
+    timeout = float(params.get("unittest_timeout", 60))
+
+    try:
+        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:
+                    line = f.readline()
+                    if line:
+                        logging.info(line.rstrip())
+                    elif vm.is_dead():
+                        break
+                    else:
+                        time.sleep(1)
+                else:
+                    raise error.TestFail("Timeout elapsed (%ss)" % timeout)
+                # Make sure everything has been read and logged
+                while True:
+                    line = f.readline()
+                    if line:
+                        logging.info(line.rstrip())
+                    else:
+                        break
+            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, timeout):
+                raise error.TestFail("Timeout elapsed (%ss)" % timeout)
+    finally:
+        # Copy test log to debugdir/unittest.log
+        testlog_path = os.path.join(test.debugdir, "unittest.log")
+        shutil.copy(vm.testlog_file_name, testlog_path)
+
+    # Check qemu's exit status
+    status = vm.process.get_status()
+    if status != 0:
+        raise error.TestFail("qemu exited with status %s (see unittest "
+                             "output at %s)" % (status, testlog_path))
Signature · 1 line
1.5.4.1
#3 lore raw

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

Based on Naphtali Sprei's patches.

Changes from v1:
- Remove reference_output parameter

---
 client/tests/kvm/unittests.cfg.sample |   83 +++++++++++++++++++++++++++++++++
 1 files changed, 83 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/unittests.cfg.sample
client/tests/kvm/unittests.cfg.sample new file +83 -0
new file mode 100644
index 0000000..f3b7fcd
@@ -0,0 +1,83 @@
+# 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 are expected under unittests/
+        kernel = unittests/
+
+        variants:
+            - access:
+                kernel += access.flat
+            - apic:
+                kernel += apic.flat
+            - emulator:
+                kernel += emulator.flat
+            - hypercall:
+                kernel += hypercall.flat
+            - memtest1:
+                kernel += memtest1.flat
+            - msr:
+                kernel += msr.flat
+            - port80:
+                kernel += port80.flat
+            - realmode:
+                kernel += realmode.flat
+            - sieve:
+                kernel += sieve.flat
+            - simple:
+                kernel += simple.flat
+            - smptest:
+                kernel += smptest.flat
+            - stringio:
+                kernel += stringio.flat
+            - tsc:
+                kernel += tsc.flat
+            - vmexit:
+                kernel += vmexit.flat
Signature · 1 line
1.5.4.1
#4 lore raw
In reply to Michael Goldish
Quoted 10 lines · Michael Goldish
---
  client/tests/kvm/kvm_vm.py |   15 +++++++++++++++
  1 files changed, 15 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +0 -0
index 94bacdf..f3c05f3 100755

client/tests/kvm/kvm_vm.py class VM: · line 277

Quoted 10 lines
client/tests/kvm/kvm_vm.py +6 -0
@@ -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
+
 

Shell quoting is a good idea here. Everywhere else too, in fact, but -append is very likely to contain spaces.

Signature · 1 line
error compiling committee.c: too many arguments to function
#5 lore raw
Quoted 14 lines · Avi Kivity
Quoted 13 lines · Michael Goldish
---
  client/tests/kvm/kvm_vm.py |   15 +++++++++++++++
  1 files changed, 15 insertions(+), 0 deletions(-)
client/tests/kvm/kvm_vm.py +0 -0
index 94bacdf..f3c05f3 100755
@@ -268,6 +268,12 @@ class VM:
          def add_pcidevice(help, host):
              return " -pcidevice host=%s" % host
 
Quoted 11 lines

client/tests/kvm/kvm_vm.py class VM: · line 278

Quoted 7 lines
client/tests/kvm/kvm_vm.py +6 -0
+        def add_kernel(help, filename):
+            return " -kernel %s" % filename
+
+        def add_kernel_cmdline(help, cmdline):
+            return " -append %s" % cmdline
+
 

Shell quoting is a good idea here. Everywhere else too, in fact, but -append is very likely to contain spaces.

Thanks. I'll fix that for all parameters in a new patch.