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, os, platform, time | 5 import logging, os, platform, re, tempfile, time |
6 from autotest_lib.client.common_lib import error | 6 from autotest_lib.client.common_lib import error |
7 from autotest_lib.client.common_lib import utils | |
7 | 8 |
8 | 9 |
9 class TimeoutError(error.TestError): | 10 class TimeoutError(error.TestError): |
10 """Error raised when we time out when waiting on a condition.""" | 11 """Error raised when we time out when waiting on a condition.""" |
11 | 12 |
12 | 13 |
14 class Crossystem(object): | |
15 """A wrapper for the crossystem utility.""" | |
16 | |
17 def __init__(self, client): | |
18 self.cros_system_data = {} | |
19 self._client = client | |
20 | |
21 def init(self): | |
22 self.cros_system_data = {} | |
23 (fd, fname) = tempfile.mkstemp() | |
24 f = open(fname, 'w') | |
Mandeep Singh Baines
2011/04/07 21:15:42
Why not use the fd from above?
vb
2011/04/07 21:34:59
It gets messy with files opened on client/host, et
| |
25 self._client.run('crossystem', stdout_tee=f) | |
26 f.close() | |
27 text = open(fname).read() | |
Mandeep Singh Baines
2011/04/07 21:15:42
Use utils.read_file() instead.
vb
2011/04/07 21:34:59
Done.
| |
28 for line in text.splitlines(): | |
29 assignment_string = line.strip().split('#')[0] | |
Mandeep Singh Baines
2011/04/07 21:15:42
The strip here seems unnecessary.
vb
2011/04/07 21:34:59
true, done.
| |
30 if not assignment_string.count('='): | |
31 continue | |
32 (name, value) = assignment_string.split('=', 1) | |
33 self.cros_system_data[name.strip()] = value.strip() | |
34 os.remove(fname) | |
35 | |
36 def __getattr__(self, name): | |
37 """ | |
38 Retrieve a crosssystem attribute. | |
39 | |
40 The call crossystemobject.name() will return the crossystem reported | |
41 string. | |
42 """ | |
43 return lambda : self.cros_system_data[name] | |
44 | |
45 | |
13 def poll_for_condition( | 46 def poll_for_condition( |
14 condition, exception=None, timeout=10, sleep_interval=0.1, desc=None): | 47 condition, exception=None, timeout=10, sleep_interval=0.1, desc=None): |
15 """Poll until a condition becomes true. | 48 """Poll until a condition becomes true. |
16 | 49 |
17 condition: function taking no args and returning bool | 50 condition: function taking no args and returning bool |
18 exception: exception to throw if condition doesn't become true | 51 exception: exception to throw if condition doesn't become true |
19 timeout: maximum number of seconds to wait | 52 timeout: maximum number of seconds to wait |
20 sleep_interval: time to sleep between polls | 53 sleep_interval: time to sleep between polls |
21 desc: description of default TimeoutError used if 'exception' is None | 54 desc: description of default TimeoutError used if 'exception' is None |
22 | 55 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 which do not appear in the whitelist. | 103 which do not appear in the whitelist. |
71 | 104 |
72 Arguments: | 105 Arguments: |
73 dmesg - string containing raw dmesg buffer | 106 dmesg - string containing raw dmesg buffer |
74 message_level - minimum message priority to check | 107 message_level - minimum message priority to check |
75 whitelist - messages to ignore | 108 whitelist - messages to ignore |
76 | 109 |
77 Returns: | 110 Returns: |
78 List of unexpected warnings | 111 List of unexpected warnings |
79 """ | 112 """ |
80 | 113 whitelist_re = re.compile(r'(%s)' % '|'.join(whitelist)) |
81 unexpected = [] | 114 unexpected = [] |
82 for line in dmesg.splitlines(): | 115 for line in dmesg.splitlines(): |
83 if int(line[1]) <= message_level: | 116 if int(line[1]) <= message_level: |
84 if not 'used greatest stack depth' in line: | 117 stripped_line = line.split('] ', 1)[1] |
85 stripped_line = line.split('] ', 1)[1] | 118 if whitelist_re.search(stripped_line): |
86 if not stripped_line in whitelist: | 119 continue |
87 unexpected.append(stripped_line) | 120 unexpected.append(stripped_line) |
88 return unexpected | 121 return unexpected |
OLD | NEW |