# 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/.
"""Utility functions to handle test chunking."""
import json import logging import os from abc import ABCMeta, abstractmethod
from manifestparser import TestManifest from manifestparser.filters import chunk_by_runtime, tags from mozbuild.util import memoize from mozinfo.platforminfo import PlatformInfo from moztest.resolve import TEST_SUITES, TestManifestLoader, TestResolver from taskgraph.util.yaml import load_yaml
from gecko_taskgraph import GECKO from gecko_taskgraph.util.bugbug import CT_LOW, BugbugTimeoutException, push_schedules
logger = logging.getLogger(__name__)
here = os.path.abspath(os.path.dirname(__file__))
resolver = TestResolver.from_environment(cwd=here, loader_cls=TestManifestLoader)
def guess_mozinfo_from_task(task, repo="", app_version="", test_tags=[]): """Attempt to build a mozinfo dict from a task definition.
This won't be perfect and many values used in the manifests will be missing. But
it should cover most of the major ones and be "good enough"for chunking in the
taskgraph.
Args:
task (dict): A task definition.
Returns:
A dict that can be used as a mozinfo replacement. """
setting = task["test-setting"]
runtime_keys = setting["runtime"].keys()
platform_info = PlatformInfo(setting)
info = { "debug": platform_info.debug, "bits": platform_info.bits, "asan": setting["build"].get("asan", False), "tsan": setting["build"].get("tsan", False), "ccov": setting["build"].get("ccov", False), "mingwclang": setting["build"].get("mingwclang", False), "nightly_build": "a1" in app_version, # https://searchfox.org/mozilla-central/source/build/moz.configure/init.configure#1101 "release_or_beta": "a"notin app_version, "repo": repo,
} # the following are used to evaluate reftest skip-if
info["webrtc"] = not info["mingwclang"]
info["opt"] = ( not info["debug"] andnot info["asan"] andnot info["tsan"] andnot info["ccov"]
)
info["os"] = platform_info.os
# crashreporter is disabled for asan / tsan builds if info["asan"] or info["tsan"]:
info["crashreporter"] = False else:
info["crashreporter"] = True
for variant in TEST_VARIANTS:
tag = TEST_VARIANTS[variant].get("mozinfo", "") if tag == "": continue
value = variant in runtime_keys
if variant == "1proc":
value = not value elif"fission"in variant:
value = any( "1proc"notin key or"no-fission"notin key for key in runtime_keys
) if"no-fission"notin variant:
value = not value elif tag == "xorigin":
value = any("xorigin"in key for key in runtime_keys)
info[tag] = value
# wpt has canvas and webgpu as tags, lets find those for tag in WPT_SUBSUITES.keys(): if tag in task["test-name"]:
info[tag] = True else:
info[tag] = False
# NOTE: as we are using an array here, frozenset() cannot work with a 'list' # this is cast to a string
info["tag"] = json.dumps(test_tags)
info["automation"] = True return info
@memoize def get_runtimes(platform, suite_name): ifnot suite_name ornot platform: raise TypeError("suite_name and platform cannot be empty.")
base = os.path.join(GECKO, "testing", "runtimes", "manifest-runtimes-{}.json") for key in ("android", "windows"): if key in platform:
path = base.format(key) break else:
path = base.format("unix")
ifnot os.path.exists(path): raise OSError(f"manifest runtime file at {path} not found.")
with open(path) as fh: return json.load(fh)[suite_name]
def chunk_manifests(suite, platform, chunks, manifests): """Run the chunking algorithm.
Args:
platform (str): Platform used to find runtime info.
chunks (int): Number of chunks to split manifests into.
manifests(list): Manifests to chunk.
Returns:
A list of length `chunks` where each item contains a list of manifests
that run in that chunk. """
ini_manifests = set([x.replace(".toml", ".ini") for x in manifests])
if"web-platform-tests"notin suite and"marionette"notin suite:
runtimes = {
k: v for k, v in get_runtimes(platform, suite).items() if k in ini_manifests
}
retVal = [] for c in chunk_by_runtime(None, chunks, runtimes).get_chunked_manifests(
ini_manifests
):
retVal.append(
[m if m in manifests else m.replace(".ini", ".toml") for m in c[1]]
)
# Keep track of test paths for each chunk, and the runtime information.
chunked_manifests = [[] for _ in range(chunks)]
# Spread out the test manifests evenly across all chunks. for index, key in enumerate(sorted(manifests)):
chunked_manifests[index % chunks].append(key)
# One last sort by the number of manifests. Chunk size should be more or less # equal in size.
chunked_manifests.sort(key=lambda x: len(x))
# Return just the chunked test paths. return chunked_manifests
class BaseManifestLoader(metaclass=ABCMeta): def __init__(self, params):
self.params = params
@abstractmethod def get_manifests(self, flavor, subsuite, mozinfo): """Compute which manifests should run for the given flavor, subsuite and mozinfo.
This function returns skipped manifests separately so that more balanced
chunks can be achieved by only considering "active" manifests in the
chunking algorithm.
Args:
flavor (str): The suite to run. Values are defined by the 'build_flavor' key in `moztest.resolve.TEST_SUITES`.
subsuite (str): The subsuite to run or'undefined' to denote no subsuite.
mozinfo (frozenset): Set of data in the form of (<key>, <value>) used for filtering.
Returns:
A tuple of two manifest lists. The first is the set of active manifests (will
run at least one test. The second is a list of skipped manifests (all tests are
skipped). """
class DefaultLoader(BaseManifestLoader): """Load manifests using metadata from the TestResolver."""
@memoize def get_manifests(self, suite, frozen_mozinfo):
mozinfo = dict(frozen_mozinfo) # Compute all tests for the given suite/subsuite.
tests = self.get_tests(suite)
if"web-platform-tests"in suite:
manifests = set()
subsuite = [x for x in WPT_SUBSUITES.keys() if mozinfo[x]] for t in tests: if json.loads(mozinfo["tag"]) andnot any(
x in t.get("tags", []) for x in json.loads(mozinfo["tag"])
): continue if subsuite: # add specific directories if any(x in t["manifest"] for x in WPT_SUBSUITES[subsuite[0]]):
manifests.add(t["manifest"]) else:
containsSubsuite = False for subsuites in WPT_SUBSUITES.values(): if any(subsuite in t["manifest"] for subsuite in subsuites):
containsSubsuite = True break
manifests = {chunk_by_runtime.get_manifest(t) for t in tests}
filters = [] if json.loads(mozinfo["tag"]):
filters.extend([tags([x]) for x in json.loads(mozinfo["tag"])])
# Compute the active tests.
m = TestManifest()
m.tests = tests
tests = m.active_tests(disabled=False, exists=False, filters=filters, **mozinfo)
active = {} # map manifests and 'other' directories included for t in tests:
mp = chunk_by_runtime.get_manifest(t)
active.setdefault(mp, [])
# Don't prune any manifests if we're on a backstop push or there was a timeout. if self.params["backstop"] or self.timedout: return manifests
try:
data = push_schedules(self.params["project"], self.params["head_rev"]) except BugbugTimeoutException:
logger.warning("Timed out waiting for bugbug, loading all test manifests.")
self.timedout = True return self.get_manifests(suite, mozinfo)
bugbug_manifests = {
m for m, c in data.get("groups", {}).items() if c >= self.CONFIDENCE_THRESHOLD
}
def get_manifest_loader(name, params): # Ensure we never create more than one instance of the same loader type for # performance reasons. if name in _loader_cache: return _loader_cache[name]
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.