Commit a77347f5 by Zachary Snow

streamline test performance

parent baf95b27
...@@ -12,50 +12,54 @@ assertExists() { ...@@ -12,50 +12,54 @@ assertExists() {
# USAGE: simulate <vcd-file> <log-file> <top-module> <file> [<file> ...] # USAGE: simulate <vcd-file> <log-file> <top-module> <file> [<file> ...]
simulate() { simulate() {
# arguments # arguments
sim_vcd="$1"; shift sim_vcd=$1
sim_log="$1"; shift sim_log=$2
sim_top="$1"; shift sim_top=$3
shift 3
# compile the files # compile the files
sim_prog="$SHUNIT_TMPDIR/simprog.exe" sim_prog=$SHUNIT_TMPDIR/simprog.exe
iv_output=`iverilog \ iv_output=`iverilog \
-Wall \ -Wall \
-Wno-select-range \ -Wno-select-range \
-Wno-anachronisms \ -Wno-anachronisms \
-o "$sim_prog" \ -o $sim_prog \
-g2005 \ -g2005 \
-DTEST_VCD="\"$sim_vcd\"" \ -DTEST_VCD="\"$sim_vcd\"" \
-DTEST_TOP=$sim_top \ -DTEST_TOP=$sim_top \
"$SCRIPT_DIR/tb_dumper.v" \ $SCRIPT_DIR/tb_dumper.v \
"$@" 2>&1` "$@" 2>&1`
assertTrue "iverilog on $1 failed" $? assertTrue "iverilog on $1 failed" $?
assertNull "iverilog emitted warnings:" "$iv_output" if [ -n "$iv_output" ]; then
if [ "$iv_output" != "" ]; then assertNull "iverilog emitted warnings:" "$iv_output"
echo "$iv_output" echo "$iv_output"
fi fi
# run the simulation # run the simulation
$sim_prog > "$sim_log.temp" $sim_prog > $sim_log.temp
assertTrue "simulating $1 failed" $? assertTrue "simulating $1 failed" $?
assertExists $sim_vcd
# remove the date from the VCD # remove the date from the VCD
sed -i.orig -e "1,3d" "$sim_vcd" sed -i.orig -e "1,3d" $sim_vcd
# remove extraneous log lines # remove extraneous log lines
cat "$sim_log.temp" | grep -v "VCD info: dumpfile" > $sim_log cat $sim_log.temp | grep -v "VCD info: dumpfile" > $sim_log
} }
assertConverts() { assertConverts() {
ac_file="$1" ac_file=$1
ac_tmpa="$SHUNIT_TMPDIR/ac-conv-tmpa.v" ac_tmpa=$SHUNIT_TMPDIR/ac-conv-tmpa.v
ac_tmpb="$SHUNIT_TMPDIR/ac-conv-tmpb.v" $SV2V $ac_file 2> /dev/null > $ac_tmpa
ac_tmpc="$SHUNIT_TMPDIR/ac-conv-tmpc.v"
$SV2V "$ac_file" 2> /dev/null > "$ac_tmpa"
assertTrue "1st conversion of $ac_file failed" $? assertTrue "1st conversion of $ac_file failed" $?
$SV2V "$ac_tmpa" 2> /dev/null > "$ac_tmpb" ac_tmpb=$SHUNIT_TMPDIR/ac-conv-tmpb.v
$SV2V $ac_tmpa 2> /dev/null > $ac_tmpb
assertTrue "2nd conversion of $ac_file failed" $? assertTrue "2nd conversion of $ac_file failed" $?
$SV2V "$ac_tmpb" 2> /dev/null > "$ac_tmpc" if [ -n "$(diff $ac_tmpa $ac_tmpb)" ]; then
assertTrue "3rd conversion of $ac_file failed" $? ac_tmpc=$SHUNIT_TMPDIR/ac-conv-tmpc.v
diff "$ac_tmpb" "$ac_tmpc" > /dev/null $SV2V $ac_tmpb 2> /dev/null > $ac_tmpc
assertTrue "conversion of $ac_file not stable after the second iteration" $? assertTrue "3rd conversion of $ac_file failed" $?
diff $ac_tmpb $ac_tmpc > /dev/null
assertTrue "conversion of $ac_file not stable after the second iteration" $?
fi
# using sed to remove quoted strings # using sed to remove quoted strings
filtered=`sed -E 's/"([^"]|\")+"//g' "$ac_tmpa"` filtered=`sed -E 's/"([^"]|\")+"//g' $ac_tmpa`
# check for various things iverilog accepts which we don't want to output # check for various things iverilog accepts which we don't want to output
PATTERNS="\$bits\|\$dimensions\|\$unpacked_dimensions\|\$left\|\$right\|\$low\|\$high\|\$increment\|\$size" PATTERNS="\$bits\|\$dimensions\|\$unpacked_dimensions\|\$left\|\$right\|\$low\|\$high\|\$increment\|\$size"
echo "$filtered" | grep "$PATTERNS" > /dev/null echo "$filtered" | grep "$PATTERNS" > /dev/null
...@@ -68,61 +72,53 @@ assertConverts() { ...@@ -68,61 +72,53 @@ assertConverts() {
# convert SystemVerilog source file(s) # convert SystemVerilog source file(s)
convert() { convert() {
out_file="$1"; shift out_file=$1; shift
$SV2V "$@" 2> /dev/null > "$out_file" $SV2V "$@" 2> /dev/null > $out_file
assertTrue "conversion failed" $? assertTrue "conversion failed" $?
assertExists "$out_file"
} }
simpleTest() { simpleTest() {
sv="$1" sv=$1
ve="$2" ve=$2
tb="$3" tb=$3
assertNotNull "SystemVerilog file not specified" $sv assertConverts $sv
assertNotNull "Verilog file not specified" $ve assertConverts $ve
assertNotNull "Testbench not specified" $tb
# some tests don't have a separate testbench, instead having the top-level # some tests don't have a separate testbench, instead having the top-level
# module defined in both of the input files # module defined in both of the input files
if [ ! -f "$tb" ]; then if [ ! -f $tb ]; then
tb="$SCRIPT_DIR/empty.v" tb=$SCRIPT_DIR/empty.v
else
assertConverts $tb
fi fi
assertExists $sv cv=$SHUNIT_TMPDIR/conv.v
assertExists $ve convert $cv $sv
assertExists $tb
assertConverts "$sv"
assertConverts "$ve"
assertConverts "$tb"
cv="$SHUNIT_TMPDIR/conv.v"
convert "$cv" "$sv"
simulateAndCompare "$ve" "$cv" "$tb" simulateAndCompare $ve $cv $tb
} }
simulateAndCompare() { simulateAndCompare() {
ve="$1" ve=$1
cv="$2" cv=$2
tb="$3" tb=$3
ref_vcd="$SHUNIT_TMPDIR/ref.vcd" ref_vcd=$SHUNIT_TMPDIR/ref.vcd
gen_vcd="$SHUNIT_TMPDIR/gen.vcd" gen_vcd=$SHUNIT_TMPDIR/gen.vcd
ref_log="$SHUNIT_TMPDIR/ref.log" ref_log=$SHUNIT_TMPDIR/ref.log
gen_log="$SHUNIT_TMPDIR/gen.log" gen_log=$SHUNIT_TMPDIR/gen.log
# simulate and compare the two files # simulate and compare the two files
simulate "$ref_vcd" "$ref_log" top "$ve" "$tb" simulate $ref_vcd $ref_log top $ve $tb
simulate "$gen_vcd" "$gen_log" top "$cv" "$tb" simulate $gen_vcd $gen_log top $cv $tb
output=`diff "$ref_vcd" "$gen_vcd"` output=`diff $ref_vcd $gen_vcd`
assertTrue "VCDs are different:\n$output" $? assertTrue "VCDs are different:\n$output" $?
output=`diff "$ref_log" "$gen_log"` output=`diff $ref_log $gen_log`
assertTrue "Simulation outputs differ:\n$output" $? assertTrue "Simulation outputs differ:\n$output" $?
} }
runTest() { runTest() {
test="$1" test=$1
simpleTest "${test}.sv" "${test}.v" "${test}_tb.v" simpleTest "${test}.sv" "${test}.v" "${test}_tb.v"
} }
...@@ -4,15 +4,19 @@ SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"` ...@@ -4,15 +4,19 @@ SCRIPT_DIR=`dirname "${BASH_SOURCE[0]}"`
tests=`ls *.sv | sed -e "s_\.sv\\\$__"` tests=`ls *.sv | sed -e "s_\.sv\\\$__"`
if [ "$1" ]; then if [ $1 ]; then
tests="$1" tests=$1
shift shift
if [ ! -f $tests.sv ]; then
echo "Could not find $tests.sv"
exit 1
fi
fi fi
addTest() { addTest() {
test="$1" test=$1
eval "test_$test() { runTest \"$test\"; }" eval "test_$test() { runTest \"$test\"; }"
suite_addTest "test_$test" suite_addTest test_$test
} }
suite() { suite() {
...@@ -21,6 +25,6 @@ suite() { ...@@ -21,6 +25,6 @@ suite() {
done done
} }
source "$SCRIPT_DIR/functions.sh" source $SCRIPT_DIR/functions.sh
. shunit2 . shunit2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment