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, utils | 5 import logging, os, time, utils |
6 from autotest_lib.client.bin import site_login, test | 6 from autotest_lib.client.bin import site_ui_test |
7 from autotest_lib.client.common_lib import error | 7 from autotest_lib.client.common_lib import error |
8 | 8 |
9 class login_LogoutProcessCleanup(test.test): | 9 class login_LogoutProcessCleanup(site_ui_test.UITest): |
10 version = 1 | 10 version = 1 |
11 | 11 |
12 def __get_session_manager_pid(self): | 12 def __get_session_manager_pid(self): |
13 """Get the PID of the session manager.""" | 13 """Get the PID of the session manager.""" |
14 | 14 |
15 return utils.system_output('pgrep "^session_manager$"', | 15 return utils.system_output('pgrep "^session_manager$"', |
16 ignore_status = True) | 16 ignore_status = True) |
17 | 17 |
18 | 18 |
19 def __get_chronos_pids(self): | 19 def __get_chronos_pids(self): |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 for p in pids: | 72 for p in pids: |
73 if self.__is_process_dead(p): | 73 if self.__is_process_dead(p): |
74 continue | 74 continue |
75 if not self.__process_has_ancestor(p, session_manager): | 75 if not self.__process_has_ancestor(p, session_manager): |
76 logging.info('found pid (%s) owned by chronos and not ' | 76 logging.info('found pid (%s) owned by chronos and not ' |
77 'started by the session manager' % p) | 77 'started by the session manager' % p) |
78 return True | 78 return True |
79 return False | 79 return False |
80 | 80 |
81 | 81 |
82 def setup(self): | 82 def run_once(self, is_control=False, timeout=10): |
83 site_login.setup_autox(self) | |
84 | |
85 | |
86 def run_once(self, script='autox_script.json', is_control=False, | |
87 timeout=10): | |
88 logged_in = site_login.logged_in() | |
89 | |
90 # Require that we start the test logged in | |
91 if not logged_in: | |
92 site_login.attempt_login(self, script) | |
93 | |
94 # Start a process as chronos. This should get killed when logging out. | 83 # Start a process as chronos. This should get killed when logging out. |
95 bg_job = utils.BgJob('su chronos -c "sleep 3600"') | 84 bg_job = utils.BgJob('su chronos -c "sleep 3600"') |
96 | 85 |
97 session_manager = self.__get_session_manager_pid() | 86 session_manager = self.__get_session_manager_pid() |
98 if session_manager == "": | 87 if session_manager == "": |
99 raise error.TestError('Could not find session manager pid') | 88 raise error.TestError('Could not find session manager pid') |
100 | 89 |
101 if not self.__has_chronos_processes(session_manager): | 90 if not self.__has_chronos_processes(session_manager): |
102 raise error.TestFail('Expected to find processes owned by chronos ' | 91 raise error.TestFail('Expected to find processes owned by chronos ' |
103 'that were not started by the session manager while logged in.') | 92 'that were not started by the session manager while logged in.') |
104 | 93 |
105 site_login.attempt_logout() | 94 self.logout() |
106 | 95 |
107 logging.info('Logged out, searching for processes that should be dead') | 96 logging.info('Logged out, searching for processes that should be dead') |
108 | 97 |
109 # Wait until we have a new session manager. At that point, all | 98 # Wait until we have a new session manager. At that point, all |
110 # old processes should be dead. | 99 # old processes should be dead. |
111 old_session_manager = session_manager | 100 old_session_manager = session_manager |
112 while session_manager == "" or session_manager == old_session_manager: | 101 while session_manager == "" or session_manager == old_session_manager: |
113 time.sleep(0.1) | 102 time.sleep(0.1) |
114 session_manager = self.__get_session_manager_pid() | 103 session_manager = self.__get_session_manager_pid() |
115 | 104 |
116 if self.__has_chronos_processes(session_manager): | 105 if self.__has_chronos_processes(session_manager): |
117 # Make sure the test job we started is dead. | 106 # Make sure the test job we started is dead. |
118 if bg_job.sp.returncode == None: | 107 if bg_job.sp.returncode == None: |
119 bg_job.sp.kill() | 108 bg_job.sp.kill() |
120 raise error.TestFail('Expected NOT to find processes owned by ' | 109 raise error.TestFail('Expected NOT to find processes owned by ' |
121 'chronos that were not started by the session manager ' | 110 'chronos that were not started by the session manager ' |
122 'while logged out.') | 111 'while logged out.') |
123 | |
124 # Reset the logged in state to how we started | |
125 if logged_in: | |
126 site_login.attempt_login(self, script) | |
OLD | NEW |