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, time | 5 import logging, os, time |
6 from autotest_lib.client.bin import site_log_reader, site_ui_test, test | 6 from autotest_lib.client.bin import site_log_reader, site_ui_test, test |
7 from autotest_lib.client.common_lib import error, utils | 7 from autotest_lib.client.common_lib import error, utils |
8 | 8 |
9 _CRASH_PATH = '/sbin/crash_reporter' | 9 _CRASH_PATH = '/sbin/crash_reporter' |
10 _PENDING_SHUTDOWN_PATH = '/var/lib/crash_reporter/pending_clean_shutdown' | 10 _PENDING_SHUTDOWN_PATH = '/var/lib/crash_reporter/pending_clean_shutdown' |
| 11 _UNCLEAN_SHUTDOWN_DETECTED_PATH = '/tmp/unclean-shutdown-detected' |
11 _UNCLEAN_SHUTDOWN_MESSAGE = 'Last shutdown was not clean' | 12 _UNCLEAN_SHUTDOWN_MESSAGE = 'Last shutdown was not clean' |
12 | 13 |
13 class logging_UncleanShutdown(site_ui_test.UITest): | 14 class logging_UncleanShutdown(site_ui_test.UITest): |
14 version = 1 | 15 version = 1 |
15 auto_login = False | 16 auto_login = False |
16 | 17 |
17 | 18 |
18 def run_once(self): | 19 def run_once(self): |
19 if not os.path.exists(_PENDING_SHUTDOWN_PATH): | 20 if not os.path.exists(_PENDING_SHUTDOWN_PATH): |
20 raise error.TestFail('pending shutdown file, %s, not found' % | 21 raise error.TestFail('pending shutdown file, %s, not found' % |
21 _PENDING_SHUTDOWN_PATH) | 22 _PENDING_SHUTDOWN_PATH) |
22 | 23 |
23 log_reader = site_log_reader.LogReader() | 24 log_reader = site_log_reader.LogReader() |
24 log_reader.set_start_by_reboot(-1) | 25 log_reader.set_start_by_reboot(-1) |
25 | 26 |
26 if log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE): | 27 if log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE): |
27 raise error.TestFail( | 28 raise error.TestFail( |
28 'Unexpectedly detected kernel crash during boot') | 29 'Unexpectedly detected unclean shutdown during boot') |
| 30 |
| 31 if os.path.exists(_UNCLEAN_SHUTDOWN_DETECTED_PATH): |
| 32 raise error.TestFail('an unclean shutdown file was detected') |
29 | 33 |
30 # Log in and out twice to make sure that doesn't cause | 34 # Log in and out twice to make sure that doesn't cause |
31 # an unclean shutdown message. | 35 # an unclean shutdown message. |
32 for i in range(2): | 36 for i in range(2): |
33 self.login() | 37 self.login() |
34 time.sleep(5) | 38 time.sleep(5) |
35 self.logout() | 39 self.logout() |
36 time.sleep(5) | 40 time.sleep(5) |
37 | 41 |
38 if log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE): | 42 if log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE): |
39 logging.info('Unexpected logs: ', log_reader.get_logs()) | 43 logging.info('Unexpected logs: ', log_reader.get_logs()) |
40 raise error.TestFail( | 44 raise error.TestFail( |
41 'Unexpectedly detected kernel crash during login/logout') | 45 'Unexpectedly detected kernel crash during login/logout') |
42 | 46 |
| 47 if os.path.exists(_UNCLEAN_SHUTDOWN_DETECTED_PATH): |
| 48 raise error.TestFail('an unclean shutdown file was generated') |
| 49 |
43 # Run the shutdown and verify it does not complain of unclean | 50 # Run the shutdown and verify it does not complain of unclean |
44 # shutdown. | 51 # shutdown. |
45 | 52 |
46 log_reader.set_start_by_current() | 53 log_reader.set_start_by_current() |
47 utils.system('%s --clean_shutdown' % _CRASH_PATH) | 54 utils.system('%s --clean_shutdown' % _CRASH_PATH) |
48 utils.system('%s --init' % _CRASH_PATH) | 55 utils.system('%s --init' % _CRASH_PATH) |
49 | 56 |
50 if log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE): | 57 if (log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE) or |
| 58 os.path.exists(_UNCLEAN_SHUTDOWN_DETECTED_PATH)): |
51 raise error.TestFail('Incorrectly signalled unclean shutdown') | 59 raise error.TestFail('Incorrectly signalled unclean shutdown') |
52 | 60 |
53 # Now simulate an unclean shutdown and test handling. | 61 # Now simulate an unclean shutdown and test handling. |
54 | 62 |
55 log_reader.set_start_by_current() | 63 log_reader.set_start_by_current() |
56 utils.system('%s --init' % _CRASH_PATH) | 64 utils.system('%s --init' % _CRASH_PATH) |
57 | 65 |
58 if not log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE): | 66 if not log_reader.can_find(_UNCLEAN_SHUTDOWN_MESSAGE): |
59 raise error.TestFail('Did not signal unclean shutdown when should') | 67 raise error.TestFail('Did not signal unclean shutdown when should') |
| 68 |
| 69 if not os.path.exists(_UNCLEAN_SHUTDOWN_DETECTED_PATH): |
| 70 raise error.TestFail('Did not touch unclean shutdown file') |
| 71 |
| 72 os.remove(_UNCLEAN_SHUTDOWN_DETECTED_PATH) |
OLD | NEW |