Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / testing / marionette / mach_commands.py
blob609c3c8cd55f6744110270107648a029fa7e576f
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import unicode_literals
7 import os
8 import sys
9 import argparse
11 from mozlog.structured import commandline
13 from mozbuild.base import (
14 MachCommandBase,
15 MachCommandConditions as conditions,
18 from mach.decorators import (
19 CommandArgument,
20 CommandProvider,
21 Command,
24 MARIONETTE_DISABLED_B2G = '''
25 The %s command requires a Marionette-enabled build.
27 Please create an engineering build, which has Marionette enabled. You can do
28 this by ommitting the VARIANT variable when building, or using:
30 VARIANT=eng ./build.sh
31 '''
33 # A parser that will accept structured logging commandline arguments.
34 _parser = argparse.ArgumentParser()
35 commandline.add_logging_group(_parser)
37 def run_marionette(tests, b2g_path=None, emulator=None, testtype=None,
38 address=None, binary=None, topsrcdir=None, **kwargs):
39 from marionette.runtests import (
40 MarionetteTestRunner,
41 BaseMarionetteOptions,
42 startTestRunner
45 parser = BaseMarionetteOptions()
46 commandline.add_logging_group(parser)
47 options, args = parser.parse_args()
49 if not tests:
50 tests = [os.path.join(topsrcdir,
51 'testing/marionette/client/marionette/tests/unit-tests.ini')]
53 options.type = testtype
54 if b2g_path:
55 options.homedir = b2g_path
56 if emulator:
57 options.emulator = emulator
58 else:
59 options.binary = binary
60 path, exe = os.path.split(options.binary)
62 options.address = address
64 parser.verify_usage(options, tests)
66 options.logger = commandline.setup_logging("Marionette Unit Tests",
67 options,
68 {"mach": sys.stdout})
70 runner = startTestRunner(MarionetteTestRunner, options, tests)
71 if runner.failed > 0:
72 return 1
74 return 0
76 @CommandProvider
77 class B2GCommands(MachCommandBase):
78 def __init__(self, context):
79 MachCommandBase.__init__(self, context)
81 for attr in ('b2g_home', 'device_name'):
82 setattr(self, attr, getattr(context, attr, None))
83 @Command('marionette-webapi', category='testing',
84 description='Run a Marionette webapi test (test WebAPIs using marionette).',
85 conditions=[conditions.is_b2g])
86 @CommandArgument('--type', dest='testtype',
87 help='Test type, usually one of: browser, b2g, b2g-qemu.',
88 default='b2g')
89 @CommandArgument('tests', nargs='*', metavar='TESTS',
90 help='Path to test(s) to run.')
91 def run_marionette_webapi(self, tests, testtype=None):
92 emulator = None
93 if self.device_name:
94 if self.device_name.startswith('emulator'):
95 emulator = 'arm'
96 if 'x86' in self.device_name:
97 emulator = 'x86'
99 if self.substs.get('ENABLE_MARIONETTE') != '1':
100 print(MARIONETTE_DISABLED_B2G % 'marionette-webapi')
101 return 1
103 return run_marionette(tests, b2g_path=self.b2g_home, emulator=emulator,
104 testtype=testtype, topsrcdir=self.topsrcdir, address=None)
106 @CommandProvider
107 class MachCommands(MachCommandBase):
108 @Command('marionette-test', category='testing',
109 description='Run a Marionette test (Check UI or the internal JavaScript using marionette).',
110 conditions=[conditions.is_firefox],
111 parser=_parser,
113 @CommandArgument('--address',
114 help='host:port of running Gecko instance to connect to.')
115 @CommandArgument('--type', dest='testtype',
116 help='Test type, usually one of: browser, b2g, b2g-qemu.',
117 default='browser')
118 @CommandArgument('tests', nargs='*', metavar='TESTS',
119 help='Path to test(s) to run.')
120 def run_marionette_test(self, tests, address=None, testtype=None,
121 **kwargs):
122 binary = self.get_binary_path('app')
123 return run_marionette(tests, binary=binary, testtype=testtype,
124 topsrcdir=self.topsrcdir, address=address)