kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

commit 3f7a01dcdb627b6713ad17682130a09824bdce21
parent a2df3a5a2105cd5314df6542dfb42ade10c623d8
Author: Ryan Sepassi <rsepassi@gmail.com>
Date:   Tue, 16 Jun 2026 14:23:32 -0700

test/tools: cover image rom/sections/metadata + validation flags

31 new self-checking cases in the image block of test-driver-tools:

- sections: declared-order + reversed-order concatenation (exact byte
  strings), determinism (byte-identical re-emit), missing-section run_fail,
  and the --section-without-sections-format rejection.
- rom: --pad-to-required run_fail, fixed size + payload/fill byte check,
  determinism, and payload-exceeds-size run_fail.
- metadata: presence, stable-content greps (format/object_format/build_id),
  byte-identical re-emit, and the section-source source/base fields.
- validation: --require-entry/--require-symbol/--require-section pass+fail
  pairs, --no-dynamic on a static image, and the --format elf deferral.

tools-driver: 88 pass, 0 fail, 0 skip.

Diffstat:
Mtest/tools/run.sh | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 89 insertions(+), 0 deletions(-)

diff --git a/test/tools/run.sh b/test/tools/run.sh @@ -213,5 +213,94 @@ contains image-pad-fill-byte "$work/kernel.pad.hex" \ run_fail image-max-size "$KIT" image --format bin --max-size 1 \ "$work/kernel.elf" -o "$work/kernel.too-small.bin" +# ---- image: --format sections --------------------------------------------- +# Concatenate named sections in DECLARED order. The fixture's .text is a lone +# `ret` (0xc3) and .rodata is 0x11223344, so the concatenation and its reverse +# are exact, checkable byte strings. +run_ok image-sections "$KIT" image --format sections \ + --section .text --section .rodata "$work/kernel.elf" -o "$work/sec.bin" +"$KIT" xxd -p "$work/sec.bin" > "$work/sec.hex" +contains image-sections-order "$work/sec.hex" "c311223344" +run_ok image-sections-rev "$KIT" image --format sections \ + --section .rodata --section .text "$work/kernel.elf" -o "$work/sec.rev.bin" +"$KIT" xxd -p "$work/sec.rev.bin" > "$work/sec.rev.hex" +contains image-sections-rev-order "$work/sec.rev.hex" "11223344c3" +# Determinism: same input + options twice is byte-identical. +run_ok image-sections-again "$KIT" image --format sections \ + --section .text --section .rodata "$work/kernel.elf" -o "$work/sec.again.bin" +same_file image-sections-deterministic "$work/sec.bin" "$work/sec.again.bin" +# A missing named section is a hard error. +run_fail image-sections-missing "$KIT" image --format sections \ + --section .nope "$work/kernel.elf" -o "$work/sec.miss.bin" +# --section is rejected for the plain bin format. +run_fail image-section-needs-format "$KIT" image --format bin \ + --section .text "$work/kernel.elf" -o "$work/sec.bad.bin" + +# ---- image: --format rom -------------------------------------------------- +# ROM is a fixed-size flat binary; it requires an explicit --pad-to. Driving it +# from the 5-byte section concatenation gives a small, exact payload to pad. +run_fail image-rom-needs-size "$KIT" image --format rom \ + --section .text --section .rodata "$work/kernel.elf" -o "$work/rom.bad.bin" +run_ok image-rom "$KIT" image --format rom --section .text --section .rodata \ + --pad-to 16 --fill 0xff "$work/kernel.elf" -o "$work/rom.bin" +rom_got=$(wc -c < "$work/rom.bin" | tr -d ' ') +if [ "$rom_got" = "16" ]; then + ok image-rom-size +else + echo "got $rom_got want 16" > "$work/image-rom-size.diag" + not_ok image-rom-size "$work/image-rom-size.diag" +fi +"$KIT" xxd -p "$work/rom.bin" > "$work/rom.hex" +contains image-rom-payload-and-fill "$work/rom.hex" "c311223344ffffffffffffffffffffff" +# Determinism: identical bytes on a second run. +run_ok image-rom-again "$KIT" image --format rom --section .text \ + --section .rodata --pad-to 16 --fill 0xff "$work/kernel.elf" \ + -o "$work/rom.again.bin" +same_file image-rom-deterministic "$work/rom.bin" "$work/rom.again.bin" +# Payload larger than the requested size fails (5 payload bytes, pad-to 4). +run_fail image-rom-overflow "$KIT" image --format rom --section .text \ + --section .rodata --pad-to 4 "$work/kernel.elf" -o "$work/rom.of.bin" + +# ---- image: --metadata sidecar -------------------------------------------- +# Deterministic JSON: stable keys, no host paths/timestamps. Assert presence, +# a few stable fields, and byte-identical re-emission. +run_ok image-metadata "$KIT" image --format bin \ + --metadata "$work/meta.json" "$work/kernel.elf" -o "$work/meta.bin" +assert_file_exists image-metadata-file "$work/meta.json" +contains image-metadata-format "$work/meta.json" '"format": "bin"' +contains image-metadata-objfmt "$work/meta.json" '"object_format": "elf"' +contains image-metadata-buildid "$work/meta.json" '"build_id":' +run_ok image-metadata-again "$KIT" image --format bin \ + --metadata "$work/meta2.json" "$work/kernel.elf" -o "$work/meta2.bin" +same_file image-metadata-deterministic "$work/meta.json" "$work/meta2.json" +# Section-source metadata records the section selection and marks the base as +# not a load address. +run_ok image-metadata-sections "$KIT" image --format sections \ + --section .text --section .rodata --metadata "$work/meta.sec.json" \ + "$work/kernel.elf" -o "$work/meta.sec.bin" +contains image-metadata-sections-source "$work/meta.sec.json" '"source": "sections"' +contains image-metadata-sections-base "$work/meta.sec.json" \ + '"base_is_load_address": false' + +# ---- image: validation flags ---------------------------------------------- +# The fixture is a static -no-pie ELF with an _start entry and a .text section. +run_ok image-require-entry-ok "$KIT" image --require-entry --format bin \ + "$work/kernel.elf" -o "$work/req.bin" +run_ok image-require-symbol-ok "$KIT" image --require-symbol _start \ + --format bin "$work/kernel.elf" -o "$work/req.bin" +run_fail image-require-symbol-missing "$KIT" image \ + --require-symbol no_such_symbol --format bin "$work/kernel.elf" \ + -o "$work/req.bad.bin" +run_ok image-require-section-ok "$KIT" image --require-section .text \ + --format bin "$work/kernel.elf" -o "$work/req.bin" +run_fail image-require-section-missing "$KIT" image \ + --require-section .nope --format bin "$work/kernel.elf" -o "$work/req.bad.bin" +# A static, non-dynamic image passes --no-dynamic. +run_ok image-no-dynamic-ok "$KIT" image --no-dynamic --format bin \ + "$work/kernel.elf" -o "$work/nd.bin" +# --format elf is deferred to objcopy/strip and reports so. +run_fail image-format-elf-deferred "$KIT" image --format elf \ + "$work/kernel.elf" -o "$work/elf.bin" + kit_summary tools-driver kit_exit