|
Packit Service |
c5cf8c |
#! /usr/bin/env perl
|
|
Packit Service |
c5cf8c |
# -*- Mode: perl; -*-
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# This script merges output from two files that should be applied to the
|
|
Packit Service |
c5cf8c |
# same source file. This is needed for MPICH on systems that support
|
|
Packit Service |
c5cf8c |
# gcov but do not support weak symbols. This script is invoked by
|
|
Packit Service |
c5cf8c |
# the coverage target in the Makefiles generated by automake.
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
$debug = 0;
|
|
Packit Service |
c5cf8c |
if ($#ARGV != 1) {
|
|
Packit Service |
c5cf8c |
print STDERR "gcovmerge.pl file1 file2
|
|
Packit Service |
c5cf8c |
Merge the gcov output of file1 and file 2 and write the result to stdout
|
|
Packit Service |
c5cf8c |
";
|
|
Packit Service |
c5cf8c |
exit(1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
$f1 = $ARGV[0];
|
|
Packit Service |
c5cf8c |
$f2 = $ARGV[1];
|
|
Packit Service |
c5cf8c |
open (I1, "<$f1" ) || die "Cannot open $f1";
|
|
Packit Service |
c5cf8c |
open (I2, "<$f2" ) || die "Cannot open $f2";
|
|
Packit Service |
c5cf8c |
while (!eof(I1) && !eof(I2)) {
|
|
Packit Service |
c5cf8c |
$s1 = <I1>;
|
|
Packit Service |
c5cf8c |
$s2 = <I2>;
|
|
Packit Service |
c5cf8c |
# The following apply to the preceeding line, and in the case of
|
|
Packit Service |
c5cf8c |
# a macro, there may be multiple lines. In the merge case,
|
|
Packit Service |
c5cf8c |
# we don't have a good way to interpret these, so we skip them
|
|
Packit Service |
c5cf8c |
# ^\s*branch\s+\d+\s+never executed
|
|
Packit Service |
c5cf8c |
# ^\s*call\s+\d+\s+never executed
|
|
Packit Service |
c5cf8c |
do {
|
|
Packit Service |
c5cf8c |
$foundSkip = 0;
|
|
Packit Service |
c5cf8c |
if ($s1 =~ /^\s*branch\s+\d+\s+never executed/ ||
|
|
Packit Service |
c5cf8c |
$s1 =~ /^\s*call\s+\d+\s+never executed/) {
|
|
Packit Service |
c5cf8c |
$s1 = <I1>;
|
|
Packit Service |
c5cf8c |
$foundSkip = 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ($s2 =~ /^\s*branch\s+\d+\s+never executed/ ||
|
|
Packit Service |
c5cf8c |
$s2 =~ /^\s*call\s+\d+\s+never executed/) {
|
|
Packit Service |
c5cf8c |
$s2 = <I2>;
|
|
Packit Service |
c5cf8c |
$foundSkip = 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Other cases: If text, then compare and output
|
|
Packit Service |
c5cf8c |
if ($s1 =~ /^\s*[A-za-z]+/) {
|
|
Packit Service |
c5cf8c |
$foundSkip = 1;
|
|
Packit Service |
c5cf8c |
if ($s1 eq $s2) {
|
|
Packit Service |
c5cf8c |
print $s1;
|
|
Packit Service |
c5cf8c |
$s1 = <I1>;
|
|
Packit Service |
c5cf8c |
$s2 = <I2>;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
$s1 = <I1>;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ($s2 =~ /^\s*[A-za-z]+/) {
|
|
Packit Service |
c5cf8c |
$foundSkip = 1;
|
|
Packit Service |
c5cf8c |
$s2 = <I2>;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} while ($foundSkip);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print "Comparing >$s1< and >$s2<\n" if $debug;
|
|
Packit Service |
c5cf8c |
$out = "";
|
|
Packit Service |
c5cf8c |
if ($s1 ne $s2) {
|
|
Packit Service |
c5cf8c |
# See if these are in expected format:
|
|
Packit Service |
c5cf8c |
# ^\s*#####:\s*\d+:.* or
|
|
Packit Service |
c5cf8c |
# ^\s*\d+:\s*d+:.* or
|
|
Packit Service |
c5cf8c |
# ^\s*-:\s*d+:.*
|
|
Packit Service |
c5cf8c |
if ($s1 =~ /^\s*#+:\s*(\d+):(.*)/) {
|
|
Packit Service |
c5cf8c |
$s1count = -1;
|
|
Packit Service |
c5cf8c |
$s1linenum = $1;
|
|
Packit Service |
c5cf8c |
$s1line = $2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif ($s1 =~ /^\s*(\d+):\s*(\d+):(.*)/) {
|
|
Packit Service |
c5cf8c |
$s1count = $1;
|
|
Packit Service |
c5cf8c |
$s1linenum = $2;
|
|
Packit Service |
c5cf8c |
$s1line = $3;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif ($s1 =~ /^\s*-:\s*(\d+):(.*)/) {
|
|
Packit Service |
c5cf8c |
$s1count = -1;
|
|
Packit Service |
c5cf8c |
$s1linenum = $1;
|
|
Packit Service |
c5cf8c |
$s1line = $2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
print "Unrecognized format for s1\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ($s2 =~ /^\s*#+:\s*(\d+):(.*)/) {
|
|
Packit Service |
c5cf8c |
$s2count = -1;
|
|
Packit Service |
c5cf8c |
$s2linenum = $1;
|
|
Packit Service |
c5cf8c |
$s2line = $2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif ($s2 =~ /^\s*(\d+):\s*(\d+):(.*)/) {
|
|
Packit Service |
c5cf8c |
$s2count = $1;
|
|
Packit Service |
c5cf8c |
$s2linenum = $2;
|
|
Packit Service |
c5cf8c |
$s2line = $3;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif ($s2 =~ /^\s*-:\s*(\d+):(.*)/) {
|
|
Packit Service |
c5cf8c |
$s2count = -1;
|
|
Packit Service |
c5cf8c |
$s2linenum = $1;
|
|
Packit Service |
c5cf8c |
$s2line = $2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
print "Unrecognized format for s2\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ($s1line eq $s2line && $s1linenum == $s2linenum) {
|
|
Packit Service |
c5cf8c |
$nlines = 0;
|
|
Packit Service |
c5cf8c |
if ($s1count > 0) { $nlines += $s1count; }
|
|
Packit Service |
c5cf8c |
if ($s2count > 0) { $nlines += $s2count; }
|
|
Packit Service |
c5cf8c |
# Format line: number of characters in leader (9:5:.*)
|
|
Packit Service |
c5cf8c |
if ($nlines == 0) {
|
|
Packit Service |
c5cf8c |
$nlineTxt = " #####";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
$nlineTxt = sprintf( "%9d", $nlines );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
$linenumTxt = sprintf( "%5d", $s1linenum );
|
|
Packit Service |
c5cf8c |
$out = "$nlineTxt:$linenumTxt:$s1line\n";
|
|
Packit Service |
c5cf8c |
#$out = "$nlines:$s1linenum:$s1line\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
# This outputs both lines
|
|
Packit Service |
c5cf8c |
$out = $s1 . $s2;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
$out = $s1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print $out;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# One of the two files has reached the EOF. Copy out the rest of the other file
|
|
Packit Service |
c5cf8c |
while (!eof(I1)) {
|
|
Packit Service |
c5cf8c |
$s1 = <I1>;
|
|
Packit Service |
c5cf8c |
print $s1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
while (!eof(I2)) {
|
|
Packit Service |
c5cf8c |
$s2 = <I2>;
|
|
Packit Service |
c5cf8c |
print $s2;
|
|
Packit Service |
c5cf8c |
}
|