GithubHelp home page GithubHelp logo

simonkagstrom / kcov Goto Github PK

View Code? Open in Web Editor NEW
684.0 29.0 108.0 8.17 MB

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options

Home Page: http://simonkagstrom.github.io/kcov/

License: GNU General Public License v2.0

CMake 6.01% CSS 1.29% HTML 0.94% JavaScript 13.75% C++ 55.97% C 9.52% Shell 0.85% Python 10.71% Makefile 0.75% Assembly 0.01% Dockerfile 0.11% Go 0.09%
codecov coverage travis-ci unittesting codecov-uploader instrumentation

kcov's Introduction

Coveralls coverage status Codecov coverage status Coverity Scan Build Status Docker Pulls

PayPal Donate Github All Releases

kcov

Kcov is a FreeBSD/Linux/OSX code coverage tester for compiled languages, Python and Bash. Kcov was originally a fork of Bcov, but has since evolved to support a large feature set in addition to that of Bcov.

Kcov, like Bcov, uses DWARF debugging information for compiled programs to make it possible to collect coverage information without special compiler switches.

For a video introduction, look at this presentation from SwedenCPP

Installing

Refer to the INSTALL file for build instructions, or use our official Docker images:

How to use it

Basic usage is straight-forward:

kcov /path/to/outdir executable [args for the executable]

/path/to/outdir will contain lcov-style HTML output generated continuously while the application runs. Kcov will also write cobertura- compatible XML output and generic JSON coverage information and can easily be integrated in various CI systems.

Filtering output

It's often useful to filter output, since e.g., /usr/include is seldom of interest. This can be done in two ways:

kcov --exclude-pattern=/usr/include --include-pattern=part/of/path,other/path \
      /path/to/outdir executable

which will do a string-comparison and include everything which contains part/of/path or other/path but exclude everything that has the /usr/include string in it.

kcov --include-path=/my/src/path /path/to/outdir executable
kcov --exclude-path=/usr/include /path/to/outdir executable

Does the same thing, but with proper path lookups.

Merging multiple kcov runs

Kcov can also merge the results of multiple earlier runs. To use this mode, call kcov with --merge, an output path and one or more paths to an earlier run, e.g.,

kcov --merge /tmp/merged-output /tmp/kcov-output1 /tmp/kcov-output2
kcov --merge /tmp/merged-output /tmp/kcov-output*    # With a wildcard

Use from continuous integration systems

kcov is easy to integrate with travis-ci together with coveralls.io or codecov.io. It can also be used from Jenkins, SonarQube and GitLab CI. Refer to

  • coveralls for details about travis-ci + coveralls, or
  • codecov for details about travis-ci + codecov
  • jenkins for details about how to integrate in Jenkins
  • sonarqube for how to use kcov and sonarqube together
  • gitlab for use with GitLab

More information

kcov is written by Simon Kagstrom [email protected] and more information can be found at the web page

kcov's People

Contributors

aghecenco avatar asomers avatar austin987 avatar bossmc avatar botellaa avatar brycefisher avatar cattanimarco avatar davidtazy avatar dbanetto avatar dciabrin avatar dridi avatar garik avatar hanaasagi avatar jameswarner avatar ko1nksm avatar lifthrasiir avatar luehmann avatar mbland avatar mmlb avatar myzhan avatar neumannt avatar orycterope avatar pauldreik avatar perillo avatar philwhineray avatar richardwhiuk avatar shailpatels avatar simonkagstrom avatar unphased avatar vincentgibert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kcov's Issues

Merging coverage data from multiple invocations of a unit under test

I'm describing this from the perspective of bash/python scripts, but it is probably applicable for C/C++ executables as well...

If you have a unit under test such as the following:

#!/bin/bash
#unitundertest.sh

function block1()
{
    echo "In block1()"

    for f in 1 2 3 4 5
    do
        echo $f
    done
}

function block2()
{
    echo "In block2()"

    for f in 1 2 3 4 5
    do
        echo $f
    done
}

#
# Main
#

case $1 in
1)
    block1
    ;;
2)
    block2
    ;;
all)
    block1
    block2
    ;;
esac
exit 0

and you have a couple of test drivers which invoke unitundertest.sh passing different arguments

#!/bin/bash
# testdriver1.sh
kcov ./coverage ./unitundertest.sh 1
exit 0
#!/bin/bash
# testdriver2.sh
kcov ./coverage ./unitundertest.sh 2
exit 0

It would be useful if after executing testdriver1.sh and testdriver2.sh (presumably part of a larger test suite), the coverage data includes merged output reflecting both invocations: showing that block1() and block2() were both covered. Currently, the coverage gathered for unitundertest.sh seems to reflect the last invocation only, so no merge takes place and the coverage only reflects block2().

Running kcov on the higher-level test suite script rather than the individual scripts isn't an option because kcov doesn't collect coverage data on nested scripts.

Thanks for a great tool!
Chris

kcov error with alias

I have this simple test bash script:

#!/bin/bash
shopt -s expand_aliases
alias test_alias='{
echo called test_alias
} '
test_alias

When I run kcov on it, I get this output

