From fbc5b83b58f7add6ba3b241bcd9fd8903d4f81e6 Mon Sep 17 00:00:00 2001 From: Geoff Brown Date: Wed, 18 Apr 2018 14:43:35 -0600 Subject: [PATCH] Bug 1445716 - Add Android mach command 'geckoview-junit'; r=jmaher --- testing/mochitest/mach_commands.py | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/testing/mochitest/mach_commands.py b/testing/mochitest/mach_commands.py index 8bac433a1355..511ed70a998d 100644 --- a/testing/mochitest/mach_commands.py +++ b/testing/mochitest/mach_commands.py @@ -179,6 +179,15 @@ class MochitestRunner(MozbuildObject): 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: @@ -241,6 +250,38 @@ def setup_argument_parser(): 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): @@ -441,6 +482,40 @@ class MachCommands(MachCommandBase): 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):