blob: d720ffb84f80837620285658bce059e8b0dabe3c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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 --strip-trailing-cr -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
|