% kcov /tmp/mhamilt/kcov_out ./test.sh
called test_alias
echo called test_alias
} '

Why is kcov printing everything after the first line of the alias definition? That alias syntax is valid (or at least clearly works in the test code and in our larger code base.) In our larger case the alias is many lines long; all but the first are printed.

BTW, this is kcov-25 on a Linux RHEL6 machine, using bash-4.1.2.

(An unrelated question; why does kcov not have a --version/-v option?)

Thanks.

Mark E. Hamilton

kcov fails to show uncovered files

Hi, yet again,

I have this test case which does nothing but define a function

#!/bin/bash
function some_test
    {
    test "${1}" == "--quiet" &&
        { quiet=${1} ; shift ; }
    }

In this instance it desn't actually execute anything, and kcov correctly reports the file as 0% covered. However, the 'Code covered' field shows 'NaN%' and 'Instrumented lines' as 0, and when I click the file link the content of the file is not displayed.

kcov issue with backslash within string

This might be related to #57; if so, feel free to drop this one, or merge them.

IAE, I have this test script:

#!/bin/bash
USAGE="usage: ${toolName} [--help] [--option1] \\
       [--option1|--option3] \\
       function_name [function_options] ...
"

It should produce no output, but when I run it with kcov I get this

% kcov /sierra/dev/mhamilt/kcov_out ./test.sh
       [--option1|--option3] \
       function_name [function_options] ...
'

If I add a echo "$USAGE" to the end of the script I get this output:

% kcov /sierra/dev/mhamilt/kcov_out ./test.sh
usage:  [--help] [--option1] \
       [--option1|--option3] \
       function_name [function_options] ...

       [--option1|--option3] \
       function_name [function_options] ...
'
       [--option1|--option3] \
       function_name [function_options] ...
'

This is with kcov-25 on a Linux RHEL6 machine using bash-4.1.2.

Thanks.

Mark E. Hamilton

Report branch coverage (basic blocks executed)

I found the results not analyze branch and class coverage. DO kcov only supports line coverage ,do we has a plan to support?
I think if we can get the coverage information about lines,we can calculate the branch.The source code must be understood,so there must be a interpreter for each singe language.

dlopen'ed shared libraries are not traced

Thanks for this high quality software. I was quite surprised when I found it; I think it should be much more popular.

Anyway, in our application we use dlopen to load a lot of other libraries like plugins. Unfortunately, the dlopen'ed libraries do not appear in the coverage output.

I guess that kcov could catch dlopen calls and dynamically instrument the loaded library just as it is done
with all directly linked shared libraries.

kcov: error: Cannot open linux-vdso.so.1

I get this error when running kcov on Arch Linux:

kcov: error: Cannot open linux-vdso.so.1

ldd shows the shared library exists. The kcov folder is generated, but the HTML shows that the binary was never run.

Any ideas?

[PATCH] Improve Makefile

I had several problems when I tried to install kcov. So I decided to improve Makefile in some ways. Will send patch by e-mail.

Make kcov buildable on non-Linux systems

The ptrace-support is probably Linux-specific, and the ELF/DWARF-parsing is at least limited to Linux and BSDs. However, the Python and Bash coverage collection should work everywhere, so it should be possible to build kcov in other places as well.

Improvements to src/CMakeLists.txt is needed to solve this.

coveralls.io support

Hi,

I wrote a small bash script which can upload kcov coverage results to coveralls.io in travis environment:
http://lavela.hu/kcov2coveralls.sh

I used it this way in my travis after-script hook:
/tmp/kcov2coveralls.sh /tmp/coverage/tests.sh/ >/tmp/coveralls.json
curl -F 'json_file=@/tmp/coveralls.json' https://coveralls.io/api/v1/jobs

I guess my script isn't 100% error-proof...
I tested it only with my pet project. (misspell_fixer.)

What is your opinion about supporting coveralls.io?
I mean if you want feel free to use my script, otherwise I think I would polish it a bit more and upload to github. Maybe others could use it.
In its actual form it is more like a proof-of-concept than a mature project, but at least it works.

Best regards,
Lajos

Compilation failure

gcc-4.7.1 fails to compile latest kcov. Error messages:

cd /tmp/tgz/kcov/build/src && /usr/bin/c++    -std=c++0x -Wall -D_GLIBCXX_USE_NANOSLEEP -DKCOV_LIBRARY_PREFIX=/tmp -g -I/tmp/tgz/kcov/src/include -I/usr/local/include    -o CMakeFiles/kcov.dir/elf.cc.o -c /tmp/tgz/kcov/src/elf.cc
/tmp/tgz/kcov/src/elf.cc: In member function 'bool Elf::checkFile()':
/tmp/tgz/kcov/src/elf.cc:94:11: error: 'close' was not declared in this scope
/tmp/tgz/kcov/src/elf.cc: In member function 'bool Elf::parseOneDwarf()':
/tmp/tgz/kcov/src/elf.cc:132:12: error: 'close' was not declared in this scope
/tmp/tgz/kcov/src/elf.cc:227:11: error: 'close' was not declared in this scope
/tmp/tgz/kcov/src/elf.cc: In member function 'bool Elf::parseOneElf()':
/tmp/tgz/kcov/src/elf.cc:316:11: error: 'close' was not declared in this scope
make[2]: *** [src/CMakeFiles/kcov.dir/elf.cc.o] Error 1

