-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_test.pl
executable file
·77 lines (67 loc) · 1.93 KB
/
run_test.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env perl
use strict;
use Data::Dumper;
use Getopt::Std;
use FindBin qw( $RealBin );
use lib "$RealBin/../perl";
use Toolbox;
my $tb = Toolbox->new();
my $usage = "$0 [option] test_file...
options: -h this help
-t <regexp> execute the test with matching name(s) (all by default)
";
my %opt; # GLOBAL: to store the options
Getopt::Std::getopts( 'ht:', \%opt );
if( $opt{'h'} or @ARGV == 0 ){
print "$usage\n";
exit 0;
}
$opt{t} = '.' unless $opt{t};
my %test_info = ();
my %elapsed = ();
my $rank = 0;
my $test_id = '';
while( <> ){
next if /^\#/;
next if /^\s*$/;
if( /^TEST=(.+)/ ){
$rank++;
$test_id = $1;
$tb->die( "Duplicated test: $test_id" ) if exists $test_info{$test_id};
$test_info{$test_id} = {
rank => $rank,
cmd => '',
}
}
else{
$tb->die( "Not test defined yet: $_" ) unless $test_id;
while( /\$(\w+)/g ){
$tb->die( "Environment variable '$1' not set in line: $_" ) unless exists $ENV{$1};
}
$test_info{$test_id}{cmd} .= $_;
}
}
foreach my $test_id ( sort { $test_info{$a}{rank} <=> $test_info{$b}{rank} } keys %test_info ){
unless( $test_id =~ /$opt{t}/o ){
$tb->report( 'skip', $test_id );
next;
}
my @cmd = (
'TEST_NAME=' . $test_id,
'TMP=' . $ENV{'TMP'},
'MNET=' . $ENV{'MNET'},
# 'NCORE=' . $ENV{'NCORE'},
);
push @cmd, $ENV{'INIT'} if $ENV{'INIT'};
push @cmd, $test_info{$test_id}{cmd};
my $t0 = time();
warn "\n";
$tb->system( join "\n", @cmd );
$test_info{$test_id}{elapsed} = time() - $t0;
$tb->report( $test_id, $test_info{$test_id}{elapsed} . ' s');
}
warn "\n";
$tb->report( '', '### Test Summary ###' );
foreach my $test_id ( sort { $test_info{$a}{rank} <=> $test_info{$b}{rank} } keys %test_info ){
$tb->report( $test_id, $test_info{$test_id}{elapsed} . ' s');
}