| 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 | 5 import commands, logging, random, re, time |
| 6 from autotest_lib.client.bin import test, utils | 6 from autotest_lib.client.bin import test, utils |
| 7 from autotest_lib.client.common_lib import error | 7 from autotest_lib.client.common_lib import error |
| 8 from autotest_lib.client.cros import rtc, sys_power | 8 from autotest_lib.client.cros import rtc, sys_power |
| 9 | 9 |
| 10 START_SUSPEND_MESSAGES = [ 'Freezing user space' ] | 10 START_SUSPEND_MESSAGES = [ 'Freezing user space' ] |
| 11 END_SUSPEND_MESSAGES = [ 'Back to C!', 'Resume caused by' ] | 11 END_SUSPEND_MESSAGES = [ 'Back to C!', 'Resume caused by' ] |
| 12 END_RESUME_MESSAGES = [ 'Restarting tasks' ] | 12 END_RESUME_MESSAGES = [ 'Restarting tasks' ] |
| 13 | 13 |
| 14 class power_Resume(test.test): | 14 class power_Resume(test.test): |
| 15 version = 1 | 15 version = 1 |
| 16 preserve_srcdir = True | 16 preserve_srcdir = True |
| 17 | 17 |
| 18 | 18 |
| 19 def _get_last_msg_time(self, msg): | 19 def _get_last_msg(self, msg): |
| 20 cmd = "grep -a '%s' /var/log/messages | tail -n 1" % msg | 20 cmd = "grep -a '%s' /var/log/messages | tail -n 1" % msg |
| 21 # The order in which processes are un-frozen is indeterminate | 21 # The order in which processes are un-frozen is indeterminate |
| 22 # and therfore this test may get resumed before the system has gotten | 22 # and therfore this test may get resumed before the system has gotten |
| 23 # a chance to finalize writes to logfile. Sleep a bit to take care of | 23 # a chance to finalize writes to logfile. Sleep a bit to take care of |
| 24 # this race. | 24 # this race. |
| 25 count = 0 | 25 count = 0 |
| 26 data = commands.getoutput(cmd) | 26 data = commands.getoutput(cmd) |
| 27 while len(data) == 0 and count < 5: | 27 while len(data) == 0 and count < 5: |
| 28 count +=1 | 28 count +=1 |
| 29 time.sleep(1) | 29 time.sleep(1) |
| 30 data = commands.getoutput(cmd) | 30 data = commands.getoutput(cmd) |
| 31 | 31 |
| 32 if count == 5: | 32 if count == 5: |
| 33 raise error.TestError("Failed to find log message: " + msg) | 33 raise error.TestError("Failed to find log message: " + msg) |
| 34 | 34 |
| 35 return data |
| 36 |
| 37 def _get_last_msg_time(self, msg): |
| 38 data = self._get_last_msg(msg) |
| 35 match = re.search(r' \[\s*([0-9.]+)\] ', data) | 39 match = re.search(r' \[\s*([0-9.]+)\] ', data) |
| 36 if match is None: | 40 if match is None: |
| 37 raise error.TestError('Failed to find timestamp for log message: ' | 41 raise error.TestError('Failed to find timestamp for log message: ' |
| 38 + msg) | 42 + msg) |
| 39 | 43 |
| 40 msg_time = float(match.group(1)) | 44 msg_time = float(match.group(1)) |
| 41 logging.debug("Last message '%s' time = %f" % (msg, msg_time)) | 45 logging.debug("Last message '%s' time = %f" % (msg, msg_time)) |
| 42 return msg_time | 46 return msg_time |
| 43 | 47 |
| 44 def _get_last_msg_time_multiple(self, msgs): | 48 def _get_last_msg_time_multiple(self, msgs): |
| 45 time = -1 | 49 time = -1 |
| 46 for msg in msgs: | 50 for msg in msgs: |
| 47 try: | 51 try: |
| 48 time = self._get_last_msg_time(msg) | 52 time = self._get_last_msg_time(msg) |
| 49 break | 53 break |
| 50 except error.TestError as e: | 54 except error.TestError as e: |
| 51 logging.info("%s, trying next message" % str(e)) | 55 logging.info("%s, trying next message" % str(e)) |
| 52 | 56 |
| 53 return time | 57 return time |
| 54 | 58 |
| 55 def _get_start_suspend_time(self): | 59 def _get_start_suspend_time(self): |
| 56 time = self._get_last_msg_time_multiple(START_SUSPEND_MESSAGES) | 60 time = self._get_last_msg_time_multiple(START_SUSPEND_MESSAGES) |
| 57 if time == -1: | 61 if time == -1: |
| 58 raise error.TestError("Could not find start suspend time message.") | 62 raise error.TestError("Could not find start suspend time message.") |
| 59 | 63 |
| 60 return time | 64 return time |
| 61 | 65 |
| 66 def _get_end_cpu_resume_time(self): |
| 67 return self._get_last_msg_time('CPU[0-9]\+ is up') |
| 62 | 68 |
| 63 def _get_end_suspend_time(self): | 69 def _get_end_suspend_time(self): |
| 64 time = self._get_last_msg_time_multiple(END_SUSPEND_MESSAGES) | 70 time = self._get_last_msg_time_multiple(END_SUSPEND_MESSAGES) |
| 65 if time == -1: | 71 if time == -1: |
| 66 raise error.TestError("Could not find end suspend time message.") | 72 raise error.TestError("Could not find end suspend time message.") |
| 67 | 73 |
| 68 return time | 74 return time |
| 69 | 75 |
| 70 def _get_end_resume_time(self): | 76 def _get_end_resume_time(self): |
| 71 time = self._get_last_msg_time_multiple(END_RESUME_MESSAGES) | 77 time = self._get_last_msg_time_multiple(END_RESUME_MESSAGES) |
| 72 if time == -1: | 78 if time == -1: |
| 73 raise error.TestError("Could not find end resume time message.") | 79 raise error.TestError("Could not find end resume time message.") |
| 74 | 80 |
| 75 return time | 81 return time |
| 76 | 82 |
| 83 def _get_device_resume_time(self): |
| 84 data = self._get_last_msg("PM: resume of devices complete after") |
| 85 match = re.search(r'PM: resume of devices complete after ([0-9.]+)', |
| 86 data) |
| 87 if match is None: |
| 88 raise error.TestError('Failed to find device resume time on line: ' |
| 89 + data) |
| 90 # convert from msec to sec |
| 91 return float(match.group(1)) / 1000 |
| 77 | 92 |
| 78 def _get_hwclock_seconds(self): | 93 def _get_hwclock_seconds(self): |
| 79 """ | 94 """ |
| 80 Read the hwclock resume time saved off by powerd_resume | 95 Read the hwclock resume time saved off by powerd_resume |
| 81 """ | 96 """ |
| 82 count = 0 | 97 count = 0 |
| 83 while count < 5: | 98 while count < 5: |
| 84 hwclock_output = utils.read_file('/tmp/hwclock-on-resume') | 99 hwclock_output = utils.read_file('/tmp/hwclock-on-resume') |
| 85 logging.debug('hwclock_output: ' + hwclock_output) | 100 logging.debug('hwclock_output: ' + hwclock_output) |
| 86 match = re.search( | 101 match = re.search( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 112 logging.debug('alarm_time = %d', alarm_time) | 127 logging.debug('alarm_time = %d', alarm_time) |
| 113 rtc.set_wake_alarm(alarm_time) | 128 rtc.set_wake_alarm(alarm_time) |
| 114 | 129 |
| 115 # Suspend the system to RAM | 130 # Suspend the system to RAM |
| 116 sys_power.suspend_to_ram() | 131 sys_power.suspend_to_ram() |
| 117 | 132 |
| 118 # Get suspend and resume times from /var/log/messages | 133 # Get suspend and resume times from /var/log/messages |
| 119 start_suspend_time = self._get_start_suspend_time() | 134 start_suspend_time = self._get_start_suspend_time() |
| 120 end_suspend_time = self._get_end_suspend_time() | 135 end_suspend_time = self._get_end_suspend_time() |
| 121 end_resume_time = self._get_end_resume_time() | 136 end_resume_time = self._get_end_resume_time() |
| 137 end_cpu_resume_time = self._get_end_cpu_resume_time() |
| 138 kernel_device_resume_time = self._get_device_resume_time() |
| 122 | 139 |
| 123 # Calculate the suspend/resume times | 140 # Calculate the suspend/resume times |
| 124 total_resume_time = self._get_hwclock_seconds() - alarm_time | 141 total_resume_time = self._get_hwclock_seconds() - alarm_time |
| 125 suspend_time = end_suspend_time - start_suspend_time | 142 suspend_time = end_suspend_time - start_suspend_time |
| 126 kernel_resume_time = end_resume_time - end_suspend_time | 143 kernel_resume_time = end_resume_time - end_suspend_time |
| 144 kernel_cpu_resume_time = end_cpu_resume_time - end_suspend_time |
| 127 firmware_resume_time = total_resume_time - kernel_resume_time | 145 firmware_resume_time = total_resume_time - kernel_resume_time |
| 128 | 146 |
| 129 # Prepare the results | 147 # Prepare the results |
| 130 results = {} | 148 results = {} |
| 131 results['seconds_system_suspend'] = suspend_time | 149 results['seconds_system_suspend'] = suspend_time |
| 132 results['seconds_system_resume'] = total_resume_time | 150 results['seconds_system_resume'] = total_resume_time |
| 133 results['seconds_system_resume_firmware'] = firmware_resume_time | 151 results['seconds_system_resume_firmware'] = firmware_resume_time |
| 134 results['seconds_system_resume_kernel'] = kernel_resume_time | 152 results['seconds_system_resume_kernel'] = kernel_resume_time |
| 153 results['seconds_system_resume_kernel_cpu'] = kernel_cpu_resume_time |
| 154 results['seconds_system_resume_kernel_dev'] = kernel_device_resume_time |
| 135 self.write_perf_keyval(results) | 155 self.write_perf_keyval(results) |
| OLD | NEW |