-
Notifications
You must be signed in to change notification settings - Fork 1
/
grade.sh
283 lines (246 loc) · 6.22 KB
/
grade.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
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
#!/bin/sh
verbose=false
if [ "x$1" = "x-v" ]
then
verbose=true
out=/dev/stdout
err=/dev/stderr
else
out=/dev/null
err=/dev/null
fi
pts=5
timeout=30
preservefs=n
echo_n () {
# suns can't echo -n, and Mac OS X can't echo "x\c"
# assume argument has no doublequotes
awk 'BEGIN { printf("'"$*"'"); }' </dev/null
}
runbochs () {
# Find the address of the kernel readline function,
# which the kernel monitor uses to read commands interactively.
brkaddr=`grep 'readline$' obj/kern/kernel.sym | sed -e's/ .*$//g'`
#echo "brkaddr $brkaddr"
# Run Bochs, setting a breakpoint at readline(),
# and feeding in appropriate commands to run, then quit.
t0=`date +%s.%N 2>/dev/null`
(
# The sleeps are necessary in some Bochs to
# make it parse each line separately. Sleeping
# here sure beats waiting for the timeout.
echo vbreak 0x8:0x$brkaddr
sleep .5
echo c
# EOF will do just fine to quit.
) | (
ulimit -t $timeout
# date
bochs -q 'display_library: nogui' \
'parport1: enabled=1, file="bochs.out"'
# date
) >$out 2>$err
t1=`date +%s.%N 2>/dev/null`
time=`echo "scale=1; ($t1-$t0)/1" | sed 's/.N/.0/g' | bc 2>/dev/null`
time="(${time}s)"
}
# Usage: runtest <tagname> <defs> <strings...>
runtest () {
perl -e "print '$1: '"
rm -f obj/kern/init.o obj/kern/kernel obj/kern/bochs.img
[ "$preservefs" = y ] || rm -f obj/fs/fs.img
if $verbose
then
echo "gmake $2... "
fi
gmake $2 >$out
if [ $? -ne 0 ]
then
echo gmake $2 failed
exit 1
fi
runbochs
if [ ! -s bochs.out ]
then
echo 'no bochs.out'
else
shift
shift
continuetest "$@"
fi
}
quicktest () {
perl -e "print '$1: '"
shift
continuetest "$@"
}
stubtest () {
perl -e "print qq|$1: OK $2\n|";
shift
score=`expr $pts + $score`
}
continuetest () {
okay=yes
not=false
for i
do
if [ "x$i" = "x!" ]
then
not=true
elif $not
then
if egrep "^$i\$" bochs.out >/dev/null
then
echo "got unexpected line '$i'"
if $verbose
then
exit 1
fi
okay=no
fi
not=false
else
egrep "^$i\$" bochs.out >/dev/null
if [ $? -ne 0 ]
then
echo "missing '$i'"
if $verbose
then
exit 1
fi
okay=no
fi
not=false
fi
done
if [ "$okay" = "yes" ]
then
score=`expr $pts + $score`
echo OK $time
else
echo WRONG $time
fi
}
# Usage: runtest1 [-tag <tagname>] <progname> [-Ddef...] STRINGS...
runtest1 () {
if [ $1 = -tag ]
then
shift
tag=$1
prog=$2
shift
shift
else
tag=$1
prog=$1
shift
fi
runtest1_defs=
while expr "x$1" : 'x-D.*' >/dev/null; do
runtest1_defs="DEFS+='$1' $runtest1_defs"
shift
done
runtest "$tag" "DEFS='-DTEST=_binary_obj_user_${prog}_start' DEFS+='-DTESTSIZE=_binary_obj_user_${prog}_size' $runtest1_defs" "$@"
}
score=0
runtest1 hello \
'.00000000. new env 00001000' \
'hello, world' \
'i am environment 00001000' \
'.00001000. exiting gracefully' \
'.00001000. free env 00001000' \
'Destroyed the only environment - nothing more to do!'
# the [00001000] tags should have [] in them, but that's
# a regular expression reserved character, and i'll be damned if
# I can figure out how many \ i need to add to get through
# however many times the shell interprets this string. sigh.
runtest1 buggyhello \
'.00001000. user_mem_check assertion failure for va 00000001' \
'.00001000. free env 00001000'
runtest1 evilhello \
'.00001000. user_mem_check assertion failure for va f0100...' \
'.00001000. free env 00001000'
runtest1 divzero \
! '1/0 is ........!' \
'Incoming TRAP frame at 0xefbfff..' \
'TRAP frame at 0xf.......' \
' trap 0x00000000 Divide error' \
' eip 0x008.....' \
' ss 0x----0023' \
'.00001000. free env 00001000'
runtest1 breakpoint \
'Welcome to the JOS kernel monitor!' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x00000003 Breakpoint' \
' eip 0x008.....' \
' ss 0x----0023' \
! '.00001000. free env 00001000'
runtest1 softint \
'Welcome to the JOS kernel monitor!' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000d General Protection' \
' eip 0x008.....' \
' ss 0x----0023' \
'.00001000. free env 00001000'
#runtest1 badsegment \
# 'Incoming TRAP frame at 0xefbfffbc' \
# 'TRAP frame at 0xf.......' \
# ' trap 0x0000000d General Protection' \
# ' err 0x0000001c' \
# ' eip 0x008.....' \
# ' ss 0x----0023' \
# '.00001000. free env 00001000'
##
## XXX badsegment no longer works on Bochs 2.2.6; Bochs refuses to produce
## a General Protection fault and instead just panics, with the message:
##
## ========================================================================
## Bochs is exiting with the following message:
## [CPU0 ] fetch_raw_descriptor: LDTR.valid=0
## ========================================================================
##
## Unfortunately, we've had to comment this test out. Please reenable it if
## Bochs fixes this bug!!
##
stubtest badsegment "(stubbed out due to Bochs 2.2.6 bug)"
runtest1 faultread \
! 'I read ........ from location 0!' \
'.00001000. user fault va 00000000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000004' \
'.00001000. free env 00001000'
runtest1 faultreadkernel \
! 'I read ........ from location 0xf0100000!' \
'.00001000. user fault va f0100000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000005' \
'.00001000. free env 00001000' \
runtest1 faultwrite \
'.00001000. user fault va 00000000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000006' \
'.00001000. free env 00001000'
runtest1 faultwritekernel \
'.00001000. user fault va f0100000 ip 008.....' \
'Incoming TRAP frame at 0xefbfffbc' \
'TRAP frame at 0xf.......' \
' trap 0x0000000e Page Fault' \
' err 0x00000007' \
'.00001000. free env 00001000'
runtest1 testbss \
'Making sure bss works right...' \
'Yes, good. Now doing a wild write off the end...' \
'.00001000. user fault va 00c..... ip 008.....' \
'.00001000. free env 00001000'
echo "Score: $score/60"
if [ $score -lt 60 ]; then
exit 1
fi