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 logging, math, re, utils | 5 import logging, math, re |
6 from autotest_lib.client.bin import site_log_reader, test | 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 cros_logging |
| 9 |
8 | 10 |
9 class platform_AccurateTime(test.test): | 11 class platform_AccurateTime(test.test): |
10 version = 1 | 12 version = 1 |
11 | 13 |
12 | 14 |
13 def __get_offset(self, string): | 15 def __get_offset(self, string): |
14 if (string.find('No time correction needed') > -1) : | 16 if (string.find('No time correction needed') > -1) : |
15 return float(0.0) | 17 return float(0.0) |
16 else : | 18 else : |
17 offset = re.search(r'Setting (-?[\d+\.]+) seconds', string) | 19 offset = re.search(r'Setting (-?[\d+\.]+) seconds', string) |
18 if offset is None: | 20 if offset is None: |
19 # If string is empty, check the sys logs dumped later. | 21 # If string is empty, check the sys logs dumped later. |
20 raise error.TestError('Unable to find offset in %s' % string) | 22 raise error.TestError('Unable to find offset in %s' % string) |
21 return float(offset.group(1)) | 23 return float(offset.group(1)) |
22 | 24 |
23 def run_once(self): | 25 def run_once(self): |
24 reader = site_log_reader.LogReader() | 26 reader = cros_logging.LogReader() |
25 reader.set_start_by_current() | 27 reader.set_start_by_current() |
26 # Check if htpdate is currently running | 28 # Check if htpdate is currently running |
27 if utils.system('pgrep htpdate', ignore_status=True) != 0: | 29 if utils.system('pgrep htpdate', ignore_status=True) != 0: |
28 raise error.TestError('htpdate server was not already running') | 30 raise error.TestError('htpdate server was not already running') |
29 # Stop it since we cannot start another instance of htpdate | 31 # Stop it since we cannot start another instance of htpdate |
30 utils.system('initctl stop htpdate') | 32 utils.system('initctl stop htpdate') |
31 try: | 33 try: |
32 # Now grab the current time and get its offset | 34 # Now grab the current time and get its offset |
33 cmd = '/usr/sbin/htpdate -u ntp:ntp -s -t -w www.google.com' | 35 cmd = '/usr/sbin/htpdate -u ntp:ntp -s -t -w www.google.com' |
34 output = utils.system_output(cmd,retain_output=True) | 36 output = utils.system_output(cmd,retain_output=True) |
35 server_offset = self.__get_offset(output) | 37 server_offset = self.__get_offset(output) |
36 logging.info("server time offset: %f" % server_offset) | 38 logging.info("server time offset: %f" % server_offset) |
37 | 39 |
38 self.write_perf_keyval({'seconds_offset': abs(server_offset)}) | 40 self.write_perf_keyval({'seconds_offset': abs(server_offset)}) |
39 finally: | 41 finally: |
40 utils.system('initctl start htpdate') | 42 utils.system('initctl start htpdate') |
41 logging.debug('sys logs emitted: %s' % reader.get_logs()) | 43 logging.debug('sys logs emitted: %s' % reader.get_logs()) |
OLD | NEW |