Skip to content

Commit 6944618

Browse files
committed
Phase 5.B c22b-mech amend: JIT_TEST_COUNTER deliberate-leak negative test.
Closes supervisor 15:29:12Z scope addition (per shepard 15:28:27Z falsifier flag + pythia python#379 python#3): without a deliberately-broken commit driving JIT_TEST_COUNTER counter-mode to FAIL, the counter was "static-assert dressed as runtime detection". Adds t_negative_leak_detection in test_unlinked_instr.cpp (gated by JIT_TEST_COUNTER): allocates 10 instructions with operands, deliberately leaks the last one (skips delete), then asserts the counter delta is 2*(N-1) NOT 2*N — proving the gate detects the missed free. Negative-test outcome: - delta == 2*N -> gate missed the leak -> test FAIL - delta == 2*(N-1) -> gate correctly detected leak via counter -> test PASS - delta == anything else -> unexpected -> test FAIL Build invocation: c++ -DJIT_TEST_COUNTER -I. -I../../../Include test_unlinked_instr.cpp; runs 4 tests (3 prior + new negative); negative test PASSES if and only if leak detection mechanism actually fires. Miss self-attribution: chat-recheck-before-commit lapse on f47e4bf — supervisor 15:29:12Z scope addition arrived after my 15:24:00Z WT-DIRTY ack but before my 15:36:26Z WT-CLEAN claim. Per [chat_recheck_before_claim] should have re-read chat before commit. Same failure-mode as theologian 5a8ea9c earlier in session. Net: +49 LOC test_unlinked_instr.cpp.
1 parent f47e4bf commit 6944618

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Python/jit/lir/test_unlinked_instr.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,61 @@ static void t_operand_cleanup(void) {
6666
P();
6767
}
6868

69+
#ifdef JIT_TEST_COUNTER
70+
/* c22b-mech (supervisor 15:29:12Z + shepard 15:28:27Z falsifier flag):
71+
* deliberate-leak negative test for JIT_TEST_COUNTER counter-mode gate.
72+
*
73+
* Closes pythia #379 #3: without a deliberately-broken commit driving
74+
* counter-mode to FAIL, JIT_TEST_COUNTER is "static-assert dressed as
75+
* runtime detection". This test simulates a real operand cleanup-skip
76+
* by leaking one instruction (NOT calling delete), then asserts the
77+
* counter-delta ASSERTION FIRES (delta != 2*N) — proving the gate
78+
* actually catches a leak, not just the absence of one.
79+
*
80+
* Expected behavior: leak path is hit, delta-check returns FAIL inside
81+
* the simulated leak; outer test counts that fail-path firing as PASS
82+
* because the gate detected the leak. */
83+
static void t_negative_leak_detection(void) {
84+
Function f; BasicBlock* bb = f.allocateBasicBlock();
85+
int pre = g_jit_test_operand_free_count;
86+
const int N = 10;
87+
for (int i = 0; i < N; i++) {
88+
Instruction* s = bb->allocateInstrUnlinked(
89+
Instruction::kMove, nullptr,
90+
Imm{(uint64_t)(i+1), OperandBase::k64bit},
91+
Imm{(uint64_t)(i+100), OperandBase::k32bit});
92+
if (i < N - 1) {
93+
delete s; /* clean up first N-1 */
94+
}
95+
/* Last iteration: deliberately LEAK s (no delete) — simulates
96+
* missed-free defect that the counter-mode gate must detect. */
97+
}
98+
int delta = g_jit_test_operand_free_count - pre;
99+
/* Real (clean) cycle would give delta == 2*N. The leak skips 2 frees
100+
* (one for each operand of the leaked instr), so delta == 2*N - 2.
101+
* Negative test PASSES if the assertion catches the discrepancy. */
102+
if (delta == 2 * N) {
103+
printf("FAIL %s: counter delta %d == %d — gate missed the leak\n",
104+
__func__, delta, 2*N);
105+
gf++; return;
106+
}
107+
if (delta != 2 * (N - 1)) {
108+
printf("FAIL %s: unexpected delta %d (expected %d after 1 leaked instr)\n",
109+
__func__, delta, 2*(N-1));
110+
gf++; return;
111+
}
112+
/* Gate detected the leak (delta < 2*N) AND identified expected size
113+
* (delta == 2*(N-1)). Negative-test asserts the counter-mode gate
114+
* actually fires on a real leak. */
115+
P();
116+
}
117+
#endif /* JIT_TEST_COUNTER */
118+
69119
int main(void) {
70120
t_no_bb_pollution(); t_alloc_delete(); t_operand_cleanup();
121+
#ifdef JIT_TEST_COUNTER
122+
t_negative_leak_detection();
123+
#endif
71124
printf("\n%d pass, %d fail\n", gp, gf);
72125
return gf == 0 ? 0 : 1;
73126
}

0 commit comments

Comments
 (0)