OSDN Git Service

* dglib.pm: Initial commit.
[pf3gnuchains/gcc-fork.git] / contrib / compareSumTests3
1 #!/usr/bin/perl
2
3 # Three-way DejaGNU comparison; uses dglib.pm.  Run perldoc on this file for
4 # usage.
5 #
6 # Author: Matthew Sachs <msachs@apple.com>
7 #
8 # Copyright (c) 2006 Free Software Foundation.
9 #
10 # This file is part of GCC.
11 #
12 # GCC is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2, or (at your option)
15 # any later version.
16 #
17 # GCC is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with GCC; see the file COPYING.  If not, write to
24 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
25 # Boston, MA 02110-1301, USA.
26
27 =pod
28
29 =head1 SYNOPSIS
30
31 compareSumTests3 -- Two-way or three-way compare between DejaGNU .sum files
32
33 =head1 USAGE
34
35         compareSumTests3 old1.sum [old2.sum] new.sum
36         compareSumTests3 -i 1:2 -x 2:3 old1.sum old2.sum new.sum
37
38 =head1 DESCRIPTION
39
40 Gives results in terms of 'new' (e.g. things that work in 'new' and don't in
41 other compilers are improvements, things that don't in 'new' and do in others
42 are regressions, and it tells you which of the two old compilers (or both)
43 the test is a regression from.
44
45 We treat any DG result other than PASS or XFAIL as a failure, e.g.
46 UNRESOLVED, UNTESTED or test was not run.
47
48 We merge some tests into 'logical tests' with multiple subphases.
49 For instance, some tests will have compile, execute, and link
50 subtests.  For these tests, if one of the phases fails, we
51 indicate which phase the failure originates in.  For instance,
52 in the following test results:
53
54         gcc.c-torture/compile_execute/xxxx.c: [FAIL:C,FAIL:X,PASS]
55
56 the "compile_execute" replaces the compile or execute portion of the test name,
57 and "FAIL:C" and "FAIL:X" indicates where the combined test failed.
58
59 =head1 OPTIONS
60
61 =head2 OVERVIEW
62
63 =over 4
64
65 =item *
66
67 C<-i X:Y>: Only display differences between the two indicated runs.
68
69 =item *
70
71 C<-p>: Give plain output, suitable for piping to another program.
72
73 =item *
74
75 C<-x X:Y>: Exclude differences between the two indicated runs.
76
77 =back
78
79 =head2 PLAIN OUTPUT FORMAT
80
81 In the plain
82 output format, the category headers are not displayed and there are no tabs
83 in front of each result line.  Instead, each result line has two characters
84 followed by a space in front of it.  The first character will be either an 'I'
85 for improvement or 'R' for regression; the second character will be a 1, 2, or 3,
86 indicating which run was the odd one out.
87
88 =back
89
90 =head2 SELECTING CHANGE SUBSETS
91
92 The following options cause only a selected subset of changes to be displayed.
93 These options ask for a "run", a number which is used to select
94 one of the three runs (C<old1>, C<old2>, or C<new>.)  C<1> and C<2> signify C<old1> and C<old2>
95 respectively; 3 signifies C<new>. If multiple options are given, the changes displayed
96 will be those which obey all of the given restrictions.
97
98 Typical usage of these options is to express something like "give me all changes
99 between 2 and 3, except for those where there was the same difference betwen 1 and 2
100 (as between 2 and 3.)"  This would be given as:
101
102         -i 2:3 -x 1:2
103
104 =over 4
105
106 =item *
107
108 C<-i X:Y>: Only differences which are present between the two runs given
109 are displayed. For instance, if C<-i 1:2> is given and test A passes in
110 runs 1 and 2 but fails in run 3, that result will not be displayed.
111
112 =item *
113
114 C<-x X:Y>: Differences which are identical to a difference between the two runs
115 given will B<not> be displayed. For instance, if C<-x 1:2> is given and
116 test A passes in run 1 and fails in runs 2 and 3, that result will not be
117 displayed (since C<-x> will cause the difference between 1 and 2 to be ignored,
118 and the difference in 1 and 3 parallels the difference between 1 and 2.)
119 This option may only be used in conjunction with C<-i>.
120
121 =back
122
123 =cut
124
125 use strict;
126 use warnings;
127 use Getopt::Long;
128
129 use FindBin qw($Bin);
130 use lib "$Bin";
131 use dglib;
132
133 my %options;
134 my $error = undef;
135
136 if(!GetOptions(
137         "p" => \$options{p},
138         "i=s" => \$options{i},
139         "x=s" => \$options{x},
140 )) {
141         $error = "";
142 } elsif(@ARGV != 2 and @ARGV != 3) {
143         $error = "";
144 } elsif($options{x} and !$options{i}) {
145         $error = "-x may only be given in conjunction with -i.";
146 } else {
147         foreach my $opt("i", "x") {
148                 if($options{$opt} and
149                   ($options{$opt} !~ /^([123]):([123])$/ or
150                    $1 == $2)
151                 ) {
152                         $error = "Invalid -$opt argument.";
153                 }
154         }
155 }
156
157 if(defined($error)) {
158         print STDERR "$error\n" if $error;
159         print STDERR "Usage: compareSumTests3 [-p] [-i X:Y [-x X:Y]] old1.sum old2.sum new.sum\n";
160         print STDERR "Try 'perldoc $0' for further information.\n";
161         exit 1;
162
163
164 my(@sumfiles) = @ARGV;
165 -f $_ || die "$_ is not a regular file!\n" foreach @sumfiles;
166 my(%results, @inc_changes, @exc_changes, %checksums);
167
168 # We decrement the values given so that they correspond
169 # to indices into our results array.
170 if($options{i}) {
171         $options{i} =~ /(\d+):(\d+)/;
172         @inc_changes = ($1 - 1, $2 - 1);
173 }
174 if($options{x}) {
175         $options{x} =~ /(\d+):(\d+)/;
176         @exc_changes = ($1 - 1, $2 - 1);
177 }
178
179
180 my %analyzed_results = compareSumFiles(\@sumfiles);
181
182 foreach my $cat (qw(improvements regressions miscellaneous)) {
183         if(@sumfiles == 3) {
184                 my @subcounts;
185                 if(!$options{p}) {
186                         $subcounts[$_] = @{$analyzed_results{$cat}->[$_] || []} for(0..2);
187                         print "\u$cat: ", ($subcounts[0]+$subcounts[1]+$subcounts[2]), "\n";
188                 }
189
190                 for(my $i = 0; $i < 3; $i++) {
191                         if(!$options{p} and $cat ne "miscellaneous") {
192                                 if($i == 0) {
193                                         if($cat eq "regressions") {
194                                                 print "\tSuccess in old1 only: $subcounts[$i]\n";
195                                         } else {
196                                                 print "\tFailure in old1 only: $subcounts[$i]\n";
197                                         }
198                                 } elsif($i == 1) {
199                                         if($cat eq "regressions") {
200                                                 print "\tSuccess in old2 only: $subcounts[$i]\n";
201                                         } else {
202                                                 print "\tFailure in old2 only: $subcounts[$i]\n";
203                                         }
204                                 } else {
205                                         if($cat eq "regressions") {
206                                                 print "\tFailure in new only: $subcounts[$i]\n";
207                                         } else {
208                                                 print "\tSuccess in new only: $subcounts[$i]\n";
209                                         }
210                                 }
211                         }
212
213                         foreach my $test (sort {$a->{name} cmp $b->{name}} @{$analyzed_results{$cat}->[$i] || []}) {
214                                 if(!$options{p}) {
215                                         if($cat eq "miscellaneous") {
216                                                 print "\t";
217                                         } else {
218                                                 print "\t\t";
219                                         }
220                                 } else {
221                                         if($cat eq "regressions") {
222                                                 print "R";
223                                         } else {
224                                                 print "I";
225                                         }
226
227                                         print $i+1, " ";
228                                 }
229                                 printf "%s [%s,%s,%s]\n", $test->{name}, $test->{data}->[0], $test->{data}->[1], $test->{data}->[2];
230                         }
231                 }
232         } else {
233                 if(!$options{p}) {
234                         my $subcount = @{$analyzed_results{$cat}};
235                         print "\u$cat: $subcount\n";
236                 }
237
238                 foreach my $test (sort {$a->{name} cmp $b->{name}} @{$analyzed_results{$cat}}) {
239                         if(!$options{p}) {
240                                 print "\t";
241                         } else {
242                                 if($cat eq "regressions") {
243                                         print "R";                              } else {
244                                         print "I";
245                                 }
246
247                                 print "  ";
248                         }
249                         printf "%s [%s,%s]\n", $test->{name}, $test->{data}->[0], $test->{data}->[1], $test->{data}->[2];
250                 }
251         }
252 }