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/.
|
|
|
|
|
2018-01-17 18:14:43 +03:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2014-01-16 18:58:56 +04:00
|
|
|
|
2017-07-26 17:00:47 +03:00
|
|
|
import argparse
|
2020-04-02 16:04:41 +03:00
|
|
|
import functools
|
2020-04-21 14:58:04 +03:00
|
|
|
import logging
|
2013-04-19 16:19:54 +04:00
|
|
|
import os
|
2014-01-16 18:58:56 +04:00
|
|
|
import sys
|
2013-04-19 16:19:54 +04:00
|
|
|
|
2019-11-25 19:33:45 +03:00
|
|
|
from six import iteritems
|
|
|
|
|
2013-04-19 16:19:54 +04:00
|
|
|
from mach.decorators import (
|
|
|
|
CommandProvider,
|
|
|
|
Command,
|
|
|
|
)
|
|
|
|
|
2017-07-26 17:00:47 +03:00
|
|
|
from mozbuild.base import (
|
|
|
|
MachCommandBase,
|
|
|
|
MachCommandConditions as conditions,
|
2020-04-21 14:58:04 +03:00
|
|
|
BinaryNotFoundException,
|
2017-07-26 17:00:47 +03:00
|
|
|
)
|
|
|
|
|
2019-06-27 17:09:05 +03:00
|
|
|
SUPPORTED_APPS = ['firefox', 'android', 'thunderbird']
|
2017-07-26 17:00:47 +03:00
|
|
|
|
|
|
|
def create_parser_tests():
|
2016-12-13 20:10:51 +03:00
|
|
|
from marionette_harness.runtests import MarionetteArguments
|
2016-07-27 07:52:42 +03:00
|
|
|
from mozlog.structured import commandline
|
2019-02-20 22:18:06 +03:00
|
|
|
|
2016-07-27 07:52:42 +03:00
|
|
|
parser = MarionetteArguments()
|
|
|
|
commandline.add_logging_group(parser)
|
|
|
|
return parser
|
2014-07-18 05:28:45 +04:00
|
|
|
|
2017-07-26 17:00:47 +03:00
|
|
|
|
2016-07-05 21:09:33 +03:00
|
|
|
def run_marionette(tests, 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
|
|
|
|
2016-12-13 20:10:51 +03:00
|
|
|
from marionette_harness.runtests import (
|
2013-10-15 23:54:21 +04:00
|
|
|
MarionetteTestRunner,
|
2015-11-09 17:07:52 +03:00
|
|
|
MarionetteHarness
|
2013-10-15 23:54:21 +04:00
|
|
|
)
|
|
|
|
|
2017-07-26 17:00:47 +03:00
|
|
|
parser = create_parser_tests()
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2016-06-29 19:55:32 +03:00
|
|
|
args = argparse.Namespace(tests=tests)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2016-05-20 00:38:38 +03:00
|
|
|
args.binary = binary
|
2018-03-13 16:49:09 +03:00
|
|
|
args.logger = kwargs.pop('log', None)
|
2013-10-15 23:54:21 +04:00
|
|
|
|
2019-11-25 19:33:45 +03:00
|
|
|
for k, v in iteritems(kwargs):
|
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
|
|
|
|
2017-11-23 21:04:19 +03:00
|
|
|
if not args.logger:
|
|
|
|
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
|
|
|
|
2017-07-26 17:00:47 +03:00
|
|
|
|
2013-10-15 23:54:21 +04:00
|
|
|
@CommandProvider
|
2018-01-24 22:13:34 +03:00
|
|
|
class MarionetteTest(MachCommandBase):
|
2017-07-26 17:00:47 +03:00
|
|
|
@Command("marionette-test",
|
|
|
|
category="testing",
|
2019-03-13 20:14:35 +03:00
|
|
|
description="Remote control protocol to Gecko, used for browser automation.",
|
2020-04-02 16:04:41 +03:00
|
|
|
conditions=[functools.partial(conditions.is_buildapp_in, apps=SUPPORTED_APPS)],
|
2017-07-26 17:00:47 +03:00
|
|
|
parser=create_parser_tests,
|
|
|
|
)
|
2018-01-24 22:13:34 +03:00
|
|
|
def marionette_test(self, tests, **kwargs):
|
2017-07-26 17:00:47 +03:00
|
|
|
if "test_objects" in kwargs:
|
|
|
|
tests = []
|
|
|
|
for obj in kwargs["test_objects"]:
|
|
|
|
tests.append(obj["file_relpath"])
|
|
|
|
del kwargs["test_objects"]
|
|
|
|
|
2019-06-27 17:09:05 +03:00
|
|
|
if not tests:
|
|
|
|
if conditions.is_thunderbird(self):
|
|
|
|
tests = [os.path.join(self.topsrcdir,
|
|
|
|
"comm/testing/marionette/unit-tests.ini")]
|
|
|
|
else:
|
|
|
|
tests = [os.path.join(self.topsrcdir,
|
|
|
|
"testing/marionette/harness/marionette_harness/tests/unit-tests.ini")]
|
|
|
|
|
|
|
|
if not kwargs.get("binary") and \
|
|
|
|
(conditions.is_firefox(self) or conditions.is_thunderbird(self)):
|
2020-04-21 14:58:04 +03:00
|
|
|
try:
|
|
|
|
kwargs["binary"] = self.get_binary_path("app")
|
|
|
|
except BinaryNotFoundException as e:
|
|
|
|
self.log(logging.ERROR, 'marionette-test',
|
|
|
|
{'error': str(e)},
|
|
|
|
'ERROR: {error}')
|
|
|
|
self.log(logging.INFO, 'marionette-test',
|
|
|
|
{'help': e.help()},
|
|
|
|
'{help}')
|
|
|
|
return 1
|
2019-03-14 13:29:47 +03:00
|
|
|
|
2017-07-26 17:00:47 +03:00
|
|
|
return run_marionette(tests, topsrcdir=self.topsrcdir, **kwargs)
|