Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(375)

Side by Side Diff: client/site_tests/power_Resume/power_Resume.py

Issue 3417014: retry log parsing for suspend/resume event messages (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: Created 10 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 data = commands.getoutput( 15 cmd = "grep -a '%s' /var/log/messages | tail -n 1" % msg
16 "grep -a '%s' /var/log/messages | tail -n 1" % msg) 16 # The order in which processes are un-frozen is indeterminate
17 # and therfore this test may get resumed before the system has gotten
18 # a chance to finalize writes to logfile. Sleep a bit to take care of
19 # this race.
20 count = 0
21 data = commands.getoutput(cmd)
22 while len(data) == 0 and count < 5:
23 count +=1
24 time.sleep(1)
25 data = commands.getoutput(cmd)
26
27 if count == 5:
28 raise error.TestError("Failed to find log message: " + msg)
29
17 match = re.search(r' \[\s*([0-9.]+)\] ', data) 30 match = re.search(r' \[\s*([0-9.]+)\] ', data)
18 if match is None: 31 if match is None:
19 raise error.TestError('Failed to find log message: ' + msg) 32 raise error.TestError('Failed to find timestamp for log message: '
33 + msg)
20 34
21 msg_time = float(match.group(1)) 35 msg_time = float(match.group(1))
22 logging.debug("Last message '%s' time = %f" % (msg, msg_time)) 36 logging.debug("Last message '%s' time = %f" % (msg, msg_time))
23 return msg_time 37 return msg_time
24 38
25 39
26 def _get_start_suspend_time(self): 40 def _get_start_suspend_time(self):
27 return self._get_last_msg_time('Freezing user space') 41 return self._get_last_msg_time('Freezing user space')
28 42
29 43
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 utils.set_wake_alarm(alarm_time) 105 utils.set_wake_alarm(alarm_time)
92 106
93 # Suspend the system to RAM 107 # Suspend the system to RAM
94 utils.suspend_to_ram() 108 utils.suspend_to_ram()
95 109
96 # Get suspend and resume times from /var/log/messages 110 # Get suspend and resume times from /var/log/messages
97 start_suspend_time = self._get_start_suspend_time() 111 start_suspend_time = self._get_start_suspend_time()
98 end_suspend_time = self._get_end_suspend_time() 112 end_suspend_time = self._get_end_suspend_time()
99 end_resume_time = self._get_end_resume_time() 113 end_resume_time = self._get_end_resume_time()
100 114
101 # The order in which processes are un-frozen is indeterminate
102 # and therfore this test may get resumed before the system has gotten
103 # a chance to write the end resume message. Sleep for a short time
104 # to take care of this race.
105 count = 0
106 while end_resume_time < start_suspend_time and count < 5:
107 count += 1
108 time.sleep(1)
109 end_resume_time = self._get_end_resume_time()
110
111 if count == 5:
112 raise error.TestError('Failed to find end resume time')
113
114 # Calculate the suspend/resume times 115 # Calculate the suspend/resume times
115 total_resume_time = self._get_hwclock_seconds() - alarm_time 116 total_resume_time = self._get_hwclock_seconds() - alarm_time
116 suspend_time = end_suspend_time - start_suspend_time 117 suspend_time = end_suspend_time - start_suspend_time
117 kernel_resume_time = end_resume_time - end_suspend_time 118 kernel_resume_time = end_resume_time - end_suspend_time
118 firmware_resume_time = total_resume_time - kernel_resume_time 119 firmware_resume_time = total_resume_time - kernel_resume_time
119 120
120 # Prepare the results 121 # Prepare the results
121 results = {} 122 results = {}
122 results['seconds_system_suspend'] = suspend_time 123 results['seconds_system_suspend'] = suspend_time
123 results['seconds_system_resume'] = total_resume_time 124 results['seconds_system_resume'] = total_resume_time
124 results['seconds_system_resume_firmware'] = firmware_resume_time 125 results['seconds_system_resume_firmware'] = firmware_resume_time
125 results['seconds_system_resume_kernel'] = kernel_resume_time 126 results['seconds_system_resume_kernel'] = kernel_resume_time
126 self.write_perf_keyval(results) 127 self.write_perf_keyval(results)
127 128
128 # Finally, sanity check critical system components 129 # Finally, sanity check critical system components
129 self._sanity_check_system() 130 self._sanity_check_system()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698