Files
scriptc/packages/runtime/test/glibc-random.test.ts
Chris Tate c08ab955ae Enforce linting and consistent source formatting
- Enforce oxlint and oxfmt for owned JavaScript and TypeScript with independent CI checks.
- Preserve compiler import boundaries and protected fixtures while cleaning up lint findings.
- Standardize source formatting and validate import, fixture, and embedded-source protections.
2026-10-05 17:51:24 -05:00

47 lines
1.4 KiB
TypeScript

import { execFileSync } from "node:child_process";
import { mkdtempSync, rmSync } from "node:fs";
import { join } from "node:path";
import { expect, test } from "vitest";
const report =
process.platform === "linux"
? (process.report.getReport() as { header: { glibcVersionRuntime?: string } })
: undefined;
const version = report?.header.glibcVersionRuntime?.split(".").map(Number);
const supported =
version !== undefined &&
(version[0]! > 2 || (version[0] === 2 && version[1]! >= 34)) &&
(process.arch === "x64" || process.arch === "arm64");
test.skipIf(!supported)(
"glibc 2.34 CSPRNG retries interruptions and partial reads and traps on entropy failure",
() => {
const directory = mkdtempSync("/tmp/scriptc-glibc-random-");
const binary = join(directory, "random");
try {
execFileSync(
"zig",
[
"cc",
"-target",
`${process.arch === "x64" ? "x86_64" : "aarch64"}-linux-gnu.2.34`,
"-std=c11",
"-O2",
"-D_GNU_SOURCE",
"-I",
join(import.meta.dirname, "../src"),
join(import.meta.dirname, "test_glibc_random.c"),
"-o",
binary,
],
{ timeout: 120_000 },
);
expect(execFileSync(binary, [], { encoding: "utf8" })).toBe(
"entropy retries and failures verified\n",
);
} finally {
rmSync(directory, { recursive: true, force: true });
}
},
120_000,
);