regression.in 5.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# All rights reserved.
#
use strict;
use English;
use Getopt::Std;
use POSIX qw(setsid ceil);
use POSIX ":sys_wait_h";

sub usage ()
{
15
    print STDERR "Usage: $0 [-v] [-p] pid eid\n";
16 17 18 19
    print STDERR " -v     - Enables verbose output\n";
    print STDERR " -n     - Skip the diffs\n";
    print STDERR " -p     - Turn on assign prepass\n";
    print STDERR " -m <N> - Set the multiplex factor for the prepass\n";
20 21
    exit(1);
}
22
my $optlist    = "vpm:ns:";
23
my $verbose    = 0;
24
my $prepass    = 0;
25 26
my $nodiff     = 0;
my $startwith  = 0;
27
my $mfactor;
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
my $optarg     = "";

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $MAPPER      = "$TB/bin/mapper";
my $WRAPPER     = "$TB/libexec/assign_wrapper";

#
# Load the Testbed support stuff. 
#
use lib "@prefix@/lib";
use libdb;
use libtestbed;
use User;

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

# Turn off line buffering on output
$| = 1;

# Protos
sub fatal($);
55
sub DoRegression($);
56 57 58 59 60 61 62 63 64

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
65
if (@ARGV && @ARGV != 2) {
66 67 68 69 70 71
    usage();
}
if (defined($options{"v"})) {
    $verbose++;
    $optarg = "-v";
}
72 73 74
if (defined($options{"n"})) {
    $nodiff++;
}
75 76 77 78 79 80 81 82
if (defined($options{"p"})) {
    $prepass = 1;
    $optarg  = "$optarg -x";
}
if (defined($options{"m"})) {
    $mfactor = $options{"m"};
    $optarg  = "$optarg -m $mfactor";
}
83 84 85
if (defined($options{"s"})) {
    $startwith = $options{"s"};
}
86

87 88 89 90 91
my $this_user = User->ThisUser();
if (! defined($this_user)) {
    tbdie("You ($UID) do not exist!");
}

92
my @builtintests = ( 
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
		     ["testbed",      "two-simple"],
		     ["testbed",      "lan-link-delay"],
		     ["testbed",      "lan-link-tbdelay"],
		     ["testbed",      "jail-linklan-delay"],
		     ["testbed",      "jail-delayed-router"],
		     ["testbed",      "jail-lan-NN"],
		     ["testbed",      "myelab"],
		     ["emulab-ops",   "virt-mesh"],
		     ["SkyNet",       "100nodebig"],
		     ["puproj",       "CRAQ-LAN"],
		     ["DDoS-Defense", "streamPuzzles2"],
		     ["ShadowCfg",    "pplive-ct-zj"],
		     ["tbres",        "lt-meshtest"],
		     ["tbres",        "vnode-pairs"],
		     ["testbed",      "bigolesnake"],
		     ["testbed",      "firewall"],
		     ["testbed",      "fourswitch"],
		     ["testbed",      "planetlab2"], 
		     ["tbres",        "mess"],
		     ["tbres",        "pelab-bt-fake"],
113
		     # Template 11361/46
114
		     ["tbres",        "T11361-46"], 
115
		     # Template 11953/3
116 117 118
		     ["tbres",        "T11953-3"],
		     # This takes a long time!
		     ["SkyNet",       "500nodebig"],
119 120 121 122
		   );

if (@ARGV) {
    @builtintests = ([$ARGV[0], $ARGV[1]]);
123
}
124 125 126 127

foreach my $ref (@builtintests) {
    my ($pid, $eid) = @{$ref};

128 129 130 131
    if ($startwith > 0) {
	$startwith--;
	next;
    }
132 133 134 135 136 137 138 139 140
    my $experiment = Experiment->Lookup($pid, $eid);
    if (!defined($experiment)) {
	fatal("Could not lookup experiment object $pid,$eid!");
    }
    if (!TBAdmin() &&
	! $experiment->AccessCheck($this_user, TB_EXPT_DESTROY)) {
	fatal("You do not have permission to map this experiment!");
    }
    DoRegression($experiment);
141
}
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
exit(0);

sub DoRegression($)
{
    my ($experiment) = @_;

    my $pid = $experiment->pid();
    my $eid = $experiment->eid();

    print "Doing a regression test on $pid,$eid\n";
    
    if (! -e "Mapper/$pid/$eid") {
	system("mkdir -p Mapper/$pid/$eid") == 0
	    or fatal("Could not mkdir Mapper/$pid/$eid");
    }
    if (! -e "Wrapper/$pid/$eid") {
	system("mkdir -p Wrapper/$pid/$eid") == 0
	    or fatal("Could not mkdir Wrapper/$pid/$eid");
    }
    system("/bin/rm -rf Mapper/$pid/$eid/* Wrapper/$pid/$eid/*") == 0
	or fatal("Could not clean directories");

    my $now = time();
    print "  Running the wrapper ... \n";
    system("cd Wrapper/$pid/$eid; ".
167
	   "$WRAPPER -r -k $optarg $pid $eid > wrapper.log 2>&1");
168 169 170 171 172 173 174 175 176
    if ($?) {
	fatal("Wrapper failed");
    }
    my $howlong = time() - $now;
    print "    Done in $howlong seconds\n";
    
    $now = time();
    print "  Running the mapper ... \n";
    system("cd Mapper/$pid/$eid; ".
177
	   "$MAPPER -r -z $optarg $pid $eid > mapper.log 2>&1");
178 179 180 181 182 183
    if ($?) {
	fatal("Mapper failed");
    }
    $howlong = time() - $now;
    print "    Done in $howlong seconds\n";

184 185 186 187 188 189
    if (! $nodiff) {
	print "  Diffing the results ...\n";
	system("diff -r -q Mapper/$pid/$eid/$pid-$eid.pstate ".
	       "           Wrapper/$pid/$eid/$pid-$eid.pstate") == 0
	       or fatal("Results differed!");
    }
190

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    print " Running in reverse mode ...\n";

    system("/bin/rm -rf Mapper/$pid/$eid/* Wrapper/$pid/$eid/*") == 0
	or fatal("Could not clean directories");

    $now = time();
    print "  Running the mapper ... \n";
    system("cd Mapper/$pid/$eid; ".
	   "$MAPPER -r -k $optarg $pid $eid > mapper.log 2>&1");
    if ($?) {
	fatal("Mapper failed");
    }
    $howlong = time() - $now;
    print "    Done in $howlong seconds\n";
    
    $now = time();
    print "  Running the wrapper ... \n";
    system("cd Wrapper/$pid/$eid; ".
	   "$WRAPPER -r -z $optarg $pid $eid > wrapper.log 2>&1");
    if ($?) {
	fatal("Wrapper failed");
    }
    $howlong = time() - $now;
    print "    Done in $howlong seconds\n";

216 217 218 219 220 221
    if (! $nodiff) {
	print "  Diffing the results ...\n";
	system("diff -r -q Mapper/$pid/$eid/$pid-$eid.pstate ".
	       "           Wrapper/$pid/$eid/$pid-$eid.pstate") == 0
	       or fatal("Results differed!");
    }
222
    return 0;
223 224 225 226 227 228 229 230
}

exit(0);

sub fatal($)
{
    die("$_[0]\n");
}