spawn implemented.
[mit-jos.git] / grade.sh
blob89bd855ca31b3f2b41afca91e381675e4213ab71
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 # Reset the file system to its original, pristine state
161 resetfs() {
162 rm -f obj/fs/fs.img
163 gmake obj/fs/fs.img >$out
167 resetfs
169 runtest1 -tag 'fs i/o [testfsipc]' testfsipc \
170 'FS can do I/O' \
171 ! 'idle loop can do I/O' \
173 quicktest 'read_block [testfsipc]' \
174 'superblock is good' \
176 quicktest 'write_block [testfsipc]' \
177 'write_block is good' \
179 quicktest 'read_bitmap [testfsipc]' \
180 'read_bitmap is good' \
182 quicktest 'alloc_block [testfsipc]' \
183 'alloc_block is good' \
185 quicktest 'file_open [testfsipc]' \
186 'file_open is good' \
188 quicktest 'file_get_block [testfsipc]' \
189 'file_get_block is good' \
191 quicktest 'file_truncate [testfsipc]' \
192 'file_truncate is good' \
194 quicktest 'file_flush [testfsipc]' \
195 'file_flush is good' \
197 quicktest 'file rewrite [testfsipc]' \
198 'file rewrite is good' \
200 quicktest 'serv_* [testfsipc]' \
201 'serve_open is good' \
202 'serve_map is good' \
203 'serve_close is good' \
204 'stale fileid is good' \
206 echo PART A SCORE: $score/55
208 partascore=$score
210 score=0
211 pts=10
212 runtest1 -tag 'motd display [writemotd]' writemotd \
213 'OLD MOTD' \
214 'This is /motd, the message of the day.' \
215 'NEW MOTD' \
216 'This is the NEW message of the day!' \
218 preservefs=y
219 runtest1 -tag 'motd change [writemotd]' writemotd \
220 'OLD MOTD' \
221 'This is the NEW message of the day!' \
222 'NEW MOTD' \
223 ! 'This is /motd, the message of the day.' \
225 pts=25
226 preservefs=n
227 runtest1 -tag 'spawn via icode [icode]' icode \
228 'icode: read /motd' \
229 'This is /motd, the message of the day.' \
230 'icode: spawn /init' \
231 'init: running' \
232 'init: data seems okay' \
233 'icode: exiting' \
234 'init: bss seems okay' \
235 "init: args: 'init' 'initarg1' 'initarg2'" \
236 'init: exiting' \
238 echo PART B SCORE: $score/45
240 if [ $partascore -lt 55 -o $score -lt 45 ]; then
241 exit 1