1 | #!/usr/bin/perl |
---|
2 | use strict; |
---|
3 | use warnings; |
---|
4 | |
---|
5 | my $reg_summary = qr/^UnitTester:.*\stests=([0-9]+)\s/; |
---|
6 | my $reg_interrupted = qr/interrupting.*deadlocked.*test/oi; |
---|
7 | my $reg_sanitizer = qr/error.*addresssanitizer/oi; |
---|
8 | |
---|
9 | sub log_summary($) { |
---|
10 | my ($log) = @_; |
---|
11 | |
---|
12 | my $interrupted = 0; |
---|
13 | my $sanitizer = 0; |
---|
14 | |
---|
15 | open(LOG,'<'.$log) || die "Failed to read '$log' (Reason: $!)"; |
---|
16 | my $line; |
---|
17 | LINE: while (defined ($line=<LOG>)) { |
---|
18 | if ($line =~ $reg_summary) { |
---|
19 | my $summary = undef; |
---|
20 | my $failure = 0; |
---|
21 | my $testCount = $1; |
---|
22 | if ($testCount==0) { |
---|
23 | ; # looks like all tests in this module have been skipped |
---|
24 | } |
---|
25 | else { |
---|
26 | chomp($line); |
---|
27 | $line =~ s/^UnitTester:\s*//; |
---|
28 | my @items = split /\s+/, $line; |
---|
29 | my $module = undef; |
---|
30 | my $passed = undef; |
---|
31 | foreach (@items) { |
---|
32 | my ($key,$value) = split /=/, $_; |
---|
33 | if ($key eq 'target') { |
---|
34 | $value =~ s/\.a//; |
---|
35 | $module = $value; |
---|
36 | } |
---|
37 | elsif ($key eq 'passed') { |
---|
38 | $passed = $value; |
---|
39 | if ($passed eq 'ALL') { $passed = $testCount; } |
---|
40 | } |
---|
41 | } |
---|
42 | $summary = "- $module ($passed/$testCount)"; |
---|
43 | if ($passed != $testCount) { $failure = 1; } |
---|
44 | } |
---|
45 | |
---|
46 | close(LOG); |
---|
47 | return ($summary,$failure); |
---|
48 | } |
---|
49 | elsif ($line =~ $reg_interrupted) { |
---|
50 | $interrupted = 1; |
---|
51 | last LINE; |
---|
52 | } |
---|
53 | elsif ($line =~ $reg_sanitizer) { |
---|
54 | $sanitizer = 1; |
---|
55 | last LINE; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | close(LOG); |
---|
60 | |
---|
61 | # no summary found -> problem |
---|
62 | my $module = $log; # fallback |
---|
63 | my $extraMsg = '; invalid logname'; |
---|
64 | |
---|
65 | if ($log =~ /logs\//o) { |
---|
66 | my $name = $'; |
---|
67 | if ($name =~ /^([^\.]+)\.test/o) { |
---|
68 | $module = $1; |
---|
69 | $extraMsg = ''; |
---|
70 | } |
---|
71 | else { |
---|
72 | $module = $name; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | my $msg = 'no summary; crashed?'; |
---|
77 | if ($interrupted==1) { $msg = 'interrupted; deadlock?'; } |
---|
78 | if ($sanitizer==1) { $msg = 'aborted by AddressSanitizer'; } |
---|
79 | |
---|
80 | return ("- $module ($msg$extraMsg)",1); |
---|
81 | } |
---|
82 | |
---|
83 | sub main() { |
---|
84 | my $args = scalar(@ARGV); |
---|
85 | if ($args!=1) { |
---|
86 | die "Usage: log_result.pl unittest.log"; |
---|
87 | } |
---|
88 | else { |
---|
89 | my ($summary,$failure) = log_summary($ARGV[0]); |
---|
90 | if (defined $summary) { |
---|
91 | if ($failure==1) { |
---|
92 | print sprintf("%-35s <- FAILED\n", $summary); |
---|
93 | } |
---|
94 | else { |
---|
95 | print $summary."\n"; |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | main(); |
---|