Commit | Line | Data |
---|---|---|
970ed795 EL |
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 | chomp $host; | |
11 | ||
12 | my $user = $ENV{USER} || $ENV{USERNAME}; | |
13 | ||
14 | @expected_filenames = ( | |
15 | "logcontrol.log", | |
16 | "changed_name-changename-L.log", | |
17 | "changed_name-changename-.log", | |
18 | "changed_name--.log", | |
19 | ); | |
20 | } | |
21 | ||
22 | if ($] < 5.006) { | |
23 | # ancient perl, we must be on Solaris :( | |
24 | my @perlloc = qw( /proj/TTCN/Tools/perl-5.10.1/bin/perl /mnt/TTCN/Tools/perl-5.10.1/bin/perl ); | |
25 | foreach (@perlloc) { | |
26 | if (-x $_) { | |
27 | warn "Let's try with $_ instead"; | |
28 | exec( $_, '-wT', $0, @ARGV ) or die "That didn't work either: $!"; | |
29 | } | |
30 | } | |
31 | } | |
32 | else { | |
33 | require Test::More; | |
34 | use constant NUM_LOGFILES => scalar @expected_filenames; | |
35 | ||
36 | Test::More->import( | |
37 | tests => | |
38 | 1 # test number of log files | |
39 | + 2 * NUM_LOGFILES # test existence + switched/not switched | |
40 | + 1 # lines to be seen | |
41 | + 1 # lines not to be seen | |
42 | + 1 # setverdict | |
43 | + 2 # entity info on/off | |
44 | + 2 # match hint verbosity | |
45 | ); | |
46 | } | |
47 | ||
48 | use strict; | |
49 | ||
50 | ############################################################## | |
51 | # grep a file. Returns the number of times (lines) it matched. | |
52 | # Parameter 1: filename | |
53 | # Parameter 2: regex | |
54 | sub grepper($$) { | |
55 | local $_; | |
56 | my ($filename, $regex) = @_; | |
57 | my $result = 0; | |
58 | open (LOG, '< ' . $filename) or die "open $filename: $!, $^E"; | |
59 | while (<LOG>) { | |
60 | if ( /$regex/ ) { | |
61 | ++$result; | |
62 | } | |
63 | } | |
64 | close(LOG) or die "close: $!, $^E"; | |
65 | return $result; | |
66 | } | |
67 | ||
68 | ############################################################## | |
69 | # Return 1 if "switching to log file" appears in the file. | |
70 | # One parameter, the file name | |
71 | sub switched($) { | |
72 | return grepper($_[0], qr/EXECUTOR_RUNTIME \S+\.ttcn:\d+ Switching to log file/) != 0; | |
73 | } | |
74 | ||
75 | # Start ! | |
76 | ||
77 | # Collect the list of log files on the disk. There are two patterns. | |
78 | my @files = <changed_name*.log>; | |
79 | push @files , <logcontrol[.]log>; | |
80 | ||
81 | # Check that it is the correct number | |
82 | is(scalar @files, NUM_LOGFILES, 'Number of log files'); | |
83 | ||
84 | foreach my $x ( @expected_filenames ) | |
85 | { | |
86 | # Filter the list of filenames, keep just the matching ones | |
87 | my @g = grep($_ =~ /^$x$/, @files); | |
88 | # There must be exactly one match | |
89 | is(scalar @g, 1, "Found : $x"); | |
90 | } | |
91 | ||
92 | foreach my $fn ( @files ) | |
93 | { | |
94 | chomp $fn; | |
95 | =head | |
96 | if ($fn =~ /^e=no,h=[\w.]+,l=\w+,n=HC,r=hc,t=,c=,s=\.log$/ ) { | |
97 | ok( !switched($fn), "Not switched : $fn" ); | |
98 | is( grepper($fn, qr/The address of MC was set to a local IP address\. This may cause incorrect behaviour/), 1, | |
99 | "Local IP warn: $fn" ); | |
100 | } | |
101 | else { | |
102 | ok( switched($fn), "Switched : $fn" ); | |
103 | } | |
104 | ||
105 | if ($fn =~ /^c=,s=.log$/) { | |
106 | is( grepper($fn, qr/does not guarantee unique log file name for every test system process/), 1, | |
107 | "Warns once : $fn\n(about log file name not being unique)" ); | |
108 | } | |
109 | =cut | |
110 | # | |
111 | if ($fn =~ /changed_name-changename-/) { | |
112 | ok( switched($fn), "Switched : $fn" ); | |
113 | } | |
114 | else { | |
115 | ok(!switched($fn), "Not switched : $fn" ); | |
116 | } | |
117 | ||
118 | if ($fn =~ /logcontrol\.log/) { | |
119 | # post-run checks for testcase on_off() | |
120 | is( grepper($fn, qr/[^n][^o][^t] see this/), 5, "Log lines that should be seen"); | |
121 | # This number needs to be adjusted ---------^^ to match testcase on_off | |
122 | # The zero below is fixed :) ---------------VV | |
123 | is( grepper($fn, qr/not see this/) , 0, "Log lines that should NOT be seen"); | |
124 | is( grepper($fn, qr/VERDICTOP.*We\'re back/), 1, "Setverdict line that should be seen"); | |
125 | ||
126 | # post-run checks for testcase entity() | |
127 | is( grepper($fn, qr/USER_UNQUALIFIED \S+.ttcn:\d+\(testcase:\w+\) The tc should be mentioned in this log line/), 1, "LogEntityInfo switched on"); | |
128 | is( grepper($fn, qr/USER_UNQUALIFIED \S+.ttcn:\d+ The entity should not be logged anymore/) , 1, "LogEntityInfo switched off"); | |
129 | ||
130 | # post-run checks for testcase hints() | |
131 | is( grepper($fn, qr/Compact:\Q[0 <-> 0].field2 := "forty-two" with "fourty-two" unmatched\E/), 1, "Matching hints compact"); | |
132 | is( grepper($fn, qr/Full :.*unmatched Some hints to find the reason of mismatch:/) , 1, "Matching hints full"); | |
133 | } | |
134 | } | |
135 | ||
136 | ||
137 | __END__ | |
138 | ||
139 | Note: logcontrol.log will look like this only if location info was enabled. | |
140 | This means the -L flag *must* be supplied to the TTCN-3 compiler! | |
141 | Check the compilation log if the "LogEntityInfo switched on/off" test fail. | |
142 | ||
143 | 16:33:40.464985 USER_UNQUALIFIED logcontrol.ttcn:64(testcase:entity) The tc should be mentioned in this log line | |
144 | 16:33:40.465002 USER_UNQUALIFIED logcontrol.ttcn:68 The entity should not be logged anymore |