mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-02 07:43:42 +08:00
The scr_map unit test compiles 23 runtime translation units with ASan/UBSan, and that build is essentially the whole test: 90s of clang against a 2.1s binary run. scr_hash.c alone takes 29s at -O1 because the sanitizer instruments its unrolled digest rounds; scr_json.c and scr_lib.c add 28s more. The test then normally ran within 20s of its 120s timeout, and whenever a lane shared the box it repeatedly timed out in both the plain and sanitized lanes. The link set cannot shrink: scr_map.c's dyn ops need scr_dyn_* from scr_json.c, scr_lib.c supplies the remaining date/math/number/perf symbols, and scr_lib.c needs scr_hash.c. The test asserts Map semantics under sanitizers, not codegen, and its cost checks are relative bounds, so build it at -O0: every assertion and sanitizer check still runs and the build drops to about 15s. Eight concurrent copies now take 20-22s each instead of 90s, with the timeout unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.2 KiB
TypeScript
72 lines
2.2 KiB
TypeScript
import { execFile } from "node:child_process";
|
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { promisify } from "node:util";
|
|
import { expect, test } from "vitest";
|
|
|
|
const exec = promisify(execFile);
|
|
|
|
test("number-key maps keep Map semantics across linear, direct and hashed indexes", async () => {
|
|
const scratch = await mkdtemp(join(tmpdir(), "scriptc-map-"));
|
|
const src = import.meta.dirname;
|
|
const binary = join(scratch, "map");
|
|
try {
|
|
await exec("clang", [
|
|
"-std=c11",
|
|
// The runtime link set includes scr_json.c, scr_lib.c and scr_hash.c.
|
|
// With ASan/UBSan their optimized builds dominate the test's cost: -O1
|
|
// takes about 90s (scr_hash.c alone 29s, its unrolled digest rounds
|
|
// instrumented) and regularly starved past this test's timeout when the
|
|
// lane shared the box. The test checks Map semantics under sanitizers,
|
|
// not codegen, so -O0 keeps every assertion and sanitizer check and
|
|
// builds in about 15s.
|
|
"-O0",
|
|
"-Wall",
|
|
"-Wextra",
|
|
"-fsanitize=address,undefined",
|
|
"-I",
|
|
src,
|
|
"-o",
|
|
binary,
|
|
...[
|
|
"scr_map.test.c",
|
|
"scr_json.c",
|
|
"scr_string.c",
|
|
"scr_array.c",
|
|
"scr_arena.c",
|
|
"scr_map.c",
|
|
"scr_exception.c",
|
|
"scr_error.c",
|
|
"scr_number.c",
|
|
"scr_console.c",
|
|
"scr_closure.c",
|
|
"scr_object.c",
|
|
"scr_union.c",
|
|
"scr_cycle.c",
|
|
"scr_alloc.c",
|
|
"scr_lib.c",
|
|
"scr_hash.c",
|
|
"scr_bytes.c",
|
|
"scr_shared.c",
|
|
"scr_bigint.c",
|
|
"scr_url.c",
|
|
"scr_url_params.c",
|
|
"scr_path.c",
|
|
].map((file) => join(src, file)),
|
|
...(process.platform === "linux" ? ["-D_GNU_SOURCE", "-lm"] : []),
|
|
]);
|
|
const result = await exec(binary, [], {
|
|
env: {
|
|
...process.env,
|
|
ASAN_OPTIONS: "detect_leaks=0:halt_on_error=1",
|
|
UBSAN_OPTIONS: "halt_on_error=1",
|
|
},
|
|
});
|
|
expect(result.stdout).toBe("number-key maps passed\n");
|
|
expect(result.stderr).toBe("");
|
|
} finally {
|
|
await rm(scratch, { recursive: true, force: true });
|
|
}
|
|
}, 120_000);
|