Error: Cannot open /usr/lib/debug/.build-id/fe/88530b2a48100dc39d0fa7b1333080aaec5b2c.debug

Dear all,
When I try to use kcov to collect the coverage info with my helloworld.c program first time. I got following error message:

Cannot open /usr/lib/debug/.build-id/fe/88530b2a48100dc39d0fa7b1333080aaec5b2c.debug

I have tried to give full permission to /usr/lib/debug/ directory.
I also tried to use
sudo kcov output/ ./helloworld.c test
as the command

However it doesnt help.
I also try to google it, but find no relative information online.
I installed kcov successfully, and ran kcov on Ubuntu 14.04 LTS in oracle virtual box.
So do you guys have any idea what is the issue that causes this problem?

Thanks!

KCov 16 crashes on tracing shotwell

While generating a report for shotwell kcov crashes:

[test@rhel7vm tmp]$ ps aux | grep shotwell
test     24163  0.0  2.7 1107016 42176 pts/0   Tl+  08:21   0:00 shotwell
test     24589  0.0  0.0 112640   980 pts/1    D+   08:40   0:00 grep --color=auto shotwell

[test@rhel7vm tmp]$ gdb --args kcov --pid=24163 --exclude-pattern=*.c /tmp/coverage /usr/bin/shotwell
(gdb) r
Starting program: /usr/local/bin/kcov --pid=24163 --exclude-pattern=\*.c /tmp/coverage /usr/bin/shotwell
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff6338700 (LWP 24532)]

Program received signal SIGSEGV, Segmentation fault.
0x0000000000477c9a in HtmlWriter::escapeHtml(std::string const&) ()
(gdb) t a a bt

Thread 2 (Thread 0x7ffff6338700 (LWP 24628)):
#0  0x00007ffff726b9fd in open64 () at ../sysdeps/unix/syscall-template.S:81
#1  0x0000000000467b03 in Ptrace::solibThreadMain() ()
#2  0x0000000000467cb7 in Ptrace::threadStatic(void*) ()
#3  0x00007ffff7264df3 in start_thread (arg=0x7ffff6338700) at pthread_create.c:308
#4  0x00007ffff68643dd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:113

Thread 1 (Thread 0x7ffff7fdd740 (LWP 24624)):
#0  0x0000000000477c9a in HtmlWriter::escapeHtml(std::string const&) ()
#1  0x0000000000473956 in HtmlWriter::writeOne(kcov::WriterBase::File*) ()
#2  0x0000000000476d83 in HtmlWriter::write() ()
#3  0x000000000047b085 in kcov::OutputHandler::produce() ()
#4  0x000000000045c227 in Collector::run(std::string const&) ()
#5  0x000000000047a700 in main ()

(gdb) info f 0
Stack frame at 0x7fffffffddf0:
 rip = 0x477c9a in HtmlWriter::escapeHtml(std::string const&); saved rip 0x473956
 called by frame at 0x7fffffffe120
 Arglist at 0x7fffffffdde0, args: 
 Locals at 0x7fffffffdde0, Previous frame's sp is 0x7fffffffddf0
 Saved registers:
  rbx at 0x7fffffffddd8, rbp at 0x7fffffffdde0, rip at 0x7fffffffdde8
(gdb) print *(char**)0x7fffffffdde0
$1 = 0x7fffffffe110 "`\341\377\377\377\177"
(gdb) 

Strange interaction with python 'unittest' package

This is with kcov21 built on SLES11 SP3 using gcc4.8.3.
I have some python unit test code using the Python 2.6.9 'unittest' package; when run from a shell, the test code calls unittest.main(), which in turn calls all test cases (methods on a class inheriting from unittest.TestCase). Sample output:

Ran 28 tests in 0.030s

OK

When the same code is run under kcov, no unit test cases are found to execute, so no coverage is generated:

Ran 0 tests in 0.000s

OK

Any suggestions on how to proceed debugging this?

kcov issue with braces in if check

Hi,again,

I hope I'm not keeping you from other (paying) work. ;)

I have another test case that looks like this:

#!/bin/bash
echo "Hello"
function some_test
    {
    test "${1}" == "--quiet" &&
        { quiet=${1} ; shift ; }
    }

The kcov report correctly shows the echo as green (covered) and the test statement as red (uncovered.) However, it shows the brace delimited quiet statement as while (uncovered) and the total coverage as 50%.

If I change the quiet line to either of these

        {
        quiet=${1} ; shift ;
        }
        {
        quiet=${1}
        shift
        }

kcov correctly reports them all as uncovered.

kcov doesn't pass Ctrl+C to application which called setpgid()

If kcov is used on an application which calls setpgid() to change into a separate process group, pressing Ctrl+C will terminate kcov while the checked application stays alive.

Here's some example code to reproduce this:

#include <stdio.h>
#include <unistd.h>

