name: p7-l1-shared-global-race description: "P7 L1 differential tests that touch shared C globals (me/cref_me, local[], highest_fd, timeofday) must serialize on a mutex — cargo runs" metadata: node_type: memory type: feedback originSessionId: 7cceaba5-1974-4889-94b9-afa6039d571f#
P7 (I/O core) ports touch process-wide C globals (me/cref_me, and coming up
local[], highest_fd, timeofday, FdAry). An L1 differential test that zeroes
then reads such a global races against cargo's other parallel #[test] threads in
the same binary — one test zeroes me while another reads it → flaky wrong values
(seen in P7a bsd_diff.rs: cref_me.sendB read 0 instead of the written value;
the failing case passed when run alone via a filter, which is the tell).
Why: unlike heap clients passed by pointer (per-test, no sharing), a static mut
global is one instance shared by all tests in the binary. This is the L1 analogue of
the L2 PORT_LOCK.
How to apply: in any L1 test file that mutates+reads a shared C global, add a
file-level static LOCK: std::sync::Mutex<()> = Mutex::new(()) and have the per-test
setup() return the held guard (LOCK.lock().unwrap_or_else(|e| e.into_inner()));
bind it let _guard = setup(); so it's held for the whole body. See
ircd-testkit/tests/bsd_diff.rs. Diagnose a suspected race by re-running the single
failing test with a name filter — if it passes alone but fails in the suite, it's this.
Related: [[l1-cref-static-symbol-limit]], [[piauth-state]] (P7 is the linear next phase).