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/.
7 from argparse
import Namespace
9 from mach
.decorators
import Command
11 here
= os
.path
.abspath(os
.path
.dirname(__file__
))
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
})
22 logger
= kwargs
["log"]
24 args
= Namespace(**kwargs
)
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")
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("-")]
49 os
.environ
["GTEST_FILTER"] = extra_args
[0]
50 logger
.info("GTEST_FILTER=%s" % extra_args
[0])
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
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")
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
)
79 tester
= remotegtests
.RemoteGTests()
80 return tester
.run_gtest(
87 args
.remote_test_root
,
93 def setup_argument_parser():
96 mozinfo
.find_and_update_from_json(here
)
98 if mozinfo
.info
.get("buildapp") == "mobile/android":
101 parser
= remotegtests
.remoteGtestOptions()
105 parser
= rungtests
.gtestOptions()
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