OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 self.RunShellCommand('logcat -c') | 700 self.RunShellCommand('logcat -c') |
701 args = [] | 701 args = [] |
702 if self._adb._target_arg: | 702 if self._adb._target_arg: |
703 args += shlex.split(self._adb._target_arg) | 703 args += shlex.split(self._adb._target_arg) |
704 args += ['logcat', '-v', 'threadtime'] | 704 args += ['logcat', '-v', 'threadtime'] |
705 if filters: | 705 if filters: |
706 args.extend(filters) | 706 args.extend(filters) |
707 else: | 707 else: |
708 args.append('*:v') | 708 args.append('*:v') |
709 | 709 |
710 if logfile: | |
711 class NewLineNormalizer: | |
bulach
2012/09/04 11:22:56
nit: (object)
| |
712 """A file-like object that normalizes end-of-line characters in the | |
bulach
2012/09/04 11:22:56
nit: needs to be one line and end with a period, s
| |
713 input stream to unix-style newlines ('\n'). | |
714 | |
715 Pexpect runs adb within a pseudo-tty device (see | |
716 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written | |
717 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate | |
718 lines, the log ends up having '\r\r\n' at the end of each line. This | |
719 filter replaces the above with a single '\n' in the data stream. | |
720 """ | |
721 def __init__(self, output): | |
722 self.output = output | |
723 | |
724 def write(self, data): | |
725 data = data.replace('\r\r\n', '\n') | |
726 self.output.write(data) | |
727 | |
728 def flush(self): | |
729 self.output.flush() | |
bulach
2012/09/04 11:22:56
nit: add a \n before 730
| |
730 logfile = NewLineNormalizer(logfile) | |
731 | |
710 # Spawn logcat and syncronize with it. | 732 # Spawn logcat and syncronize with it. |
711 for _ in range(4): | 733 for _ in range(4): |
712 self._logcat = pexpect.spawn('adb', args, timeout=timeout, | 734 self._logcat = pexpect.spawn('adb', args, timeout=timeout, |
713 logfile=logfile) | 735 logfile=logfile) |
714 self.RunShellCommand('log startup_sync') | 736 self.RunShellCommand('log startup_sync') |
715 if self._logcat.expect(['startup_sync', pexpect.EOF, | 737 if self._logcat.expect(['startup_sync', pexpect.EOF, |
716 pexpect.TIMEOUT]) == 0: | 738 pexpect.TIMEOUT]) == 0: |
717 break | 739 break |
718 self._logcat.close(force=True) | 740 self._logcat.close(force=True) |
719 else: | 741 else: |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1020 ' '.join(['-c %s' % c for c in category]), | 1042 ' '.join(['-c %s' % c for c in category]), |
1021 '--throttle %d' % throttle, | 1043 '--throttle %d' % throttle, |
1022 '-s %d' % seed, | 1044 '-s %d' % seed, |
1023 '-v ' * verbosity, | 1045 '-v ' * verbosity, |
1024 '--monitor-native-crashes', | 1046 '--monitor-native-crashes', |
1025 '--kill-process-after-error', | 1047 '--kill-process-after-error', |
1026 extra_args, | 1048 extra_args, |
1027 '%d' % event_count] | 1049 '%d' % event_count] |
1028 return self.RunShellCommand(' '.join(cmd), | 1050 return self.RunShellCommand(' '.join(cmd), |
1029 timeout_time=event_count*throttle*1.5) | 1051 timeout_time=event_count*throttle*1.5) |
OLD | NEW |