|
Packit Service |
c5cf8c |
#! /usr/bin/env perl
|
|
Packit Service |
c5cf8c |
# -*- Mode:perl ; -*-
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# This file converts a coverate data file, produced by the simple coverage
|
|
Packit Service |
c5cf8c |
# package, into an html file showing the covered and uncovered parts of the
|
|
Packit Service |
c5cf8c |
# code.
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# The format of the simple coverage package data is
|
|
Packit Service |
c5cf8c |
# routine \t nargs \t #calls \t sourcefile \t first-line \t last-line \n
|
|
Packit Service |
c5cf8c |
# sorted by routine name and number of arguments.
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# NOT YET WRITTEN
|
|
Packit Service |
c5cf8c |
# This program reads the data file; then takes each different source file
|
|
Packit Service |
c5cf8c |
# and creates a simple HTML version, using color to accent uncovered and
|
|
Packit Service |
c5cf8c |
# covered code
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# First step:
|
|
Packit Service |
c5cf8c |
# read file. Save data as
|
|
Packit Service |
c5cf8c |
# %SourceFiles{ name } => internal hash name
|
|
Packit Service |
c5cf8c |
# %internalhashname{ firstline } => "lastline:routine:argcount:ncall"
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# Then we can sort on the keys and the use that for "next line with covered"
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# Reading the source code, we check each
|
|
Packit Service |
c5cf8c |
# COVERAGE_BEGIN/END
|
|
Packit Service |
c5cf8c |
# for a corresponding entry in the data (in internalhashname). Surround
|
|
Packit Service |
c5cf8c |
# the block with pale green or red if covered or uncovered.
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sub ReadCovData {
|
|
Packit Service |
c5cf8c |
my $filename = $_[0];
|
|
Packit Service |
c5cf8c |
my $srccnt = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open FD, "<$filename" || die "Could not open coverage file $filename\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (<FD>) {
|
|
Packit Service |
c5cf8c |
chomp;
|
|
Packit Service |
c5cf8c |
my ($routine,$argcnt,$callcnt,$srcfile,$firstline,$lastline) =
|
|
Packit Service |
c5cf8c |
split(/\t/,$_);
|
|
Packit Service |
c5cf8c |
if (!defined($SourceFiles{$srcfile})) {
|
|
Packit Service |
c5cf8c |
$srccnt++;
|
|
Packit Service |
c5cf8c |
$srchash = "srchash$srccnt";
|
|
Packit Service |
c5cf8c |
$SourceFiles{$srcfile} = $srchash;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
$srchash = $SourceFiles{$srcfile};
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
$$srchash{$firstline} = "$lastline\t$routine\t$argcnt\t$callcnt";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
close FD;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# For debugging
|
|
Packit Service |
c5cf8c |
sub DebugWriteCovData {
|
|
Packit Service |
c5cf8c |
foreach my $srcfile (keys(%SourceFiles)) {
|
|
Packit Service |
c5cf8c |
my $srchash = $SourceFiles{$srcfile};
|
|
Packit Service |
c5cf8c |
print "srchash = $srchash\n";
|
|
Packit Service |
c5cf8c |
foreach my $line (sort(keys(%$srchash))) {
|
|
Packit Service |
c5cf8c |
print "$line\t$$srchash{$line}\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Read a source file and annotate it based on the information in the
|
|
Packit Service |
c5cf8c |
# srchash
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# There are three states for the annoted file:
|
|
Packit Service |
c5cf8c |
# nocode - not within a coverage block
|
|
Packit Service |
c5cf8c |
# incov - within AND covered
|
|
Packit Service |
c5cf8c |
# uncov - within and NOT covered
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
%annotecolors = ( "nocode" => "white",
|
|
Packit Service |
c5cf8c |
"incov" => "lightgreen",
|
|
Packit Service |
c5cf8c |
"uncov" => "red",
|
|
Packit Service |
c5cf8c |
);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Save routine => file:line
|
|
Packit Service |
c5cf8c |
%coveredRoutines = ();
|
|
Packit Service |
c5cf8c |
%uncoveredRoutines = ();
|
|
Packit Service |
c5cf8c |
sub ReadAndAnnoteSrcfile {
|
|
Packit Service |
c5cf8c |
my $srcfile = $_[0];
|
|
Packit Service |
c5cf8c |
my $srchash = $_[1]; # *name* of the source hash
|
|
Packit Service |
c5cf8c |
my $annotefile = $_[2];
|
|
Packit Service |
c5cf8c |
my $linecount = 0;
|
|
Packit Service |
c5cf8c |
my $state = "nocode", $newstate;
|
|
Packit Service |
c5cf8c |
my $bgcolor, $newcolor;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
$bgcolor = $annotecolors{$state};
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open FD, "<$srcfile" || die "Cannot open source file $srcfile\n";
|
|
Packit Service |
c5cf8c |
open OUTFD, ">$annotefile" || die "Cannot open annotation file $annotefile\n";
|
|
Packit Service |
c5cf8c |
&WriteHTMLHeader( OUTFD, "Coverage file for $srcfile" );
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print OUTFD "
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (<FD>) {
|
|
Packit Service |
c5cf8c |
$linecount ++;
|
|
Packit Service |
c5cf8c |
if (/COVERAGE_START\(([^,]*),([^\)]*)\)/) {
|
|
Packit Service |
c5cf8c |
my $routine = $1;
|
|
Packit Service |
c5cf8c |
my $argcnt = $2;
|
|
Packit Service |
c5cf8c |
my $rname = "$routine-$argcnt";
|
|
Packit Service |
c5cf8c |
if (defined($$srchash{$linecount})) {
|
|
Packit Service |
c5cf8c |
$newstate = "incov";
|
|
Packit Service |
c5cf8c |
$coveredRoutines{$rname} = "$srcfile:$linecount";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
$newstate = "uncov";
|
|
Packit Service |
c5cf8c |
$uncoveredRoutines{$rname} = "$srcfile:$linecount";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
elsif (/COVERAGE_END/) {
|
|
Packit Service |
c5cf8c |
$newstate = "nocode";
|
|
Packit Service |
c5cf8c |
print OUTFD &HTMLify( $_ );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if ($newstate eq $state) {
|
|
Packit Service |
c5cf8c |
print OUTFD &HTMLify( $_ );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
else {
|
|
Packit Service |
c5cf8c |
# State transitions happen at either the beginning or the
|
|
Packit Service |
c5cf8c |
# If at the end, the line has already been output.
|
|
Packit Service |
c5cf8c |
print OUTFD "\n";
|
|
Packit Service |
c5cf8c |
$state = $newstate;
|
|
Packit Service |
c5cf8c |
$bgcolor = $annotecolors{$state};
|
|
Packit Service |
c5cf8c |
print OUTFD "
|
|
Packit Service |
c5cf8c |
if ($newstate ne "nocode") {
|
|
Packit Service |
c5cf8c |
print OUTFD &HTMLify( $_ );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# Finish off the last table.
|
|
Packit Service |
c5cf8c |
print OUTFD "\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
close FD;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
&WriteHTMLTrailer( OUTFD );
|
|
Packit Service |
c5cf8c |
close OUTFD;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Summary report
|
|
Packit Service |
c5cf8c |
# TODO : compare the routines found to a master list of all routines.
|
|
Packit Service |
c5cf8c |
# generate a third list of unseen routines
|
|
Packit Service |
c5cf8c |
$maxcol = 4;
|
|
Packit Service |
c5cf8c |
sub CoverageSummary {
|
|
Packit Service |
c5cf8c |
my ($filename) = @_;
|
|
Packit Service |
c5cf8c |
my $col;
|
|
Packit Service |
c5cf8c |
my %unseenRoutines = %allRoutines;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
open FD, ">$filename" || die "Cannot open summary file $filename\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
&WriteHTMLHeader( FD, "Coverage Summary" );
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print FD "Covered routines\n";
|
|
Packit Service |
c5cf8c |
print FD "";
|
|
Packit Service |
c5cf8c |
$col = 1;
|
|
Packit Service |
c5cf8c |
foreach $name (sort(keys(%coveredRoutines))) {
|
|
Packit Service |
c5cf8c |
if ($col == 1) { print FD ""; }
|
|
Packit Service |
c5cf8c |
my ($routine,$argcnt) = split(/-/,$name);
|
|
Packit Service |
c5cf8c |
print FD "$routine";
|
|
Packit Service |
c5cf8c |
if (defined($unseenRoutines{$routine})) {
|
|
Packit Service |
c5cf8c |
delete $unseenRoutines{$routine};
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ($col++ == $maxcol) {$col = 1; print FD "\n"; }
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
while ($col != 1) {
|
|
Packit Service |
c5cf8c |
print FD "";
|
|
Packit Service |
c5cf8c |
if ($col++ == $maxcol) {$col = 1; print FD "\n"; }
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
print FD "\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print FD "Uncovered routines\n";
|
|
Packit Service |
c5cf8c |
print FD "";
|
|
Packit Service |
c5cf8c |
$col = 1;
|
|
Packit Service |
c5cf8c |
foreach $name (sort(keys(%uncoveredRoutines))) {
|
|
Packit Service |
c5cf8c |
if ($col == 1) { print FD ""; }
|
|
Packit Service |
c5cf8c |
my ($routine,$argcnt) = split(/-/,$name);
|
|
Packit Service |
c5cf8c |
my $where = $uncoveredRoutines{$name};
|
|
Packit Service |
c5cf8c |
$where =~ s/.*\///;
|
|
Packit Service |
c5cf8c |
print FD "$routine($where)";
|
|
Packit Service |
c5cf8c |
if ($col++ == $maxcol) {$col = 1; print FD "\n"; }
|
|
Packit Service |
c5cf8c |
if (defined($unseenRoutines{$routine})) {
|
|
Packit Service |
c5cf8c |
delete $unseenRoutines{$routine};
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
while ($col != 1) {
|
|
Packit Service |
c5cf8c |
print FD "";
|
|
Packit Service |
c5cf8c |
if ($col++ == $maxcol) {$col = 1; print FD "\n"; }
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
print FD "\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print FD "Unseen routines\n";
|
|
Packit Service |
c5cf8c |
print FD "";
|
|
Packit Service |
c5cf8c |
$col = 1;
|
|
Packit Service |
c5cf8c |
foreach $name (sort(keys(%unseenRoutines))) {
|
|
Packit Service |
c5cf8c |
if ($col == 1) { print FD ""; }
|
|
Packit Service |
c5cf8c |
my $routine = $name;
|
|
Packit Service |
c5cf8c |
print FD "$routine";
|
|
Packit Service |
c5cf8c |
if ($col++ == $maxcol) {$col = 1; print FD "\n"; }
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
while ($col != 1) {
|
|
Packit Service |
c5cf8c |
print FD "";
|
|
Packit Service |
c5cf8c |
if ($col++ == $maxcol) {$col = 1; print FD "\n"; }
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
print FD "\n";
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
&WriteHTMLTrailer( FD );
|
|
Packit Service |
c5cf8c |
close FD;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
%coveredRoutines = ();
|
|
Packit Service |
c5cf8c |
%uncoveredRoutines = ();
|
|
Packit Service |
c5cf8c |
%allRoutines = (); # Not yet used
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
sub ReadAllList {
|
|
Packit Service |
c5cf8c |
my $filename = $_[0];
|
|
Packit Service |
c5cf8c |
open FD, "<$filename" || return 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
while (<FD>) {
|
|
Packit Service |
c5cf8c |
chomp;
|
|
Packit Service |
c5cf8c |
s/\r//;
|
|
Packit Service |
c5cf8c |
$allRoutines{$_} = 1;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
close FD;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# --------------------------------------------------------------------------
|
|
Packit Service |
c5cf8c |
sub WriteHTMLHeader {
|
|
Packit Service |
c5cf8c |
my ($FD,$title) = @_;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print $FD "<HTML>\n<HEAD>\n<TITLE>$title</TITLE></HEAD>\n";
|
|
Packit Service |
c5cf8c |
print $FD "<BODY BGCOLOR=\"FFFFFF\">\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
sub WriteHTMLTrailer {
|
|
Packit Service |
c5cf8c |
my $FD = $_[0];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
print $FD "</BODY>\n</HTML>\n";
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# HTMLify
|
|
Packit Service |
c5cf8c |
# Take an input line and make it value HTML
|
|
Packit Service |
c5cf8c |
sub HTMLify {
|
|
Packit Service |
c5cf8c |
my $line = $_[0];
|
|
Packit Service |
c5cf8c |
$line =~ s/\&/--AMP--/g;
|
|
Packit Service |
c5cf8c |
$line =~ s/>/>/g;
|
|
Packit Service |
c5cf8c |
$line =~ s/</</g;
|
|
Packit Service |
c5cf8c |
$line =~ s/--AMP--/&/g;
|
|
Packit Service |
c5cf8c |
return $line;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
# --------------------------------------------------------------------------
|
|
Packit Service |
c5cf8c |
#
|
|
Packit Service |
c5cf8c |
# Temp for testing
|
|
Packit Service |
c5cf8c |
&ReadAllList( "mpi.dat" );
|
|
Packit Service |
c5cf8c |
# Remove those deprecated MPI routines that are not in the C++ binding
|
|
Packit Service |
c5cf8c |
# FIXME: Check that C++ binding does not include these
|
|
Packit Service |
c5cf8c |
foreach my $oldname ("Type_ub", "Type_lb", "Attr_delete", "Attr_get",
|
|
Packit Service |
c5cf8c |
"Attr_put", "Keyval_free", "Keyval_create",
|
|
Packit Service |
c5cf8c |
"Errhandler_get", "Errhandler_set",
|
|
Packit Service |
c5cf8c |
"Errhandler_create", "Address", "Type_struct",
|
|
Packit Service |
c5cf8c |
"Type_extent", "Type_hvector", "Type_hindexed" ) {
|
|
Packit Service |
c5cf8c |
delete $allRoutines{$oldname};
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
&ReadCovData( "cov.dat" );
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
# Generate the output
|
|
Packit Service |
c5cf8c |
foreach $srcfile (keys(%SourceFiles)) {
|
|
Packit Service |
c5cf8c |
my $srchash = $SourceFiles{$srcfile};
|
|
Packit Service |
c5cf8c |
my $annotefile;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
$annotefile = $srcfile;
|
|
Packit Service |
c5cf8c |
# Still needed: A way to update the directory paths. This
|
|
Packit Service |
c5cf8c |
# simply removes -all- directories. We may instead
|
|
Packit Service |
c5cf8c |
# want a way to remove a prefix only
|
|
Packit Service |
c5cf8c |
$annotefile =~ s/.*\///g;
|
|
Packit Service |
c5cf8c |
$annotefile .= ".htm";
|
|
Packit Service |
c5cf8c |
print "annote file = $annotefile\n";
|
|
Packit Service |
c5cf8c |
&ReadAndAnnoteSrcfile( $srcfile, $srchash, $annotefile );
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
&CoverageSummary( "cov.sum.htm" );
|