OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import commands, logging, random, re, time, utils | 5 import commands, logging, random, re, time, utils |
6 from autotest_lib.client.bin import test | 6 from autotest_lib.client.bin import test |
7 from autotest_lib.client.common_lib import error | 7 from autotest_lib.client.common_lib import error, rtc, sys_power |
8 | 8 |
9 class power_Resume(test.test): | 9 class power_Resume(test.test): |
10 version = 1 | 10 version = 1 |
11 preserve_srcdir = True | 11 preserve_srcdir = True |
12 | 12 |
13 | 13 |
14 def _get_last_msg_time(self, msg): | 14 def _get_last_msg_time(self, msg): |
15 cmd = "grep -a '%s' /var/log/messages | tail -n 1" % msg | 15 cmd = "grep -a '%s' /var/log/messages | tail -n 1" % msg |
16 # The order in which processes are un-frozen is indeterminate | 16 # The order in which processes are un-frozen is indeterminate |
17 # and therfore this test may get resumed before the system has gotten | 17 # and therfore this test may get resumed before the system has gotten |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 def run_once(self): | 94 def run_once(self): |
95 # Some idle time before initiating suspend-to-ram | 95 # Some idle time before initiating suspend-to-ram |
96 idle_time = random.randint(1, 10) | 96 idle_time = random.randint(1, 10) |
97 time.sleep(idle_time) | 97 time.sleep(idle_time) |
98 | 98 |
99 # Safe enough number, can tweek if necessary | 99 # Safe enough number, can tweek if necessary |
100 time_to_sleep = 10 | 100 time_to_sleep = 10 |
101 | 101 |
102 # Set the alarm | 102 # Set the alarm |
103 alarm_time = int(utils.get_hwclock_seconds()) + time_to_sleep | 103 alarm_time = rtc.get_seconds() + time_to_sleep |
104 logging.debug('alarm_time = %d', alarm_time) | 104 logging.debug('alarm_time = %d', alarm_time) |
105 utils.set_wake_alarm(alarm_time) | 105 rtc.set_wake_alarm(alarm_time) |
106 | 106 |
107 # Suspend the system to RAM | 107 # Suspend the system to RAM |
108 utils.suspend_to_ram() | 108 sys_power.suspend_to_ram() |
109 | 109 |
110 # Get suspend and resume times from /var/log/messages | 110 # Get suspend and resume times from /var/log/messages |
111 start_suspend_time = self._get_start_suspend_time() | 111 start_suspend_time = self._get_start_suspend_time() |
112 end_suspend_time = self._get_end_suspend_time() | 112 end_suspend_time = self._get_end_suspend_time() |
113 end_resume_time = self._get_end_resume_time() | 113 end_resume_time = self._get_end_resume_time() |
114 | 114 |
115 # Calculate the suspend/resume times | 115 # Calculate the suspend/resume times |
116 total_resume_time = self._get_hwclock_seconds() - alarm_time | 116 total_resume_time = self._get_hwclock_seconds() - alarm_time |
117 suspend_time = end_suspend_time - start_suspend_time | 117 suspend_time = end_suspend_time - start_suspend_time |
118 kernel_resume_time = end_resume_time - end_suspend_time | 118 kernel_resume_time = end_resume_time - end_suspend_time |
119 firmware_resume_time = total_resume_time - kernel_resume_time | 119 firmware_resume_time = total_resume_time - kernel_resume_time |
120 | 120 |
121 # Prepare the results | 121 # Prepare the results |
122 results = {} | 122 results = {} |
123 results['seconds_system_suspend'] = suspend_time | 123 results['seconds_system_suspend'] = suspend_time |
124 results['seconds_system_resume'] = total_resume_time | 124 results['seconds_system_resume'] = total_resume_time |
125 results['seconds_system_resume_firmware'] = firmware_resume_time | 125 results['seconds_system_resume_firmware'] = firmware_resume_time |
126 results['seconds_system_resume_kernel'] = kernel_resume_time | 126 results['seconds_system_resume_kernel'] = kernel_resume_time |
127 self.write_perf_keyval(results) | 127 self.write_perf_keyval(results) |
128 | 128 |
129 # Finally, sanity check critical system components | 129 # Finally, sanity check critical system components |
130 self._sanity_check_system() | 130 self._sanity_check_system() |
OLD | NEW |