diff options
| author | kx <kx@radix-linux.su> | 2026-10-09 18:00:15 +0300 |
|---|---|---|
| committer | kx <kx@radix-linux.su> | 2026-10-09 18:00:15 +0300 |
| commit | 065da3509019b15dd0e678072e6be629e5330bef (patch) | |
| tree | 69c934c9e786ac048b4fbe8f4c4c5571661521f4 /tests/tst-tool-config-runner.sh | |
| parent | d130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff) | |
| download | libmcpu-0.4.0.tar.xz | |
Version 0.4.00.4.0
Diffstat (limited to 'tests/tst-tool-config-runner.sh')
| -rwxr-xr-x | tests/tst-tool-config-runner.sh | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/tst-tool-config-runner.sh b/tests/tst-tool-config-runner.sh new file mode 100755 index 0000000..790da58 --- /dev/null +++ b/tests/tst-tool-config-runner.sh @@ -0,0 +1,97 @@ +#!/bin/sh +set -eu + +: "${TOOL_CONFIG_TEST:?}" "${CPU_AS:?}" "${CPU_LD:?}" "${CPU_RUN:?}" "${TEST_SRCDIR:?}" + +TMP=${TMPDIR:-/tmp}/libmcpu-tool-config-$$ +mkdir -p "$TMP/home/.mcpu/etc" "$TMP/relative-root/lib" +trap 'rm -rf "$TMP"' EXIT HUP INT TERM + +HOME="$TMP/home" +export HOME + +# Baseline: no config files, executable-derived root remains active. +"$TOOL_CONFIG_TEST" --no-config > "$TMP/default.txt" +DEFAULT_LIB=$(sed -n 's/^lib=//p' "$TMP/default.txt") +test -n "$DEFAULT_LIB" + +# The obsolete per-user path must be ignored. +printf '%s\n' 'MCPU_LD_SYSTEM_LIBRARY_PATH = /obsolete/path;' \ + > "$HOME/.mcpu/mcpu-ld.conf" +"$TOOL_CONFIG_TEST" > "$TMP/old-user.txt" +test "$(sed -n 's/^lib=//p' "$TMP/old-user.txt")" = "$DEFAULT_LIB" + +# The new per-user path has highest user-level priority and expands $HOME. +cat > "$HOME/.mcpu/etc/mcpu-ld.conf" <<'EOC' +MCPU_LD_SYSTEM_LIBRARY_PATH = $HOME/mcpu-next/lib; +EOC +"$TOOL_CONFIG_TEST" > "$TMP/user.txt" +test "$(sed -n 's/^lib=//p' "$TMP/user.txt")" = "$HOME/mcpu-next/lib" + +# An explicit empty value disables the configured system library tree. +printf '%s\n' 'MCPU_LD_SYSTEM_LIBRARY_PATH = ;' \ + > "$HOME/.mcpu/etc/mcpu-ld.conf" +"$TOOL_CONFIG_TEST" > "$TMP/empty.txt" +test -z "$(sed -n 's/^lib=//p' "$TMP/empty.txt")" + +# --no-config ignores even a malformed user configuration and keeps default. +printf '%s\n' 'MCPU_LD_SYSTEM_LIBRARY_PATH = broken' \ + > "$HOME/.mcpu/etc/mcpu-ld.conf" +"$TOOL_CONFIG_TEST" --no-config > "$TMP/no-config.txt" +test "$(sed -n 's/^lib=//p' "$TMP/no-config.txt")" = "$DEFAULT_LIB" +if "$TOOL_CONFIG_TEST" > /dev/null 2>&1; then + echo "malformed user configuration was unexpectedly accepted" >&2 + exit 1 +fi + +# Absolute --sys-root implies --no-config and uses PATH/lib. +"$TOOL_CONFIG_TEST" --sys-root="$TMP/absolute-root" > "$TMP/absolute.txt" +test "$(sed -n 's/^root=//p' "$TMP/absolute.txt")" = "$TMP/absolute-root" +test "$(sed -n 's/^lib=//p' "$TMP/absolute.txt")" = "$TMP/absolute-root/lib" + +# Relative --sys-root is resolved from the invocation working directory. +( + cd "$TMP" + "$TOOL_CONFIG_TEST" --sys-root=relative-root > "$TMP/relative.txt" +) +test "$(sed -n 's/^root=//p' "$TMP/relative.txt")" = "$TMP/relative-root" +test "$(sed -n 's/^lib=//p' "$TMP/relative.txt")" = "$TMP/relative-root/lib" + + +# The production linker and runner use the same policy state. +"$CPU_AS" -o "$TMP/radd.o" "$TEST_SRCDIR/fixtures/radd-pi.s" >/dev/null +if "$CPU_LD" --stack-size=512 -o "$TMP/radd.melf" "$TMP/radd.o" >/dev/null 2>&1; then + echo "mcpu-ld unexpectedly accepted malformed user configuration" >&2 + exit 1 +fi +"$CPU_LD" --no-config --stack-size=512 \ + -o "$TMP/radd.melf" "$TMP/radd.o" >/dev/null +"$CPU_RUN" --no-config --digits=60 --real-data=4096@16 \ + "$TMP/radd.melf" > "$TMP/run-no-config.txt" +case "$(cat "$TMP/run-no-config.txt")" in + 5.14159265358979323846264338327950288419716939937510582097*) ;; + *) echo "unexpected --no-config execution result" >&2; exit 1 ;; +esac + +if "$CPU_RUN" --digits=60 --real-data=4096@16 \ + "$TMP/radd.melf" >/dev/null 2>&1; then + echo "mcpu-run unexpectedly accepted malformed user configuration" >&2 + exit 1 +fi + +"$CPU_LD" --sys-root "$TMP/absolute-root" --stack-size=512 \ + -o "$TMP/radd-sysroot.melf" "$TMP/radd.o" >/dev/null +"$CPU_RUN" --sys-root="$TMP/absolute-root" --digits=60 \ + --real-data=4096@16 "$TMP/radd-sysroot.melf" > "$TMP/run-sysroot.txt" +case "$(cat "$TMP/run-sysroot.txt")" in + 5.14159265358979323846264338327950288419716939937510582097*) ;; + *) echo "unexpected --sys-root execution result" >&2; exit 1 ;; +esac + +# Both production tools expose the common policy options. +"$CPU_LD" --help 2>&1 | grep -q -- '--no-config' +"$CPU_LD" --help 2>&1 | grep -q -- '--sys-root=PATH' +"$CPU_RUN" --help 2>&1 | grep -q -- '--no-config' +"$CPU_RUN" --help 2>&1 | grep -q -- '--sys-root=PATH' + +exit 0 |
