From 0d425cc445c2405fa597035eff9f116046caa2ef Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 6 Dec 2026 08:30:01 +0800 Subject: [PATCH] test(elf): share single-export fixtures (#17322) --- src/domain/native/nativeExportParser.test.ts | 29 +++++--------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/domain/native/nativeExportParser.test.ts b/src/domain/native/nativeExportParser.test.ts index d258a14626f..1d5d3252af0 100644 --- a/src/domain/native/nativeExportParser.test.ts +++ b/src/domain/native/nativeExportParser.test.ts @@ -1279,6 +1279,9 @@ const nullSymbolNameNote = (nameOffset: number) => new RegExp(`symbol 0\\b.*0x100\\b.*0x${nameOffset.toString(16)}\\b`, "su"), ); +const singleExportImage = (bits: 32 | 64, little: boolean) => + elfExportImage({ bits, little, symbols: [{ name: "kept_export" }] }); + describe("ELF dynamic symbol null entry", () => { it.each([32, 64] as const)( "rejects an ELF%s null symbol with a nonzero field other than st_name", @@ -1286,21 +1289,13 @@ describe("ELF dynamic symbol null entry", () => { for (const little of [true, false]) { const width = bits === 64 ? 24 : 16; for (let byte = 4; byte < width; byte++) { - const bytes = elfExportImage({ - bits, - little, - symbols: [{ name: "kept_export" }], - }); + const bytes = singleExportImage(bits, little); bytes[NULL_SYMBOL_OFFSET + byte] = 1; expect(() => parseNativeExports(bytes, artifact)).toThrow( BinaryFormatFailure, ); } - const named = elfExportImage({ - bits, - little, - symbols: [{ name: "kept_export" }], - }); + const named = singleExportImage(bits, little); writeNullSymbolName(named, 0x956, little); named[NULL_SYMBOL_OFFSET + (bits === 64 ? 4 : 12)] = 0x12; expect(() => parseNativeExports(named, artifact)).toThrow( @@ -1317,23 +1312,13 @@ describe("ELF dynamic symbol null entry", () => { "records a nonzero st_name on an otherwise undefined ELF%s symbol", (bits) => { for (const little of [true, false]) { - const clean = parse( - elfExportImage({ - bits, - little, - symbols: [{ name: "kept_export" }], - }), - ); + const clean = parse(singleExportImage(bits, little)); expect(clean.exports.map(({ name }) => name)).toEqual(["kept_export"]); expect(clean.limitations.join("\n")).not.toContain("st_name"); // 0x956 is the reported shape and falls outside this fixture's // string table. Offset 1 is the bytes of kept_export. for (const nameOffset of [0x956, 1]) { - const bytes = elfExportImage({ - bits, - little, - symbols: [{ name: "kept_export" }], - }); + const bytes = singleExportImage(bits, little); writeNullSymbolName(bytes, nameOffset, little); const result = parse(bytes); expect(result.exports.map(({ name }) => name)).toEqual([