Bug 1890277: part 4) Add CSPParser support for the `trusted-types` directive, guarded...
[gecko.git] / testing / gtest / mach_test_package_commands.py
blob0b11db89979173cdff579fb42f580bb67f1bda93
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 os
6 import sys
7 from argparse import Namespace
9 from mach.decorators import Command
11 here = os.path.abspath(os.path.dirname(__file__))
12 parser = None
13 logger = None
16 def run_gtest(context, **kwargs):
17 from mozlog.commandline import setup_logging
19 if not kwargs.get("log"):
20 kwargs["log"] = setup_logging("gtest", kwargs, {"mach": sys.stdout})
21 global logger
22 logger = kwargs["log"]
24 args = Namespace(**kwargs)
26 import mozinfo
28 if mozinfo.info.get("buildapp") == "mobile/android":
29 return run_gtest_android(context, args)
30 return run_gtest_desktop(context, args)
33 def run_gtest_desktop(context, args):
34 prog = context.firefox_bin
35 xre_path = os.path.dirname(context.firefox_bin)
36 if sys.platform == "darwin":
37 xre_path = os.path.join(xre_path, "Resources")
38 utility_path = context.bin_dir
39 cwd = os.path.join(context.package_root, "gtest")
41 logger.info(
42 "mach calling run_gtest with prog=%s xre_path=%s cwd=%s utility_path=%s"
43 % (prog, xre_path, cwd, utility_path)
45 # The gtest option parser ignores some options normally passed to the mozharness
46 # command, so some hacking is required, for now:
47 extra_args = [arg for arg in args.args if not arg.startswith("-")]
48 if extra_args:
49 os.environ["GTEST_FILTER"] = extra_args[0]
50 logger.info("GTEST_FILTER=%s" % extra_args[0])
52 import rungtests
54 tester = rungtests.GTests()
55 return tester.run_gtest(prog, xre_path, cwd, utility_path=utility_path)
58 def run_gtest_android(context, args):
59 config = context.mozharness_config
60 if config:
61 args.adb_path = config["exes"]["adb"] % {
62 "abs_work_dir": context.mozharness_workdir
64 cwd = os.path.join(context.package_root, "gtest")
65 libxul_path = os.path.join(cwd, "gtest_bin", "gtest", "libxul.so")
67 logger.info(
68 "mach calling android run_gtest with package=%s cwd=%s libxul=%s"
69 % (args.package, cwd, libxul_path)
71 # The remote gtest option parser ignores some options normally passed to the mozharness
72 # command, so some hacking is required, for now:
73 extra_args = [arg for arg in args.args if not arg.startswith("-")]
74 test_filter = extra_args[0] if extra_args else None
75 logger.info("test filter=%s" % test_filter)
77 import remotegtests
79 tester = remotegtests.RemoteGTests()
80 return tester.run_gtest(
81 cwd,
82 args.shuffle,
83 test_filter,
84 args.package,
85 args.adb_path,
86 args.device_serial,
87 args.remote_test_root,
88 libxul_path,
89 args.symbols_path,
93 def setup_argument_parser():
94 import mozinfo
96 mozinfo.find_and_update_from_json(here)
97 global parser
98 if mozinfo.info.get("buildapp") == "mobile/android":
99 import remotegtests
101 parser = remotegtests.remoteGtestOptions()
102 else:
103 import rungtests
105 parser = rungtests.gtestOptions()
106 return parser
109 @Command(
110 "gtest",
111 category="testing",
112 description="Run the gtest harness.",
113 parser=setup_argument_parser,
115 def gtest(command_context, **kwargs):
116 command_context._mach_context.activate_mozharness_venv()
117 result = run_gtest(command_context._mach_context, **kwargs)
118 return 0 if result else 1