From 4b1f9e2cb436e74ce6084dbc35df5f052cb701bf Mon Sep 17 00:00:00 2001 From: David Phillips Date: Sun, 4 Aug 2019 14:21:05 +1200 Subject: Wrap tests in valgrind, clean up memory leaks --- test/emul/run-emul.sh | 42 +++++++++++++++++---------------- test/full-pipeline/run-full-pipeline.sh | 7 +++--- test/valgrind.sh | 2 ++ 3 files changed, 28 insertions(+), 23 deletions(-) create mode 100644 test/valgrind.sh (limited to 'test') 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 diff --git a/test/full-pipeline/run-full-pipeline.sh b/test/full-pipeline/run-full-pipeline.sh index aeb7c4f..cfa149f 100755 --- a/test/full-pipeline/run-full-pipeline.sh +++ b/test/full-pipeline/run-full-pipeline.sh @@ -29,6 +29,7 @@ else fi WORK=$(mktemp -d) pushd $(dirname "$0") >/dev/null +source ../valgrind.sh export ASM="$PWD/../../assembler" export DISASM="$PWD/../../disassembler" has_failure=0 @@ -39,17 +40,17 @@ for first_stage_asm in *.asm ; do second_stage_bin="$WORK/${first_stage_asm}-second_stage.bin" # Assemble test code - if ! "$ASM" "$first_stage_asm" "$first_stage_bin" ; then + if ! "$VALGRIND" $VALGRIND_OPTS "$ASM" "$first_stage_asm" "$first_stage_bin" ; then fail "$first_stage_asm" "first stage assembly failed" continue fi # Disassemble test code and re-assemble that disassembly - if ! "$DISASM" "$first_stage_bin" "$second_stage_asm" ; then + if ! "$VALGRIND" $VALGRIND_OPTS "$DISASM" "$first_stage_bin" "$second_stage_asm" ; then fail "$first_stage_asm" "first stage disassembly failed" continue fi - if ! "$ASM" "$second_stage_asm" "$second_stage_bin" ; then + if ! "$VALGRIND" $VALGRIND_OPTS "$ASM" "$second_stage_asm" "$second_stage_bin" ; then fail "$first_stage_asm" "second stage assembly failed" continue fi diff --git a/test/valgrind.sh b/test/valgrind.sh new file mode 100644 index 0000000..9c230d4 --- /dev/null +++ b/test/valgrind.sh @@ -0,0 +1,2 @@ +VALGRIND=valgrind +VALGRIND_OPTS="-q --error-exitcode=1 --leak-check=full --show-reachable=yes" -- cgit v1.1