docs/notes/coverage.html
Code coverage analysis helps visualize which parts of the backend are exercised by backend tests. This guide outlines the process for generating an HTML coverage report for Filament's backend on macOS.
You'll need a recent version of Clang and its corresponding LLVM tools for code coverage. You can install these using Homebrew or MacPorts.
Install the llvm package:
brew install llvm
This typically installs the tools in a location like /usr/local/opt/llvm/bin. You may need to add this to your PATH environment variable.
Install a specific version of Clang (e.g., version 18):
sudo port install clang-18
MacPorts often adds version suffixes to the tool names (e.g., llvm-cov-mp-18).
Ensure you can locate the following tools from your installation:
clang and clang++ (The C/C++ compilers)llvm-profdata (For merging coverage data)llvm-cov (For generating reports)The rest of this guide assumes your tools are in your PATH. If not, you'll need to use the full path to each executable.
Compile the backend_test_mac target with coverage instrumentation. This is done by setting the CC and CXX environment variables to point to your Clang compiler and using the -V flag in the build script.
CC=clang CXX=clang++ ./build.sh -V -p desktop debug backend_test_mac
If your Clang executables aren't in your PATH or have version suffixes, provide the full name or path (e.g., CC=/opt/local/bin/clang CXX=/opt/local/bin/clang++).
Running the test suite will generate the raw coverage data needed for the report.
Navigate to the build output directory:
Run the tests for a specific backend (e.g., Metal):
This command creates a default.profraw file in the current directory, which contains the raw execution profile data.
Finally, process the raw data and generate an HTML report.
Merge the raw profile data into a single file using llvm-profdata.
Generate the HTML report using llvm-cov. This command creates a report for the entire backend_test_mac executable.
Open the report in your browser:
In the report, code paths that were not executed during the test run will be highlighted in red.