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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 build_id = self.RunShellCommand('getprop ro.build.id')[0] | 801 build_id = self.RunShellCommand('getprop ro.build.id')[0] |
802 assert build_id | 802 assert build_id |
803 return build_id | 803 return build_id |
804 | 804 |
805 def GetBuildType(self): | 805 def GetBuildType(self): |
806 """Returns the build type of the system (e.g. eng).""" | 806 """Returns the build type of the system (e.g. eng).""" |
807 build_type = self.RunShellCommand('getprop ro.build.type')[0] | 807 build_type = self.RunShellCommand('getprop ro.build.type')[0] |
808 assert build_type | 808 assert build_type |
809 return build_type | 809 return build_type |
810 | 810 |
811 def StartMonitoringLogcat(self, clear=True, timeout=10, logfile=None, | 811 def StartMonitoringLogcat(self, clear=True, logfile=None, filters=None): |
812 filters=None): | |
813 """Starts monitoring the output of logcat, for use with WaitForLogMatch. | 812 """Starts monitoring the output of logcat, for use with WaitForLogMatch. |
814 | 813 |
815 Args: | 814 Args: |
816 clear: If True the existing logcat output will be cleared, to avoiding | 815 clear: If True the existing logcat output will be cleared, to avoiding |
817 matching historical output lurking in the log. | 816 matching historical output lurking in the log. |
818 timeout: Deprecated, will be removed soon. | |
819 filters: A list of logcat filters to be used. | 817 filters: A list of logcat filters to be used. |
820 """ | 818 """ |
821 if clear: | 819 if clear: |
822 self.RunShellCommand('logcat -c') | 820 self.RunShellCommand('logcat -c') |
823 args = [] | 821 args = [] |
824 if self._adb._target_arg: | 822 if self._adb._target_arg: |
825 args += shlex.split(self._adb._target_arg) | 823 args += shlex.split(self._adb._target_arg) |
826 args += ['logcat', '-v', 'threadtime'] | 824 args += ['logcat', '-v', 'threadtime'] |
827 if filters: | 825 if filters: |
828 args.extend(filters) | 826 args.extend(filters) |
829 else: | 827 else: |
830 args.append('*:v') | 828 args.append('*:v') |
831 | 829 |
832 if logfile: | 830 if logfile: |
833 logfile = NewLineNormalizer(logfile) | 831 logfile = NewLineNormalizer(logfile) |
834 | 832 |
835 # Spawn logcat and syncronize with it. | 833 # Spawn logcat and syncronize with it. |
836 for _ in range(4): | 834 for _ in range(4): |
837 self._logcat = pexpect.spawn('adb', args, timeout=timeout, | 835 self._logcat = pexpect.spawn('adb', args, timeout=10, logfile=logfile) |
838 logfile=logfile) | |
839 self.RunShellCommand('log startup_sync') | 836 self.RunShellCommand('log startup_sync') |
840 if self._logcat.expect(['startup_sync', pexpect.EOF, | 837 if self._logcat.expect(['startup_sync', pexpect.EOF, |
841 pexpect.TIMEOUT]) == 0: | 838 pexpect.TIMEOUT]) == 0: |
842 break | 839 break |
843 self._logcat.close(force=True) | 840 self._logcat.close(force=True) |
844 else: | 841 else: |
845 logging.critical('Error reading from logcat: ' + str(self._logcat.match)) | 842 logging.critical('Error reading from logcat: ' + str(self._logcat.match)) |
846 sys.exit(1) | 843 sys.exit(1) |
847 | 844 |
848 def GetMonitoredLogCat(self): | 845 def GetMonitoredLogCat(self): |
(...skipping 18 matching lines...) Expand all Loading... |
867 or |error_re|. | 864 or |error_re|. |
868 | 865 |
869 Returns: | 866 Returns: |
870 The re match object if |success_re| is matched first or None if |error_re| | 867 The re match object if |success_re| is matched first or None if |error_re| |
871 is matched first. | 868 is matched first. |
872 """ | 869 """ |
873 logging.info('<<< Waiting for logcat:' + str(success_re.pattern)) | 870 logging.info('<<< Waiting for logcat:' + str(success_re.pattern)) |
874 t0 = time.time() | 871 t0 = time.time() |
875 while True: | 872 while True: |
876 if not self._logcat: | 873 if not self._logcat: |
877 self.StartMonitoringLogcat(clear, timeout=timeout) | 874 self.StartMonitoringLogcat(clear) |
878 try: | 875 try: |
879 while True: | 876 while True: |
880 # Note this will block for upto the timeout _per log line_, so we need | 877 # Note this will block for upto the timeout _per log line_, so we need |
881 # to calculate the overall timeout remaining since t0. | 878 # to calculate the overall timeout remaining since t0. |
882 time_remaining = t0 + timeout - time.time() | 879 time_remaining = t0 + timeout - time.time() |
883 if time_remaining < 0: raise pexpect.TIMEOUT(self._logcat) | 880 if time_remaining < 0: raise pexpect.TIMEOUT(self._logcat) |
884 self._logcat.expect(PEXPECT_LINE_RE, timeout=time_remaining) | 881 self._logcat.expect(PEXPECT_LINE_RE, timeout=time_remaining) |
885 line = self._logcat.match.group(1) | 882 line = self._logcat.match.group(1) |
886 if error_re: | 883 if error_re: |
887 error_match = error_re.search(line) | 884 error_match = error_re.search(line) |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 """ | 1182 """ |
1186 def __init__(self, output): | 1183 def __init__(self, output): |
1187 self._output = output | 1184 self._output = output |
1188 | 1185 |
1189 def write(self, data): | 1186 def write(self, data): |
1190 data = data.replace('\r\r\n', '\n') | 1187 data = data.replace('\r\r\n', '\n') |
1191 self._output.write(data) | 1188 self._output.write(data) |
1192 | 1189 |
1193 def flush(self): | 1190 def flush(self): |
1194 self._output.flush() | 1191 self._output.flush() |
OLD | NEW |