Bug 1435433 - Print master test summary after android mochitests when runByManifest; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Wed, 07 Feb 2018 13:33:43 -0700
changeset 402860 0af93cb1ff942b2fc21d2ff3c63ec3306f5df719
parent 402859 c358f1f20f8a8a3dcf72839d522e3459a8d32599
child 402861 edd553a6aa7d94f7bcff8351cc778ff0c709a0d5
push id33405
push usershindli@mozilla.com
push dateThu, 08 Feb 2018 10:04:47 +0000
treeherdermozilla-central@0ac953fcddf1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1435433
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435433 - Print master test summary after android mochitests when runByManifest; r=jmaher
build/mobile/remoteautomation.py
testing/mochitest/runtestsremote.py
--- a/build/mobile/remoteautomation.py
+++ b/build/mobile/remoteautomation.py
@@ -273,24 +273,30 @@ class RemoteAutomation(Automation):
         return self.RProcess(self._devicemanager, cmd, stdout, stderr, env, cwd, self._appName,
                              **self._processArgs)
 
     # be careful here as this inner class doesn't have access to outer class members
     class RProcess(object):
         # device manager process
         dm = None
         def __init__(self, dm, cmd, stdout=None, stderr=None, env=None, cwd=None, app=None,
-                     messageLogger=None):
+                     messageLogger=None, counts=None):
             self.dm = dm
             self.stdoutlen = 0
             self.lastTestSeen = "remoteautomation.py"
             self.proc = dm.launchProcess(cmd, stdout, cwd, env, True)
             self.messageLogger = messageLogger
             self.utilityPath = None
 
+            self.counts = counts
+            if self.counts is not None:
+                self.counts['pass'] = 0
+                self.counts['fail'] = 0
+                self.counts['todo'] = 0
+
             if (self.proc is None):
                 if cmd[0] == 'am':
                     self.proc = stdout
                 else:
                     raise Exception("unable to launch process")
             self.procName = cmd[0].split('/')[-1]
             if cmd[0] == 'am' and cmd[1] in RemoteAutomation._specialAmCommands:
                 self.procName = app
@@ -355,16 +361,32 @@ class RemoteAutomation(Automation):
                 return False
 
             for line in lines:
                 # This passes the line to the logger (to be logged or buffered)
                 parsed_messages = self.messageLogger.write(line)
                 for message in parsed_messages:
                     if isinstance(message, dict) and message.get('action') == 'test_start':
                         self.lastTestSeen = message['test']
+                    if isinstance(message, dict) and message.get('action') == 'log':
+                        line = message['message'].strip()
+                        if self.counts:
+                            m = re.match(".*:\s*(\d*)", line)
+                            if m:
+                                try:
+                                    val = int(m.group(1))
+                                    if "Passed:" in line:
+                                        self.counts['pass'] += val
+                                    elif "Failed:" in line:
+                                        self.counts['fail'] += val
+                                    elif "Todo:" in line:
+                                        self.counts['todo'] += val
+                                except:
+                                    pass
+
             return True
 
         @property
         def getLastTestSeen(self):
             return self.lastTestSeen
 
         # Wait for the remote process to end (or for its activity to go to background).
         # While waiting, periodically retrieve the process output and print it.
--- a/testing/mochitest/runtestsremote.py
+++ b/testing/mochitest/runtestsremote.py
@@ -291,24 +291,29 @@ class MochiRemote(MochitestDesktop):
         # whereas runtest.py's `runApp` takes a mozprofile object.
         if 'profileDir' not in kwargs and 'profile' in kwargs:
             kwargs['profileDir'] = kwargs.pop('profile').profile
 
         # remove args not supported by automation.py
         kwargs.pop('marionette_args', None)
 
         ret, _ = self._automation.runApp(*args, **kwargs)
+        self.countpass += self.counts['pass']
+        self.countfail += self.counts['fail']
+        self.counttodo += self.counts['todo']
+
         return ret, None
 
 
 def run_test_harness(parser, options):
     parser.validate(options)
 
     message_logger = MessageLogger(logger=None)
-    process_args = {'messageLogger': message_logger}
+    counts = dict()
+    process_args = {'messageLogger': message_logger, 'counts': counts}
     auto = RemoteAutomation(None, "fennec", processArgs=process_args)
 
     if options is None:
         raise ValueError("Invalid options specified, use --help for a list of valid options")
 
     options.runByManifest = False
     # roboextender is used by mochitest-chrome tests like test_java_addons.html,
     # but not by any plain mochitests
@@ -318,16 +323,17 @@ def run_test_harness(parser, options):
     dm = options.dm
     auto.setDeviceManager(dm)
     mochitest = MochiRemote(auto, dm, options)
     options.dm = None
 
     log = mochitest.log
     message_logger.logger = log
     mochitest.message_logger = message_logger
+    mochitest.counts = counts
 
     # Check that Firefox is installed
     expected = options.app.split('/')[-1]
     installed = dm.shellCheckOutput(['pm', 'list', 'packages', expected])
     if expected not in installed:
         log.error("%s is not installed on this device" % expected)
         return 1