thanks to damocles, two places changed. one relates to the performance boost.
[mit-jos.git] / grade.sh
blob5601f41b792eb20101d98aff9f0fc85918adab4c
1 #!/bin/sh
3 verbose=false
5 if [ "x$1" = "x-v" ]
6 then
7 verbose=true
8 out=/dev/stdout
9 err=/dev/stderr
10 else
11 out=/dev/null
12 err=/dev/null
15 pts=5
16 timeout=30
17 preservefs=n
19 echo_n () {
20 # suns can't echo -n, and Mac OS X can't echo "x\c"
21 # assume argument has no doublequotes
22 awk 'BEGIN { printf("'"$*"'"); }' </dev/null
25 runbochs () {
26 # Find the address of the kernel readline function,
27 # which the kernel monitor uses to read commands interactively.
28 brkaddr=`grep 'readline$' obj/kern/kernel.sym | sed -e's/ .*$//g'`
29 #echo "brkaddr $brkaddr"
31 # Run Bochs, setting a breakpoint at readline(),
32 # and feeding in appropriate commands to run, then quit.
33 t0=`date +%s.%N 2>/dev/null`
35 # The sleeps are necessary in some Bochs to
36 # make it parse each line separately. Sleeping
37 # here sure beats waiting for the timeout.
38 echo vbreak 0x8:0x$brkaddr
39 sleep .5
40 echo c
41 # EOF will do just fine to quit.
42 ) | (
43 ulimit -t $timeout
44 # date
45 bochs -q 'display_library: nogui' \
46 'parport1: enabled=1, file="bochs.out"'
47 # date
48 ) >$out 2>$err
49 t1=`date +%s.%N 2>/dev/null`
50 time=`echo "scale=1; ($t1-$t0)/1" | sed 's/.N/.0/g' | bc 2>/dev/null`
51 time="(${time}s)"
54 # Usage: runtest <tagname> <defs> <strings...>
55 runtest () {
56 perl -e "print '$1: '"
57 rm -f obj/kern/init.o obj/kern/kernel obj/kern/bochs.img
58 [ "$preservefs" = y ] || rm -f obj/fs/fs.img
59 if $verbose
60 then
61 echo "gmake $2... "
63 gmake $2 >$out
64 if [ $? -ne 0 ]
65 then
66 echo gmake $2 failed
67 exit 1
69 runbochs
70 if [ ! -s bochs.out ]
71 then
72 echo 'no bochs.out'
73 else
74 shift
75 shift
76 continuetest "$@"
80 quicktest () {
81 perl -e "print '$1: '"
82 shift
83 continuetest "$@"
86 stubtest () {
87 perl -e "print qq|$1: OK $2\n|";
88 shift
89 score=`expr $pts + $score`
92 continuetest () {
93 okay=yes
95 not=false
96 for i
98 if [ "x$i" = "x!" ]
99 then
100 not=true
101 elif $not
102 then
103 if egrep "^$i\$" bochs.out >/dev/null
104 then
105 echo "got unexpected line '$i'"
106 if $verbose
107 then
108 exit 1
110 okay=no
112 not=false
113 else
114 egrep "^$i\$" bochs.out >/dev/null
115 if [ $? -ne 0 ]
116 then
117 echo "missing '$i'"
118 if $verbose
119 then
120 exit 1
122 okay=no
124 not=false
126 done
127 if [ "$okay" = "yes" ]
128 then
129 score=`expr $pts + $score`
130 echo OK $time
131 else
132 echo WRONG $time
136 # Usage: runtest1 [-tag <tagname>] <progname> [-Ddef...] STRINGS...
137 runtest1 () {
138 if [ $1 = -tag ]
139 then
140 shift
141 tag=$1
142 prog=$2
143 shift
144 shift
145 else
146 tag=$1
147 prog=$1
148 shift
150 runtest1_defs=
151 while expr "x$1" : 'x-D.*' >/dev/null; do
152 runtest1_defs="DEFS+='$1' $runtest1_defs"
153 shift
154 done
155 runtest "$tag" "DEFS='-DTEST=_binary_obj_user_${prog}_start' DEFS+='-DTESTSIZE=_binary_obj_user_${prog}_size' $runtest1_defs" "$@"
158 score=0
159 timeout=10
161 runtest1 dumbfork \
162 '.00000000. new env 00001000' \
163 '.00000000. new env 00001001' \
164 '0: I am the parent!' \
165 '9: I am the parent!' \
166 '0: I am the child!' \
167 '9: I am the child!' \
168 '19: I am the child!' \
169 '.00001001. exiting gracefully' \
170 '.00001001. free env 00001001' \
171 '.00001002. exiting gracefully' \
172 '.00001002. free env 00001002'
174 echo PART A SCORE: $score/5
176 runtest1 faultread \
177 ! 'I read ........ from location 0!' \
178 '.00001001. user fault va 00000000 ip 008.....' \
179 'TRAP frame at 0xf.......' \
180 ' trap 0x0000000e Page Fault' \
181 ' err 0x00000004' \
182 '.00001001. free env 00001001'
184 runtest1 faultwrite \
185 '.00001001. user fault va 00000000 ip 008.....' \
186 'TRAP frame at 0xf.......' \
187 ' trap 0x0000000e Page Fault' \
188 ' err 0x00000006' \
189 '.00001001. free env 00001001'
191 runtest1 faultdie \
192 'i faulted at va deadbeef, err 6' \
193 '.00001001. exiting gracefully' \
194 '.00001001. free env 00001001'
196 runtest1 faultalloc \
197 'fault deadbeef' \
198 'this string was faulted in at deadbeef' \
199 'fault cafebffe' \
200 'fault cafec000' \
201 'this string was faulted in at cafebffe' \
202 '.00001001. exiting gracefully' \
203 '.00001001. free env 00001001'
205 runtest1 faultallocbad \
206 '.00001001. user_mem_check assertion failure for va deadbeef' \
207 '.00001001. free env 00001001'
209 runtest1 faultnostack \
210 '.00001001. user_mem_check assertion failure for va eebfff..' \
211 '.00001001. free env 00001001'
213 runtest1 faultbadhandler \
214 '.00001001. user_mem_check assertion failure for va (deadb|eebfe)...' \
215 '.00001001. free env 00001001'
217 runtest1 faultevilhandler \
218 '.00001001. user_mem_check assertion failure for va (f0100|eebfe)...' \
219 '.00001001. free env 00001001'
221 runtest1 forktree \
222 '....: I am .0.' \
223 '....: I am .1.' \
224 '....: I am .000.' \
225 '....: I am .100.' \
226 '....: I am .110.' \
227 '....: I am .111.' \
228 '....: I am .011.' \
229 '....: I am .001.' \
230 '.00001001. exiting gracefully' \
231 '.00001002. exiting gracefully' \
232 '.0000200.. exiting gracefully' \
233 '.0000200.. free env 0000200.'
235 echo PART B SCORE: $score/50
237 runtest1 spin \
238 '.00000000. new env 00001000' \
239 '.00000000. new env 00001001' \
240 'I am the parent. Forking the child...' \
241 '.00001001. new env 00001002' \
242 'I am the parent. Running the child...' \
243 'I am the child. Spinning...' \
244 'I am the parent. Killing the child...' \
245 '.00001001. destroying 00001002' \
246 '.00001001. free env 00001002' \
247 '.00001001. exiting gracefully' \
248 '.00001001. free env 00001001'
250 runtest1 pingpong \
251 '.00000000. new env 00001000' \
252 '.00000000. new env 00001001' \
253 '.00001001. new env 00001002' \
254 'send 0 from 1001 to 1002' \
255 '1002 got 0 from 1001' \
256 '1001 got 1 from 1002' \
257 '1002 got 8 from 1001' \
258 '1001 got 9 from 1002' \
259 '1002 got 10 from 1001' \
260 '.00001001. exiting gracefully' \
261 '.00001001. free env 00001001' \
262 '.00001002. exiting gracefully' \
263 '.00001002. free env 00001002' \
265 runtest1 primes \
266 '.00000000. new env 00001000' \
267 '.00000000. new env 00001001' \
268 '.00001001. new env 00001002' \
269 '2 .00001002. new env 00001003' \
270 '3 .00001003. new env 00001004' \
271 '5 .00001004. new env 00001005' \
272 '7 .00001005. new env 00001006' \
273 '11 .00001006. new env 00001007'
275 echo PART C SCORE: $score/65
277 if [ $score -lt 65 ]; then
278 exit 1