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 # Default set of tests.
42 @TESTS = unless @TESTS > 0;
44 clean_dir (), exit if $action eq 'clean';
47 exit if $action eq 'extract';
50 exit if $action eq 'build';
52 run_and_grade_tests ();
55 exit if $action eq 'test';
57 assemble_final_grade ();
58 exit if $action eq 'assemble';
60 die "Don't know how to '$action'";
62 # Runs $test in directory output/$test.
63 # Returns 'ok' if it went ok, otherwise an explanation.
65 xsystem ("cp $GRADES_DIR/$test.dsk output/$test/fs.dsk",
66 DIE => "cp failed\n");
69 $args = 'some arguments for you!'
70 if grep ($_ eq $test, qw(args-argc args-argv0
71 args-argvn args-multiple));
72 $args = 'onearg' if $test eq 'args-single';
73 $args = 'two args' if $test eq 'args-dbl-space';
74 $args = '15' if $test eq 'multi-recurse';
75 $args = '0' if $test eq 'multi-oom';
76 $args = " $args" if $args ne '';
79 my ($timeout) = $test !~ /^multi-/ ? 10 : 600;
80 my ($result) = run_pintos ("pintos "
81 . "--os-disk=pintos/src/userprog/build/os.dsk "
82 . "--fs-disk=output/$test/fs.dsk "
83 . "-v run -q -ex \"$test$args\"",
86 rename "output/$test/fs.dsk", "output/$test/fs.dsk.keep"
87 if $test eq 'write-normal';
91 sub grade_write_normal {
93 verify_common (@output);
94 compare_output ("$GRADES_DIR/write-normal.exp", @output);
95 my ($test_txt) = "output/$test/test.txt";
96 get_file ("test.txt", $test_txt) if ! -e $test_txt;
98 my (@actual) = snarf ($test_txt);
99 my (@expected) = snarf ("$GRADES_DIR/sample.txt");
102 if ($#actual == $#expected) {
104 for my $i (0...$#actual) {
105 $eq = 0 if $actual[$i] ne $expected[$i];
112 $details = "Expected file content:\n";
113 $details .= join ('', map (" $_\n", @expected));
114 $details .= "Actual file content:\n";
115 $details .= join ('', map (" $_\n", @actual));
116 $extra{$test} = $details;
118 die "File written didn't have expected content.\n";
122 sub grade_multi_oom {
124 verify_common (@output);
126 @output = canonicalize_exit_codes (get_core_output (@output));
128 while (my ($m) = $output[0] =~ /^\(multi-oom\) begin (\d+)$/) {
129 die "Child process $m started out of order.\n" if $m != $n;
133 die "Only $n child process(es) started.\n" if $n < 15;
135 # There could be a death notice for a process that didn't get
136 # fully loaded, and/or notices from the loader.
138 && ($output[0] =~ /^multi-oom: exit\(-1\)$/
139 || $output[0] =~ /^load: /)) {
144 die "Output ended unexpectedly before process $n finished.\n"
148 chomp ($_ = shift @output);
149 die "Found '$_' expecting 'end' message.\n" if !/^\(multi-oom\) end/;
150 die "Child process $n ended out of order.\n"
151 if !/^\(multi-oom\) end $n$/;
153 chomp ($_ = shift @output);
154 die "Kernel didn't print proper exit message for process $n.\n"
155 if !/^multi-oom: exit\($n\)$/;
157 die "Spurious output at end: '$output[0]'.\n" if @output;
161 my ($guest_fn, $host_fn) = @_;
162 my ($result) = run_pintos ("pintos "
163 . "--os-disk=pintos/src/userprog/build/os.dsk "
164 . "--fs-disk=output/$test/fs.dsk.keep "
165 . "-v get $guest_fn $host_fn",
166 LOG => "$test/get-$guest_fn",
169 die "`pintos get $guest_fn' failed - $result\n"