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 3# found in the LICENSE file. 4 5from autotest_lib.client.bin import utils 6from autotest_lib.client.common_lib import error 7from autotest_lib.client.cros import cros_ui, upstart 8from autotest_lib.client.cros.crash import user_crash_test 9 10 11_CRASH_REPORTER_ENABLED_PATH = '/var/lib/crash_reporter/crash-handling-enabled' 12 13 14class logging_UserCrash(user_crash_test.UserCrashTest): 15 """Verifies crash reporting for user processes.""" 16 version = 1 17 18 19 def _get_uptime(self): 20 with open('/proc/uptime', 'r') as f: 21 uptime_seconds = float(f.readline().split()[0]) 22 23 return uptime_seconds 24 25 26 # This test has a tast counterpart, but the tast version only performs a 27 # slightly different function. Specifically, the tast variant does not 28 # verify that crash reporter state is valid before any tests run and 29 # re-initialize crash reporter. 30 # TODO(https://crbug.com/1085194): Write a tast test to verify that crash 31 # reporter's state is good on a "clean" system. 32 def _test_reporter_startup(self): 33 """Test that the core_pattern is set up by crash reporter.""" 34 # Turn off crash filtering so we see the original setting. 35 self.disable_crash_filtering() 36 output = utils.read_file(self._CORE_PATTERN).rstrip() 37 expected_core_pattern = ('|%s --user=%%P:%%s:%%u:%%g:%%f' % 38 self._CRASH_REPORTER_PATH) 39 if output != expected_core_pattern: 40 raise error.TestFail('core pattern should have been %s, not %s' % 41 (expected_core_pattern, output)) 42 43 44 # This test has a critical tast counterpart, but we leave it here because 45 # it verifies that the in_progress_integration_test variable will be set in 46 # autotests. 47 def _test_chronos_crasher(self): 48 """Test a user space crash when running as chronos is handled.""" 49 self._check_crashing_process( 50 'chronos', 51 extra_meta_contents='upload_var_in_progress_integration_test=' 52 'logging_UserCrash') 53 54 55 def initialize(self): 56 user_crash_test.UserCrashTest.initialize(self) 57 58 # If the device has a GUI, return the device to the sign-in screen, as 59 # some tests will fail inside a user session. 60 if upstart.has_service('ui'): 61 cros_ui.restart() 62 63 64 def run_once(self): 65 """ Run all tests once """ 66 self._prepare_crasher() 67 self._populate_symbols() 68 69 # Run the test once without re-initializing 70 # to catch problems with the default crash reporting setup 71 self.run_crash_tests(['reporter_startup'], 72 initialize_crash_reporter=False, 73 must_run_all=False) 74 75 self.run_crash_tests(['reporter_startup', 'chronos_crasher'], 76 initialize_crash_reporter=True) 77