| 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 errno, logging, os, re, signal, subprocess, time | 5 import errno, logging, os, re, signal, subprocess, time |
| 6 import common | 6 import common |
| 7 import constants as chromeos_constants, cryptohome, ui | 7 import constants as chromeos_constants, cros_logging, cryptohome, ui |
| 8 from autotest_lib.client.bin import test, utils, site_log_reader | 8 from autotest_lib.client.bin import utils |
| 9 from autotest_lib.client.common_lib import error | 9 from autotest_lib.client.common_lib import error |
| 10 | 10 |
| 11 | 11 |
| 12 _DEFAULT_TIMEOUT = 30 | 12 _DEFAULT_TIMEOUT = 30 |
| 13 | 13 |
| 14 | 14 |
| 15 class TimeoutError(error.TestError): | 15 class TimeoutError(error.TestError): |
| 16 """Error raised when we time out while waiting on a condition.""" | 16 """Error raised when we time out while waiting on a condition.""" |
| 17 pass | 17 pass |
| 18 | 18 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 (username, password)) | 131 (username, password)) |
| 132 | 132 |
| 133 if not __get_session_manager_pid(): | 133 if not __get_session_manager_pid(): |
| 134 raise UnexpectedCondition("Session manager is not running") | 134 raise UnexpectedCondition("Session manager is not running") |
| 135 | 135 |
| 136 if logged_in(): | 136 if logged_in(): |
| 137 raise UnexpectedCondition("Already logged in") | 137 raise UnexpectedCondition("Already logged in") |
| 138 | 138 |
| 139 # Mark /var/log/messages now; we'll run through all subsequent log messages | 139 # Mark /var/log/messages now; we'll run through all subsequent log messages |
| 140 # if we couldn't log in to see if the browser crashed. | 140 # if we couldn't log in to see if the browser crashed. |
| 141 log_reader = site_log_reader.LogReader() | 141 log_reader = cros_logging.LogReader() |
| 142 log_reader.set_start_by_current() | 142 log_reader.set_start_by_current() |
| 143 | 143 |
| 144 ax = ui.get_autox() | 144 ax = ui.get_autox() |
| 145 # navigate to login screen | 145 # navigate to login screen |
| 146 ax.send_hotkey("Ctrl+Alt+L") | 146 ax.send_hotkey("Ctrl+Alt+L") |
| 147 # escape out of any login screen menus (e.g., the network selection menu) | 147 # escape out of any login screen menus (e.g., the network selection menu) |
| 148 ax.send_hotkey("Escape") | 148 ax.send_hotkey("Escape") |
| 149 time.sleep(0.5) | 149 time.sleep(0.5) |
| 150 if (username): | 150 if (username): |
| 151 # focus username | 151 # focus username |
| (...skipping 26 matching lines...) Expand all Loading... |
| 178 TimeoutError: logout didn't complete before timeout | 178 TimeoutError: logout didn't complete before timeout |
| 179 UnexpectedCondition: user is not logged in | 179 UnexpectedCondition: user is not logged in |
| 180 """ | 180 """ |
| 181 if not logged_in(): | 181 if not logged_in(): |
| 182 raise UnexpectedCondition('Already logged out') | 182 raise UnexpectedCondition('Already logged out') |
| 183 | 183 |
| 184 oldpid = __get_session_manager_pid() | 184 oldpid = __get_session_manager_pid() |
| 185 | 185 |
| 186 # Mark /var/log/messages now; we'll run through all subsequent log messages | 186 # Mark /var/log/messages now; we'll run through all subsequent log messages |
| 187 # if we couldn't TERM and restart the session manager. | 187 # if we couldn't TERM and restart the session manager. |
| 188 log_reader = site_log_reader.LogReader() | 188 |
| 189 log_reader = cros_logging.LogReader() |
| 189 log_reader.set_start_by_current() | 190 log_reader.set_start_by_current() |
| 190 | 191 |
| 191 # Gracefully exiting the session manager causes the user's session to end. | 192 # Gracefully exiting the session manager causes the user's session to end. |
| 192 utils.system('pkill -TERM -o ^%s$' % chromeos_constants.SESSION_MANAGER) | 193 utils.system('pkill -TERM -o ^%s$' % chromeos_constants.SESSION_MANAGER) |
| 193 | 194 |
| 194 wait_for_condition( | 195 wait_for_condition( |
| 195 condition=lambda: __session_manager_restarted(oldpid), | 196 condition=lambda: __session_manager_restarted(oldpid), |
| 196 timeout_msg='Timed out waiting for logout', | 197 timeout_msg='Timed out waiting for logout', |
| 197 timeout=timeout, | 198 timeout=timeout, |
| 198 process='session_manager', | 199 process='session_manager', |
| 199 log_reader=log_reader, | 200 log_reader=log_reader, |
| 200 crash_msg='session_manager crashed while shutting down.') | 201 crash_msg='session_manager crashed while shutting down.') |
| 201 | 202 |
| 202 | 203 |
| 203 def wait_for_browser(timeout=_DEFAULT_TIMEOUT): | 204 def wait_for_browser(timeout=_DEFAULT_TIMEOUT): |
| 204 """Wait until a Chrome process is running. | 205 """Wait until a Chrome process is running. |
| 205 | 206 |
| 206 Args: | 207 Args: |
| 207 timeout: float number of seconds to wait | 208 timeout: float number of seconds to wait |
| 208 | 209 |
| 209 Raises: | 210 Raises: |
| 210 TimeoutError: Chrome didn't start before timeout | 211 TimeoutError: Chrome didn't start before timeout |
| 211 """ | 212 """ |
| 212 # Mark /var/log/messages now; we'll run through all subsequent log messages | 213 # Mark /var/log/messages now; we'll run through all subsequent log messages |
| 213 # if we couldn't start chrome to see if the browser crashed. | 214 # if we couldn't start chrome to see if the browser crashed. |
| 214 log_reader = site_log_reader.LogReader() | 215 log_reader = cros_logging.LogReader() |
| 215 log_reader.set_start_by_current() | 216 log_reader.set_start_by_current() |
| 216 wait_for_condition( | 217 wait_for_condition( |
| 217 lambda: os.system('pgrep ^%s$' % chromeos_constants.BROWSER) == 0, | 218 lambda: os.system('pgrep ^%s$' % chromeos_constants.BROWSER) == 0, |
| 218 timeout_msg='Timed out waiting for Chrome to start', | 219 timeout_msg='Timed out waiting for Chrome to start', |
| 219 timeout=timeout, | 220 timeout=timeout, |
| 220 process='chrome', | 221 process='chrome', |
| 221 log_reader=log_reader, | 222 log_reader=log_reader, |
| 222 crash_msg='Chrome crashed while starting up.') | 223 crash_msg='Chrome crashed while starting up.') |
| 223 | 224 |
| 224 | 225 |
| 225 def wait_for_cryptohome(timeout=_DEFAULT_TIMEOUT): | 226 def wait_for_cryptohome(timeout=_DEFAULT_TIMEOUT): |
| 226 """Wait until cryptohome is mounted. | 227 """Wait until cryptohome is mounted. |
| 227 | 228 |
| 228 Args: | 229 Args: |
| 229 timeout: float number of seconds to wait | 230 timeout: float number of seconds to wait |
| 230 | 231 |
| 231 Raises: | 232 Raises: |
| 232 TimeoutError: cryptohome wasn't mounted before timeout | 233 TimeoutError: cryptohome wasn't mounted before timeout |
| 233 """ | 234 """ |
| 234 # Mark /var/log/messages now; we'll run through all subsequent log messages | 235 # Mark /var/log/messages now; we'll run through all subsequent log messages |
| 235 # if we couldn't get the browser up to see if the browser crashed. | 236 # if we couldn't get the browser up to see if the browser crashed. |
| 236 log_reader = site_log_reader.LogReader() | 237 log_reader = cros_logging.LogReader() |
| 237 log_reader.set_start_by_current() | 238 log_reader.set_start_by_current() |
| 238 wait_for_condition( | 239 wait_for_condition( |
| 239 condition=lambda: cryptohome.is_mounted(), | 240 condition=lambda: cryptohome.is_mounted(), |
| 240 timeout_msg='Timed out waiting for cryptohome to be mounted', | 241 timeout_msg='Timed out waiting for cryptohome to be mounted', |
| 241 timeout=timeout, | 242 timeout=timeout, |
| 242 process='cryptohomed', | 243 process='cryptohomed', |
| 243 log_reader=log_reader, | 244 log_reader=log_reader, |
| 244 crash_msg='cryptohomed crashed during mount attempt') | 245 crash_msg='cryptohomed crashed during mount attempt') |
| 245 | 246 |
| 246 | 247 |
| 247 def wait_for_login_prompt(timeout=_DEFAULT_TIMEOUT): | 248 def wait_for_login_prompt(timeout=_DEFAULT_TIMEOUT): |
| 248 """Wait the login prompt is on screen and ready | 249 """Wait the login prompt is on screen and ready |
| 249 | 250 |
| 250 Args: | 251 Args: |
| 251 timeout: float number of seconds to wait | 252 timeout: float number of seconds to wait |
| 252 | 253 |
| 253 Raises: | 254 Raises: |
| 254 TimeoutError: Login prompt didn't get up before timeout | 255 TimeoutError: Login prompt didn't get up before timeout |
| 255 """ | 256 """ |
| 256 # Mark /var/log/messages now; we'll run through all subsequent log messages | 257 # Mark /var/log/messages now; we'll run through all subsequent log messages |
| 257 # if we couldn't get the browser up to see if the browser crashed. | 258 # if we couldn't get the browser up to see if the browser crashed. |
| 258 log_reader = site_log_reader.LogReader() | 259 log_reader = cros_logging.LogReader() |
| 259 log_reader.set_start_by_current() | 260 log_reader.set_start_by_current() |
| 260 wait_for_condition( | 261 wait_for_condition( |
| 261 condition=lambda: os.access( | 262 condition=lambda: os.access( |
| 262 chromeos_constants.LOGIN_PROMPT_READY_MAGIC_FILE, os.F_OK), | 263 chromeos_constants.LOGIN_PROMPT_READY_MAGIC_FILE, os.F_OK), |
| 263 timeout_msg='Timed out waiting for login prompt', | 264 timeout_msg='Timed out waiting for login prompt', |
| 264 timeout=timeout, | 265 timeout=timeout, |
| 265 process='chrome', | 266 process='chrome', |
| 266 log_reader=log_reader, | 267 log_reader=log_reader, |
| 267 crash_msg='Chrome crashed before the login prompt.') | 268 crash_msg='Chrome crashed before the login prompt.') |
| 268 | 269 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 286 """Wait until the initial Chrome window is mapped. | 287 """Wait until the initial Chrome window is mapped. |
| 287 | 288 |
| 288 Args: | 289 Args: |
| 289 timeout: float number of seconds to wait | 290 timeout: float number of seconds to wait |
| 290 | 291 |
| 291 Raises: | 292 Raises: |
| 292 TimeoutError: Chrome window wasn't mapped before timeout | 293 TimeoutError: Chrome window wasn't mapped before timeout |
| 293 """ | 294 """ |
| 294 # Mark /var/log/messages now; we'll run through all subsequent log messages | 295 # Mark /var/log/messages now; we'll run through all subsequent log messages |
| 295 # if we couldn't get the browser up to see if the browser crashed. | 296 # if we couldn't get the browser up to see if the browser crashed. |
| 296 log_reader = site_log_reader.LogReader() | 297 log_reader = cros_logging.LogReader() |
| 297 log_reader.set_start_by_current() | 298 log_reader.set_start_by_current() |
| 298 wait_for_condition( | 299 wait_for_condition( |
| 299 lambda: os.access( | 300 lambda: os.access( |
| 300 chromeos_constants.CHROME_WINDOW_MAPPED_MAGIC_FILE, os.F_OK), | 301 chromeos_constants.CHROME_WINDOW_MAPPED_MAGIC_FILE, os.F_OK), |
| 301 'Timed out waiting for initial Chrome window', | 302 'Timed out waiting for initial Chrome window', |
| 302 timeout=timeout, | 303 timeout=timeout, |
| 303 process='chrome', | 304 process='chrome', |
| 304 log_reader=log_reader, | 305 log_reader=log_reader, |
| 305 crash_msg='Chrome crashed before first tab rendered.') | 306 crash_msg='Chrome crashed before first tab rendered.') |
| 306 | 307 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 except (IOError, OSError) as error: | 368 except (IOError, OSError) as error: |
| 368 logging.error(error) | 369 logging.error(error) |
| 369 | 370 |
| 370 # Restart the UI. | 371 # Restart the UI. |
| 371 nuke_login_manager() | 372 nuke_login_manager() |
| 372 utils.poll_for_condition( | 373 utils.poll_for_condition( |
| 373 lambda: __session_manager_restarted(oldpid), | 374 lambda: __session_manager_restarted(oldpid), |
| 374 TimeoutError('Timed out waiting for logout'), | 375 TimeoutError('Timed out waiting for logout'), |
| 375 timeout) | 376 timeout) |
| 376 wait_for_login_prompt() | 377 wait_for_login_prompt() |
| OLD | NEW |