initial commit
[mit-jos.git] / grade.sh
blobaa12f7aa98da146b33fb76ad37569a00f47c89a8
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)"
56 gmake
57 runbochs
59 score=0
61 echo_n "Printf: "
62 if grep "6828 decimal is 15254 octal!" bochs.out >/dev/null
63 then
64 score=`expr 20 + $score`
65 echo OK $time
66 else
67 echo WRONG $time
70 echo_n "Backtrace: "
71 args=`grep "ebp f01.* eip f0100.* args" bochs.out | awk '{ print $6 }'`
72 cnt=`echo $args | grep '^00000000 00000000 00000001 00000002 00000003 00000004 00000005' | wc -w`
73 if [ $cnt -eq 8 ]
74 then
75 score=`expr 15 + $score`
76 echo_n "Count OK"
77 else
78 echo_n "Count WRONG"
81 cnt=`grep "ebp f01.* eip f0100.* args" bochs.out | awk 'BEGIN { FS = ORS = " " }
82 { print $6 }
83 END { printf("\n") }' | grep '^00000000 00000000 00000001 00000002 00000003 00000004 00000005' | wc -w`
84 if [ $cnt -eq 8 ]; then
85 score=`expr 15 + $score`
86 echo , Args OK $time
87 else
88 echo , Args WRONG "($args)" $time
91 echo "Score: $score/50"
93 if [ $score -lt 50 ]; then
94 exit 1