Prime Path Coverage in the GNU Compiler Collection
Jørgen Kvalsvik
TL;DR
The paper presents a GCC v15 implementation of prime path coverage, a structural path-coverage criterion that subsumes MC/DC and offers a practical balance between test count and defect detection. It introduces a suffix-tree-based enumeration method that reduces path-pruning complexity to $O(n^2 m)$ from $O(n^2 m^2)$ and employs bitset-based instrumentation to track prime-path execution with minimal overhead. Prime paths are represented and reported via gcov, enabling precise guidance on code to exercise for coverage while recomputing paths from the CFG as needed. The work also discusses thresholds to control path explosion and identifies bottlenecks in large SCCs and instrumentation passes, outlining future directions for heuristics and potential extensions to path frequencies and industry uptake.
Abstract
We describe the implementation of the prime path coverage support introduced the GNU Compiler Collection 15, a structural coverage metric that focuses on paths of execution through the program. Prime path coverage strikes a good balance between the number of tests and coverage, and requires that loops are taken, taken more than once, and skipped. We show that prime path coverage subsumes modified condition/decision coverage (MC/DC). We improve on the current state-of-the-art algorithms for enumerating prime paths by using a suffix tree for efficient pruning of duplicated and redundant subpaths, reducing it to $O(n^2m)$ from $O(n^2m^2)$, where $n$ is the length of the longest path and $m$ is the number of candidate paths. We can efficiently track candidate paths using a few bitwise operations based on a compact representation of the indices of the ordered prime paths. By analyzing the control flow graph, GCC can observe and instrument paths in a language-agnostic manner, and accurately report what code must be run in what order to achieve coverage.
