Skip to content

Commit 8789b7e

Browse files
committed
[clang][NFC] Update top-level Code Coverage documentation to include MC/DC.
1 parent 95c1039 commit 8789b7e

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

clang/docs/SourceBasedCodeCoverage.rst

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ To compile code with coverage enabled, pass ``-fprofile-instr-generate
6464
Note that linking together code with and without coverage instrumentation is
6565
supported. Uninstrumented code simply won't be accounted for in reports.
6666

67+
To compile code with Modified Condition/Decision Coverage (MC/DC) enabled,
68+
pass ``-fcoverage-mcdc`` in addition to the clang options specified above.
69+
MC/DC is an advanced form of code coverage most applicable in the embedded
70+
space.
71+
6772
Running the instrumented program
6873
================================
6974

@@ -211,6 +216,10 @@ region counts:
211216
| 4| 1|}
212217
------------------
213218
219+
If the application was instrumented for Modified Condition/Decision Coverage
220+
(MC/DC) using the clang option ``-fcoverage-mcdc``, an MC/DC subview can be
221+
enabled using ``--show-mcdc`` that will show detailed MC/DC information for
222+
each complex condition boolean expression containing at most six conditions.
214223

215224
To generate a file-level summary of coverage statistics instead of a
216225
line-oriented report, try:
@@ -259,7 +268,7 @@ the exported data at a high level in the llvm-cov source code.
259268
Interpreting reports
260269
====================
261270

262-
There are five statistics tracked in a coverage summary:
271+
There are six statistics tracked in a coverage summary:
263272

264273
* Function coverage is the percentage of functions which have been executed at
265274
least once. A function is considered to be executed if any of its
@@ -288,10 +297,28 @@ There are five statistics tracked in a coverage summary:
288297
that is comprised of two individual conditions, each of which evaluates to
289298
either true or false, producing four total branch outcomes.
290299

291-
Of these five statistics, function coverage is usually the least granular while
292-
branch coverage is the most granular. 100% branch coverage for a function
293-
implies 100% region coverage for a function. The project-wide totals for each
294-
statistic are listed in the summary.
300+
* Modified Condition/Decision Coverage (MC/DC) is the percentage of individual
301+
branch conditions that have been shown to independently affect the decision
302+
outcome of the boolean expression they comprise. This is accomplished using
303+
the analysis of executed control flow through the expression (i.e. test
304+
vectors) to show that as a condition's outcome is varied between "true" and
305+
false", the decision's outcome also varies between "true" and false", while
306+
the outcome of all other conditions is held fixed (or they are masked out as
307+
unevaluatable, as happens in languages whose logical operators have
308+
short-circuit semantics). MC/DC builds on top of branch coverage and
309+
requires that all code blocks and all execution paths have been tested. This
310+
statistic is hidden by default in reports, but it can be enabled via the
311+
``-show-mcdc-summary`` option as long as code was also compiled using the
312+
clang option ``-fcoverage-mcdc``.
313+
314+
* Boolean expressions that are only comprised of one condition (and therefore
315+
have no logical operators) are not included in MC/DC analysis and are
316+
trivially deducible using branch coverage.
317+
318+
Of these six statistics, function coverage is usually the least granular while
319+
branch coverage (with MC/DC) is the most granular. 100% branch coverage for a
320+
function implies 100% region coverage for a function. The project-wide totals
321+
for each statistic are listed in the summary.
295322

296323
Format compatibility guarantees
297324
===============================
@@ -453,6 +480,21 @@ Branch coverage is tied directly to branch-generating conditions in the source
453480
code. Users should not see hidden branches that aren't actually tied to the
454481
source code.
455482

483+
MC/DC Instrumentation
484+
---------------------
485+
486+
When instrumenting for Modified Condition/Decision Coverage (MC/DC) using the
487+
clang option ``-fcoverage-mcdc``, users are limited to at most **six** leaf-level
488+
conditions in a boolean expression. A warning will be generated for boolean
489+
expressions that contain more than six, and they will not be instrumented for
490+
MC/DC.
491+
492+
Also, if a boolean expression is embedded in the nest of another boolean
493+
expression but separated by a non-logical operator, this is also not supported.
494+
For example, in ``x = (a && b && c && func(d && f))``, the ``d && f`` case
495+
starts a new boolean expression that is separated from the other conditions by
496+
the operator ``func()``. When this is encountered, a warning will be generated
497+
and the boolean expression will not be instrumented.
456498

457499
Switch statements
458500
-----------------

llvm/docs/CoverageMappingFormat.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ There are several kinds of mapping regions:
146146
<span>}</span>
147147
</pre>`
148148

149+
* Decision regions associate multiple branch regions with a boolean
150+
expression in the source code. This information also includes the number of
151+
bitmap bytes needed to represent the expression's executed test vectors as
152+
well as the total number of instrumentable branch conditions that comprise
153+
the expression. Decision regions are used to visualize Modified
154+
Condition/Decision Coverage (MC/DC) in *llvm-cov* for each boolean
155+
expression. When decision regions are used, control flow IDs are assigned to
156+
each associated branch region. One ID represents the current branch
157+
condition, and two additional IDs represent the next branch condition in the
158+
control flow given a true or false evaluation, respectively. This allows
159+
*llvm-cov* to reconstruct the control flow around the conditions in order to
160+
comprehend the full list of potential executable test vectors.
161+
149162
.. _source code range:
150163

151164
Source Range:

0 commit comments

Comments
 (0)