-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathgrade-lab6.sh
130 lines (103 loc) · 2.71 KB
/
grade-lab6.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
#!/bin/sh
qemuopts="-hda obj/kern/kernel.img -hdb obj/fs/fs.img"
. ./grade-functions.sh
$make
rand() {
perl -e "my \$r = int(1024 + rand() * (65535 - 1024));print \"\$r\\n\";"
}
qemu_test_httpd() {
pts=5
echo ""
perl -e "print ' wget localhost:$http_port/: '"
if wget -o wget.log -O /dev/null localhost:$http_port/; then
echo "WRONG, got back data";
else
if egrep "ERROR 404" wget.log >/dev/null; then
score=`expr $pts + $score`
echo "OK";
else
echo "WRONG, did not get 404 error";
fi
fi
perl -e "print ' wget localhost:$http_port/index.html: '"
if wget -o /dev/null -O qemu.out localhost:$http_port/index.html; then
if diff qemu.out fs/index.html > /dev/null; then
score=`expr $pts + $score`
echo "OK";
else
echo "WRONG, returned data does not match index.html";
fi
else
echo "WRONG, got error";
fi
perl -e "print ' wget localhost:$http_port/random_file.txt: '"
if wget -o wget.log -O /dev/null localhost:$http_port/random_file.txt; then
echo "WRONG, got back data";
else
if egrep "ERROR 404" wget.log >/dev/null; then
score=`expr $pts + $score`
echo "OK";
else
echo "WRONG, did not get 404 error";
fi
fi
kill $qemu_pid
wait 2> /dev/null
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)"
}
qemu_test_echosrv() {
pts=85
str="$t0: network server works"
echo $str | nc -q 3 localhost $echosrv_port > qemu.out
kill $qemu_pid
wait 2> /dev/null
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)"
if egrep "^$str\$" qemu.out > /dev/null
then
score=`expr $pts + $score`
echo OK $time
else
echo WRONG $time
fi
}
# Override run to start QEMU and return without waiting
run() {
t0=`date +%s.%N 2>/dev/null`
# The timeout here doesn't really matter, but it helps prevent
# runaway qemu's
(
ulimit -t $timeout
exec $qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot
) >$out 2>$err &
qemu_pid=$!
sleep 8 # wait for qemu to start up
}
# Make continuetest a no-op and run the tests ourselves
continuetest () {
return
}
# Reset the file system to its original, pristine state
resetfs() {
rm -f obj/fs/fs.img
$make obj/fs/fs.img >$out
}
score=0
http_port=`rand`
echosrv_port=`rand`
echo "using http port: $http_port"
echo "using echo server port: $echosrv_port"
qemuopts="$qemuopts -net user -net nic,model=i82559er"
qemuopts="$qemuopts -redir tcp:$echosrv_port::7 -redir tcp:$http_port::80"
resetfs
runtest1 -tag 'tcp echo server [echosrv]' echosrv
qemu_test_echosrv
runtest1 -tag 'web server [httpd]' httpd
qemu_test_httpd
echo "Score: $score/100"
if [ $score -lt 100 ]; then
exit 1
fi