2

When I run gcov then the output says 87% covered... then I want to use gcovr, but it does never work. I tried to run from many directories, with lots of options. In some cases, a few files I get coverage but not the file I want to see.

My project consists of 3 files:

  • src\main.c
  • src\makefile
  • tst\test1.c
  • tst\test2.c
  • tst\makefile
  • tst\obj\all object files, gcno, gcda are stored here...
  • build\build.bat to make the project (windows)

Should I change the directory structure? How to see which version of gcov I should use? I want to see the coverage for main.c, but only get the coverage for test1.c and test2.c and those are not relevant for coverage!!

Next to the test files, I have include directories on C:\compiler which are not required for coverage.

I tried Python27:

python c:\python27\scripts\gcovr -g --object-directory=. -r ..\..\..\ --html --html-details -o program.html -v

I tried Python36:

c:\python36\scripts\gcovr --use-gcov-files -v --object-dir=.

But never get the coverage for my device under test. Only gcov without gcovr works, so the files must be correct.

amon
  • 57,091
  • 2
  • 89
  • 149
Bart Mensfort
  • 995
  • 11
  • 21
  • (1) Can you add which gcovr version and which GCC/gcov version you are using? (2) From which directories are you running gcovr? – amon Mar 27 '18 at 08:49
  • Can you also explain why you need to use the -g/--use-gcov-files flag? That option assumes that you have previously run gcov for all source files you are interested in. Can you show how you are invoking gcov? – amon Mar 28 '18 at 10:40
  • gcov is easy to use, but the output is not usefull for Jenkins. I didn't try to make it compatible, instead debugged gcovr. I forked the main project and made changes for windows at: https://github.com/barthoukes/gcovr and they work for C and C++ in WIndows 10. For Linux it's working reasonable already. Just get 1 file, gcovr. It is actually a python script, easy to debug. – Bart Mensfort Apr 15 '18 at 16:19

2 Answers2

0

try add -f '' option. There bug in gcovr which is getting out when we build out of tree

  • Already found the issue by disabling some lines inside gcovr itself. Actually, the script is very small so it's easy to debug. In fact the \ is duplicated and changed to \\, so I found c:\dir\source\ is changed to C\\:\\\\dir\\source\\ and this will never compare anymore with c:\dir\source and then all files are filtered out. In Linux this problem is not there, so gcovr needs more work to make windows compatible, – Bart Mensfort Mar 28 '18 at 05:45
  • @BartMensfort I'm confident there might be a solution without having to hack around in the gcovr code if you can answer my comment to your question – from which directories are you running gcovr? Filtering on Windows is [known to have problems](http://gcovr.com/guide.html#using-filters). If you help me understand your problem, this will help me [develop a more sensible approach to filtering](https://github.com/gcovr/gcovr/issues/191). – amon Mar 28 '18 at 10:37
0

I found several problems when running the GCOVR in Windows, especially concerning \ instead of / and using colon character : in the name like C:\file.c

When you use \ it needs to use 2 of them \ and somewhere in the gcovr it changes to \\ or \\\ ... this is not going well, at some point it tries to find the root of your source files by subtracting 2 paths. but it cannot find this, e.g. \a\b\c\d it will not find in \a\b\c\d . So, look in : [github.com/barthoukes/gcovr][1]

THe solution is still very dirty, but it works for my projects in Windows. I think the gcovr people also are discussing this problem.

You only need the file: gcovr

Bart Mensfort
  • 995
  • 11
  • 21
  • I tried to look at your gcovr fork but couldn't find your changes – could you perhaps `git push` them so that they are publicly visible? Btw I am one of the gcovr maintainers, so I'm very interested in the solution you came up with. – amon Apr 16 '18 at 11:13