# Copyright (C) 2003,2008 MySQL AB # Copyright (C) 2010,2017 Sergei Golubchik and MariaDB Corporation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
# Run gcov and report test coverage on only those code lines touched by # a given list of commits.
use strict;
use warnings;
use Getopt::Long;
use File::Find;
use Cwd qw/realpath/;
my $opt_verbose=0;
my $opt_generate;
my $opt_help;
my $opt_purge;
my $opt_only_gcov;
my $opt_skip_gcov;
The dgcov program runs gcov for code coverage analysis, and reports missing
coverage only for those lines that are changed by the specified commit(s).
Commits are specified in the format of git diff arguments. For example:
* All unpushed commits: $0 \@{u} HEAD
* All uncommitted changes: $0 HEAD
* Specific commit: $0 <commit>^ <commit>
If no arguments are specified, it prints the coverage forall uncommitted
changes, if any, otherwise for the last commit.
Options:
-h --help This help.
-v --verbose Show commands run.
-p --purge Deleteall test coverage information, to prepare for a
new coverage test.
-o --only-gcov Stop after running gcov, don't run git
-s --skip-gcov Do not run gcov, assume .gcov files are already in place
-g --generate Create .dgcov files forall source files
Prior to running this tool, MariaDB should be built with
cmake -DENABLE_GCOV=ON
and the testsuite should be run. dgcov will report the coverage forall lines modified in the specified commits. END
exit 1;
}
sub gcov_one_file {
return unless /\.gcda$/;
unless ($opt_skip_gcov) {
$cmd= "gcov -il '$_' 2>/dev/null >/dev/null";
print STDERR ++$file_no,"\r"if not $opt_verbose and -t STDERR;
logv "Running: $cmd";
system($cmd)==0 or die "system($cmd): $? $!";
}
(my $filename = $_)=~ s/\.[^.]+$//; # remove extension
my $gcov_file_path= $File::Find::dir."/$filename.gcov"; if (! -f $gcov_file_path)
{
return;
} # now, read the generated file if ($gcc_version <9){ for my $gcov_file (<$_*.gcov>) {
open FH, '<', "$gcov_file_path" or die "open(<$gcov_file_path): $!";
my $fname; while (<FH>) {
chomp; if (/^function:/) {
next;
} if (/^file:/) {
$fname=realpath(-f $' ? $' : $root.$');
next;
}
next if /^lcount:\d+,-\d+/; # whatever that means
unless (/^lcount:(\d+),(\d+)/ and $fname) {
warn "unknown line '$_' in $gcov_file_path";
next;
}
$cov{$fname}->{$1}+=$2;
}
close(FH);
}
} else {
require IO::Uncompress::Gunzip;
require JSON::PP;
no warnings 'once';
my $gcov_file_json;
s/\.gcda$// if $gcc_version >= 11;
IO::Uncompress::Gunzip::gunzip("$_.gcov.json.gz", \$gcov_file_json)
or die "gunzip($_.gcov.json.gz): $IO::Uncompress::Gunzip::GunzipError";
my $obj= JSON::PP::decode_json $gcov_file_json; for my $file (@{$obj->{files}}) { for my $line (@{$file->{lines}}){
$cov{$file->{file}}->{$line->{line_number}}+= $line->{count};
}
}
}
}
sub write_coverage {
my $fn=$File::Find::name;
my $h=$cov{$fn};
return unless $h and $root eq substr $fn, 0, length($root);
open I, '<', $fn or die "open(<$fn): $!";
open O, '>', "$fn.dgcov" or die "open(>$fn.dgcov): $!";
logv "Annotating: ", substr $fn, length($root); while (<I>) {
printf O '%9s:%5s:%s', gcov_prefix($h->{$.}), $., $_;
}
close I;
close O;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.18 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.