| OLD | NEW |
| 1 # Copyright (C) 2012 Google Inc. All rights reserved. | 1 # Copyright (C) 2012 Google Inc. All rights reserved. |
| 2 # | 2 # |
| 3 # Redistribution and use in source and binary forms, with or without | 3 # Redistribution and use in source and binary forms, with or without |
| 4 # modification, are permitted provided that the following conditions are | 4 # modification, are permitted provided that the following conditions are |
| 5 # met: | 5 # met: |
| 6 # | 6 # |
| 7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
| 8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
| 9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
| 10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 def _battery_level_for_device(self, commands): | 396 def _battery_level_for_device(self, commands): |
| 397 battery_status = commands.run(['shell', 'dumpsys', 'battery']) | 397 battery_status = commands.run(['shell', 'dumpsys', 'battery']) |
| 398 if 'Error' in battery_status or "Can't find service: battery" in battery
_status: | 398 if 'Error' in battery_status or "Can't find service: battery" in battery
_status: |
| 399 _log.warning('Unable to read the battery level from device with seri
al "%s".', commands.get_serial()) | 399 _log.warning('Unable to read the battery level from device with seri
al "%s".', commands.get_serial()) |
| 400 return 0 | 400 return 0 |
| 401 | 401 |
| 402 return int(re.findall(r'level: (\d+)', battery_status)[0]) | 402 return int(re.findall(r'level: (\d+)', battery_status)[0]) |
| 403 | 403 |
| 404 def _is_device_screen_on(self, commands): | 404 def _is_device_screen_on(self, commands): |
| 405 power_status = commands.run(['shell', 'dumpsys', 'power']) | 405 power_status = commands.run(['shell', 'dumpsys', 'power']) |
| 406 return 'mScreenOn=true' in power_status or 'mScreenOn=SCREEN_ON_BIT' in
power_status or 'Display Power: state=ON' in power_status | 406 return ('mScreenOn=true' in power_status or |
| 407 'mScreenOn=SCREEN_ON_BIT' in power_status or |
| 408 'Display Power: state=ON' in power_status) |
| 407 | 409 |
| 408 | 410 |
| 409 class AndroidPort(base.Port): | 411 class AndroidPort(base.Port): |
| 410 port_name = 'android' | 412 port_name = 'android' |
| 411 | 413 |
| 412 # Avoid initializing the adb path [worker count]+1 times by storing it as a
static member. | 414 # Avoid initializing the adb path [worker count]+1 times by storing it as a
static member. |
| 413 _adb_path = None | 415 _adb_path = None |
| 414 | 416 |
| 415 SUPPORTED_VERSIONS = ('android') | 417 SUPPORTED_VERSIONS = ('android') |
| 416 | 418 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 440 | 442 |
| 441 # Initialize the AndroidDevices class which tracks available devices. | 443 # Initialize the AndroidDevices class which tracks available devices. |
| 442 default_devices = None | 444 default_devices = None |
| 443 if hasattr(self._options, 'adb_devices') and len(self._options.adb_devic
es): | 445 if hasattr(self._options, 'adb_devices') and len(self._options.adb_devic
es): |
| 444 default_devices = self._options.adb_devices | 446 default_devices = self._options.adb_devices |
| 445 | 447 |
| 446 self._debug_logging = self.get_option('android_logging') | 448 self._debug_logging = self.get_option('android_logging') |
| 447 self._devices = AndroidDevices(default_devices, self._debug_logging) | 449 self._devices = AndroidDevices(default_devices, self._debug_logging) |
| 448 | 450 |
| 449 # Tell AndroidCommands where to search for the "adb" command. | 451 # Tell AndroidCommands where to search for the "adb" command. |
| 450 AndroidCommands.set_adb_command_path_options(['adb', | 452 AndroidCommands.set_adb_command_path_options( |
| 451 self.path_from_chromium_ba
se('third_party', 'android_tools', 'sdk', 'platform-tools', 'adb')]) | 453 ['adb', self.path_from_chromium_base('third_party', 'android_tools',
'sdk', 'platform-tools', 'adb')]) |
| 452 | 454 |
| 453 prepared_devices = self.get_option('prepared_devices', []) | 455 prepared_devices = self.get_option('prepared_devices', []) |
| 454 for serial in prepared_devices: | 456 for serial in prepared_devices: |
| 455 self._devices.set_device_prepared(serial) | 457 self._devices.set_device_prepared(serial) |
| 456 | 458 |
| 457 def default_smoke_test_only(self): | 459 def default_smoke_test_only(self): |
| 458 return True | 460 return True |
| 459 | 461 |
| 460 # Local public methods. | 462 # Local public methods. |
| 461 def path_to_forwarder(self): | 463 def path_to_forwarder(self): |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 self._log_error('Failed to start the content_shell application. Retr
ies=%d. Log:%s' % (retries, self._get_logcat())) | 1139 self._log_error('Failed to start the content_shell application. Retr
ies=%d. Log:%s' % (retries, self._get_logcat())) |
| 1138 self.stop() | 1140 self.stop() |
| 1139 time.sleep(2) | 1141 time.sleep(2) |
| 1140 self._abort('Failed to start the content_shell application multiple time
s. Giving up.') | 1142 self._abort('Failed to start the content_shell application multiple time
s. Giving up.') |
| 1141 | 1143 |
| 1142 def _start_once(self, pixel_tests, per_test_args): | 1144 def _start_once(self, pixel_tests, per_test_args): |
| 1143 super(ChromiumAndroidDriver, self)._start(pixel_tests, per_test_args, wa
it_for_ready=False) | 1145 super(ChromiumAndroidDriver, self)._start(pixel_tests, per_test_args, wa
it_for_ready=False) |
| 1144 | 1146 |
| 1145 self._log_debug('Starting forwarder') | 1147 self._log_debug('Starting forwarder') |
| 1146 self._forwarder_process = self._port._server_process_constructor( | 1148 self._forwarder_process = self._port._server_process_constructor( |
| 1147 self._port, 'Forwarder', self._android_commands.adb_command() + ['sh
ell', '%s -no-spawn-daemon %s' % (self._driver_details.device_forwarder_path(),
FORWARD_PORTS)]) | 1149 self._port, 'Forwarder', self._android_commands.adb_command() + |
| 1150 ['shell', '%s -no-spawn-daemon %s' % (self._driver_details.device_fo
rwarder_path(), FORWARD_PORTS)]) |
| 1148 self._forwarder_process.start() | 1151 self._forwarder_process.start() |
| 1149 | 1152 |
| 1150 deadline = time.time() + DRIVER_START_STOP_TIMEOUT_SECS | 1153 deadline = time.time() + DRIVER_START_STOP_TIMEOUT_SECS |
| 1151 if not self._wait_for_server_process_output(self._forwarder_process, dea
dline, 'Forwarding device port'): | 1154 if not self._wait_for_server_process_output(self._forwarder_process, dea
dline, 'Forwarding device port'): |
| 1152 return False | 1155 return False |
| 1153 | 1156 |
| 1154 self._android_commands.run(['logcat', '-c']) | 1157 self._android_commands.run(['logcat', '-c']) |
| 1155 | 1158 |
| 1156 cmd_line_file_path = self._driver_details.command_line_file() | 1159 cmd_line_file_path = self._driver_details.command_line_file() |
| 1157 original_cmd_line_file_path = cmd_line_file_path + '.orig' | 1160 original_cmd_line_file_path = cmd_line_file_path + '.orig' |
| 1158 if self._android_commands.file_exists( | 1161 if self._android_commands.file_exists( |
| 1159 cmd_line_file_path) and not self._android_commands.file_exists(o
riginal_cmd_line_file_path): | 1162 cmd_line_file_path) and not self._android_commands.file_exists(o
riginal_cmd_line_file_path): |
| 1160 # We check for both the normal path and the backup because we do not
want to step | 1163 # We check for both the normal path and the backup because we do not
want to step |
| 1161 # on the backup. Otherwise, we'd clobber the backup whenever we chan
ged the | 1164 # on the backup. Otherwise, we'd clobber the backup whenever we chan
ged the |
| 1162 # command line during the run. | 1165 # command line during the run. |
| 1163 self._android_commands.run(['shell', 'mv', cmd_line_file_path, origi
nal_cmd_line_file_path]) | 1166 self._android_commands.run(['shell', 'mv', cmd_line_file_path, origi
nal_cmd_line_file_path]) |
| 1164 | 1167 |
| 1165 self._android_commands.run(['shell', 'echo'] + self._android_driver_cmd_
line(pixel_tests, | 1168 self._android_commands.run( |
| 1166
per_test_args) + ['>', self._driver_details.command_line_file()]) | 1169 ['shell', 'echo'] + |
| 1170 self._android_driver_cmd_line(pixel_tests, per_test_args) + |
| 1171 ['>', self._driver_details.command_line_file()]) |
| 1167 self._created_cmd_line = True | 1172 self._created_cmd_line = True |
| 1168 | 1173 |
| 1169 self._android_commands.run(['shell', 'rm', '-rf', self._driver_details.d
evice_crash_dumps_directory()]) | 1174 self._android_commands.run(['shell', 'rm', '-rf', self._driver_details.d
evice_crash_dumps_directory()]) |
| 1170 self._android_commands.mkdir(self._driver_details.device_crash_dumps_dir
ectory(), chmod='777') | 1175 self._android_commands.mkdir(self._driver_details.device_crash_dumps_dir
ectory(), chmod='777') |
| 1171 | 1176 |
| 1172 start_result = self._android_commands.run( | 1177 start_result = self._android_commands.run( |
| 1173 ['shell', 'am', 'start', '-e', 'RunInSubThread', '-n', self._driver_
details.activity_name()]) | 1178 ['shell', 'am', 'start', '-e', 'RunInSubThread', '-n', self._driver_
details.activity_name()]) |
| 1174 if start_result.find('Exception') != -1: | 1179 if start_result.find('Exception') != -1: |
| 1175 self._log_error('Failed to start the content_shell application. Exce
ption:\n' + start_result) | 1180 self._log_error('Failed to start the content_shell application. Exce
ption:\n' + start_result) |
| 1176 return False | 1181 return False |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1207 # If normal_startup_event is not set in time, the main thread mu
st be blocked at | 1212 # If normal_startup_event is not set in time, the main thread mu
st be blocked at |
| 1208 # reading/writing the fifo. Kill the fifo reading/writing proces
ses to let the | 1213 # reading/writing the fifo. Kill the fifo reading/writing proces
ses to let the |
| 1209 # main thread escape from the deadlocked state. After that, the
main thread will | 1214 # main thread escape from the deadlocked state. After that, the
main thread will |
| 1210 # treat this as a crash. | 1215 # treat this as a crash. |
| 1211 self._log_error('Deadlock detected. Processes killed.') | 1216 self._log_error('Deadlock detected. Processes killed.') |
| 1212 for i in processes: | 1217 for i in processes: |
| 1213 i.kill() | 1218 i.kill() |
| 1214 | 1219 |
| 1215 # Start a thread to kill the pipe reading/writing processes on deadlock
of the fifos during startup. | 1220 # Start a thread to kill the pipe reading/writing processes on deadlock
of the fifos during startup. |
| 1216 normal_startup_event = threading.Event() | 1221 normal_startup_event = threading.Event() |
| 1217 threading.Thread(name='DeadlockDetector', target=deadlock_detector, | 1222 threading.Thread( |
| 1218 args=([self._server_process, self._read_stdout_process,
self._read_stderr_process], normal_startup_event)).start() | 1223 name='DeadlockDetector', |
| 1224 target=deadlock_detector, |
| 1225 args=([self._server_process, self._read_stdout_process, self._read_s
tderr_process], normal_startup_event)).start() |
| 1219 | 1226 |
| 1220 # The test driver might crash during startup or when the deadlock detect
or hits | 1227 # The test driver might crash during startup or when the deadlock detect
or hits |
| 1221 # a deadlock and kills the fifo reading/writing processes. | 1228 # a deadlock and kills the fifo reading/writing processes. |
| 1222 if not self._wait_for_server_process_output(self._server_process, deadli
ne, '#READY'): | 1229 if not self._wait_for_server_process_output(self._server_process, deadli
ne, '#READY'): |
| 1223 return False | 1230 return False |
| 1224 | 1231 |
| 1225 # Inform the deadlock detector that the startup is successful without de
adlock. | 1232 # Inform the deadlock detector that the startup is successful without de
adlock. |
| 1226 normal_startup_event.set() | 1233 normal_startup_event.set() |
| 1227 self._log_debug("content_shell is ready") | 1234 self._log_debug("content_shell is ready") |
| 1228 return True | 1235 return True |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1308 return command | 1315 return command |
| 1309 | 1316 |
| 1310 def _read_prompt(self, deadline): | 1317 def _read_prompt(self, deadline): |
| 1311 last_char = '' | 1318 last_char = '' |
| 1312 while True: | 1319 while True: |
| 1313 current_char = self._server_process.read_stdout(deadline, 1) | 1320 current_char = self._server_process.read_stdout(deadline, 1) |
| 1314 if current_char == ' ': | 1321 if current_char == ' ': |
| 1315 if last_char in ('#', '$'): | 1322 if last_char in ('#', '$'): |
| 1316 return | 1323 return |
| 1317 last_char = current_char | 1324 last_char = current_char |
| OLD | NEW |