3

I am trying to get html coverage for a test using gcc 4.8.2 and lcov 1.10. I am sure that my source, objects and gcov files are at same place and that I'm running lcov from directory where I ran my compiler from as well.

I'm getting the following error:

$ lcov --capture --directory "objs/i386/MinGW/Os_SingleCore_SC3
/IocTest_tests_SingleCore_SC3" --output-file coverage.info
Capturing coverage data from objs/i386/MinGW/Os_SingleCore_SC3/IocTest_tests_SingleCore_SC3
Found gcov version: 4.8.2
Scanning objs/i386/MinGW/Os_SingleCore_SC3/IocTest_tests_SingleCore_SC3 for .gcda files ...
Found 3 data files in objs/i386/MinGW/Os_SingleCore_SC3/IocTest_tests_SingleCore_SC3
Processing IocTest_tests_SingleCore_SC3/IocTest.gcda
geninfo: WARNING: cannot find an entry for objs#i386#MinGW#Os_SingleCore_SC3#IocTest_tests_SingleCore_SC3#IocTest.c.gcov in .gcno file, skipping file!
geninfo: WARNING: no data found for /cygdrive/e/testRepo/WinPort-Os-cd354a27d1d9/WinPort/Os/Tests/OS_REQ/objs\i386\MinGW\Os_SingleCore_SC3\IocTest_tests_SingleCore_SC3\IocTest.c
Processing IocTest_tests_SingleCore_SC3/OS_REQ.gcda
geninfo: WARNING: cannot find an entry for objs#i386#MinGW#Os_SingleCore_SC3#IocTest_tests_SingleCore_SC3#OS_REQ.c.gcov in .gcno file, skipping file!
geninfo: WARNING: no data found for /cygdrive/e/testRepo/WinPort-Os-cd354a27d1d9/WinPort/Os/Tests/OS_REQ/objs\i386\MinGW\Os_SingleCore_SC3\IocTest_tests_SingleCore_SC3\OS_REQ.c
Processing IocTest_tests_SingleCore_SC3/TestMain.gcda
geninfo: WARNING: cannot find an entry for objs#i386#MinGW#Os_SingleCore_SC3#IocTest_tests_SingleCore_SC3#TestMain.c.gcov in .gcno file, skipping file!
geninfo: WARNING: no data found for /cygdrive/e/testRepo/WinPort-Os-cd354a27d1d9/WinPort/Os/Tests/OS_REQ/objs\i386\MinGW\Os_SingleCore_SC3\IocTest_tests_SingleCore_SC3\TestMain.c
Finished .info-file creation
CodesInChaos
  • 106,488
  • 23
  • 218
  • 262
risaldar
  • 71
  • 1
  • 2
  • 10

3 Answers3

1

Firstly I would suggest to check if gcov returns correct coverage data. Means need to run gcov tool and check *.gcov file for actual result. If it returns any coverage.

Secondly you could use --base-directory, for example

$ lcov --base-directory .  --directory . -c -o gcov/lcov.info
valbok
  • 321
  • 2
  • 5
0

I found these steps to work: https://codeflu.blog/2014/12/26/using-gcov-and-lcov-to-generate-beautiful-c-code-coverage-statistics/

Did you compile first with -g -O0 and --coverage flags? Did you copy the .gcno files from the build directory over to the same directory with the .gcda files?

Have you tried adding the option --ignore-errors gcov,source,graph ? It may actually be working from some files and this will ensure lcov continues to run past any problem files. If you find files that do work then you can step back and figure out why the files above are not working for lcov. Perhaps they are missing their corresponding .gcno files.

v2v1
  • 640
  • 8
  • 18
0

Update CMakeList.txt to add following flags:

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_OUTPUT_EXTENSION_REPLACE 1)

goto build dir

cd {project/lib}
rm -rf *  //Remove all items if you want 
cmake ..
make
./MyTest

Run test cases to get .gcda files. There might be other ways to generate gcda files but I prefer this way

lcov --capture --directory . --output-file AnyName.info

AnyName.info will contain output

genhtml AnyName.info --output-directory CODE_COVERAGE

you will find one directory CODE_COVERAGE in current directory, go to CODE_COVERAGE and double click on index.html it will show current code coverage for test cases

Kara
  • 6,115
  • 16
  • 50
  • 57
Mahipal
  • 589
  • 4
  • 7