Problem:
I'm using the following flags to generate the code coverage of my Qt application (.pro file):
QMAKE_CXXFLAGS += --coverage
QMAKE_LFLAGS += --coverage
The code coverage is correctly generated, the problem is that if I want to run only one test function/class (and the GCDA files were already created) I get the following error message:
profiling: /Users/user/.../build-myapp/myclass.gcda: cannot merge previous GCDA file: corrupt arc tag (0x00000000)
Note that the error message is shown for each GCDA file. Also, note that it doesn't seem to affect the test cases.
Workaround:
As explained here, it "is a result of the build tools failing to merge current results into the existing .gcda coverage files". As answered in the question, an option is to delete the GCDA files before running the tests. For example, by adding the following command in the build phase:
find . -name "*.gcda" -print0 | xargs -0 rm
Question:
My problem is that I don't want to delete the old GCDA files every time I run the test cases. As I'm running only one test function/class, I want to keep the old GCDA files as they are, and only merge the GCDA file related to the current class. As I manually checked, it is already being done because only the coverage of my current class is updated, and the old coverages remain the same.
So, is there a command to just ignore (don't show) the error messages related to the GCDA merging problems? Or even better, a command to only update the GCDA files related to the current test class?
Note: I'm using Qt 5.3.2 on macOS Sierra with Clang.
Related questions:
Code coverage warnings spam output
How to merge multiple versions of gcda files?
.gcda files don't merge on multiple runs
When you compile with profiling, the results of each run are stored in a file that ends with .gcda.
The error appears when your existing .gcda file is in a different format than the current program that just finished running.
This happened to me when I had run a Linux version of my executable, then recompiled for MacOS and ran it. The MacOS program saw the existing .gcda file and generated pages of errors.
Eliminate the errors by removing the existing .gcda file.
I came across the same problem. My solution is:
There is a general Test.pro project which uses SUBDIRS to include every test project as subproject.
In each test subproject I have the following line
QMAKE_POST_LINK = rm -f "*.gcda"
This deletes the *.gcda files only for the subproject which was just relinked. Unmodified projects keep their *.gcda files.
Related
I'm looking to determine coverage of some unit tests. The project requires a second directory (basically from a GitHub repository) and when running everything, I usually add the 2nd lib directory with
use lib "/path/to/second/dir/lib";
and currently I have this in the Build.PL file (I'm using Module::Build). Running ./Build test gives a nice summary of all of the test (about 10 files-worth), however, running cover -test gives me errors, specifically, a
Can't use an undefined value as a symbol reference at XXX
which is a file in that second directory.
Is this because it appears that the Module::Build tends to copy files to the blib directory? If so, does it use the files there? What are the other differences between running cover -test and ./Build test?
I'm in the process of generating coverage information of a c++ application and using gtest for the same, and the C++ application is part of the buildroot build. Got correct coverage information for almost files except header files. So I googled the same and found this link as useful, having said that I didn't get the correct answer.
gcov is not generating coverage information for header files
From the link, I understood that to obtain "mymoneyaccount.cpp.gcov",execute "gcov mymoneyaccount.cpp", but to obtain "mymoneyaccount.h.gcov", we need to execute "gcov mymoneyaccounttest.cpp". My first doubt is Anyone have an idea why we need to execute the test app to generate the .gcov of header file? Both files include "mymoneyaccount.h"."
My exact scenario is I'm trying to get the code coverage of source files which is located in "Source" folder and the test application is located in the "Test" folder.
Please find the folder structure.
Source
1.1 a
1.1.1 logic.cpp
1.1.2 logic.h
Test
2.1 a
2.1.1 logictest.cpp
Both Source and Test are art of Buildroot build system, cross compiled it and run the test in the Raspberry Pi-3. As part of Compilation process, logic.cpp.gcno & logictest.cpp.gcno files were generated in the build PC and as part of execution process in the Raspberry Pi-3, corresponding .gcda files were generated. Copied the .gcda files from the RPi to the corresponding locations in Build PC. Executed the gcov on the .gcno files and get the coverage details. Coverage of logic.cpp.gcov is valid and the .h.gcov in the Test directory is satisfying, were .h.gcov in the Source directory is not. Opened the .h.gcov in the Source dir, it shows line counts with the exact source code(not valid coverage data), but the .h.gcov in the Test dir, shows the line counts with code as /EOF/(hope it shows the valid coverage data). Hope it is clear now. Is any solution to view the content of the .h.gcov in the Test directory as the exact code?. Then only we can ensure that we got a valid coverage data and we can implement more test cases with the remaining code. Thank you.
I want to generate a coverage report for my github repo, it's a big C++ project built with CMake.
I add --coverage(equals to -fprofile-arcs -ftest-coverage) option to g++ build and link arguments in my CMakeLists.txt, and I use gcov to generate code coverage data and upload the data to codecov.io.
These automated builds and tests are done in my Jenkins CI. The related code of Jenkins's execute shell is here:
cmake -DCODE_COVERAGE=ON -Dasan=OFF -DNEBULA_ASAN_PRELOAD= ..
make -j8
ctest -j8
#generate code coverage report and upload it to codecov.io
TEST_FILES=$(find . -name '*.cpp.o')
#gcov -abcr $TEST_FILES
for test_file in $TEST_FILES; do gcov -abcr $test_file; done
curl -s https://codecov.io/bash | bash -s - -t c85ebdca-ec7c-4301-a6ed-7967cf175db5
When Jenkins excutes make -j8 and ctest -j8, and gcov -abcr $test_file I do get the related .gcno files, .gcda files, and gcov files. But when Jenkins excutes curl -s https://codecov.io/bash | bash -s - -t c85ebdca-ec7c-4301-a6ed-7967cf175db5 to upload the data files to codecov, the output seems strange. I see a lot of similar errors like:
ExecutionPlan.gcno:'_ZNK6nebula4cpp29ValueType8get_typeEv' has arcs to entry block
ExecutionPlan.gcno:'_ZNK6nebula4cpp29ValueType8get_typeEv' has arcs from exit block
And the -r option of gcov seems doesn't work because I also get a lot of coverage report of system header files.
And at the last the Jenkins tells me the build fails, so I can't see the coverage report in codecov.
Ps:
The source cpp files is not in the same directory with the .cpp.o(CMake's default C++ object type is .cpp.o not .o) files. And I do the above excute shell's code in the build directory, the .gcno, .gcda, and .gcov files are generated in the same directory.
Bucause the CMake's default object type is .cpp.o, the gcno and gcda files type generated is .cpp.gcno and .cpp.gcdas. So I use gcov filename.cpp.o insead of gcov filename.cpp which will tell me couldn't open filename.gcno errors.
I do some experiments to find the reason of errors. I find when I give gcov one input file like gcov 1.cpp.o, I will get no has arcs from exit block errors, but when I give gcov more than one input files like gcov 1.cpp.o 2.cpp.o , I get the errors of has arcs from exit block. I think a probably reason is about combing multiple gcov files.
I would like to edit an existing software to add a new source file (Source.cpp).
But, I can't manage the compilation process (it seems to be automake and it looks very complicated).
The software (iperf 2: https://sourceforge.net/projects/iperf2/files/?source=navbar) is compiled using a classical ./configure make then make install.
If I just add the file to the corresponding source and include directory, I got this error message:
Settings.cpp:(.text+0x969) : undefined reference to ...
It looks like the makefile isn't able to produce the output file associated with my new source file (Source.cpp). So, I probably need to indicate it manually somewhere.
I searched a bit in the project files and it seemed that the file to edit was: "Makefile.am".
I added my source to the variable iperf_SOURCES in that file but it didn't workded.
Could you help me to find the file where I need to indicate my new source file (it seems a pretty standard compilation scheme but I never used automake softwares and this one seems very complicated).
Thank you in advance
This project is built with the autotools, as you already figured out.
The makefiles are built by automake. It takes its input in files that usually have a am file name extension.
The iperf program is built by the makefile generated from src/Makefile.am. This is indicated by:
bin_PROGRAMS = iperf
All (actually this is a simplification, but which holds in this case) source files of a to be built binary are in the corresponding name_SOURCES variable, thus in this case iperf_SOURCES. Just add your source file to the end of that list, like so (keeping their formatting):
iperf_SOURCES = \
Client.cpp \
# lines omitted
tcp_window_size.c \
my_new_file.c
Now, to reflect this change in any future generated src/Makefile you need to run automake. This will modify src/Makefile.in, which is a template that is used by config.sub at the end of configure to generate the actual makefile.
Running automake can happen in various ways:
If you already have makefiles that were generated after an configure these should take care of rebuilding themselves. This seems to fail sometimes though!
You could run automake (in the top level directory) by hand. I've never done this, as there is the better solution to...
Run autoreconf --install (possibly add --force to the arguments) in the top level directory. This will regenerate the entire build system, calling all needed programs such as autoheader, autoconf and of course automake. This is my favorite solution.
The later two options require calling configure again, IMO ideally doing an out of source built:
# in top level dir
mkdir build
cd build
../configure # arguments
make # should now also compile and link your new source file
I am using gcov as my code coverage tool for my c++ project with gcc (currently 4.6.3 but soon to be 4.8) on Ubuntu 12.04 and am getting the error cannot open graph file. What does this error mean? And how do I get rid of it so that I can see my code coverage?
I've seen other solutions to this problem the most popular being to use clang (gcov: cannot open graph file) instead of gcc but I can't switch compilers, I have to use gcc so that is not a workable solution for me. Plus, the documentation on gcov says that it should work with gcc.
Another solution was to fix a configuration file (http://ubuntuforums.org/showthread.php?t=1547252) but I'm not sure what configuration file this user is speaking of so if that is my problem as well I don't know how to fix it
my .gcda and .gcno files are correctly being generated in my obj directory
beyond going into my top directory where I compile my code and doing gcov *.c I'v also tried
gcov -o directory/to/obj *.c
and
gcov -o directory/to/obj *.gcda
and
gcov -o directory/to/obj *.gcno
but none of these solutions work; i still get the cannot open graph file error.
Any help or advice would be appreciated!
The above problem is due to absence of .gcda and .gcno file in the directory where your source code present .
So my suggestion is 1st copy one .gcda and .gcno file of particular .c file in your source code where your .c resides then execute gcov filename.c.
If you get coverage ,then try to soft link all your .gcda and .gcno to source code if dont want to copy from obj directory then as u stated problem ll be solved
Let me clarify few of the things that you were doing wrong.
First: you always tried to specify *.gcda, *.gcno, *.c etc after obj directory path, which is totally wrong.
What you need to do is to specify it as "-o path/to/obj/ " (path to directory)
You can even specify path to gcda file of that particular c/c++ source file and specify path to obj directory in "-o" flag to get the report for that file.
And if you use gcovr instead of gcov for your reports then you can get all the kind of reports by specifying only the root directory (directory above src & obj) with "-r -root=ROOT" flag.
Refer to this user guide for details on gcovr.