]> git.saurik.com Git - apple/ld64.git/blame - unit-tests/bin/result-filter.pl
ld64-123.2.tar.gz
[apple/ld64.git] / unit-tests / bin / result-filter.pl
CommitLineData
d696c285
A
1#!/usr/bin/perl -w
2
3use strict;
4use Data::Dumper;
5use File::Find;
6use Cwd;
7
8$Data::Dumper::Terse = 1;
9
10my $root = undef;
11my $entry = '';
12my $pass_count = 0;
13my $total_count = 0;
14
15# first match "root: "
16
17# a line starting with "cwd:" marks the beginning of a new test case
18# call process_entry() on each test case
19while(<>)
20{
21 if(m/^root:\s+(.*?)$/)
22 {
23 $root = $1;
24 }
25 elsif(m/^cwd:\s+(.*?)$/)
26 {
27 if(length($entry))
28 {
29 &process_entry($root, $entry);
30 $entry = '';
31 }
32 $entry .= $_;
33 }
34 else
35 {
36 $entry .= $_;
37 }
38}
39# don't forget last test case (no cwd: to mark end)
40if(length($entry))
41{
42 &process_entry($root, $entry);
43}
44
45# show totals
46my $percentage = $pass_count * 100 / $total_count;
47printf " * * * %d of %d unit-tests passed (%.1f percent) * * *\n", $pass_count, $total_count, $percentage;
48
49
50sub process_entry
51{
52 my ($root, $lines) = @_;
53
54 # build an associative array of keys to value(s)
55 my $lines_seq = [split /\n/, $lines];
56 #print Dumper($lines_seq);
57 my $tbl = { 'root' => $root, 'stdout' => [], 'stderr' => [] };
58 my $line;
59 foreach $line (@$lines_seq)
60 {
61 if($line =~ m/^(\w+):\s+(.*)$/)
62 {
63 my $key = $1;
64 my $val = $2;
65 if(!exists($$tbl{$key}))
66 { $$tbl{$key} = ''; }
67
68 if($key eq 'stdout' || $key eq 'stderr') # if type is @array
69 {
70 push @{$$tbl{$key}}, $val;
71 }
72 else
73 {
74 $$tbl{$key} .= $val;
75 }
76 }
77 else
78 {
79 print "ERROR: $line";
80 }
81 }
82 #print Dumper($tbl);
83 #return;
84
85 my $test_name = $$tbl{cwd};
86 if ($test_name =~ m|.*/([a-zA-Z0-9-+_]+)$|)
87 {
88 $test_name = $1;
89 }
90
91 #if make failed (exit was non-zero), mark this as a failure
92 if(0 ne $$tbl{exit})
93 {
94 printf "%-40s FAIL Makefile failure\n", $test_name;
95 $total_count++;
a645023d
A
96 #my $line1;
97 #foreach $line1 (@{$$tbl{stdout}})
98 #{
99 # printf "stdout: %s\n", $line1;
100 #}
101 #foreach $line1 (@{$$tbl{stderr}})
102 #{
103 # printf "stderr: %s\n", $line1;
104 #}
d696c285
A
105 return;
106 }
107
108 #if there was any output to stderr, mark this as a failure
109 foreach $line (@{$$tbl{stderr}})
110 {
111 printf "%-40s FAIL spurious stderr failure: %s\n", $test_name, $line;
112 $total_count++;
113 return;
114 }
115
116 # scan all stdout looking for lines that start with PASS or FAIL
117 my $seen_result = 0;
118 foreach $line (@{$$tbl{stdout}})
119 {
120 if($line =~ m/^(PASS|XPASS|FAIL|XFAIL).+/)
121 {
d696c285
A
122 $total_count++;
123 if($line =~ m/^PASS.+/)
124 {
125 $pass_count++;
126 }
a61fdf0a
A
127 else
128 {
129 # only print failure lines
130 printf "%-40s %s\n", $test_name, $line;
131 }
d696c285
A
132 $seen_result = 1;
133 }
134 }
135 if(!$seen_result)
136 {
137 printf "%-40s AMBIGIOUS missing [X]PASS/[X]FAIL\n", $test_name;
138 $total_count++;
a645023d
A
139 #my $line1;
140 #foreach $line1 (@{$$tbl{stdout}})
141 #{
142 # printf "stdout: %s\n", $line1;
143 #}
144 #foreach $line1 (@{$$tbl{stderr}})
145 #{
146 # printf "stderr: %s\n", $line1;
147 #}
d696c285
A
148 }
149}