tbts 5.17 KB
Newer Older
1
#!/usr/bin/perl
2 3 4 5 6 7 8 9 10 11
BEGIN {
  #add localcpan path to library search path
  if (-f glob("~/lib/perl5/Test/Harness.pm")) {
    my $localcpan_path = glob('~/lib/perl5');
    my $p5l = $ENV{PERL5LIB};
    unless ( (defined $p5l) && ($p5l =~ /$localcpan_path/)) {
      my $sep = (defined $p5l) ? ":" : "";
      $ENV { PERL5LIB} .= "$sep" . " $localcpan_path";
      push @INC, $localcpan_path;
    }
12
    push @INC, $localcpan_path;
13
  }
14
  $ENV{PERL5LIB} .= ":tests";
15
}
Kevin Tew's avatar
Kevin Tew committed
16

17 18
use lib qw(lib tests);
use SemiModern::Perl;
Kevin Tew's avatar
Kevin Tew committed
19

Kevin Tew's avatar
Kevin Tew committed
20
use Data::Dumper;
21
use TBConfig;
22
use TestBed::Daemonize;
Kevin Tew's avatar
Kevin Tew committed
23

24 25
my $emailme;
my $daemonize;
Kevin Tew's avatar
Kevin Tew committed
26 27
{
  use Getopt::Long;
28
  my $debug;
29 30
  my $project;
  my $group;
Kevin Tew's avatar
Kevin Tew committed
31
  my $xmlrpcurl;
32 33

  my $cmdline_defines;
Kevin Tew's avatar
Kevin Tew committed
34 35
  my $concurrent_prerun_jobs;
  my $concurrent_node_usage;
Kevin Tew's avatar
Kevin Tew committed
36
  my $exclude_steps;
37
  my $runonly;
38 39 40
  my $dontkill;
  my $alreadyalive;
  my $daemonize;
Kevin Tew's avatar
Kevin Tew committed
41
  my $result = GetOptions (
42 43 44 45 46 47 48 49
      "d|debug"        => \$debug,
      "define=s%"      => \$cmdline_defines,
      "project=s"      => \$project,
      "xmlrpcurl=s"    => \$xmlrpcurl,
      "group=s"        => \$group,
      "cprj=i"         => \$concurrent_prerun_jobs,
      "cnu=i"          => \$concurrent_node_usage,
      "excludesteps=s" => \$exclude_steps,
50
      "runonly=s"       => \$runonly,
51 52 53
      "dontkill"       => \$dontkill,
      "alreadyalive"   => \$alreadyalive,
      "daemonize"      => \$daemonize,
54
      "emailme=s"      => \$emailme,
Kevin Tew's avatar
Kevin Tew committed
55
    );
Kevin Tew's avatar
Kevin Tew committed
56

57 58 59 60
  if ($debug)     { $ENV { 'TBTS_DEBUG'      } = 1          ; $TBConfig::DEBUG_XML_CLIENT = 1       ; }
  if ($group)     { $ENV { 'TBTS_GROUP'      } = $group     ; $TBConfig::DEFAULT_GID = $group       ; }
  if ($project)   { $ENV { 'TBTS_PROJECT'    } = $project   ; $TBConfig::DEFAULT_PID = $project     ; }
  if ($xmlrpcurl) { $ENV { 'TBTS_XMLRPC_URL' } = $xmlrpcurl ; $TBConfig::XMLRPC_SERVER = $xmlrpcurl ; }
61
  if ($concurrent_prerun_jobs) { $TBConfig::concurrent_prerun_jobs = $concurrent_prerun_jobs; }
62 63 64
  if ($concurrent_node_usage)  { $TBConfig::concurrent_node_usage = $concurrent_node_usage; }
  if ($cmdline_defines)        { $TBConfig::cmdline_defines = $cmdline_defines; }
  if ($exclude_steps)          { $TBConfig::exclude_steps = [split(/ /, $exclude_steps)]; }
65
  if ($runonly)                { $TBConfig::runonly = [split(/ /, $runonly)]; }
66 67
  if ($dontkill)               { $TBConfig::exclude_steps = [qw/swapout end/]}
  if ($alreadyalive)           { $TBConfig::exclude_steps = [qw/create swapin swapout end/]}
68
  if ($daemonize or $emailme)  { TestBed::Daemonize::daemonize; }
Kevin Tew's avatar
Kevin Tew committed
69
}
70

