From patchwork Wed Aug 24 04:05:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 1090692 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7O45Uod018483 for ; Wed, 24 Aug 2011 04:05:30 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750893Ab1HXEF0 (ORCPT ); Wed, 24 Aug 2011 00:05:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13450 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750788Ab1HXEF0 (ORCPT ); Wed, 24 Aug 2011 00:05:26 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7O45P6B002487 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 24 Aug 2011 00:05:25 -0400 Received: from freedom.local.com (vpn-9-173.rdu.redhat.com [10.11.9.173]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p7O45M8K015041; Wed, 24 Aug 2011 00:05:23 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, avi@redhat.com, gleb@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH] KVM test: Add cpu_hotplug subtest Date: Wed, 24 Aug 2011 01:05:13 -0300 Message-Id: <1314158713-14402-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 24 Aug 2011 04:05:30 +0000 (UTC) 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: As of the latest qemu-kvm (08-24-2011) HEAD, trying to online more CPUs than the ones already available leads to qemu hanging: File /home/lmr/Code/autotest-git/client/virt/kvm_monitor.py, line 279, in cmd raise MonitorProtocolError(msg) MonitorProtocolError: Could not find (qemu) prompt after command cpu_set 2 online. Output so far: "" Signed-off-by: Lucas Meneghel Rodrigues --- client/tests/kvm/tests/cpu_hotplug.py | 99 ++++++++++++++++++++++++++++++++ client/tests/kvm/tests_base.cfg.sample | 7 ++ 2 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 client/tests/kvm/tests/cpu_hotplug.py diff --git a/client/tests/kvm/tests/cpu_hotplug.py b/client/tests/kvm/tests/cpu_hotplug.py new file mode 100644 index 0000000..fa75c9b --- /dev/null +++ b/client/tests/kvm/tests/cpu_hotplug.py @@ -0,0 +1,99 @@ +import os, logging, re +from autotest_lib.client.common_lib import error +from autotest_lib.client.virt import virt_test_utils + + +@error.context_aware +def run_cpu_hotplug(test, params, env): + """ + Runs CPU hotplug test: + + 1) Pick up a living guest + 2) Send the monitor command cpu_set [cpu id] for each cpu we wish to have + 3) Verify if guest has the additional CPUs showing up under + /sys/devices/system/cpu + 4) Try to bring them 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 = env.get_vm(params["main_vm"]) + vm.verify_alive() + timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=timeout) + + n_cpus_add = int(params.get("n_cpus_add", 1)) + current_cpus = int(params.get("smp", 1)) + total_cpus = current_cpus + n_cpus_add + + error.context("getting guest dmesg before addition") + dmesg_before = session.cmd("dmesg -c") + + error.context("Adding %d CPUs to guest" % n_cpus_add) + for i in range(total_cpus): + vm.monitor.cmd("cpu_set %s online" % i) + + output = vm.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.cmd("dmesg -c") + logging.debug("Guest dmesg output after CPU add:\n%s" % dmesg_after) + + # Verify whether the new cpus are showing up on /sys + error.context("verifying if new CPUs are showing on guest's /sys dir") + n_cmd = 'find /sys/devices/system/cpu/cpu[0-99] -maxdepth 0 -type d | wc -l' + output = session.cmd(n_cmd) + logging.debug("List of cpus on /sys:\n%s" % output) + try: + cpus_after_addition = int(output) + except ValueError: + logging.error("Output of '%s': %s", n_cmd, 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)) + + error.context("locating online files for guest's new CPUs") + r_cmd = 'find /sys/devices/system/cpu/cpu[0-99]/online -maxdepth 0 -type f' + online_files = session.cmd(r_cmd) + logging.debug("CPU online files detected: %s", online_files) + online_files = online_files.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] + error.context("changing online status for CPU %s" % cpu_id) + check_online_status = session.cmd("cat %s" % online_file) + try: + check_online_status = int(check_online_status) + except ValueError: + raise error.TestFail("Unable to get online status from CPU %s" % + cpu_id) + assert(check_online_status in [0, 1]) + if check_online_status == 0: + error.context("Bringing CPU %s online" % cpu_id) + session.cmd("echo 1 > %s" % online_file) + + # 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") + + timeout = int(params.get("cpu_hotplug_timeout"), 300) + error.context("running cpu_hotplug autotest after cpu addition") + virt_test_utils.run_autotest(vm, session, control_path, timeout, + test.outputdir, params) diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index ca8a9c0..b22118b 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -1104,6 +1104,13 @@ variants: dd_timeout = 900 check_cmd_timeout = 900 + - cpu_hotplug: + type = cpu_hotplug + 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.