All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: lmr@redhat.com, autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH] KVM test: Measure the timedrift after continuing a stopped vm
Date: Fri, 28 May 2010 20:04:15 +0800	[thread overview]
Message-ID: <20100528120415.1008.1892.stgit@dhcp-91-25.nay.redhat.com> (raw)

This test extends the timedifrt test and measures the timedirft across
the vm stopping and continuing. Two helpers function are also added in
kvm_test_utils to do the stop and continue.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 client/tests/kvm/tests/timedrift_with_stop.py |   97 +++++++++++++++++++++++++
 1 files changed, 97 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/timedrift_with_stop.py

diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index 24e2bf5..7e158a3 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -181,6 +181,30 @@ def migrate(vm, env=None):
         raise
 
 
+def stop(vm):
+    """
+    Stop a running vm
+    """
+    s, o = vm.send_monitor_cmd("stop")
+    if s != 0:
+        raise error.TestError("Could not send the stop command")
+    s, o = vm.send_monitor_cmd("info status")
+    if "paused" not in o:
+        raise error.TestFail("VM does not stop afer send stop command")
+
+    
+def cont(vm):
+    """
+    Continue a stopped vm
+    """
+    s, o = vm.send_monitor_cmd("cont")
+    if s != 0:
+        raise error.TestError("Could not send the cont command")
+    s, o = vm.send_monitor_cmd("info status")
+    if "running" not in o:
+        raise error.TestFail("VM still in paused status after sending cont")
+    
+
 def get_time(session, time_command, time_filter_re, time_format):
     """
     Return the host time and guest time.  If the guest time cannot be fetched
diff --git a/client/tests/kvm/tests/timedrift_with_stop.py b/client/tests/kvm/tests/timedrift_with_stop.py
new file mode 100644
index 0000000..b99dd40
--- /dev/null
+++ b/client/tests/kvm/tests/timedrift_with_stop.py
@@ -0,0 +1,97 @@
+import logging, time, commands, re
+from autotest_lib.client.common_lib import error
+import kvm_subprocess, kvm_test_utils, kvm_utils
+
+
+def run_timedrift_with_stop(test, params, env):
+    """
+    Time drift test with stop/continue the guest:
+
+    1) Log into a guest.
+    2) Take a time reading from the guest and host.
+    3) Stop the running of the guest
+    4) Sleep for a while
+    5) Continue the guest running
+    6) Take a second time reading.
+    7) If the drift (in seconds) is higher than a user specified value, fail.
+
+    @param test: KVM test object.
+    @param params: Dictionary with test parameters.
+    @param env: Dictionary with the test environment.
+    """
+    login_timeout = int(params.get("login_timeout", 360))
+    vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
+    session = kvm_test_utils.wait_for_login(vm, timeout=login_timeout)
+
+    # Collect test parameters:
+    # Command to run to get the current time
+    time_command = params.get("time_command")
+    # Filter which should match a string to be passed to time.strptime()
+    time_filter_re = params.get("time_filter_re")
+    # Time format for time.strptime()
+    time_format = params.get("time_format")
+    drift_threshold = float(params.get("drift_threshold", "10"))
+    drift_threshold_single = float(params.get("drift_threshold_single", "3"))
+    stop_iterations = int(params.get("stop_iterations", 1))
+    stop_time = int(params.get("stop_time", 60))
+
+    try:
+        # Get initial time
+        # (ht stands for host time, gt stands for guest time)
+        (ht0, gt0) = kvm_test_utils.get_time(session, time_command,
+                                             time_filter_re, time_format)
+
+        # Stop the guest
+        for i in range(stop_iterations):
+            # Get time before current iteration
+            (ht0_, gt0_) = kvm_test_utils.get_time(session, time_command,
+                                                   time_filter_re, time_format)
+            # Run current iteration
+            logging.info("Stop %s second: iteration %d of %d..." %
+                         (stop_time, i + 1, stop_iterations))
+            
+            kvm_test_utils.stop(vm)
+            time.sleep(stop_time)
+            kvm_test_utils.cont(vm)
+            
+            # Get time after current iteration
+            (ht1_, gt1_) = kvm_test_utils.get_time(session, time_command,
+                                                   time_filter_re, time_format)
+            # Report iteration results
+            host_delta = ht1_ - ht0_
+            guest_delta = gt1_ - gt0_
+            drift = abs(host_delta - guest_delta)
+            logging.info("Host duration (iteration %d): %.2f" %
+                         (i + 1, host_delta))
+            logging.info("Guest duration (iteration %d): %.2f" %
+                         (i + 1, guest_delta))
+            logging.info("Drift at iteration %d: %.2f seconds" %
+                         (i + 1, drift))
+            # Fail if necessary
+            if drift > drift_threshold_single:
+                raise error.TestFail("Time drift too large at iteration %d: "
+                                     "%.2f seconds" % (i + 1, drift))
+
+        # Get final time
+        (ht1, gt1) = kvm_test_utils.get_time(session, time_command,
+                                             time_filter_re, time_format)
+
+    finally:
+        if session:
+            session.close()
+
+    # Report results
+    host_delta = ht1 - ht0
+    guest_delta = gt1 - gt0
+    drift = abs(host_delta - guest_delta)
+    logging.info("Host duration (%d stops): %.2f" %
+                 (stop_iterations, host_delta))
+    logging.info("Guest duration (%d stops): %.2f" %
+                 (stop_iterations, guest_delta))
+    logging.info("Drift after %d stops: %.2f seconds" %
+                 (stop_iterations, drift))
+
+    # Fail if necessary
+    if drift > drift_threshold:
+        raise error.TestFail("Time drift too large after %d stops: "
+                             "%.2f seconds" % (stop_iterations, drift))
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 5349034..c2babb9 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -183,6 +183,13 @@ variants:
                 reboot_iterations = 1
                 drift_threshold = 10
                 drift_threshold_single = 3
+            - with_stop:
+                type = timedrift_with_stop
+                stop_interations = 1
+                drift_threshold = 10
+                drift_threshold_single = 3
+
+
 
     - balloon_check:  install setup unattended_install
         type = balloon_check

                 reply	other threads:[~2010-05-28 12:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100528120415.1008.1892.stgit@dhcp-91-25.nay.redhat.com \
    --to=jasowang@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lmr@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.