int main (int argc, char** argv)
{
    printf("pid: %d\n", getpid());
    printf("pgid: %d\n", getpgid(0));

    printf("calling setpgid...\n");
    const int result = setpgid(0, 0);
    printf("setpgid result: %d\n", result);

    printf("pid: %d\n", getpid());
    printf("pgid: %d\n", getpgid(0));

    sleep(1000);

    return 0;
}

When run as eg. kcov /tmp/test test-setpgid the application will show that it initially belongs to the process group of kcov itself; after calling setpgid() it is in its own process group. When it then sleeps, kcov can be killed easily but the test application will remain running. It must be killed explicitly.

IIUC process groups are meant exactly for this kind of behavior: signals sent to the process group leader are sent to all processes in the group. By calling setpgid() the tested application explicitly prevents this. However I think kcov should try to "override" this behavior, by catching SIGINT/SIGTERM and explicitly sending it to the tested application.

Background: I want to use kcov as "transparent drop-in" in my tests: the command line for the tested application should just get kcov results/coverage/ prepended, and the tested application should behave as usual except that coverage info is collected. This means that when the test framework tries to terminate the tested application, it will now actually terminate kcov - that's why I need kcov to pass the signal to the tested application.

Do you think this feature could be added?

kcov trying to read non existent files.

Hi, again,

We have some shell script code which sources in a dynamically generated file when it runs. To test it the unittest script simply creates a dummy file to be sourced from within a test directory. When the test complets the directory (and the dynamic file) is deleted.

The test itself is a Python unittest script, so it runs many different tests, all of which (currently) write to the same kcov output directory for that testrun, so that we can accumulate test results for the entire file being tested.

If I start with an empty kcov_out directory and run one test it passes. However, if I run the entire test script the first test passes, but all subsequent tests fail because kcov reports this error and returns a failure exit status:

kcov: error: File /tmp/test_dir/file.dat exists, but can't be read???

I can reproduce this with the following test script and command sequence:

% cat test.sh
#!/bin/bash
test -f file.dat &&
    source file.dat
rm -f file.dat

% echo -e "some_var=some_value\n" > file.dat
% kcov /tmp/kcov_out ./test.sh
% kcov /tmp/kcov_out ./test.sh
kcov: error: File /tmp/test_dir/file.dat exists, but can't be read???

I tried excluding this file with --exclude-pattern=file.dat, and that seemed to work, but using --exclude-pattern='*.dat' did not work.

So, two things:

  1. Is there a better way to make kcov not complain about files in its database that are no longer present? (Could the error message be phrased better? Ie, 'File ... previously checked but can no longer be found'.)
  2. Does the --exclude-pattern use patterns other than filename metacharacters, or does it not use patterns?

kcov not covering case statements with balanced parenthesis

We use balanced parenthesis in all of our shell case statement so that syntax hightlighting and brace matching works correctly in editors. However, if I test this example script four times, passing it 'a', 'b', 'c', and 'd' successively :

#!/bin/bash
case ${1} in
(a)
   echo Got $1
   ;;
(b)
   echo Got $1
   ;;
c)
   echo Got $1
   ;;
*)
   echo Got $1
   ;;
esac

kcov only reports 71.4% coverage. The case and echo statements are all green, the 'c0' and '*0' lines are white (not executed, I think) but the 'a' and '(b)' lines are red for not covered

Lookup program-to-cover in PATH unless full path is given

We currently use the Python coverage packge to check our python code, and parse the data files output by that tool to verify that all tested modules have the expected coverage. We'd like to do something similar with shell scripts, but since kcov doesn't generate a similarly formatted text file it seemed that the json file(s) might be way to go. However, I tried a simple test to read the json fail which failed with this traceback.

 >>> obj = json.load(open("index.json"))
Traceback (most recent call last):
...
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

I then tried pasting the contents of the index.json file into http://jsonlint.com and it would not validate there either. Am I doing this wrong, or do I just misunderstand what these files actually are? Is there better way to parse them in python?

Also, is there a more appropriate forum for asking this sort of question instead of this issue tracker?

Thanks.

Mark E. Hamilton

cmake error:Could NOT find LibDwarf (missing: LIBDWARF_LIBRARIES LIBDWARF_INCLUDE_DIRS)

already install libbdwraft , however ,when I run cmake, always alert:
Could NOT find LibDwarf (missing: LIBDWARF_LIBRARIES LIBDWARF_INCLUDE_DIRS)

ls /usr/local/lib/libdwarf.*
/usr/local/lib/libdwarf.a /usr/local/lib/libdwarf.h

cmake '-DCMAKE_C_FLAGS:STRING=-O3 -march=i686' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ..

CMake Warning (dev) at src/CMakeLists.txt:3 (project):
Policy CMP0048 is not set: project() command manages VERSION variables.
Run "cmake --help-policy CMP0048" for policy details. Use the cmake_policy
command to set the policy and suppress this warning.

The following variable(s) would be set to empty:

PROJECT_VERSION
PROJECT_VERSION_MAJOR
PROJECT_VERSION_MINOR
PROJECT_VERSION_PATCH

