Add more tests.
[pintos-anon] / grading / userprog / prep-disk
1 #! /usr/bin/perl -w
2
3 use strict;
4 use Getopt::Long;
5
6 my ($pintos) = "pintos";
7 my ($os_disk) = "../../src/userprog/build/os.dsk";
8 my ($fs_disk);
9 my ($test);
10
11 GetOptions ("os-disk=s" => \$os_disk,
12             "fs-disk=s" => \$fs_disk,
13             "test=s" => \$test,
14             "help" => sub { usage (0) })
15     or die "option parsing failed; use --help for help\n";
16
17 if (!defined ($test)) {
18     die "test name expected; use --help for help\n"
19         if @ARGV != 1;
20     $test = shift @ARGV;
21 } elsif (@ARGV != 0) {
22     die "can't have non-option arg with --test\n";
23 }
24
25 $fs_disk = "$test.dsk" if !defined $fs_disk;
26
27 if (! -e $os_disk) {
28     print STDERR "$os_disk: stat: $!\n";
29     print STDERR "perhaps you should `make' in ../../src/userprog?\n";
30     exit 1;
31 }
32
33 our ($formatted) = 0;
34
35 unlink $fs_disk;
36 xsystem ("$pintos make-disk '$fs_disk' 2");
37 put_file ("$test");
38 put_file ("sample.txt")
39     if grep ($_ eq $test,
40              qw (open-normal open-boundary open-twice
41                  close-normal close-twice
42                  read-normal read-bad-ptr read-boundary read-zero
43                  write-normal write-boundary write-zero));               
44
45 sub put_file {
46     my ($fn) = @_;
47     my ($cmd) = "$pintos -v --os-disk='$os_disk' --fs-disk='$fs_disk' put";
48     $cmd .= " -f", $formatted = 1 if !$formatted;
49     $cmd .= " '$fn'";
50     xsystem ($cmd);
51 }
52
53 sub xsystem {
54     my ($cmd) = @_;
55     print "$cmd\n";
56     system ($cmd) == 0 || die "command failed\n";
57 }