Bug 787203 - [mozrunner] Expose a start_logcat method in Device; r?ahal draft
authorMaja Frydrychowicz <mjzffr@gmail.com>
Thu, 30 Jun 2016 17:41:17 -0400
changeset 384162 5740f34d24d9af7ea531de2d8af2f63dad751cdf
parent 384161 0fab90810807c40ecf7765209dd3e2bbabb499dd
child 384163 690640b663de9c1afb5e5d9a3ac059b2fcfcbd6d
push id22185
push usermjzffr@gmail.com
push dateTue, 05 Jul 2016 18:12:09 +0000
reviewersahal
bugs787203
milestone50.0a1
Bug 787203 - [mozrunner] Expose a start_logcat method in Device; r?ahal This is a refactor. |start_logcat| allows filtering by tag and is used for recording gecko.log for Marionette tests on Fennec. MozReview-Commit-ID: 9NO6jQDMQ9E
testing/mozbase/mozrunner/mozrunner/devices/base.py
--- a/testing/mozbase/mozrunner/mozrunner/devices/base.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/base.py
@@ -136,20 +136,32 @@ class Device(object):
         self.dm.connect()
         self.connected = True
 
         if self.logdir:
             # save logcat
             logcat_log = os.path.join(self.logdir, '%s.log' % serial)
             if os.path.isfile(logcat_log):
                 self._rotate_log(logcat_log)
-            logcat_args = [self.app_ctx.adb, '-s', '%s' % serial,
-                           'logcat', '-v', 'time', '-b', 'main', '-b', 'radio']
-            self.logcat_proc = ProcessHandler(logcat_args, logfile=logcat_log)
-            self.logcat_proc.run()
+            self.logcat_proc = self.start_logcat(serial, logfile=logcat_log)
+
+    def start_logcat(self, serial, logfile=None, stream=None, filterspec=None):
+        logcat_args = [self.app_ctx.adb, '-s', '%s' % serial,
+                       'logcat', '-v', 'time', '-b', 'main', '-b', 'radio']
+        # only log filterspec
+        if filterspec:
+            logcat_args.extend(['-s', filterspec])
+        process_args = {}
+        if logfile:
+            process_args['logfile'] = logfile
+        elif stream:
+            process_args['stream'] = stream
+        proc = ProcessHandler(logcat_args, **process_args)
+        proc.run()
+        return proc
 
     def reboot(self):
         """
         Reboots the device via adb.
         """
         self.dm.reboot(wait=True)
 
     def install_busybox(self, busybox):