Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: build/android/pylib/android_commands.py

Issue 12035016: Android: fixes timeout for WaitForLogMatch. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 assert build_type 771 assert build_type
772 return build_type 772 return build_type
773 773
774 def StartMonitoringLogcat(self, clear=True, timeout=10, logfile=None, 774 def StartMonitoringLogcat(self, clear=True, timeout=10, logfile=None,
775 filters=None): 775 filters=None):
776 """Starts monitoring the output of logcat, for use with WaitForLogMatch. 776 """Starts monitoring the output of logcat, for use with WaitForLogMatch.
777 777
778 Args: 778 Args:
779 clear: If True the existing logcat output will be cleared, to avoiding 779 clear: If True the existing logcat output will be cleared, to avoiding
780 matching historical output lurking in the log. 780 matching historical output lurking in the log.
781 timeout: How long WaitForLogMatch will wait for the given match 781 timeout: Deprecated, will be removed soon.
782 filters: A list of logcat filters to be used. 782 filters: A list of logcat filters to be used.
783 """ 783 """
784 if clear: 784 if clear:
785 self.RunShellCommand('logcat -c') 785 self.RunShellCommand('logcat -c')
786 args = [] 786 args = []
787 if self._adb._target_arg: 787 if self._adb._target_arg:
788 args += shlex.split(self._adb._target_arg) 788 args += shlex.split(self._adb._target_arg)
789 args += ['logcat', '-v', 'threadtime'] 789 args += ['logcat', '-v', 'threadtime']
790 if filters: 790 if filters:
791 args.extend(filters) 791 args.extend(filters)
(...skipping 24 matching lines...) Expand all
816 816
817 def WaitForLogMatch(self, success_re, error_re, clear=False, timeout=10): 817 def WaitForLogMatch(self, success_re, error_re, clear=False, timeout=10):
818 """Blocks until a matching line is logged or a timeout occurs. 818 """Blocks until a matching line is logged or a timeout occurs.
819 819
820 Args: 820 Args:
821 success_re: A compiled re to search each line for. 821 success_re: A compiled re to search each line for.
822 error_re: A compiled re which, if found, terminates the search for 822 error_re: A compiled re which, if found, terminates the search for
823 |success_re|. If None is given, no error condition will be detected. 823 |success_re|. If None is given, no error condition will be detected.
824 clear: If True the existing logcat output will be cleared, defaults to 824 clear: If True the existing logcat output will be cleared, defaults to
825 false. 825 false.
826 timeout: Timeout in seconds to wait for a log match.
826 827
827 Raises: 828 Raises:
828 pexpect.TIMEOUT upon the timeout specified by StartMonitoringLogcat(). 829 pexpect.TIMEOUT after |timeout| seconds without a match for |success_re|
830 or |error_re|.
829 831
830 Returns: 832 Returns:
831 The re match object if |success_re| is matched first or None if |error_re| 833 The re match object if |success_re| is matched first or None if |error_re|
832 is matched first. 834 is matched first.
833 """ 835 """
834 logging.info('<<< Waiting for logcat:' + str(success_re.pattern)) 836 logging.info('<<< Waiting for logcat:' + str(success_re.pattern))
835 t0 = time.time() 837 t0 = time.time()
836 while True: 838 while True:
837 if not self._logcat: 839 if not self._logcat:
838 self.StartMonitoringLogcat(clear, timeout=timeout) 840 self.StartMonitoringLogcat(clear, timeout=timeout)
839 try: 841 try:
840 while True: 842 while True:
841 # Note this will block for upto the timeout _per log line_, so we need 843 # Note this will block for upto the timeout _per log line_, so we need
842 # to calculate the overall timeout remaining since t0. 844 # to calculate the overall timeout remaining since t0.
843 time_remaining = t0 + self._logcat.timeout - time.time() 845 time_remaining = t0 + timeout - time.time()
844 if time_remaining < 0: raise pexpect.TIMEOUT(self._logcat) 846 if time_remaining < 0: raise pexpect.TIMEOUT(self._logcat)
845 self._logcat.expect(PEXPECT_LINE_RE, timeout=time_remaining) 847 self._logcat.expect(PEXPECT_LINE_RE, timeout=time_remaining)
846 line = self._logcat.match.group(1) 848 line = self._logcat.match.group(1)
847 if error_re: 849 if error_re:
848 error_match = error_re.search(line) 850 error_match = error_re.search(line)
849 if error_match: 851 if error_match:
850 return None 852 return None
851 success_match = success_re.search(line) 853 success_match = success_re.search(line)
852 if success_match: 854 if success_match:
853 return success_match 855 return success_match
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 """ 1148 """
1147 def __init__(self, output): 1149 def __init__(self, output):
1148 self._output = output 1150 self._output = output
1149 1151
1150 def write(self, data): 1152 def write(self, data):
1151 data = data.replace('\r\r\n', '\n') 1153 data = data.replace('\r\r\n', '\n')
1152 self._output.write(data) 1154 self._output.write(data)
1153 1155
1154 def flush(self): 1156 def flush(self):
1155 self._output.flush() 1157 self._output.flush()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698