# 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/.
# Integrates the xpcshell test runner with mach.
import errno import logging import os import sys
from mach.decorators import Command from mozbuild.base import BinaryNotFoundException, MozbuildObject from mozbuild.base import MachCommandConditions as conditions from mozbuild.util import cpu_count, macos_performance_cores from mozlog import structured from xpcshellcommandline import parser_desktop, parser_remote
here = os.path.abspath(os.path.dirname(__file__))
# This should probably be consolidated with similar classes in other test # runners. class InvalidTestPathError(Exception): """Exception raised when the test path is not valid."""
class XPCShellRunner(MozbuildObject): """Run xpcshell tests."""
def run_test(self, **kwargs): """Runs an individual xpcshell test."""
# TODO Bug 794506 remove once mach integrates with virtualenv.
build_path = os.path.join(self.topobjdir, "build") if build_path notin sys.path:
sys.path.append(build_path)
src_build_path = os.path.join(self.topsrcdir, "mozilla", "build") if os.path.isdir(src_build_path):
sys.path.append(src_build_path)
return self.run_suite(**kwargs)
def _run_xpcshell_harness(self, **kwargs): # Obtain a reference to the xpcshell test runner. import runxpcshelltests
tests_dir = os.path.join(self.topobjdir, "_tests", "xpcshell") # We want output from the test to be written immediately if we are only # running a single test.
single_test = (
len(kwargs["testPaths"]) == 1 and os.path.isfile(kwargs["testPaths"][0]) or kwargs["manifest"] and (len(kwargs["manifest"].test_paths()) == 1)
)
if kwargs["mozInfo"] isNone:
kwargs["mozInfo"] = os.path.join(self.topobjdir, "mozinfo.json")
if kwargs["symbolsPath"] isNone:
kwargs["symbolsPath"] = os.path.join(self.distdir, "crashreporter-symbols")
if kwargs["logfiles"] isNone:
kwargs["logfiles"] = False
if kwargs["profileName"] isNone:
kwargs["profileName"] = "firefox"
if kwargs["testingModulesDir"] isNone:
kwargs["testingModulesDir"] = os.path.join(self.topobjdir, "_tests/modules")
if kwargs["utility_path"] isNone:
kwargs["utility_path"] = self.bindir
if kwargs["manifest"] isNone:
kwargs["manifest"] = os.path.join(tests_dir, "xpcshell.toml")
if kwargs["failure_manifest"] isNone:
kwargs["failure_manifest"] = os.path.join(
self.statedir, "xpcshell.failures.toml"
)
# Use the object directory for the temp directory to minimize the chance # of file scanning. The overhead from e.g. search indexers and anti-virus # scanners like Windows Defender can add tons of overhead to test execution. # We encourage people to disable these things in the object directory.
temp_dir = os.path.join(self.topobjdir, "temp") try:
os.mkdir(temp_dir) except OSError as e: if e.errno != errno.EEXIST: raise
kwargs["tempDir"] = temp_dir
result = xpcshell.runTests(kwargs)
self.log_manager.disable_unstructured()
ifnot result andnot xpcshell.sequential:
print( "Tests were run in parallel. Try running with --sequential " "to make sure the failures were not caused by this."
) return int(not result)
class AndroidXPCShellRunner(MozbuildObject): """Run Android xpcshell tests."""
def run_test(self, **kwargs): # TODO Bug 794506 remove once mach integrates with virtualenv.
build_path = os.path.join(self.topobjdir, "build") if build_path notin sys.path:
sys.path.append(build_path)
ifnot kwargs["localAPK"]: for root, _, paths in os.walk(os.path.join(kwargs["objdir"], "gradle")): for file_name in paths: if file_name.endswith(".apk") and file_name.startswith( "test_runner"
):
kwargs["localAPK"] = os.path.join(root, file_name)
print("using APK: %s" % kwargs["localAPK"]) break if kwargs["localAPK"]: break else: raise Exception("APK not found in objdir. You must specify an APK.")
ifnot kwargs["xrePath"]:
MOZ_HOST_BIN = os.environ.get("MOZ_HOST_BIN") if MOZ_HOST_BIN:
kwargs["xrePath"] = MOZ_HOST_BIN
# We should probably have a utility function to ensure the tree is # ready to run tests. Until then, we just create the state dir (in # case the tree wasn't built with mach).
command_context._ensure_state_subdir_exists(".")
ifnot params["threadCount"]: if sys.platform == "darwin": # On Apple Silicon, we have found that increasing the number of # threads (processes) above the CPU count reduces the performance # (bug 1917833), and makes the machine less performant. It is even # better if we can use the exact number of performance cores, so we # attempt to do that here.
perf_cores = macos_performance_cores() if perf_cores > 0:
params["threadCount"] = perf_cores else:
params["threadCount"] = int((cpu_count() * 3) / 2) else: # pylint --py3k W1619
params["threadCount"] = int((cpu_count() * 3) / 2)
if conditions.is_android(command_context): from mozrunner.devices.android_device import (
InstallIntent,
get_adb_path,
verify_android_device,
)
if sys.platform == "linux":
install_portal_test_dependencies = False if"manifest"in params and params["manifest"]: # When run from "mach test", the manifest is available now. try:
tags = " ".join(params["manifest"].get("tags")).split(" ") except KeyError: # .get("tags") may raise KeyError.
tags = [] if"webextensions"in tags and"portal"in tags:
install_portal_test_dependencies = True else: # When run from "mach xpcshell-test", the manifest is not available # yet. We could default to True to force the initialization of the # virtualenv, but that would force this dependency on every use of # "mach xpcshell-test". So for now, force it to False. # If a dev wants to run the test, they can run "mach test" instead.
install_portal_test_dependencies = False
if install_portal_test_dependencies:
dir_relpath = params["manifest"].get("dir_relpath")[0] # Only Linux Native Messaging Portal xpcshell tests need this.
req = os.path.join(
dir_relpath, "linux_native-messaging-portal_requirements.txt",
)
command_context.virtualenv_manager.activate()
command_context.virtualenv_manager.install_pip_requirements(
req, require_hashes=False
)
try: return xpcshell.run_test(**params) except InvalidTestPathError as e:
print(str(e)) return 1
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.