build: wire new src dirs, crt objects, and make check into Autotools

This commit is contained in:
2026-09-03 19:36:32 -04:00
parent 558cf8fd12
commit 40a392f454
8 changed files with 1889 additions and 9 deletions
+95
View File
@@ -0,0 +1,95 @@
#!/bin/sh
# vlibc — make check mode matrix (todo 6).
#
# Runs every scenario that a single "run the binary once" TESTS entry cannot
# cover: the -f failure modes of the four syscall/errno/setjmp/headers tests
# and the full test_startup mode matrix. Every scenario pins its exact exit
# status and (where load-bearing) its exact stdout; see tests/test_startup.c
# and the individual tests for the mode contracts.
#
# The binaries are the static vlibc executables built by make check next to
# the top-level Makefile. make check executes this script with the build
# directory root as the working directory (in-tree and VPATH builds alike),
# so the binaries resolve as plain ./<name> paths relative to the CWD, NOT
# relative to this script's location.
fail=0
# run_rc <binary> <want_rc> <description> [args...]
# Runs the binary with the given args and checks the exit status only (the
# -f modes print diagnostics, whose text is not part of the contract).
run_rc()
{
bin=$1
want_rc=$2
desc=$3
shift 3
"$bin" "$@" >/dev/null 2>&1
rc=$?
if [ "$rc" -ne "$want_rc" ]; then
echo "FAIL: $desc: rc=$rc want=$want_rc"
fail=1
else
echo "ok: $desc"
fi
}
# run <binary> <want_rc> <want_stdout> <description> [args...]
# Like run_rc but also compares the exact stdout (stderr discarded). An
# empty want_stdout matches an empty stdout.
run()
{
bin=$1
want_rc=$2
want_out=$3
desc=$4
shift 4
out=$("$bin" "$@" 2>/dev/null)
rc=$?
if [ "$rc" -ne "$want_rc" ]; then
echo "FAIL: $desc: rc=$rc want=$want_rc"
fail=1
elif [ "$out" != "$want_out" ]; then
echo "FAIL: $desc: stdout [$out] want [$want_out]"
fail=1
else
echo "ok: $desc"
fi
}
bindir=.
# -f failure scenarios of the four arg-mode tests (exit status is the
# contract; the diagnostics on stdout are not pinned).
run_rc "./test_syscall" 0 "syscall -f: ENOENT via fake TCB slot" -f
run_rc "./test_strerror" 0 "strerror -f: unknown errno formats" -f
run_rc "./test_setjmp" 0 "setjmp -f: longjmp(env,0) coerced to 1" -f
run_rc "./test_headers" 132 "headers -f: assert(0) traps (SIGILL)" -f
# test_startup mode matrix (each mode pins its own exit status; the default
# mode exits 42 on success, which is why it is not a bare TESTS entry).
run "./test_startup" 42 "C
B
A" "startup default: atexit LIFO CBA, status 42"
run "./test_startup" 5 "Q" "startup -q: quick_exit runs only at_quick_exit" -q
run "./test_startup" 7 "" "startup -z: _exit runs no handlers" -z
run "./test_startup" 0 "" "startup -t: main-thread TLS + errno TCB slot" -t
run "./test_startup" 0 "" "startup -x: handler-list limits" -x
# -e needs VLIBC_TEST_VAR=hello in environ (checked by the test itself).
out=$(VLIBC_TEST_VAR=hello "./test_startup" -e extraarg 2>/dev/null)
rc=$?
if [ "$rc" -ne 0 ]; then
echo "FAIL: startup -e: argv/env plumbing rc=$rc want=0"
fail=1
elif [ "$out" != "argc=3
argv0=./test_startup
argv1=-e
argv2=extraarg" ]; then
echo "FAIL: startup -e: unexpected stdout [$out]"
fail=1
else
echo "ok: startup -e: argv/env plumbing"
fi
exit $fail