Suspend function for site_wifitest
Suspend for a specified number of seconds. This makes use a if a newly created python script for using the RTC to trigger a suspend, then running a command. There is both a foreground and background variant.
BUG=none
TEST=Created a test in the Roaming Suite (not yet approved).
Manually ran command on x201, l13 and Andretti.
Review URL: http://codereview.chromium.org/3471015
diff --git a/server/site_system_suspend.py b/server/site_system_suspend.py
new file mode 100644
index 0000000..cf2d058
--- /dev/null
+++ b/server/site_system_suspend.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+
+"""Tell system to suspend, and resume some number of seconds later.
+
+Use the RTC to generate a wakeup some number of seconds into the
+future, then go to sleep. Note that this module is not aware of
+the actual time when the system will suspend. Depending on other
+system activities, there may be several seconds between when this
+script runs until when the system actually goes to sleep. In fact
+that time may be after the wakeup has been scheduled, and the
+system may never wake up! It is up to the caller to make prudent
+decisions as to upper bound of delay before going to sleep, and to
+choose a wakeup time greater than this interval.
+"""
+
+import os, re, subprocess, sys
+import rtc, sys_power
+
+time_to_sleep = 30
+if len(sys.argv) > 1:
+ time_to_sleep = int(sys.argv[1])
+
+if len(sys.argv) > 2:
+ after_command = ' '.join(sys.argv[2:])
+else:
+ after_command = None
+
+rtc.set_wake_alarm(rtc.get_seconds() + time_to_sleep)
+sys_power.suspend_to_ram()
+
+if after_command:
+ os.system(after_command)
diff --git a/server/site_wifitest.py b/server/site_wifitest.py
index 7be9311..7fc0f16 100644
--- a/server/site_wifitest.py
+++ b/server/site_wifitest.py
@@ -751,6 +751,37 @@
self.client_netdump_thread = None
+ def client_suspend(self, params):
+ """ Suspend the system """
+
+ script_client_file = self.install_script('site_system_suspend.py',
+ '../client/common_lib/rtc.py',
+ '../client/common_lib/'
+ 'sys_power.py')
+ result = self.client.run('python "%s" %d' %
+ (script_client_file, int(params.get("suspend_time", 5))))
+
+
+ def client_suspend_bg(self, params):
+ """ Suspend the system in the background """
+
+ script_client_file = self.install_script('site_system_suspend.py',
+ '../client/common_lib/rtc.py',
+ '../client/common_lib/'
+ 'sys_power.py')
+ cmd = ('python "%s" %d' %
+ (script_client_file, int(params.get("suspend_time", 5))))
+ self.client_suspend_thread = HelperThread(self.client, cmd)
+ self.client_suspend_thread.start()
+
+
+ def client_suspend_end(self, params):
+ """ Join the backgrounded suspend thread """
+
+ self.client_suspend_thread.join()
+ if self.client_suspend_thread.result.exit_status:
+ raise error.TestError('suspend failed')
+
class HelperThread(threading.Thread):
# Class that wraps a ping command in a thread so it can run in the bg.
def __init__(self, client, cmd):
@@ -760,8 +791,7 @@
def run(self):
# NB: set ignore_status as we're always terminated w/ pkill
- self.client.run(self.cmd, ignore_status=True)
-
+ self.result = self.client.run(self.cmd, ignore_status=True)
def __byfile(a, b):
if a['file'] < b['file']: