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