Bug 1883861 - Part 1: Move visitMemoryBarrier into the common CodeGenerator file...
[gecko.git] / testing / firefox-ui / mach_commands.py
blob4c0d4a126f1946740f0a8600a9d8aff97c82b14c
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 import logging
6 import os
7 import sys
9 import six
10 from mach.decorators import Command
11 from mozbuild.base import BinaryNotFoundException
12 from mozbuild.base import MachCommandConditions as conditions
15 def setup_argument_parser_functional():
16 from firefox_ui_harness.arguments.base import FirefoxUIArguments
17 from mozlog.structured import commandline
19 parser = FirefoxUIArguments()
20 commandline.add_logging_group(parser)
21 return parser
24 def run_firefox_ui_test(topsrcdir=None, **kwargs):
25 from argparse import Namespace
27 import firefox_ui_harness
28 from mozlog.structured import commandline
30 parser = setup_argument_parser_functional()
32 fxui_dir = os.path.join(topsrcdir, "testing", "firefox-ui")
34 # Set the resources path which is used to serve test data via wptserve
35 if not kwargs["server_root"]:
36 kwargs["server_root"] = os.path.join(fxui_dir, "resources")
38 # If called via "mach test" a dictionary of tests is passed in
39 if "test_objects" in kwargs:
40 tests = []
41 for obj in kwargs["test_objects"]:
42 tests.append(obj["file_relpath"])
43 kwargs["tests"] = tests
44 elif not kwargs.get("tests"):
45 # If no tests have been selected, set default ones
46 kwargs["tests"] = os.path.join(fxui_dir, "tests", "functional", "manifest.ini")
48 kwargs["logger"] = kwargs.pop("log", None)
49 if not kwargs["logger"]:
50 kwargs["logger"] = commandline.setup_logging(
51 "Firefox UI - Functional Tests", {"mach": sys.stdout}
54 args = Namespace()
56 for k, v in six.iteritems(kwargs):
57 setattr(args, k, v)
59 parser.verify_usage(args)
61 failed = firefox_ui_harness.cli_functional.cli(args=vars(args))
63 if failed > 0:
64 return 1
65 else:
66 return 0
69 @Command(
70 "firefox-ui-functional",
71 category="testing",
72 conditions=[conditions.is_firefox],
73 description="Run the functional test suite of Firefox UI tests.",
74 parser=setup_argument_parser_functional,
76 def run_firefox_ui_functional(command_context, **kwargs):
77 try:
78 kwargs["binary"] = kwargs["binary"] or command_context.get_binary_path("app")
79 except BinaryNotFoundException as e:
80 command_context.log(
81 logging.ERROR,
82 "firefox-ui-functional",
83 {"error": str(e)},
84 "ERROR: {error}",
86 command_context.log(
87 logging.INFO, "firefox-ui-functional", {"help": e.help()}, "{help}"
89 return 1
91 return run_firefox_ui_test(topsrcdir=command_context.topsrcdir, **kwargs)