fix O_RDWR bug.
[mit-jos.git] / grade.sh
blob732780b2f129062e3422e81bc7c1058d6dccd0ce
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
160 # 20 points - run-icode
161 pts=20
162 runtest1 -tag 'updated file system switch [icode]' icode \
163 'icode: read /motd' \
164 'This is /motd, the message of the day.' \
165 'icode: spawn /init' \
166 'init: running' \
167 'init: data seems okay' \
168 'icode: exiting' \
169 'init: bss seems okay' \
170 "init: args: 'init' 'initarg1' 'initarg2'" \
171 'init: running sh' \
173 pts=10
174 runtest1 -tag 'PTE_SHARE [testpteshare]' testpteshare \
175 'fork handles PTE_SHARE right' \
176 'spawn handles PTE_SHARE right' \
178 # 10 points - run-testfdsharing
179 pts=10
180 runtest1 -tag 'fd sharing [testfdsharing]' testfdsharing \
181 'read in parent succeeded' \
182 'read in child succeeded'
184 # 10 points - run-testpipe
185 pts=10
186 runtest1 -tag 'pipe [testpipe]' testpipe \
187 'pipe read closed properly' \
188 'pipe write closed properly' \
190 # 10 points - run-testpiperace
191 pts=10
192 runtest1 -tag 'pipe race [testpiperace]' testpiperace \
193 ! 'child detected race' \
194 ! 'RACE: pipe appears closed' \
195 "race didn't happen" \
197 # 10 points - run-testpiperace2
198 pts=10
199 runtest1 -tag 'pipe race 2 [testpiperace2]' testpiperace2 \
200 ! 'RACE: pipe appears closed' \
201 ! 'child detected race' \
202 "race didn't happen" \
204 # 10 points - run-primespipe
205 pts=10
206 timeout=120
207 echo 'The primespipe test has up to 2 minutes to complete. Be patient.'
208 runtest1 -tag 'primespipe' primespipe \
209 ! 1 2 3 ! 4 5 ! 6 7 ! 8 ! 9 \
210 ! 10 11 ! 12 13 ! 14 ! 15 ! 16 17 ! 18 19 \
211 ! 20 ! 21 ! 22 23 ! 24 ! 25 ! 26 ! 27 ! 28 29 \
212 ! 30 31 ! 32 ! 33 ! 34 ! 35 ! 36 37 ! 38 ! 39 \
213 541 1009 1097
215 # 20 points - run-testshell
216 pts=20
217 timeout=60
218 runtest1 -tag 'shell [testshell]' testshell \
219 'shell ran correctly' \
221 echo "Score: $score/100"
223 if [ $score -lt 100 ]; then
224 exit 1