forked from rurban/perl-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status_upd
executable file
·299 lines (279 loc) · 7.99 KB
/
status_upd
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/perl -w
# status_upd [-suqftad] [ 1.26 | path ]
# process perlall maketest logfiles:
# `perl$ver Makefile.PL && make test > log.test-$platform-$ver; make clean`
# and find and sort by FAIL/TODO and platform+version
use strict;
use Data::Dumper;
use Getopt::Long;
use Set::Object qw(reftype);
sub help {
print <<EOF;
status_upd -fqd [ 1.32 | path ]
OPTIONS:
-q quiet
-f fail only
-t todo only
-d no unify dumps
-a all, do not skip too old logs
-s sort by test (ignored)
-u update STATUS (ignored)
-h help
EOF
exit;
}
my $logs = "log.test-*-5.*";
my $dir = ".";
my $STATUS = "./STATUS";
chdir ".." if ! -d "t" and -d "../t";
chdir "../.." if ! -d "t" and -d "../../t";
my ($sortbytest, $update, $quiet, $failonly, $todoonly, $noskip, $nodump, $help);
Getopt::Long::Configure ("bundling");
GetOptions ("sort|s" => \$sortbytest, #ignored
"update|u" => \$update, #ignored
"quiet|q" => \$quiet,
"fail|f" => \$failonly,
"todo|pass|t" => \$todoonly,
"all|a" => \$noskip,
"dump|d" => \$nodump,
"help|h" => \$help);
help if $help;
for (@ARGV) {
-d "t/reports/$_" and $dir = "t/reports/$_";
-d "$_" and $dir = $_;
}
# read stdout lines from a grep command and
# prints and return a string of the sorted
# results and a hash for further processing.
sub status {
my $h = shift;
my @g = @_;
my $s = "";
my %h = %$h;
my $prefix = '';
my $oldprefix = '';
my $skipped = 0;
while (@g) {
if ($g[0] =~ /^--/) {
$oldprefix = $prefix if $prefix;
$prefix = '';
shift @g;
next;
}
my $file = shift @g;
my $failed = shift @g;
my $ctime = 0;
unless ($prefix) {
my ($f) = $file =~ m{(log.test-.*?)-t/};
($prefix) = $file =~ m{log.test-(.*?)-t/};
if ($prefix and $oldprefix ne $prefix) {
#$prefix =~ s/ATGRZ.+?-/cygwin-/;
$ctime = -f $f ? sprintf("%0.3f", -C $f) : 0;
print "\n$prefix: age=$ctime" unless $quiet;
if ($ctime > 1.5 and !$noskip) {
$skipped = 1;
print " skipped: too old" unless $quiet;
$s .= "\n$prefix:\n" unless $quiet;
} else {
$s .= "\n$prefix:\n";
$skipped = 0;
}
print "\n" unless $quiet;
}
}
next unless $prefix;
next unless $file;
chomp $file;
($file) = $file =~ m{log.test-.*-(t/[\w\.]+\s?)};
next unless $file;
$file =~ s{\s*$}{};
$file =~ s{^\s*}{};
$failed =~ s{^.+(Failed tests?:?)}{$1}i;
$failed =~ s{^.+TODO passed:}{TODO passed:};
chomp $failed;
$failed =~ s/(\d)-(\d)/$1..$2/g;
my $f = $failed;
$f =~ s{^Failed tests?:?\s*(.+)$}{$1}i;
$f =~ s{^TODO passed:\s*}{};
$f =~ s/ //g;
my $c = "$file\t" if $failed;
$c .= "\t" if length($file) < 8;
$c .= "$failed\n";
$h{$prefix}->{$file} = $f;
next if $skipped;
print "$c" unless $quiet;
$s .= $c;
}
print "\n" unless $quiet;
[ $s, \%h ];
}
# split into platform, version, [feature]
# debian-squeeze-amd64-5.10.1-nt => ("debian-squeeze-amd64", "5.10", "nt")
sub platform_version_split {
local $_ = shift;
my ($p,$v,$f) = m/^(.+)-(5\.[\d\.]+)([-dnt]+)?$/;
$f =~ s/^-// if $f; # d, d-nt, nt or empty
$v =~ s/(\d\.\d+)\.\d+/$1/ if $v;
return ($p,$v,$f);
}
sub h_size($) { scalar keys %{$_[0]} }
sub split_tests($) {
my $t = shift;
map {
if (/(\d+)\.\.(\d+)/) {
($1 .. $2)
} else {
$_
}
} split /,\s*/, $t;
}
sub in_both ($$) {
# only the elements on both lists
my %h1 = map { $_ => 1 } @{$_[0]};
my %h2 = map { $_ => 1 } @{$_[1]};
for (keys %h1) {
my $e = $h1{$_};
undef $h1{$_} unless $h2{$e};
}
sort keys %h1;
}
# every
sub all_common {
my $h = shift; # platform_version -> test_file -> test_no_failed
my $result = shift; # skip already deleted results, initially empty
my (%tests);
if (@_ == 1) {
delete $h->{$_[0]}->{''};
return $h->{$_[0]};
}
# init with shortest list, sort hash by least number of keys
my @p = sort { h_size($h->{$a}) <=> h_size($h->{$b}) } @_;
my $pivot = $p[0];
my $pivotset = Set::Object->new(keys %{$h->{$pivot}});
for ($pivotset->members) {
if (my $k = $h->{$pivot}->{$_}) {
$tests{$_} = Set::Object->new(split_tests($k));
}
}
for my $p (@_) { # check for common keys (in every)
my $c = $pivotset * Set::Object->new(keys %{$h->{$p}});
for ($c->members) {
if ($_ and exists $tests{$_}) {
$result->{$_} = $result->{$_} ? $tests{$_} * $result->{$_} : $tests{$_};
$result->{$_} = $result->{$_} * Set::Object->new( split_tests($h->{$p}->{$_}) )
if $result->{$_}->members;
$result->{$_} = $result->{$_}->members;# status_upd -f -q -d
}
delete $result->{$_} unless $result->{$_};
}
}
delete $result->{''};
return $result;
}
# XXX FIXME does not work yet
sub unify_results {
my $h = shift; # platform_version -> file -> failed
my $name = shift; # todo or fail
# first check for common results in files, all platforms
my @platforms = keys %$h;
my $result = all_common($h, {}, @platforms);
if (%$result) {
print Data::Dumper->Dump([$result],["common_$name"]);
# initialize for next round: delete already common found
for my $p (@platforms) {
for (keys %{$h->{$p}}) {
if ($result->{$_} and $result->{$_} ne $h->{$p}->{$_}) { # strip out common tests
my $both = Set::Object->new(split_tests $h->{$p}->{$_})
- Set::Object->new($result->{$_});
if ($both->members) {
$h->{$p}->{$_} = join(",", $both->members);
} else {
undef $h->{$p}->{$_};
}
}
}
}
}
my $h_sav = $h;
# ignore the platform for now. we don't have any platform issues.
# check for all pairs version - feature the shortest commons
# 1. sort by versions (ignore platform + features) *-v-*
# ignore older devel versions (5.11), just blead
my %versions;
for (@platforms) {
my ($p,$v,$f) = platform_version_split($_);
push @{$versions{$v}}, ($_) if $v;
}
for my $v (sort keys %versions) {
if ($v !~ /^5\.(7|9|11)$/) { # skip 5.11, 5.9, 5.7, but not blead (5.13 currently)
my $v1 = all_common($h, $result, @{$versions{$v}});
if (%$v1) {
print Data::Dumper->Dump([$v1],["v$v $name"]);
}
}
}
# 2. sort by feature (ignore platform + version) *-*-f
$h = $h_sav;
my %feat;
for (@platforms) {
my ($p,$v,$f) = platform_version_split($_);
$f = "" unless $f;
push @{$feat{$f}}, ($_);
}
for my $f (sort keys %feat) {
my $f1 = all_common($h, $result, @{$feat{$f}});
if (%$f1) {
print Data::Dumper->Dump([$f1],["feature $f $name"]);
}
}
}
my $dlogs = $dir eq '.' ? "$logs" : "$dir/$logs";
my $cmd = 'grep -a -i "tests" ' . $dlogs . " | grep -v t/CORE";
#print "$cmd\n" unless $quiet;
my %h;
my %h_sav = %h;
if (my @g = `$cmd`) {
for my $file (@g) {
my $prefix;
if (($prefix) = $file =~ m{log.test-(.*?):}) {
($file) = $file =~ m/(log.test-.*?):/;
my $ctime = -f $file ? sprintf("%0.3f", -C $file) : 0;
if ($ctime < 1.5 or $noskip) {
$h{$prefix}->{''} = '';
}
}
}
} else {
die "no $logs found\n";
}
if (!$todoonly) {
my $cmd = 'grep -a -B1 -i "Failed test" ' . $dlogs . " | grep -v t/CORE";
print "$cmd\n" unless $quiet;
if (my @g = `$cmd`) {
my $failed = status(\%h, @g);
print $failed->[0] if $nodump and $quiet;
my $failedu = unify_results($failed->[1], "fail") unless $nodump;
}
}
%h = %h_sav;
if (!$failonly) {
my $cmd = 'grep -a -B1 -i "TODO passed" ' . $dlogs . " | grep -v t/CORE";
print "\n$cmd\n" unless $quiet;
if (my @g = `$cmd`) {
my $todo = status(\%h, @g);
print $todo->[0] if $nodump and $quiet;
my $todou = unify_results($todo->[1], "todo_pass") unless $nodump;
}
}
# XXX TODO: update the TEST STATUS section in "./STATUS"
if ($update) {
die "file not found $STATUS\n" unless -e $STATUS;
die "-u update STATUS not yet implemented\n";
# sort away platforms
}
# Local Variables:
# mode: cperl
# cperl-indent-level: 2
# fill-column: 100
# End:
# vim: expandtab shiftwidth=2: