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)