Validation test: the L3 stand-in finds its parent with pgrep -a on macOS

translation_l3_stage::spirv_val_runs_in_the_l3_stage_that_replaced_the_translation failed on
macOS CI (run 47003321413, macos-26), the first macOS run to reach it: 'spirv-val ran under
"96367: not the L3 stage", not the worker's L3 stage'. The worker is right; the test's stand-in
is wrong. The stand-in spirv-val asks pgrep for the processes whose arguments hold
"--l3-stage engine" and looks for its parent there. macOS's pgrep leaves out its own ancestors
unless given -a (pgrep(1): "By default, the current pgrep or pkill process and all of its
ancestors are excluded"), and the L3 stage is pgrep's grandparent, so it never matched. procps's
pgrep on Linux excludes only itself, which is why the Linux job passes.

The stand-in now passes -a on Darwin alone: procps reads -a as --list-full, which would print each
command line beside its pid and break the exact pid match.

Verified: a local probe of the same script under `bash -c "sh standin.sh; :" --l3-stage engine`
on macOS 27 printed "not found" with plain pgrep and "found" with the fixed line. The test itself
runs on the next macOS CI run; it is not run on the M3 (no tests there).
This commit is contained in:
Anees Iqbal committed 2026-12-02 18:09:53 -08:00
1 parent e85535dbfa
commit 4bd7516305
1 file changed
+8 -2
@@ -19,7 +19,11 @@ use std::process::Command;
///
/// It finds its parent with `pgrep`, never `ps`: macOS's `ps` is setuid root, and the worker's
/// process-group monitor cannot read a root process's memory (`proc_pid_rusage` answers `EPERM`),
/// which fails the attempt as a tooling error whenever a sample lands while `ps` runs.
/// which fails the attempt as a tooling error whenever a sample lands while `ps` runs. macOS's
/// `pgrep` leaves out its own ancestors, the stand-in's parent among them, unless given `-a`;
/// procps's `pgrep` on Linux lists only other processes already and reads `-a` as
/// `--list-full`, which would put each command line beside its pid, so `-a` is passed on macOS
/// alone.
fn stand_in(
dir: &Path,
name: &str,
@@ -32,7 +36,9 @@ fn stand_in(
let script = format!(
"#!/bin/sh\n\
if [ \"$1\" = --version ]; then echo '{version}'; exit 0; fi\n\
if pgrep -f -- '--l3-stage engine' | grep -qx \"$PPID\"; then\n\
ancestors=\n\
if [ \"$(uname)\" = Darwin ]; then ancestors=-a; fi\n\
if pgrep $ancestors -f -- '--l3-stage engine' | grep -qx \"$PPID\"; then\n\
echo \"$PPID: --l3-stage engine\" >> '{calls}'\n\
else\n\
echo \"$PPID: not the L3 stage\" >> '{calls}'\n\