1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! Live pid list: the grow loop and buffer arithmetic against the real kernel, not the
//! synthetic seams `grow_loop` and `buffer_arithmetic` use.
//!
//! `proc_listallpids` fills whatever buffer it is handed and reports how many pids it
//! wrote — it never reports truncation — so an undersized buffer produces a short list
//! with no error, and asserting the snapshot is non-empty cannot see it. The pins here
//! therefore split in two: `the_first_buffer_is_large_enough` pins the ARITHMETIC (a real
//! sizing answer plus headroom must exceed the answer itself), and
//! `snapshot_count_agrees_with_the_kernels_sizing_answer` checks the delivered LIST against
//! a second source.
use ;
/// The ARITHMETIC pin, at the live layer: `capacity_for` applied to a REAL sizing answer
/// must still ask for more room than that answer. Not a hard `rounds == 1`: `fill_all()`'s
/// sizing call and its fill are two separate syscalls with a live host between them, and
/// unrelated process churn during that window can legitimately push a correct
/// implementation to a second round (parallel `cargo test` itself spawns processes), so a
/// round-count assertion would be flaky against correct code, not just against the
/// regression it exists to catch.
/// Pins the snapshot's pid count against the kernel's own sizing answer — bracketing two
/// sizing calls around the snapshot and taking the smaller removes drift from processes
/// created during the window, leaving only the kernel's own small sizing slack plus
/// whatever exited mid-snapshot. The tolerance is PROPORTIONAL, not a fixed constant:
/// requiring at least half the sizing answer's pids to survive catches a units-style
/// regression with a wide margin, while tolerating far more process churn between two
/// back-to-back syscalls than is plausible in practice.
///
/// This has a real, bounded blind spot at low process counts: with the /4 regression
/// present, the delivered length is `expected/4 + 16`, and `2*(expected/4 + 16) >= expected`
/// holds for any `expected <= 64` - i.e. the assertion below would pass even with the bug
/// present on a host/CI runner sized that small. `sizing_answer()` is always at least
/// `nprocs + 20`, so `expected <= 64` means fewer than ~44 live processes - implausible for
/// a full OS, but an explicit floor is cheaper than trusting that. Fails loudly rather than
/// passing vacuously if it's ever wrong.
/// The end-to-end grow loop against the REAL kernel and REAL allocator - not a synthetic
/// stand-in for either. Every grow-loop test in `grow_loop` drives `collect_pids` with an
/// injected `fill`; the only test that calls the real `fill_from_kernel`
/// (`fill_from_kernel_reports_written_equal_to_the_buffers_own_length`, in `real_glue`) does
/// exactly one saturating fill and stops, never feeding the result back through the doubling
/// loop. So the composition `collect_pids` + `fill_from_kernel` + `allocate_pids` actually
/// runs in production is otherwise never exercised - a regression at that seam (e.g.
/// `fill_from_kernel` sizing from a stale length, or `collect_pids` reusing the previous
/// buffer instead of the newly allocated one) would pass every other test in this module.
///
/// A starting capacity of 2 cannot hold any real host's process table, forcing at least one
/// real saturate-and-retry round - the live kernel CAN be made to under-report on demand this
/// way, by simply starting deliberately small; that does not require a kernel that reports a
/// specific total, an error, or a bogus over-report on command, which is why `fill` stays
/// injected for those cases (see `collect_pids`'s doc).
///
/// Pinned with the same proportional tolerance as
/// `snapshot_count_agrees_with_the_kernels_sizing_answer`, not a fixed round or pid count:
/// both are host-load-dependent - see that test's doc for why.