-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgrade-functions.sh
171 lines (154 loc) · 3.17 KB
/
grade-functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
verbose=false
if [ "x$1" = "x-v" ]
then
verbose=true
out=/dev/stdout
err=/dev/stderr
else
out=/dev/null
err=/dev/null
fi
if gmake --version >/dev/null 2>&1; then make=gmake; else make=make; fi
pts=5
timeout=30
preservefs=n
qemu=`$make -s --no-print-directory which-qemu`
brkfn=readline
echo_n () {
# suns can't echo -n, and Mac OS X can't echo "x\c"
# assume argument has no doublequotes
awk 'BEGIN { printf("'"$*"'"); }' </dev/null
}
run () {
# Find the address of the kernel readline function,
# which the kernel monitor uses to read commands interactively.
brkaddr=`grep " $brkfn\$" obj/kern/kernel.sym | sed -e's/ .*$//g'`
#echo "brkaddr $brkaddr"
# Generate a unique GDB port
port=$(expr `id -u` % 5000 + 25000)
# Run qemu, setting a breakpoint at readline(),
# and feeding in appropriate commands to run, then quit.
t0=`date +%s.%N 2>/dev/null`
(
ulimit -t $timeout
exec $qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot -s -S -p $port
) >$out 2>$err &
PID=$!
(
echo "target remote localhost:$port"
echo "br *0x$brkaddr"
echo c
) > jos.in
sleep 1
gdb -batch -nx -x jos.in > /dev/null 2>&1
t1=`date +%s.%N 2>/dev/null`
time=`echo "scale=1; ($t1-$t0)/1" | sed 's/.N/.0/g' | bc 2>/dev/null`
time="(${time}s)"
rm jos.in
# Make sure QEMU is dead. On OS X, exiting gdb doesn't always exit QEMU.
kill $PID > /dev/null 2>&1
}
# Usage: runtest <tagname> <defs> <strings...>
runtest () {
perl -e "print '$1: '"
rm -f obj/kern/init.o obj/kern/kernel obj/kern/kernel.img
[ "$preservefs" = y ] || rm -f obj/fs/fs.img
if $verbose
then
echo "$make $2... "
fi
$make $2 >$out
if [ $? -ne 0 ]
then
rm -f obj/kern/init.o
echo $make $2 failed
exit 1
fi
# We just built a weird init.o that runs a specific test. As
# a result, 'make qemu' will run the last graded test and
# 'make clean; make qemu' will run the user-specified
# environment. Remove our weird init.o to fix this.
rm -f obj/kern/init.o
run
if [ ! -s jos.out ]
then
echo 'no jos.out'
else
shift
shift
continuetest "$@"
fi
}
quicktest () {
perl -e "print '$1: '"
shift
continuetest "$@"
}
stubtest () {
perl -e "print qq|$1: OK $2\n|";
shift
score=`expr $pts + $score`
}
continuetest () {
okay=yes
not=false
for i
do
if [ "x$i" = "x!" ]
then
not=true
elif $not
then
if egrep "^$i\$" jos.out >/dev/null
then
echo "got unexpected line '$i'"
if $verbose
then
exit 1
fi
okay=no
fi
not=false
else
egrep "^$i\$" jos.out >/dev/null
if [ $? -ne 0 ]
then
echo "missing '$i'"
if $verbose
then
exit 1
fi
okay=no
fi
not=false
fi
done
if [ "$okay" = "yes" ]
then
score=`expr $pts + $score`
echo OK $time
else
echo WRONG $time
fi
}
# Usage: runtest1 [-tag <tagname>] <progname> [-Ddef...] STRINGS...
runtest1 () {
if [ $1 = -tag ]
then
shift
tag=$1
prog=$2
shift
shift
else
tag=$1
prog=$1
shift
fi
runtest1_defs=
while expr "x$1" : 'x-D.*' >/dev/null; do
runtest1_defs="DEFS+='$1' $runtest1_defs"
shift
done
runtest "$tag" "DEFS='-DTEST=_binary_obj_user_${prog}_start' DEFS+='-DTESTSIZE=_binary_obj_user_${prog}_size' $runtest1_defs" "$@"
}