aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Nimmagadda <sunil@nimmagadda.net>2026-11-09 11:46:07 +0530
committerSunil Nimmagadda <sunil@nimmagadda.net>2026-11-09 11:46:07 +0530
commit80781f54bdb3b9f383a56b736ffcd67a8868a361 (patch)
treebc091caf9000bec6c9c4b95ddbf3e858c5ceeb99
parentdf9370112ddce1995637c80c58024733a0a9c1ba (diff)
Format it for visual inspection.
While check, assert the header length against expected value too.
-rw-r--r--elf/test.lua26
1 files changed, 22 insertions, 4 deletions
diff --git a/elf/test.lua b/elf/test.lua
index a0f7a38..dda8f78 100644
--- a/elf/test.lua
+++ b/elf/test.lua
@@ -118,19 +118,37 @@ local function hex_to_bytes(hex)
end
test("header.pack 64_le_x86-64", function ()
- local header = {
+ local h = {
class = ec.Class.bit64,
data = ec.Endian.little,
type = ec.Type.exec,
machine = ec.Machine.x86_64,
}
local expected = hex_to_bytes(table.concat({
+ -- "BBBBBBBBBxxxxxxx"
"7f454c46020101000000000000000000",
+ -- "I2I2I4"
"02003e0001000000",
- "000000000000000040000000000000000000000000000000",
- "00000000400038000000400000000000",
+ -- string.rep(fmt.word(hdr.class), 3), where I8 is selected
+ table.concat({
+ "0000000000000000", -- entry
+ "4000000000000000", -- phoff
+ "0000000000000000", -- shoff
+ }),
+ -- "I4I2I2I2I2I2I2"
+ table.concat({
+ "00000000", -- flags
+ "4000", -- ehsize
+ "3800", -- phentsize
+ "0000", -- phnum
+ "4000", -- shentsize
+ "0000", -- shnum
+ "0000", -- shstrndx
+ })
}))
- assert(elf_header.pack(elf_header.normalize(header)) == expected, "mismatch")
+ local actual = elf_header.pack(elf_header.normalize(h))
+ assert(#actual == 64, "invalid ELF64 header size")
+ assert(actual == expected, "mismatch")
end)
-- Test segment.lua