How to make gcov and gcovr pick up source and header files - gcov

I am trying to generate coverage report for project using .bat file as detailed below.
I see very few .gcov files. Also, when I click on link on generated html output, I am not able to see file details (file not found error). How do I fix it?
After I execute .bat file, I see output like ‘parsing coverage data for QString.h’ (QT library files). Is it expected?
I have seen many related questions but I am not able to figure out
(in report_coverage.bat)
set GCovrpath= C:\python37\script\lib\
set GCovpath= C:\abc\ghj\bin\
set datafiles= C:\source\mywork\root\testing\unittests\rose\build\debug\
set gcovr_src= C:\source\mywork\root\
%GCovpath%gcov.exe %datafiles% >> output.log
gcovr %datafiles% -s -p --html --html-details --gcov-executable %GCovpath%gcov.exe -o Test.html –verbose
Here are details….
Compile and execute code using
QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage
QMAKE_LFLAGS += --coverage
.GCNO and .GCDA files are generated as expected
It seems simple directory structure
Root
Header
Rose
Marigold
Jasmin
Source
Rose
Marigold
Jasmin
Testing
UnitTests
Rose
build
debug
Marigold
build
debug
Jasmin
build
debug
Thank you.
Update:
See answer below

I can not emphasis enough "\" for windows.
run this command from debug folder(because test.exe is here)
gcov -b -l -s C:\source\mywork\root\ debug\*.gcno
run this command from Unit tests folder (this will exclude .h files and files containing test)
gcovr -g -k -v --root C:\source\mywork\root\ -e ".*\.h" -e ".*test[_-|A-Z|a-z|0-9]*\.cpp" --html --html-details -o report.html

If you invoke gcov yourself, you need to run it from the same directory where the compiler was executed, and you need to give it either the path to the gcno, gcda, or source file. Gcov can only handle one input file at a time.
When gcov runs in the correct place, it can look at compilation metadata to find the correct source file. If there are errors about missing source files, that indicates that you didn't use the correct directory.
Gcovr runs gcov automatically, and has heuristics to figure out the correct directory. However, you should still run it from the directory where you started the compilation (typically, a build directory).
And gcovr will exclude coverage data if it doesn't belong to your project. If you have a separate build directory, you will need to set the --root argument to the directory containing your source code. Gcov processes coverage data for all files that were compiled, which makes this post-processing by gcovr necessary.
In verbose mode, gcovr will output “Parsing coverage data for <file>” when opening a gcov report. It will then use data within the file to decide whether it belongs to your project, and output “Filtering coverage data” if the source code is part of your project, “Excluding coverage data” otherwise.
There are multiple reasons why the coverage report might not be complete:
There is a problem with filtering.
Gcovr's heuristics can get confused when multiple files have the same name, e.g. two files called util.h in different directories.
Gcovr's --html-details report consists of multiple .html files, so make sure that they are all available.
In your BAT file, this invocation might work better:
gcovr --root ../src --print-summary --sort-percentage --html-details --gcov-executable %GCovpath%gcov.exe --output Test.html --verbose
assuming the following directory structure, and that you run gcovr from within build/:
your-project/
src/
Header/
...
Source/
...
Testing/
...
build/
...
If there are problems with a root path like ../src, consider using an absolute path like C:/path/to/the/src.

Related

Get bazel-bin directory easily in the terminal

