Information
We are currently investigating an issue with the editor of some pages. Please save your work and avoid to create new pages until this banner is gone.
GCOV is a tool you can use in conjunction with GCC to test code coverage in your programs.
For building with coverage support you need to add some flags to gcc/g++ compiler and linker:
Code Block | ||
---|---|---|
| ||
g++ -fprofile-arcs -ftest-coverage
#Or simply, which includes the previous flags
g++ --coverage |
Using the ACS Makefile, you can take advantage of MAKE_GCOV environment variable:
Code Block |
---|
#Build ACS
cd ACS
MAKE_GCOV=1 make build
$Build a single module
cd <some_module>/src
MAKE_GCOV=1 make clean all install |
As a result, you will have a .gcno file for each compiled .o file in your object directory.
The execution is the same as always, you don't need to use a wrapper application or pass any special flag or environment variable. As a result you will get a .gcda file for each translation unit that was initialized during the execution of your executable(s). The file will be placed by default in the same directory where the corresponding .gcno and .o are. For some scenarios, you may need this to be placed in a different directory, and for this you have the GCOV_PREFIX and GCOV_PREFIX_STRIP environment variables.
These variables need to be set before running any executable, so the .gcda files are created according to them.
As an example we have built code from modules /home/almamgr/Repos/repo/mod1 and /home/almamgr/Repos/repo/mod2, and we want to analyze the .gcda data in /home/almamgr/gcov/data:
Code Block |
---|
export GCOV_PREFIX_STRIP=3
export GCOV_PREFIX=/home/almamgr/gcov/data
#To automate the value for GCOV_PREFIX_STRIP, you could do something like this:
export GCOV_PREFIX_STRIP=$(echo /home/almamgr/Repos/repo |grep -o / |wc -l) |
In this case, the .gcda files will be found in /home/almamgr/Repos/repo/mod1/object and /home/almamgr/Repos/repo/mod2/object directories.