[KVM-AUTOTEST PATCH 2/3] KVM test: corrections to guest_s4

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



- Log into the guest again after it resumes from S4 ('session2' doesn't survive
  S4 in user networking mode).
- Use != 0 when checking the status returned by get_command_status(), because
  when things go wrong, it can also return None.
- Use time.sleep(float(params.get(...))) instead of time.sleep(params.get(...))
  (time.sleep() doesn't accept strings).
- Do not check that the VM is alive after vm.create() because vm.create()
  already does that.
- Use get_command_output(kill_test_s4_cmd) instead of sendline(kill_test_s4_cmd),
  because get_command_output() waits for the prompt to return, and allows us to
  be sure that the command got delivered to the guest.  This is especially
  important if the session is closed immediately after sending the command.
  In the case of the command that performs suspend to disk (set_s4_cmd), and the
  test_s4_cmd for Linux (nohup ...), it is OK to use sendline() because the
  prompt may never return.  In the latter case, sleep(5) after the sendline()
  call should ensure that the command got delivered before the test proceeds.
- Change the timeouts in the wait_for(vm.is_dead, ...) call.
- For Windows guests modify test_s4_cmd to 'start ping -t localhost'.
  Using start /B isn't safe because then ping's output is redirected to a dead
  shell session.
- For Windows guests mdify check_s4_cmd to 'tasklist | find /I "ping.exe"'.
  (It's a little more specific than just "ping".)
- Run guest_s4 after autoit tests because it can leave Windows guests with an
  annoying welcome screen.
- Make the logging messages more consistent with the style of other tests.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_tests.cfg.sample |   23 ++++++++---------
 client/tests/kvm/tests/guest_s4.py    |   45 +++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample
index 9ccc9b5..296449d 100644
--- a/client/tests/kvm/kvm_tests.cfg.sample
+++ b/client/tests/kvm/kvm_tests.cfg.sample
@@ -118,15 +118,6 @@ variants:
     - linux_s3:     install setup
         type = linux_s3
 
-    - guest_s4:
-        type = guest_s4
-        check_s4_support_cmd = grep -q disk /sys/power/state
-        test_s4_cmd = "cd /tmp/;nohup tcpdump -q -t ip host localhost"
-        check_s4_cmd = pgrep tcpdump
-        set_s4_cmd = echo disk > /sys/power/state
-        kill_test_s4_cmd = pkill tcpdump
-        services_up_timeout = 30
-
     - timedrift:    install setup
         extra_params += " -rtc-td-hack"
         variants:
@@ -166,7 +157,6 @@ variants:
         used_cpus = 5
         used_mem = 2560
 
-
     - autoit:       install setup
         type = autoit
         autoit_binary = D:\AutoIt3.exe
@@ -176,6 +166,15 @@ variants:
             - notepad:
                 autoit_script = autoit/notepad1.au3
 
+    - guest_s4:
+        type = guest_s4
+        check_s4_support_cmd = grep -q disk /sys/power/state
+        test_s4_cmd = "cd /tmp; nohup tcpdump -q -t ip host localhost"
+        check_s4_cmd = pgrep tcpdump
+        set_s4_cmd = echo disk > /sys/power/state
+        kill_test_s4_cmd = pkill tcpdump
+        services_up_timeout = 30
+
     - nic_hotplug:       install setup
         type = pci_hotplug
         pci_type = nic
@@ -518,8 +517,8 @@ variants:
             host_load_instances = 8
         guest_s4:
             check_s4_support_cmd = powercfg /hibernate on
-            test_s4_cmd = start /B ping -n 3000 localhost
-            check_s4_cmd = tasklist | find /I "ping"
+            test_s4_cmd = start ping -t localhost
+            check_s4_cmd = tasklist | find /I "ping.exe"
             set_s4_cmd = rundll32.exe PowrProf.dll, SetSuspendState
             kill_test_s4_cmd = taskkill /IM ping.exe /F
             services_up_timeout = 30
diff --git a/client/tests/kvm/tests/guest_s4.py b/client/tests/kvm/tests/guest_s4.py
index 7147e3b..f08b9d2 100644
--- a/client/tests/kvm/tests/guest_s4.py
+++ b/client/tests/kvm/tests/guest_s4.py
@@ -5,7 +5,7 @@ import kvm_test_utils, kvm_utils
 
 def run_guest_s4(test, params, env):
     """
-    Suspend guest to disk,supports both Linux & Windows OSes.
+    Suspend guest to disk, supports both Linux & Windows OSes.
 
     @param test: kvm test object.
     @param params: Dictionary with test parameters.
@@ -14,53 +14,62 @@ def run_guest_s4(test, params, env):
     vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
     session = kvm_test_utils.wait_for_login(vm)
 
-    logging.info("Checking whether guest OS supports suspend to disk (S4)")
+    logging.info("Checking whether guest OS supports suspend to disk (S4)...")
     status = session.get_command_status(params.get("check_s4_support_cmd"))
     if status is None:
         logging.error("Failed to check if guest OS supports S4")
     elif status != 0:
         raise error.TestFail("Guest OS does not support S4")
 
-    logging.info("Wait until all guest OS services are fully started")
-    time.sleep(params.get("services_up_timeout"))
+    logging.info("Waiting until all guest OS services are fully started...")
+    time.sleep(float(params.get("services_up_timeout", 30)))
 
     # Start up a program (tcpdump for linux & ping for Windows), as a flag.
     # If the program died after suspend, then fails this testcase.
     test_s4_cmd = params.get("test_s4_cmd")
     session.sendline(test_s4_cmd)
+    time.sleep(5)
 
     # Get the second session to start S4
     session2 = kvm_test_utils.wait_for_login(vm)
 
+    # Make sure the background program is running as expected
     check_s4_cmd = params.get("check_s4_cmd")
-    if session2.get_command_status(check_s4_cmd):
+    if session2.get_command_status(check_s4_cmd) != 0:
         raise error.TestError("Failed to launch '%s' as a background process" %
                               test_s4_cmd)
     logging.info("Launched background command in guest: %s" % test_s4_cmd)
 
     # Suspend to disk
-    logging.info("Start suspend to disk now...")
+    logging.info("Starting suspend to disk now...")
     session2.sendline(params.get("set_s4_cmd"))
 
-    if not kvm_utils.wait_for(vm.is_dead, 360, 30, 2):
-        raise error.TestFail("VM refuses to go down. Suspend failed")
-    logging.info("VM suspended successfully. Wait before booting it again.")
+    # Make sure the VM goes down
+    if not kvm_utils.wait_for(vm.is_dead, 240, 2, 2):
+        raise error.TestFail("VM refuses to go down. Suspend failed.")
+    logging.info("VM suspended successfully. Sleeping for a while before "
+                 "resuming it.")
     time.sleep(10)
 
     # Start vm, and check whether the program is still running
-    logging.info("Start suspended VM...")
-
+    logging.info("Resuming suspended VM...")
     if not vm.create():
         raise error.TestError("Failed to start VM after suspend to disk")
-    if not vm.is_alive():
-        raise error.TestError("VM seems to be dead after it was suspended")
 
-    # Check whether test command still alive
-    logging.info("Checking if background command is still alive")
-    if session2.get_command_status(check_s4_cmd):
-        raise error.TestFail("Command %s failed. S4 failed" % test_s4_cmd)
+    # Log into the resumed VM
+    logging.info("Logging into resumed VM...")
+    session2 = kvm_utils.wait_for(vm.remote_login, 120, 0, 2)
+    if not session2:
+        raise error.TestFail("Could not log into VM after resuming from "
+                             "suspend to disk")
+
+    # Check whether the test command is still alive
+    logging.info("Checking if background command is still alive...")
+    if session2.get_command_status(check_s4_cmd) != 0:
+        raise error.TestFail("Background command '%s' stopped running. S4 "
+                             "failed." % test_s4_cmd)
 
     logging.info("VM resumed successfuly after suspend to disk")
-    session2.sendline(params.get("kill_test_s4_cmd"))
+    session2.get_command_output(params.get("kill_test_s4_cmd"))
     session.close()
     session2.close()
-- 
1.5.4.1

--
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

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux