PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/grade-lab6.sh

https://github.com/sandesh247/cse506-lab
Shell | 253 lines | 193 code | 44 blank | 16 comment | 24 complexity | c8d5c61e0f277dfc085541833c7cba43 MD5 | raw file
  1. #!/bin/sh
  2. qemuopts="-hda obj/kern/kernel.img -hdb obj/fs/fs.img"
  3. . ./grade-functions.sh
  4. TCPDUMP=`PATH=$PATH:/usr/sbin:/sbin which tcpdump`
  5. if [ x$TCPDUMP = x ]; then
  6. echo "Unable to find tcpdump in path, /usr/sbin, or /sbin" >&2
  7. exit 1
  8. fi
  9. $make
  10. rand() {
  11. perl -e "my \$r = int(1024 + rand() * (65535 - 1024));print \"\$r\\n\";"
  12. }
  13. check_testoutput() {
  14. num=$1
  15. $TCPDUMP -XX -r slirp.cap 2>/dev/null | egrep 0x0000 | (
  16. n=0
  17. while read line; do
  18. if [ $n -eq $num ]; then
  19. fail "extra packets sent"
  20. return 1
  21. fi
  22. if ! echo $line | egrep ": 5061 636b 6574 203. 3. Packet.0?$n$" > /dev/null; then
  23. fail "incorrect packet $n of $num"
  24. return 1
  25. fi
  26. n=`expr $n + 1`
  27. done
  28. if [ $n -ne $num ]; then
  29. fail "only got $n of $num packets"
  30. return 1
  31. fi
  32. )
  33. if [ $? = 0 ]; then
  34. pass
  35. else
  36. # The failure happened in a subshell, and thus wasn't
  37. # reflected in our tally
  38. fail > /dev/null
  39. fi
  40. }
  41. wait_for_line() {
  42. found=0
  43. for tries in `seq 10`; do
  44. if egrep "$1" jos.out >/dev/null; then
  45. found=1
  46. break
  47. fi
  48. sleep 1
  49. done
  50. if [ $found -eq 0 ]; then
  51. kill $PID
  52. wait 2> /dev/null
  53. echo "missing '$1'"
  54. fail
  55. return 1
  56. fi
  57. }
  58. check_testinput() {
  59. num=$1
  60. # Wait until it's ready to receive packets
  61. if ! wait_for_line 'Waiting for packets'; then
  62. return
  63. fi
  64. # Send num UDP packets
  65. # TODO: Uncomment
  66. echo "Echo Server Port is $echosrv_port, PID is $PID"
  67. for m in `seq -f '%03g' $num`; do
  68. # Don't use "localhost" here or some versions of
  69. # netcat will use UDP6, which qemu isn't listening on.
  70. echo "Packet $m" | nc -u -q 0 127.0.0.1 $echosrv_port
  71. done
  72. # Wait for the packets to be processed (1 second is usually
  73. # enough; if it takes more than 4, something's probably wrong)
  74. sleep 4
  75. echo "After sleep 4"
  76. kill $PID
  77. wait 2> /dev/null
  78. egrep '^input: ' jos.out | (
  79. expect() {
  80. if ! read line; then
  81. fail "$name not received"
  82. exit 1
  83. fi
  84. if ! echo "$line" | egrep "$1$" >/dev/null; then
  85. fail "receiving $name"
  86. echo "expected input: $1"
  87. echo "got $line"
  88. exit 1
  89. fi
  90. }
  91. # ARP reply
  92. name="ARP reply"
  93. expect "0000 5254 0012 3456 .... .... .... 0806 0001"
  94. expect "0010 0800 0604 0002 .... .... .... 0a00 0202"
  95. expect "0020 5254 0012 3456 0a00 020f"
  96. for m in `seq -f '%03g' $num`; do
  97. name="packet $m/$num"
  98. hex=$(echo $m | sed -re 's/(.)(.)(.)/3\1 3\23\3/')
  99. expect "0000 5254 0012 3456 .... .... .... 0800 4500"
  100. expect "0010 0027 .... 0000 ..11 .... .... .... 0a00"
  101. expect "0020 020f .... 0007 0013 .... 5061 636b 6574"
  102. expect "0030 20$hex 0a"
  103. done
  104. )
  105. if [ $? = 0 ]; then
  106. pass
  107. else
  108. # The failure happened in a subshell, and thus wasn't
  109. # reflected in our tally
  110. fail > /dev/null
  111. fi
  112. }
  113. check_echosrv() {
  114. if ! wait_for_line 'bound'; then
  115. return
  116. fi
  117. str="$t0: network server works"
  118. echo $str | nc -q 3 localhost $echosrv_port > qemu.out
  119. kill $PID
  120. wait 2> /dev/null
  121. if egrep "^$str\$" qemu.out > /dev/null
  122. then
  123. pass
  124. else
  125. fail
  126. fi
  127. }
  128. check_httpd() {
  129. if ! wait_for_line 'Waiting for http connections'; then
  130. return
  131. fi
  132. echo ""
  133. # Each of the three tests is worth a third of the points
  134. pts=$(expr $pts / 3)
  135. perl -e "print ' wget localhost:$http_port/: '"
  136. if wget -o wget.log -O /dev/null localhost:$http_port/; then
  137. fail "got back data";
  138. else
  139. if egrep "ERROR 404" wget.log >/dev/null; then
  140. pass;
  141. else
  142. fail "did not get 404 error";
  143. fi
  144. fi
  145. perl -e "print ' wget localhost:$http_port/index.html: '"
  146. if wget -o /dev/null -O qemu.out localhost:$http_port/index.html; then
  147. if diff qemu.out fs/index.html > /dev/null; then
  148. pass;
  149. else
  150. fail "returned data does not match index.html";
  151. fi
  152. else
  153. fail "got error";
  154. fi
  155. perl -e "print ' wget localhost:$http_port/random_file.txt: '"
  156. if wget -o wget.log -O /dev/null localhost:$http_port/random_file.txt; then
  157. fail "got back data";
  158. else
  159. if egrep "ERROR 404" wget.log >/dev/null; then
  160. pass;
  161. else
  162. fail "did not get 404 error";
  163. fi
  164. fi
  165. kill $PID
  166. wait 2> /dev/null
  167. }
  168. http_port=`rand`
  169. echosrv_port=`rand`
  170. echo "using http port: $http_port"
  171. echo "using echo server port: $echosrv_port"
  172. qemuopts="$qemuopts -net user -net nic,model=i82559er"
  173. qemuopts="$qemuopts -redir tcp:$echosrv_port::7 -redir tcp:$http_port::80"
  174. qemuopts="$qemuopts -redir udp:$echosrv_port::7"
  175. qemuopts="$qemuopts -pcap slirp.cap"
  176. pts=5
  177. runtest1 -tag 'testtime' testtime -DTEST_NO_NS \
  178. 'starting count down: 5 4 3 2 1 0 ' \
  179. pts=5
  180. runtest1 -tag 'pci attach' hello -DTEST_NO_NS \
  181. 'PCI function 00:03.0 .8086:1209. enabled'
  182. pts=15
  183. rm -f obj/net/testoutput*
  184. runtest1 -tag 'testoutput [5 packets]' -dir net testoutput \
  185. -DTEST_NO_NS -DTESTOUTPUT_COUNT=5 \
  186. -check check_testoutput 5
  187. pts=10
  188. rm -f obj/net/testoutput*
  189. runtest1 -tag 'testoutput [100 packets]' -dir net testoutput \
  190. -DTEST_NO_NS -DTESTOUTPUT_COUNT=100 \
  191. -check check_testoutput 100
  192. showpart A
  193. # From here on, we need to drive the network while QEMU is running, so
  194. # switch into asynchronous mode.
  195. brkfn=
  196. pts=10
  197. runtest1 -tag "testinput [100 packets]" -dir net testinput -DTEST_NO_NS \
  198. -check check_testinput 100
  199. pts=15
  200. runtest1 -tag "testinput [5 packets]" -dir net testinput -DTEST_NO_NS \
  201. -check check_testinput 5
  202. pts=15
  203. runtest1 -tag 'tcp echo server [echosrv]' echosrv \
  204. -check check_echosrv
  205. pts=30 # Actually 3 tests
  206. runtest1 -tag 'web server [httpd]' httpd \
  207. -check check_httpd
  208. showpart B
  209. showfinal