From: Ben Pfaff Date: Wed, 27 Oct 2004 00:48:14 +0000 (+0000) Subject: Work on userprog tests. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5979ba5edd96453f3658e58bdbd7686a4f4380e2;p=pintos-anon Work on userprog tests. --- diff --git a/grading/userprog/Makefile b/grading/userprog/Makefile index d085aae..a928b97 100644 --- a/grading/userprog/Makefile +++ b/grading/userprog/Makefile @@ -8,5 +8,22 @@ $(1)_SRC = $(1).c endef $(foreach prog,$(SINGLETONS),$(eval $(call SINGLETON_PROG,$(prog)))) +DISKS = $(patsubst %,%.dsk,$(PROGS)) + +disks: $(DISKS) + +PINTOS = ../../src/utils/pintos +%.dsk: % os.dsk + rm -f $@ fs.dsk + $(PINTOS) make-disk fs.dsk 2 + $(PINTOS) -v run -f -q + $(PINTOS) -v put $< + mv fs.dsk $@ + +os.dsk: ../../src/userprog/build/os.dsk + ln -sf $< $@ + +clean:: + rm -f $(DISKS) include $(SRCDIR)/Makefile.userprog diff --git a/grading/userprog/review.txt b/grading/userprog/review.txt new file mode 100644 index 0000000..38ea7ac --- /dev/null +++ b/grading/userprog/review.txt @@ -0,0 +1,65 @@ +Design (/120 points) +-------------------- + +a) DESIGNDOC (/60 pts) + a) Arg passing (/10) + b) System calls (/20) + Didn't discuss global vs local allocation of fileID's + How to handle exceptions & why (ie killing processes + that do bad things) + Explaining choice of openFileID's & ASIDS + c) Multiprogramming (/30) + How to find a free page. + Explaining how new processes are executed. + How they deal with running out of memory error on loading. + +b) Other Design (/60 pts) + + 1. Argument passing + No checking for page boundaries in argument passing -10 + Uses memcpy/bcopy/memmove or file reading/writing for +5 + copying up to/starting from page boundaries -- good job! + (Search for memcpy/bcopy, not just extern, make sure they call it + with the possibility of copying more than 4 bytes at a time. ALSO if + they do File Read/Writes then that is not byte-by-byte but they will + fail page crossing only take off for failing the pagecrossing test.) + Don't decomp / reuse translation code -5 + Using strtok instead of strtok_r or strsep -1 + (strtok is not thread-safe) + + 2. System calls + No checking for page boundaries in system calls -20 + (-5 if they only forgot for some system calls but did it somewhere) + Interrupts turned off for all system calls -10 + Doesn't close open files after process exits -2 + table/when file is closed, it is not removed from file table + Uses printf/fscanf/putc/getc when interacting -5 + with StandardInput / StandardOutput + Using fixed length buffer for Read/Write -5 + Using pointer to int casts as ASID/FileId without justifying -5 + + 3. Multiprogramming + Don't use the bitmap object -5 + Bitmap is not cleared when process dies -5 + Access to bitmap is not sychronized -5 + getting next ASID is not synchronized -5 + ...or (mututally exclusive, depending on their solution)... + Doesn't use ASID's at all, but their system for identifying -5 + processes has synchronization or uniqueness problems (e.g. + careless use of AddrSpace*'s) + Multiple translations for a page -10 + (One vaddr maps to two paddr's, or vice versa) + +Style (/30 points) +------------------ +0) Had to modify code to get to compile the first -10 + time +1) Minor changes to machine code -10 +2) Extraneous output -5 +3) Unexplained dependencies -5 +4) Not Decomposing Exception handler -5 + +TESTCASEs (/30 points) +---------------------- + Don't write own testcases -15 + Not sufficient testing up to -10 diff --git a/grading/userprog/run-tests b/grading/userprog/run-tests new file mode 100755 index 0000000..62d243c --- /dev/null +++ b/grading/userprog/run-tests @@ -0,0 +1,780 @@ +#! /usr/bin/perl + +use warnings; +use strict; +use POSIX; +use Algorithm::Diff; +use Getopt::Long; + +our ($VERBOSE) = 0; # Verbosity of output +our (@TESTS); # Tests to run. +my ($clean) = 0; +my ($grade) = 0; + +GetOptions ("v|verbose+" => \$VERBOSE, + "h|help" => sub { usage (0) }, + "t|test=s" => \@TESTS, + "c|clean" => \$clean, + "g|grade" => \$grade) + or die "Malformed command line; use --help for help.\n"; +die "Non-option argument not supported; use --help for help.\n" + if @ARGV > 0; + +sub usage { + my ($exitcode) = @_; + print "run-tests, for grading Pintos multiprogramming projects.\n\n"; + print "Invoke from a directory containing a student tarball named by\n"; + print "the submit script, e.g. username.Oct.12.04.20.04.09.tar.gz.\n"; + print "In normal usage, no options are needed.\n\n"; + print "Output is produced in tests.out and details.out.\n\n"; + print "Options:\n"; + print " -c, --clean Remove old output files before starting\n"; + print " -t, --test=TEST Execute TEST only (allowed multiple times)\n"; + print " -g, --grade Instead of running tests, compose grade.out\n"; + print " -v, --verbose Print commands before executing them\n"; + print " -h, --help Print this help message\n"; + exit $exitcode; +} + +# Default set of tests. +@TESTS = ("alarm-single", "alarm-multiple", "alarm-zero", "alarm-negative", + "join-simple", + "join-quick", "join-multiple", "join-nested", + "join-dummy", "join-invalid", "join-no", + "priority-preempt", "priority-fifo", "priority-donate-one", + "priority-donate-multiple", "priority-donate-nest", + "mlfqs-on", "mlfqs-off") + unless @TESTS > 0; + +# Handle final grade mode. +if ($grade) { + open (OUT, ">grade.out") or die "grade.out: create: $!\n"; + + open (GRADE, ") { + last if /^\s*$/; + print OUT; + } + close (GRADE); + + my (@tests) = snarf ("tests.out"); + my ($p_got, $p_pos) = $tests[0] =~ m%\((\d+)/(\d+)\)% or die; + + my (@review) = snarf ("review.txt"); + my ($part_lost) = (0, 0); + for (my ($i) = $#review; $i >= 0; $i--) { + local ($_) = $review[$i]; + if (my ($loss) = /^\s*([-+]\d+)/) { + $part_lost += $loss; + } elsif (my ($out_of) = m%\[\[/(\d+)\]\]%) { + my ($got) = $out_of + $part_lost; + $got = 0 if $got < 0; + $review[$i] =~ s%\[\[/\d+\]\]%($got/$out_of)% or die; + $part_lost = 0; + + $p_got += $got; + $p_pos += $out_of; + } + } + die "Lost points outside a section\n" if $part_lost; + + for (my ($i) = 1; $i <= $#review; $i++) { + if ($review[$i] =~ /^-{3,}\s*$/ && $review[$i - 1] !~ /^\s*$/) { + $review[$i] = '-' x (length ($review[$i - 1])); + } + } + + print OUT "\nOVERALL SCORE\n"; + print OUT "-------------\n"; + print OUT "$p_got points out of $p_pos total\n\n"; + + print OUT map ("$_\n", @tests), "\n"; + print OUT map ("$_\n", @review), "\n"; + + print OUT "DETAILS\n"; + print OUT "-------\n\n"; + print OUT map ("$_\n", snarf ("details.out")); + + exit 0; +} + +# Find the directory that contains the grading files. +our ($GRADES_DIR); +($GRADES_DIR = $0) =~ s#/[^/]+$##; +-d $GRADES_DIR or die "$GRADES_DIR: stat: $!\n"; + +if ($clean) { + # Verify that we're roughly in the correct directory + # before we go blasting away files. + choose_tarball (); + + xsystem ("rm -rf output pintos", VERBOSE => 1); + xsystem ("rm -f details.out tests.out", VERBOSE => 1); +} + +# Create output directory, if it doesn't already exist. +-d ("output") || mkdir ("output") or die "output: mkdir: $!\n"; + +# Extract submission. +extract_tarball () if ! -d "pintos"; + +# Verify that the proper directory was submitted. +-d "pintos/src/threads" or die "pintos/src/threads: stat: $!\n"; + +# Run and grade the tests. +our $test; +our %result; +our %details; +our %extra; +for $test (@TESTS) { + print "$test: "; + my ($result) = run_test ($test); + if ($result eq 'ok') { + $result = grade_test ($test); + $result =~ s/\n$//; + } + print "$result\n"; + + $result{$test} = $result; +} + +# MLFQS takes results from mlfqs-on and mlfqs-off. +grade_mlfqs_speedup (); +grade_mlfqs_priority (); + +# Write output. +write_grades (); +write_details (); + +sub choose_tarball { + my (@tarballs) + = grep (/^[a-z0-9]+\.[A-Za-z]+\.\d+\.\d+\.\d+\.\d+.\d+\.tar\.gz$/, + glob ("*.tar.gz")); + die "no pintos dir and no source tarball\n" if scalar (@tarballs) == 0; + + # Sort tarballs in reverse order by time. + @tarballs = sort { ext_mdyHMS ($b) cmp ext_mdyHMS ($a) } @tarballs; + + print "Multiple tarballs: choosing $tarballs[0]\n" + if scalar (@tarballs) > 1; + return $tarballs[0]; +} + +sub extract_tarball { + my ($tarball) = choose_tarball (); + + mkdir "pintos" or die "pintos: mkdir: $!\n"; + mkdir "pintos/src" or die "pintos: mkdir: $!\n"; + + print "Extracting $tarball...\n"; + xsystem ("cd pintos/src && tar xzf ../../$tarball", + DIE => "extraction failed\n"); + + print "Patching...\n"; + xsystem ("patch -fs pintos/src/lib/debug.c < $GRADES_DIR/panic.diff", + LOG => "patch", + DIE => "patch failed\n"); +} + +sub ext_mdyHMS { + my ($s) = @_; + my ($ms, $d, $y, $H, $M, $S) = + $s =~ /.([A-Za-z]+)\.(\d+)\.(\d+)\.(\d+)\.(\d+).(\d+)\.tar\.gz$/ + or die; + my ($m) = index ("janfebmaraprmayjunjulaugsepoctnovdec", lc $ms) / 3 + or die; + return sprintf "%02d-%02d-%02d %02d:%02d:%02d", $y, $m, $d, $H, $M, $S; +} + +sub test_source { + my ($test) = @_; + my ($src) = "$GRADES_DIR/$test.c"; + $src = "$GRADES_DIR/mlfqs.c" if $test =~ /^mlfqs/; + -e $src or die "$src: stat: $!\n"; + return $src; +} + +sub test_constants { + my ($defines) = ""; + $defines .= "#define MLFQS 1\n" if $test eq 'mlfqs-on'; + return $defines; + } + +sub run_test { + my ($test) = @_; + + # Reuse older results if any. + if (open (DONE, "; + chomp $status; + close (DONE); + return $status; + } + + # Really run the test. + my ($status) = really_run_test ($test); + + # Save the results for later. + open (DONE, ">output/$test/done") or die "output/$test/done: create: $!\n"; + print DONE "$status\n"; + close (DONE); + + return $status; +} + +sub really_run_test { + # Need to run it. + # If there's residue from an earlier test, move it to .old. + # If there's already a .old, delete it. + xsystem ("rm -rf output/$test.old", VERBOSE => 1) if -d "output/$test.old"; + rename "output/$test", "output/$test.old" or die "rename: $!\n" + if -d "output/$test"; + + # Make output directory. + mkdir "output/$test"; + + # Change constants.h if necessary. + my ($defines) = test_constants ($test); + if ($defines ne snarf ("pintos/src/constants.h")) { + open (CONSTANTS, ">pintos/src/constants.h"); + print CONSTANTS $defines; + close (CONSTANTS); + } + + # Changes devices/timer.c if necessary. + my ($new_time_slice) = $test eq 'priority-fifo' ? 100 : 1; + my (@timer) = snarf ("pintos/src/devices/timer.c"); + if (!grep (/^\#define TIME_SLICE $new_time_slice$/, @timer)) { + @timer = grep (!/^\#define TIME_SLICE/, @timer); + unshift (@timer, "#define TIME_SLICE $new_time_slice"); + open (TIMER, ">pintos/src/devices/timer.c"); + print TIMER map ("$_\n", @timer); + close (TIMER); + } + + # Copy in the new test.c and delete enough files to ensure a full rebuild. + my ($src) = test_source ($test); + xsystem ("cp $src pintos/src/threads/test.c", DIE => "cp failed\n"); + unlink ("pintos/src/threads/build/threads/test.o"); + unlink ("pintos/src/threads/build/kernel.o"); + unlink ("pintos/src/threads/build/kernel.bin"); + unlink ("pintos/src/threads/build/os.dsk"); + + # Build. + xsystem ("cd pintos/src/threads && make", LOG => "$test/make") + or return "compile error"; + + # Copy out files for backtraces later. + xsystem ("cp pintos/src/threads/build/kernel.o output/$test"); + xsystem ("cp pintos/src/threads/build/os.dsk output/$test"); + + # Run. + my ($timeout) = 10; + $timeout = 600 if $test =~ /^mlfqs/; + xsystem ("cd pintos/src/threads/build && pintos -v run -q", + LOG => "$test/run", + TIMEOUT => $timeout) + or return "Bochs error"; + + return "ok"; +} + +sub grade_test { + my ($test) = @_; + + my (@output) = snarf ("output/$test/run.out"); + + if (-e "$GRADES_DIR/$test.exp") { + eval { + verify_common (@output); + compare_output ("$GRADES_DIR/$test.exp", @output); + } + } else { + my ($grade_func); + ($grade_func = $test) =~ s/-/_/g; + eval "grade_$grade_func (\@output)"; + } + if ($@) { + die $@ if $@ =~ /at \S+ line \d+$/; + return $@; + } + return "ok"; +} + +sub grade_alarm_single { + verify_alarm (1, @_); +} + +sub grade_alarm_multiple { + verify_alarm (7, @_); +} + +sub verify_alarm { + my ($iterations, @output) = @_; + + verify_common (@output); + + my (@products); + for (my ($i) = 0; $i < $iterations; $i++) { + for (my ($t) = 0; $t < 5; $t++) { + push (@products, ($i + 1) * ($t + 1) * 10); + } + } + @products = sort {$a <=> $b} @products; + + local ($_); + foreach (@output) { + die $_ if /Out of order/; + + my ($p) = /product=(\d+)$/; + next if !defined $p; + + my ($q) = shift (@products); + die "Too many wakeups.\n" if !defined $q; + die "Out of order wakeups ($p vs. $q).\n" if $p != $q; # FIXME + } + die scalar (@products) . " fewer wakeups than expected.\n" + if @products != 0; +} + +sub grade_alarm_zero { + my (@output) = @_; + verify_common (@output); + die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output); +} + +sub grade_alarm_negative { + my (@output) = @_; + verify_common (@output); + die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output); +} + +sub grade_join_invalid { + my (@output) = @_; + verify_common (@output); + grep (/Testing invalid join/, @output) or die "Test didn't start\n"; + grep (/Invalid join test done/, @output) or die "Test didn't complete\n"; +} + +sub grade_join_no { + my (@output) = @_; + verify_common (@output); + grep (/Testing no join/, @output) or die "Test didn't start\n"; + grep (/No join test done/, @output) or die "Test didn't complete\n"; +} + +sub grade_join_multiple { + my (@output) = @_; + + verify_common (@output); + my (@t); + $t[4] = $t[5] = $t[6] = -1; + local ($_); + foreach (@output) { + my ($idx) = /^Thread (\d+)/ or next; + my ($iter) = /iteration (\d+)$/; + $iter = 5 if /done!$/; + die "Malformed output\n" if !defined $iter; + if ($idx == 6) { + die "Thread 6 started before either other thread finished\n" + if $t[4] < 5 && $t[5] < 5; + die "Thread 6 started before thread 4 finished\n" + if $t[4] < 5; + die "Thread 6 started before thread 5 finished\n" + if $t[5] < 5; + } + die "Thread $idx out of order output\n" if $t[$idx] != $iter - 1; + $t[$idx] = $iter; + } + + my ($err) = ""; + for my $idx (4, 5, 6) { + if ($t[$idx] == -1) { + $err .= "Thread $idx did not run at all\n"; + } elsif ($t[$idx] != 5) { + $err .= "Thread $idx only completed $t[$idx] iterations\n"; + } + } + die $err if $err ne ''; +} + +sub grade_priority_fifo { + my (@output) = @_; + + verify_common (@output); + my ($thread_cnt) = 10; + my ($iter_cnt) = 5; + my (@order); + my (@t) = (-1) x $thread_cnt; + local ($_); + foreach (@output) { + my ($idx) = /^Thread (\d+)/ or next; + my ($iter) = /iteration (\d+)$/; + $iter = $iter_cnt if /done!$/; + die "Malformed output\n" if !defined $iter; + if (@order < $thread_cnt) { + push (@order, $idx); + die "Thread $idx repeated within first $thread_cnt iterations: " + . join (' ', @order) . ".\n" + if grep ($_ == $idx, @order) != 1; + } else { + die "Thread $idx ran when $order[0] should have.\n" + if $idx != $order[0]; + push (@order, shift @order); + } + die "Thread $idx out of order output.\n" if $t[$idx] != $iter - 1; + $t[$idx] = $iter; + } + + my ($err) = ""; + for my $idx (0..$#t) { + if ($t[$idx] == -1) { + $err .= "Thread $idx did not run at all.\n"; + } elsif ($t[$idx] != $iter_cnt) { + $err .= "Thread $idx only completed $t[$idx] iterations.\n"; + } + } + die $err if $err ne ''; +} + +sub grade_mlfqs_on { + my (@output) = @_; + verify_common (@output); + our (@mlfqs_on_stats) = mlfqs_stats (@output); +} + +sub grade_mlfqs_off { + my (@output) = @_; + verify_common (@output); + our (@mlfqs_off_stats) = mlfqs_stats (@output); +} + +sub grade_mlfqs_speedup { + our (@mlfqs_off_stats); + our (@mlfqs_on_stats); + eval { + check_mlfqs (); + my ($off_ticks) = $mlfqs_off_stats[1]; + my ($on_ticks) = $mlfqs_on_stats[1]; + die "$off_ticks ticks without MLFQS, $on_ticks with MLFQS\n" + if $on_ticks >= $off_ticks; + die "ok\n"; + }; + chomp $@; + $result{'mlfqs-speedup'} = $@; +} + +sub grade_mlfqs_priority { + our (@mlfqs_off_stats); + our (@mlfqs_on_stats); + eval { + check_mlfqs () if !defined (@mlfqs_on_stats); + for my $cat qw (CPU IO MIX) { + die "Priority changed away from PRI_DEFAULT (29) without MLFQS\n" + if $mlfqs_off_stats[0]{$cat}{MIN} != 29 + || $mlfqs_off_stats[0]{$cat}{MAX} != 29; + die "Minimum priority never changed from PRI_DEFAULT (29) " + . "with MLFQS\n" + if $mlfqs_on_stats[0]{$cat}{MIN} == 29; + die "Maximum priority never changed from PRI_DEFAULT (29) " + . "with MLFQS\n" + if $mlfqs_on_stats[0]{$cat}{MAX} == 29; + } + die "ok\n"; + }; + chomp $@; + $result{'mlfqs-priority'} = $@; +} + +sub check_mlfqs { + our (@mlfqs_off_stats); + our (@mlfqs_on_stats); + die "p1-4 didn't finish with MLFQS on or off\n" + if !defined (@mlfqs_off_stats) && !defined (@mlfqs_on_stats); + die "p1-4 didn't finish with MLFQS on\n" + if !defined (@mlfqs_on_stats); + die "p1-4 didn't finish with MLFQS off\n" + if !defined (@mlfqs_off_stats); +} + +sub mlfqs_stats { + my (@output) = @_; + my (%stats) = (CPU => {}, IO => {}, MIX => {}); + my (%map) = ("CPU intensive" => 'CPU', + "IO intensive" => 'IO', + "Alternating IO/CPU" => 'MIX'); + my (%rmap) = reverse %map; + my ($ticks); + local ($_); + foreach (@output) { + $ticks = $1 if /Timer: (\d+) ticks/; + my ($thread, $pri) = /^([A-Za-z\/ ]+): (\d+)$/ or next; + my ($t) = $map{$thread} or next; + + my ($s) = $stats{$t}; + $$s{N}++; + $$s{SUM} += $pri; + $$s{SUM2} += $pri * $pri; + $$s{MIN} = $pri if !defined ($$s{MIN}) || $pri < $$s{MIN}; + $$s{MAX} = $pri if !defined ($$s{MAX}) || $pri > $$s{MAX}; + } + + my (%expect_n) = (CPU => 5000, IO => 1000, MIX => 12000); + for my $cat (values (%map)) { + my ($s) = $stats{$cat}; + die "$rmap{$cat} printed $$s{N} times, not $expect_n{$cat}\n" + if $$s{N} != $expect_n{$cat}; + die "$rmap{$cat} priority dropped to $$s{MIN}, below PRI_MIN (0)\n" + if $$s{MIN} < 0; + die "$rmap{$cat} priority rose to $$s{MAX}, above PRI_MAX (59)\n" + if $$s{MAX} > 59; + $$s{MEAN} = $$s{SUM} / $$s{N}; + } + + return (\%stats, $ticks); +} + +sub verify_common { + my (@output) = @_; + + my (@assertion) = grep (/PANIC/, @output); + if (@assertion != 0) { + my ($details) = "Kernel panic:\n $assertion[0]\n"; + + my (@stack_line) = grep (/Call stack:/, @output); + if (@stack_line != 0) { + $details .= " $stack_line[0]\n\n"; + $details .= "Translation of backtrace:\n"; + my (@addrs) = $stack_line[0] =~ /Call stack:((?: 0x[0-9a-f]+)+)/; + + my ($A2L); + if (`uname -m` + =~ /i.86|pentium.*|[pk][56]|nexgen|viac3|6x86|athlon.*/) { + $A2L = "addr2line"; + } else { + $A2L = "i386-elf-addr2line"; + } + open (A2L, "$A2L -fe output/$test/kernel.o @addrs|"); + for (;;) { + my ($function, $line); + last unless defined ($function = ); + $line = ; + chomp $function; + chomp $line; + $details .= " $function ($line)\n"; + } + } + $extra{$test} = $details; + die "Kernel panic. Details at end of file.\n" + } + + die "No output at all\n" if @output == 0; + die "Didn't start up properly: no \"Pintos booting\" startup message\n" + if !grep (/Pintos booting with.*kB RAM\.\.\./, @output); + die "Didn't start up properly: no \"Boot complete\" startup message\n" + if !grep (/Boot complete/, @output); + die "Didn't shut down properly: no \"Timer: # ticks\" shutdown message\n" + if !grep (/Timer: \d+ ticks/, @output); + die "Didn't shut down properly: no \"Powering off\" shutdown message\n" + if !grep (/Powering off/, @output); +} + +sub compare_output { + my ($exp_file, @actual) = @_; + my (@expected) = snarf ($exp_file); + + @actual = map ("$_\n", @actual); + @expected = map ("$_\n", @expected); + + # Trim header and trailer from @actual. + while (scalar (@actual) && $actual[0] ne $expected[0]) { + shift (@actual); + } + die "First line of expected output was not present.\n" if !@actual; + while (scalar (@actual) && $actual[$#actual] ne $expected[$#expected]) { + pop (@actual); + } + die "Final line of expected output was not present.\n" if !@actual; + + # Check whether they're the same. + if ($#actual == $#expected) { + my ($eq) = 1; + for (my ($i) = 0; $i <= $#expected; $i++) { + $eq = 0 if $actual[$i] ne $expected[$i]; + } + return if $eq; + } + + # They differ. Output a diff. + my (@diff) = ""; + my ($d) = Algorithm::Diff->new (\@expected, \@actual); + while ($d->Next ()) { + my ($ef, $el, $af, $al) = $d->Get (qw (min1 max1 min2 max2)); + if ($d->Same ()) { + push (@diff, map (" $_", $d->Items (1))); + } else { + push (@diff, map ("- $_", $d->Items (1))) if $d->Items (1); + push (@diff, map ("+ $_", $d->Items (2))) if $d->Items (2); + } + } + + my ($details) = ""; + $details .= "$test actual output:\n"; + $details .= join ('', map (" $_", @actual)); + $details .= "\n$test expected output:\n"; + $details .= join ('', map (" $_", @expected)); + $details .= "\nOutput differences in `diff -u' format:\n"; + $details .= join ('', @diff) . "\n"; + $details{$test} = $details; + die "Output differs from expected. Details at end of file.\n"; +} + +sub write_grades { + my (@summary) = snarf ("$GRADES_DIR/tests.txt"); + + my ($ploss) = 0; + my ($tloss) = 0; + my ($total) = 0; + for (my ($i) = 0; $i <= $#summary; $i++) { + local ($_) = $summary[$i]; + if (my ($loss, $test) = /^ -(\d+) ([-a-zA-Z0-9]+):/) { + my ($result) = $result{$test} || "Not tested."; + + if ($result eq 'ok') { + splice (@summary, $i, 1); + $i--; + } else { + $ploss += $loss; + $tloss += $loss; + splice (@summary, $i + 1, 0, + map (" $_", split ("\n", $result))); + } + } elsif (my ($ptotal) = /^Score: \/(\d+)$/) { + $total += $ptotal; + $summary[$i] = "Score: " . ($ptotal - $ploss) . "/$ptotal"; + splice (@summary, $i, 0, " All tests passed.") if $ploss == 0; + $ploss = 0; + $i++; + } + } + my ($ts) = "(" . ($total - $tloss) . "/" . $total . ")"; + $summary[0] =~ s/\[\[total\]\]/$ts/; + + open (SUMMARY, ">tests.out"); + print SUMMARY map ("$_\n", @summary); + close (SUMMARY); +} + +sub write_details { + open (DETAILS, ">details.out"); + my ($n) = 0; + for my $test (@TESTS) { + next if $result{$test} eq 'ok'; + + my ($details) = $details{$test}; + next if !defined ($details) && ! -e "output/$test/run.out"; + + print DETAILS "\n" if $n++; + print DETAILS "--- $test details ", '-' x (50 - length ($test)); + print DETAILS "\n\n"; + + if (!defined $details) { + $details = "Output:\n\n" . snarf ("output/$test/run.out"); + } + print DETAILS $details; + + print DETAILS "\n", "-" x 10, "\n\n$extra{$test}" + if defined $extra{$test}; + } + close (DETAILS); + +} + +sub xsystem { + my ($command, %options) = @_; + print "$command\n" if $VERBOSE || $options{VERBOSE}; + + my ($log) = $options{LOG}; + if (defined ($log)) { + $command = "($command) >output/$log.out 2>output/$log.err"; + } + + my ($pid, $status); + eval { + local $SIG{ALRM} = sub { die "alarm\n" }; + alarm $options{TIMEOUT} if defined $options{TIMEOUT}; + $pid = fork; + die "fork: $!\n" if !defined $pid; + exec ($command), die "$command: exec: $!\n" if !$pid; + waitpid ($pid, 0); + $status = $?; + alarm 0; + }; + if ($@) { + die unless $@ eq "alarm\n"; # propagate unexpected errors + print "Timed out.\n"; + kill SIGTERM, $pid; + $status = 0; + } + + if (WIFSIGNALED ($status)) { + my ($signal) = WTERMSIG ($status); + die "Interrupted\n" if $signal == SIGINT; + print "Child terminated with signal $signal\n"; + } + + unlink ("output/$log.err") if defined ($log) && $status == 0; + + return $status == 0; +} + +sub snarf { + my ($file) = @_; + open (OUTPUT, $file) or die "$file: open: $!\n"; + my (@lines) = ; + chomp (@lines); + close (OUTPUT); + return wantarray ? @lines : join ('', map ("$_\n", @lines)); +} + +sub files_equal { + my ($a, $b) = @_; + my ($equal); + open (A, "<$a") or die "$a: open: $!\n"; + open (B, "<$b") or die "$b: open: $!\n"; + if (-s A != -s B) { + $equal = 0; + } else { + my ($sa, $sb); + for (;;) { + sysread (A, $sa, 1024); + sysread (B, $sb, 1024); + $equal = 0, last if $sa ne $sb; + $equal = 1, last if $sa eq ''; + } + } + close (A); + close (B); + return $equal; +} + +sub file_contains { + my ($file, $expected) = @_; + open (FILE, "<$file") or die "$file: open: $!\n"; + my ($actual); + sysread (FILE, $actual, -s FILE); + my ($equal) = $actual eq $expected; + close (FILE); + return $equal; +} + +sub number_lines { + my ($ln, $lines) = @_; + my ($out); + for my $line (@$lines) { + chomp $line; + $out .= sprintf "%4d %s\n", $ln++, $line; + } + return $out; +} diff --git a/grading/userprog/tests.txt b/grading/userprog/tests.txt new file mode 100644 index 0000000..794fad1 --- /dev/null +++ b/grading/userprog/tests.txt @@ -0,0 +1,96 @@ +CORRECTNESS [[total]] +--------------------- + +Argument passing + -5 args-argc: argc is not set correctly + -5 args-argv0: executable name not passed as argv[0] + -5 args-multiple: passing multiple arguments fails + -5 args-dblspace: using multiple spaces between arguments fails + +System calls: halt, exec + -1 halt: halt system call fails + -2 exit: exit system call malfunctions +Score: /3 + +System calls: create + -2 create-normal: create a file in the most normal way + -1 create-empty: pass empty string to create system call + -1 create-null: pass null pointer to create system call + -1 create-bad-ptr: pass invalid pointer to create system call + -1 create-long: pass long file name to create system call + -1 create-exists: pass name of an existing file to create system call +Score: /7 + +System calls: open + -2 open-normal: open a file in the most normal way + -2 open-missing: try to open a file that doesn't exist + -1 open-empty: pass empty string to open system call + -1 open-null: pass null pointer to open system call + -1 open-twice: open the same file twice +Score: /7 + +System calls: close + -2 close-normal: close an open file in the most normal way + -2 close-twice: try to close an open file twice + -1 close-stdin: try to close stdin + -1 close-stdout: try to close stdout + -1 close-bad-fd: try to close invalid file descriptor +Score: /7 + +System calls: read + -2 read-normal: read from open file in most normal way + -2 read-bad-ptr: pass invalid pointer to read system call + -1 read-zero: try to read zero bytes + -1 read-stdout: try to read from stdout + -1 read-bad-fd: try to read from invalid file descriptor +Score: /7 + +System calls: write + -2 write-normal: write to open file in most normal way + -2 write-bad-ptr: pass invalid pointer to write system call + -1 write-zero: try to write zero bytes + -1 write-stdin: try to write to stdin + -1 write-bad-fd: try to write to invalid file descriptor +Score: /7 + +System calls: exec + -2 exec-once: call exec/join once + -2 exec-multiple: call exec/join multiple times + -2 exec-missing: exec of nonexistent file must return -1 + -1 exec-bad-ptr: pass invalid pointer to exec system call +Score: /7 + +System calls: join + -2 join-simple: join must return proper value + -2 join-twice: join a subprocess two times + -2 join-killed: join must return -1 if subprocess killed by kernel + -1 join-bad-pid: join must return if passed bad pid +Score: /7 + +Multiprogramming + - + +3. Multiprogramming / Page boundary checking (/50 points) + Multiprogramming: Exec'ing two simple programs -30 + from another program doesn't work + Open/Create fails on page boundary -5 + Read/Write fails on page boundary -5 + Can close file opened by parent -5 + Running out of physical memory crashes OS -5 + Shell test doesn't work with normal page size -5 + Shell test doesn't work with smaller page size -5 + Exec/Join tests 0 and 1 fail when we substitute a new + bitmap.cc that returns pages in a random order. -5 + +----------- +Notes on the shell tests : + +Large page size echo/matmult test + -5 if nothing works no matter what you do + -4 if shell works in either case but matmult doesn't work in either case + +Small page size echo/matmult test + -5 if nothing works no matter what you do + -4 if shell works in either case but matmult doesn't work in either case +------------ + diff --git a/src/Makefile.userprog b/src/Makefile.userprog index e28a408..26d622d 100644 --- a/src/Makefile.userprog +++ b/src/Makefile.userprog @@ -1,3 +1,5 @@ +# -*- makefile -*- + include $(SRCDIR)/Make.config SHELL = /bin/sh @@ -49,7 +51,7 @@ libc.a: $(LIB_OBJ) ar r $@ $^ ranlib $@ -clean: +clean:: rm -f $(PROGS) $(PROGS_OBJ) $(PROGS_DEP) rm -f $(LIB_DEP) $(LIB_OBJ) lib/user/entry.[do] libc.a