3 # Find the directory that contains the grading files.
6 # Add our Perl library directory to the include path.
8 ($GRADES_DIR = $0) =~ s#/[^/]+$##;
9 -d $GRADES_DIR or die "$GRADES_DIR: stat: $!\n";
10 unshift @INC, "$GRADES_DIR/../lib";
17 our ($hw) = "userprog";
18 our (@TESTS); # Tests to run.
23 parse_cmd_line qw (args-argc args-argv0 args-argvn args-single args-multiple
25 sc-bad-sp sc-bad-arg sc-boundary
27 create-normal create-empty create-null create-bad-ptr
28 create-long create-exists create-bound
29 open-normal open-missing open-boundary open-empty open-null
30 open-bad-ptr open-twice
31 close-normal close-twice close-stdin close-stdout
33 read-normal read-bad-ptr read-boundary read-zero read-stdout
35 write-normal write-bad-ptr write-boundary write-zero
36 write-stdin write-bad-fd
37 exec-once exec-arg exec-multiple exec-missing exec-bad-ptr
38 join-simple join-twice join-killed join-bad-pid
39 multi-recurse multi-oom multi-child-fd);
41 clean_dir (), exit if $action eq 'clean';
44 exit if $action eq 'extract';
47 exit if $action eq 'build';
49 run_and_grade_tests ();
52 exit if $action eq 'test';
54 assemble_final_grade ();
55 exit if $action eq 'assemble';
57 die "Don't know how to '$action'";
59 # Runs $test in directory output/$test.
60 # Returns 'ok' if it went ok, otherwise an explanation.
62 xsystem ("cp $GRADES_DIR/$test.dsk output/$test/fs.dsk",
63 DIE => "cp failed\n");
66 $args = 'some arguments for you!'
67 if grep ($_ eq $test, qw(args-argc args-argv0
68 args-argvn args-multiple));
69 $args = 'onearg' if $test eq 'args-single';
70 $args = 'two args' if $test eq 'args-dbl-space';
71 $args = '15' if $test eq 'multi-recurse';
72 $args = '0' if $test eq 'multi-oom';
73 $args = " $args" if $args ne '';
76 my ($timeout) = $test !~ /^multi-/ ? 10 : 600;
77 my ($result) = run_pintos ("pintos "
78 . "--os-disk=pintos/src/userprog/build/os.dsk "
79 . "--fs-disk=output/$test/fs.dsk "
80 . "-v run -q -ex \"$test$args\"",
83 rename "output/$test/fs.dsk", "output/$test/fs.dsk.keep"
84 if $test eq 'write-normal';
88 sub grade_write_normal {
90 verify_common (@output);
91 compare_output ("$GRADES_DIR/write-normal.exp", @output);
92 my ($test_txt) = "output/$test/test.txt";
93 get_file ("test.txt", $test_txt) if ! -e $test_txt;
95 my (@actual) = snarf ($test_txt);
96 my (@expected) = snarf ("$GRADES_DIR/sample.txt");
99 if ($#actual == $#expected) {
101 for my $i (0...$#actual) {
102 $eq = 0 if $actual[$i] ne $expected[$i];
109 $details = "Expected file content:\n";
110 $details .= join ('', map (" $_\n", @expected));
111 $details .= "Actual file content:\n";
112 $details .= join ('', map (" $_\n", @actual));
113 $extra{$test} = $details;
115 die "File written didn't have expected content.\n";
119 sub grade_multi_oom {
121 verify_common (@output);
123 @output = canonicalize_exit_codes (get_core_output (@output));
125 while (my ($m) = $output[0] =~ /^\(multi-oom\) begin (\d+)$/) {
126 die "Child process $m started out of order.\n" if $m != $n;
130 die "Only $n child process(es) started.\n" if $n < 15;
132 # There could be a death notice for a process that didn't get
133 # fully loaded, and/or notices from the loader.
135 && ($output[0] =~ /^multi-oom: exit\(-1\)$/
136 || $output[0] =~ /^load: /)) {
141 die "Output ended unexpectedly before process $n finished.\n"
145 chomp ($_ = shift @output);
146 die "Found '$_' expecting 'end' message.\n" if !/^\(multi-oom\) end/;
147 die "Child process $n ended out of order.\n"
148 if !/^\(multi-oom\) end $n$/;
150 chomp ($_ = shift @output);
151 die "Kernel didn't print proper exit message for process $n.\n"
152 if !/^multi-oom: exit\($n\)$/;
154 die "Spurious output at end: '$output[0]'.\n" if @output;
158 my ($guest_fn, $host_fn) = @_;
159 my ($result) = run_pintos ("pintos "
160 . "--os-disk=pintos/src/userprog/build/os.dsk "
161 . "--fs-disk=output/$test/fs.dsk.keep "
162 . "-v get $guest_fn $host_fn",
163 LOG => "$test/get-$guest_fn",
166 die "`pintos get $guest_fn' failed - $result\n"