This warning is for project developers. Use -Wno-dev to suppress it.

CMake Error at /usr/local/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:136 (message):
Could NOT find LibDwarf (missing: LIBDWARF_LIBRARIES LIBDWARF_INCLUDE_DIRS)
Call Stack (most recent call first):
/usr/local/share/cmake-3.0/Modules/FindPackageHandleStandardArgs.cmake:343 (_FPHSA_FAILURE_MESSAGE)
cmake/FindLibDwarf.cmake:57 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
src/CMakeLists.txt:7 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/mingchao.xiamc/software/kcov-19/build/CMakeFiles/CMakeOutput.log".

  • make -j2
    make: *** No targets specified and no makefile found. Stop.

Usage question regarding kcov --report-only

This may be more of a usage question than an issue (not sure)...

If I've run a number of 'kcov --collect-only /path/to/coverage' tests on various scripts/executables and now want to generate the coverage report, 'kcov --report /path/to/coverage' it is expecting me to specify an in-file. Even if I specify a small "no-op" script as the in-file, kcov is exit with a return code of 1.

Thanks!
Chris

introduction to users

How can I get the coverage of a server which never stops?I tried this:
kcov --pid=15390 ~/apache_muzong/htdocs/test2/

but,it seems does not supportted

Usage: kcov [OPTIONS] out-dir in-file [args...]

Where [OPTIONS] are
-h, --help this text
-p, --pid=PID trace PID instead of executing in-file,
in-file is optional in this case
-l, --limits=low,high setup limits for low/high coverage (default 25,75)

--collect-only Only collect coverage data (don't produce HTML/
Cobertura output)
--report-only Produce output from stored databases, don't collect

--include-path=path comma-separated paths to include in the coverage report
--exclude-path=path comma-separated paths to exclude from the coverage
report
--include-pattern=pat comma-separated path patterns to include in the
coverage report
--exclude-pattern=pat comma-separated path patterns to exclude from the
coverage report
--uncommon-options print uncommon options for --help

Examples:
kcov /tmp/frodo ./frodo # Check coverage for ./frodo
kcov --pid=1000 /tmp/frodo # Check coverage for PID 1000
kcov --include-pattern=/src/frodo/ /tmp/frodo ./frodo # Only include files
# including /src/frodo
kcov --collect-only /tmp/kcov ./frodo # Collect coverage, don't report
kcov --report-only /tmp/kcov ./frodo # Report coverage collected above

bash: Unexpected output when redirecting stderr>stdout

Hi, again,

I have another simple test script:

#!/bin/bash
test -n "$FILE" && redirect="> ${FILE}"
eval echo stuff  2>&1 ${redirect:-}

When I ran it with kcov I expected to just see 'stuff'. What I got was this:

% kcov /tmp/kcov_out test.sh
[email protected]@3@echo stuff
stuff

When I set the FILE variable and run it again I get this:

% FILE=blather kcov /tmp/kcov_out test.sh
[email protected]@3@echo stuff
% cat blather
stuff

Mark E. Hamilton

traced application crashes due to to int3 instructions in bad place

This might well be a bug in my application or in the compiler, but it might be useful to document this issue here anyway: when running a somewhat complicated application under kcov, the application crashes with Segmentation Fault (it doesn't crash when run without kcov, and it's also pretty much Valgrind-clean).

The crash happens for example in std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_fill_insert() called from std::vector::resize().

Here's what gdb shows in disassemble /r (look at 0x080d1658):

   0x080d164d <+349>:    8b 45 08       mov    0x8(%ebp),%eax
   0x080d1650 <+352>:    8b 4d dc       mov    -0x24(%ebp),%ecx
   0x080d1653 <+355>:    8b 5d 08       mov    0x8(%ebp),%ebx
   0x080d1656 <+358>:    89 10  mov    %edx,(%eax)
   0x080d1658 <+360>:    89 cc  mov    %ecx,%esp
   0x080d165a <+362>:    04 cc  add    $0xcc,%al
   0x080d165c <+364>:    d0 8b cc d4 01 d0      rorb   -0x2ffe2b34(%ebx)
   0x080d1662 <+370>:    89 43 08       mov    %eax,0x8(%ebx)
   0x080d1665 <+373>:    83 c4 4c       add    $0x4c,%esp
   0x080d1668 <+376>:    5b     pop    %ebx
   0x080d1669 <+377>:    5e     pop    %esi

Here's what objdump -d shows for the same place:

 80d164d:       8b 45 08                mov    0x8(%ebp),%eax
 80d1650:       8b 4d dc                mov    -0x24(%ebp),%ecx
 80d1653:       8b 5d 08                mov    0x8(%ebp),%ebx
 80d1656:       89 10                   mov    %edx,(%eax)
 80d1658:       89 48 04                mov    %ecx,0x4(%eax)
 80d165b:       89 d0                   mov    %edx,%eax
 80d165d:       8b 55 d4                mov    -0x2c(%ebp),%edx
 80d1660:       01 d0                   add    %edx,%eax
 80d1662:       89 43 08                mov    %eax,0x8(%ebx)
 80d1665:       83 c4 4c                add    $0x4c,%esp
 80d1668:       5b                      pop    %ebx
 80d1669:       5e                      pop    %esi

