run_linktest.pl.in 2.13 KB
Newer Older
1
#!/usr/bin/perl -w -T
2 3 4 5 6 7 8
#
# wrapper for running linktest that includes
# an extra event for reporting completion.

use strict;
use Getopt::Std;

9 10 11
# security
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';

12
sub usage {
13 14 15 16
    my $msg = "Usage: run_linktest.pl [-s server] [-p port] [-k keyfile] -e pid/eid [-q]\n";
    $msg .= "\t-q\tquick termination mode\n";
    $msg .= "\t-d n\tdebug level n (development only)\n";
    warn $msg;
17 18 19
    return 1;
}

20 21 22 23 24 25
# signal handler in case the process is killed.
$SIG{INT} = sub {
    print "Aborted. Linktest continues on nodes.\n";
    exit(1);
};

26
my $server;
27
my $port;
28
my %opt = ();
29
getopts("s:e:d:qp:k:",\%opt);
30
if ($opt{s}) { $server = $opt{s}; } else { $server = "boss"; }
31
if ($opt{p}) { $port = $opt{p}; }
32 33 34 35 36 37 38
exit &usage unless ($opt{e});
my ($pid,$eid) = split(/\//,$opt{e});

my $linktest_path; # path to linktest data.
$linktest_path = "/proj/" . $pid . "/exp/" . $eid . "/tbdata/linktest";

# send the startup event.
39 40 41
my $args = &starter;
# event arguments
$args .=  " -x START";
42
if(defined($opt{q})) {
43
    $args .= " STARTAT=1 STOPAT=3";
44
}
45 46 47 48 49 50 51 52
if(defined($opt{d})) {
    $args .= " DEBUG=" . $opt{d};
}
&my_system($args);

print "Linktest in progress...\n";
print "Quick termination requested.\n" if defined($opt{q});
print "Debug mode requested.\n" if defined($opt{d});
53 54

# wait for the shutdown event.
55 56 57 58
$args = &starter;
$args .= " -w STOP";
&my_system($args);

59 60 61 62 63 64 65 66 67 68 69 70

# analyze results of the run
exit &analyze;

sub analyze {
    my @dir_contents;
    opendir (DIR,$linktest_path) || die "cannot open Linktest directory.";
    @dir_contents = grep(/\.fatal$|\.error$/, readdir(DIR));
    closedir(DIR);

    foreach my $file (@dir_contents)
    {
71
	&my_system("/bin/cat","$linktest_path/$file");
72 73 74 75 76 77 78 79 80 81
	
    }
    if(@dir_contents) {
	return 1;
    } else {
	print "No errors\n";
	return 0;
    }
}

82 83 84 85 86 87 88
sub my_system {
    if(my $pid = fork) {
	waitpid($pid,0);
    } else {
	my @arg_array = split(/\s+/,"@_");
	exec(@arg_array);
    }
89

90
}
91

92 93 94 95 96 97 98 99 100 101
sub starter {
    my $cmd = "@CLIENT_BINDIR@/ltevent -s $server -e $pid/$eid";
    if(defined ($opt{p})){
	$cmd .= " -p " . $opt{p};
    }
    if(defined($opt{k})) {
	$cmd .= " -k " . $opt{k};
    }
    return $cmd
}