| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
use strict; |
| 4 |
# No use warnings; in 5.005 but we have the -w flag |
| 5 |
|
| 6 |
my @expected_filenames; |
| 7 |
|
| 8 |
BEGIN { # @expected_filenames must be set at compile time |
| 9 |
my $host = $ENV{HOSTNAME} || $ENV{HOSTNAME} || `hostname`; |
| 10 |
|
| 11 |
$host =~ s/\r|\n//g; |
| 12 |
#$host =~ s/\.\S+//; |
| 13 |
|
| 14 |
my $user = $ENV{USER} || $ENV{USERNAME}; |
| 15 |
|
| 16 |
@expected_filenames = ( |
| 17 |
"e=no,h=$host,l=$user,n=HC,r=hc,t=,c=,s=\.log", |
| 18 |
"e=no,h=$host,l=$user,n=MTC,r=mtc,t=,c=,s=\.log", |
| 19 |
"e=no,h=$host,l=$user,n=MTC,r=mtc,t=,c=tc_nooooo,s=\.log", |
| 20 |
"e=no,h=$host,l=$user,n=MTC,r=mtc,t=,c=tc_no,s=\.log", |
| 21 |
"e=no,h=$host,l=$user,n=MTC,r=mtc,t=No,c=tc_nooooo,s=\.log", |
| 22 |
"e=no,h=$host,l=$user,n=MTC,r=mtc,t=No,c=tc_no,s=\.log", |
| 23 |
"c=,s=.log", |
| 24 |
"c=tc_nooooo,s=\.log", |
| 25 |
"c=tc_no,s=\.log", |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
if ($] < 5.006) { |
| 30 |
# ancient perl, we must be on Solaris :( |
| 31 |
my @perlloc = qw( /proj/TTCN/Tools/perl-5.10.1/bin/perl /mnt/TTCN/Tools/perl-5.10.1/bin/perl ); |
| 32 |
foreach (@perlloc) { |
| 33 |
if (-x $_) { |
| 34 |
warn "Let's try with $_ instead"; |
| 35 |
exec( $_, '-wT', $0, @ARGV ) or die "That didn't work either: $!"; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
else { |
| 40 |
require Test::More; |
| 41 |
use constant NUM_LOGFILES => scalar @expected_filenames; |
| 42 |
|
| 43 |
Test::More->import( |
| 44 |
tests => |
| 45 |
1 # test number of log files |
| 46 |
+ 2 * NUM_LOGFILES # test existence + switched/not switched |
| 47 |
+ 1 # Local IP address warning |
| 48 |
+ 1 # Non-unique log file name warning |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
use strict; |
| 53 |
|
| 54 |
# grep a file. Returns the number of times (lines) it matched. |
| 55 |
# Parameter 1: filename |
| 56 |
# Parameter 2: regex |
| 57 |
sub grepper($$) { |
| 58 |
local $_; |
| 59 |
my ($filename, $regex) = @_; |
| 60 |
my $result = 0; |
| 61 |
open (LOG, '< ' . $filename) or die "open : $!, $^E"; |
| 62 |
while (<LOG>) { |
| 63 |
if ( /$regex/ ) { |
| 64 |
++$result; |
| 65 |
} |
| 66 |
} |
| 67 |
close(LOG) or die "close: $!, $^E"; |
| 68 |
return $result; |
| 69 |
} |
| 70 |
|
| 71 |
# Return 1 if "switching to log file" appears in the file. |
| 72 |
# One parameter, the file name |
| 73 |
sub switched($) { |
| 74 |
return grepper($_[0], qr/EXECUTOR_RUNTIME [sS]witching to log file/) != 0; |
| 75 |
} |
| 76 |
|
| 77 |
# Start ! |
| 78 |
|
| 79 |
# Collect the list of log files on the disk. There are two patterns. |
| 80 |
my @files = <e=no,h=*,l=*,n={HC\,r=hc,MTC\,r=mtc},*.log>; |
| 81 |
push @files , <c=*.log>; |
| 82 |
|
| 83 |
# Check that it is the correct number |
| 84 |
is(scalar @files, NUM_LOGFILES, 'Number of log files'); |
| 85 |
|
| 86 |
foreach my $x ( @expected_filenames ) |
| 87 |
{ |
| 88 |
# Filter the list of filenames, keep just the matching ones |
| 89 |
my @g = grep($_ =~ /^$x$/, @files); |
| 90 |
# There must be exactly one match |
| 91 |
is(scalar @g, 1, "Found : $x"); |
| 92 |
} |
| 93 |
|
| 94 |
foreach my $fn ( @files ) |
| 95 |
{ |
| 96 |
chomp $fn; |
| 97 |
if ($fn =~ /^e=no,h=[\w.-]+,l=\w+,n=HC,r=hc,t=,c=,s=\.log$/ ) { |
| 98 |
ok( !switched($fn), "Not switched : $fn" ); |
| 99 |
is( grepper($fn, qr/The address of MC was set to a local IP address\. This may cause incorrect behavior/), 1, |
| 100 |
"Local IP warn: $fn" ); |
| 101 |
} |
| 102 |
else { |
| 103 |
ok( switched($fn), "Switched : $fn" ); |
| 104 |
} |
| 105 |
|
| 106 |
if ($fn =~ /^c=,s=.log$/) { |
| 107 |
is( grepper($fn, qr/does not guarantee unique log file name for every test system process/), 1, |
| 108 |
"Warns once : $fn\n(about log file name not being unique)" ); |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
__END__ |