IIUC there's an int3 instruction at 0x080d1659, in the middle of another instruction?

I think I'd seen a similar issue with bcov as well one time, and traced it back to weird debug info (which pointed into the middle of an x86 instruction). Not sure if that's the same problem again, because this time I have a newer compiler and platform.

This happens with latest kcov, with an application compiled with g++ 4.4.7-3 under RHEL6.4 x86-64.

Merging coverage of different tests using the same executable

Hi,

thanks again for fixing the shared library coverage. My current issue lies with the merging of coverage from multiple runs of the same executable.
If I run

kcov /tmp/kcov app -opt1
kcov /tmp/kcov app -opt2

then /tmp/kcov holds only the results of the last invocation of "app".

If I use different directories for each invocation and then use kcov-merge, I seem not to be able to look at individual source file coverage anymore.

Is there a way to aggregate coverage from multiple runs of the same executable (with different options?)

Best wishes,
Matthias

Coverage of bash script fails on cat<<EOF || foo statement

I agree that the construct is bad and should never be used, but I'm working on a project where it's heavily used...

#!/bin/bash

# This works
cat<<EOF
foo
bar
EOF

echo "This also works"

# This breaks
cat<<EOF || echo "cat failed"
foo
bar
EOF

echo "From here on it do not work!"

child thread stuck but main thread keep running when using kcov pid attach

Hi, simon kagstrom:
I download kcov lasted code from this project, compile it with gcc4.4, and try to use kcov to collect coverage data on my cpp project, but i got a problem when using pid attach method (i have to use pid attach method). How can i fix this or work around it?
On platform RHEL6 (Red Hat Enterprise Linux Server release 6.1 (Santiago)), kcov only makes child thread stuck; on platfrom RHEL5 (Red Hat Enterprise Linux Server release 5.4 (Tikanga)), kcov makes main thread and child thread stuck both.

kcov pid attach command like this:

kcov --pid=the_test_process_pid kcov/output/directory ./program_under_test

My project is a multi-thread program implemented with pthread. To demonstrate this issue, i simplify the model to the code below.

#include <iostream>
#include <fstream>
#include<pthread.h>
#include<sys/types.h>
#include<unistd.h>

void* thread_main(void *) {
  std::ofstream ofs("thread.log");
  int i = 0;
  while(true) {
    ofs << ++i << std::endl;
    sleep(1);
  }
}

int main() {
  pthread_t t;
  int thread_code = pthread_create(&t, NULL, thread_main, NULL);
  std::ofstream ofs("main.log");
  int i = 0;
  while(true) {
    ofs << ++i << std::endl;
    sleep(1);
  }
  return 0;
}

system version:
Linux version 2.6.32-131.21.1.tb477.el6.x86_64 (gcc version 4.4.4 20100726 (Red Hat 4.4.4-13) (GCC) )

gcc:
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.6 20110731 (Red Hat 4.4.6-3) (GCC)

thank you!

show combined coverage

Is it possible to display the combined coverage from running different applications? I have several unit test applications (small applications testing particular parts of the same API), and would like to see coverage info for the entire API after running all tests.

Currently the HTML report contains a a separate coverage report for each unit test application. I'd like to see a single report instead (or in addition to the separate reports).

HTML output generates many file-duplicates

When running kcov multiple times, the HTML output contains many instances of the same file, e.g., file.1.html, file.2.html etc. For identical files, this is unnecessary and will just consume space.

The reason for this is that the HTML output uses a flat directory structure whereas the binary might contain source files from several directories. I.e., game-engine/data.c and sound/data.c would produce the same file, so kcov will add an incrementing counter to the filename to avoid this clash.

A better way would be to use a hash of the contents instead, i.e., produce something like

file.54fdc922.html
file.99cba13.html

etc.

kcov might hang on signal reception due to free() being called from signal handler

Sorry for yet another issue report :-/ I already feel bad for coming up with all these quirks...

Sometimes kcov hangs when it receives a termination signal (eg. signal 15 - SIGTERM). The traced process itself is in zombie state (ps shows it as <defunct>).

GDB shows that kcov hangs inside the destructors called from the signal handler (here in thread 2):

(gdb) info threads 
  Id   Target Id         Frame 
  2    Thread 0x7f5514eb0720 (LWP 8351) 0x0000003bd22f806e in __lll_lock_wait_private ()
   from /lib64/libc.so.6
