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/.
|
|
|
|
|
2015-06-22 03:39:09 +03:00
|
|
|
from __future__ import absolute_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
|
2014-07-18 05:28:45 +04:00
|
|
|
import argparse
|
2014-01-16 18:58:56 +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
|
|
|
|
2016-05-31 20:15:37 +03:00
|
|
|
def setup_marionette_argument_parser():
|
2015-09-03 01:57:25 +03:00
|
|
|
from marionette.runner.base import BaseMarionetteArguments
|
|
|
|
return BaseMarionetteArguments()
|
2014-07-18 05:28:45 +04:00
|
|
|
|
2016-05-20 00:38:38 +03:00
|
|
|
def run_marionette(tests, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs):
|
2015-09-03 01:57:25 +03:00
|
|
|
from mozlog.structured import commandline
|
2014-10-10 20:58:10 +04:00
|
|
|
|
2015-03-04 04:37:19 +03:00
|
|
|
from marionette.runtests import (
|
2013-10-15 23:54:21 +04:00
|
|
|
MarionetteTestRunner,
|
2015-08-18 23:27:04 +03:00
|
|
|
BaseMarionetteArguments,
|
2015-11-09 17:07:52 +03:00
|
|
|
MarionetteHarness
|
2013-10-15 23:54:21 +04:00
|
|
|
)
|
|
|
|
|
2015-08-18 23:27:04 +03:00
|
|
|
parser = BaseMarionetteArguments()
|
2014-07-18 05:28:45 +04:00
|
|
|
commandline.add_logging_group(parser)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
|
|
|
if not tests:
|
|
|
|
tests = [os.path.join(topsrcdir,
|
2016-02-06 20:34:10 +03:00
|
|
|
'testing/marionette/harness/marionette/tests/unit-tests.ini')]
|
2016-02-29 20:39:28 +03:00
|
|
|
|
|
|
|
args = parser.parse_args(args=tests)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2016-05-20 00:38:38 +03:00
|
|
|
args.binary = binary
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2014-10-20 16:55:28 +04:00
|
|
|
for k, v in kwargs.iteritems():
|
2015-08-18 23:27:04 +03:00
|
|
|
setattr(args, k, v)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2015-08-18 23:27:04 +03:00
|
|
|
parser.verify_usage(args)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2015-08-18 23:27:04 +03:00
|
|
|
args.logger = commandline.setup_logging("Marionette Unit Tests",
|
|
|
|
args,
|
|
|
|
{"mach": sys.stdout})
|
2016-03-19 05:33:08 +03:00
|
|
|
failed = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
|
2015-11-10 21:09:13 +03:00
|
|
|
if failed > 0:
|
2015-11-09 17:07:52 +03:00
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
2013-04-19 16:19:54 +04:00
|
|
|
|
2016-05-31 20:15:37 +03:00
|
|
|
def setup_session_argument_parser():
|
|
|
|
from session.runner.base import BaseSessionArguments
|
|
|
|
return BaseSessionArguments()
|
|
|
|
|
|
|
|
def run_session(tests, testtype=None, address=None, binary=None, topsrcdir=None, **kwargs):
|
|
|
|
from mozlog.structured import commandline
|
|
|
|
|
|
|
|
from marionette.runtests import (
|
|
|
|
MarionetteHarness
|
|
|
|
)
|
|
|
|
|
|
|
|
from session.runtests import (
|
|
|
|
SessionTestRunner,
|
|
|
|
BaseSessionArguments,
|
|
|
|
SessionArguments,
|
|
|
|
SessionTestCase,
|
|
|
|
)
|
|
|
|
|
|
|
|
parser = BaseSessionArguments()
|
|
|
|
commandline.add_logging_group(parser)
|
|
|
|
|
|
|
|
if not tests:
|
|
|
|
tests = [os.path.join(topsrcdir,
|
|
|
|
'testing/marionette/harness/session/tests/unit-tests.ini')]
|
|
|
|
|
|
|
|
args = parser.parse_args(args=tests)
|
|
|
|
|
|
|
|
args.binary = binary
|
|
|
|
|
|
|
|
for k, v in kwargs.iteritems():
|
|
|
|
setattr(args, k, v)
|
|
|
|
|
|
|
|
parser.verify_usage(args)
|
|
|
|
|
|
|
|
args.logger = commandline.setup_logging("Session Unit Tests",
|
|
|
|
args,
|
|
|
|
{"mach": sys.stdout})
|
|
|
|
failed = MarionetteHarness(runner_class=SessionTestRunner, parser_class=SessionArguments,
|
|
|
|
testcase_class=SessionTestCase, args=vars(args)).run()
|
|
|
|
if failed > 0:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
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',
|
2014-08-09 17:37:29 +04:00
|
|
|
description='Run a Marionette webapi test (test WebAPIs using marionette).',
|
2013-10-15 23:54:21 +04:00
|
|
|
conditions=[conditions.is_b2g])
|
2015-03-19 23:15:33 +03: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 16:19:54 +04:00
|
|
|
@CommandArgument('tests', nargs='*', metavar='TESTS',
|
|
|
|
help='Path to test(s) to run.')
|
2014-10-20 16:55:28 +04:00
|
|
|
def run_marionette_webapi(self, tests, **kwargs):
|
2014-04-30 20:57:39 +04: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 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,
|
2014-10-20 16:55:28 +04:00
|
|
|
topsrcdir=self.topsrcdir, **kwargs)
|
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',
|
2014-08-09 17:37:29 +04:00
|
|
|
description='Run a Marionette test (Check UI or the internal JavaScript using marionette).',
|
2014-07-18 05:28:45 +04:00
|
|
|
conditions=[conditions.is_firefox],
|
2016-05-31 20:15:37 +03:00
|
|
|
parser=setup_marionette_argument_parser,
|
2014-07-18 05:28:45 +04:00
|
|
|
)
|
2014-10-20 16:55:28 +04:00
|
|
|
def run_marionette_test(self, tests, **kwargs):
|
2015-09-18 16:53:37 +03:00
|
|
|
if 'test_objects' in kwargs:
|
|
|
|
tests = []
|
|
|
|
for obj in kwargs['test_objects']:
|
|
|
|
tests.append(obj['file_relpath'])
|
|
|
|
del kwargs['test_objects']
|
|
|
|
|
2016-06-27 21:21:31 +03:00
|
|
|
bin_path = self.get_binary_path('app')
|
2016-06-28 14:44:30 +03:00
|
|
|
if kwargs.get('binary') is not None:
|
2016-06-27 21:21:31 +03:00
|
|
|
print "Warning: ignoring '--binary' option, using binary at " + bin_path
|
|
|
|
kwargs['binary'] = bin_path
|
2015-09-03 01:57:25 +03:00
|
|
|
return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
|
2016-05-31 20:15:37 +03:00
|
|
|
|
|
|
|
@Command('session-test', category='testing',
|
|
|
|
description='Run a Session test (Check Telemetry using marionette).',
|
|
|
|
conditions=[conditions.is_firefox],
|
|
|
|
parser=setup_session_argument_parser,
|
|
|
|
)
|
|
|
|
def run_session_test(self, tests, **kwargs):
|
|
|
|
if 'test_objects' in kwargs:
|
|
|
|
tests = []
|
|
|
|
for obj in kwargs['test_objects']:
|
|
|
|
tests.append(obj['file_relpath'])
|
|
|
|
del kwargs['test_objects']
|
|
|
|
|
|
|
|
kwargs['binary'] = self.get_binary_path('app')
|
|
|
|
return run_session(tests, topsrcdir=self.topsrcdir, **kwargs)
|