Bitcoin Core has a nice way to gather code coverage data, though it only runs the unit tests and (optionally) the BitcoinJ tests.
With this update, the RPC tests (via qa/pull-tester/rpc-tests.py) are also executed, when gathering code coverage data with make cov.
When cleaning, there were several leftovers, and only the coverage related files in src/ were removed, while the ones in the other dirs remained. The leftovers from tests are now also removed, whereby qa/tmp/ is related to the BitcoinJ tests, and cache/ is related to RPC tests.
Because Python is used to run the RPC tests, it is explicitly checked, whether Python is available.
The configuration option --enable-extended-rpc-tests may be used to enable extended RPC tests, and the configuration option --enable-comparison-tool-reorg-tests may be used to enable extended tests via BitcoinJ. Note that the extended tests can take some time.
How to:
Generating coverage data requires lcov, which may be installed with:
sudo apt-get install lcov
There are a few configuration options, but no further setup is necessary.
To include the BitcoinJ tests, get the test tool:
TOOL_URL=https://github.com/theuni/bitcoind-comparisontool/raw/master/pull-tests-8c6666f.jar
TOOL_HASH=a865332b3827abcde684ab79f5f43c083b0b6a4c97ff5508c79f29fee24f11cd
wget $TOOL_URL -O ./share/BitcoindComparisonTool.jar
echo "$TOOL_HASH ./share/BitcoindComparisonTool.jar" | shasum --algorithm 256 --check
The coverage data can then be gathered with:
./autogen.sh
./configure --enable-lcov --with-comparison-tool=./share/BitcoindComparisonTool.jar
make
make cov
It runs the tests and generates two HTML reports:
test_bitcoin.coverage/index.htmltotal.coverage/index.html
Example report:
(only line and function coverage, no branch coverage, without extended tests)