Skip to content

Commit

Permalink
lab3
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Clements committed Sep 29, 2011
1 parent 82f50cb commit 9bf29a3
Show file tree
Hide file tree
Showing 48 changed files with 2,030 additions and 17 deletions.
32 changes: 30 additions & 2 deletions GNUmakefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ NM := $(GCCPREFIX)nm


# Native commands # Native commands
NCC := gcc $(CC_VER) -pipe NCC := gcc $(CC_VER) -pipe
NATIVE_CFLAGS := $(CFLAGS) $(DEFS) $(LABDEFS) -I$(TOP) -MD -Wall
TAR := gtar TAR := gtar
PERL := perl PERL := perl


# Compiler flags # Compiler flags
# -fno-builtin is required to avoid refs to undefined functions in the kernel. # -fno-builtin is required to avoid refs to undefined functions in the kernel.
# Only optimize to -O1 to discourage inlining, which complicates backtraces. # 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 += -fno-omit-frame-pointer
CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32 CFLAGS += -Wall -Wno-format -Wno-unused -Werror -gstabs -m32


Expand Down Expand Up @@ -125,6 +126,8 @@ USER_CFLAGS := $(CFLAGS) -DJOS_USER -gstabs
# Include Makefrags for subdirectories # Include Makefrags for subdirectories
include boot/Makefrag include boot/Makefrag
include kern/Makefrag include kern/Makefrag
include lib/Makefrag
include user/Makefrag




IMAGES = $(OBJDIR)/kern/kernel.img IMAGES = $(OBJDIR)/kern/kernel.img
Expand Down Expand Up @@ -173,12 +176,16 @@ realclean: clean
distclean: realclean distclean: realclean
rm -rf conf/gcc.mk rm -rf conf/gcc.mk


ifneq ($(V),@)
GRADEFLAGS += -v
endif

grade: $(LABSETUP)grade-lab$(LAB).sh grade: $(LABSETUP)grade-lab$(LAB).sh
@echo $(MAKE) clean @echo $(MAKE) clean
@$(MAKE) clean || \ @$(MAKE) clean || \
(echo "'make clean' failed. HINT: Do you have another running instance of JOS?" && exit 1) (echo "'make clean' failed. HINT: Do you have another running instance of JOS?" && exit 1)
$(MAKE) all $(MAKE) all
sh $(LABSETUP)grade-lab$(LAB).sh sh $(LABSETUP)grade-lab$(LAB).sh $(GRADEFLAGS)


handin: tarball handin: tarball
@echo Please visit http://pdos.csail.mit.edu/6.828/submit/ @echo Please visit http://pdos.csail.mit.edu/6.828/submit/
Expand All @@ -187,6 +194,27 @@ handin: tarball
tarball: realclean 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 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=user_$*" $(IMAGES)
$(V)rm -f $(OBJDIR)/kern/init.o

run-%-nox-gdb: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) -nographic $(QEMUOPTS) -S $(QEMUGDB)

run-%-gdb: .gdbinit
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) $(QEMUOPTS) -S $(QEMUGDB)

run-%-nox:
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) -nographic $(QEMUOPTS)

run-%:
$(V)$(MAKE) --no-print-directory prep-$*
$(QEMU) $(QEMUOPTS)


# This magic automatically generates makefile dependencies # This magic automatically generates makefile dependencies
# for header files included from C source files we compile, # for header files included from C source files we compile,
Expand Down
4 changes: 2 additions & 2 deletions conf/lab.mk
Original file line number Original file line Diff line number Diff line change
@@ -1,2 +1,2 @@
LAB=2 LAB=3
PACKAGEDATE=Wed Sep 14 23:28:01 EDT 2011 PACKAGEDATE=Wed Sep 28 23:57:24 EDT 2011
135 changes: 134 additions & 1 deletion grade-functions.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ run () {
qemuextra="-S $qemugdb" qemuextra="-S $qemugdb"
fi 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` t0=`date +%s.%N 2>/dev/null`
( (
ulimit -t $timeout ulimit -t $timeout
exec $qemu -nographic $qemuopts -serial file:jos.out -monitor null -no-reboot $qemuextra exec $qemucommand
) >$out 2>$err & ) >$out 2>$err &
PID=$! PID=$!


Expand Down Expand Up @@ -122,3 +127,131 @@ fail () {
fi 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
Original file line number Original file line Diff line number Diff line change
@@ -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
Loading

0 comments on commit 9bf29a3

Please sign in to comment.