-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest
More file actions
executable file
·305 lines (258 loc) · 5.69 KB
/
test
File metadata and controls
executable file
·305 lines (258 loc) · 5.69 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
303
304
305
#!/bin/bash
shopt -s nullglob
# script de test pour le projet de compilation
option=$1
compilo=$2
score=0
max=0
verbose=0
echo "Testing $2"
echo
rm -f syntax/bad/testfile-*.py
rm -f syntax/good/testfile-*.py
rm -f typing/bad/testfile-*.py
rm -f typing/good/testfile-*.py
ocamllex split.mll
ocaml split.ml syntax/bad/bad.split
ocaml split.ml syntax/good/good.split
ocaml split.ml typing/bad/bad.split
ocaml split.ml typing/good/good.split
compile () {
if [[ $verbose != 0 ]]; then
echo Compile $1 $2
$compilo $1 $2;
else
$compilo $1 $2 > /dev/null 2>&1;
fi;
}
# part 1 : parsing
partie1 () {
score=0
max=0
echo "Part 1 (parsing)"
echo -n "bad "
for f in syntax/bad/*.py; do
echo -n ".";
max=`expr $max + 1`;
compile --parse-only $f;
case $? in
"0")
echo
echo "FAIL on "$f" (should fail)";;
"1") score=`expr $score + 1`;;
*)
echo
echo "FAIL on "$f" (for a bad reason)";;
esac
done
echo
echo -n "good "
for f in syntax/good/*.py typing/bad/*.py typing/good/*.py exec/*.py exec-fail/*.py; do
echo -n ".";
max=`expr $max + 1`;
compile --parse-only $f;
case $? in
"1")
echo
echo "FAIL on "$f" (should succeed)";;
"0") score=`expr $score + 1`;;
*)
echo
echo "FAIL on "$f" (for a bad reason)";;
esac
done
echo
percent=`expr 100 \* $score / $max`;
echo -n "Parsing: $score/$max : $percent%"; }
# part 2 : type checking
partie2 () {
echo
echo "Part 2 (type checking)"
score=0
max=0
echo -n "bad "
for f in typing/bad/*.py; do
echo -n ".";
max=`expr $max + 1`;
compile --type-only $f;
case $? in
"0")
echo
echo "FAIL on "$f" (should fail)";;
"1") score=`expr $score + 1`;;
*)
echo
echo "FAIL on "$f" (for a bad reason)";;
esac
done
echo
echo -n "good "
for f in typing/good/*.py exec/*.py exec-fail/*.py; do
echo -n ".";
max=`expr $max + 1`;
compile --type-only $f;
case $? in
"1")
echo
echo "FAIL on "$f" (should succeed)";;
"0") score=`expr $score + 1`;;
*)
echo
echo "FAIL on "$f" (for a bad reason)";;
esac
done
echo
percent=`expr 100 \* $score / $max`;
echo "Typing: $score/$max : $percent%";
}
# part 3: code generation
partie3 () {
score_comp=0
score_out=0
score_test=0
max=0
echo "Part 3 (code generation)"
echo "Execution with no runtime error"
echo "-------------------------------"
# timeout="why3-cpulimit 30 0 -h"
for f in exec/*.py; do
echo -n "."
asm=exec/`basename $f .py`.s
rm -f $asm
expected=exec/`basename $f .py`.out
max=`expr $max + 1`;
if compile $f; then
rm -f out
score_comp=`expr $score_comp + 1`;
if gcc -no-pie $asm && ./a.out > out; then
# if ./a.out > out; then
score_out=`expr $score_out + 1`;
if cmp --quiet out $expected; then
score_test=`expr $score_test + 1`;
else
echo
echo "FAIL: bad output for $f"
fi
else
echo
echo "FAIL: generated code for $f fails"
fi
else
echo
echo "FAIL: $f does not compile"
fi
done
echo
echo "Execution with a runtime error"
echo "------------------------------"
for f in exec-fail/*.py; do
echo -n "."
asm=exec-fail/`basename $f .py`.s
rm -f $asm
max=`expr $max + 1`;
if compile $f && gcc -no-pie $asm; then
# if compile $f ; then
score_comp=`expr $score_comp + 1`;
if { ./a.out > out; } >& /dev/null; then
echo
echo "FAIL: code for $f should fail at runtime"
else
score_test=`expr $score_test + 1`;
score_out=`expr $score_out + 1`;
fi
else
echo
echo "FAIL: $f does not compile"
fi
done
echo
percent=`expr 100 \* $score / $max`;
echo "Compilation:";
percent=`expr 100 \* $score_comp / $max`;
echo "Compilation: $score_comp/$max : $percent%";
percent=`expr 100 \* $score_out / $max`;
echo "Code behavior: $score_out/$max : $percent%";
percent=`expr 100 \* $score_test / $max`;
echo "Expected output: $score_test/$max : $percent%";}
# part 3i : execution tests with interpreter
partie3i () {
score_out=0
score_test=0
max=0
echo
echo "Part 3i (interpreter)"
echo "Execution with no runtime error"
echo "-------------------------------"
# timeout="why3-cpulimit 30 0 -h"
for f in exec/*.py; do
echo -n "."
expected=exec/`basename $f .py`.out
max=`expr $max + 1`;
rm -f out
if $compilo $f > out; then
score_test=`expr $score_test + 1`;
if cmp --quiet out $expected; then
score_out=`expr $score_out + 1`;
else
echo
echo "FAIL : bad output for $f"
fi
else
echo
echo "FAIL to interpret $f (should succed)"
fi
done
echo
echo "Execution with a runtime error"
echo "------------------------------"
for f in exec-fail/*.py; do
echo -n "."
max=`expr $max + 1`;
if $compilo $f > out 2>&1; then
echo
echo "FAIL : interpretation of $f should fail"
else
score_test=`expr $score_test + 1`;
score_out=`expr $score_out + 1`;
fi
done
echo
echo "Interpretation:";
percent=`expr 100 \* $score_test / $max`;
echo "Behavior: $score_test/$max : $percent%";
percent=`expr 100 \* $score_out / $max`;
echo "Expected output: $score_out/$max : $percent%";}
case $option in
"-1" )
partie1;;
"-2" )
partie2;;
"-3" )
partie3;;
"-i" )
partie3i;;
"-v1" )
verbose=1;
partie1;;
"-v2" )
verbose=1;
partie2;;
"-v3" )
verbose=1;
partie3;;
"-all" )
partie1;
partie2;
partie3;;
* )
echo "usage : $0 <option> <compilo>"
echo "specify an option from : "
echo "-1 : to test syntatic analysis"
echo "-2 : to test type-checking"
echo "-3 : to test code production"
echo "-v1 : to test syntatic analysis (verbose)"
echo "-v2 : to test type-checking (verbose)"
echo "-v3 : to test code production (verbose)"
echo "-all : test all";;
esac
echo