commit 771ea6e79386c386bfdc40a35019c81a8de76f22
parent 560e47bb1831c255803a9c532ab5c74b8862b826
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Thu, 16 Jul 2026 10:14:01 -0700
test: wire release audit acceptance coverage
Diffstat:
4 files changed, 240 insertions(+), 5 deletions(-)
diff --git a/mk/test.mk b/mk/test.mk
@@ -71,6 +71,7 @@ TEST_TARGETS = \
test-driver-cpio \
test-driver-cas \
test-driver-cc \
+ test-driver-stack-protector \
test-driver-help \
test-driver-build \
test-driver-build-coord \
@@ -333,7 +334,7 @@ test-images:
test-cf-corpus-selftest:
@bash test/lib/kit_corpus_selftest.sh
-test-driver: test-driver-help test-driver-cc test-driver-build test-driver-build-coord test-driver-ar test-driver-cpio test-driver-cas test-driver-strip test-driver-objcopy test-driver-objdump test-driver-pkg test-driver-strings test-driver-tools test-driver-wasm
+test-driver: test-driver-help test-driver-cc test-driver-stack-protector test-driver-build test-driver-build-coord test-driver-ar test-driver-cpio test-driver-cas test-driver-strip test-driver-objcopy test-driver-objdump test-driver-pkg test-driver-strings test-driver-tools test-driver-diagnostics test-driver-wasm
test-driver-help: bin
@KIT=$(abspath $(BIN)) sh test/driver/help_uniform.sh
@@ -341,6 +342,9 @@ test-driver-help: bin
test-driver-cc: bin
@KIT=$(abspath $(BIN)) sh test/driver/run.sh
+test-driver-stack-protector: bin
+ @KIT=$(abspath $(BIN)) sh test/driver/stack_protector.sh
+
test-driver-build: bin
@KIT=$(abspath $(BIN)) sh test/buildcmds/run.sh
@@ -439,7 +443,9 @@ test-driver-cpio: bin
test-driver-cas: bin
@KIT=$(abspath $(BIN)) sh test/cas/run.sh
-test-driver-strip: bin
+
+test-driver-strip: bin build/test/object_rewrite_test
+ @build/test/object_rewrite_test
@KIT=$(abspath $(BIN)) test/strip/run.sh
test-driver-objcopy: bin
@@ -512,6 +518,9 @@ test-driver-strings: bin
test-driver-tools: bin
@KIT=$(abspath $(BIN)) sh test/tools/run.sh
+test-driver-diagnostics: bin
+ @KIT=$(abspath $(BIN)) sh test/diagnostics/run.sh
+
test-driver-wasm: bin
@KIT=$(abspath $(BIN)) sh test/driver-wasm/run.sh
@@ -866,6 +875,7 @@ KIT_RT_RUNTIME_ARCHES ?= aa64 x64 rv64
RT_RUNTIME_DEPS := $(foreach a,$(KIT_RT_RUNTIME_ARCHES),$(_TEST_RT_$(a)))
LINK_EXE_RUNNER = build/test/link-exe-runner
LINK_SCRIPT_TEST_BIN = build/test/link_script_test
+LINK_COMPAT_TEST_BIN = build/test/link_compat_test
test-rt-runtime: bin $(RT_RUNTIME_DEPS) $(LINK_EXE_RUNNER)
@bash test/rt/run.sh
@@ -1046,8 +1056,10 @@ test-coff-windows-vm: bin rt-x86_64-pc-windows rt-aarch64-windows windows-ucrt-s
# The parse/asm/macho harnesses select a cross-target via KIT_TEST_ARCH
# (default aa64); the link rt dependency is resolved through the shared
# _TEST_RT_<arch> map defined above (near test-rt-runtime).
-test-link: lib $(ROUNDTRIP_BIN) $(ROUNDTRIP_BIN_MACHO) $(LINK_EXE_RUNNER) $(JIT_RUNNER) $(LINK_SCRIPT_TEST_BIN)
+test-link: lib $(ROUNDTRIP_BIN) $(ROUNDTRIP_BIN_MACHO) $(LINK_EXE_RUNNER) \
+ $(JIT_RUNNER) $(LINK_SCRIPT_TEST_BIN) $(LINK_COMPAT_TEST_BIN)
$(LINK_SCRIPT_TEST_BIN)
+ $(LINK_COMPAT_TEST_BIN)
bash test/link/run.sh
# x64 ELF link/reloc-application coverage. test-link defaults to aa64, so
@@ -1074,6 +1086,10 @@ test-macho: lib $(TEST_RT_DEP) $(ROUNDTRIP_BIN_MACHO) $(LINK_EXE_RUNNER) $(JIT_R
KIT_TEST_ALLOW_SKIP=$${KIT_TEST_ALLOW_SKIP:-1} \
bash test/link/run.sh
+.PHONY: test-link-macho-symbols
+test-link-macho-symbols: bin $(LINK_EXE_RUNNER)
+ bash test/link/macho-symbols.sh
+
OPT_TEST_BIN = build/test/cg_ir_lower_test
TINY_INLINE_TEST_BIN = build/test/tiny_inline_test
diff --git a/mk/test_unit.mk b/mk/test_unit.mk
@@ -34,7 +34,7 @@ UNIT_TESTS_PUBLIC := \
cg_fp_cmp_test \
cg_control_test cg_const_test hash_test cas_test release_index_test \
panic_recovery_test profile_test build_public_link_test \
- link_script_test \
+ link_script_test link_compat_test object_rewrite_test \
rv64_jit_test rv32_jit_test aa64_inline_test rv64_inline_test x64_inline_test \
arm32_inline_test \
strength_reduce_test
@@ -48,6 +48,8 @@ panic_recovery_test_SRC := test/api/panic_recovery_test.c
profile_test_SRC := test/api/profile_test.c
build_public_link_test_SRC := test/build/build_public_link_test.c
link_script_test_SRC := test/link/link_script_test.c
+link_compat_test_SRC := test/link/link_compat_test.c
+object_rewrite_test_SRC := test/api/object_rewrite_test.c
cg_api_test_SRC := test/api/cg_type_test.c
cg_switch_test_SRC := test/api/cg_switch_test.c
cg_fp_cmp_test_SRC := test/api/cg_fp_cmp_test.c
diff --git a/test/ar/cases/08-conventional-dash-and-alias.sh b/test/ar/cases/08-conventional-dash-and-alias.sh
@@ -2,7 +2,7 @@
# dispatch, and leading-dash operands inside directories containing spaces.
mkdir 'dash path' 'tool aliases'
printf 'member bytes\n' > 'dash path/-member.o'
-"$KIT" install "$PWD/tool aliases" ar >/dev/null
+"$KIT" install "$PWD/tool aliases" ar >/dev/null 2>&1
ar_alias="$PWD/tool aliases/ar"
echo '== direct -rcs =='
diff --git a/test/tools/run.sh b/test/tools/run.sh
@@ -24,6 +24,21 @@ KIT_KIT_DIR="$repo_root/test/lib"
. "$repo_root/test/lib/kit_sh_kit.sh"
kit_report_init
+expect_status() { # WANT NAME COMMAND...
+ es_want=$1
+ es_name=$2
+ shift 2
+ "$@" > "$work/$es_name.out" 2> "$work/$es_name.err"
+ es_got=$?
+ if [ "$es_got" -eq "$es_want" ]; then
+ ok "$es_name"
+ else
+ printf 'wanted %s, got %s\n' "$es_want" "$es_got" > "$work/$es_name.diag"
+ cat "$work/$es_name.err" >> "$work/$es_name.diag"
+ not_ok "$es_name" "$work/$es_name.diag"
+ fi
+}
+
# A fixture with text, newlines, NUL and high bytes — exercises the ASCII
# column and binary round-tripping.
printf 'Hello, kit!\nLine two.\n\000\001\377\376' > "$work/data.bin"
@@ -51,6 +66,25 @@ run_fail cmp-differ-exit "$KIT" cmp "$work/data.bin" "$work/diff.bin"
contains cmp-differ-message "$work/cmp.out" "differ: char"
run_fail cmp-silent-exit "$KIT" cmp -s "$work/data.bin" "$work/diff.bin"
+# GNU-compatible count/skip spellings, checked overflow, -- paths, and the
+# operational-vs-usage status split.
+printf 'abc' > "$work/cmp-short"
+printf 'zabcX' > "$work/cmp-prefixed"
+run_ok cmp-ignore-initial-long "$KIT" cmp --ignore-initial=0:1 --bytes=3 \
+ "$work/cmp-short" "$work/cmp-prefixed"
+run_ok cmp-ignore-initial-short "$KIT" cmp -i0:1 -n3 \
+ "$work/cmp-short" "$work/cmp-prefixed"
+expect_status 1 cmp-missing-operational "$KIT" cmp "$work/missing" \
+ "$work/cmp-short"
+expect_status 2 cmp-count-overflow "$KIT" cmp --bytes=18446744073709551616 \
+ "$work/cmp-short" "$work/cmp-short"
+cp "$work/cmp-short" "$work/-cmp-input"
+(cd "$work" && "$KIT" cmp -- -cmp-input cmp-short) \
+ > "$work/cmp-dash.out" 2> "$work/cmp-dash.err"
+if [ "$?" -eq 0 ]; then ok cmp-double-dash; else
+ not_ok cmp-double-dash "$work/cmp-dash.err"
+fi
+
# ---- hash (CLI smoke; vectors covered by the test-hash unit test) ----------
printf '123456789' > "$work/crc.in"
"$KIT" hash -a crc32 "$work/crc.in" > "$work/crc.out" 2>&1
@@ -71,6 +105,176 @@ contains alias-crc32 "$work/crc32.out" "cbf43926"
# A pinned alias rejects -a (its algorithm is fixed).
run_fail alias-sha256sum-no-a "$KIT" sha256sum -a blake2b "$work/crc.in"
+# Check manifests use the same generic hashing path, enforce exact 256-bit
+# widths, and preserve the 0/1/2 contract.
+printf 'manifest payload\n' > "$work/check payload.bin"
+"$KIT" sha256sum "$work/check payload.bin" > "$work/sha256.manifest"
+expect_status 0 sha256-check-ok "$KIT" sha256sum -c "$work/sha256.manifest"
+contains sha256-check-ok-row "$work/sha256-check-ok.out" ": OK"
+expect_status 0 sha256-check-quiet "$KIT" sha256sum -c --quiet \
+ "$work/sha256.manifest"
+if [ ! -s "$work/sha256-check-quiet.out" ]; then ok sha256-check-quiet-empty;
+else not_ok sha256-check-quiet-empty "$work/sha256-check-quiet.out"; fi
+printf 'changed\n' > "$work/check payload.bin"
+expect_status 1 sha256-check-mismatch "$KIT" sha256sum --check \
+ "$work/sha256.manifest"
+contains sha256-check-failed-row "$work/sha256-check-mismatch.out" ": FAILED"
+expect_status 1 sha256-check-status "$KIT" sha256sum -c --status \
+ "$work/sha256.manifest"
+if [ ! -s "$work/sha256-check-status.out" ]; then ok sha256-check-status-empty;
+else not_ok sha256-check-status-empty "$work/sha256-check-status.out"; fi
+printf 'not a manifest\n' > "$work/malformed.manifest"
+expect_status 1 sha256-check-malformed "$KIT" sha256sum -c \
+ "$work/malformed.manifest"
+
+printf 'manifest payload\n' > "$work/check payload.bin"
+"$KIT" b2sum "$work/check payload.bin" > "$work/b2.manifest"
+expect_status 0 b2-check-ok "$KIT" b2sum -c "$work/b2.manifest"
+printf '%0128d %s\n' 0 "$work/check payload.bin" > "$work/b2-512.manifest"
+expect_status 1 b2-check-reject-512 "$KIT" b2sum -c "$work/b2-512.manifest"
+contains b2-check-reject-512-message "$work/b2-check-reject-512.err" \
+ "BLAKE2b-512 manifest is incompatible"
+
+sha_stdin=$("$KIT" sha256sum "$work/check payload.bin" | sed 's/ .*//')
+printf '%s -\n' "$sha_stdin" > "$work/stdin.manifest"
+expect_status 1 sha256-check-dual-stdin sh -c \
+ '"$1" sha256sum -c - < "$2"' sh "$KIT" "$work/stdin.manifest"
+contains sha256-check-dual-message "$work/sha256-check-dual-stdin.err" \
+ "manifest and payload cannot both read standard input"
+
+# Installed multicall aliases exercise argv[0] routing as well as `kit TOOL`.
+ln -s "$KIT" "$work/sha256sum"
+expect_status 0 sha256-check-installed "$work/sha256sum" -c \
+ "$work/sha256.manifest"
+
+# Shared bounded suggestions stay on stderr, retain usage status, and never
+# autocorrect the input.
+expect_status 2 suggest-command "$KIT" objdmp
+contains suggest-command-value "$work/suggest-command.err" "did you mean 'objdump'"
+if [ ! -s "$work/suggest-command.out" ]; then ok suggest-command-stdout-empty;
+else not_ok suggest-command-stdout-empty "$work/suggest-command.out"; fi
+expect_status 2 suggest-cc-option "$KIT" cc --hlep
+contains suggest-cc-option-value "$work/suggest-cc-option.err" "did you mean '--help'"
+expect_status 2 suggest-target "$KIT" cc -target aarch65-none-elf -c missing.c
+contains suggest-target-value "$work/suggest-target.err" "did you mean"
+expect_status 2 suggest-target-discovery "$KIT" cc -target aardvark-none-elf \
+ -c missing.c
+contains suggest-target-discovery-value "$work/suggest-target-discovery.err" \
+ "kit targets"
+expect_status 2 suggest-language "$KIT" build-obj -x see missing.c
+contains suggest-language-value "$work/suggest-language.err" "did you mean"
+
+# Canonical version output and all help routes agree; version remains internal
+# (the install aliases are tested by the install suite).
+"$KIT" --version > "$work/version-top"
+"$KIT" version > "$work/version-command"
+same_file version-command-identical "$work/version-top" "$work/version-command"
+expect_status 0 version-help-route "$KIT" help version
+expect_status 0 version-short-help "$KIT" version -h
+expect_status 0 version-long-help "$KIT" version --help
+expect_status 2 version-not-installable "$KIT" install \
+ "$work/version aliases" version
+if [ ! -e "$work/version aliases/version" ]; then ok version-alias-absent;
+else not_ok version-alias-absent; fi
+
+# Raw assembler stdin uses a stable synthetic source name. Exercise direct and
+# installed argv[0] dispatch, plus `--` for a leading-dash source pathname.
+run_ok conventional-install-aliases "$KIT" install \
+ "$work/tool aliases" as cc
+mkdir -p "$work/dash paths"
+printf '.text\n.globl _start\n_start:\n ret\n' | \
+ "$KIT" as -target x86_64-none-elf -o "$work/stdin-direct.o" - \
+ > "$work/as-stdin-direct.out" 2> "$work/as-stdin-direct.err"
+if [ "$?" -eq 0 ]; then ok as-stdin-direct; else
+ not_ok as-stdin-direct "$work/as-stdin-direct.err"
+fi
+printf '.text\n.globl _start\n_start:\n ret\n' | \
+ "$work/tool aliases/as" -target x86_64-none-elf \
+ -o "$work/stdin-alias.o" - \
+ > "$work/as-stdin-alias.out" 2> "$work/as-stdin-alias.err"
+if [ "$?" -eq 0 ]; then ok as-stdin-installed; else
+ not_ok as-stdin-installed "$work/as-stdin-alias.err"
+fi
+same_file as-stdin-direct-installed "$work/stdin-direct.o" \
+ "$work/stdin-alias.o"
+printf 'definitely_not_an_instruction\n' | \
+ "$KIT" as -target x86_64-none-elf -o "$work/stdin-bad.o" - \
+ > "$work/as-stdin-bad.out" 2> "$work/as-stdin-bad.err"
+as_bad_rc=$?
+if [ "$as_bad_rc" -eq 1 ]; then ok as-stdin-error-status; else
+ printf 'status=%s\n' "$as_bad_rc" > "$work/as-stdin-bad.diag"
+ not_ok as-stdin-error-status "$work/as-stdin-bad.diag"
+fi
+contains as-stdin-diagnostic-name "$work/as-stdin-bad.err" "<stdin>"
+printf '.text\n.globl dash_source\ndash_source:\n ret\n' \
+ > "$work/dash paths/-source.s"
+(cd "$work/dash paths" && "$KIT" as -target x86_64-none-elf \
+ -o dash-source.o -- -source.s) \
+ > "$work/as-dash.out" 2> "$work/as-dash.err"
+if [ "$?" -eq 0 ]; then ok as-double-dash; else
+ not_ok as-double-dash "$work/as-dash.err"
+fi
+
+# Every supported compiler-to-linker spelling must produce the same linked
+# image. The script lives at a path containing spaces and a leading-dash
+# basename so comma forwarding and argv pairing are both exercised.
+mkdir -p "$work/link scripts"
+link_script="$work/link scripts/-layout script.lds"
+cat > "$link_script" <<'EOF'
+ENTRY(_start)
+SECTIONS {
+ . = 0x10000;
+ .text : ALIGN(1) { *(.text .text.*) }
+ /DISCARD/ : { *(.note.*) *(.comment) *(.eh_frame) }
+}
+EOF
+link_common='-target x86_64-none-elf -nostdlib -static -no-pie'
+# shellcheck disable=SC2086 -- intentionally expand the fixed common argv.
+run_ok link-flags-separate "$KIT" cc $link_common -T "$link_script" \
+ -e _start "$work/stdin-direct.o" -o "$work/link-separate.elf"
+# shellcheck disable=SC2086
+run_ok link-flags-joined "$KIT" cc $link_common -T"$link_script" \
+ -e_start "$work/stdin-direct.o" -o "$work/link-joined.elf"
+# shellcheck disable=SC2086
+run_ok link-flags-equal "$KIT" cc $link_common --script="$link_script" \
+ --entry=_start "$work/stdin-direct.o" -o "$work/link-equal.elf"
+# shellcheck disable=SC2086
+run_ok link-flags-wl "$KIT" cc $link_common \
+ "-Wl,-T,$link_script,-e,_start" "$work/stdin-direct.o" \
+ -o "$work/link-wl.elf"
+# shellcheck disable=SC2086
+run_ok link-flags-xlinker "$KIT" cc $link_common \
+ -Xlinker -T -Xlinker "$link_script" -Xlinker -e -Xlinker _start \
+ "$work/stdin-direct.o" -o "$work/link-xlinker.elf"
+# shellcheck disable=SC2086
+run_ok link-flags-installed "$work/tool aliases/cc" $link_common \
+ "-Wl,-T,$link_script,-e,_start" "$work/stdin-direct.o" \
+ -o "$work/link-installed.elf"
+for linked in joined equal wl xlinker installed; do
+ same_file "link-flags-identical-$linked" "$work/link-separate.elf" \
+ "$work/link-$linked.elf"
+done
+
+# `--` is shared by the file-oriented byte utilities, including argv[0]
+# multicall aliases and leading-dash paths in a directory containing spaces.
+mkdir -p "$work/dash paths"
+printf 'printable payload\n' > "$work/dash paths/-payload.bin"
+(cd "$work/dash paths" && "$KIT" strings -- -payload.bin) \
+ > "$work/strings-dash.out" 2> "$work/strings-dash.err"
+contains strings-double-dash "$work/strings-dash.out" "printable payload"
+ln -s "$KIT" "$work/strings"
+(cd "$work/dash paths" && "$work/strings" -- -payload.bin) \
+ > "$work/strings-alias-dash.out" 2> "$work/strings-alias-dash.err"
+contains strings-alias-double-dash "$work/strings-alias-dash.out" \
+ "printable payload"
+(cd "$work/dash paths" && "$KIT" xxd -p -- -payload.bin) \
+ > "$work/xxd-dash.out" 2> "$work/xxd-dash.err"
+contains xxd-double-dash "$work/xxd-dash.out" "7072696e7461626c65207061796c6f6164"
+printf '\303' > "$work/dash paths/-code.bin"
+(cd "$work/dash paths" && "$KIT" disas -target x86_64 -- -code.bin) \
+ > "$work/disas-dash.out" 2> "$work/disas-dash.err"
+contains disas-double-dash "$work/disas-dash.out" "ret"
+
# ---- disas -----------------------------------------------------------------
"$KIT" disas -target aarch64 -x "1f 20 03 d5" > "$work/d-aa64.out" 2>&1
contains disas-aa64-nop "$work/d-aa64.out" "nop"
@@ -143,6 +347,9 @@ run_fail alias-gunzip-wrong-format "$KIT" gunzip "$work/cz.lz4only"
# Error exits: bad format / two inputs / missing file all exit non-zero.
run_fail compress-err-bad-format "$KIT" compress -z bogus "$work/cz.txt"
+expect_status 2 compress-format-suggestion "$KIT" compress -z gzi "$work/cz.txt"
+contains compress-format-suggestion-value "$work/compress-format-suggestion.err" \
+ "did you mean 'gzip'"
run_fail compress-err-two-inputs "$KIT" compress "$work/cz.txt" "$work/cz.empty"
run_fail compress-err-missing-file "$KIT" compress "$work/cz.nope"
if printf 'plain text not compressed' | "$KIT" compress -d >/dev/null 2>&1; then
@@ -170,6 +377,9 @@ else
fi
# ---- image ---------------------------------------------------------------
+expect_status 2 image-format-suggestion "$KIT" image --format bing missing.o
+contains image-format-suggestion-value "$work/image-format-suggestion.err" \
+ "did you mean 'bin'"
cat > "$work/kernel.s" <<'EOF'
.globl _start
.section .text
@@ -183,6 +393,13 @@ run_ok image-build-elf "$KIT" build-exe -target x86_64-none-elf \
-nostdlib -static -no-pie -e _start "$work/kernel.s" -o "$work/kernel.elf"
run_ok image-bin "$KIT" image --format bin "$work/kernel.elf" \
-o "$work/kernel.bin"
+cp "$work/kernel.elf" "$work/-kernel.elf"
+(cd "$work" && "$KIT" image --format bin -o kernel.dash.bin -- -kernel.elf) \
+ > "$work/image-dash.out" 2> "$work/image-dash.err"
+if [ "$?" -eq 0 ]; then ok image-double-dash; else
+ not_ok image-double-dash "$work/image-dash.err"
+fi
+same_file image-double-dash-bytes "$work/kernel.bin" "$work/kernel.dash.bin"
run_ok image-paddr "$KIT" image --format bin --addr paddr "$work/kernel.elf" \
-o "$work/kernel.paddr.bin"
same_file image-paddr-matches-vaddr "$work/kernel.bin" "$work/kernel.paddr.bin"