diff options
Diffstat (limited to 'tests/tst-stage-actions-runner.sh')
| -rwxr-xr-x | tests/tst-stage-actions-runner.sh | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/tst-stage-actions-runner.sh b/tests/tst-stage-actions-runner.sh new file mode 100755 index 0000000..1deef01 --- /dev/null +++ b/tests/tst-stage-actions-runner.sh @@ -0,0 +1,111 @@ +#!/bin/sh + +set -eu + +: "${CPU_AS:?}" "${CPU_LD:?}" "${CPU_RUN:?}" "${TEST_SRCDIR:?}" + +base="${TMPDIR:-/tmp}/libmcpu-stage-actions-$$" +trap 'rm -f "$base"*' EXIT HUP INT TERM + +# The published LIFE example: one scalar print action, two registers, one line. +"$CPU_AS" -o "$base-life.o" "$TEST_SRCDIR/fixtures/life-print.s" >/dev/null +"$CPU_LD" -o "$base-life" --stack-size=1K "$base-life.o" >/dev/null +out=`"$CPU_RUN" --steps=3 \ + --on-step=print-int-regs:r64@0x00000,r64@0x00008 \ + -- "$base-life"` +expected='1 10 +2 20 +3 30' +test "x$out" = "x$expected" + +# AFTER_INIT also exists when the executable has no separate .init section. +out=`"$CPU_RUN" --steps=1 \ + --before-run=set-int-regs:r64@0x00000=77 \ + --after-init=print-int-regs:r64@0x00000 \ + --on-step=print-int-regs:r64@0x00000,r64@0x00008 \ + -- "$base-life"` +expected='77 +1 10' +test "x$out" = "x$expected" + +# Explicit -- must make option-looking tokens ordinary guest argv strings. +"$CPU_AS" -o "$base-argv.o" "$TEST_SRCDIR/fixtures/argc-argv.s" >/dev/null +"$CPU_LD" -o "$base-argv" --stack-size=4K "$base-argv.o" >/dev/null +out=`"$CPU_RUN" --on-step=print-int-regs:r64@0x00000,r8@0x00020,r8@0x00021 \ + -- "$base-argv" --help -x` +test "x$out" = "x3 104 120" + +cat > "$base-model.s" <<'EOS' +.data + .real 64, 0.0 + +.input + .integer 64, 0 + +.output + .integer 64, 0 + .integer 64, 0 + +.init +_start: + END + +.text +_life: + END + JMP _life +EOS + +"$CPU_AS" -o "$base-model.o" "$base-model.s" >/dev/null +"$CPU_LD" -o "$base-model" --stack-size=1K "$base-model.o" >/dev/null + +# Multiple set/print objects, stage ordering and mpu_sscanf()-based values. +out=`"$CPU_RUN" --steps=1 --digits=20 \ + --before-run=set-int-input:64@0=100 \ + --before-run=set-real-data:64@16=1.5 \ + --after-init=print-int-input:64@0 \ + --after-init=print-real-data:64@16 \ + --on-step=set-int-output:64@0=41,64@8=42 \ + --on-step=print-int-output:64@0,64@8 \ + --after-run=print-int-output:64@0,64@8 \ + -- "$base-model"` +case "$out" in + "100 +1.500000000000000"*"E+0 +41 42 +41 42") ;; + *) echo "unexpected stage-action output:" >&2; echo "$out" >&2; exit 1 ;; +esac + +# AFTER_RUN follows FINI -> END on graceful EXIT. +cat > "$base-fini.s" <<'EOS' +.text +_start_life: + LDI r32@0x00008, 0 + EXIT r32@0x00008 + +.fini +_fini: + LDI r64@0x00000, 99 + END +EOS +"$CPU_AS" -o "$base-fini.o" "$base-fini.s" >/dev/null +"$CPU_LD" -o "$base-fini" --stack-size=1K "$base-fini.o" >/dev/null +out=`"$CPU_RUN" --after-run=print-int-regs:r64@0x00000 -- "$base-fini"` +test "x$out" = "x99" + +# A raw stage action is exactly one dump; comma lists are deliberately invalid. +if "$CPU_RUN" --before-run=print-raw-data:1@16,1@17 -- "$base-model" \ + >/dev/null 2>&1; then + echo "raw stage action accepted a comma-separated list" >&2 + exit 1 +fi + +# Arbitrary raw writes are intentionally absent. +if "$CPU_RUN" --before-run=set-raw-input:1@0=00 -- "$base-model" \ + >/dev/null 2>&1; then + echo "set-raw-input unexpectedly accepted" >&2 + exit 1 +fi + +exit 0 |
