Skip to content

Commit d8a78e8

Browse files
committed
fix(test): deterministic ceiling for the GLR merge-cap regression guard
perl_glr_deep_parse_recursion_capped wandered between 2s and 218s for the IDENTICAL input: past the merge cap the ambiguity-exploded GLR parse grinds at an environment-dependent rate (allocator/scheduler state in the forked child), and the test paid for however long that grind ran. It was the critical path of every parallel run and the dominant chunk of the sequential one. The guard's actual signal is the CRASH, not the grind: when CBM_TS_STACK_MERGE_MAX_DEPTH regresses, the recursive stack-merge overflows within the first second at this depth (same profile as the sibling pre-guard probe, rc=139 in under a second). The forked child now arms a 10s alarm whose handler exits cleanly — a real SIGSEGV/SIGBUS still terminates the child by signal first and stays visible to WIFSIGNALED, so the RED path is untouched; only the pointless remainder of the grind is skipped. Windows (in-process branch) is unchanged. Suite b: 13s across three consecutive runs (was 2-218s). Full parallel run: 97s wall, 6,374 passed / 0 failed / 1 skipped, union guard clean — vs 351s sequential on the same machine (3.6x). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 5fdbd7b commit d8a78e8

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎tests/test_stack_overflow.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,15 @@ static bool so_extract_crashes(const char *content, CBMLanguage lang, const char
441441
#endif
442442
}
443443

444+
#if !defined(_WIN32)
445+
/* Child-side alarm handler: a clean exit on the deadline — never reached on
446+
* a crash (SIGSEGV/SIGBUS terminate the child first and stay visible). */
447+
static void so_parse_alarm_exit(int sig) {
448+
(void)sig;
449+
_exit(0);
450+
}
451+
#endif
452+
444453
/* Parse `content` with tree-sitter DIRECTLY in a forked child — bypassing
445454
* cbm_extract_file's Perl pre-parse nesting guard — returning true if the child
446455
* died by signal. This is the crash-isolating regression for the vendored GLR
@@ -471,6 +480,15 @@ static bool so_parse_crashes(const char *content, CBMLanguage lang) {
471480
return false;
472481
}
473482
if (pid == 0) {
483+
/* Deterministic ceiling: past the merge cap the ambiguity-exploded
484+
* GLR parse GRINDS (minutes, environment-dependent — measured 2s to
485+
* 218s for the identical input). The guard's signal is the CRASH,
486+
* which fires within the first seconds when the recursion cap
487+
* regresses — so a clean exit after 10s proves the cap held without
488+
* paying for the rest of the grind. SIGSEGV/SIGBUS still report as
489+
* WIFSIGNALED; the alarm handler exits cleanly, never masking them. */
490+
signal(SIGALRM, so_parse_alarm_exit);
491+
alarm(10);
474492
TSParser *parser = ts_parser_new();
475493
if (parser) {
476494
ts_parser_set_language(parser, ts_lang);

0 commit comments

Comments
 (0)