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

use strict;
use Getopt::Std;
8
use English;
9

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

13
sub usage {
14
15
16
17
    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;
18
19
20
    return 1;
}

21
22
23
24
25
26
27
28
#
# This script should be run as a real person!
#
if (! $EUID) {
    die("*** $0:\n".
	"    This script should not be run as root!\n");
}

29
30
31
32
33
34
# signal handler in case the process is killed.
$SIG{INT} = sub {
    print "Aborted. Linktest continues on nodes.\n";
    exit(1);
};

35
my $server;
36
my $port;
37
my %opt = ();
38
getopts("s:e:d:qp:k:",\%opt);
39
if ($opt{s}) { $server = $opt{s}; } else { $server = "boss"; }
40
if ($opt{p}) { $port = $opt{p}; }
41
42
43
44
45
46
47
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.
48
49
50
my $args = &starter;
# event arguments
$args .=  " -x START";
51
if(defined($opt{q})) {
52
    $args .= " STARTAT=1 STOPAT=3";
53
}
54
55
56
57
58
59
60
61
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});
62
63

# wait for the shutdown event.
64
65
66
67
$args = &starter;
$args .= " -w STOP";
&my_system($args);

68
69
70
71
72
73
74
75
76
77
78
79

# 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)
    {
80
	&my_system("/bin/cat","$linktest_path/$file");
81
82
83
84
85
86
87
88
89
90
	
    }
    if(@dir_contents) {
	return 1;
    } else {
	print "No errors\n";
	return 0;
    }
}

91
92
93
94
95
96
97
sub my_system {
    if(my $pid = fork) {
	waitpid($pid,0);
    } else {
	my @arg_array = split(/\s+/,"@_");
	exec(@arg_array);
    }
98

99
}
100

101
102
103
104
105
106
107
108
109
110
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
}