-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·302 lines (262 loc) · 7.04 KB
/
run.sh
File metadata and controls
executable file
·302 lines (262 loc) · 7.04 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/bin/bash
# Deprecated: use run_system_tests.py instead
declare -r ROOT_DIR=${TRAVIS_BUILD_DIR:-$(git rev-parse --show-toplevel)}
declare -r TIPC=${ROOT_DIR}/build/src/tipc
declare -r RTLIB=${ROOT_DIR}/rtlib
declare -r SCRATCH_DIR=$(mktemp -d)
if [ -z "${TIPCLANG}" ]; then
echo error: TIPCLANG env var must be set
exit 1
fi
curdir="$(basename `pwd`)"
if [ "${curdir}" != "system" ]; then
echo "Test runner must be executed in .../tipc/test/system"
exit 1
fi
numtests=0
numfailures=0
initialize_test() {
echo -n "."
rm -f ${SCRATCH_DIR}/*
((numtests++))
}
# Self contained test cases
for i in selftests/*.tip
do
base="$(basename $i .tip)"
# test optimized program
initialize_test
${TIPC} $i
${TIPCLANG} -w $i.bc ${RTLIB}/tip_rtlib.bc -o $base
./${base} &>/dev/null
exit_code=${?}
if [ ${exit_code} -ne 0 ]; then
echo -n "Test failure for : "
echo $i
./${base}
((numfailures++))
else
rm ${base}
fi
rm $i.bc
# test unoptimized program
initialize_test
${TIPC} -do $i
${TIPCLANG} -w $i.bc ${RTLIB}/tip_rtlib.bc -o $base
./${base} &>/dev/null
exit_code=${?}
if [ ${exit_code} -ne 0 ]; then
echo -n "Test failure for : "
echo $i
./${base}
((numfailures++))
else
rm ${base}
fi
rm $i.bc
done
# IO related test cases
for i in iotests/*.expected
do
initialize_test
expected="$(basename $i .tip)"
executable="$(echo $expected | cut -f1 -d-)"
input="$(echo $expected | cut -f2 -d- | cut -f1 -d.)"
${TIPC} iotests/$executable.tip
${TIPCLANG} -w iotests/$executable.tip.bc ${RTLIB}/tip_rtlib.bc -o $executable
./${executable} $input >iotests/$executable.output 2>iotests/$executable.output
diff iotests/$executable.output $i > ${SCRATCH_DIR}/$executable.diff
if [[ -s ${SCRATCH_DIR}/$executable.diff ]]
then
echo -n "Test differences for : "
echo $i
cat ${SCRATCH_DIR}/$executable.diff
((numfailures++))
fi
rm iotests/$executable.tip.bc
rm iotests/$executable.output
rm $executable
done
# Tests to cover driver logic for error and argument handling
for i in iotests/*error.tip
do
initialize_test
${TIPC} $i &>/dev/null
exit_code=${?}
if [ ${exit_code} -eq 0 ]; then
echo -n "Test failure for : "
echo -n $i
echo " expected error"
((numfailures++))
rm iotests/*error.tip.bc
fi
done
# System tests for polymorphic type inference
for i in polytests/*.tip
do
base="$(basename $i .tip)"
# test optimized program
initialize_test
${TIPC} --pi $i
${TIPCLANG} -w $i.bc ${RTLIB}/tip_rtlib.bc -o $base
./${base} &>/dev/null
exit_code=${?}
if [ ${exit_code} -ne 0 ]; then
echo -n "Test failure for : "
echo $i
./${base}
((numfailures++))
else
rm ${base}
fi
rm $i.bc
${TIPC} --pp --pt --pi $i >${SCRATCH_DIR}/$base.pppt
diff $i.pppt ${SCRATCH_DIR}/$base.pppt >${SCRATCH_DIR}/$base.diff
if [[ -s ${SCRATCH_DIR}/$base.diff ]]
then
echo -n "Test differences for : "
echo $i
cat ${SCRATCH_DIR}/$base.diff
((numfailures++))
fi
done
# Tests to cover argument handling
# Test pretty printing and symbol printing.
initialize_test
${TIPC} -pp -ps iotests/fib.tip >${SCRATCH_DIR}/fib.ppps
diff iotests/fib.ppps ${SCRATCH_DIR}/fib.ppps >${SCRATCH_DIR}/fib.diff
if [[ -s ${SCRATCH_DIR}/fib.diff ]]
then
echo "Test differences for : iotests/fib.tip"
cat ${SCRATCH_DIR}/fib.diff
((numfailures++))
fi
# Test default output file.
initialize_test
input=iotests/main.tip
expected=iotests/main.tip.ll
${TIPC} --asm $input
if [ ! -f $expected ]; then
echo -n "Did not find expected output, $expected, for input $input"
((numfailures++))
fi
rm $expected
# Test human-readable assembly.
initialize_test
input=iotests/fib.tip
output=${SCRATCH_DIR}/fib.tip.ll
expected=iotests/fib.tip.ll
diffed=${SCRATCH_DIR}/fib.diff
${TIPC} --asm $input -o $output
diff <(sed -n '4,$p' $output) <(sed -n '4,$p' $expected) > $diffed
if [ -s $diffed ]; then
echo -n "Test differences for: $input"
cat $diffed
((numfailures++))
fi
# Test call graph.
initialize_test
input=iotests/fib.tip
output=${SCRATCH_DIR}/fib.tip.bc
output_graph=${SCRATCH_DIR}/fib.tip.dot
expected_graph=iotests/fib.tip.dot
diffed_graph=${SCRATCH_DIR}/fib.tip.dot.diff
${TIPC} --pcg=$output_graph $input -o $output
diff $output_graph $expected_graph > $diffed_graph
if [ -s $diffed_graph ]; then
echo "Test differences for: $input"
cat $diffed_graph
((numfailures++))
fi
# Test bad input.
initialize_test
nonexistent=$(uuidgen).tip
while [ -e $nonexistent ]; do
nonexistent=$(uuidgen).tip
done
${TIPC} $nonexistent &>/dev/null
exit_code=${?}
if [ ${exit_code} -eq 0 ]; then
echo -n "Test failure for non-exisitent input"
((numfailures++))
fi
# Type checking at the system level
for i in selftests/*.tip
do
initialize_test
base="$(basename $i .tip)"
${TIPC} -pp -pt $i >${SCRATCH_DIR}/$base.pppt
diff $i.pppt ${SCRATCH_DIR}/$base.pppt >${SCRATCH_DIR}/$base.diff
if [[ -s ${SCRATCH_DIR}/$base.diff ]]
then
echo -n "Test differences for : "
echo $i
cat ${SCRATCH_DIR}/$base.diff
((numfailures++))
fi
done
# Test unwritable output file for both ast and call graph printing
initialize_test
outputfile=iotests/unwritable
chmod a-w $outputfile
input=iotests/linkedlist.tip
${TIPC} --pa=$outputfile $input 2>${SCRATCH_DIR}/unwritable.out
grep "failed to open" ${SCRATCH_DIR}/unwritable.out > ${SCRATCH_DIR}/unwritable.grep
if [[ ! -s ${SCRATCH_DIR}/unwritable.grep ]]; then
echo -n "Test differences for: $outputfile"
echo $i
cat ${SCRATCH_DIR}/$outputfile.grep
((numfailures++))
fi
initialize_test
outputfile=iotests/unwritable
chmod a-w $outputfile
input=iotests/linkedlist.tip
${TIPC} --pcg=$outputfile $input 2>${SCRATCH_DIR}/unwritable.out
grep "failed to open" ${SCRATCH_DIR}/unwritable.out > ${SCRATCH_DIR}/unwritable.grep
if [[ ! -s ${SCRATCH_DIR}/unwritable.grep ]]; then
echo -n "Test differences for: $outputfile"
echo $i
cat ${SCRATCH_DIR}/$outputfile.grep
((numfailures++))
fi
# Logging test
# enable logging for a basic smoke test
initialize_test
${TIPC} -pt -log=/dev/null selftests/polyfactorial.tip &>/dev/null
# Test AST visualizer
initialize_test
input=iotests/linkedlist.tip
output_graph=${SCRATCH_DIR}/linkedlist.tip.dot
expected_output=iotests/linkedlist.tip.dot
diffed_graph=${SCRATCH_DIR}/linkedlist.tip.dot.diff
${TIPC} --pa=$output_graph $input
diff $output_graph $expected_output > $diffed_graph
if [ -s $diffed_graph ]; then
echo "Test differences for: $input"
cat $diffed_graph
((numfailures++))
fi
initialize_test
input=selftests/ptr4.tip
output_graph=${SCRATCH_DIR}/ptr4.tip.dot
expected_output=selftests/ptr4.tip.dot
diffed_graph=${SCRATCH_DIR}/ptr4.tip.dot.diff
${TIPC} --pa=$output_graph $input
diff $output_graph $expected_output > $diffed_graph
if [ -s $diffed_graph ]; then
echo "Test differences for: $input"
cat $diffed_graph
((numfailures++))
fi
# Print out the test results
if [ ${numfailures} -eq "0" ]; then
echo -n " all "
echo -n ${numtests}
echo " tests passed"
else
echo -n " "
echo -n ${numfailures}/${numtests}
echo " tests failed"
fi
rm -r ${SCRATCH_DIR}