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";
18 our (@TESTS); # Tests to run.
22 parse_cmd_line qw (pt-grow-stack pt-big-stk-obj pt-bad-addr pt-write-code
23 page-linear page-parallel page-merge-seq page-merge-par
24 page-shuffle mmap-read mmap-close mmap-unmap mmap-overlap
25 mmap-twice mmap-write mmap-exit mmap-shuffle);
27 clean_dir (), exit if $action eq 'clean';
30 exit if $action eq 'extract';
33 exit if $action eq 'build';
35 run_and_grade_tests ();
38 exit success () if $action eq 'test';
40 assemble_final_grade ();
41 exit success () if $action eq 'assemble';
43 die "Don't know how to '$action'";
45 # Runs $test in directory output/$test.
46 # Returns 'ok' if it went ok, otherwise an explanation.
48 # Set up output directory.
49 xsystem ("cp $GRADES_DIR/$test.dsk output/$test/fs.dsk",
50 DIE => "cp failed\n");
51 xsystem ("pintos make-disk output/$test/swap.dsk 2 >/dev/null 2>&1",
52 DIE => "failed to create swap disk");
55 return run_pintos (["--os-disk=pintos/src/vm/build/os.dsk",
56 "--fs-disk=output/$test/fs.dsk",
57 "--swap-disk=output/$test/swap.dsk",
58 "-v", "run", "-q", "-ex", "$test"],
63 sub grade_process_death {
64 my ($proc_name, @output) = @_;
66 verify_common (@output);
67 @output = get_core_output (@output);
68 die "First line of output is not `($proc_name) begin' message.\n"
69 if $output[0] ne "($proc_name) begin";
70 die "Output contains `FAIL' message.\n"
71 if grep (/FAIL/, @output);
72 die "Output contains spurious ($proc_name) message.\n"
73 if grep (/\($proc_name\)/, @output) > 1;
76 sub grade_pt_bad_addr {
77 grade_process_death ('pt-bad-addr', @_);
80 sub grade_pt_write_code {
81 grade_process_death ('pt-write-code', @_);
84 sub grade_mmap_unmap {
85 grade_process_death ('mmap-unmap', @_);