regression.in 6.99 KB
Newer Older
1 2
#!/usr/bin/perl -w
#
3
# Copyright (c) 2000-2010 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23 24 25 26 27 28 29 30 31
#
use strict;
use English;
use Getopt::Std;
use POSIX qw(setsid ceil);
use POSIX ":sys_wait_h";

sub usage ()
{
32
    print STDERR "Usage: $0 [-v] [-p] pid eid\n";
33 34 35 36
    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";
37
    print STDERR " -t     - Only compare vtop files\n";
38 39
    exit(1);
}
40
my $optlist    = "vpm:ns:t";
41
my $verbose    = 0;
42
my $prepass    = 0;
43 44
my $nodiff     = 0;
my $startwith  = 0;
45
my $toponly    = 0;
46
my $mfactor;
47 48 49 50 51 52 53 54
my $optarg     = "";

#
# Configure variables
#
my $TB		= "@prefix@";
my $TBOPS       = "@TBOPSEMAIL@";
my $MAPPER      = "$TB/bin/mapper";
55
my $COREMAPPER  = "/usr/testbed/devel/regression/bin/mapper";
56
my $WRAPPER     = "$TB/libexec/assign_wrapper";
57
my $DBNAME	= "@TBDBNAME@";
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

#
# 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($);
76
sub DoRegression($);
77 78 79 80 81 82 83 84 85

#
# Parse command arguments. Once we return from getopts, all that should be
# left are the required arguments.
#
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
86
if (@ARGV && @ARGV != 2) {
87 88 89 90 91 92
    usage();
}
if (defined($options{"v"})) {
    $verbose++;
    $optarg = "-v";
}
93 94 95
if (defined($options{"n"})) {
    $nodiff++;
}
96 97 98
if (defined($options{"t"})) {
    $toponly++;
}
99 100 101 102 103 104 105 106
if (defined($options{"p"})) {
    $prepass = 1;
    $optarg  = "$optarg -x";
}
if (defined($options{"m"})) {
    $mfactor = $options{"m"};
    $optarg  = "$optarg -m $mfactor";
}
107 108 109
if (defined($options{"s"})) {
    $startwith = $options{"s"};
}
110

111 112 113 114
if ($DBNAME eq "tbdb" && !$toponly) {
    fatal("Cannot use regression mode on main DB");
}

115 116 117 118 119
my $this_user = User->ThisUser();
if (! defined($this_user)) {
    tbdie("You ($UID) do not exist!");
}

120
my @builtintests = ( 
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
		     ["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"],
		     ["ShadowCfg",    "pplive-ct-zj"],
		     ["tbres",        "lt-meshtest"],
		     ["tbres",        "vnode-pairs"],
		     ["testbed",      "bigolesnake"],
		     ["testbed",      "firewall"],
		     ["testbed",      "fourswitch"],
		     ["tbres",        "mess"],
138
		     # Template 11361/46
139
		     ["tbres",        "T11361-46"], 
140
		     # Template 11953/3
141 142 143
		     ["tbres",        "T11953-3"],
		     # This takes a long time!
		     ["SkyNet",       "500nodebig"],
144 145 146 147
		   );

if (@ARGV) {
    @builtintests = ([$ARGV[0], $ARGV[1]]);
148
}
149 150 151 152

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

153 154 155 156
    if ($startwith > 0) {
	$startwith--;
	next;
    }
157 158 159 160 161 162 163 164 165
    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);
166
}
167 168 169 170 171 172 173 174
exit(0);

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

    my $pid = $experiment->pid();
    my $eid = $experiment->eid();
175 176
    my $args = "";
    my $cmd;
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

    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();
192 193 194 195 196 197 198 199 200 201
    print "  Running the old mapper ... \n";
    if ($toponly) {
	$args = "-n -t -d";
	$cmd  = $COREMAPPER;
    }
    else { 
	#$args = "-r -k -d -v";
	$args = "-r -d -v";
	$cmd  = $MAPPER;
    }
202
    system("cd Wrapper/$pid/$eid; ".
203
	   "$cmd $args $optarg $pid $eid > wrapper.log 2>&1");
204
    if ($?) {
205
	fatal("Old mapper failed");
206 207 208 209 210 211
    }
    my $howlong = time() - $now;
    print "    Done in $howlong seconds\n";
    
    $now = time();
    print "  Running the mapper ... \n";
212 213
    #$args = ($toponly ? "-n -t -d" : "-r -z -d -v");
    $args = ($toponly ? "-n -t -d" : "-r -d -v ");
214
    system("cd Mapper/$pid/$eid; ".
215
	   "$COREMAPPER $args $optarg $pid $eid > mapper.log 2>&1");
216 217 218 219 220 221
    if ($?) {
	fatal("Mapper failed");
    }
    $howlong = time() - $now;
    print "    Done in $howlong seconds\n";

222 223
    if (! $nodiff) {
	print "  Diffing the results ...\n";
224 225 226 227 228 229 230 231 232 233
	if ($toponly) {
	    system("diff -r -q -b Mapper/$pid/$eid/$pid-$eid.vtop ".
		   "              Wrapper/$pid/$eid/$pid-$eid.vtop") == 0
		   or fatal("Results differed!");
	}
	else {
	    system("diff -r -q Mapper/$pid/$eid/$pid-$eid.pstate ".
		   "           Wrapper/$pid/$eid/$pid-$eid.pstate") == 0
		   or fatal("Results differed!");
	}
234
    }
235 236
    return 0
	if (1 || $toponly);
237

238 239 240 241 242 243 244 245
    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; ".
246
	   "$COREMAPPER -r -k $optarg $pid $eid > mapper.log 2>&1");
247 248 249 250 251 252 253
    if ($?) {
	fatal("Mapper failed");
    }
    $howlong = time() - $now;
    print "    Done in $howlong seconds\n";
    
    $now = time();
254
    print "  Running the old mapper ... \n";
255
    system("cd Wrapper/$pid/$eid; ".
256
	   "$MAPPER -r -z $optarg $pid $eid > wrapper.log 2>&1");
257 258 259 260 261 262
    if ($?) {
	fatal("Wrapper failed");
    }
    $howlong = time() - $now;
    print "    Done in $howlong seconds\n";

263 264 265 266 267 268
    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!");
    }
269
    return 0;
270 271 272 273 274 275 276 277
}

exit(0);

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