fea0bfb9ccf12500642b0bc10cf888d12c6d2a47
[pintos-anon] / grading / vm / run-tests
1 #! /usr/bin/perl
2
3 # Find the directory that contains the grading files.
4 our ($GRADES_DIR);
5
6 # Add our Perl library directory to the include path. 
7 BEGIN {
8     ($GRADES_DIR = $0) =~ s#/[^/]+$##;
9     -d $GRADES_DIR or die "$GRADES_DIR: stat: $!\n";
10     unshift @INC, "$GRADES_DIR/../lib";
11 }
12
13 use warnings;
14 use strict;
15 use Pintos::Grading;
16
17 our ($hw) = "vm";
18 our (@TESTS);           # Tests to run.
19 our ($test);
20 our ($action);
21
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);
26
27 clean_dir (), exit if $action eq 'clean';
28
29 extract_sources (); 
30 exit if $action eq 'extract';
31
32 build (); 
33 exit if $action eq 'build';
34
35 run_and_grade_tests (); 
36 write_grades (); 
37 write_details ();
38 exit success () if $action eq 'test';
39
40 assemble_final_grade ();
41 exit success () if $action eq 'assemble';
42
43 die "Don't know how to '$action'";
44
45 # Runs $test in directory output/$test.
46 # Returns 'ok' if it went ok, otherwise an explanation.
47 sub run_test {
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");
53
54     # Run.
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"],
59                        LOG => "$test/run",
60                        TIMEOUT => 600);
61 }
62 \f
63 sub grade_process_death {
64     my ($proc_name, @output) = @_;
65
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;
74 }
75
76 sub grade_pt_bad_addr {
77     grade_process_death ('pt-bad-addr', @_);
78 }
79
80 sub grade_pt_write_code {
81     grade_process_death ('pt-write-code', @_);
82 }
83
84 sub grade_mmap_unmap {
85     grade_process_death ('mmap-unmap', @_);
86 }