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