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 dbus, logging, os, re, shutil, socket, sys, time | 5 import dbus, logging, os, re, shutil, socket, sys, time |
6 import common | 6 import common |
7 import auth_server, constants as chromeos_constants, cryptohome, dns_server | 7 import auth_server, constants as chromeos_constants, cryptohome, dns_server |
8 import cros_logging, cros_ui, login | 8 import cros_logging, cros_ui, login |
9 from autotest_lib.client.bin import test, utils | 9 from autotest_lib.client.bin import test, utils |
10 from autotest_lib.client.common_lib import error | 10 from autotest_lib.client.common_lib import error |
(...skipping 14 matching lines...) Expand all Loading... |
25 variable 'auto_login' to False. | 25 variable 'auto_login' to False. |
26 | 26 |
27 Subclasses can log in with arbitrary credentials by passing | 27 Subclasses can log in with arbitrary credentials by passing |
28 the 'creds' parameter in their control file. See the documentation of | 28 the 'creds' parameter in their control file. See the documentation of |
29 UITest.initialize for more details. | 29 UITest.initialize for more details. |
30 | 30 |
31 If your subclass overrides the initialize() or cleanup() methods, it | 31 If your subclass overrides the initialize() or cleanup() methods, it |
32 should make sure to invoke this class' version of those methods as well. | 32 should make sure to invoke this class' version of those methods as well. |
33 The standard super(...) function cannot be used for this, since the base | 33 The standard super(...) function cannot be used for this, since the base |
34 test class is not a 'new style' Python class. | 34 test class is not a 'new style' Python class. |
| 35 |
| 36 Any crashes detected during the test run will automatically generate a test |
| 37 failure exception, to disable this behavior set ignore_crashes = True. |
35 """ | 38 """ |
36 version = 1 | 39 version = 1 |
37 | 40 |
38 auto_login = True | 41 auto_login = True |
39 username = None | 42 username = None |
40 password = None | 43 password = None |
41 | 44 |
42 """Processes that we know crash and are willing to ignore.""" | 45 ignore_crashes = False |
43 crash_blacklist = ['powerm'] | |
44 | 46 |
45 def __init__(self, job, bindir, outputdir): | 47 def __init__(self, job, bindir, outputdir): |
46 self._dns = {} # for saving/restoring dns entries | 48 self._dns = {} # for saving/restoring dns entries |
47 test.test.__init__(self, job, bindir, outputdir) | 49 test.test.__init__(self, job, bindir, outputdir) |
48 | 50 |
49 def xsystem(self, cmd, timeout=None, ignore_status=False): | 51 def xsystem(self, cmd, timeout=None, ignore_status=False): |
50 """Convenience wrapper around cros_ui.xsystem, to save you an import. | 52 """Convenience wrapper around cros_ui.xsystem, to save you an import. |
51 """ | 53 """ |
52 return cros_ui.xsystem(cmd, timeout, ignore_status) | 54 return cros_ui.xsystem(cmd, timeout, ignore_status) |
53 | 55 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 """Tears down fake dns and fake Google Accounts server. If your | 283 """Tears down fake dns and fake Google Accounts server. If your |
282 subclass does not create these objects, you will want to override this | 284 subclass does not create these objects, you will want to override this |
283 method as well. | 285 method as well. |
284 """ | 286 """ |
285 if hasattr(self, '_authServer'): | 287 if hasattr(self, '_authServer'): |
286 self.revert_dns() | 288 self.revert_dns() |
287 self._authServer.stop() | 289 self._authServer.stop() |
288 self._dnsServer.stop() | 290 self._dnsServer.stop() |
289 | 291 |
290 | 292 |
291 def __log_crashed_processes(self, processes): | 293 def __check_for_crashes(self): |
292 """Runs through the log watched by |watcher| to see if a crash was | 294 """Runs through logs collected since initialization to see if any crash |
293 reported for any process names listed in |processes|. | 295 was reported. Crashes are recorded as INFO messages plus raised as a |
| 296 error.TestFail exception. |
294 """ | 297 """ |
295 regex = re.compile(r'Received crash notification for (\w+).+ (sig \d+)', | 298 crashes = [] |
296 re.MULTILINE) | 299 regex = re.compile('Received crash notification for (.+)', re.MULTILINE) |
297 for match in regex.finditer(self._log_reader.get_logs()): | 300 for match in regex.finditer(self._log_reader.get_logs()): |
298 if match.group(1) in processes: | 301 self.job.record('INFO', self.tagged_testname, |
299 self.job.record('INFO', self.tagged_testname, | 302 'Crash detected: %s' % match.group(1)) |
300 "%s crash" % m.group(1), m.group(2)) | 303 crashes.append(match.group(1)) |
| 304 |
| 305 if crashes: |
| 306 raise error.TestFail('Crash(es) detected: %s' % ', '.join(crashes)) |
301 | 307 |
302 | 308 |
303 def cleanup(self): | 309 def cleanup(self): |
304 """Overridden from test.cleanup() to log out when the test is complete. | 310 """Overridden from test.cleanup() to log out when the test is complete. |
305 """ | 311 """ |
306 logpath = chromeos_constants.CHROME_LOG_DIR | 312 logpath = chromeos_constants.CHROME_LOG_DIR |
307 | 313 |
308 try: | 314 try: |
309 for file in os.listdir(logpath): | 315 for file in os.listdir(logpath): |
310 fullpath = os.path.join(logpath, file) | 316 fullpath = os.path.join(logpath, file) |
(...skipping 15 matching lines...) Expand all Loading... |
326 | 332 |
327 if os.path.isfile(chromeos_constants.CRYPTOHOMED_LOG): | 333 if os.path.isfile(chromeos_constants.CRYPTOHOMED_LOG): |
328 try: | 334 try: |
329 base = os.path.basename(chromeos_constants.CRYPTOHOMED_LOG) | 335 base = os.path.basename(chromeos_constants.CRYPTOHOMED_LOG) |
330 shutil.copy(chromeos_constants.CRYPTOHOMED_LOG, | 336 shutil.copy(chromeos_constants.CRYPTOHOMED_LOG, |
331 os.path.join(self.resultsdir, base)) | 337 os.path.join(self.resultsdir, base)) |
332 except (IOError, OSError) as error: | 338 except (IOError, OSError) as error: |
333 logging.error(error) | 339 logging.error(error) |
334 | 340 |
335 self.stop_authserver() | 341 self.stop_authserver() |
336 self.__log_crashed_processes(self.crash_blacklist) | 342 # Make sure this is the last line as it will throw exceptions preventing |
| 343 # subsequent cleanup code from running. |
| 344 if not self.ignore_crashes: |
| 345 self.__check_for_crashes() |
337 | 346 |
338 | 347 |
339 def get_auth_endpoint_misses(self): | 348 def get_auth_endpoint_misses(self): |
340 if hasattr(self, '_authServer'): | 349 if hasattr(self, '_authServer'): |
341 return self._authServer.get_endpoint_misses() | 350 return self._authServer.get_endpoint_misses() |
342 else: | 351 else: |
343 return {} | 352 return {} |
OLD | NEW |