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-run-memory-options.sh | |
| parent | d130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff) | |
| download | libmcpu-0.4.0.tar.xz | |
Version 0.4.00.4.0
Diffstat (limited to 'tests/tst-run-memory-options.sh')
| -rwxr-xr-x | tests/tst-run-memory-options.sh | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/tst-run-memory-options.sh b/tests/tst-run-memory-options.sh new file mode 100755 index 0000000..ab176ce --- /dev/null +++ b/tests/tst-run-memory-options.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +set -eu + +: "${CPU_AS:?}" "${CPU_LD:?}" "${CPU_RUN:?}" + +base="${TMPDIR:-/tmp}/libmcpu-run-memory-$$" +trap 'rm -f "$base.s" "$base.o" "$base.melf"' EXIT HUP INT TERM + +cat > "$base.s" <<'EOS' +.data + .integer 64, 11 + .real 64, 1.5 + +.control + .integer 64, 21 + .real 64, 2.5 + +.input + .integer 64, 31 + .real 64, 3.5 + +.output + .integer 64, 41 + .real 64, 4.5 + +.trace + .integer 64, 51 + .real 64, 5.5 + +.text +_start_life: + HALT +EOS + +"$CPU_AS" -o "$base.o" "$base.s" >/dev/null +"$CPU_LD" -o "$base.melf" --stack-size=1K --heap-size=64K --heap-limit=1M \ + "$base.o" >/dev/null + +check_integer() +{ + option="$1" + expected="$2" + out=`"$CPU_RUN" "$option" "$base.melf"` + if test "$out" != "$expected"; then + echo "unexpected $option result: $out" >&2 + exit 1 + fi +} + +check_real() +{ + option="$1" + expected="$2" + out=`"$CPU_RUN" --digits=20 "$option" "$base.melf"` + case "$out" in + "$expected"*) ;; + *) echo "unexpected $option result: $out" >&2; exit 1 ;; + esac +} + +check_raw() +{ + option="$1" + memory="$2" + bytes="$3" + out=`"$CPU_RUN" "$option" "$base.melf"` + case "$out" in + "$memory memory dump: ($bytes bytes):"*) ;; + *) echo "unexpected $option dump: $out" >&2; exit 1 ;; + esac +} + +check_integer --int-data=64@16 11 +check_real --real-data=64@24 1.500000000000000E+0 +check_integer --int-control=64@0 21 +check_real --real-control=64@8 2.500000000000000E+0 +check_integer --int-heap=64@16 0 +check_real --real-heap=64@16 0.000000000000000E+0 +check_integer --int-input=64@0 31 +check_real --real-input=64@8 3.500000000000000E+0 +check_integer --int-output=64@0 41 +check_real --real-output=64@8 4.500000000000000E+0 +check_integer --int-trace=64@0 51 +check_real --real-trace=64@8 5.500000000000000E+0 + +# Exercise every accepted binary suffix while forcing clipping to 16 bytes. +check_raw --raw-data=1K@16 DATA 16 +check_raw --raw-control=1M@0 CONTROL 16 +check_raw --raw-input=1G@0 INPUT 16 +check_raw --raw-output=1KiB@0 OUTPUT 16 +check_raw --raw-trace=1MiB@0 TRACE 16 +check_raw --raw-heap=1GiB@65520 HEAP 16 + +# Segment/object bounds must reject an address at or beyond the end. +if "$CPU_RUN" --raw-control=1@16 "$base.melf" >/dev/null 2>&1; then + echo "--raw-control accepted address at CONTROL end" >&2 + exit 1 +fi +if "$CPU_RUN" --int-heap=64@65530 "$base.melf" >/dev/null 2>&1; then + echo "--int-heap accepted object crossing HEAP end" >&2 + exit 1 +fi +if "$CPU_RUN" --raw-data=1@32 "$base.melf" >/dev/null 2>&1; then + echo "--raw-data accepted address at .data end" >&2 + exit 1 +fi +if "$CPU_RUN" --raw-data=18446744073709551615GiB@16 "$base.melf" >/dev/null 2>&1; then + echo "--raw-data accepted overflowing byte count" >&2 + exit 1 +fi + +# The descriptions in --help intentionally begin in one vertical column. +help=`"$CPU_RUN" --help 2>&1` +for option in int-control real-control raw-control int-heap real-heap raw-heap \ + int-input real-input raw-input int-output real-output raw-output \ + int-trace real-trace raw-trace; do + echo "$help" | grep -- "--$option=" >/dev/null || exit 1 +done + +exit 0 |
