c04faea87af0753035e93351e8fc0dd6681de766
[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 ();
23
24 # Default set of tests.
25 @TESTS = qw (pt-grow-stack pt-big-stk-obj pt-bad-addr pt-write-code
26              page-linear page-parallel page-merge-seq page-merge-par
27              page-shuffle mmap-read mmap-close mmap-unmap mmap-overlap
28              mmap-twice mmap-write mmap-exit mmap-shuffle
29             ) unless @TESTS > 0;
30
31 clean_dir (), exit if $action eq 'clean';
32
33 extract_sources (); 
34 exit if $action eq 'extract';
35
36 build (); 
37 exit if $action eq 'build';
38
39 run_and_grade_tests (); 
40 write_grades (); 
41 write_details ();
42 exit if $action eq 'test';
43
44 assemble_final_grade ();
45 exit if $action eq 'assemble';
46
47 die "Don't know how to '$action'";
48
49 # Runs $test in directory output/$test.
50 # Returns 'ok' if it went ok, otherwise an explanation.
51 sub run_test {
52     # Set up output directory.
53     xsystem ("cp $GRADES_DIR/$test.dsk output/$test/fs.dsk",
54              DIE => "cp failed\n");
55     xsystem ("pintos make-disk output/$test/swap.dsk 2 >/dev/null 2>&1",
56              DIE => "failed to create swap disk");
57
58     # Run.
59     return run_pintos ("pintos "
60                        . "--os-disk=pintos/src/vm/build/os.dsk "
61                        . "--fs-disk=output/$test/fs.dsk "
62                        . "--swap-disk=output/$test/swap.dsk "
63                        . "-v run -q -ex \"$test\"",
64                        LOG => "$test/run",
65                        TIMEOUT => 600);
66 }
67 \f
68 sub grade_process_death {
69     my ($proc_name, @output) = @_;
70
71     verify_common (@output);
72     @output = get_core_output (@output);
73     die "First line of output is not `($proc_name) begin' message.\n"
74         if $output[0] ne "($proc_name) begin";
75     die "Output contains `FAIL' message.\n"
76         if grep (/FAIL/, @output);
77     die "Output contains spurious ($proc_name) message.\n"
78         if grep (/\($proc_name\)/, @output) > 1;
79 }
80
81 sub grade_pt_bad_addr {
82     grade_process_death ('pt-bad-addr', @_);
83 }
84
85 sub grade_pt_write_code {
86     grade_process_death ('pt-write-code', @_);
87 }
88
89 sub grade_mmap_unmap {
90     grade_process_death ('mmap-unmap', @_);
91 }