Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 258 lines (226 sloc) 4.459 kB
52e7e6a @aclements lab1
aclements authored
1 verbose=false
2
3 if [ "x$1" = "x-v" ]
4 then
5 verbose=true
6 out=/dev/stdout
7 err=/dev/stderr
8 else
9 out=/dev/null
10 err=/dev/null
11 fi
12
13 if gmake --version >/dev/null 2>&1; then make=gmake; else make=make; fi
14
15 #
16 # QEMU
17 #
18
19 timeout=30
20 preservefs=n
21 qemu=`$make -s --no-print-directory print-qemu`
22 gdbport=`$make -s --no-print-directory print-gdbport`
23 qemugdb=`$make -s --no-print-directory print-qemugdb`
24 brkfn=readline
25
26 echo_n () {
27 # suns can't echo -n, and Mac OS X can't echo "x\c"
28 # assume argument has no doublequotes
29 awk 'BEGIN { printf("'"$*"'"); }' </dev/null
30 }
31
32 # Run QEMU with serial output redirected to jos.out. If $brkfn is
33 # non-empty, wait until $brkfn is reached or $timeout expires, then
34 # kill QEMU.
35 run () {
36 qemuextra=
37 if [ "$brkfn" ]; then
38 qemuextra="-S $qemugdb"
39 fi
40
9bf29a3 @aclements lab3
aclements authored
41 qemucommand="$qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot $qemuextra"
42 if $verbose; then
43 echo $qemucommand 1>&2
44 fi
45
52e7e6a @aclements lab1
aclements authored
46 t0=`date +%s.%N 2>/dev/null`
47 (
48 ulimit -t $timeout
9bf29a3 @aclements lab3
aclements authored
49 exec $qemucommand
52e7e6a @aclements lab1
aclements authored
50 ) >$out 2>$err &
51 PID=$!
52
53 # Wait for QEMU to start
54 sleep 1
55
56 if [ "$brkfn" ]; then
57 # Find the address of the kernel $brkfn function,
58 # which is typically what the kernel monitor uses to
59 # read commands interactively.
60 brkaddr=`grep " $brkfn\$" obj/kern/kernel.sym | sed -e's/ .*$//g'`
61
62 (
63 echo "target remote localhost:$gdbport"
64 echo "br *0x$brkaddr"
65 echo c
66 ) > jos.in
67 gdb -batch -nx -x jos.in > /dev/null 2>&1
68
69 # Make sure QEMU is dead. On OS X, exiting gdb
70 # doesn't always exit QEMU.
71 kill $PID > /dev/null 2>&1
72 fi
73 }
74
75 #
76 # Scoring
77 #
78
79 pts=5
80 part=0
81 partpos=0
82 total=0
83 totalpos=0
84
85 showpart () {
86 echo "Part $1 score: $part/$partpos"
87 echo
88 total=`expr $total + $part`
89 totalpos=`expr $totalpos + $partpos`
90 part=0
91 partpos=0
92 }
93
94 showfinal () {
95 total=`expr $total + $part`
96 totalpos=`expr $totalpos + $partpos`
97 echo "Score: $total/$totalpos"
98 if [ $total -lt $totalpos ]; then
99 exit 1
100 fi
101 }
102
103 passfailmsg () {
104 msg="$1"
105 shift
106 if [ $# -gt 0 ]; then
107 msg="$msg,"
108 fi
109
110 t1=`date +%s.%N 2>/dev/null`
111 time=`echo "scale=1; ($t1-$t0)/1" | sed 's/.N/.0/g' | bc 2>/dev/null`
112
113 echo $msg "$@" "(${time}s)"
114 }
115
116 pass () {
117 passfailmsg OK "$@"
118 part=`expr $part + $pts`
119 partpos=`expr $partpos + $pts`
120 }
121
122 fail () {
123 passfailmsg WRONG "$@"
124 partpos=`expr $partpos + $pts`
125 if $verbose; then
126 exit 1
127 fi
128 }
129
9bf29a3 @aclements lab3
aclements authored
130
131 #
132 # User tests
133 #
134
135 # Usage: runtest <tagname> <defs> <check fn> <check args...>
136 runtest () {
137 perl -e "print '$1: '"
138 rm -f obj/kern/init.o obj/kern/kernel obj/kern/kernel.img
139 [ "$preservefs" = y ] || rm -f obj/fs/fs.img
140 if $verbose
141 then
142 echo "$make $2... "
143 fi
144 $make $2 >$out
145 if [ $? -ne 0 ]
146 then
147 rm -f obj/kern/init.o
148 echo $make $2 failed
149 exit 1
150 fi
151 # We just built a weird init.o that runs a specific test. As
152 # a result, 'make qemu' will run the last graded test and
153 # 'make clean; make qemu' will run the user-specified
154 # environment. Remove our weird init.o to fix this.
155 rm -f obj/kern/init.o
156 run
157
158 # Give qemu some more time to run (for asynchronous mode).
159 # This way, we get the small 1 second wait for most tests
160 # and a longer wait (5 seconds) in case qemu needs that
161 # time to load.
162 if [ ! -s jos.out ]
163 then
164 sleep 4
165 fi
166
167 if [ ! -s jos.out ]
168 then
169 fail > /dev/null # Still increment number of possible points
170 echo 'no jos.out'
171 else
172 shift
173 shift
174 check=$1
175 shift
176 $check "$@"
177 fi
178 }
179
180 quicktest () {
181 perl -e "print '$1: '"
182 shift
183 checkregexps "$@"
184 }
185
186 checkregexps () {
187 okay=yes
188
189 not=false
190 for i
191 do
192 if [ "x$i" = "x!" ]
193 then
194 not=true
195 elif $not
196 then
197 if egrep "^$i\$" jos.out >/dev/null
198 then
199 echo "got unexpected line '$i'"
200 okay=no
201 fi
202 not=false
203 else
204 egrep "^$i\$" jos.out >/dev/null
205 if [ $? -ne 0 ]
206 then
207 echo "missing '$i'"
208 okay=no
209 fi
210 not=false
211 fi
212 done
213 if [ "$okay" = "yes" ]
214 then
215 pass
216 else
217 fail
218 fi
219 }
220
221 # Usage: runtest1 [-tag <tagname>] [-dir <dirname>] <progname> [-Ddef...] [-check checkfn] checkargs...
222 runtest1 () {
223 tag=
224 dir=user
225 check=checkregexps
226 while true; do
227 if [ $1 = -tag ]
228 then
229 tag=$2
230 elif [ $1 = -dir ]
231 then
232 dir=$2
233 else
234 break
235 fi
236 shift
237 shift
238 done
239 prog=$1
240 shift
241 if [ "x$tag" = x ]
242 then
243 tag=$prog
244 fi
245 runtest1_defs=
246 while expr "x$1" : 'x-D.*' >/dev/null; do
247 runtest1_defs="DEFS+='$1' $runtest1_defs"
248 shift
249 done
250 if [ "x$1" = "x-check" ]; then
251 check=$2
252 shift
253 shift
254 fi
255 runtest "$tag" "DEFS='-DTEST=${dir}_${prog}' $runtest1_defs" "$check" "$@"
256 }
257
Something went wrong with that request. Please try again.