summaryrefslogtreecommitdiff
path: root/test/emul/run-emul.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test/emul/run-emul.sh')
-rwxr-xr-xtest/emul/run-emul.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/emul/run-emul.sh b/test/emul/run-emul.sh
new file mode 100755
index 0000000..3b5ae69
--- /dev/null
+++ b/test/emul/run-emul.sh
@@ -0,0 +1,68 @@
+#!/bin/bash -e
+
+#
+# Script for running all of the automated tests that involve the assembler
+# and emulator.
+# These tests are assembly files with postconditions for registers specified
+# in special syntax within comments. They contain code to run, and the post-
+# conditions are checked in order to determine the test result.
+#
+
+fail() {
+ echo -e '[\e[1;31mFAIL\e[0m] '"$1:" "$2"
+}
+
+pass() {
+ echo -e '[\e[1;32mPASS\e[0m] '"$1"
+}
+
+clean() {
+ echo "Removing work dir $WORK"
+ rm -r "$WORK"
+}
+
+WORK=$(mktemp -d)
+pushd $(dirname "$0") >/dev/null
+export ASM="$PWD/../../assembler"
+export EMUL="$PWD/../../emulator"
+has_failure=0
+
+for asmfile in *.asm ; do
+ binfile="$WORK/$(sed -e 's/\.asm$/.bin/' <<< "$asmfile")"
+ outfile="$WORK/$(sed -e 's/\.asm$/.out/' <<< "$asmfile")"
+ # Assemble test code
+ if ! "$ASM" "$asmfile" "$binfile" ; then
+ fail "$asmfile" "test assembly failed"
+ continue
+ fi
+
+ "$EMUL" "$binfile" > "$outfile"
+
+ # Each postcondition line must hold true, and forms a separate test to
+ # help track down failures
+ (echo '; POST $0 = 0' ;
+ echo '; POST $H = 0xFFFF' ;
+ grep '^;\s\+POST\s\+' "$asmfile" ) | while read line ; do
+ reg=$(awk -F= '{print $1}' <<< "$line" | awk '{print $(NF)}')
+ val=$(awk -F= '{print $2}' <<< "$line"| awk '{print $1}')
+ subtest="${asmfile}:POST-${reg}"
+ # Scrape output of emulator for register value
+ actual=$(grep "$reg" "$outfile" | awk '{print $2}')
+ if [[ "$actual" -eq "$val" ]]; then
+ pass "$subtest"
+ else
+ fail "$subtest" "postcondition (expect $val, got $actual)"
+ has_failure=1
+ fi
+ done
+
+done
+popd >/dev/null
+
+if [[ "$failure" != "0" && "$NO_CLEAN" == "1" ]] ; then
+ echo "Warning: Leaving work dir $WORK in place. Please remove this yourself"
+else
+ clean
+fi
+
+exit "$has_failure"