# 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 web-platform-tests test runner with mach.
import os import sys
from mach.decorators import Command from mach_commands_base import WebPlatformTestsRunner, create_parser_wpt from mozbuild.base import MachCommandConditions as conditions from mozbuild.base import MozbuildObject
here = os.path.abspath(os.path.dirname(__file__))
INTEROP_REQUIREMENTS_PATH = os.path.join(here, "interop_requirements.txt")
class WebPlatformTestsRunnerSetup(MozbuildObject):
default_log_type = "mach"
if kwargs["product"] in {"firefox", "firefox_android"}: if kwargs["specialpowers_path"] isNone:
kwargs["specialpowers_path"] = os.path.join(
self.distdir, "xpi-stage", "specialpowers@mozilla.org.xpi"
)
if (
kwargs["exclude"] isNone and kwargs["include"] isNone andnot sys.platform.startswith("linux")
):
kwargs["exclude"] = ["css"]
if kwargs["ssl_type"] in (None, "pregenerated"):
cert_root = os.path.join(tests_src_path, "tools", "certs") if kwargs["ca_cert_path"] isNone:
kwargs["ca_cert_path"] = os.path.join(cert_root, "cacert.pem")
if kwargs["host_key_path"] isNone:
kwargs["host_key_path"] = os.path.join(
cert_root, "web-platform.test.key"
)
if kwargs["host_cert_path"] isNone:
kwargs["host_cert_path"] = os.path.join(
cert_root, "web-platform.test.pem"
)
if kwargs["reftest_screenshot"] isNone:
kwargs["reftest_screenshot"] = "fail"
kwargs["capture_stdio"] = True
return kwargs
def kwargs_firefox(self, kwargs): """Setup kwargs specific to running Firefox and other gecko browsers""" from wptrunner import wptcommandline
kwargs = self.kwargs_common(kwargs)
if kwargs["binary"] isNone:
kwargs["binary"] = self.get_binary_path()
if kwargs["webdriver_binary"] isNone:
kwargs["webdriver_binary"] = self.find_webdriver_binary()
if kwargs["certutil_binary"] isNone:
kwargs["certutil_binary"] = self.get_binary_path("certutil")
if kwargs["install_fonts"] isNone:
kwargs["install_fonts"] = True
if kwargs["preload_browser"] isNone:
kwargs["preload_browser"] = False
if kwargs["prefs_root"] isNone:
kwargs["prefs_root"] = os.path.join(self.topsrcdir, "testing", "profiles")
if kwargs["stackfix_dir"] isNone:
kwargs["stackfix_dir"] = self.bindir
kwargs["gmp_path"] = os.pathsep.join(
os.path.join(self.distdir, "bin", p, "1.0") for p in ("gmp-fake", "gmp-fakeopenh264")
)
kwargs = wptcommandline.check_args(kwargs)
return kwargs
def kwargs_firefox_android(self, kwargs): from wptrunner import wptcommandline
kwargs = self.kwargs_common(kwargs)
# package_name may be different in the future
package_name = kwargs["package_name"] ifnot package_name:
kwargs["package_name"] = package_name = "org.mozilla.geckoview.test_runner"
# Note that this import may fail in non-firefox-for-android trees from mozrunner.devices.android_device import (
InstallIntent,
get_adb_path,
verify_android_device,
)
def kwargs_wptrun(self, kwargs): """Setup kwargs for wpt-run which is only used for non-gecko browser products""" from tools.wpt import run, virtualenv
kwargs = self.kwargs_common(kwargs)
# Our existing kwargs corresponds to the wptrunner command line arguments. # `wpt run` extends this with some additional arguments that are consumed by # the frontend. Copy over the default values of these extra arguments so they # are present when we call into that frontend.
run_parser = run.create_parser()
run_kwargs = run_parser.parse_args([kwargs["product"], kwargs["test_list"]])
for key, value in vars(run_kwargs).items(): if key notin kwargs:
kwargs[key] = value
# Install the deps # We do this explicitly to avoid calling pip with options that aren't # supported in the in-tree version
wptrunner_path = os.path.join(self._here, "tests", "tools", "wptrunner")
browser_cls = run.product_setup[kwargs["product"]].browser_cls
requirements = ["requirements.txt"] if (
hasattr(browser_cls, "requirements") and browser_cls.requirements isnotNone
):
requirements.append(browser_cls.requirements)
for filename in requirements:
path = os.path.join(wptrunner_path, filename) if os.path.exists(path):
self.virtualenv_manager.install_pip_requirements(
path, require_hashes=False
)
# This is kind of a hack; override the metadata paths so we don't use # gecko metadata for non-gecko products for url_base, test_root in kwargs["test_paths"].items():
meta_suffix = url_base.strip("/")
meta_dir = os.path.join(
self._here, "products", kwargs["product"].name, meta_suffix
)
test_root.metadata_path = meta_dir ifnot os.path.exists(meta_dir):
os.makedirs(meta_dir) return kwargs
def setup_fonts_firefox(self): # Ensure the Ahem font is available ifnot sys.platform.startswith("darwin"):
font_path = os.path.join(os.path.dirname(self.get_binary_path()), "fonts") else:
font_path = os.path.join(
os.path.dirname(self.get_binary_path()),
os.pardir, "Resources", "res", "fonts",
)
ahem_src = os.path.join(
self.topsrcdir, "testing", "web-platform", "tests", "fonts", "Ahem.ttf"
)
ahem_dest = os.path.join(font_path, "Ahem.ttf") ifnot os.path.exists(ahem_dest) and os.path.exists(ahem_src): with open(ahem_src, "rb") as src, open(ahem_dest, "wb") as dest:
dest.write(src.read())
for build_type in ["release", "debug"]:
try_paths.append(
os.path.join(self.topsrcdir, "target", build_type, f"geckodriver{ext}")
)
found_paths = [] for path in try_paths: if os.path.exists(path):
found_paths.append(path)
if found_paths: # Pick the most recently modified version
found_paths.sort(key=os.path.getmtime) return found_paths[-1]
parser = argparse.ArgumentParser()
parser.add_argument( "--no-update",
dest="update",
action="store_false",
default=True,
help="Don't update manifest before continuing",
)
parser.add_argument( "-r", "--rebuild",
action="store_true",
default=False,
help="Force a full rebuild of the manifest.",
)
parser.add_argument( "--cache-root",
action="store",
default=os.path.join(get_state_dir(), "cache", "wpt"),
help="Path in which to store any caches (default /.wptcache/)",
)
parser.add_argument( "test_ids", action="store", nargs="+", help="Test ids for which to get paths"
)
parser.add_argument( "--json", action="store_true", default=False, help="Output as JSON"
) return parser
@Command( "web-platform-tests",
category="testing",
conditions=[conditions.is_firefox_or_android],
description="Run web-platform-tests.",
parser=create_parser_wpt,
virtualenv_name="wpt",
) def run_web_platform_tests(command_context, **params): if params["product"] isNone: if conditions.is_android(command_context):
params["product"] = "firefox_android" else:
params["product"] = "firefox" if"test_objects"in params:
include = []
test_types = set() for item in params["test_objects"]:
include.append(item["name"])
test_types.add(item.get("subsuite")) ifNonenotin test_types:
params["test_types"] = list(test_types)
params["include"] = include del params["test_objects"] # subsuite coming from `mach test` means something more like `test type`, so remove that argument if"subsuite"in params: del params["subsuite"] if params.get("debugger", None): import mozdebug
logger = wpt_runner.setup_logging(**params) # wptrunner already handles setting any log parameter from # mach test to the logger, so it's OK to remove that argument now if"log"in params: del params["log"]
if (
conditions.is_android(command_context) and params["product"] != "firefox_android"
):
logger.warning("Must specify --product=firefox_android in Android environment.")
@Command( "wpt-interop-score",
category="testing",
description="Score a run according to Interop 2023",
parser=create_parser_interop_score,
virtualenv_name="wpt-interop",
) def wpt_interop_score(command_context, **params): import interop
interop.score_runs(**params) return 0
¤ Dauer der Verarbeitung: 0.31 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.