Skip to content

Commit

Permalink
Merge branch 'lab3'
Browse files Browse the repository at this point in the history
  • Loading branch information
kelwin committed Sep 27, 2012
2 parents 934ce23 + 71f35fe commit 543773c
Show file tree
Hide file tree
Showing 53 changed files with 2,082 additions and 111 deletions.
50 changes: 38 additions & 12 deletions GNUmakefile
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 "***"
Expand All @@ -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)
Expand All @@ -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/
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions conf/lab.mk
@@ -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
135 changes: 134 additions & 1 deletion grade-functions.sh
Expand Up @@ -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=$!

Expand Down Expand Up @@ -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" "$@"
}

120 changes: 120 additions & 0 deletions grade-lab3.sh
@@ -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

0 comments on commit 543773c

Please sign in to comment.