I have generated some output files using bazel build, but its is a bit tedious to specify the path of the bazel-bin directory everytime I need to access the output.
In deeply nested bazel projects, not only do I need to get the specific repository, /Users/username/repos/organisation/folder/folder/repo, I also need to add the bazel-bin/folder1/folder2/folder3/folder4/binary_i_want. I would prefer to say $output/binary_i_want. Bazel should be able to get the project directory (as it looks up the workspace file), and find the bazel-bin, and then look for the equivalent directory I am in. This is because I might not be running it directly, but instead copying this file to an android device, with adb push.
Is this possible? Thank you
You can use $(bazel info bazel-bin)/binary_i_want for this.
Edit: Getting the complete path to an artifact generate by a rule is a bit more involved. One option using jq could be:
$(bazel info workspace)/$(bazel aquery //:some_path --output jsonproto 2>/dev/null | jq -r ".artifacts[0].execPath")
(Inspired by this answer: Bazel: How do you get the path to a generated file?)

cmake: Download easylogging++ and use sources directly

I would like to download easylogging++ package, extract the content and then directly use easylogging++.h and easylogging++.cc in my sources.
I started with this:
ExternalProject_Add(
easyloggingpp
PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/downloads
URL https://github.com/muflihun/easyloggingpp/archive/v9.96.4.tar.gz
INSTALL_COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp && cp src/easyloggingpp-9.96.4/src/* ${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp/)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp)
set(easylogging ${CMAKE_CURRENT_BINARY_DIR}/external/easyloggingpp/easylogging++.cc)
..
add_dependencies(myproject easyloggingpp)
This creates downloads/ directory in my project, but it's empty and no files appear in external/ directory, even the directory itself is not created.
How can I achieve downloading this package and directly merging its sources with mine? I would like to achieve something similar to bazel's new_http_archive.
It seems that ExternalProject_Add is not for the use case I am trying to implement. It looks like the download is only executed during compilation step, not the configuration step. That's a bummer.
I was able to achieve similar result by coding this manually and it works fairly well:
file(MAKE_DIRECTORY downloads external)
################################################################################
# Easylogging++
################################################################################
if(EXISTS "external/easyloggingpp")
else()
file(MAKE_DIRECTORY external/easyloggingpp)
file(DOWNLOAD
https://github.com/muflihun/easyloggingpp/archive/v9.96.4.zip
downloads/easyloggingpp.zip)
execute_process(COMMAND unzip downloads/easyloggingpp.zip -d downloads)
file(GLOB easyloggingpp_files downloads/easyloggingpp-9.96.4/src/easylogging++.*)
file(COPY ${easyloggingpp_files} DESTINATION external/easyloggingpp)
endif()
include_directories(external/easyloggingpp)
set(easyloggingpp external/easyloggingpp/easylogging++.cc)
This works perfectly fine for me and I adtually understand what is happening during the process. The cool things are that cmake . step doesn't download unless it is necessary.

How to setup and use lua squish?

I know it can be a dumb question , but how i can setup and use squish to compile my lua scripts.
I'm tired searching google and i can't find anything to explain me how to use
Someone can point me on right direction
I use lua 5.1 on windows OS
Thank you
First download and unpack the archive containing Squish's code. Alternatively, you may clone the repository. The change into the directory containing the squish.lua file. You will also need a Lua 5.1 executable (which I'll assume is called lua51.exe in the commands below).
The Unix Makefile in the archive contains roughly the following commands (translated to Windows) to build the squish tool:
bootstrap squish tool (without gzip compression or debug support for now)
lua51.exe squish.lua -q --with-minify --with-uglify --with-compile --with-virtual-io
prepare gzip compression modules
lua51.exe squish -q gzip
prepare debug support
lua51.exe squish -q debug
build final tool (with gzip compression and debug support)
lua51.exe squish -q --with-minify --with-uglify --with-compile --with-virtual-io --with-gzip --with-debug
The result is a Lua script squish (without the .lua extension) in the current directory. To use it you have to write a squishy file for your project and execute a command line similar to the last one above in the directory containing your squishy file.

Is there anyway to merge two gcov files into one

I am using gcov for coverage test in macosx platform. I finish the configuration for xcode by set:
1. Build Settings ==> Generate Test Coverage Files == Yes
2. Build Settings ==> Instrument Progaram Flow == Yes
3. Build Phases ==> Link Binary with library ==> add "libprofile_rt.dylib"
Then generate the files "Test.d, Test.dia, Test.gcno, Test.gcda, Test.o"
Then i use gcov-4.2 -b Test.gcno command to generate the Test.m.gcov file (this is what i want), but next time when i run test cases again, the files "Test.d, Test.dia, Test.gcno, Test.gcda, Test.o" will be generated again, and the data will be reset.
So I have two questions:
Is there any way for me to make the data in these coverage files accumulated so that i can run so many times of my project and then generate files at the end.
If the #1 is hopeless, could you tell me how to merge two Test.gcno files (generated by two times' running) into one. I try gcov in terminal, below are the options for gcov command:
gcov-4.2 -help
Usage: gcov [OPTION]... SOURCEFILE
Print code coverage information.
-h, --help Print this help, then exit
-v, --version Print version number, then exit
-a, --all-blocks Show information for every basic block
-b, --branch-probabilities Include branch probabilities in output
-c, --branch-counts Given counts of branches taken
rather than percentages
-n, --no-output Do not create an output file
-l, --long-file-names Use long output file names for included
source files
-f, --function-summaries Output summaries for each function
-o, --object-directory DIR|FILE Search for object files in DIR or called FILE
-p, --preserve-paths Preserve all pathname components
-u, --unconditional-branches Show unconditional branch counts too
For bug reporting instructions, please see:
<URL:http://developer.apple.com/bugreporter>.
Thanks for all your help in advance
The usual workflow for gcov is
Compile and link with coverage support (-fprofile-arcs -ftest-coverage)
Run your executables, possibly multiple times, possibly with different parameters / settings. This will create accumulative usage information in the .gcda files
Invoke gcov to get coverage statistics in a human-readable format (.gcov)
So basically, successive runs of the application will result in accumulated coverage statistics. It's just that these accumulations will take place in the .gcda files, not the .gcov files, so you have to re-run gcov each time you want to see updated statistics.

lcov issue generating output file

I have been trying to get the code coverage of some test cases I have been running using lcov.
However when I run
lcov --directory $PWD --capture --output-file lcov.output
I am getting a warning
geninfo: WARNING: cannot find an entry for test.c.gcov in .bb file, skipping file!
If I run gcov directly on test.c, I am able to generate a gcov output which successfully shows the utilization.
I am new to code coverage. Any help to fix this would we greatly appreciated.
There had been a change in the gcov format at some point.
Basically the issue is because current versions of gcov produces a header with source file name etc.
Lcov expected this header and tried to extract this failing which the error was shown.
As a workaround, I modified the LCOV code such that if the header returned was empty, the source file name is assumed directly from the gcov file name. This solution may not be the most elegant as it may cause incompatibles if the gcov file is created with a name different from the source file name
Update: This particular issue was due to a bug in lcov-1.8. The versions from lcov-1.10 should have the fix for this. (http://ltp.cvs.sourceforge.net/viewvc/ltp/utils/analysis/lcov/bin/geninfo?r1=1.106&r2=1.107)

Resources