Every instance rt's device tests open goes through one helper, crate::tests::validation. It enables VK_LAYER_KHRONOS_validation for its own test process through the loader's and the layer's own variables (VK_INSTANCE_LAYERS; report flags error,warn, debug action log, one log file per process). It checks that every device of the cfg's kind lists an active validation tool (vkGetPhysicalDeviceToolProperties), so a run whose loader found no layer fails. Once the instance is gone, it reads the log, prints each line with the test's name and fails on any message. The 41 sites that called Instance::new go through it; the exit-handler test reads its child's log, since the child's instance never drops. One test makes a deliberately invalid call (a buffer of size 0, refused by the layer) and checks that its log holds exactly VUID-VkBufferCreateInfo-size-00912. The product keeps no layer code and no variable read. Its one change is a visibility: Instance's shared state is pub(crate), so the helper waits, bounded, on a weak handle of it until the instance is gone, and only then reads the log. scripts/validation-layer makes the layer's directory, one version (1.4.363.0) on every leg, as a carry: Linux's copied from a node whose pacman package is that version and unaltered, Windows's from MSYS2's clang64 packages checked against the package database's SHA-256, and macOS's from a Homebrew install at that version. scripts/matrix carries it to every job that runs rt's device tests (GPU legs, lavapipe, the Windows host), points VK_LAYER_PATH at it, and puts the layer's version in the leg's note. A job without the layer says so and points the loader at none. The harness's timing jobs run without it. Verified: the matrix's unit tests (48, two new ones run the layer's shell for real) and the layer carry made. Builds and legs follow.
116 lines
5.5 KiB
Python
116 lines
5.5 KiB
Python
"""The matrix's sizing of its jobs, on recorded runs whose answers are known.
|
|
|
|
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s scripts/matrix
|
|
"""
|
|
|
|
import importlib.machinery
|
|
import importlib.util
|
|
import json
|
|
import subprocess
|
|
import tempfile
|
|
import threading
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
_loader = importlib.machinery.SourceFileLoader("matrix", str(Path(__file__).resolve().parent / "matrix"))
|
|
_spec = importlib.util.spec_from_loader("matrix", _loader)
|
|
matrix = importlib.util.module_from_spec(_spec)
|
|
_loader.exec_module(matrix)
|
|
|
|
|
|
def run_of(stats):
|
|
"""A matrix run holding STATS, {kind@node: [runs]}, and nothing else it needs to size jobs."""
|
|
run = object.__new__(matrix.Run)
|
|
run.stats = stats
|
|
run.lock = threading.Lock()
|
|
run.spaces = {}
|
|
run.nodes = {"host": {"os": "windows"}}
|
|
run.short = "abc"
|
|
run.jobs = []
|
|
return run
|
|
|
|
|
|
def recorded(ram, peak, minutes=10, killed=False, full=False):
|
|
return dict(ram=ram, peak=peak, minutes=minutes, killed=killed, full=full)
|
|
|
|
|
|
class SizeTests(unittest.TestCase):
|
|
def test_a_build_is_sized_from_whole_builds_alone(self):
|
|
# Incremental builds peaked near 2 GiB: their peaks size nothing, so the default stands.
|
|
incremental = [recorded(3, 2.1), recorded(3, 2.0), recorded(3, 2.2)]
|
|
self.assertEqual(run_of({"winbuild@host": incremental}).size("winbuild", "host"), (16, 60))
|
|
# A whole build that peaked at 9.5 GiB: 1.3 times it, rounded up.
|
|
whole = incremental + [recorded(16, 9.5, full=True)]
|
|
self.assertEqual(run_of({"winbuild@host": whole}).size("winbuild", "host")[0], 13)
|
|
# One that ended for want of its 16 GiB: twice that.
|
|
killed = whole + [recorded(16, 16, killed=True, full=True)]
|
|
self.assertEqual(run_of({"winbuild@host": killed}).size("winbuild", "host")[0], 32)
|
|
|
|
def test_minutes_follow_the_last_three_runs_of_either_form(self):
|
|
runs = [recorded(16, 9, minutes=50, full=True), recorded(3, 2, minutes=8), recorded(3, 2, minutes=9)]
|
|
self.assertEqual(run_of({"build@n": runs}).size("build", "n")[1], 75)
|
|
self.assertEqual(run_of({"build@n": runs[1:]}).size("build", "n")[1], 30)
|
|
|
|
|
|
class RetryTests(unittest.TestCase):
|
|
def test_a_job_that_wanted_ram_runs_again_with_twice_its_room_up_to_the_default(self):
|
|
run = run_of({"winbuild@host": [recorded(3, 2.0, full=True)]})
|
|
asked = []
|
|
|
|
def potluck(*args, cwd=None):
|
|
if args[0] == "dispatch":
|
|
asked.append(int(args[args.index("--ram") + 1]))
|
|
reply = {"job": f"j{len(asked)}", "state": "queued"}
|
|
else:
|
|
ram = asked[-1]
|
|
reply = {"recent": [{"id": f"j{len(asked)}", "started_at": 1, "ended_at": 60001,
|
|
"exit_code": 137, "workspace": None,
|
|
"usage": {"peak_mem_bytes": ram * 2**30}}]}
|
|
return subprocess.CompletedProcess(args, 0, json.dumps(reply), "")
|
|
|
|
waited = subprocess.CompletedProcess([], 137, "", "rustc-LLVM ERROR: out of memory")
|
|
with tempfile.TemporaryDirectory() as rdir, \
|
|
mock.patch.object(matrix, "potluck", potluck), \
|
|
mock.patch.object(matrix.subprocess, "run", return_value=waited), \
|
|
mock.patch.object(matrix, "log"):
|
|
run.rdir = Path(rdir)
|
|
code, _, _ = run.job("winbuild", "host", "true", "winbuild-leg", space="winbuild")
|
|
# Sized from its whole build's 2 GiB peak, then doubled up to the default, 16 GiB.
|
|
self.assertEqual(asked, [4, 8, 16])
|
|
self.assertEqual(code, 137)
|
|
|
|
|
|
class LayerTests(unittest.TestCase):
|
|
"""The shell a device-test job runs to unpack the carried validation layer, run for real."""
|
|
|
|
def run_lines(self, layer, cwd, env=None):
|
|
lines = matrix.layer_lines(layer, "linux", "leg")
|
|
script = lines + '\necho "path $VK_LAYER_PATH"'
|
|
return subprocess.run(["bash", "-c", script], cwd=cwd, env=env, capture_output=True, text=True).stdout
|
|
|
|
def test_a_job_unpacks_its_os_directory_and_points_the_loader_at_it(self):
|
|
with tempfile.TemporaryDirectory() as carry, tempfile.TemporaryDirectory() as work:
|
|
(Path(carry) / "linux").mkdir()
|
|
(Path(carry) / "linux/VERSION").write_text("1.2.3 (from somewhere)\n")
|
|
for args in (["init", "-q"], ["add", "linux"],
|
|
["-c", "user.name=t", "-c", "user.email=t@localhost", "commit", "-q", "-m", "layer"]):
|
|
subprocess.run(["git", *args], cwd=carry, check=True)
|
|
rev = subprocess.run(["git", "rev-parse", "HEAD"], cwd=carry, capture_output=True, text=True).stdout.strip()
|
|
env = {"PATH": "/usr/bin:/bin", "POTLUCK_MIRROR_layer": str(Path(carry) / ".git")}
|
|
out = self.run_lines(("POTLUCK_MIRROR_layer", rev), work, env)
|
|
self.assertIn("M2V-DEVICE leg validationLayer 1.2.3 (from somewhere)", out)
|
|
pointed = Path(out.split("path ", 1)[1].strip())
|
|
self.assertEqual(pointed.resolve(), (Path(work) / ".validation-layer/linux").resolve())
|
|
|
|
def test_a_job_with_no_layer_says_so_and_finds_none(self):
|
|
with tempfile.TemporaryDirectory() as work:
|
|
for layer in (None, ("POTLUCK_MIRROR_absent", "0" * 40)):
|
|
out = self.run_lines(layer, work, {"PATH": "/usr/bin:/bin"})
|
|
self.assertIn("M2V-DEVICE leg validationLayer missing: ", out)
|
|
self.assertIn("/.no-validation-layer", out)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|