From patchwork Fri Jan 22 19:25:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 74728 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0MJPHh2009221 for ; Fri, 22 Jan 2010 19:25:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752682Ab0AVTZP (ORCPT ); Fri, 22 Jan 2010 14:25:15 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752623Ab0AVTZO (ORCPT ); Fri, 22 Jan 2010 14:25:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57604 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752621Ab0AVTZM (ORCPT ); Fri, 22 Jan 2010 14:25:12 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0MJPBoE011799 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Jan 2010 14:25:11 -0500 Received: from localhost.localdomain (vpn-10-169.rdu.redhat.com [10.11.10.169]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o0MJP2G2009623; Fri, 22 Jan 2010 14:25:09 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, mgoldish@redhat.com, Lucas Meneghel Rodrigues Subject: [PATCH 3/3] KVM test: Add cpu_hotplug subtest Date: Fri, 22 Jan 2010 17:25:00 -0200 Message-Id: <1264188300-18894-3-git-send-email-lmr@redhat.com> In-Reply-To: <1264188300-18894-2-git-send-email-lmr@redhat.com> References: <1264188300-18894-1-git-send-email-lmr@redhat.com> <1264188300-18894-2-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/tests/kvm/tests/cpu_hotplug.py b/client/tests/kvm/tests/cpu_hotplug.py new file mode 100644 index 0000000..013b45a --- /dev/null +++ b/client/tests/kvm/tests/cpu_hotplug.py @@ -0,0 +1,92 @@ +import os, logging, re +from autotest_lib.client.common_lib import error +from autotest_lib.client.bin import utils +import kvm_subprocess, kvm_utils, kvm_test_utils + +def run_cpu_hotplug(test, params, env): + """ + Runs CPU hotplug 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 + # As of today (01-21-2010) it is unlikely that we're going to raise the + # number of processors of a VM to anywhere near 100, but still, it's good + # to put some boundaries to the test + if total_cpus > 100: + raise error.TestError("Unsupported number of total CPUs: %s. " + "Please choose a smaller number." % total_cpus) + + dmesg_before = session.get_command_output("dmesg -c") + + logging.info("Adding %d CPUs to guest" % n_cpus_add) + (ret, output) = vm.send_monitor_cmd("cpu_set %s online" % total_cpus) + if ret != 0: + raise error.TestFail("Failed to add CPUs to guest: %s" % output) + + 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' + try: + cpus_after_addition = int(session.get_command_output(n_cmd)) + except ValueError: + raise error.TestFail("Unable to get CPU count after CPU addition " + "(Guest dead?)") + + 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: + online_status = int(session.get_command_output("cat %s" % + online_file)) + except ValueError: + raise error.TestFail("Unable to get online status from CPU %s " + "(Guest dead?)" % cpu_id) + if online_status == 0: + logging.debug("CPU %s offline, bringing it online" % cpu_id) + rc = session.get_command_status("echo 1 > %s" % online_file) + if rc != 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 + timeout = int(params.get("cpu_hotplug_timeout")) + test_name = "cpu_hotplug" + control_path = os.path.join(test.bindir, "autotest_control", + "cpu_hotplug.control") + outputdir = test.outputdir + + logging.info("Executing CPU hotplug autotest on guest") + kvm_test_utils.run_autotest(vm, session, control_path, timeout, test_name, + outputdir) + diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample index e48f1d2..a1af395 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -240,6 +240,11 @@ variants: - fmt_raw: image_format_stg = raw + - cpu_hotplug: + type = cpu_hotplug + cpu_hotplug_timeout = 600 + n_cpus_add = 1 + - system_reset: install setup unattended_install type = boot reboot_method = system_reset