List:Commits« Previous MessageNext Message »
From:Rafal Somla Date:June 19 2009 2:33pm
Subject:bzr commit into mysql-6.0-backup branch (Rafal.Somla:2827)
View as plain text  
#At file:///ext/mysql/bzr/backup/lcov/ based on revid:jorgen.loland@stripped

 2827 Rafal Somla	2009-06-19
      A patch for mysql-test/mysql-test-lcov.pl script which makes it 
      honour purecov annotations and not include such annotated lines
      in the coverage report.
     @ mysql-test/mysql-test-lcov.pl
        The lines which are purecov annotated are removed from the lcov
        output file before it is processed with genhtml. Option
        --no-checksum must be given to lcov as otherwise checksums are
        violated by removing lines.

    modified:
      mysql-test/mysql-test-lcov.pl
=== modified file 'mysql-test/mysql-test-lcov.pl'
--- a/mysql-test/mysql-test-lcov.pl	2009-03-10 11:30:19 +0000
+++ b/mysql-test/mysql-test-lcov.pl	2009-06-19 14:33:10 +0000
@@ -83,6 +83,7 @@ usage() if $opt_help;
 #
 my $cmd;
 my $res;
+my %ignore;
 
 #
 # Hide EXCLUDE_FILES
@@ -178,7 +179,7 @@ hide_exclude_files();
 #
 # LCOV
 #
-$cmd= "lcov -q -c -f -d . -o $RESULT_DIR/lcov.info";
+$cmd= "lcov -q -c --no-checksum -f -d . -o $RESULT_DIR/lcov.info";
 print STDERR "Running: $cmd\n" if !$opt_quiet;
 $res= system($cmd);
 if ($res)
@@ -188,6 +189,18 @@ if ($res)
 }
 
 #
+# Purge annotated lines.
+#
+eval {
+  purge_annotated("$RESULT_DIR/lcov.info");
+};
+if ($@)
+{
+  recover_exclude_files();
+  die $@;
+}
+
+#
 # GENHTML
 #
 $cmd= "genhtml -q --prefix=`pwd` -o $RESULT_DIR " .
@@ -207,3 +220,140 @@ recover_exclude_files();
 
 print "Result is in $RESULT_DIR/index.html\n";
 
+
+sub purge_annotated
+{
+  print STDERR "Purging annotated lines\n" if !$opt_quiet;
+
+  my $lcov_file= shift;
+  my $line;
+  my $skip= 0;
+  my $file;
+  my $skip_count;
+
+  unlink "$lcov_file.orig";
+  rename "$lcov_file", "$lcov_file.orig";
+
+  eval
+  {
+    open IN, '<', "$lcov_file.orig"
+     or die "Could not open $lcov_file for reading";
+
+    open OUT, '>', "$lcov_file"
+     or die "Could not open $lcov_file for writing";
+
+    while ($line= <IN>)
+    {
+      $skip= 0;
+      $_= $line;
+
+      #
+      # lcov records are delimited by "SF:<source file>" and "end_of_record" 
+      # lines.
+      #
+      next unless (/^SF:/ ... /^end_of_record/);
+
+      #
+      # When first line of a record is found, read the file path and scan it
+      # for annotated lines.
+      #
+      if (/^SF:(.*)$/)
+      {
+        $file= $1;
+        $skip_count= 0;
+        # print STDERR "Processing file $file\n";
+        #
+        # Scan source file for annotated lines. Lines which should be ignored
+        # are put in %ignore hash.
+        #
+        find_annotations($file);
+        next;
+      }
+
+      #
+      # DA lines contain execution counts for each line. If line is to be 
+      # ignored, then the corresponding DA line is skipped.
+      #
+      if (/^DA:(\d+),(\d+)/)
+      {
+        my ($lnum,$lcount)= ($1, $2);
+
+        if ($ignore{$lnum})
+        {
+          #print STDERR "Skipping line $lnum\n";
+          ++$skip_count;
+          $skip=1;
+          next;
+        }
+      }
+
+      #
+      # LF line contains the number of lines which are traced for coverage.
+      # We subtract from it the number of lines which were skipped.
+      #
+      if (/^LF:(\d+)/)
+      {
+        my $howmuch= $1-$skip_count;
+        print OUT "LF:$howmuch\n";
+        $skip=1;
+        next;
+      }
+
+    }
+    continue
+    {
+      print OUT $line unless $skip;
+    }	# while
+
+  }; # eval
+
+  close OUT;
+  close IN;
+
+  if ($@)
+  {
+    rename "$lcov_file.orig", "$lcov_file";
+    die $@;
+  }
+  else
+  {
+    unlink "$lcov_file.orig";
+  }
+}
+
+sub find_annotations
+{
+  my $file= shift;
+  my $lnum= 0;
+
+  #print STDERR "Looking for annotated lines in $file\n";
+
+  %ignore= ();
+  my $annotation= undef;
+
+
+  open FH, '<', $file
+   or die "Could not open source $file\n";
+
+  while (<FH>)
+  {
+    ++$lnum;
+
+    if (m!/\*\s+purecov\s*:\s*begin\s+(inspected|tested|deadcode)!
+        .. m!/\*\s+purecov\s*:\s*end!)
+    {
+      $ignore{$lnum}= 1;
+      next;
+    }
+
+    if (m!/\*\s+purecov\s*:\s*(inspected|tested|deadcode)!)
+    {
+      $ignore{$lnum}= 1;
+    }
+
+  } continue {
+   # print STDERR "Ignoring line $lnum in $file\n" if $ignore{$lnum};
+  }
+
+  close FH;
+}


Attachment: [text/bzr-bundle] bzr/rafal.somla@sun.com-20090619143310-a007qqsv2qbvd32k.bundle
Thread
bzr commit into mysql-6.0-backup branch (Rafal.Somla:2827)Rafal Somla19 Jun