* 1    Thread 0x7f5514eae700 (LWP 9002) 0x0000003bd2a0ed8d in open64 () from /lib64/libpthread.so.0
(gdb) bt
#0  0x0000003bd2a0ed8d in open64 () from /lib64/libpthread.so.0
#1  0x000000000041b8a6 in Ptrace::solibThreadMain() ()
#2  0x000000000041ba59 in Ptrace::threadStatic(void*) ()
#3  0x0000003bd2a07851 in start_thread () from /lib64/libpthread.so.0
#4  0x0000003bd22e890d in clone () from /lib64/libc.so.6
(gdb) thread 2
[Switching to thread 2 (Thread 0x7f5514eb0720 (LWP 8351))]
#0  0x0000003bd22f806e in __lll_lock_wait_private () from /lib64/libc.so.6
(gdb) bt
#0  0x0000003bd22f806e in __lll_lock_wait_private () from /lib64/libc.so.6
#1  0x0000003bd227cf70 in _L_lock_5189 () from /lib64/libc.so.6
#2  0x0000003bd227897b in _int_free () from /lib64/libc.so.6
#3  0x0000000000411b9c in Collector::~Collector() ()
#4  0x000000000042a606 in do_cleanup() ()
#5  0x000000000042a668 in ctrlc(int) ()
#6  <signal handler called>
#7  0x0000003bd2276155 in malloc_consolidate () from /lib64/libc.so.6
#8  0x0000003bd2279385 in _int_malloc () from /lib64/libc.so.6
#9  0x0000003bd227a911 in malloc () from /lib64/libc.so.6
#10 0x00007f551512b51d in operator new (sz=16352) at ../../.././libstdc++-v3/libsupc++/new_op.cc:52
#11 0x00007f551518b069 in allocate (__n=<optimized out>, this=<optimized out>)
    at /mnt/usb2/inst/gcc-4.7.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/new_allocator.h:94
#12 std::string::_Rep::_S_create (__capacity=16327, __old_capacity=<optimized out>, __alloc=...)
    at /mnt/usb2/inst/gcc-4.7.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:609
#13 0x00007f551518bdd8 in std::string::_Rep::_M_clone (this=0x1be4f00, __alloc=..., 
    __res=<optimized out>)
    at /mnt/usb2/inst/gcc-4.7.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:631
#14 0x00007f551518bec0 in std::string::reserve (this=this@entry=0x7fff339a6eb0, __res=<optimized out>, 
    __res@entry=8194)
    at /mnt/usb2/inst/gcc-4.7.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:512
#15 0x00007f551518c3b6 in std::string::append (this=0x7fff339a6eb0, __str=...)
    at /mnt/usb2/inst/gcc-4.7.3/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/basic_string.tcc:334
#16 0x00000000004261ab in HtmlWriter::writeOne(kcov::WriterBase::File*) ()
#17 0x000000000042a5a4 in HtmlWriter::write() ()
#18 0x0000000000430972 in kcov::OutputHandler::produce() ()
#19 0x00000000004115d7 in Collector::run(std::string const&) ()
#20 0x000000000042ab43 in main ()

I don't know how to reproduce this reliably; it happens in maybe one out of 20 cases here, when running my application under kcov, performing some automated test, then killing kcov.

This happens under RHEL6.4 x86_64.

I think the hang happens because free() is called from the signal handler, when the malloc data structures are possibly in an inconsistent state.

How about completely removing do_cleanup() and exit(0) from the signal handler? When the traced application is killed, the kernel-engine should do a clean exit anyway?
I tried this and it basically worked, except that kcov returns exit code 255 (I think) instead of the error code 0 from the application - will have to look into this more closely.

no code coverage for lines after commands like "Z=`a <<$PATH`" or setting PS4 variable

Hi Simon,

I have a simple shell script which sources a env file and prints and the i am not able to get the code coverage for the lines after the following 2 lines were executed.

  1. If a input re-direction sing is used like "CURR_PATH=a << $PATH"
  2. If the shell prompt variable is set like
    PS4_FORMAT=' \D{%Y%m%d-%k:%M:%S}$(printf " %-20s:%-4d" ${BASH_SOURCE##*/} ${LINENO}):'
    export PS4="$PS4_FORMAT"

Contents of scripts
[
chetan_clust_1_01:~ # cat 1.env

!/bin/bash

PRIVPORTS="0:1023"
SSH_PORT=22
SMTP_PORT=25

CURR_PATH=a << $PATH 2>/dev/null
echo $CURR_PATH

PS4_FORMAT=' \D{%Y%m%d-%k:%M:%S}$(printf " %-20s:%-4d" ${BASH_SOURCE##*/} ${LINENO}): '
export PS4="$PS4_FORMAT"

DHCP_PORTS=67:68
TFTP_PORT=69
HTTP_PORT_PRIV=8080

chetan_clust_1_01:~ # cat 1.sh

!/bin/bash

. ./1.env
echo "hello" 2>/dev/null
CURR_PATH=pwd
export MY_PATH="$CURR_PATH"
echo "world"
chetan_clust_1_01:~ #

]

Can you please help me to identify what could be the issue. Attaching the code coverage snapshots for each of the 2 cases

issue_1
issue_2

Thanks and Regards
Chetan

Is kcov supported on rhel 6.5, as cmake is failing to find LibDwarf

Hi Simon,

I am trying to build kcov on rhel 6.5 and facing issue with cmake.
Is kcov supported with rhel 6.5 ? If yes can you please let me know what am i missing.

