2013-04-19 16:19:54 +04: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/.
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2014-01-16 18:58:56 +04:00
|
|
|
|
2013-04-19 16:19:54 +04:00
|
|
|
import os
|
2014-01-16 18:58:56 +04:00
|
|
|
import sys
|
|
|
|
|
|
|
|
from mozlog import structured
|
2013-04-19 16:19:54 +04:00
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
MachCommandConditions as conditions,
|
|
|
|
)
|
2013-04-19 16:19:54 +04:00
|
|
|
|
|
|
|
from mach.decorators import (
|
|
|
|
CommandArgument,
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
2013-10-15 23:54:21 +04: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
|
|
|
|
'''
|
|
|
|
|
|
|
|
def run_marionette(tests, b2g_path=None, emulator=None, testtype=None,
|
2014-01-16 18:58:56 +04:00
|
|
|
address=None, binary=None, topsrcdir=None):
|
2013-10-15 23:54:21 +04:00
|
|
|
from marionette.runtests import (
|
|
|
|
MarionetteTestRunner,
|
2013-12-17 06:17:08 +04:00
|
|
|
BaseMarionetteOptions,
|
2013-10-15 23:54:21 +04:00
|
|
|
startTestRunner
|
|
|
|
)
|
|
|
|
|
2013-12-17 06:17:08 +04:00
|
|
|
parser = BaseMarionetteOptions()
|
2013-10-15 23:54:21 +04:00
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if not tests:
|
|
|
|
tests = [os.path.join(topsrcdir,
|
|
|
|
'testing/marionette/client/marionette/tests/unit-tests.ini')]
|
|
|
|
|
|
|
|
options.type = testtype
|
|
|
|
if b2g_path:
|
|
|
|
options.homedir = b2g_path
|
|
|
|
if emulator:
|
|
|
|
options.emulator = emulator
|
|
|
|
else:
|
2014-01-16 18:58:56 +04:00
|
|
|
options.binary = binary
|
|
|
|
path, exe = os.path.split(options.binary)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
|
|
|
options.address = address
|
|
|
|
|
|
|
|
parser.verify_usage(options, tests)
|
|
|
|
|
2014-01-16 18:58:56 +04:00
|
|
|
options.logger = structured.commandline.setup_logging("Marionette Unit Tests",
|
|
|
|
options,
|
|
|
|
{"mach": sys.stdout})
|
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
runner = startTestRunner(MarionetteTestRunner, options, tests)
|
|
|
|
if runner.failed > 0:
|
|
|
|
return 1
|
|
|
|
|
|
|
|
return 0
|
2013-04-19 16:19:54 +04:00
|
|
|
|
|
|
|
@CommandProvider
|
2013-10-15 23:54:21 +04: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',
|
|
|
|
description='Run a Marionette webapi test',
|
|
|
|
conditions=[conditions.is_b2g])
|
2013-04-19 16:19:54 +04:00
|
|
|
@CommandArgument('--type', dest='testtype',
|
2013-10-15 23:54:21 +04:00
|
|
|
help='Test type, usually one of: browser, b2g, b2g-qemu.',
|
|
|
|
default='b2g')
|
2013-04-19 16:19:54 +04:00
|
|
|
@CommandArgument('tests', nargs='*', metavar='TESTS',
|
|
|
|
help='Path to test(s) to run.')
|
2014-04-30 20:57:39 +04:00
|
|
|
def run_marionette_webapi(self, tests, testtype=None):
|
|
|
|
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 16:19:54 +04:00
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
if self.substs.get('ENABLE_MARIONETTE') != '1':
|
|
|
|
print(MARIONETTE_DISABLED_B2G % 'marionette-webapi')
|
|
|
|
return 1
|
2013-04-19 16:19:54 +04:00
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
return run_marionette(tests, b2g_path=self.b2g_home, emulator=emulator,
|
|
|
|
testtype=testtype, topsrcdir=self.topsrcdir, address=None)
|
2013-04-19 16:19:54 +04:00
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
|
|
|
|
@CommandProvider
|
|
|
|
class MachCommands(MachCommandBase):
|
|
|
|
@Command('marionette-test', category='testing',
|
|
|
|
description='Run a Marionette test.',
|
|
|
|
conditions=[conditions.is_firefox])
|
|
|
|
@CommandArgument('--address',
|
|
|
|
help='host:port of running Gecko instance to connect to.')
|
|
|
|
@CommandArgument('--type', dest='testtype',
|
|
|
|
help='Test type, usually one of: browser, b2g, b2g-qemu.',
|
|
|
|
default='browser')
|
|
|
|
@CommandArgument('tests', nargs='*', metavar='TESTS',
|
|
|
|
help='Path to test(s) to run.')
|
|
|
|
def run_marionette_test(self, tests, address=None, testtype=None):
|
2014-01-16 18:58:56 +04:00
|
|
|
binary = self.get_binary_path('app')
|
|
|
|
return run_marionette(tests, binary=binary, testtype=testtype,
|
2013-10-15 23:54:21 +04:00
|
|
|
topsrcdir=self.topsrcdir, address=address)
|