Unverified 提交 c4f56e5b authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Remove lcov dep from the repo (#1288)

上级 28ff4a73
......@@ -30,6 +30,8 @@
# Ignore all fuzzer generated test inputs.
/worker/fuzzer/new-corpus/*
!/worker/fuzzer/new-corpus/.placeholder
# lcov is just for local usage.
/worker/lcov
## Others.
/coverage
......
.version
*.gcda
*.gcno
*.info
*.tar.gz
*.rpm
Contributing to LCOV
====================
Please read this document if you would like to help improving the LTP GCOV
extension (LCOV). In general, all types of contributions are welcome, for
example:
* Fixes for code or documentation
* Performance and compatibility improvements
* Functional enhancements
There are some rules that these contributions must follow to be acceptable for
inclusion:
1. The contribution must align with the project goals of LCOV.
2. The contribution must follow a particular format.
3. The contribution must be signed.
Once you have made sure that your contribution follows these rules, send it via
e-mail to the LTP coverage mailing list [1].
Signing your work
=================
All contributions to LCOV must be signed by putting the following line at the
end of the explanation of a patch:
Signed-off-by: Your Name <your.email@example.org>
By signing a patch, you certify the following:
By making a contribution to the LTP GCOV extension (LCOV) on
http://ltp.sourceforge.net, I certify that:
a) The contribution was created by me and I have the right to submit it
under the terms and conditions of the open source license
"GNU General Public License, version 2 or later".
(http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
b) The contribution is made free of any other party's intellectual property
claims or rights.
c) I understand and agree that this project and the contribution are public
and that a record of the contribution (including all personal information
I submit with it, including my sign-off) is maintained indefinitely and
may be redistributed consistent with this project or the open source
license(s) involved.
Project goals
=============
The goal of LCOV is to provide a set of command line tools that can be used to
collect, process and visualize code coverage data as produced by the gcov tool
that is part of the GNU Compiler Collection (GCC) [2].
If you have an idea for a contribution but are unsure if it aligns with the
project goals, feel free to discuss the idea on the LTP coverage mailing
list [1].
Contribution format
===================
To contribute a change, please create a patch using 'git format-patch'.
Alternatively you can use the diff utility with the following command line
options:
diff -Naurp
Please base your changes on the most current version of LCOV. You can use the
following command line to obtain this version from the lcov Git repository:
git clone https://github.com/linux-test-project/lcov.git
Add a meaningful description of the contribution to the top of the patch. The
description should follow this format:
component: short description
detailed description
Signed-off-by: Your Name <your.email@example.org>
With your Signed-off-by, you certify the rules stated in section
"Signing your work".
--
[1] ltp-coverage@lists.sourceforge.net
[2] http://gcc.gnu.org
差异被折叠。
#
# Makefile for LCOV
#
# Make targets:
# - install: install LCOV tools and man pages on the system
# - uninstall: remove tools and man pages from the system
# - dist: create files required for distribution, i.e. the lcov.tar.gz
# and the lcov.rpm file. Just make sure to adjust the VERSION
# and RELEASE variables below - both version and date strings
# will be updated in all necessary files.
# - clean: remove all generated files
#
VERSION := $(shell bin/get_version.sh --version)
RELEASE := $(shell bin/get_version.sh --release)
FULL := $(shell bin/get_version.sh --full)
# Set this variable during 'make install' to specify the Perl interpreter used in
# installed scripts, or leave empty to keep the current interpreter.
export LCOV_PERL_PATH := /usr/bin/perl
PREFIX := /usr/local
CFG_DIR := $(PREFIX)/etc
BIN_DIR := $(PREFIX)/bin
MAN_DIR := $(PREFIX)/share/man
TMP_DIR := $(shell mktemp -d)
FILES := $(wildcard bin/*) $(wildcard man/*) README Makefile \
$(wildcard rpm/*) lcovrc
.PHONY: all info clean install uninstall rpms test
all: info
info:
@echo "Available make targets:"
@echo " install : install binaries and man pages in DESTDIR (default /)"
@echo " uninstall : delete binaries and man pages from DESTDIR (default /)"
@echo " dist : create packages (RPM, tarball) ready for distribution"
@echo " test : perform self-tests"
clean:
rm -f lcov-*.tar.gz
rm -f lcov-*.rpm
make -C example clean
make -C test -s clean
install:
bin/install.sh bin/lcov $(DESTDIR)$(BIN_DIR)/lcov -m 755
bin/install.sh bin/genhtml $(DESTDIR)$(BIN_DIR)/genhtml -m 755
bin/install.sh bin/geninfo $(DESTDIR)$(BIN_DIR)/geninfo -m 755
bin/install.sh bin/genpng $(DESTDIR)$(BIN_DIR)/genpng -m 755
bin/install.sh bin/gendesc $(DESTDIR)$(BIN_DIR)/gendesc -m 755
bin/install.sh man/lcov.1 $(DESTDIR)$(MAN_DIR)/man1/lcov.1 -m 644
bin/install.sh man/genhtml.1 $(DESTDIR)$(MAN_DIR)/man1/genhtml.1 -m 644
bin/install.sh man/geninfo.1 $(DESTDIR)$(MAN_DIR)/man1/geninfo.1 -m 644
bin/install.sh man/genpng.1 $(DESTDIR)$(MAN_DIR)/man1/genpng.1 -m 644
bin/install.sh man/gendesc.1 $(DESTDIR)$(MAN_DIR)/man1/gendesc.1 -m 644
bin/install.sh man/lcovrc.5 $(DESTDIR)$(MAN_DIR)/man5/lcovrc.5 -m 644
bin/install.sh lcovrc $(DESTDIR)$(CFG_DIR)/lcovrc -m 644
bin/updateversion.pl $(DESTDIR)$(BIN_DIR)/lcov $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(BIN_DIR)/genhtml $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(BIN_DIR)/geninfo $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(BIN_DIR)/genpng $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(BIN_DIR)/gendesc $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(MAN_DIR)/man1/lcov.1 $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(MAN_DIR)/man1/genhtml.1 $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(MAN_DIR)/man1/geninfo.1 $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(MAN_DIR)/man1/genpng.1 $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(MAN_DIR)/man1/gendesc.1 $(VERSION) $(RELEASE) $(FULL)
bin/updateversion.pl $(DESTDIR)$(MAN_DIR)/man5/lcovrc.5 $(VERSION) $(RELEASE) $(FULL)
uninstall:
bin/install.sh --uninstall bin/lcov $(DESTDIR)$(BIN_DIR)/lcov
bin/install.sh --uninstall bin/genhtml $(DESTDIR)$(BIN_DIR)/genhtml
bin/install.sh --uninstall bin/geninfo $(DESTDIR)$(BIN_DIR)/geninfo
bin/install.sh --uninstall bin/genpng $(DESTDIR)$(BIN_DIR)/genpng
bin/install.sh --uninstall bin/gendesc $(DESTDIR)$(BIN_DIR)/gendesc
bin/install.sh --uninstall man/lcov.1 $(DESTDIR)$(MAN_DIR)/man1/lcov.1
bin/install.sh --uninstall man/genhtml.1 $(DESTDIR)$(MAN_DIR)/man1/genhtml.1
bin/install.sh --uninstall man/geninfo.1 $(DESTDIR)$(MAN_DIR)/man1/geninfo.1
bin/install.sh --uninstall man/genpng.1 $(DESTDIR)$(MAN_DIR)/man1/genpng.1
bin/install.sh --uninstall man/gendesc.1 $(DESTDIR)$(MAN_DIR)/man1/gendesc.1
bin/install.sh --uninstall man/lcovrc.5 $(DESTDIR)$(MAN_DIR)/man5/lcovrc.5
bin/install.sh --uninstall lcovrc $(DESTDIR)$(CFG_DIR)/lcovrc
dist: lcov-$(VERSION).tar.gz lcov-$(VERSION)-$(RELEASE).noarch.rpm \
lcov-$(VERSION)-$(RELEASE).src.rpm
lcov-$(VERSION).tar.gz: $(FILES)
mkdir $(TMP_DIR)/lcov-$(VERSION)
cp -r * $(TMP_DIR)/lcov-$(VERSION)
bin/copy_dates.sh . $(TMP_DIR)/lcov-$(VERSION)
make -C $(TMP_DIR)/lcov-$(VERSION) clean
bin/updateversion.pl $(TMP_DIR)/lcov-$(VERSION) $(VERSION) $(RELEASE) $(FULL)
bin/get_changes.sh > $(TMP_DIR)/lcov-$(VERSION)/CHANGES
cd $(TMP_DIR) ; \
tar cfz $(TMP_DIR)/lcov-$(VERSION).tar.gz lcov-$(VERSION)
mv $(TMP_DIR)/lcov-$(VERSION).tar.gz .
rm -rf $(TMP_DIR)
lcov-$(VERSION)-$(RELEASE).noarch.rpm: rpms
lcov-$(VERSION)-$(RELEASE).src.rpm: rpms
rpms: lcov-$(VERSION).tar.gz
mkdir $(TMP_DIR)
mkdir $(TMP_DIR)/BUILD
mkdir $(TMP_DIR)/RPMS
mkdir $(TMP_DIR)/SOURCES
mkdir $(TMP_DIR)/SRPMS
cp lcov-$(VERSION).tar.gz $(TMP_DIR)/SOURCES
cd $(TMP_DIR)/BUILD ; \
tar xfz $(TMP_DIR)/SOURCES/lcov-$(VERSION).tar.gz \
lcov-$(VERSION)/rpm/lcov.spec
rpmbuild --define '_topdir $(TMP_DIR)' \
-ba $(TMP_DIR)/BUILD/lcov-$(VERSION)/rpm/lcov.spec
mv $(TMP_DIR)/RPMS/noarch/lcov-$(VERSION)-$(RELEASE).noarch.rpm .
mv $(TMP_DIR)/SRPMS/lcov-$(VERSION)-$(RELEASE).src.rpm .
rm -rf $(TMP_DIR)
test:
@make -C test -s all
-------------------------------------------------
- README file for the LTP GCOV extension (LCOV) -
- Last changes: 2016-12-19 -
-------------------------------------------------
Description
-----------
LCOV is an extension of GCOV, a GNU tool which provides information about
what parts of a program are actually executed (i.e. "covered") while running
a particular test case. The extension consists of a set of Perl scripts
which build on the textual GCOV output to implement the following enhanced
functionality:
* HTML based output: coverage rates are additionally indicated using bar
graphs and specific colors.
* Support for large projects: overview pages allow quick browsing of
coverage data by providing three levels of detail: directory view,
file view and source code view.
LCOV was initially designed to support Linux kernel coverage measurements,
but works as well for coverage measurements on standard user space
applications.
Further README contents
-----------------------
1. Included files
2. Installing LCOV
3. An example of how to access kernel coverage data
4. An example of how to access coverage data for a user space program
5. Questions and Comments
1. Important files
------------------
README - This README file
CHANGES - List of changes between releases
bin/lcov - Tool for capturing LCOV coverage data
bin/genhtml - Tool for creating HTML output from LCOV data
bin/gendesc - Tool for creating description files as used by genhtml
bin/geninfo - Internal tool (creates LCOV data files)
bin/genpng - Internal tool (creates png overviews of source files)
bin/install.sh - Internal tool (takes care of un-/installing)
man - Directory containing man pages for included tools
example - Directory containing an example to demonstrate LCOV
lcovrc - LCOV configuration file
Makefile - Makefile providing 'install' and 'uninstall' targets
2. Installing LCOV
------------------
The LCOV package is available as either RPM or tarball from:
http://ltp.sourceforge.net/coverage/lcov.php
To install the tarball, unpack it to a directory and run:
make install
Use Git for the most recent (but possibly unstable) version:
git clone https://github.com/linux-test-project/lcov.git
Change to the resulting lcov directory and type:
make install
3. An example of how to access kernel coverage data
---------------------------------------------------
Requirements: get and install the gcov-kernel package from
http://sourceforge.net/projects/ltp
Copy the resulting gcov kernel module file to either the system wide modules
directory or the same directory as the Perl scripts. As root, do the following:
a) Resetting counters
lcov --zerocounters
b) Capturing the current coverage state to a file
lcov --capture --output-file kernel.info
c) Getting HTML output
genhtml kernel.info
Point the web browser of your choice to the resulting index.html file.
4. An example of how to access coverage data for a user space program
---------------------------------------------------------------------
Requirements: compile the program in question using GCC with the options
-fprofile-arcs and -ftest-coverage. During linking, make sure to specify
-lgcov or -coverage.
Assuming the compile directory is called "appdir", do the following:
a) Resetting counters
lcov --directory appdir --zerocounters
b) Capturing the current coverage state to a file
lcov --directory appdir --capture --output-file app.info
Note that this step only works after the application has
been started and stopped at least once. Otherwise lcov will
abort with an error mentioning that there are no data/.gcda files.
c) Getting HTML output
genhtml app.info
Point the web browser of your choice to the resulting index.html file.
Please note that independently of where the application is installed or
from which directory it is run, the --directory statement needs to
point to the directory in which the application was compiled.
For further information on the gcc profiling mechanism, please also
consult the gcov man page.
5. Questions and comments
-------------------------
See the included man pages for more information on how to use the LCOV tools.
Please email further questions or comments regarding this tool to the
LTP Mailing list at ltp-coverage@lists.sourceforge.net
#!/usr/bin/env bash
#
# Usage: copy_dates.sh SOURCE TARGET
#
# For each file found in SOURCE, set the modification time of the copy of that
# file in TARGET to either the time of the latest Git commit (if SOURCE contains
# a Git repository and the file was not modified after the last commit), or the
# modification time of the original file.
SOURCE="$1"
TARGET="$2"
if [ -z "$SOURCE" -o -z "$TARGET" ] ; then
echo "Usage: $0 SOURCE TARGET" >&2
exit 1
fi
[ -d "$SOURCE/.git" ] ; NOGIT=$?
echo "Copying modification/commit times from $SOURCE to $TARGET"
cd "$SOURCE" || exit 1
find * -type f | while read FILENAME ; do
[ ! -e "$TARGET/$FILENAME" ] && continue
# Copy modification time
touch -m "$TARGET/$FILENAME" -r "$FILENAME"
[ $NOGIT -eq 1 ] && continue # No Git
git diff --quiet -- "$FILENAME" || continue # Modified
git diff --quiet --cached -- "$FILENAME" || continue # Modified
# Apply modification time from Git commit time
TIME=$(git log --pretty=format:%cd -n 1 --date=iso -- "$FILENAME")
[ -n "$TIME" ] && touch -m "$TARGET/$FILENAME" --date "$TIME"
done
#!/usr/bin/env perl
#
# Copyright (c) International Business Machines Corp., 2002
#
# 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; either version 2 of the License, or (at
# your option) any later version.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# gendesc
#
# This script creates a description file as understood by genhtml.
# Input file format:
#
# For each test case:
# <test name><optional whitespace>
# <at least one whitespace character (blank/tab)><test description>
#
# Actual description may consist of several lines. By default, output is
# written to stdout. Test names consist of alphanumeric characters
# including _ and -.
#
#
# History:
# 2002-09-02: created by Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
#
use strict;
use warnings;
use File::Basename;
use Getopt::Long;
use Cwd qw/abs_path/;
# Constants
our $tool_dir = abs_path(dirname($0));
our $lcov_version = 'LCOV version '.`$tool_dir/get_version.sh --full`;
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
our $tool_name = basename($0);
# Prototypes
sub print_usage(*);
sub gen_desc();
sub warn_handler($);
sub die_handler($);
# Global variables
our $help;
our $version;
our $output_filename;
our $input_filename;
#
# Code entry point
#
$SIG{__WARN__} = \&warn_handler;
$SIG{__DIE__} = \&die_handler;
# Parse command line options
if (!GetOptions("output-filename=s" => \$output_filename,
"version" =>\$version,
"help|?" => \$help
))
{
print(STDERR "Use $tool_name --help to get usage information\n");
exit(1);
}
$input_filename = $ARGV[0];
# Check for help option
if ($help)
{
print_usage(*STDOUT);
exit(0);
}
# Check for version option
if ($version)
{
print("$tool_name: $lcov_version\n");
exit(0);
}
# Check for input filename
if (!$input_filename)
{
die("No input filename specified\n".
"Use $tool_name --help to get usage information\n");
}
# Do something
gen_desc();
#
# print_usage(handle)
#
# Write out command line usage information to given filehandle.
#
sub print_usage(*)
{
local *HANDLE = $_[0];
print(HANDLE <<END_OF_USAGE)
Usage: $tool_name [OPTIONS] INPUTFILE
Convert a test case description file into a format as understood by genhtml.
-h, --help Print this help, then exit
-v, --version Print version number, then exit
-o, --output-filename FILENAME Write description to FILENAME
For more information see: $lcov_url
END_OF_USAGE
;
}
#
# gen_desc()
#
# Read text file INPUT_FILENAME and convert the contained description to a
# format as understood by genhtml, i.e.
#
# TN:<test name>
# TD:<test description>
#
# If defined, write output to OUTPUT_FILENAME, otherwise to stdout.
#
# Die on error.
#
sub gen_desc()
{
local *INPUT_HANDLE;
local *OUTPUT_HANDLE;
my $empty_line = "ignore";
open(INPUT_HANDLE, "<", $input_filename)
or die("ERROR: cannot open $input_filename!\n");
# Open output file for writing
if ($output_filename)
{
open(OUTPUT_HANDLE, ">", $output_filename)
or die("ERROR: cannot create $output_filename!\n");
}
else
{
*OUTPUT_HANDLE = *STDOUT;
}
# Process all lines in input file
while (<INPUT_HANDLE>)
{
chomp($_);
if (/^(\w[\w-]*)(\s*)$/)
{
# Matched test name
# Name starts with alphanum or _, continues with
# alphanum, _ or -
print(OUTPUT_HANDLE "TN: $1\n");
$empty_line = "ignore";
}
elsif (/^(\s+)(\S.*?)\s*$/)
{
# Matched test description
if ($empty_line eq "insert")
{
# Write preserved empty line
print(OUTPUT_HANDLE "TD: \n");
}
print(OUTPUT_HANDLE "TD: $2\n");
$empty_line = "observe";
}
elsif (/^\s*$/)
{
# Matched empty line to preserve paragraph separation
# inside description text
if ($empty_line eq "observe")
{
$empty_line = "insert";
}
}
}
# Close output file if defined
if ($output_filename)
{
close(OUTPUT_HANDLE);
}
close(INPUT_HANDLE);
}
sub warn_handler($)
{
my ($msg) = @_;
warn("$tool_name: $msg");
}
sub die_handler($)
{
my ($msg) = @_;
die("$tool_name: $msg");
}
差异被折叠。
差异被折叠。
#!/usr/bin/env perl
#
# Copyright (c) International Business Machines Corp., 2002
#
# 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; either version 2 of the License, or (at
# your option) any later version.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# genpng
#
# This script creates an overview PNG image of a source code file by
# representing each source code character by a single pixel.
#
# Note that the Perl module GD.pm is required for this script to work.
# It may be obtained from http://www.cpan.org
#
# History:
# 2002-08-26: created by Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
#
use strict;
use warnings;
use File::Basename;
use Getopt::Long;
use Cwd qw/abs_path/;
# Constants
our $tool_dir = abs_path(dirname($0));
our $lcov_version = 'LCOV version '.`$tool_dir/get_version.sh --full`;
our $lcov_url = "http://ltp.sourceforge.net/coverage/lcov.php";
our $tool_name = basename($0);
# Prototypes
sub gen_png($$$@);
sub check_and_load_module($);
sub genpng_print_usage(*);
sub genpng_process_file($$$$);
sub genpng_warn_handler($);
sub genpng_die_handler($);
#
# Code entry point
#
# Check whether required module GD.pm is installed
if (check_and_load_module("GD"))
{
# Note: cannot use die() to print this message because inserting this
# code into another script via do() would not fail as required!
print(STDERR <<END_OF_TEXT)
ERROR: required module GD.pm not found on this system (see www.cpan.org).
END_OF_TEXT
;
exit(2);
}
# Check whether we're called from the command line or from another script
if (!caller)
{
my $filename;
my $tab_size = 4;
my $width = 80;
my $out_filename;
my $help;
my $version;
$SIG{__WARN__} = \&genpng_warn_handler;
$SIG{__DIE__} = \&genpng_die_handler;
# Parse command line options
if (!GetOptions("tab-size=i" => \$tab_size,
"width=i" => \$width,
"output-filename=s" => \$out_filename,
"help" => \$help,
"version" => \$version))
{
print(STDERR "Use $tool_name --help to get usage ".
"information\n");
exit(1);
}
$filename = $ARGV[0];
# Check for help flag
if ($help)
{
genpng_print_usage(*STDOUT);
exit(0);
}
# Check for version flag
if ($version)
{
print("$tool_name: $lcov_version\n");
exit(0);
}
# Check options
if (!$filename)
{
die("No filename specified\n");
}
# Check for output filename
if (!$out_filename)
{
$out_filename = "$filename.png";
}
genpng_process_file($filename, $out_filename, $width, $tab_size);
exit(0);
}
#
# genpng_print_usage(handle)
#
# Write out command line usage information to given filehandle.
#
sub genpng_print_usage(*)
{
local *HANDLE = $_[0];
print(HANDLE <<END_OF_USAGE)
Usage: $tool_name [OPTIONS] SOURCEFILE
Create an overview image for a given source code file of either plain text
or .gcov file format.
-h, --help Print this help, then exit
-v, --version Print version number, then exit
-t, --tab-size TABSIZE Use TABSIZE spaces in place of tab
-w, --width WIDTH Set width of output image to WIDTH pixel
-o, --output-filename FILENAME Write image to FILENAME
For more information see: $lcov_url
END_OF_USAGE
;
}
#
# check_and_load_module(module_name)
#
# Check whether a module by the given name is installed on this system
# and make it known to the interpreter if available. Return undefined if it
# is installed, an error message otherwise.
#
sub check_and_load_module($)
{
eval("use $_[0];");
return $@;
}
#
# genpng_process_file(filename, out_filename, width, tab_size)
#
sub genpng_process_file($$$$)
{
my $filename = $_[0];
my $out_filename = $_[1];
my $width = $_[2];
my $tab_size = $_[3];
local *HANDLE;
my @source;
open(HANDLE, "<", $filename)
or die("ERROR: cannot open $filename!\n");
# Check for .gcov filename extension
if ($filename =~ /^(.*).gcov$/)
{
# Assume gcov text format
while (<HANDLE>)
{
if (/^\t\t(.*)$/)
{
# Uninstrumented line
push(@source, ":$1");
}
elsif (/^ ###### (.*)$/)
{
# Line with zero execution count
push(@source, "0:$1");
}
elsif (/^( *)(\d*) (.*)$/)
{
# Line with positive execution count
push(@source, "$2:$3");
}
}
}
else
{
# Plain text file
while (<HANDLE>) { push(@source, ":$_"); }
}
close(HANDLE);
gen_png($out_filename, $width, $tab_size, @source);
}
#
# gen_png(filename, width, tab_size, source)
#
# Write an overview PNG file to FILENAME. Source code is defined by SOURCE
# which is a list of lines <count>:<source code> per source code line.
# The output image will be made up of one pixel per character of source,
# coloring will be done according to execution counts. WIDTH defines the
# image width. TAB_SIZE specifies the number of spaces to use as replacement
# string for tabulator signs in source code text.
#
# Die on error.
#
sub gen_png($$$@)
{
my $filename = shift(@_); # Filename for PNG file
my $overview_width = shift(@_); # Imagewidth for image
my $tab_size = shift(@_); # Replacement string for tab signs
my @source = @_; # Source code as passed via argument 2
my $height; # Height as define by source size
my $overview; # Source code overview image data
my $col_plain_back; # Color for overview background
my $col_plain_text; # Color for uninstrumented text
my $col_cov_back; # Color for background of covered lines
my $col_cov_text; # Color for text of covered lines
my $col_nocov_back; # Color for background of lines which
# were not covered (count == 0)
my $col_nocov_text; # Color for test of lines which were not
# covered (count == 0)
my $col_hi_back; # Color for background of highlighted lines
my $col_hi_text; # Color for text of highlighted lines
my $line; # Current line during iteration
my $row = 0; # Current row number during iteration
my $column; # Current column number during iteration
my $color_text; # Current text color during iteration
my $color_back; # Current background color during iteration
my $last_count; # Count of last processed line
my $count; # Count of current line
my $source; # Source code of current line
my $replacement; # Replacement string for tabulator chars
local *PNG_HANDLE; # Handle for output PNG file
# Handle empty source files
if (!@source) {
@source = ( "" );
}
$height = scalar(@source);
# Create image
$overview = new GD::Image($overview_width, $height)
or die("ERROR: cannot allocate overview image!\n");
# Define colors
$col_plain_back = $overview->colorAllocate(0xff, 0xff, 0xff);
$col_plain_text = $overview->colorAllocate(0xaa, 0xaa, 0xaa);
$col_cov_back = $overview->colorAllocate(0xaa, 0xa7, 0xef);
$col_cov_text = $overview->colorAllocate(0x5d, 0x5d, 0xea);
$col_nocov_back = $overview->colorAllocate(0xff, 0x00, 0x00);
$col_nocov_text = $overview->colorAllocate(0xaa, 0x00, 0x00);
$col_hi_back = $overview->colorAllocate(0x00, 0xff, 0x00);
$col_hi_text = $overview->colorAllocate(0x00, 0xaa, 0x00);
# Visualize each line
foreach $line (@source)
{
# Replace tabs with spaces to keep consistent with source
# code view
while ($line =~ /^([^\t]*)(\t)/)
{
$replacement = " "x($tab_size - ((length($1) - 1) %
$tab_size));
$line =~ s/^([^\t]*)(\t)/$1$replacement/;
}
# Skip lines which do not follow the <count>:<line>
# specification, otherwise $1 = count, $2 = source code
if (!($line =~ /(\*?)(\d*):(.*)$/)) { next; }
$count = $2;
$source = $3;
# Decide which color pair to use
# If this line was not instrumented but the one before was,
# take the color of that line to widen color areas in
# resulting image
if (($count eq "") && defined($last_count) &&
($last_count ne ""))
{
$count = $last_count;
}
if ($count eq "")
{
# Line was not instrumented
$color_text = $col_plain_text;
$color_back = $col_plain_back;
}
elsif ($count == 0)
{
# Line was instrumented but not executed
$color_text = $col_nocov_text;
$color_back = $col_nocov_back;
}
elsif ($1 eq "*")
{
# Line was highlighted
$color_text = $col_hi_text;
$color_back = $col_hi_back;
}
else
{
# Line was instrumented and executed
$color_text = $col_cov_text;
$color_back = $col_cov_back;
}
# Write one pixel for each source character
$column = 0;
foreach (split("", $source))
{
# Check for width
if ($column >= $overview_width) { last; }
if ($_ eq " ")
{
# Space
$overview->setPixel($column++, $row,
$color_back);
}
else
{
# Text
$overview->setPixel($column++, $row,
$color_text);
}
}
# Fill rest of line
while ($column < $overview_width)
{
$overview->setPixel($column++, $row, $color_back);
}
$last_count = $2;
$row++;
}
# Write PNG file
open (PNG_HANDLE, ">", $filename)
or die("ERROR: cannot write png file $filename!\n");
binmode(*PNG_HANDLE);
print(PNG_HANDLE $overview->png());
close(PNG_HANDLE);
}
sub genpng_warn_handler($)
{
my ($msg) = @_;
warn("$tool_name: $msg");
}
sub genpng_die_handler($)
{
my ($msg) = @_;
die("$tool_name: $msg");
}
#!/usr/bin/env bash
#
# Usage: get_changes.sh
#
# Print lcov change log information as provided by Git
TOOLDIR=$(cd $(dirname $0) >/dev/null ; pwd)
cd $TOOLDIR
if ! git --no-pager log --no-merges --decorate=short --color=never 2>/dev/null ; then
cat "$TOOLDIR/../CHANGES" 2>/dev/null
fi
#!/usr/bin/env bash
#
# Usage: get_version.sh --version|--release|--full
#
# Print lcov version or release information as provided by Git, .version
# or a fallback.
TOOLDIR=$(cd $(dirname $0) >/dev/null ; pwd)
GITVER=$(cd $TOOLDIR ; git describe --tags 2>/dev/null)
if [ -z "$GITVER" ] ; then
# Get version information from file
if [ -e "$TOOLDIR/../.version" ] ; then
source "$TOOLDIR/../.version"
fi
else
# Get version information from git
FULL=${GITVER:1}
VERSION=${GITVER%%-*}
VERSION=${VERSION:1}
if [ "${GITVER#*-}" != "$GITVER" ] ; then
RELEASE=${GITVER#*-}
RELEASE=${RELEASE/-/.}
fi
fi
# Fallback
[ -z "$VERSION" ] && VERSION="1.0"
[ -z "$RELEASE" ] && RELEASE="1"
[ -z "$FULL" ] && FULL="$VERSION"
[ "$1" == "--version" ] && echo -n "$VERSION"
[ "$1" == "--release" ] && echo -n "$RELEASE"
[ "$1" == "--full" ] && echo -n "$FULL"
#!/usr/bin/env bash
#
# install.sh [--uninstall] sourcefile targetfile [install options]
#
# Check for uninstall option
if test "x$1" == "x--uninstall" ; then
UNINSTALL=true
SOURCE=$2
TARGET=$3
shift 3
else
UNINSTALL=false
SOURCE=$1
TARGET=$2
shift 2
fi
# Check usage
if test -z "$SOURCE" || test -z "$TARGET" ; then
echo Usage: install.sh [--uninstall] source target [install options] >&2
exit 1
fi
#
# do_install(SOURCE_FILE, TARGET_FILE)
#
do_install()
{
local SOURCE=$1
local TARGET=$2
local PARAMS=$3
install -d $(dirname $TARGET)
install -p $PARAMS $SOURCE $TARGET
if [ -n "$LCOV_PERL_PATH" ] ; then
# Replace Perl interpreter specification
sed -e "1 s%^#\!.*perl.*$%#\!$LCOV_PERL_PATH%" -i $TARGET
fi
}
#
# do_uninstall(SOURCE_FILE, TARGET_FILE)
#
do_uninstall()
{
local SOURCE=$1
local TARGET=$2
# Does target exist?
if test -r $TARGET ; then
# Is target of the same version as this package?
if diff -I '^our \$lcov_version' -I '^\.TH ' -I '^#!' $SOURCE $TARGET >/dev/null; then
rm -f $TARGET
else
echo WARNING: Skipping uninstall for $TARGET - versions differ! >&2
fi
else
echo WARNING: Skipping uninstall for $TARGET - not installed! >&2
fi
}
# Call sub routine
if $UNINSTALL ; then
do_uninstall $SOURCE $TARGET
else
do_install $SOURCE $TARGET "$*"
fi
exit 0
差异被折叠。
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
sub update_man_page($);
sub update_bin_tool($);
sub update_txt_file($);
sub update_spec_file($);
sub write_version_file($);
sub get_file_info($);
our $directory = $ARGV[0];
our $version = $ARGV[1];
our $release = $ARGV[2];
our $full = $ARGV[3];
our @man_pages = ("man/gendesc.1", "man/genhtml.1", "man/geninfo.1",
"man/genpng.1", "man/lcov.1", "man/lcovrc.5");
our @bin_tools = ("bin/gendesc", "bin/genhtml", "bin/geninfo",
"bin/genpng", "bin/lcov");
our @txt_files = ("README");
our @spec_files = ("rpm/lcov.spec");
if (!defined($directory) || !defined($version) || !defined($release)) {
die("Usage: $0 DIRECTORY|FILE VERSION RELEASE FULL_VERSION\n");
}
# Determine mode of operation
if (-f $directory) {
my $file = $directory;
my $base = basename($file);
if (grep(/^$base$/, map({ basename($_) } @man_pages))) {
print("Updating man page $file\n");
update_man_page($file);
} elsif (grep(/^$base$/, map({ basename($_) } @bin_tools))) {
print("Updating bin tool $file\n");
update_bin_tool($file);
} elsif (grep(/^$base$/, map({ basename($_) } @txt_files))) {
print("Updating text file $file\n");
update_txt_file($file);
} elsif (grep(/^$base$/, map({ basename($_) } @spec_files))) {
print("Updating spec file $file\n");
update_spec_file($file);
} elsif ($base eq ".version") {
print("Updating version file $file\n");
write_version_file($file);
} else {
print("WARNING: Skipping unknown file $file\n");
}
print("Done.\n");
exit(0);
}
foreach (@man_pages) {
print("Updating man page $_\n");
update_man_page($directory."/".$_);
}
foreach (@bin_tools) {
print("Updating bin tool $_\n");
update_bin_tool($directory."/".$_);
}
foreach (@txt_files) {
print("Updating text file $_\n");
update_txt_file($directory."/".$_);
}
foreach (@spec_files) {
print("Updating spec file $_\n");
update_spec_file($directory."/".$_);
}
print("Updating version file $directory/.version\n");
write_version_file("$directory/.version");
print("Done.\n");
sub get_file_info($)
{
my ($filename) = @_;
my ($sec, $min, $hour, $year, $month, $day);
my @stat;
my $gittime;
return (0, 0, 0) if (!-e $filename);
@stat = stat($filename);
($sec, $min, $hour, $day, $month, $year) = gmtime($stat[9]);
$year += 1900;
$month += 1;
return (sprintf("%04d-%02d-%02d", $year, $month, $day),
sprintf("%04d%02d%02d%02d%02d.%02d", $year, $month, $day,
$hour, $min, $sec),
sprintf("%o", $stat[2] & 07777));
}
sub update_man_page($)
{
my ($filename) = @_;
my @date = get_file_info($filename);
my $date_string = $date[0];
local *IN;
local *OUT;
$date_string =~ s/-/\\-/g;
open(IN, "<$filename") || die ("Error: cannot open $filename\n");
open(OUT, ">$filename.new") ||
die("Error: cannot create $filename.new\n");
while (<IN>) {
s/\"LCOV\s+\d+\.\d+\"/\"LCOV $version\"/g;
s/\d\d\d\d\\\-\d\d\\\-\d\d/$date_string/g;
print(OUT $_);
}
close(OUT);
close(IN);
chmod(oct($date[2]), "$filename.new");
system("mv", "-f", "$filename.new", "$filename");
system("touch", "$filename", "-t", $date[1]);
}
sub update_bin_tool($)
{
my ($filename) = @_;
my @date = get_file_info($filename);
local *IN;
local *OUT;
open(IN, "<$filename") || die ("Error: cannot open $filename\n");
open(OUT, ">$filename.new") ||
die("Error: cannot create $filename.new\n");
while (<IN>) {
s/^(our\s+\$lcov_version\s*=).*$/$1 "LCOV version $full";/g;
print(OUT $_);
}
close(OUT);
close(IN);
chmod(oct($date[2]), "$filename.new");
system("mv", "-f", "$filename.new", "$filename");
system("touch", "$filename", "-t", $date[1]);
}
sub update_txt_file($)
{
my ($filename) = @_;
my @date = get_file_info($filename);
local *IN;
local *OUT;
open(IN, "<$filename") || die ("Error: cannot open $filename\n");
open(OUT, ">$filename.new") ||
die("Error: cannot create $filename.new\n");
while (<IN>) {
s/(Last\s+changes:\s+)\d\d\d\d-\d\d-\d\d/$1$date[0]/g;
print(OUT $_);
}
close(OUT);
close(IN);
chmod(oct($date[2]), "$filename.new");
system("mv", "-f", "$filename.new", "$filename");
system("touch", "$filename", "-t", $date[1]);
}
sub update_spec_file($)
{
my ($filename) = @_;
my @date = get_file_info($filename);
local *IN;
local *OUT;
open(IN, "<$filename") || die ("Error: cannot open $filename\n");
open(OUT, ">$filename.new") ||
die("Error: cannot create $filename.new\n");
while (<IN>) {
s/^(Version:\s*)\d+\.\d+.*$/$1$version/;
s/^(Release:\s*).*$/$1$release/;
print(OUT $_);
}
close(OUT);
close(IN);
system("mv", "-f", "$filename.new", "$filename");
system("touch", "$filename", "-t", $date[1]);
}
sub write_version_file($)
{
my ($filename) = @_;
my $fd;
open($fd, ">", $filename) or die("Error: cannot write $filename: $!\n");
print($fd "VERSION=$version\n");
print($fd "RELEASE=$release\n");
print($fd "FULL=$full\n");
close($fd);
}
#
# Makefile for the LCOV example program.
#
# Make targets:
# - example: compile the example program
# - output: run test cases on example program and create HTML output
# - clean: clean up directory
#
CC := gcc
CFLAGS := -Wall -I. -fprofile-arcs -ftest-coverage
LCOV := ../bin/lcov
GENHTML := ../bin/genhtml
GENDESC := ../bin/gendesc
GENPNG := ../bin/genpng
# Depending on the presence of the GD.pm perl module, we can use the
# special option '--frames' for genhtml
USE_GENPNG := $(shell $(GENPNG) --help >/dev/null 2>/dev/null; echo $$?)
ifeq ($(USE_GENPNG),0)
FRAMES := --frames
else
FRAMES :=
endif
.PHONY: clean output test_noargs test_2_to_2000 test_overflow
all: output
example: example.o iterate.o gauss.o
$(CC) example.o iterate.o gauss.o -o example -lgcov
example.o: example.c iterate.h gauss.h
$(CC) $(CFLAGS) -c example.c -o example.o
iterate.o: methods/iterate.c iterate.h
$(CC) $(CFLAGS) -c methods/iterate.c -o iterate.o
gauss.o: methods/gauss.c gauss.h
$(CC) $(CFLAGS) -c methods/gauss.c -o gauss.o
output: example descriptions test_noargs test_2_to_2000 test_overflow
@echo
@echo '*'
@echo '* Generating HTML output'
@echo '*'
@echo
$(GENHTML) trace_noargs.info trace_args.info trace_overflow.info \
--output-directory output --title "Basic example" \
--show-details --description-file descriptions $(FRAMES) \
--legend
@echo
@echo '*'
@echo '* See '`pwd`/output/index.html
@echo '*'
@echo
descriptions: descriptions.txt
$(GENDESC) descriptions.txt -o descriptions
all_tests: example test_noargs test_2_to_2000 test_overflow
test_noargs:
@echo
@echo '*'
@echo '* Test case 1: running ./example without parameters'
@echo '*'
@echo
$(LCOV) --zerocounters --directory .
./example
$(LCOV) --capture --directory . --output-file trace_noargs.info --test-name test_noargs --no-external
test_2_to_2000:
@echo
@echo '*'
@echo '* Test case 2: running ./example 2 2000'
@echo '*'
@echo
$(LCOV) --zerocounters --directory .
./example 2 2000
$(LCOV) --capture --directory . --output-file trace_args.info --test-name test_2_to_2000 --no-external
test_overflow:
@echo
@echo '*'
@echo '* Test case 3: running ./example 0 100000 (causes an overflow)'
@echo '*'
@echo
$(LCOV) --zerocounters --directory .
./example 0 100000 || true
$(LCOV) --capture --directory . --output-file trace_overflow.info --test-name "test_overflow" --no-external
clean:
rm -rf *.o *.bb *.bbg *.da *.gcno *.gcda *.info output example \
descriptions
To get an example of how the LCOV generated HTML output looks like,
type 'make output' and point a web browser to the resulting file
output/index.html
test_noargs
Example program is called without arguments so that default range
[0..9] is used.
test_2_to_2000
Example program is called with "2" and "2000" as arguments.
test_overflow
Example program is called with "0" and "100000" as arguments. The
resulting sum is too large to be stored as an int variable.
/*
* example.c
*
* Calculate the sum of a given range of integer numbers. The range is
* specified by providing two integer numbers as command line argument.
* If no arguments are specified, assume the predefined range [0..9].
* Abort with an error message if the resulting number is too big to be
* stored as int variable.
*
* This program example is similar to the one found in the GCOV documentation.
* It is used to demonstrate the HTML output generated by LCOV.
*
* The program is split into 3 modules to better demonstrate the 'directory
* overview' function. There are also a lot of bloated comments inserted to
* artificially increase the source code size so that the 'source code
* overview' function makes at least a minimum of sense.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "iterate.h"
#include "gauss.h"
static int start = 0;
static int end = 9;
int main (int argc, char* argv[])
{
int total1, total2;
/* Accept a pair of numbers as command line arguments. */
if (argc == 3)
{
start = atoi(argv[1]);
end = atoi(argv[2]);
}
/* Use both methods to calculate the result. */
total1 = iterate_get_sum (start, end);
total2 = gauss_get_sum (start, end);
/* Make sure both results are the same. */
if (total1 != total2)
{
printf ("Failure (%d != %d)!\n", total1, total2);
}
else
{
printf ("Success, sum[%d..%d] = %d\n", start, end, total1);
}
return 0;
}
#ifndef GAUSS_H
#define GAUSS_H GAUSS_h
extern int gauss_get_sum (int min, int max);
#endif /* GAUSS_H */
#ifndef ITERATE_H
#define ITERATE_H ITERATE_H
extern int iterate_get_sum (int min, int max);
#endif /* ITERATE_H */
/*
* methods/gauss.c
*
* Calculate the sum of a given range of integer numbers.
*
* Somewhat of a more subtle way of calculation - and it even has a story
* behind it:
*
* Supposedly during math classes in elementary school, the teacher of
* young mathematician Gauss gave the class an assignment to calculate the
* sum of all natural numbers between 1 and 100, hoping that this task would
* keep the kids occupied for some time. The story goes that Gauss had the
* result ready after only a few minutes. What he had written on his black
* board was something like this:
*
* 1 + 100 = 101
* 2 + 99 = 101
* 3 + 98 = 101
* .
* .
* 100 + 1 = 101
*
* s = (1/2) * 100 * 101 = 5050
*
* A more general form of this formula would be
*
* s = (1/2) * (max + min) * (max - min + 1)
*
* which is used in the piece of code below to implement the requested
* function in constant time, i.e. without dependencies on the size of the
* input parameters.
*
*/
#include "gauss.h"
int gauss_get_sum (int min, int max)
{
/* This algorithm doesn't work well with invalid range specifications
so we're intercepting them here. */
if (max < min)
{
return 0;
}
return (int) ((max + min) * (double) (max - min + 1) / 2);
}
/*
* methods/iterate.c
*
* Calculate the sum of a given range of integer numbers.
*
* This particular method of implementation works by way of brute force,
* i.e. it iterates over the entire range while adding the numbers to finally
* get the total sum. As a positive side effect, we're able to easily detect
* overflows, i.e. situations in which the sum would exceed the capacity
* of an integer variable.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include "iterate.h"
int iterate_get_sum (int min, int max)
{
int i, total;
total = 0;
/* This is where we loop over each number in the range, including
both the minimum and the maximum number. */
for (i = min; i <= max; i++)
{
/* We can detect an overflow by checking whether the new
sum would become negative. */
if (total + i < total)
{
printf ("Error: sum too large!\n");
exit (1);
}
/* Everything seems to fit into an int, so continue adding. */
total += i;
}
return total;
}
#
# /etc/lcovrc - system-wide defaults for LCOV
#
# To change settings for a single user, place a customized copy of this file
# at location ~/.lcovrc
#
# Specify an external style sheet file (same as --css-file option of genhtml)
#genhtml_css_file = gcov.css
# Specify coverage rate limits (in %) for classifying file entries
# HI: hi_limit <= rate <= 100 graph color: green
# MED: med_limit <= rate < hi_limit graph color: orange
# LO: 0 <= rate < med_limit graph color: red
genhtml_hi_limit = 90
genhtml_med_limit = 75
# Width of line coverage field in source code view
genhtml_line_field_width = 12
# Width of branch coverage field in source code view
genhtml_branch_field_width = 16
# Width of overview image (used by --frames option of genhtml)
genhtml_overview_width = 80
# Resolution of overview navigation: this number specifies the maximum
# difference in lines between the position a user selected from the overview
# and the position the source code window is scrolled to (used by --frames
# option of genhtml)
genhtml_nav_resolution = 4
# Clicking a line in the overview image should show the source code view at
# a position a bit further up so that the requested line is not the first
# line in the window. This number specifies that offset in lines (used by
# --frames option of genhtml)
genhtml_nav_offset = 10
# Do not remove unused test descriptions if non-zero (same as
# --keep-descriptions option of genhtml)
genhtml_keep_descriptions = 0
# Do not remove prefix from directory names if non-zero (same as --no-prefix
# option of genhtml)
genhtml_no_prefix = 0
# Do not create source code view if non-zero (same as --no-source option of
# genhtml)
genhtml_no_source = 0
# Replace tabs with number of spaces in source view (same as --num-spaces
# option of genhtml)
genhtml_num_spaces = 8
# Highlight lines with converted-only data if non-zero (same as --highlight
# option of genhtml)
genhtml_highlight = 0
# Include color legend in HTML output if non-zero (same as --legend option of
# genhtml)
genhtml_legend = 0
# Use FILE as HTML prolog for generated pages (same as --html-prolog option of
# genhtml)
#genhtml_html_prolog = FILE
# Use FILE as HTML epilog for generated pages (same as --html-epilog option of
# genhtml)
#genhtml_html_epilog = FILE
# Use custom filename extension for pages (same as --html-extension option of
# genhtml)
#genhtml_html_extension = html
# Compress all generated html files with gzip.
#genhtml_html_gzip = 1
# Include sorted overview pages (can be disabled by the --no-sort option of
# genhtml)
genhtml_sort = 1
# Include function coverage data display (can be disabled by the
# --no-func-coverage option of genhtml)
#genhtml_function_coverage = 1
# Include branch coverage data display (can be disabled by the
# --no-branch-coverage option of genhtml)
#genhtml_branch_coverage = 1
# Specify the character set of all generated HTML pages
genhtml_charset=UTF-8
# Allow HTML markup in test case description text if non-zero
genhtml_desc_html=0
# Specify the precision for coverage rates
#genhtml_precision=1
# Show missed counts instead of hit counts
#genhtml_missed=1
# Demangle C++ symbols
#genhtml_demangle_cpp=1
# Location of the gcov tool (same as --gcov-info option of geninfo)
#geninfo_gcov_tool = gcov
# Adjust test names to include operating system information if non-zero
#geninfo_adjust_testname = 0
# Calculate checksum for each source code line if non-zero (same as --checksum
# option of geninfo if non-zero, same as --no-checksum if zero)
#geninfo_checksum = 1
# Specify whether to capture coverage data for external source files (can
# be overridden by the --external and --no-external options of geninfo/lcov)
#geninfo_external = 1
# Enable libtool compatibility mode if non-zero (same as --compat-libtool option
# of geninfo if non-zero, same as --no-compat-libtool if zero)
#geninfo_compat_libtool = 0
# Use gcov's --all-blocks option if non-zero
#geninfo_gcov_all_blocks = 1
# Specify compatiblity modes (same as --compat option of geninfo).
#geninfo_compat = libtool=on, hammer=auto, split_crc=auto
# Adjust path to source files by removing or changing path components that
# match the specified pattern (Perl regular expression format)
#geninfo_adjust_src_path = /tmp/build => /usr/src
# Specify if geninfo should try to automatically determine the base-directory
# when collecting coverage data.
geninfo_auto_base = 1
# Use gcov intermediate format? Valid values are 0, 1, auto
geninfo_intermediate = auto
# Directory containing gcov kernel files
# lcov_gcov_dir = /proc/gcov
# Location of the insmod tool
lcov_insmod_tool = /sbin/insmod
# Location of the modprobe tool
lcov_modprobe_tool = /sbin/modprobe
# Location of the rmmod tool
lcov_rmmod_tool = /sbin/rmmod
# Location for temporary directories
lcov_tmp_dir = /tmp
# Show full paths during list operation if non-zero (same as --list-full-path
# option of lcov)
lcov_list_full_path = 0
# Specify the maximum width for list output. This value is ignored when
# lcov_list_full_path is non-zero.
lcov_list_width = 80
# Specify the maximum percentage of file names which may be truncated when
# choosing a directory prefix in list output. This value is ignored when
# lcov_list_full_path is non-zero.
lcov_list_truncate_max = 20
# Specify if function coverage data should be collected and processed.
lcov_function_coverage = 1
# Specify if branch coverage data should be collected and processed.
lcov_branch_coverage = 0
.TH gendesc 1 "LCOV 1.14" 2016\-12\-19 "User Manuals"
.SH NAME
gendesc \- Generate a test case description file
.SH SYNOPSIS
.B gendesc
.RB [ \-h | \-\-help ]
.RB [ \-v | \-\-version ]
.RS 8
.br
.RB [ \-o | \-\-output\-filename
.IR filename ]
.br
.I inputfile
.SH DESCRIPTION
Convert plain text test case descriptions into a format as understood by
.BR genhtml .
.I inputfile
needs to observe the following format:
For each test case:
.IP " \-"
one line containing the test case name beginning at the start of the line
.RE
.IP " \-"
one or more lines containing the test case description indented with at
least one whitespace character (tab or space)
.RE
.B Example input file:
test01
.RS
An example test case description.
.br
Description continued
.RE
test42
.RS
Supposedly the answer to most of your questions
.RE
Note: valid test names can consist of letters, decimal digits and the
underscore character ('_').
.SH OPTIONS
.B \-h
.br
.B \-\-help
.RS
Print a short help text, then exit.
.RE
.B \-v
.br
.B \-\-version
.RS
Print version number, then exit.
.RE
.BI "\-o " filename
.br
.BI "\-\-output\-filename " filename
.RS
Write description data to
.IR filename .
By default, output is written to STDOUT.
.RE
.SH AUTHOR
Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
.SH SEE ALSO
.BR lcov (1),
.BR genhtml (1),
.BR geninfo (1),
.BR genpng (1),
.BR gcov (1)
差异被折叠。
差异被折叠。
.TH genpng 1 "LCOV 1.14" 2016\-12\-19 "User Manuals"
.SH NAME
genpng \- Generate an overview image from a source file
.SH SYNOPSIS
.B genpng
.RB [ \-h | \-\-help ]
.RB [ \-v | \-\-version ]
.RS 7
.br
.RB [ \-t | \-\-tab\-size
.IR tabsize ]
.RB [ \-w | \-\-width
.IR width ]
.br
.RB [ \-o | \-\-output\-filename
.IR output\-filename ]
.br
.IR source\-file
.SH DESCRIPTION
.B genpng
creates an overview image for a given source code file of either
plain text or .gcov file format.
Note that the
.I GD.pm
Perl module has to be installed for this script to work
(it may be obtained from
.IR http://www.cpan.org ).
Note also that
.B genpng
is called from within
.B genhtml
so that there is usually no need to call it directly.
.SH OPTIONS
.B \-h
.br
.B \-\-help
.RS
Print a short help text, then exit.
.RE
.B \-v
.br
.B \-\-version
.RS
Print version number, then exit.
.RE
.BI "\-t " tab\-size
.br
.BI "\-\-tab\-size " tab\-size
.RS
Use
.I tab\-size
spaces in place of tab.
All occurrences of tabulator signs in the source code file will be replaced
by the number of spaces defined by
.I tab\-size
(default is 4).
.RE
.BI "\-w " width
.br
.BI "\-\-width " width
.RS
Set width of output image to
.I width
pixel.
The resulting image will be exactly
.I width
pixel wide (default is 80).
Note that source code lines which are longer than
.I width
will be truncated.
.RE
.BI "\-o " filename
.br
.BI "\-\-output\-filename " filename
.RS
Write image to
.IR filename .
Specify a name for the resulting image file (default is
.IR source\-file .png).
.RE
.SH AUTHOR
Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
.SH SEE ALSO
.BR lcov (1),
.BR genhtml (1),
.BR geninfo (1),
.BR gendesc (1),
.BR gcov (1)
差异被折叠。
差异被折叠。
Summary: A graphical GCOV front-end
Name: lcov
Version: 1.14
Release: 1
License: GPLv2+
Group: Development/Tools
URL: http://ltp.sourceforge.net/coverage/lcov.php
Source0: http://downloads.sourceforge.net/ltp/%{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildArch: noarch
Requires: perl >= 5.8.8
%description
LCOV is a graphical front-end for GCC's coverage testing tool gcov. It collects
gcov data for multiple source files and creates HTML pages containing the
source code annotated with coverage information. It also adds overview pages
for easy navigation within the file structure.
%prep
%setup -q -n %{name}-%{version}
%build
exit 0
%install
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT PREFIX=/usr CFG_DIR=/etc
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
/usr/bin/*
/usr/share/man/man*/*
%config /etc/*
%changelog
* Mon Aug 22 2016 Peter Oberparleiter (Peter.Oberparleiter@de.ibm.com)
- updated "make install" call to work with PREFIX Makefile changes
* Mon May 07 2012 Peter Oberparleiter (Peter.Oberparleiter@de.ibm.com)
- added dependency on perl 5.8.8 for >>& open mode support
* Wed Aug 13 2008 Peter Oberparleiter (Peter.Oberparleiter@de.ibm.com)
- changed description + summary text
* Mon Aug 20 2007 Peter Oberparleiter (Peter.Oberparleiter@de.ibm.com)
- fixed "Copyright" tag
* Mon Jul 14 2003 Peter Oberparleiter (Peter.Oberparleiter@de.ibm.com)
- removed variables for version/release to support source rpm building
- added initial rm command in install section
* Mon Apr 7 2003 Peter Oberparleiter (Peter.Oberparleiter@de.ibm.com)
- implemented variables for version/release
* Fri Oct 18 2002 Peter Oberparleiter (Peter.Oberparleiter@de.ibm.com)
- created initial spec file
include common.mak
TESTDIRS := $(sort $(patsubst %/,%,$(dir $(wildcard */Makefile))))
help: info
info:
echo "Available make targets:"
echo " test : perform self-tests"
echo " clean : remove all temporary files"
echo ""
echo "Available make variables:"
echo " SIZE : specify size of test data (small, medium, large)"
echo " V : specify level of verbosity (0, 1, 2)"
test:
for TEST in $(TESTDIRS) ; do \
make -C $$TEST test ; \
done
clean:
rm -rf *.info *.counts test.log src/
for TEST in $(TESTDIRS) ; do \
make -C $$TEST clean ; \
done
.PHONY: help info test clean
function elapsed_to_ms()
{
local ELAPSED=$1
local IFS=:.
local MS
set -- $ELAPSED
if [ $# -eq 3 ] ; then
let MS=${3#0}*10+${2#0}*1000+$1*60000
else
let MS=${4#0}*10+${3#0}*1000+${2#0}*60000+$1*3600000
fi
echo $MS
}
function t_timestamp()
{
date +"%Y-%m-%d %H:%M:%S %z"
}
function t_marker()
{
echo
echo "======================================================================"
}
function t_detail()
{
local KEY=$1
local VALUE=$2
local DOTS=" ............"
printf "%-.12s: %s\n" "$KEY$DOTS" "$VALUE"
}
function t_announce()
{
local TESTNAME="$1"
printf "$BOLD%-.30s$RESET " "$TESTNAME .............................."
t_marker >> "$LOGFILE"
t_detail "DATE" "$(t_timestamp)" >> "$LOGFILE"
t_detail "TESTNAME" "$TESTNAME" >> "$LOGFILE"
}
function t_result()
{
local COLOR="$1"
local TEXT="$2"
printf "[$COLOR$TEXT$RESET]"
}
function t_pass()
{
local TESTNAME="$1"
t_result "$GREEN" "pass"
echo "pass $TESTNAME" >> "$COUNTFILE"
}
function t_fail()
{
local TESTNAME="$1"
t_result "$RED" "fail"
echo "fail $TESTNAME" >> "$COUNTFILE"
}
function t_kill()
{
local TESTNAME="$1"
t_result "$RED" "kill"
echo "fail $TESTNAME" >> "$COUNTFILE"
}
function t_skip()
{
local TESTNAME="$1"
t_result "$BLUE" "skip"
echo "skip $TESTNAME" >> "$COUNTFILE"
}
function t_indent()
{
sed -e 's/^/ /'
}
LOGFILE="$TOPDIR/test.log"
COUNTFILE="$TOPDIR/test.counts"
TIMEFILE="$TOPDIR/test.time"
if [ -t 1 ] ; then
RED="\e[31m"
GREEN="\e[32m"
BLUE="\e[34m"
BOLD="\e[1m"
DEFAULT="\e[39m"
RESET="\e[0m"
fi
差异被折叠。
#!/usr/bin/env perl
#
# Copyright IBM Corp. 2017
#
# Usage: norminfo <coverage-data-file> [<multiplier>]
#
# Normalize coverage data file (ensure stable order), perform some sanity
# checks, and apply optional multiplier to execution counts.
#
use strict;
use warnings;
sub ferr($$$)
{
my ($pos, $filename, $msg) = @_;
if (defined($pos)) {
$pos .= ":";
} else {
$pos = "";
}
die("$0:$filename:$pos $msg");
}
sub print_sorted($$$)
{
my ($fd, $info, $multi) = @_;
my (%fn, %fns, %fnda, %brda, %da);
my ($fnf, $fnh, $brf, $brh, $lf, $lh);
while (my $line = <$fd>) {
$line =~ s/(^\s*|\s*$)//g;
if ($line =~ /^end_of_record$/) {
last;
} elsif ($line =~ /^FN:(\d+),(.*)$/) {
my ($lineno, $fnname) = ($1, $2);
if (exists($fn{$lineno})) {
ferr($., $info, "Duplicate FN: entry\n");
}
$fn{$lineno} = $fnname;
if (exists($fns{$fnname})) {
ferr($., $info, "Duplicate function name\n");
}
$fns{$fnname} = $lineno;
} elsif ($line =~ /^FNDA:(\d+),(.*)$/) {
my ($count, $fnname) = ($1, $2);
if (exists($fnda{$fnname})) {
ferr($., $info, "Duplicate FNDA: entry\n");
}
$fnda{$fnname} = int($count * $multi);
} elsif ($line =~ /^FNF:(\d+)$/) {
if (defined($fnf)) {
ferr($., $info, "Duplicate FNF: entry\n");
}
$fnf = $1;
} elsif ($line =~ /^FNH:(\d+)$/) {
if (defined($fnh)) {
ferr($., $info, "Duplicate FNH: entry\n");
}
$fnh = $1;
} elsif ($line =~ /^BRDA:(\d+),(\d+),(\d+),(\d+|-)$/) {
my ($lineno, $block, $branch, $count) = ($1, $2, $3, $4);
if (exists($brda{$lineno}->{$block}->{$branch})) {
ferr($., $info, "Duplicate BRDA: entry\n");
}
$count = int($count * $multi) if ($count ne "-");
$brda{$lineno}->{$block}->{$branch} = $count;
} elsif ($line =~ /^BRF:(\d+)$/) {
if (defined($brf)) {
ferr($., $info, "Duplicate BRF: entry\n");
}
$brf = $1;
} elsif ($line =~ /^BRH:(\d+)$/) {
if (defined($brh)) {
ferr($., $info, "Duplicate BRH: entry\n");
}
$brh = $1;
} elsif ($line =~ /^DA:(\d+),(\d+)$/) {
my ($lineno, $count) = ($1, $2);
if (exists($da{$lineno})) {
ferr($., $info, "Duplicate FNDA: entry\n");
}
$da{$lineno} = int($count * $multi);
} elsif ($line =~ /^LF:(\d+)$/) {
if (defined($lf)) {
ferr($., $info, "Duplicate LF: entry\n");
}
$lf = $1;
} elsif ($line =~ /^LH:(\d+)$/) {
if (defined($lh)) {
ferr($., $info, "Duplicate LH: entry\n");
}
$lh = $1;
} else {
ferr($., $info, "Unknown line: $line\n");
}
}
# FN:<line>,<fnname>
foreach my $lineno (sort({ $a <=> $b } keys(%fn))) {
my $fnname = $fn{$lineno};
print("FN:$lineno,$fnname\n");
}
# FNDA:<counts>,<fnname>
foreach my $fnname (keys(%fnda)) {
if (!exists($fns{$fnname})) {
ferr(undef, $info, "FNDA entry without FN: $fnname\n");
}
}
foreach my $fnname (sort({ $fns{$a} <=> $fns{$b} } keys(%fnda))) {
my $count = $fnda{$fnname};
print("FNDA:$count,$fnname\n");
}
# FNF:<counts>
print("FNF:$fnf\n") if (defined($fnf));
# FNH:<counts>
if (defined($fnh)) {
$fnh = 0 if ($multi == 0);
print("FNH:$fnh\n");
}
# BRDA:<line>,<block>,<branch>,<count>
foreach my $lineno (sort({ $a <=> $b } keys(%brda))) {
my $blocks = $brda{$lineno};
foreach my $block (sort({ $a <=> $b } keys(%{$blocks}))) {
my $branches = $blocks->{$block};
foreach my $branch (sort({ $a <=> $b }
keys(%{$branches}))) {
my $count = $branches->{$branch};
$count = "-" if ($multi == 0);
print("BRDA:$lineno,$block,$branch,$count\n");
}
}
}
# BRF:<counts>
print("BRF:$brf\n") if (defined($brf));
# BRH:<counts>
if (defined($brh)) {
$brh = 0 if ($multi == 0);
print("BRH:$brh\n");
}
# DA:<line>,<counts>
foreach my $lineno (sort({ $a <=> $b } keys(%da))) {
my $count = $da{$lineno};
print("DA:$lineno,$count\n");
}
# LF:<counts>
print("LF:$lf\n") if (defined($lf));
# LH:<count>
if (defined($lh)) {
$lh = 0 if ($multi == 0);
print("LH:$lh\n");
}
}
sub main()
{
my $infofile = $ARGV[0];
my $multi = $ARGV[1];
# info: testname -> files
# files: infofile -> data
# data: [ starting offset, starting line ]
my %info;
my $fd;
my $tn = "";
my %allfiles;
$multi = 1 if (!defined($multi));
if (!defined($infofile)) {
$infofile = "standard input";
warn("$0: Reading data from standard input\n");
open($fd, "<&STDIN") or
die("$0: Could not duplicated stdin: $!\n");
} else {
open($fd, "<", $infofile) or
die("$0: Could not open $infofile: $!\n");
}
# Register starting positions of data sets
while (my $line = <$fd>) {
if ($line =~ /^TN:(.*)$/) {
$tn = $1;
} elsif ($line =~ /^SF:(.*)$/) {
my $sf = $1;
my $pos = tell($fd);
die("$0: Could not get file position: $!\n")
if ($pos == -1);
if (exists($info{$tn}->{$sf})) {
ferr($., $infofile,
"Duplicate entry for $tn:$sf\n");
}
$info{$tn}->{$sf} = [ $pos, $. ];
$allfiles{$sf} = 1;
}
}
# Print data sets in normalized order
foreach my $filename (sort(keys(%allfiles))) {
foreach my $testname (sort(keys(%info))) {
my $pos = $info{$testname}->{$filename};
my ($cpos, $lpos) = @$pos;
next if (!defined($pos));
if (seek($fd, $cpos, 0) != 1) {
die("$0: Could not seek in $infofile: $!\n");
}
printf("TN:$testname\n");
printf("SF:$filename\n");
$. = $lpos;
print_sorted($fd, $infofile, $multi);
printf("end_of_record\n");
}
}
foreach my $testname (sort(keys(%info))) {
my $files = $info{$testname};
foreach my $filename (sort(keys(%{$files}))) {
}
}
close($fd);
}
main();
exit(0);
#!/usr/bin/env bash
#
# Copyright IBM Corp. 2017
#
# Usage: test_run <testname> <cmdline>
#
# Announce a test case, run it, and record the resulting output in the
# test log file. Must be run after testsuite_init.
#
TOPDIR=$(realpath $(dirname $0)/..) && source "$TOPDIR/bin/common"
EXCERPTLEN=10
TESTNAME="$1"
shift
TIME=$(which time 2>/dev/null)
if [ ! -z "$TIME" ] ; then
TIME="$TIME -v -o $TIMEFILE"
if ! $TIME true 2>/dev/null ; then
TIME=""
fi
fi
t_announce "$TESTNAME"
let POS=$(stat -c %s "$LOGFILE")+1
t_detail "COMMAND" "\"$*\"" >>"$LOGFILE"
t_detail "OUTPUT" "" >>"$LOGFILE"
# Run command
$TIME bash -c "$*" 2>&1 | t_indent >>"$LOGFILE"
RC=$?
# Evaluate output of time command
ELAPSED=
RESIDENT=
SIGNAL=
if [ ! -z "$TIME" ] ; then
while read LINE ; do
case "$LINE" in
"Command terminated by signal"*) SIGNAL=${LINE##* } ;;
"Elapsed"*) ELAPSED=$(elapsed_to_ms ${LINE##* }) ;;
"Maximum resident"*) RESIDENT=${LINE##* } ;;
"Exit status"*) RC=${LINE##* } ;;
esac
done < "$TIMEFILE"
rm -f "$TIMEFILE"
fi
t_detail "EXITCODE" "$RC" >>"$LOGFILE"
# Show result
if [ $RC -eq 0 -a -z "$SIGNAL" ] ; then
RESULT="pass"
t_pass "$TESTNAME"
else
if [ -z "$SIGNAL" ] ; then
RESULT="fail"
t_fail "$TESTNAME"
else
RESULT="kill"
t_kill "$TESTNAME"
fi
fi
if [ ! -z "$SIGNAL" ] ; then
t_detail "SIGNAL" "$SIGNAL" >>"$LOGFILE"
fi
if [ ! -z "$ELAPSED" ] ; then
echo -n " (time $(($ELAPSED/1000)).$(($ELAPSED%1000/100))s, "
echo "elapsed $TESTNAME $ELAPSED" >> "$COUNTFILE"
fi
if [ ! -z "$RESIDENT" ] ; then
echo -n "mem $(($RESIDENT/1024)).$((($RESIDENT%1024)/100))MB)"
echo "resident $TESTNAME $RESIDENT" >> "$COUNTFILE"
fi
echo
# Show log excerpt on failure or if requested
if [ $RC -ne 0 -o "$V" == "1" ] ; then
LEN=$(tail -c "+$POS" "$LOGFILE" | wc -l)
if [ "$LEN" -gt "$EXCERPTLEN" -a "$V" != "1" ] ; then
tail -c "+$POS" "$LOGFILE" | head -n $EXCERPTLEN | t_indent
let LEN=$LEN-$EXCERPTLEN
echo " ..."
echo " Skipping $LEN more lines (see $LOGFILE)"
else
tail -c "+$POS" "$LOGFILE" | t_indent
fi
fi
# Log more details
[ ! -z "$ELAPSED" ] && t_detail "TIME" "${ELAPSED}ms" >>"$LOGFILE"
[ ! -z "$RESIDENT" ] && t_detail "MEM" "${RESIDENT}kB" >>"$LOGFILE"
t_detail "RESULT" "$RESULT" >> "$LOGFILE"
#!/usr/bin/env bash
#
# Copyright IBM Corp. 2017
#
# Usage: test_skip <testname> <reason>
#
# Announce and record that a single test case was skipped, including an
# optional reason text. Must be run after testsuite_init.
#
TOPDIR=$(realpath $(dirname $0)/..) && source "$TOPDIR/bin/common"
TESTNAME="$1"
REASON="${*:2}" ; [ -z "$REASON" ] && REASON="<no reason given>"
t_announce "$TESTNAME"
t_skip "$TESTNAME"
echo
t_detail "REASON" "$REASON" >>"$LOGFILE"
t_detail "REASON" "$REASON" | t_indent
#!/usr/bin/env bash
#
# Copyright IBM Corp. 2017
#
# Usage: testsuite_init
#
# Announce start of test suite and prepare log files.
#
TOPDIR=$(realpath $(dirname $0)/..) && source "$TOPDIR/bin/common"
echo -e $BOLD"Starting tests"$RESET
echo "start_time $(date +%s.%N)" >"$COUNTFILE"
exec >"$LOGFILE" 2>&1
t_detail "DATE" "$(t_timestamp)"
t_detail "LCOV" ""
lcov --version 2>&1 | t_indent
t_detail "GCOV" ""
gcov --version 2>&1 | t_indent
t_detail "CPUINFO" ""
t_indent < /proc/cpuinfo
t_detail "MEMINFO" ""
t_indent < /proc/meminfo
差异被折叠。
include ../common.mak
test:
test_run lcov_diff_apply ./diff_test
clean:
make -C old clean
make -C new clean
rm -f *.info diff
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论