Permalink
Browse files

Merge branch 'lab3'

  • Loading branch information...
2 parents 934ce23 + 71f35fe commit 543773cbe72203243c8cb6f375f6d98ce26b689e @kelwin committed Sep 27, 2012
Showing with 2,082 additions and 111 deletions.
  1. +38 −12 GNUmakefile
  2. +2 −2 conf/lab.mk
  3. +134 −1 grade-functions.sh
  4. +120 −0 grade-lab3.sh
  5. +0 −75 inc/COPYRIGHT
  6. +59 −0 inc/env.h
  7. +56 −0 inc/lib.h
  8. +14 −4 inc/memlayout.h
  9. +4 −4 inc/mmu.h
  10. +1 −0 inc/string.h
  11. +13 −0 inc/syscall.h
  12. +80 −0 inc/trap.h
  13. +19 −0 inc/x86.h
  14. +15 −1 kern/Makefrag
  15. +1 −0 kern/entry.S
  16. +462 −0 kern/env.c
  17. +37 −0 kern/env.h
  18. +17 −4 kern/init.c
  19. +1 −4 kern/kclock.c
  20. +0 −1 kern/kclock.h
  21. +27 −2 kern/kdebug.c
  22. +3 −0 kern/monitor.c
  23. +64 −1 kern/pmap.c
  24. +4 −0 kern/pmap.h
  25. +75 −0 kern/syscall.c
  26. +11 −0 kern/syscall.h
  27. +216 −0 kern/trap.c
  28. +23 −0 kern/trap.h
  29. +55 −0 kern/trapentry.S
  30. +31 −0 lib/Makefrag
  31. +25 −0 lib/console.c
  32. +35 −0 lib/entry.S
  33. +9 −0 lib/exit.c
  34. +28 −0 lib/libmain.c
  35. +30 −0 lib/panic.c
  36. +62 −0 lib/printf.c
  37. +8 −0 lib/string.c
  38. +63 −0 lib/syscall.c
  39. +12 −0 user/Makefrag
  40. +11 −0 user/badsegment.c
  41. +10 −0 user/breakpoint.c
  42. +11 −0 user/buggyhello.c
  43. +13 −0 user/buggyhello2.c
  44. +13 −0 user/divzero.c
  45. +12 −0 user/evilhello.c
  46. +10 −0 user/faultread.c
  47. +10 −0 user/faultreadkernel.c
  48. +10 −0 user/faultwrite.c
  49. +10 −0 user/faultwritekernel.c
  50. +9 −0 user/hello.c
  51. +10 −0 user/softint.c
  52. +27 −0 user/testbss.c
  53. +72 −0 user/user.ld
