All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM test: Add cpu_set subtest
@ 2010-04-19 13:31 Lucas Meneghel Rodrigues
  0 siblings, 0 replies; only message in thread
From: Lucas Meneghel Rodrigues @ 2010-04-19 13:31 UTC (permalink / raw)
  To: autotest; +Cc: kvm, Lucas Meneghel Rodrigues

Tests the ability of adding virtual cpus on the fly to qemu using
the monitor command cpu_set, then after everything is OK, run the
cpu_hotplug testsuite on the guest through autotest.

Updates: The cpu_set feature has been worked out and is in
better shape, however it is my understanding that SeaBIOS code
has to be extended to support cpu_hotplug, like bochs bios did.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/tests/cpu_set.py      |   95 ++++++++++++++++++++++++++++++++
 client/tests/kvm/tests_base.cfg.sample |    7 ++
 2 files changed, 102 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/cpu_set.py

diff --git a/client/tests/kvm/tests/cpu_set.py b/client/tests/kvm/tests/cpu_set.py
new file mode 100644
index 0000000..e79fc95
--- /dev/null
+++ b/client/tests/kvm/tests/cpu_set.py
@@ -0,0 +1,95 @@
+import os, logging, re
+from autotest_lib.client.common_lib import error
+import kvm_test_utils
+
+def run_cpu_set(test, params, env):
+    """
+    Runs CPU set test:
+
+    1) Pick up a living guest
+    2) Send the monitor command cpu_set [n cpus]
+    3) Verify if guest has the additional CPU showing up under
+        /sys/devices/system/cpu
+    4) Try to bring it online by writing 1 to the 'online' file inside that dir
+    5) Run the CPU Hotplug test suite shipped with autotest inside guest
+
+    @param test: kvm test object.
+    @param params: Dictionary with test parameters.
+    @param env: Dictionary with the test environment.
+    """
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm)
+
+    n_cpus_add = int(params.get("n_cpus_add", 1))
+    current_cpus = int(params.get("smp", 1))
+    total_cpus = current_cpus + n_cpus_add
+    # Let's define some boundaries for this test
+    if total_cpus > 100:
+        raise error.TestError("Unsupported number of total CPUs: %s" %
+                              total_cpus)
+
+    dmesg_before = session.get_command_output("dmesg -c")
+
+    logging.info("Adding %d CPUs to guest", n_cpus_add)
+    for i in range(total_cpus):
+        status, output = vm.send_monitor_cmd("cpu_set %s online" % i)
+        if status != 0:
+            raise error.TestFail("Failed to add CPU %s to guest: %s" %
+                                 (i, output))
+
+    status, output = vm.send_monitor_cmd("info cpus")
+    logging.debug("Output of info cpus:\n%s", output)
+    cpu_regexp = re.compile("CPU #(\d+)")
+    total_cpus_monitor = len(cpu_regexp.findall(output))
+    if total_cpus_monitor != total_cpus:
+        raise error.TestFail("Monitor reports %s CPUs, when VM should have %s" %
+                             (total_cpus_monitor, total_cpus))
+
+    dmesg_after = session.get_command_output("dmesg -c")
+    logging.debug("Guest dmesg output after CPU add:\n%s" % dmesg_after)
+
+    # Verify whether the new cpus are showing up on /sys
+    n_cmd = 'find /sys/devices/system/cpu/cpu[0-99] -maxdepth 0 -type d | wc -l'
+    output = session.get_command_output(n_cmd)
+    try:
+        cpus_after_addition = int(output)
+    except ValueError:
+        logging.error("Verify command output: %s", output)
+        raise error.TestFail("Unable to get CPU count after CPU addition")
+
+    if cpus_after_addition != total_cpus:
+        raise error.TestFail("%s CPUs are showing up under "
+                             "/sys/devices/system/cpu, was expecting %s" %
+                             (cpus_after_addition, total_cpus))
+
+    r_cmd = 'find /sys/devices/system/cpu/cpu[0-99]/online -maxdepth 0 -type f'
+    online_files = session.get_command_output(r_cmd).split().sort()
+
+    if not online_files:
+        raise error.TestFail("Could not find CPUs that can be "
+                             "enabled/disabled on guest")
+
+    for online_file in online_files:
+        cpu_regexp = re.compile("cpu(\d+)", re.IGNORECASE)
+        cpu_id = cpu_regexp.findall(online_file)[0]
+        try:
+            check_online_status = int(session.get_command_output("cat %s" %
+                                                                 online_file))
+        except ValueError:
+            raise error.TestFail("Unable to get online status from CPU %s" %
+                                 cpu_id)
+        if check_online_status == 0:
+            logging.debug("CPU %s offline, bringing it online" % cpu_id)
+            bring_online_status = session.get_command_status("echo 1 > %s" %
+                                                             online_file)
+            if bring_online_status != 0:
+                raise error.TestError("Error bringing guest CPU %s online" %
+                                      cpu_id)
+
+    # Now that all CPUs were onlined, let's execute the
+    # autotest CPU Hotplug test
+    control_path = os.path.join(test.bindir, "autotest_control",
+                                "cpu_hotplug.control")
+    kvm_test_utils.run_autotest(vm, session, control_path,
+                                int(params.get("cpu_hotplug_timeout")),
+                                test.outputdir)
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index e73ba44..6f769e6 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -348,6 +348,13 @@ variants:
                 image_name_snapshot1 = sn1
                 image_name_snapshot2 = sn2
 
+    - cpu_set:
+        type = cpu_set
+        cpu_hotplug_timeout = 600
+        n_cpus_add = 1
+        kill_vm = yes
+        iterations = 5
+
     # system_powerdown, system_reset and shutdown *must* be the last ones
     # defined (in this order), since the effect of such tests can leave
     # the VM on a bad state.
-- 
1.6.6.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-04-19 13:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-19 13:31 [PATCH] KVM test: Add cpu_set subtest Lucas Meneghel Rodrigues

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.