Principle:ClickHouse ClickHouse Code Coverage Collection
| Knowledge Sources | |
|---|---|
| Domains | Testing, Instrumentation |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
A technique for measuring which parts of code are executed during testing to assess test completeness.
Description
Code coverage collection instruments programs to record which code paths are executed. Coverage data helps identify untested code, guide test development, and measure test quality. Modern coverage tools use compiler instrumentation (LLVM's SanitizerCoverage) that inserts callbacks at basic blocks, edges, or comparison points. ClickHouse uses custom coverage collection that stores executed addresses in arrays for per-test analysis.
Usage
Use for measuring test coverage, implementing coverage-guided fuzzing, identifying dead code, or analyzing execution patterns.
Theoretical Basis
Instrumentation Levels: Basic block (every block), edge (control flow transitions), path (full execution paths).
Compiler Integration: LLVM's `-fsanitize=coverage` instruments code with callbacks to user-defined functions.
Coverage Metrics: Line coverage, branch coverage, path coverage (increasingly expensive).
Fuzzing: Coverage-guided fuzzing (libFuzzer, AFL) uses coverage to guide input generation toward unexplored code.