View
@@ -63,10 +63,6 @@ endif
# try to generate a unique GDB port
GDBPORT := $(shell expr `id -u` % 5000 + 25000)
-# QEMU's gdb stub command line changed in 0.11
-QEMUGDB = $(shell if $(QEMU) -nographic -help | grep -q '^-gdb'; \
- then echo "-gdb tcp::$(GDBPORT)"; \
- else echo "-s -p $(GDBPORT)"; fi)
CC := $(GCCPREFIX)gcc -pipe
AS := $(GCCPREFIX)as
@@ -78,13 +74,14 @@ NM := $(GCCPREFIX)nm
# Native commands
NCC := gcc $(CC_VER) -pipe
+NATIVE_CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -I$(TOP) -MD -Wall
TAR := gtar
PERL := perl
# Compiler flags
# -fno-builtin is required to avoid refs to undefined functions in the kernel.
# Only optimize to -O1 to discourage inlining, which complicates backtraces.
-CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
+CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -O1 -fno-builtin -I$(TOP) -MD
CFLAGS += -fno-omit-frame-pointer
CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32
@@ -125,18 +122,22 @@ USER_CFLAGS := $(CFLAGS) -DJOS_USER -gstabs
# Include Makefrags for subdirectories
include boot/Makefrag
include kern/Makefrag
+include lib/Makefrag
+include user/Makefrag
+QEMUOPTS = -hda $(OBJDIR)/kern/kernel.img -serial mon:stdio -gdb tcp::$(GDBPORT) -D qemu.log
IMAGES = $(OBJDIR)/kern/kernel.img
-QEMUOPTS = -hda $(OBJDIR)/kern/kernel.img -serial mon:stdio $(QEMUEXTRA)
+QEMUOPTS += $(QEMUEXTRA)
+
.gdbinit: .gdbinit.tmpl
sed "s/localhost:1234/localhost:$(GDBPORT)/" < $^ > $@
-qemu: $(IMAGES)
+qemu: $(IMAGES) .gdbinit
$(QEMU) $(QEMUOPTS)
-qemu-nox: $(IMAGES)
+qemu-nox: $(IMAGES) .gdbinit
@echo "***"
@echo "*** Use Ctrl-a x to exit qemu"
@echo "***"
@@ -146,13 +147,13 @@ qemu-gdb: $(IMAGES) .gdbinit
@echo "***"
@echo "*** Now run 'gdb'." 1>&2
@echo "***"
- $(QEMU) $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) $(QEMUOPTS) -S
qemu-nox-gdb: $(IMAGES) .gdbinit
@echo "***"
@echo "*** Now run 'gdb'." 1>&2
@echo "***"
- $(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)
+ $(QEMU) -nographic $(QEMUOPTS) -S
print-qemu:
@echo $(QEMU)
@@ -165,20 +166,24 @@ print-qemugdb:
# For deleting the build
clean:
- rm -rf $(OBJDIR) .gdbinit jos.in
+ rm -rf $(OBJDIR) .gdbinit jos.in qemu.log
realclean: clean
rm -rf lab$(LAB).tar.gz jos.out
distclean: realclean
rm -rf conf/gcc.mk
+ifneq ($(V),@)
+GRADEFLAGS += -v
+endif
+
grade: $(LABSETUP)grade-lab$(LAB).sh
@echo $(MAKE) clean
@$(MAKE) clean || \
(echo "'make clean' failed. HINT: Do you have another running instance of JOS?" && exit 1)
$(MAKE) all
- sh $(LABSETUP)grade-lab$(LAB).sh
+ sh $(LABSETUP)grade-lab$(LAB).sh $(GRADEFLAGS)
handin: tarball
@echo Please visit http://pdos.csail.mit.edu/6.828/submit/
@@ -187,6 +192,27 @@ handin: tarball
tarball: realclean
tar cf - `find . -type f | grep -v '^\.*$$' | grep -v '/CVS/' | grep -v '/\.svn/' | grep -v '/\.git/' | grep -v 'lab[0-9].*\.tar\.gz'` | gzip > lab$(LAB)-handin.tar.gz
+# For test runs
+prep-%:
+ $(V)rm -f $(OBJDIR)/kern/init.o $(IMAGES)
+ $(V)$(MAKE) "DEFS=-DTEST=$$(case $* in *_*) echo $*;; *) echo user_$*;; esac)" $(IMAGES)
+ $(V)rm -f $(OBJDIR)/kern/init.o
+
+run-%-nox-gdb: .gdbinit
+ $(V)$(MAKE) --no-print-directory prep-$*
+ $(QEMU) -nographic $(QEMUOPTS) -S
+
+run-%-gdb: .gdbinit
+ $(V)$(MAKE) --no-print-directory prep-$*
+ $(QEMU) $(QEMUOPTS) -S
+
+run-%-nox: .gdbinit
+ $(V)$(MAKE) --no-print-directory prep-$*
+ $(QEMU) -nographic $(QEMUOPTS)
+
+run-%: .gdbinit
+ $(V)$(MAKE) --no-print-directory prep-$*
+ $(QEMU) $(QEMUOPTS)
# This magic automatically generates makefile dependencies
# for header files included from C source files we compile,
View
@@ -1,2 +1,2 @@
-LAB=2
-PACKAGEDATE=Wed Sep 14 23:28:01 EDT 2011
+LAB=3
+PACKAGEDATE=Wed Oct 12 22:56:15 EDT 2011
View
@@ -38,10 +38,15 @@ run () {
qemuextra="-S $qemugdb"
fi
+ qemucommand="$qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot $qemuextra"
+ if $verbose; then
+ echo $qemucommand 1>&2
+ fi
+
t0=`date +%s.%N 2>/dev/null`
(
ulimit -t $timeout
- exec $qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot $qemuextra
+ exec $qemucommand
) >$out 2>$err &
PID=$!
@@ -122,3 +127,131 @@ fail () {
fi
}
+
+#
+# User tests
+#
+
+# Usage: runtest <tagname> <defs> <check fn> <check args...>
+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
+
+ # Give qemu some more time to run (for asynchronous mode).
+ # This way, we get the small 1 second wait for most tests
+ # and a longer wait (5 seconds) in case qemu needs that
+ # time to load.
+ if [ ! -s jos.out ]
+ then
+ sleep 4
+ fi
+
+ if [ ! -s jos.out ]
+ then
+ fail > /dev/null # Still increment number of possible points
+ echo 'no jos.out'
+ else
+ shift
+ shift
+ check=$1
+ shift
+ $check "$@"
+ fi
+}
+
+quicktest () {
+ perl -e "print '$1: '"
+ shift
+ checkregexps "$@"
+}
+
+checkregexps () {
+ 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'"
+ okay=no
+ fi
+ not=false
+ else
+ egrep "^$i\$" jos.out >/dev/null
+ if [ $? -ne 0 ]
+ then
+ echo "missing '$i'"
+ okay=no
+ fi
+ not=false
+ fi
+ done
+ if [ "$okay" = "yes" ]
+ then
+ pass
+ else
+ fail
+ fi
+}
+
+# Usage: runtest1 [-tag <tagname>] [-dir <dirname>] <progname> [-Ddef...] [-check checkfn] checkargs...
+runtest1 () {
+ tag=
+ dir=user
+ check=checkregexps
+ while true; do
+ if [ $1 = -tag ]
+ then
+ tag=$2
+ elif [ $1 = -dir ]
+ then
+ dir=$2
+ else
+ break
+ fi
+ shift
+ shift
+ done
+ prog=$1
+ shift
+ if [ "x$tag" = x ]
+ then
+ tag=$prog
+ fi
+ runtest1_defs=
+ while expr "x$1" : 'x-D.*' >/dev/null; do
+ runtest1_defs="DEFS+='$1' $runtest1_defs"
+ shift
+ done
+ if [ "x$1" = "x-check" ]; then
+ check=$2
+ shift
+ shift
+ fi
+ runtest "$tag" "DEFS='-DTEST=${dir}_${prog}' $runtest1_defs" "$check" "$@"
+}
+
View
@@ -0,0 +1,120 @@
+#!/bin/sh
+
+qemuopts="-hda obj/kern/kernel.img"
+. ./grade-functions.sh
+
+
+$make
+
+# the [00001000] tags should have [] in them, but that's
+# a regular expression reserved character, and i'll be damned if
+# I can figure out how many \ i need to add to get through
+# however many times the shell interprets this string. sigh.
+
+pts=10
+
+runtest1 divzero \
+ ! '1/0 is ........!' \
+ 'Incoming TRAP frame at 0xefbfff..' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x00000000 Divide error' \
+ ' eip 0x008.....' \
+ ' ss 0x----0023' \
+ '.00001000. free env 00001000'
+
+runtest1 softint \
+ 'Welcome to the JOS kernel monitor!' \
+ 'Incoming TRAP frame at 0xefbfffbc' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000d General Protection' \
+ ' eip 0x008.....' \
+ ' ss 0x----0023' \
+ '.00001000. free env 00001000'
+
+runtest1 badsegment \
+ 'Incoming TRAP frame at 0xefbfffbc' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000d General Protection' \
+ ' err 0x00000028' \
+ ' eip 0x008.....' \
+ ' ss 0x----0023' \
+ '.00001000. free env 00001000'
+
+showpart A
+
+pts=5
+
+runtest1 faultread \
+ ! 'I read ........ from location 0!' \
+ '.00001000. user fault va 00000000 ip 008.....' \
+ 'Incoming TRAP frame at 0xefbfffbc' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000e Page Fault' \
+ ' err 0x00000004.*' \
+ '.00001000. free env 00001000'
+
+runtest1 faultreadkernel \
+ ! 'I read ........ from location 0xf0100000!' \
+ '.00001000. user fault va f0100000 ip 008.....' \
+ 'Incoming TRAP frame at 0xefbfffbc' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000e Page Fault' \
+ ' err 0x00000005.*' \
+ '.00001000. free env 00001000' \
+
+runtest1 faultwrite \
+ '.00001000. user fault va 00000000 ip 008.....' \
+ 'Incoming TRAP frame at 0xefbfffbc' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000e Page Fault' \
+ ' err 0x00000006.*' \
+ '.00001000. free env 00001000'
+
+runtest1 faultwritekernel \
+ '.00001000. user fault va f0100000 ip 008.....' \
+ 'Incoming TRAP frame at 0xefbfffbc' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x0000000e Page Fault' \
+ ' err 0x00000007.*' \
+ '.00001000. free env 00001000'
+
+
+runtest1 breakpoint \
+ 'Welcome to the JOS kernel monitor!' \
+ 'Incoming TRAP frame at 0xefbfffbc' \
+ 'TRAP frame at 0xf.......' \
+ ' trap 0x00000003 Breakpoint' \
+ ' eip 0x008.....' \
+ ' ss 0x----0023' \
+ ! '.00001000. free env 00001000'
+
+runtest1 testbss \
+ 'Making sure bss works right...' \
+ 'Yes, good. Now doing a wild write off the end...' \
+ '.00001000. user fault va 00c..... ip 008.....' \
+ '.00001000. free env 00001000'
+
+runtest1 hello \
+ '.00000000. new env 00001000' \
+ 'hello, world' \
+ 'i am environment 00001000' \
+ '.00001000. exiting gracefully' \
+ '.00001000. free env 00001000' \
+ 'Destroyed the only environment - nothing more to do!'
+
+runtest1 buggyhello \
+ '.00001000. user_mem_check assertion failure for va 00000001' \
+ '.00001000. free env 00001000'
+
+runtest1 buggyhello2 \
+ '.00001000. user_mem_check assertion failure for va 0....000' \
+ '.00001000. free env 00001000' \
+ ! 'hello, world'
+
+runtest1 evilhello \
+ '.00001000. user_mem_check assertion failure for va f0100...' \
+ '.00001000. free env 00001000'
+
+showpart B
+
+showfinal
Oops, something went wrong.

0 comments on commit 543773c

Please sign in to comment.