Code Coverage#
Code coverage is a software testing metric that measures the proportion of source code executed while running an automated test suite. It provides insight into test thoroughness by identifying untested functions, dead code paths, and unexercised conditional branches across library entrypoints and internal utilities.
LLVM-libc supports Modified Condition / Decision Coverage (MC/DC). MC/DC
evaluates compound boolean decisions composed of multiple sub-conditions (such
as if (A && (B || C))). Under MC/DC criteria, each individual boolean
condition must:
Evaluate to both true and false across the test suite.
Demonstrate that it can independently affect the outcome of the overall decision while other conditions remain fixed.
This provides rigorous structural verification for safety-critical algorithms without requiring exhaustive testing of all 2n condition permutations.
Continuous Profiling Architecture#
LLVM-libc uses Clang’s continuous profiling mode
(-fprofile-continuous) to record execution metrics directly into
memory-mapped profile files during test execution.
Compiler Counter Relocation#
When compiled with -fprofile-continuous, Clang configures the LLVM code
generator (-mllvm -runtime-counter-relocation=true) so that execution counter
increments reference a dynamic base pointer (*(bias + &counter) += 1). Each
branch and basic block counter dynamically resolves to an address within a
dedicated profile buffer mapped at program startup.
Runtime Memory Mapping#
During binary initialization, the profiling runtime (libclang_rt.profile)
resolves the target .profraw file and maps the execution counter section into
process memory using mmap with MAP_SHARED. The runtime sets the global bias
pointer to this mapped region, routing live counter increments directly into the
file-backed buffer.
Kernel Page-Cache Synchronization#
Execution counts are written directly to shared memory-mapped pages and
synchronized by the operating system kernel’s page cache. Subprocesses created
via fork() share the same underlying memory mapping, committing statements
executed across parent and child processes directly to the profile file.
Build System Integration#
Setting