| OLD | NEW |
| 1 import logging, time | 1 import logging, time |
| 2 from autotest_lib.client.common_lib import error | 2 from autotest_lib.client.common_lib import error |
| 3 import kvm_test_utils | |
| 4 | 3 |
| 5 | 4 |
| 6 def run_linux_s3(test, params, env): | 5 def run_linux_s3(test, params, env): |
| 7 """ | 6 """ |
| 8 Suspend a guest Linux OS to memory. | 7 Suspend a guest Linux OS to memory. |
| 9 | 8 |
| 10 @param test: kvm test object. | 9 @param test: kvm test object. |
| 11 @param params: Dictionary with test parameters. | 10 @param params: Dictionary with test parameters. |
| 12 @param env: Dictionary with the test environment. | 11 @param env: Dictionary with the test environment. |
| 13 """ | 12 """ |
| 14 vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) | 13 vm = env.get_vm(params["main_vm"]) |
| 14 vm.verify_alive() |
| 15 timeout = int(params.get("login_timeout", 360)) | 15 timeout = int(params.get("login_timeout", 360)) |
| 16 session = kvm_test_utils.wait_for_login(vm, timeout=timeout) | 16 session = vm.wait_for_login(timeout=timeout) |
| 17 | 17 |
| 18 logging.info("Checking that VM supports S3") | 18 logging.info("Checking that VM supports S3") |
| 19 status = session.get_command_status("grep -q mem /sys/power/state") | 19 session.cmd("grep -q mem /sys/power/state") |
| 20 if status == None: | |
| 21 logging.error("Failed to check if S3 exists") | |
| 22 elif status != 0: | |
| 23 raise error.TestFail("Guest does not support S3") | |
| 24 | 20 |
| 25 logging.info("Waiting for a while for X to start") | 21 logging.info("Waiting for a while for X to start") |
| 26 time.sleep(10) | 22 time.sleep(10) |
| 27 | 23 |
| 28 src_tty = session.get_command_output("fgconsole").strip() | 24 src_tty = session.cmd_output("fgconsole").strip() |
| 29 logging.info("Current virtual terminal is %s" % src_tty) | 25 logging.info("Current virtual terminal is %s", src_tty) |
| 30 if src_tty not in map(str, range(1,10)): | 26 if src_tty not in map(str, range(1, 10)): |
| 31 raise error.TestFail("Got a strange current vt (%s)" % src_tty) | 27 raise error.TestFail("Got a strange current vt (%s)" % src_tty) |
| 32 | 28 |
| 33 dst_tty = "1" | 29 dst_tty = "1" |
| 34 if src_tty == "1": | 30 if src_tty == "1": |
| 35 dst_tty = "2" | 31 dst_tty = "2" |
| 36 | 32 |
| 37 logging.info("Putting VM into S3") | 33 logging.info("Putting VM into S3") |
| 38 command = "chvt %s && echo mem > /sys/power/state && chvt %s" % (dst_tty, | 34 command = "chvt %s && echo mem > /sys/power/state && chvt %s" % (dst_tty, |
| 39 src_tty) | 35 src_tty) |
| 40 suspend_timeout = 120 + int(params.get("smp")) * 60 | 36 suspend_timeout = 120 + int(params.get("smp")) * 60 |
| 41 status = session.get_command_status(command, timeout=suspend_timeout) | 37 session.cmd(command, timeout=suspend_timeout) |
| 42 if status != 0: | |
| 43 raise error.TestFail("Suspend to mem failed") | |
| 44 | 38 |
| 45 logging.info("VM resumed after S3") | 39 logging.info("VM resumed after S3") |
| 46 | 40 |
| 47 session.close() | 41 session.close() |
| OLD | NEW |