michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: from __future__ import unicode_literals michael@0: import os michael@0: michael@0: from mozbuild.base import ( michael@0: MachCommandBase, michael@0: MachCommandConditions as conditions, michael@0: ) michael@0: michael@0: from mach.decorators import ( michael@0: CommandArgument, michael@0: CommandProvider, michael@0: Command, michael@0: ) michael@0: michael@0: MARIONETTE_DISABLED_B2G = ''' michael@0: The %s command requires a Marionette-enabled build. michael@0: michael@0: Please create an engineering build, which has Marionette enabled. You can do michael@0: this by ommitting the VARIANT variable when building, or using: michael@0: michael@0: VARIANT=eng ./build.sh michael@0: ''' michael@0: michael@0: def run_marionette(tests, b2g_path=None, emulator=None, testtype=None, michael@0: address=None, bin=None, topsrcdir=None): michael@0: from marionette.runtests import ( michael@0: MarionetteTestRunner, michael@0: BaseMarionetteOptions, michael@0: startTestRunner michael@0: ) michael@0: michael@0: parser = BaseMarionetteOptions() michael@0: options, args = parser.parse_args() michael@0: michael@0: if not tests: michael@0: tests = [os.path.join(topsrcdir, michael@0: 'testing/marionette/client/marionette/tests/unit-tests.ini')] michael@0: michael@0: options.type = testtype michael@0: if b2g_path: michael@0: options.homedir = b2g_path michael@0: if emulator: michael@0: options.emulator = emulator michael@0: else: michael@0: options.bin = bin michael@0: path, exe = os.path.split(options.bin) michael@0: michael@0: options.address = address michael@0: michael@0: parser.verify_usage(options, tests) michael@0: michael@0: runner = startTestRunner(MarionetteTestRunner, options, tests) michael@0: if runner.failed > 0: michael@0: return 1 michael@0: michael@0: return 0 michael@0: michael@0: @CommandProvider michael@0: class B2GCommands(MachCommandBase): michael@0: def __init__(self, context): michael@0: MachCommandBase.__init__(self, context) michael@0: michael@0: for attr in ('b2g_home', 'device_name'): michael@0: setattr(self, attr, getattr(context, attr, None)) michael@0: @Command('marionette-webapi', category='testing', michael@0: description='Run a Marionette webapi test', michael@0: conditions=[conditions.is_b2g]) michael@0: @CommandArgument('--emulator', choices=['x86', 'arm'], michael@0: help='Run an emulator of the specified architecture.') michael@0: @CommandArgument('--type', dest='testtype', michael@0: help='Test type, usually one of: browser, b2g, b2g-qemu.', michael@0: default='b2g') michael@0: @CommandArgument('tests', nargs='*', metavar='TESTS', michael@0: help='Path to test(s) to run.') michael@0: def run_marionette_webapi(self, tests, emulator=None, testtype=None): michael@0: if not emulator and self.device_name.find('emulator') == 0: michael@0: emulator='arm' michael@0: michael@0: if self.substs.get('ENABLE_MARIONETTE') != '1': michael@0: print(MARIONETTE_DISABLED_B2G % 'marionette-webapi') michael@0: return 1 michael@0: michael@0: return run_marionette(tests, b2g_path=self.b2g_home, emulator=emulator, michael@0: testtype=testtype, topsrcdir=self.topsrcdir, address=None) michael@0: michael@0: michael@0: @CommandProvider michael@0: class MachCommands(MachCommandBase): michael@0: @Command('marionette-test', category='testing', michael@0: description='Run a Marionette test.', michael@0: conditions=[conditions.is_firefox]) michael@0: @CommandArgument('--address', michael@0: help='host:port of running Gecko instance to connect to.') michael@0: @CommandArgument('--type', dest='testtype', michael@0: help='Test type, usually one of: browser, b2g, b2g-qemu.', michael@0: default='browser') michael@0: @CommandArgument('tests', nargs='*', metavar='TESTS', michael@0: help='Path to test(s) to run.') michael@0: def run_marionette_test(self, tests, address=None, testtype=None): michael@0: bin = self.get_binary_path('app') michael@0: return run_marionette(tests, bin=bin, testtype=testtype, michael@0: topsrcdir=self.topsrcdir, address=address)