Bug 1445716 - Add Android mach command 'geckoview-junit'; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Wed, 18 Apr 2018 14:43:35 -0600
changeset 467960 05412fcc00a740e9a718dfbd34e1011007335423
parent 467959 5247cde8ef0c1cc2c817fe693e83854579f27253
child 467961 0e277eb0ce37b3fa09b321f991d72d07f5c4202a
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1445716
milestone61.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 1445716 - Add Android mach command 'geckoview-junit'; r=jmaher
testing/mochitest/mach_commands.py
--- a/testing/mochitest/mach_commands.py
+++ b/testing/mochitest/mach_commands.py
@@ -174,16 +174,25 @@ class MochitestRunner(MozbuildObject):
         from manifestparser import TestManifest
         if tests and not options.manifestFile:
             manifest = TestManifest()
             manifest.tests.extend(tests)
             options.manifestFile = manifest
 
         return runtestsremote.run_test_harness(parser, options)
 
+    def run_geckoview_junit_test(self, context, **kwargs):
+        host_ret = verify_host_bin()
+        if host_ret != 0:
+            return host_ret
+
+        import runjunit
+        options = Namespace(**kwargs)
+        return runjunit.run_test_harness(parser, options)
+
     def run_robocop_test(self, context, tests, suite=None, **kwargs):
         host_ret = verify_host_bin()
         if host_ret != 0:
             return host_ret
 
         import imp
         path = os.path.join(self.mochitest_dir, 'runrobocop.py')
         with open(path, 'r') as fh:
@@ -236,16 +245,48 @@ def setup_argument_parser():
         # verify device and xre
         verify_android_device(build_obj, install=False, xre=True)
 
     global parser
     parser = MochitestArgumentParser()
     return parser
 
 
+def setup_junit_argument_parser():
+    build_obj = MozbuildObject.from_environment(cwd=here)
+
+    build_path = os.path.join(build_obj.topobjdir, 'build')
+    if build_path not in sys.path:
+        sys.path.append(build_path)
+
+    mochitest_dir = os.path.join(build_obj.topobjdir, '_tests', 'testing', 'mochitest')
+
+    with warnings.catch_warnings():
+        warnings.simplefilter('ignore')
+
+        # runtests.py contains MochitestDesktop, required by runjunit
+        import imp
+        path = os.path.join(build_obj.topobjdir, mochitest_dir, 'runtests.py')
+        if not os.path.exists(path):
+            path = os.path.join(here, "runtests.py")
+
+        with open(path, 'r') as fh:
+            imp.load_module('mochitest', fh, path,
+                            ('.py', 'r', imp.PY_SOURCE))
+
+        import runjunit
+
+        from mozrunner.devices.android_device import verify_android_device
+        verify_android_device(build_obj, install=False, xre=True)
+
+    global parser
+    parser = runjunit.JunitArgumentParser()
+    return parser
+
+
 # condition filters
 
 def is_buildapp_in(*apps):
     def is_buildapp_supported(cls):
         for a in apps:
             c = getattr(conditions, 'is_{}'.format(a), None)
             if c and c(cls):
                 return True
@@ -437,16 +478,50 @@ class MachCommands(MachCommandBase):
         # Only shutdown the logger if we created it
         if kwargs['log'].name == 'mach-mochitest':
             kwargs['log'].shutdown()
 
         return overall
 
 
 @CommandProvider
+class GeckoviewJunitCommands(MachCommandBase):
+
+    @Command('geckoview-junit', category='testing',
+             conditions=[conditions.is_android],
+             description='Run remote geckoview junit tests.',
+             parser=setup_junit_argument_parser)
+    def run_junit(self, **kwargs):
+        self._ensure_state_subdir_exists('.')
+
+        from mozrunner.devices.android_device import (grant_runtime_permissions,
+                                                      get_adb_path,
+                                                      verify_android_device)
+        # verify installation
+        app = kwargs.get('app')
+        device_serial = kwargs.get('deviceSerial')
+        verify_android_device(self, install=True, xre=False, app=app,
+                              device_serial=device_serial)
+        grant_runtime_permissions(self, app, device_serial=device_serial)
+
+        if not kwargs.get('adbPath'):
+            kwargs['adbPath'] = get_adb_path(self)
+
+        if not kwargs.get('log'):
+            from mozlog.commandline import setup_logging
+            format_args = {'level': self._mach_context.settings['test']['level']}
+            default_format = self._mach_context.settings['test']['format']
+            kwargs['log'] = setup_logging('mach-mochitest', kwargs,
+                                          {default_format: sys.stdout}, format_args)
+
+        mochitest = self._spawn(MochitestRunner)
+        return mochitest.run_geckoview_junit_test(self._mach_context, **kwargs)
+
+
+@CommandProvider
 class RobocopCommands(MachCommandBase):
 
     @Command('robocop', category='testing',
              conditions=[conditions.is_android],
              description='Run a Robocop test.',
              parser=setup_argument_parser)
     @CommandArgument('--serve', default=False, action='store_true',
                      help='Run no tests but start the mochi.test web server '