testing/marionette/mach_commands.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/testing/marionette/mach_commands.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +from __future__ import unicode_literals
     1.9 +import os
    1.10 +
    1.11 +from mozbuild.base import (
    1.12 +    MachCommandBase,
    1.13 +    MachCommandConditions as conditions,
    1.14 +)
    1.15 +
    1.16 +from mach.decorators import (
    1.17 +    CommandArgument,
    1.18 +    CommandProvider,
    1.19 +    Command,
    1.20 +)
    1.21 +
    1.22 +MARIONETTE_DISABLED_B2G = '''
    1.23 +The %s command requires a Marionette-enabled build.
    1.24 +
    1.25 +Please create an engineering build, which has Marionette enabled.  You can do
    1.26 +this by ommitting the VARIANT variable when building, or using:
    1.27 +
    1.28 +VARIANT=eng ./build.sh
    1.29 +'''
    1.30 +
    1.31 +def run_marionette(tests, b2g_path=None, emulator=None, testtype=None,
    1.32 +    address=None, bin=None, topsrcdir=None):
    1.33 +    from marionette.runtests import (
    1.34 +        MarionetteTestRunner,
    1.35 +        BaseMarionetteOptions,
    1.36 +        startTestRunner
    1.37 +    )
    1.38 +
    1.39 +    parser = BaseMarionetteOptions()
    1.40 +    options, args = parser.parse_args()
    1.41 +
    1.42 +    if not tests:
    1.43 +        tests = [os.path.join(topsrcdir,
    1.44 +                    'testing/marionette/client/marionette/tests/unit-tests.ini')]
    1.45 +
    1.46 +    options.type = testtype
    1.47 +    if b2g_path:
    1.48 +        options.homedir = b2g_path
    1.49 +        if emulator:
    1.50 +            options.emulator = emulator
    1.51 +    else:
    1.52 +        options.bin = bin
    1.53 +        path, exe = os.path.split(options.bin)
    1.54 +
    1.55 +    options.address = address
    1.56 +
    1.57 +    parser.verify_usage(options, tests)
    1.58 +
    1.59 +    runner = startTestRunner(MarionetteTestRunner, options, tests)
    1.60 +    if runner.failed > 0:
    1.61 +        return 1
    1.62 +
    1.63 +    return 0
    1.64 +
    1.65 +@CommandProvider
    1.66 +class B2GCommands(MachCommandBase):
    1.67 +    def __init__(self, context):
    1.68 +        MachCommandBase.__init__(self, context)
    1.69 +
    1.70 +        for attr in ('b2g_home', 'device_name'):
    1.71 +            setattr(self, attr, getattr(context, attr, None))
    1.72 +    @Command('marionette-webapi', category='testing',
    1.73 +        description='Run a Marionette webapi test',
    1.74 +        conditions=[conditions.is_b2g])
    1.75 +    @CommandArgument('--emulator', choices=['x86', 'arm'],
    1.76 +        help='Run an emulator of the specified architecture.')
    1.77 +    @CommandArgument('--type', dest='testtype',
    1.78 +        help='Test type, usually one of: browser, b2g, b2g-qemu.',
    1.79 +        default='b2g')
    1.80 +    @CommandArgument('tests', nargs='*', metavar='TESTS',
    1.81 +        help='Path to test(s) to run.')
    1.82 +    def run_marionette_webapi(self, tests, emulator=None, testtype=None):
    1.83 +        if not emulator and self.device_name.find('emulator') == 0:
    1.84 +            emulator='arm'
    1.85 +
    1.86 +        if self.substs.get('ENABLE_MARIONETTE') != '1':
    1.87 +            print(MARIONETTE_DISABLED_B2G % 'marionette-webapi')
    1.88 +            return 1
    1.89 +
    1.90 +        return run_marionette(tests, b2g_path=self.b2g_home, emulator=emulator,
    1.91 +            testtype=testtype, topsrcdir=self.topsrcdir, address=None)
    1.92 +
    1.93 +
    1.94 +@CommandProvider
    1.95 +class MachCommands(MachCommandBase):
    1.96 +    @Command('marionette-test', category='testing',
    1.97 +        description='Run a Marionette test.',
    1.98 +        conditions=[conditions.is_firefox])
    1.99 +    @CommandArgument('--address',
   1.100 +        help='host:port of running Gecko instance to connect to.')
   1.101 +    @CommandArgument('--type', dest='testtype',
   1.102 +        help='Test type, usually one of: browser, b2g, b2g-qemu.',
   1.103 +        default='browser')
   1.104 +    @CommandArgument('tests', nargs='*', metavar='TESTS',
   1.105 +        help='Path to test(s) to run.')
   1.106 +    def run_marionette_test(self, tests, address=None, testtype=None):
   1.107 +        bin = self.get_binary_path('app')
   1.108 +        return run_marionette(tests, bin=bin, testtype=testtype,
   1.109 +            topsrcdir=self.topsrcdir, address=address)

mercurial