Open renardbebe opened 3 years ago
You can try running lcov
from within the build directory. However in my experience the reports it generates are poor.
I would also recommend building with the cmake
flag CMAKE_BUILD_TYPE="RelWithDebInfo'.
Code coverage with release modes does not generate good results, and full debug mode tends to cause crashes.
Code coverage is actually a non-trivial problem. The major hurdle being that the tools were designed for in-source tree builds, but cmake
builds outside of the source tree. Also, with C++ you also have the question of how to handle header files, which can be included 100s of times in large projects. When you run gcov
on a given GCDA/GCNO/CPP pair, it will generate a GCOV not just for the source file, but for all headers that source file includes including system libraries. You could just ignore them (and this makes sense for system libraries), but a large portion of EOSIO code is contained in non-system header files. And you have to be careful you don't overwrite existing files which gcov
does by default.
Also to get more extensive coverage you can try running our ctest suites.. I would not recommend running the full suite, but the unlabelled tests will maybe take 15 minutes.
@praphael Thanks for suggestions, but I still can't obtain the coverage information correctly :(
I try to run lcov
within the build directory:
$ lcov --capture --directory . --output-file testHtml.info --test-name testHtml
But got error:
Capturing coverage data from .
Found gcov version: 9.3.0
Using intermediate gcov format
Scanning . for .gcda files ...
Found 67 data files in .
Processing libraries/chain/CMakeFiles/eosio_chain.dir/chain_id_type.cpp.gcda
/root/eos-2.1.0/eos/build/libraries/chain/CMakeFiles/eosio_chain.dir/chain_id_type.cpp.gcno:version '402*', prefer 'A93*'
geninfo: ERROR: GCOV failed for /root/eos-2.1.0/eos/build/libraries/chain/CMakeFiles/eosio_chain.dir/chain_id_type.cpp.gcda!
As far as I know, version '402*', prefer 'A93*'
is a warning and will not abort the process. The error happens in geninfo
has no further information and seems to be related to the version warning in the previous line.
The lcov
version I used is 1.14:
$ ~/eos-2.1.0/eos/build# lcov --version
lcov: LCOV version 1.14
The command to build EOS is:
# build EOSIO
$ export EOSIO_BUILD_LOCATION=$EOSIO_LOCATION/build
cd $EOSIO_BUILD_LOCATION && cmake -DCMAKE_BUILD_TYPE='RelWithDebInfo' -DCMAKE_CXX_COMPILER='clang++-7' -DCMAKE_C_COMPILER='clang-7' -DLLVM_DIR='/usr/lib/llvm-7/lib/cmake/llvm' $EOSIO_LOCATION
$ cd $EOSIO_BUILD_LOCATION && make -j$(nproc)
# install EOSIO
$ cd $EOSIO_BUILD_LOCATION && make install
Have you ever met this kind of error? Or, could you please provide me with the command you used with lcov
?
Thanks a lot!
EOS: 2.1.0 Ubuntu: 20.04 Compiler: llvm-7 clang-7 clang++-7 llvm-cov-7
I have set the
ENABLE_COVERAGE_TESTING=true
while compiling, and have generated a list of.gcno
files.Then I use the following command to start the node:
When I use
Ctrl+C
to stop the node, I found that only few files have generated the corresponding.gcda
files:I found that there is no one-to-one correspondence between
.gcno
file and.gcda
file. For example,./programs/nodeos/CMakeFiles/nodeos.dir/main.cpp.gcno
doesn't generate the corresponding.gcda
file.When I use the command in
tools/llvm-gcov.sh
to run, it will generate some.gcov
files, but the coverage of some executed file is all 0.00% (Also, these files doesn't generate.gcda
file after running). I'm sure the code innodeos/main.cpp
has been executed. Such as:So, is the way I am running is correct (such as the way to stop the node)? What is the sequence of instructions that can generate code coverage correctly?
If anyone can help me, I would be very grateful! Thanks a lot.