Good to see this test. Overall structure looks fine except comments below. On Fri, Feb 26, 2010 at 1:13 AM, Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx> wrote: > 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. > > Signed-off-by: Lucas Meneghel Rodrigues <lmr@xxxxxxxxxx> > --- > client/tests/kvm/tests/cpu_set.py | 92 ++++++++++++++++++++++++++++++++ > client/tests/kvm/tests_base.cfg.sample | 5 ++ > 2 files changed, 97 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..72213f6 > --- /dev/null > +++ b/client/tests/kvm/tests/cpu_set.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_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 > + # 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") Is the test intended only for Linux guests? If yes then we should state the dependency in the variant cpu_set as per the comment below. Otherwise we should have a more generic check and handle all the possible guests. > + > + 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) > + In my views it will be a good idea to check the number of cpus after addition through monitor as well. In a practical scenario, when a management application hotplug in a cpu, it will use the monitor info to update its metadata. So it will be nice to ensure the qemu monitor also returns the correct information. > + # 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 b00ed9e..07b394a 100644 > --- a/client/tests/kvm/tests_base.cfg.sample > +++ b/client/tests/kvm/tests_base.cfg.sample > @@ -287,6 +287,11 @@ variants: > kill_vm = yes > kill_vm_gracefully = no > > + - cpu_set: Shall not we add the dependency? like only Linux or no Windows ? > + type = cpu_set > + cpu_hotplug_timeout = 600 > + n_cpus_add = 1 > + > - system_reset: install setup unattended_install > type = boot > reboot_method = system_reset Rest looks fine!! > -- > 1.6.6.1 > > _______________________________________________ > Autotest mailing list > Autotest@xxxxxxxxxxxxxxx > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > -- Sudhir Kumar -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html