chetan_clust_1_01:~ # git clone https://github.com/SimonKagstrom/kcov.git
Initialized empty Git repository in /home/support/kcov/.git/
remote: Counting objects: 5627, done.
remote: Compressing objects: 100% (56/56), done.
remote: Total 5627 (delta 23), reused 0 (delta 0)
Receiving objects: 100% (5627/5627), 6.17 MiB | 567 KiB/s, done.
Resolving deltas: 100% (3777/3777), done.
chetan_clust_1_01:~ # cd kcov
chetan_clust_1_01:/kcov # ls
ChangeLog cmake CMakeLists.txt COPYING COPYING.externals CPack.local.cmake data doc INSTALL README src tests
chetan_clust_1_01:
/kcov # echo $CMAKE_PREFIX_PATH
/usr/lib64/elfutils:/usr/include/libdwarf
chetan_clust_1_01:~/kcov #

chetan_clust_1_01:~/kcov # cmake .
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Found LibElf: /usr/lib64/libelf.so
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:57 (MESSAGE):
Could NOT find LibDwarf (missing: LIBDWARF_LIBRARIES LIBDWARF_INCLUDE_DIRS)
Call Stack (most recent call first):
cmake/FindLibDwarf.cmake:57 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
src/CMakeLists.txt:7 (find_package)

-- Configuring incomplete, errors occurred!
chetan_clust_1_01:~/kcov # cat /etc/issue
Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel \r on an \m

chetan_clust_1_01:/kcov # rpm -qa | grep -i LibDwarf
libdwarf-devel-20140413-1.el6.x86_64
libdwarf-20140413-1.el6.x86_64
chetan_clust_1_01:
/kcov #
chetan_clust_1_01:/kcov # rpm -ql libdwarf-devel-20140413-1.el6.x86_64
/usr/include/libdwarf
/usr/include/libdwarf/dwarf.h
/usr/include/libdwarf/libdwarf.h
/usr/lib64/libdwarf.so
/usr/share/doc/libdwarf-devel-20140413
/usr/share/doc/libdwarf-devel-20140413/libdwarf2.1.pdf
/usr/share/doc/libdwarf-devel-20140413/libdwarf2p.1.pdf
/usr/share/doc/libdwarf-devel-20140413/mips_extensions.pdf
chetan_clust_1_01:
/kcov #

It would be nice to be able to change the path searched for the source code to generate the coverage report

First of all let me start by saying that I really like kcov and how easy it is to use.

However, It doesn't seem like kcov can handle the source code being located in a different location from the path that was compiled into the binary. This creates an issue if the target machine doesn't have the same directory layout as the compile machine.

To fix this I added 2 command line options to the kcov. The first option --original-path and --new-path. Basically, this replaces the string in --original-path with the string in --new-path. So if you ran the following command:

kcov --original-path=/home/user/git_repo/ --new-path=/tmp/ /tmp/testApp.kCov /tmp/testApp

The string /home/user/git_repo would be replaced by /tmp/ and kcov would search for the source code in /tmp/testApp.

Anyway, let me know if this makes sense and/or you want me to add anything to the code attached.

Now I just need to figure out how to attach the changes to this issue. (sorry new to actually using github :)

Is is true that some executable statements can not be instrumented?

Dear all,
The codes of line from 273 to 277 in coverage report of the "/ska/projects/kcov/src/reporter.cc",
(the link: http://simonkagstrom.github.io/kcov/kcov-example-output/ut/reporter.cc.64.html)
273 : void clearHits()
274 : {
275 : for (auto &it : m_addrs)
276 : it.second = 0;
277 : }
Why these codes are not instrumented?

I also got confused that in the sample codes on kcov homepage.
Why codes from line 120 to 132 are not instrumented?

I am not familiar with code instrumentation techniques and how they are implemented neither.
Maybe I am wrong, but is this a bug?

Thanks!

merged report does not show accumulated data

Originally part of Issue #37.

Running

kcov /tmp/kcov ./dlopen
kcov /tmp/kcov ./argv_dependent
kcov /tmp/kcov ./argv_dependent 1 2  # Will accumulate stuff

works fine both in the normal and the merged reports, but with

kcov /tmp/kcov ./argv_dependent
kcov /tmp/kcov ./argv_dependent 1 2  # Will accumulate stuff
kcov /tmp/kcov ./dlopen

only the last part of argv_dependent will show up in the merged report.

kcov numbers next to line number

Every executable line of code in kcov starts with this:

78 3 / 9 :

I get that the first number is the line number, but what do the second and third numbers mean? There's nothing explaining what they are on the front page or in the manual.

Measuring executed shell scripts coverage under shunit

Hi,

Referencing this: http://stackoverflow.com/questions/27555639

Recipe to reproduce:
git clone git://github.com/vlajos/misspell_fixer.git
cd misspell_fixer
git checkout -qf 2d16e17c7901bd06e24d67f315e782f148d45d0b
curl -L "https://shunit2.googlecode.com/files/shunit2-2.1.6.tgz" | tar zx
rm -rf coverage;/usr/local/bin/kcov coverage/ test/tests.sh

And there isn't anything in the output regarding the misspell_fixer.sh

Finally I rewrote most of my script this way:
vlajos/misspell-fixer@b5ec1f7

Thank you.

Best regards,
Lajos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.