From cc71f75c4b87e4d9dcea23e760f137474a50b6ab Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Thu, 11 May 2023 10:04:29 -0500 Subject: [PATCH] doc: add section about Clang code coverage --- doc/HACKING.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/doc/HACKING.md b/doc/HACKING.md index 26130658e..56f889d69 100644 --- a/doc/HACKING.md +++ b/doc/HACKING.md @@ -290,6 +290,35 @@ It can be used to analyze the lightningd source code by running binaries) is stored in .nccout files. You can browse it, for instance, with a command like `nccnav lightningd/lightningd.nccout`. +Code Coverage +------------- +Code coverage can be measured using Clang's source-based instrumentation. + +First, build with the instrumentation enabled: +```shell +make clean +./configure --enable-coverage CC=clang +make -j$(nproc) +``` + +Then run the test for which you want to measure coverage. By default, the raw +coverage profile will be written to `./default.profraw`. You can change the +output file by setting `LLVM_PROFILE_FILE`: +```shell +LLVM_PROFILE_FILE="full_channel.profraw" ./channeld/test/run-full_channel +``` + +Finally, generate an HTML report from the profile. We have a script to make this +easier: +```shell +./contrib/clang-coverage-report.sh channeld/test/run-full_channel \ + full_channel.profraw full_channel.html +firefox full_channel.html +``` + +For more advanced report generation options, see the [Clang coverage +documentation](https://clang.llvm.org/docs/SourceBasedCodeCoverage.html). + Subtleties ----------