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)
Related
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.
According to How does AOSP 9.0 build system link the executable? and What does # mean in this clang command in AOSP build log? , when linking a module, AOSP seems to produce a .rsp file that contains all the obj files that the module need,and pass the file name as a parameter to the link command, for example:
prebuilts/clang/host/linux-x86/clang-4691093/bin/clang++ /OpenSource/Build/Android/9.0.0_r30/soong/.intermediates/bionic/libc/crtbegin_so/android_x86_64_core/crtbegin_so.o #/OpenSource/Build/Android/9.0.0_r30/soong/.intermediates/frameworks/base/libs/hwui/libhwui/android_x86_64_core_shared/libhwui.so.rsp ......
But the .rsp files seems to be removed after build.
The question is, how are these file generated and how to get these files? This may require to learn and modify the build scripts which is out of reach for me.
There maybe the answer for you, read the ninja build manual , in that manual .rsp file mentioned.
https://ninja-build.org/manual.html
the following is info that I copy out.
rspfile, rspfile_content
if present (both), Ninja will use a response file for the given command, i.e. write the selected string (rspfile_content) to the given file (rspfile) before calling the command and delete the file after successful execution of the command.
This is particularly useful on Windows OS, where the maximal length of a command line is limited and response files must be used instead.
I have a C project and I would like to run QAC tool v7.0 from command line. I tried the following option,
C:\qac.exe -via <project_name.prj>
However, when I run the above command. I get an error saying the "VersionTag" is not found. The "VersionTag" string is the first line in the .prj file. I am not sure this is the right way to run this tool. Any help appreciated.
The qac -help is not giving valuable information either. The tool version is pretty old and the company 'Programming Research' behind this tool also has been renamed? to Perforce. They do not have any information about command line invocation either from the existing documentation or webpage.
The QAC utility is the "engine" part of the QAC package, corresponding to a compiler.
It won't be happy being run on command line without a number of environment variables:
QACBIN must point to the bin directory of the QAC package installation;
QACHELPFILES must point to the location of message help files;
QACOUTPUT points to the location where output files will be generated (binary .err file for each source file and textual .met file containing semantic and metric information.
The -via parameter to the command line should point at a text file containing other parameters used by the utility.
The .prj file is a package-level file defining the location of C source files being analysed plus their configuration settings files, among other things. It definitely should not be passed directly as a parameter to the QAC utility.
This should get you started, and other questions need to be more specific.
I am running following maven command on jenkins
clean org.jacoco:jacoco-maven-plugin:prepare-agent install
The jacaco exec file created as shown below.
target/coverage-reports/jacoco-int-test.exec
I would like to generate this file under following path, since all other Project use same conventions.
target/jacoco.exec
I could not figureout why it is generated in this way and how to modify it as "target/jacoco.exec"
I will use this report in sonarqube analysis.
I would appriciate your helps, thanks in advance.
As per documentation of prepare-agent - destFile parameter controls location of output file, whose default is ${project.build.directory}/jacoco.exec which is exactly target/jacoco.exe. So check your POMs to find where it is modified to be target/coverage-reports/jacoco-int-test.exec.
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.