Run 45121964904 (the gate of the 69) had three red controls, none from the candidate:
- network, Linux: the published 68 exited with -11 in the exit-pings launch. It is Mozilla's race:
a session closed before Glean initialised makes it start inside the shutdown, where glean.init can
panic ("No database found"). That launch had no window, so Glean was always born in the shutdown.
Every launch of the two oracles now waits, right after its first page, for
<profile>/datareporting/glean/db/data.safe.bin (a condition read from the host; 60 s is a red
safety limit). The launch's own work always sits between the condition and the close. The
exit-pings launch opens a page and navigates once before it closes, and its wait for the
data-policy pref (which never came) is gone. The host's bare launch, never compared, is removed.
Each launch keeps the listing of datareporting/ as evidence.
- network, Windows: the subprocess timeout killed only the python child; the firefox grandchild
held the pipe and pytest timed out without a word. crash.run_tree writes the output to files,
kills the whole tree, and names the launch that was alive and for how long.
- host, Windows: the stock control never started (Playwright's Firefox was not installed) and was
reported as "does not reach the platform provider". It now runs after a green A/A on every
Windows run, pull requests included. The job installs the browser, a missing executable is said by
name, and a stock that ran without reaching the provider prints its processes and modules. A
read-only step prints lfsvc and the location consent keys.
191 lines
9.1 KiB
Python
191 lines
9.1 KiB
Python
"""The strace stand-in of the Linux font tests: the engine's directory as links, whose executable runs the real one under ``strace`` in the
|
|
engine's place (same pid, same process group), and what reads its log (who is the parent and who a content process) and cleans its group.
|
|
|
|
Used by tests/test_the_parent_reads_the_bundle_from_fontconfig_s_cache_linux_e2e.py. No test of its own, no browser."""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
import shutil
|
|
import signal
|
|
import stat
|
|
import subprocess
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
_SYSCALLS = ("execve,clone,clone3,fork,vfork,open,openat,stat,lstat,"
|
|
"newfstatat,statx,access,faccessat,faccessat2,readlink")
|
|
#: The network calls, traced only when a caller asks (``network=True``: scripts/ci_ab_host.py, NET_CALLS): the font tests do not.
|
|
_NET_SYSCALLS = "socket,connect,bind,sendto,sendmsg,sendmmsg"
|
|
#: The signals a trace with ``exit_status`` records (``-e signal=``): the ones that end a process or are sent to end it, with the sender (``si_pid``) and the faulting address
|
|
#: (``si_addr``). The lines they make (``1234 --- SIGSEGV {si_signo=SIGSEGV, ...} ---``) are evidence of a crash and never data of the comparison (scripts/ci_ab_host.py drops
|
|
#: them when it reads the log). strace stops the tracee at every signal whether it prints it or not, so printing changes nothing the browser does.
|
|
RECORDED_SIGNALS = "SIGSEGV,SIGBUS,SIGABRT,SIGILL,SIGFPE,SIGSYS,SIGTRAP,SIGTERM,SIGINT,SIGQUIT,SIGHUP"
|
|
|
|
|
|
def _strace_options(fd_paths: bool = False, exit_status: bool = False) -> str:
|
|
"""strace's own flags: quiet, follow forks, and die with the traced process
|
|
when this build knows --kill-on-exit; ``fd_paths`` adds ``-y``, which prints the path of every file descriptor
|
|
(``3</usr/share/fonts>``), so that a path relative to a directory descriptor is known; ``exit_status`` keeps the lines that say how each process ended
|
|
(``+++ exited with 0 +++``, ``+++ killed by SIGKILL +++``: ``-q`` and not ``-qq``) and records the fatal signals (``RECORDED_SIGNALS``)."""
|
|
help_text = subprocess.run([shutil.which("strace"), "-h"], capture_output=True,
|
|
text=True).stdout
|
|
return (("-f -q -e signal=%s -s 4096" % RECORDED_SIGNALS) if exit_status else "-f -qq -s 4096") + (" -y" if fd_paths else "") + (" --kill-on-exit" if "--kill-on-exit" in help_text else "")
|
|
|
|
|
|
def _require_strace_can_trace(tmp: Path) -> None:
|
|
"""strace needs ptrace: a container or yama can refuse it, and then the
|
|
failure is the environment's, said as such, not the launch's."""
|
|
probe = subprocess.run([shutil.which("strace"), "-o", str(tmp / "probe.log"), "true"],
|
|
capture_output=True, text=True)
|
|
if probe.returncode != 0:
|
|
pytest.fail("strace cannot trace here: %s" % (probe.stderr.strip() or probe.returncode),
|
|
pytrace=False)
|
|
|
|
|
|
def _stand_in(binary: str, tree: Path, log: Path, pidfile: Path, syscalls: str = _SYSCALLS,
|
|
timestamps: bool = False, fd_paths: bool = False, network: bool = False, exit_status: bool = False,
|
|
cores: bool = False) -> str:
|
|
"""A copy of the engine's directory made of links, whose executable runs
|
|
the real one under strace, in the engine's place.
|
|
|
|
The script writes its pid and execs strace: the pid stays, and so does the
|
|
process group its launcher gave it. The core spawns the engine as the
|
|
leader of a process group of its own (``posix_spawn`` with ``setpgroup=0``,
|
|
as Playwright's launcher does with ``detached: true``), so that group holds
|
|
strace and everything it traces, and ``_kill_group`` kills the group of the
|
|
pid (``os.getpgid``). The script used to exec ``setsid``: setsid(1) forks
|
|
when its caller leads a process group, its parent exited 0 at once, and the
|
|
core saw the engine exit during startup (candidate 44161687675).
|
|
|
|
``syscalls`` is what strace traces; ``timestamps`` adds ``-ttt`` (the epoch
|
|
seconds after each pid), which ``_LINE`` does not read: a caller that asks
|
|
for them strips them first (``test_the_parent_reads_the_bundle_from_fontconfig_s_cache_linux_e2e``);
|
|
``fd_paths`` adds ``-y`` (scripts/ci_ab_host.py reads the paths the tree touched, and knows a socket by its inode);
|
|
``network`` adds the network calls to ``syscalls`` (scripts/ci_ab_host.py reads the netlink sockets and the public destinations);
|
|
``cores`` lets the tree dump core (``ulimit -c unlimited``) and changes nothing else: the working directory stays the launcher's, so the paths the trace reads
|
|
are the same, and where the kernel writes the core is the job's ``kernel.core_pattern`` (scripts/ci_ab_host.py)."""
|
|
if network:
|
|
syscalls = syscalls + "," + _NET_SYSCALLS
|
|
real = Path(os.path.realpath(binary))
|
|
tree.mkdir()
|
|
for entry in real.parent.iterdir():
|
|
if entry.name != real.name:
|
|
(tree / entry.name).symlink_to(entry)
|
|
script = tree / real.name
|
|
cores_script = "ulimit -c unlimited\n" if cores else ""
|
|
script.write_text(
|
|
"#!/bin/sh\n"
|
|
"echo $$ > %s\n"
|
|
"%s"
|
|
'exec %s %s -o %s -e trace=%s %s "$@"\n'
|
|
% (pidfile, cores_script, shutil.which("strace"), _strace_options(fd_paths, exit_status) + (" -ttt" if timestamps else ""), log, syscalls, real))
|
|
script.chmod(script.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
|
return str(script)
|
|
|
|
|
|
_LINE = re.compile(r"^(\d+)\s+(\w+)\((.*)$")
|
|
# strace -f splits a call that another thread interrupts in two lines:
|
|
# "PID clone3({...} <unfinished ...>" and "PID <... clone3 resumed>) = CHILD".
|
|
_RESUMED = re.compile(r"^(\d+)\s+<\.\.\. (\w+) resumed>(.*)$")
|
|
_RESULT = re.compile(r"=\s+(\d+)\s*$")
|
|
|
|
|
|
def _roles(lines: list, real_binary: str):
|
|
"""``(role, argv_of)`` for a strace log read as lines: ``role(pid)`` is ``"parent"``, ``"content"`` or ``"other"`` (walking up the
|
|
clones to the process that executed the engine), ``argv_of`` maps a pid to the arguments of the last execve of the engine it made."""
|
|
parent_of = {}
|
|
argv_of = {}
|
|
for line in lines:
|
|
m = _LINE.match(line) or _RESUMED.match(line)
|
|
if not m:
|
|
continue
|
|
pid, call, rest = int(m.group(1)), m.group(2), m.group(3)
|
|
if call in ("clone", "clone3", "fork", "vfork"):
|
|
r = _RESULT.search(rest)
|
|
if r:
|
|
parent_of[int(r.group(1))] = pid
|
|
elif call == "execve" and real_binary in rest:
|
|
# The arguments are on the first line even when the result comes
|
|
# on a resumed one; the last execve of a process is what it runs.
|
|
argv_of[pid] = rest
|
|
|
|
def role(pid: int) -> str:
|
|
seen = set()
|
|
while pid not in seen:
|
|
seen.add(pid)
|
|
argv = argv_of.get(pid)
|
|
if argv is not None and real_binary in argv:
|
|
return "content" if "-contentproc" in argv else "parent"
|
|
if pid not in parent_of:
|
|
break
|
|
pid = parent_of[pid]
|
|
return "other"
|
|
|
|
return role, argv_of
|
|
|
|
|
|
def _group_of(pidfile: Path):
|
|
"""The process group of the stand-in, read from its living pid (``os.getpgid``); None when it is gone or wrote no pid."""
|
|
try:
|
|
return os.getpgid(int(pidfile.read_text().strip()))
|
|
except (OSError, ValueError):
|
|
return None
|
|
|
|
|
|
def _kill_group(pidfile: Path):
|
|
"""Kill the stand-in's process group: strace, the browser and its children. Returns the group killed, or None.
|
|
|
|
Looking for the stand-in's path in the command lines found nothing (strace
|
|
and its children carry the real binary's path), so the group is the handle:
|
|
the group of the stand-in's pid, not the pid taken as a group id. Never the
|
|
group of this test: a stand-in started inside it is killed alone."""
|
|
pgid = _group_of(pidfile)
|
|
if pgid is None:
|
|
return None
|
|
if pgid == os.getpgrp():
|
|
try:
|
|
os.kill(int(pidfile.read_text().strip()), signal.SIGKILL)
|
|
except (OSError, ValueError):
|
|
pass
|
|
return None
|
|
try:
|
|
os.killpg(pgid, signal.SIGKILL)
|
|
except OSError:
|
|
pass
|
|
return pgid
|
|
|
|
|
|
def _detached(argv: list, **kwargs) -> subprocess.Popen:
|
|
"""A process started as the core starts the engine: the leader of a process group of its own (``posix_spawn`` with
|
|
``setpgroup=0`` in ``invisible_core.juggler.connection._spawn_posix``)."""
|
|
return subprocess.Popen(argv, process_group=0, **kwargs)
|
|
|
|
|
|
def _group_members(pgid: int) -> list:
|
|
"""Pids still in the process group ``pgid``."""
|
|
members = []
|
|
for pid in os.listdir("/proc"):
|
|
if not pid.isdigit():
|
|
continue
|
|
try:
|
|
stat_line = Path("/proc/%s/stat" % pid).read_text()
|
|
except OSError:
|
|
continue
|
|
fields = stat_line.rsplit(")", 1)[1].split()
|
|
# fields: state ppid pgrp ...; a zombie is already dead.
|
|
if fields[0] != "Z" and int(fields[2]) == pgid:
|
|
members.append(int(pid))
|
|
return members
|
|
|
|
|
|
def _wait_for_exit(pgid: int, seconds: float = 30.0) -> list:
|
|
end = time.monotonic() + seconds
|
|
left = _group_members(pgid)
|
|
while left and time.monotonic() < end:
|
|
time.sleep(0.1)
|
|
left = _group_members(pgid)
|
|
return left
|