Kevin Tew's avatar
Kevin Tew committed
71 72 73 74
sub find_rx_in_dir {
  my ($rx, $dir) = @_;
  my @results;
  my $scandir = sub { if (-f && m/$rx/)  { push @results,   $File::Find::name; } };
75
  use File::Find;
Kevin Tew's avatar
Kevin Tew committed
76 77 78 79 80 81 82 83 84 85 86 87
  find($scandir, $dir);
  @results;
}

sub all_ts { find_rx_in_dir(qr{\.t$}, 't'); }
sub all_tpms { find_rx_in_dir(qr{\.pm$}, 'tests'); }

sub usage {
  my $ts_text;
  my $tpms_text;
  for (all_ts) { $ts_text     .= "        " . $_ . "\n"; }
  for (all_tpms) { $tpms_text .= "        " . $_ . "\n"; }
88
  print <<"USAGE";
89 90 91
TestBed TestSwap
./tbts OPTIONS TESTSUITE|TESTFILE
        -d --debug
92 93
        -g --group=GROUPNAME
        -p --project=PROJECTNAME
Kevin Tew's avatar
Kevin Tew committed
94
        -x --xmlrpcurl=XMLRPCURL
Kevin Tew's avatar
Kevin Tew committed
95 96 97
        --define OS=FBSD410-UPDATE
        --cprj=4  => \$concurrent_prerun_jobs,
        --cnu=20  => \$concurrent_node_usage,
98
        --dontkill => --excludesteps "swapout end"
Kevin Tew's avatar
Kevin Tew committed
99
        --alreadyalive => --excludesteps "create swapin swapout end"
100 101
        --excludesteps "swapout end"
        --excludesteps "create swapin swapout end"
102
        --runonly "testname1 testname2 testname3"
103
        --daemonize
104 105
        --emailme user\@emulab.net
        
106 107

    TESTSUITES:
Kevin Tew's avatar
Kevin Tew committed
108
        massive  - all experiment tests
Kevin Tew's avatar
Kevin Tew committed
109
        all      - all framework tests
110 111 112 113
        sanity   - all framework utility and xmlrpc client modules test
        lib      - all framework utility tests
        xmlrpc   - all xmlrpc client modules tests
        critic   - runs perl critic on framework code
114

115
    TESTFILES:
116
USAGE
Kevin Tew's avatar
Kevin Tew committed
117 118 119 120 121 122 123
  print $ts_text;
  print $tpms_text;
}

sub array_single_difference {
  my ($src, $minus) = @_;
  grep { my $s = $_; !(grep { $s eq $_ } @$minus) } @$src;
124
}
125

126
use TestBed::Harness;
127
if (@ARGV) {
Kevin Tew's avatar
Kevin Tew committed
128 129 130
  my @xmlrpc = qw(t/xmlrpc/*.t);
  my @lib = qw(t/lib/*.t t/lib/*/*.t t/tbts/cmdlineargs.t);
  my @sanity = (@lib, @xmlrpc);
Kevin Tew's avatar
Kevin Tew committed
131 132 133
  my @all = sort(array_single_difference([all_ts], [qw(t/coding/pod_coverage.t t/noautorun/tbts_cmdlineargs.t t/eine/elab_in_elab.t)]));
  my @massive = (all_tpms);

Kevin Tew's avatar
Kevin Tew committed
134
  my $cmd = $ARGV[0];
135
  $_   = $cmd;
136
  chomp $_;
137
  if (/.*\.t$/ || /.*\.pm$/) { runharness(@ARGV); }
138 139 140
  elsif ($_ eq 'podc')      { system 'for x in `find lib -iname "*.pm"`; do podchecker $x 2>&1 |grep contain; done; '; }
  elsif ($_ eq 'pode')      { system 'for x in `find lib -iname "*.pm"`; do podchecker $x 2>&1 |grep ERROR; done;'; }
  elsif (/critic/)          { exec 'perlcritic lib t'; }
Kevin Tew's avatar
Kevin Tew committed
141
  elsif (/massive/)         { runharness( @massive ); }
Kevin Tew's avatar
Kevin Tew committed
142 143 144 145
  elsif (/all/)             { runharness( @all ); }
  elsif (/sanity/)          { runharness( @sanity ); }
  elsif (/lib/)             { runharness( @lib ); }
  elsif (/xmlrpc/)          { runharness( @xmlrpc ); }
Kevin Tew's avatar
Kevin Tew committed
146
  elsif (/podcov/)          { exec './tbts t/coding/pod_coverage.t 2>&1 | perl devtools/podfailure.pl'; }
147 148
}
else {
149
  usage();
150 151
}

152
TestBed::Daemonize::email_daemonize_logs($emailme) if $emailme;