-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_examples.sh
130 lines (106 loc) · 2.96 KB
/
test_examples.sh
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
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
export LONG=$1
export SOURIR="../sourir"
function ncores {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo `sysctl -n hw.ncpu || echo 2`
else
echo `nproc || echo 2`
fi
}
export OPTS="prune_true\ninline_small\nprune\nprune_false\nhoist_guards\nconst_fold\nhoist_assign\nhoist_drop\nmin_live"
export INPUTS="0\n1\n3\nnil\ntrue\nfalse"
# Move into examples directory
pushd examples > /dev/null 2>&1
# Create a temp directory
export TEMPDIR=`mktemp -d`
# Confirm that we created the directory
if [[ ! "$TEMPDIR" || ! -d "$TEMPDIR" ]]; then
echo "Could not create temp dir!"
exit 1
fi
# Always delete temp dir and its contents
function cleanup {
rm -rf "$TEMPDIR"
popd > /dev/null 2>&1
}
trap cleanup EXIT
export ALL_OPTS=$TEMPDIR/all_opts
PROCS=1
if [[ "$LONG" == "--long" ]]; then
# Long test: generate all subsets of optimization passes
p() { [ $# -eq 0 ] && echo || (shift; p "$@") | while read r ; do echo -e "$1,$r\n$r"; done }
echo -e $OPTS | p `cat` | sort | uniq | sed 's/,$//' | tail -n +2 > $ALL_OPTS
PROCS=`ncores`
export RUNS=4
else
echo "all" > $ALL_OPTS
export RUNS=7
fi
# Test file $1
function runtest {
TEST=$1
INPUT=$2
OPT=$3
OUT="$TEMPDIR/$TEST-$INPUT"
BASELINE_OUT="$OUT-base.out"
OPT_OUT="$OUT-$opt.out"
# echo "running test $1"
if [ ! -f $BASELINE_OUT ]; then
yes "$INPUT" | $SOURIR "$TEST" --quiet &> "$BASELINE_OUT"
if [ $? -ne 0 ]; then
echo -e "\n\nBaseline run failed on $TEST with input $INPUT\n"
echo " ----- LOG ----------------------------------------"
cat $BASELINE_OUT
echo " --------------------------------------------------"
exit 255
fi
fi
yes "$INPUT" | $SOURIR "$TEST" --opt $OPT --num $RUNS --quiet &> "$OPT_OUT"
if [ $? -ne 0 ]; then
echo -e "\n\nOpt run failed on $TEST with input $INPUT and opts $OPT\n"
echo " ----- LOG ----------------------------------------"
cat $OPT_OUT
echo " --------------------------------------------------"
exit 255
fi
diff $BASELINE_OUT $OPT_OUT > /dev/null
if [ $? -ne 0 ]; then
echo -e "\n\nOutput differs on $NAME with input $INPUT and opts $OPT\n"
echo " ----- DIFF ---------------------------------------"
diff $BASELINE_OUT $OPT_OUT
echo " --------------------------------------------------"
exit 255
fi
}
function status {
name=$1
done=`wc -l < $STATUS`
if [[ "$LONG" == "--long" ]]; then
echo -ne "\n[${done}/${NUM_TESTS}] ${name}"
else
echo -ne "\e[0K\r[${done}/${NUM_TESTS}] ${name} "
fi
}
function runtests {
TEST=$0
status "$TEST"
for i in `echo -e $INPUTS`
do
while read opt
do
runtest $TEST $i $opt
done
echo -n "."
done < $ALL_OPTS
echo $TEST >> $STATUS
status "$TEST"
}
export -f runtests runtest status
export NUM_TESTS=`find . -name '*.sou' | wc -l`
export STATUS="$TEMPDIR/status"
touch $STATUS
find . -name '*.sou' | xargs -n 1 -P $PROCS bash -c 'runtests $@'
RET=$?
echo
exit $RET