summaryrefslogtreecommitdiff
path: root/tests/proj2/grade.sh
diff options
context:
space:
mode:
authorHanjie Wu <hanjiew@andrew.cmu.edu>2022-12-08 17:45:55 -0500
committerHanjie Wu <hanjiew@andrew.cmu.edu>2022-12-08 17:45:55 -0500
commita054755b62e660d3d8aba42fdb0a992e2d215599 (patch)
tree5f2e793527f75240800b31025f4c4c1f58be23ab /tests/proj2/grade.sh
JIT implementation
Diffstat (limited to 'tests/proj2/grade.sh')
-rwxr-xr-xtests/proj2/grade.sh121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/proj2/grade.sh b/tests/proj2/grade.sh
new file mode 100755
index 0000000..66359e7
--- /dev/null
+++ b/tests/proj2/grade.sh
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+if [ $# = 0 ]; then
+ WEERUN='../../weerun'
+else
+ WEERUN=$1
+ shift
+fi
+
+T=${OUT:=/tmp/$USER/cs17670/$STUDENT/proj2-test/}
+mkdir -p $T
+
+
+if [ ! -x "$WEERUN" ]; then
+ printf "##+weerun\n"
+ printf "##-fail, weerun not found: %s\n" $WEERUN
+ exit 1
+fi
+
+if [ $# = 0 ]; then
+ TESTS=$(ls tests/*.wee.wasm)
+else
+ TESTS=$@
+fi
+
+# substitute for the "timeout" command on MacOS
+function xtimeout {
+ timeout=$1
+ shift
+ command=("$@")
+ (
+ "${command[@]}" &
+ runnerpid=$!
+ trap -- '' SIGTERM
+ ( # killer job
+ sleep $timeout
+ if ps -p $runnerpid > /dev/null; then
+ echo "Timed out, killing"
+ kill -SIGKILL $runnerpid 2>/dev/null
+ fi
+ ) &
+ killerpid=$!
+ wait $runnerpid
+ kill -SIGKILL $killerpid
+ )
+}
+
+function run_one() {
+ echo $WEERUN $f $ARGS
+ xtimeout 5s $WEERUN $f $ARGS > $OUT 2>$ERR
+ # ignore case
+ diff -i $EXP $OUT > $DIFF
+ OK=$?
+ if [ ! -s $DIFF ]; then
+ # remove empty diffs
+ rm $DIFF
+ else
+ cat $DIFF
+ fi
+
+ if [ $OK = 0 ]; then
+ return 0
+ else
+ echo diff $EXP $OUT
+ printf "##-fail: $ARGS\n"
+ return 1
+ fi
+
+}
+
+for f in $TESTS; do
+ # replace slashes with _
+ t=${f//\//_}
+ # replace .wasm with .runs
+ runs=${f/%.wee.wasm/.runs}
+
+ printf "##+%s\n" $t
+
+ OUT=$T/$t.out
+ ERR=$T/$t.err
+ EXP=$T/$t.expect
+ DIFF=$T/$t.diff
+
+ if [ -f $runs ]; then
+ # do multiple runs for this test
+ ok=1
+ while IFS= read -r line
+ do
+ ARGS=$(echo $line | cut -d= -f1)
+ EXPECT=$(echo $line | cut -d= -f2)
+ echo $EXPECT > $EXP
+
+ run_one
+
+ if [ $? != 0 ]; then
+ ok=0
+ break;
+ fi
+ done < $runs
+ if [ $ok = 1 ]; then
+ printf "##-ok\n"
+ fi
+ else
+ # do one run
+ e=${f/%.wee.wasm/.expect}
+ args=${f/%.wee.wasm/.args}
+ cp $e $EXP
+
+ if [ -f $args ]; then
+ ARGS=$(cat $args)
+ else
+ ARGS=""
+ fi
+
+ run_one
+
+ if [ $? = 0 ]; then
+ printf "##-ok\n"
+ fi
+ fi
+done