libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_dst_inject.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * Use of this source code is governed by the ISC License.
4 *
5 * src/inc/xtc_dst_inject.h
6 * DST bug-injection harness (the "bug-detection latency" yardstick).
7 *
8 * FoundationDB / TigerBeetle back the claim "deterministic simulation
9 * finds real bugs" by PLANTING a known bug and proving the simulator
10 * catches it within a small number of seeds, deterministically, with
11 * a replayable trace. That -- not a code-coverage percentage -- is
12 * the metric that inspires confidence: "if you break a safety
13 * invariant, DST catches it fast and hands you the exact seed."
14 *
15 * This header defines the injection points. In a normal build
16 * XTC_DST_INJECT_BUG is undefined and every check compiles to 0, so
17 * the harness is completely absent from production and from the
18 * default test build. A dedicated build defines
19 * -DXTC_DST_INJECT_BUG=<n> to activate exactly ONE planted bug, and
20 * the DST suite is then expected to FAIL (an invariant fires) within
21 * a bounded seed count -- driven by scripts/dst-bug-inject.sh, which
22 * asserts each planted bug is caught. A planted bug the sweep does
23 * NOT catch is a hole in the DST coverage of that safety property.
24 *
25 * Each bug id targets a DST-reachable safety-critical site whose
26 * violation a specific invariant checker or capstone test detects:
27 *
28 * 1 LOSTWAKE -- proc.c drops a mailbox waker fire. A parked
29 * receiver never wakes; the sim's quiescence /
30 * lost-wakeup invariant (a proc still alive but no
31 * runnable work and no timer) fires -> XTC_E_DEADLK.
32 * 2 LOCKEXCL -- lock_mgr.c grants a conflicting lock. Mutual
33 * exclusion breaks; test_sim_compose's lock-held
34 * witness (count must stay <= 1) fires.
35 * 3 NODURABLE -- wal.c skips the fdatasync but still acks the
36 * commit. An acked commit is not durable; the
37 * test_sim_compose_crash durability invariant (every
38 * acked commit present after recovery) fires.
39 *
40 * When you add a new safety invariant, add a planted-bug id here and a
41 * case to scripts/dst-bug-inject.sh so DST must prove it catches it.
42 */
43
44#ifndef XTC_DST_INJECT_H
45#define XTC_DST_INJECT_H
46
47/*
48 * XTC_DST_BUG(n) is 1 iff the build activated planted bug n. Zero in
49 * every normal build (XTC_DST_INJECT_BUG undefined), so all injection
50 * sites vanish. Exactly one bug is active per injected build.
51 */
52#if defined(XTC_DST_INJECT_BUG)
53# define XTC_DST_BUG(n) ((XTC_DST_INJECT_BUG) == (n))
54#else
55# define XTC_DST_BUG(n) (0)
56#endif
57
58/* Symbolic ids (keep in sync with scripts/dst-bug-inject.sh). */
59#define XTC_DST_BUG_LOSTWAKE 1 /* proc.c: drop a mailbox waker fire */
60#define XTC_DST_BUG_LOCKEXCL 2 /* lock_mgr.c: grant a conflicting lock */
61#define XTC_DST_BUG_NODURABLE 3 /* wal.c: skip fdatasync, still ack */
62
63#endif /* XTC_DST_INJECT_H */