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
11 from mozlog
.structured
import commandline
13 from mozbuild
.base
import (
15 MachCommandConditions
as conditions
,
18 from mach
.decorators
import (
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
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 (
41 BaseMarionetteOptions
,
45 parser
= BaseMarionetteOptions()
46 commandline
.add_logging_group(parser
)
47 options
, args
= parser
.parse_args()
50 tests
= [os
.path
.join(topsrcdir
,
51 'testing/marionette/client/marionette/tests/unit-tests.ini')]
53 options
.type = testtype
55 options
.homedir
= b2g_path
57 options
.emulator
= emulator
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",
70 runner
= startTestRunner(MarionetteTestRunner
, options
, tests
)
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.',
89 @CommandArgument('tests', nargs
='*', metavar
='TESTS',
90 help='Path to test(s) to run.')
91 def run_marionette_webapi(self
, tests
, testtype
=None):
94 if self
.device_name
.startswith('emulator'):
96 if 'x86' in self
.device_name
:
99 if self
.substs
.get('ENABLE_MARIONETTE') != '1':
100 print(MARIONETTE_DISABLED_B2G
% 'marionette-webapi')
103 return run_marionette(tests
, b2g_path
=self
.b2g_home
, emulator
=emulator
,
104 testtype
=testtype
, topsrcdir
=self
.topsrcdir
, address
=None)
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
],
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.',
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,
122 binary
= self
.get_binary_path('app')
123 return run_marionette(tests
, binary
=binary
, testtype
=testtype
,
124 topsrcdir
=self
.topsrcdir
, address
=address
)