test(dwarf): share abbreviation table fixtures (#17332)

This commit is contained in:
Vincent Koc
2026-12-06 08:46:46 +08:00
committed by GitHub
parent 0550f5f0b4
commit 693e8956d7
+15 -28
View File
@@ -6,6 +6,16 @@ import { abbrevTable, compileUnitAbbrev, uleb } from "./DwarfUnits.fixture.js";
const cache = (bytes: Buffer) => new DwarfAbbrevCache(bytes, true);
describe("DWARF abbreviation tables", () => {
const abbrevTableOfSize = (entries: number) =>
abbrevTable(
Array.from({ length: entries }, (_, index) => ({
code: index + 1,
tag: 0x11,
children: false,
attributes: [],
})),
);
it("parses implicit_const and caches the table", () => {
const bytes = compileUnitAbbrev([
{ name: 0x13, form: 0x21, implicit: 0x1c },
@@ -68,14 +78,7 @@ describe("DWARF abbreviation tables", () => {
});
it("applies the entry budget per table and evicts instead of refusing a later table", () => {
const full = abbrevTable(
Array.from({ length: MAX_DWARF_ABBREV_ENTRIES }, (_, index) => ({
code: index + 1,
tag: 0x11,
children: false,
attributes: [],
})),
);
const full = abbrevTableOfSize(MAX_DWARF_ABBREV_ENTRIES);
const next = compileUnitAbbrev([]);
const tables = cache(Buffer.concat([full, next]));
const first = tables.get(0);
@@ -88,18 +91,9 @@ describe("DWARF abbreviation tables", () => {
});
it("refreshes reused tables and evicts only the least recently used table", () => {
const table = (entries: number) =>
abbrevTable(
Array.from({ length: entries }, (_, index) => ({
code: index + 1,
tag: 0x11,
children: false,
attributes: [],
})),
);
const first = table(1);
const second = table(MAX_DWARF_ABBREV_ENTRIES - 1);
const third = table(1);
const first = abbrevTableOfSize(1);
const second = abbrevTableOfSize(MAX_DWARF_ABBREV_ENTRIES - 1);
const third = abbrevTableOfSize(1);
const secondOffset = first.length;
const thirdOffset = secondOffset + second.length;
const tables = cache(Buffer.concat([first, second, third]));
@@ -128,14 +122,7 @@ describe("DWARF abbreviation tables", () => {
});
it("bounds aggregate parsing work when overlapping tables evict each other", () => {
const full = abbrevTable(
Array.from({ length: MAX_DWARF_ABBREV_ENTRIES }, (_, index) => ({
code: index + 1,
tag: 0x11,
children: false,
attributes: [],
})),
);
const full = abbrevTableOfSize(MAX_DWARF_ABBREV_ENTRIES);
const tables = cache(full);
const secondOffset = 5; // First entry: code, tag, children, and two zeroes.
expect(tables.get(0).kind).toBe("ok");