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, shutil, time | 5 import logging, os, shutil, time |
6 from autotest_lib.client.common_lib import error | 6 from autotest_lib.client.common_lib import error |
7 from autotest_lib.server import autotest, site_host_attributes, test | 7 from autotest_lib.server import autotest, site_host_attributes, test |
8 | 8 |
9 _CONSENT_FILE = '/home/chronos/Consent To Send Stats' | |
10 _STOWED_CONSENT_FILE = '/var/lib/kernel-crash-server.consent' | |
11 | |
9 | 12 |
10 class logging_KernelCrashServer(test.test): | 13 class logging_KernelCrashServer(test.test): |
11 version = 1 | 14 version = 1 |
12 | 15 |
13 | 16 |
17 def _exact_copy(self, source, dest): | |
18 """Copy remote source to dest removing dest if source does not exist.""" | |
petkov
2010/09/30 05:29:27
I don't quite understand the comment -- you always
| |
19 self._host.run('rm -f "%s"; cp "%s" "%s" 2>/dev/null; true' % | |
20 (dest, source, dest)) | |
21 | |
22 | |
23 def cleanup(self): | |
24 self._exact_copy(_STOWED_CONSENT_FILE, _CONSENT_FILE) | |
25 test.test.cleanup(self) | |
26 | |
27 | |
28 def _can_disable_consent(self): | |
29 """Returns whether or not host can have consent disabled. | |
30 | |
31 Presence of /etc/send_metrics causes ui.conf job (which starts | |
32 after chromeos_startup) to regenerate a consent file if one | |
33 does not exist. Therefore, we cannot guarantee that | |
34 crash-reporter.conf will start with the file gone if we | |
35 removed it before causing a crash. | |
36 """ | |
37 status = self._host.run('[ -r /etc/send_metrics ]', ignore_status=True) | |
38 return status.exit_status != 0 | |
39 | |
40 | |
41 def _crash_it(self, consent): | |
42 """Crash the host after setting the consent as given.""" | |
43 if consent: | |
44 self._host.run('echo test-consent > "%s"' % _CONSENT_FILE) | |
45 else: | |
46 self._host.run('rm -f "%s"' % _CONSENT_FILE) | |
47 logging.info('KernelCrashServer: crashing %s' % self._host.hostname) | |
48 boot_id = self._host.get_boot_id() | |
49 self._host.run( | |
50 'sh -c "sync; sleep 1; echo bug > /proc/breakme" >/dev/null 2>&1 &') | |
51 self._host.wait_for_restart(old_boot_id=boot_id) | |
52 | |
53 | |
14 def run_once(self, host=None): | 54 def run_once(self, host=None): |
55 self._host = host | |
56 client_attributes = site_host_attributes.HostAttributes(host.hostname) | |
15 client_at = autotest.Autotest(host) | 57 client_at = autotest.Autotest(host) |
58 self._exact_copy(_CONSENT_FILE, _STOWED_CONSENT_FILE) | |
59 | |
16 client_at.run_test('logging_KernelCrash', | 60 client_at.run_test('logging_KernelCrash', |
17 tag='before-crash', | 61 tag='before-crash', |
18 is_before=True) | 62 is_before=True, |
63 consent=True) | |
19 | 64 |
20 client_attributes = site_host_attributes.HostAttributes(host.hostname) | |
21 if not client_attributes.has_working_kcrash: | 65 if not client_attributes.has_working_kcrash: |
22 raise error.TestNAError( | 66 raise error.TestNAError( |
23 'This device is unable to report kernel crashes') | 67 'This device is unable to report kernel crashes') |
24 # Crash the client | |
25 logging.info('KernelCrashServer: crashing %s' % host.hostname) | |
26 boot_id = host.get_boot_id() | |
27 host.run('sh -c "sleep 1; echo bug > /proc/breakme" >/dev/null 2>&1 &') | |
28 host.wait_for_restart(old_boot_id=boot_id) | |
29 | 68 |
30 # Check for crash handling | 69 self._crash_it(True) |
70 | |
71 # Check for crash handling with consent. | |
31 client_at.run_test('logging_KernelCrash', | 72 client_at.run_test('logging_KernelCrash', |
32 tag='after-crash', | 73 tag='after-crash-consent', |
33 is_before=False) | 74 is_before=False, |
75 consent=True) | |
76 | |
77 if not self._can_disable_consent(): | |
78 logging.info('This device always has metrics enabled, ' | |
79 'skipping test of metrics disabled mode.') | |
80 else: | |
81 self._crash_it(False) | |
82 | |
83 # Check for crash handling without consent. | |
84 client_at.run_test('logging_KernelCrash', | |
85 tag='after-crash-no-consent', | |
86 is_before=False, | |
87 consent=False) | |
OLD | NEW |