2013-04-19 12:19:54 +00:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2015-06-22 00:39:09 +00:00
|
|
|
from __future__ import absolute_import, unicode_literals
|
2014-01-16 14:58:56 +00:00
|
|
|
|
2013-04-19 12:19:54 +00:00
|
|
|
import os
|
2014-01-16 14:58:56 +00:00
|
|
|
import sys
|
2014-07-18 01:28:45 +00:00
|
|
|
import argparse
|
2014-01-16 14:58:56 +00:00
|
|
|
|
2013-10-15 19:54:21 +00:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
MachCommandConditions as conditions,
|
|
|
|
)
|
2013-04-19 12:19:54 +00:00
|
|
|
|
|
|
|
from mach.decorators import (
|
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
2013-10-15 19:54:21 +00:00
|
|
|
MARIONETTE_DISABLED_B2G = '''
|
|
|
|
The %s command requires a Marionette-enabled build.
|
|
|
|
|
|
|
|
Please create an engineering build, which has Marionette enabled. You can do
|
|
|
|
this by ommitting the VARIANT variable when building, or using:
|
|
|
|
|
|
|
|
VARIANT=eng ./build.sh
|
|
|
|
'''
|
|
|
|
|
2015-09-02 22:57:25 +00:00
|
|
|
def setup_argument_parser():
|
|
|
|
from marionette.runner.base import BaseMarionetteArguments
|
|
|
|
return BaseMarionetteArguments()
|
2014-07-18 01:28:45 +00:00
|
|
|
|
2013-10-15 19:54:21 +00:00
|
|
|
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None,
|
2014-07-18 01:28:45 +00:00
|
|
|
address=None, binary=None, topsrcdir=None, **kwargs):
|
2015-09-02 22:57:25 +00:00
|
|
|
from mozlog.structured import commandline
|
2014-10-10 16:58:10 +00:00
|
|
|
|
2015-03-04 01:37:19 +00:00
|
|
|
from marionette.runtests import (
|
2013-10-15 19:54:21 +00:00
|
|
|
MarionetteTestRunner,
|
2015-08-18 20:27:04 +00:00
|
|
|
BaseMarionetteArguments,
|
2015-11-09 14:07:52 +00:00
|
|
|
MarionetteHarness
|
2013-10-15 19:54:21 +00:00
|
|
|
)
|
|
|
|
|
2015-08-18 20:27:04 +00:00
|
|
|
parser = BaseMarionetteArguments()
|
2014-07-18 01:28:45 +00:00
|
|
|
commandline.add_logging_group(parser)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
|
|
|
if not tests:
|
|
|
|
tests = [os.path.join(topsrcdir,
|
2016-02-06 17:34:10 +00:00
|
|
|
'testing/marionette/harness/marionette/tests/unit-tests.ini')]
|
2016-02-29 17:39:28 +00:00
|
|
|
|
|
|
|
args = parser.parse_args(args=tests)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
|
|
|
if b2g_path:
|
2015-08-18 20:27:04 +00:00
|
|
|
args.homedir = b2g_path
|
2013-10-15 19:54:21 +00:00
|
|
|
if emulator:
|
2015-08-18 20:27:04 +00:00
|
|
|
args.emulator = emulator
|
2013-10-15 19:54:21 +00:00
|
|
|
else:
|
2015-08-18 20:27:04 +00:00
|
|
|
args.binary = binary
|
|
|
|
path, exe = os.path.split(args.binary)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2014-10-20 12:55:28 +00:00
|
|
|
for k, v in kwargs.iteritems():
|
2015-08-18 20:27:04 +00:00
|
|
|
setattr(args, k, v)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2015-08-18 20:27:04 +00:00
|
|
|
parser.verify_usage(args)
|
2013-10-15 19:54:21 +00:00
|
|
|
|
2015-08-18 20:27:04 +00:00
|
|
|
args.logger = commandline.setup_logging("Marionette Unit Tests",
|
|
|
|
args,
|
|
|
|
{"mach": sys.stdout})
|
2016-03-19 02:33:08 +00:00
|
|
|
failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
|
2015-11-10 18:09:13 +00:00
|
|
|
if failed > 0:
|
2015-11-09 14:07:52 +00:00
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
2013-04-19 12:19:54 +00:00
|
|
|
|
|
|
|
@CommandProvider
|
2013-10-15 19:54:21 +00:00
|
|
|
class B2GCommands(MachCommandBase):
|
|
|
|
def __init__(self, context):
|
|
|
|
MachCommandBase.__init__(self, context)
|
|
|
|
|
|
|
|
for attr in ('b2g_home', 'device_name'):
|
|
|
|
setattr(self, attr, getattr(context, attr, None))
|
|
|
|
@Command('marionette-webapi', category='testing',
|
2014-08-09 13:37:29 +00:00
|
|
|
description='Run a Marionette webapi test (test WebAPIs using marionette).',
|
2013-10-15 19:54:21 +00:00
|
|
|
conditions=[conditions.is_b2g])
|
2014-10-20 12:55:28 +00:00
|
|
|
@CommandArgument('--type',
|
|
|
|
default='b2g',
|
|
|
|
help='Test type, usually one of: browser, b2g, b2g-qemu.')
|
2015-03-19 20:15:33 +00:00
|
|
|
@CommandArgument('--tag', action='append', dest='test_tags',
|
|
|
|
help='Filter out tests that don\'t have the given tag. Can be used '
|
|
|
|
'multiple times in which case the test must contain at least one '
|
|
|
|
'of the given tags.')
|
2013-04-19 12:19:54 +00:00
|
|
|
@CommandArgument('tests', nargs='*', metavar='TESTS',
|
|
|
|
help='Path to test(s) to run.')
|
2014-10-20 12:55:28 +00:00
|
|
|
def run_marionette_webapi(self, tests, **kwargs):
|
2014-04-30 16:57:39 +00:00
|
|
|
emulator = None
|
|
|
|
if self.device_name:
|
|
|
|
if self.device_name.startswith('emulator'):
|
|
|
|
emulator = 'arm'
|
|
|
|
if 'x86' in self.device_name:
|
|
|
|
emulator = 'x86'
|
2013-04-19 12:19:54 +00:00
|
|
|
|
2013-10-15 19:54:21 +00:00
|
|
|
if self.substs.get('ENABLE_MARIONETTE') != '1':
|
|
|
|
print(MARIONETTE_DISABLED_B2G % 'marionette-webapi')
|
|
|
|
return 1
|
2013-04-19 12:19:54 +00:00
|
|
|
|
2013-10-15 19:54:21 +00:00
|
|
|
return run_marionette(tests, b2g_path=self.b2g_home, emulator=emulator,
|
2014-10-20 12:55:28 +00:00
|
|
|
topsrcdir=self.topsrcdir, **kwargs)
|
2013-04-19 12:19:54 +00:00
|
|
|
|
2013-10-15 19:54:21 +00:00
|
|
|
@CommandProvider
|
|
|
|
class MachCommands(MachCommandBase):
|
|
|
|
@Command('marionette-test', category='testing',
|
2014-08-09 13:37:29 +00:00
|
|
|
description='Run a Marionette test (Check UI or the internal JavaScript using marionette).',
|
2014-07-18 01:28:45 +00:00
|
|
|
conditions=[conditions.is_firefox],
|
2015-09-02 22:57:25 +00:00
|
|
|
parser=setup_argument_parser,
|
2014-07-18 01:28:45 +00:00
|
|
|
)
|
2014-10-20 12:55:28 +00:00
|
|
|
def run_marionette_test(self, tests, **kwargs):
|
2015-09-18 13:53:37 +00:00
|
|
|
if 'test_objects' in kwargs:
|
|
|
|
tests = []
|
|
|
|
for obj in kwargs['test_objects']:
|
|
|
|
tests.append(obj['file_relpath'])
|
|
|
|
del kwargs['test_objects']
|
|
|
|
|
2015-09-02 22:57:25 +00:00
|
|
|
kwargs['binary'] = self.get_binary_path('app')
|
|
|
|
return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
|