diff options
author | David Phillips <david@sighup.nz> | 2019-08-04 14:21:05 +1200 |
---|---|---|
committer | David Phillips <david@sighup.nz> | 2019-08-04 14:24:50 +1200 |
commit | 4b1f9e2cb436e74ce6084dbc35df5f052cb701bf (patch) | |
tree | 201bf4d3cf1120ad0e9a8d3fe7b1a95c2fd3333d /test/emul | |
parent | 1c8e50028e15facaa4d31992bfc6cab9d10832e6 (diff) | |
download | toy-cpu-assembler-4b1f9e2cb436e74ce6084dbc35df5f052cb701bf.tar.xz |
Wrap tests in valgrind, clean up memory leaks
Diffstat (limited to 'test/emul')
-rwxr-xr-x | test/emul/run-emul.sh | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/test/emul/run-emul.sh b/test/emul/run-emul.sh index 496f13d..2db56f3 100755 --- a/test/emul/run-emul.sh +++ b/test/emul/run-emul.sh @@ -23,6 +23,7 @@ clean() { WORK=$(mktemp -d) pushd $(dirname "$0") >/dev/null +source ../valgrind.sh export ASM="$PWD/../../assembler" export EMUL="$PWD/../../emulator" has_failure=0 @@ -36,26 +37,27 @@ for asmfile in *.asm ; do 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}:${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 - + if "$VALGRIND" $VALGRIND_OPTS "$EMUL" "$binfile" > "$outfile" ; then + # 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}:${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 + else + fail "$asmfile" "non-zero exit code" + fi done popd >/dev/null |