From: Lucas Meneghel Rodrigues Subject: Re: [Autotest] [KVM-AUTOTEST PATCH 12/17] KVM test: add simple timedrift test (mainly for Windows) Date: Fri, 24 Jul 2009 17:16:16 -0300 Message-ID: <6ac58f4f0907241316l6d5fd4a2t5b0eff7abfce7a35@mail.gmail.com> References: <980021422.777921248190056111.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> <1720969748.778471248190196300.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Yolkfull Chow , autotest@test.kernel.org, kvm@vger.kernel.org To: Michael Goldish Return-path: Received: from qw-out-2122.google.com ([74.125.92.27]:33952 "EHLO qw-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751392AbZGXUQR convert rfc822-to-8bit (ORCPT ); Fri, 24 Jul 2009 16:16:17 -0400 Received: by qw-out-2122.google.com with SMTP id 8so1031401qwh.37 for ; Fri, 24 Jul 2009 13:16:16 -0700 (PDT) In-Reply-To: <1720969748.778471248190196300.JavaMail.root@zmail05.collab.prod.int.phx2.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Tue, Jul 21, 2009 at 12:29 PM, Michael Goldish = wrote: > > ----- "Yolkfull Chow" wrote: > >> On Mon, Jul 20, 2009 at 06:07:19PM +0300, Michael Goldish wrote: >> > 1) Log into a guest. >> > 2) Take a time reading from the guest and host. >> > 3) Run load on the guest and host. >> > 4) Take a second time reading. >> > 5) Stop the load and rest for a while. >> > 6) Take a third time reading. >> > 7) If the drift immediately after load is higher than a user- >> > specified value (in %), fail. >> > If the drift after the rest period is higher than a user-specified >> value, >> > fail. >> > >> > Signed-off-by: Michael Goldish >> > --- >> > =A0client/tests/kvm/kvm.py =A0 =A0 =A0 | =A0 =A01 + >> > =A0client/tests/kvm/kvm_tests.py | =A0161 >> ++++++++++++++++++++++++++++++++++++++++- >> > =A02 files changed, 160 insertions(+), 2 deletions(-) >> > >> > diff --git a/client/tests/kvm/kvm.py b/client/tests/kvm/kvm.py >> > index b18b643..070e463 100644 >> > --- a/client/tests/kvm/kvm.py >> > +++ b/client/tests/kvm/kvm.py >> > @@ -55,6 +55,7 @@ class kvm(test.test): >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"kvm_install": =A0test_routine(= "kvm_install", >> "run_kvm_install"), >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"linux_s3": =A0 =A0 test_routin= e("kvm_tests", >> "run_linux_s3"), >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"stress_boot": =A0test_routine(= "kvm_tests", >> "run_stress_boot"), >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"timedrift": =A0 =A0test_routine(= "kvm_tests", >> "run_timedrift"), >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} >> > >> > =A0 =A0 =A0 =A0 =A0# Make it possible to import modules from the t= est's >> bindir >> > diff --git a/client/tests/kvm/kvm_tests.py >> b/client/tests/kvm/kvm_tests.py >> > index 5991aed..ca0b8c0 100644 >> > --- a/client/tests/kvm/kvm_tests.py >> > +++ b/client/tests/kvm/kvm_tests.py >> > @@ -1,4 +1,4 @@ >> > -import time, os, logging >> > +import time, os, logging, re, commands >> > =A0from autotest_lib.client.common_lib import utils, error >> > =A0import kvm_utils, kvm_subprocess, ppm_utils, scan_results >> > >> > @@ -529,7 +529,6 @@ def run_stress_boot(tests, params, env): >> > =A0 =A0 =A0""" >> > =A0 =A0 =A0# boot the first vm >> > =A0 =A0 =A0vm =3D kvm_utils.env_get_vm(env, params.get("main_vm")) >> > - >> > =A0 =A0 =A0if not vm: >> > =A0 =A0 =A0 =A0 =A0raise error.TestError("VM object not found in >> environment") >> > =A0 =A0 =A0if not vm.is_alive(): >> > @@ -586,3 +585,161 @@ def run_stress_boot(tests, params, env): >> > =A0 =A0 =A0 =A0 =A0for se in sessions: >> > =A0 =A0 =A0 =A0 =A0 =A0 =A0se.close() >> > =A0 =A0 =A0 =A0 =A0logging.info("Total number booted: %d" % (num -= 1)) >> > + >> > + >> > +def run_timedrift(test, params, env): >> > + =A0 =A0""" >> > + =A0 =A0Time drift test (mainly for Windows guests): >> > + >> > + =A0 =A01) Log into a guest. >> > + =A0 =A02) Take a time reading from the guest and host. >> > + =A0 =A03) Run load on the guest and host. >> > + =A0 =A04) Take a second time reading. >> > + =A0 =A05) Stop the load and rest for a while. >> > + =A0 =A06) Take a third time reading. >> > + =A0 =A07) If the drift immediately after load is higher than a u= ser- >> > + =A0 =A0specified value (in %), fail. >> > + =A0 =A0If the drift after the rest period is higher than a >> user-specified value, >> > + =A0 =A0fail. >> > + >> > + =A0 =A0@param test: KVM test object. >> > + =A0 =A0@param params: Dictionary with test parameters. >> > + =A0 =A0@param env: Dictionary with the test environment. >> > + =A0 =A0""" >> > + =A0 =A0vm =3D kvm_utils.env_get_vm(env, params.get("main_vm")) >> > + =A0 =A0if not vm: >> > + =A0 =A0 =A0 =A0raise error.TestError("VM object not found in >> environment") >> > + =A0 =A0if not vm.is_alive(): >> > + =A0 =A0 =A0 =A0raise error.TestError("VM seems to be dead; Test = requires a >> living VM") >> > + >> > + =A0 =A0logging.info("Waiting for guest to be up...") >> > + >> > + =A0 =A0session =3D kvm_utils.wait_for(vm.ssh_login, 240, 0, 2) >> > + =A0 =A0if not session: >> > + =A0 =A0 =A0 =A0raise error.TestFail("Could not log into guest") >> > + >> > + =A0 =A0logging.info("Logged in") >> > + >> > + =A0 =A0# Collect test parameters: >> > + =A0 =A0# Command to run to get the current time >> > + =A0 =A0time_command =3D params.get("time_command") >> > + =A0 =A0# Filter which should match a string to be passed to >> time.strptime() >> > + =A0 =A0time_filter_re =3D params.get("time_filter_re") >> > + =A0 =A0# Time format for time.strptime() >> > + =A0 =A0time_format =3D params.get("time_format") >> > + =A0 =A0guest_load_command =3D params.get("guest_load_command") >> > + =A0 =A0guest_load_stop_command =3D >> params.get("guest_load_stop_command") >> > + =A0 =A0host_load_command =3D params.get("host_load_command") >> > + =A0 =A0guest_load_instances =3D int(params.get("guest_load_insta= nces", >> "1")) >> > + =A0 =A0host_load_instances =3D int(params.get("host_load_instanc= es", >> "0")) >> > + =A0 =A0# CPU affinity mask for taskset >> > + =A0 =A0cpu_mask =3D params.get("cpu_mask", "0xFF") >> > + =A0 =A0load_duration =3D float(params.get("load_duration", "30")= ) >> > + =A0 =A0rest_duration =3D float(params.get("rest_duration", "10")= ) >> > + =A0 =A0drift_threshold =3D float(params.get("drift_threshold", "= 200")) >> > + =A0 =A0drift_threshold_after_rest =3D >> float(params.get("drift_threshold_after_rest", >> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"200")) >> > + >> > + =A0 =A0guest_load_sessions =3D [] >> > + =A0 =A0host_load_sessions =3D [] >> > + >> > + =A0 =A0# Remember the VM's previous CPU affinity >> > + =A0 =A0prev_cpu_mask =3D commands.getoutput("taskset -p %s" % >> vm.get_pid()) >> > + =A0 =A0prev_cpu_mask =3D prev_cpu_mask.split()[-1] >> > + =A0 =A0# Set the VM's CPU affinity >> > + =A0 =A0commands.getoutput("taskset -p %s %s" % (cpu_mask, >> vm.get_pid())) >> > + >> > + =A0 =A0try: >> > + =A0 =A0 =A0 =A0# Get time before load >> > + =A0 =A0 =A0 =A0host_time_0 =3D time.time() >> > + =A0 =A0 =A0 =A0session.sendline(time_command) >> > + =A0 =A0 =A0 =A0(match, s) =3D session.read_up_to_prompt() >> > + =A0 =A0 =A0 =A0s =3D re.findall(time_filter_re, s)[0] >> > + =A0 =A0 =A0 =A0guest_time_0 =3D time.mktime(time.strptime(s, tim= e_format)) >> >> Hi Machael, this test looks good for me, but I have a little >> suggestion: >> Why not write a common function to get guest time which really save >> many >> duplicate codes here? It could has four parameters and I would also >> help >> write it for you :-) >> >> def get_guest_time(session, time_command, filter_re, format): >> =A0 =A0 session.sendline(time_command) >> =A0 =A0 (match, s) =3D session.read_up_to_prompt() >> =A0 =A0 s =3D re.findall(filter_re, s)[0] >> =A0 =A0 curr_time =3D time.mktime(time.strptime(s, format)) >> =A0 =A0 return curr_time > > Thanks, makes perfect sense. The code seemed quite short already so I > didn't bother, but it should save quite a few lines. > > While we're at it, maybe the function should return the host time as = well: > (host_time_0, guest_time_0) =3D get_current_time(...) > > Anyway, if it's OK with everyone, I think I'll do it in an additional > commit rather than re-post this one, because even a small change like > that needs to undergo some minimal testing. Yes, I am OK with it. I am currently trying the test here on my test box. Code looks good.