OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium 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 """Provides a variety of device interactions based on adb. | 5 """Provides a variety of device interactions based on adb. |
6 | 6 |
7 Eventually, this will be based on adb_wrapper. | 7 Eventually, this will be based on adb_wrapper. |
8 """ | 8 """ |
9 # pylint: disable=unused-argument | 9 # pylint: disable=unused-argument |
10 | 10 |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 if not output: | 1048 if not output: |
1049 return '' | 1049 return '' |
1050 elif len(output) == 1: | 1050 elif len(output) == 1: |
1051 return output[0] | 1051 return output[0] |
1052 else: | 1052 else: |
1053 msg = 'one line of output was expected, but got: %s' | 1053 msg = 'one line of output was expected, but got: %s' |
1054 raise device_errors.CommandFailedError(msg % output, str(self)) | 1054 raise device_errors.CommandFailedError(msg % output, str(self)) |
1055 else: | 1055 else: |
1056 return output | 1056 return output |
1057 | 1057 |
1058 def _RunPipedShellCommand(self, script, **kwargs): | 1058 def _RunPipedShellCommand(self, script, check_return=True, **kwargs): |
1059 PIPESTATUS_LEADER = 'PIPESTATUS: ' | 1059 PIPESTATUS_LEADER = 'PIPESTATUS: ' |
1060 | 1060 |
1061 script += '; echo "%s${PIPESTATUS[@]}"' % PIPESTATUS_LEADER | 1061 script += '; echo "%s${PIPESTATUS[@]}"' % PIPESTATUS_LEADER |
1062 kwargs.update(shell=True, check_return=True) | 1062 kwargs.update(shell=True) |
1063 output = self.RunShellCommand(script, **kwargs) | 1063 output = self.RunShellCommand(script, **kwargs) |
1064 pipestatus_line = output[-1] | 1064 pipestatus_line = output[-1] |
1065 | 1065 |
1066 if not pipestatus_line.startswith(PIPESTATUS_LEADER): | 1066 if not pipestatus_line.startswith(PIPESTATUS_LEADER): |
1067 logger.error('Pipe exit statuses of shell script missing.') | 1067 logger.error('Pipe exit statuses of shell script missing.') |
1068 raise device_errors.AdbShellCommandFailedError( | 1068 raise device_errors.AdbShellCommandFailedError( |
1069 script, output, status=None, | 1069 script, output, status=None, |
1070 device_serial=self.serial) | 1070 device_serial=self.serial) |
1071 | 1071 |
1072 output = output[:-1] | 1072 output = output[:-1] |
1073 statuses = [ | 1073 statuses = [ |
1074 int(s) for s in pipestatus_line[len(PIPESTATUS_LEADER):].split()] | 1074 int(s) for s in pipestatus_line[len(PIPESTATUS_LEADER):].split()] |
1075 if any(statuses): | 1075 if check_return and any(statuses): |
1076 raise device_errors.AdbShellCommandFailedError( | 1076 raise device_errors.AdbShellCommandFailedError( |
1077 script, output, status=statuses, | 1077 script, output, status=statuses, |
1078 device_serial=self.serial) | 1078 device_serial=self.serial) |
1079 return output | 1079 return output |
1080 | 1080 |
1081 @decorators.WithTimeoutAndRetriesFromInstance() | 1081 @decorators.WithTimeoutAndRetriesFromInstance() |
1082 def KillAll(self, process_name, exact=False, signum=device_signal.SIGKILL, | 1082 def KillAll(self, process_name, exact=False, signum=device_signal.SIGKILL, |
1083 as_root=False, blocking=False, quiet=False, | 1083 as_root=False, blocking=False, quiet=False, |
1084 timeout=None, retries=None): | 1084 timeout=None, retries=None): |
1085 """Kill all processes with the given name on the device. | 1085 """Kill all processes with the given name on the device. |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 except device_errors.AdbShellCommandFailedError as e: | 1363 except device_errors.AdbShellCommandFailedError as e: |
1364 # TODO(crbug.com/739899): This is attempting to diagnose flaky EBUSY | 1364 # TODO(crbug.com/739899): This is attempting to diagnose flaky EBUSY |
1365 # errors that have been popping up in single-device scenarios. | 1365 # errors that have been popping up in single-device scenarios. |
1366 # Remove it once we've figured out what's causing them and how best | 1366 # Remove it once we've figured out what's causing them and how best |
1367 # to handle them. | 1367 # to handle them. |
1368 m = _EBUSY_RE.search(e.output) | 1368 m = _EBUSY_RE.search(e.output) |
1369 if m: | 1369 if m: |
1370 logging.error( | 1370 logging.error( |
1371 'Hit EBUSY while attempting to make missing directories.') | 1371 'Hit EBUSY while attempting to make missing directories.') |
1372 logging.error('lsof output:') | 1372 logging.error('lsof output:') |
1373 for l in self._RunPipedShellCommand( | 1373 cmd = 'lsof | grep %s' % cmd_helper.SingleQuote(m.group(1)) |
1374 'lsof | grep %s' % cmd_helper.SingleQuote(m.group(1))): | 1374 for l in self._RunPipedShellCommand(cmd, check_return=False): |
1375 logging.error(' %s', l) | 1375 logging.error(' %s', l) |
1376 raise | 1376 raise |
1377 self._PushFilesImpl(host_device_tuples, all_changed_files) | 1377 self._PushFilesImpl(host_device_tuples, all_changed_files) |
1378 for func in cache_commit_funcs: | 1378 for func in cache_commit_funcs: |
1379 func() | 1379 func() |
1380 | 1380 |
1381 def _GetChangedAndStaleFiles(self, host_path, device_path, track_stale=False): | 1381 def _GetChangedAndStaleFiles(self, host_path, device_path, track_stale=False): |
1382 """Get files to push and delete | 1382 """Get files to push and delete |
1383 | 1383 |
1384 Args: | 1384 Args: |
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2770 on: bool to decide state to switch to. True = on False = off. | 2770 on: bool to decide state to switch to. True = on False = off. |
2771 """ | 2771 """ |
2772 def screen_test(): | 2772 def screen_test(): |
2773 return self.IsScreenOn() == on | 2773 return self.IsScreenOn() == on |
2774 | 2774 |
2775 if screen_test(): | 2775 if screen_test(): |
2776 logger.info('Screen already in expected state.') | 2776 logger.info('Screen already in expected state.') |
2777 return | 2777 return |
2778 self.SendKeyEvent(keyevent.KEYCODE_POWER) | 2778 self.SendKeyEvent(keyevent.KEYCODE_POWER) |
2779 timeout_retry.WaitFor(screen_test, wait_period=1) | 2779 timeout_retry.WaitFor(screen_test, wait_period=1) |
OLD | NEW |