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-bad-ptr write-boundary write-zero
44                  multi-child-fd));
45 put_file ("child-simple") if $test eq 'exec-once' or $test eq 'exec-multiple';
46 put_file ("child-arg") if $test eq 'exec-arg';
47 put_file ("child-close") if $test eq 'multi-child-fd';
48
49 sub put_file {
50     my ($fn) = @_;
51     my ($cmd) = "$pintos -v --os-disk='$os_disk' --fs-disk='$fs_disk' put";
52     $cmd .= " -f", $formatted = 1 if !$formatted;
53     $cmd .= " '$fn'";
54     xsystem ($cmd);
55 }
56
57 sub xsystem {
58     my ($cmd) = @_;
59     print "$cmd\n";
60     system ($cmd) == 0 || die "command failed\n";
61 }