Guide · Code coverage

MC/DC: showing that every condition matters

MC/DC is the coverage level required for the most critical software. It requires showing that each condition in a decision changes the outcome on its own. Here is its definition, the method for building the tests, its variants, its pitfalls, and what the standards say about it.

Definition

What is MC/DC?

MC/DC stands for Modified Condition/Decision Coverage. The tests must meet four requirements.

  1. Every entry and exit point of the program has been reached.
  2. Every decision has taken all its possible outcomes: true and false.
  3. Every condition in a decision has taken all its possible values.
  4. Every condition has shown its effect: it is varied while the others are held fixed, and the outcome of the decision changes.

The first three requirements make up condition/decision coverage. The fourth makes the difference: a condition that never changes the outcome is either poorly tested or useless. For the vocabulary (decision, condition) and the comparison with the other levels, see coverage levels.

Origin

Where does it come from?

MC/DC was born in aerospace. DO-178B, published in 1992, required it for level A software, whose failure would have catastrophic consequences. DO-178C, which succeeded it in 2011, kept this requirement.

The idea is to come close to the confidence that testing every combination would give, without paying the price: the number of tests grows with the number of conditions, not as a power of two. John Chilenski and Steven Miller published the reference analysis in 1994.

MC/DC has since spread to other sectors: automotive, with ISO 26262, and industry, with IEC 61508.

Method

The method step by step

A train controller applies the brakes when the train is moving and a door is open, or when an emergency stop is requested.

The decision contains three conditions:

  • A: speed > 0;
  • B: door_open;
  • C: emergency.

It reads A && (B || C).

int brake(int speed, int door_open, int emergency)
{
    if (speed > 0 && (door_open || emergency))
        return 1;   /* apply the brakes */
    return 0;
}
  1. Draw up the truth table: three conditions, eight rows.
  2. Find the pairs: for each condition, two rows in which only that condition changes, and the outcome changes too.
  3. Choose the smallest set of rows that contains a pair for every condition.
  4. Write one test per selected row, from the requirements, with the expected result.
RowABCBrakePairs
1FFFno—
2FFTnoA with 6
3FTFnoA with 7
4FTTnoA with 8
5TFFnoB with 7, C with 6
6TFTyesA with 2, C with 5
7TTFyesA with 3, B with 5
8TTTyesA with 4

T: true. F: false. Highlighted: the four selected rows.

The pairs

A has three possible pairs: 2-6, 3-7 or 4-8. B has only one, 5-7, and so has C, 5-6. Rows 5, 6 and 7 are therefore required; adding row 2, or row 3, covers A.

The four tests

brake(0, 0, 1) → 0; brake(50, 0, 0) → 0; brake(50, 0, 1) → 1; brake(50, 1, 0) → 1. That is N + 1 tests for three conditions.

What they detect

If the code forgot the emergency stop (speed > 0 && door_open), the row 6 test would not brake and would fail.

In C, in row 2, B and C are not evaluated: A is false, and so is the decision. The 2-6 pair remains valid, because B and C have the same values in both tests; see short-circuit evaluation in C and C++.

Effort

How many tests?

For a decision with N conditions, MC/DC requires between N + 1 and 2N tests. Multiple condition coverage requires up to 2N.

ConditionsMC/DCMultiple condition
23 to 44
34 to 68
56 to 1032
1011 to 201,024
2021 to 401,048,576

These figures are per decision, for the "unique-cause" variant. The real cost is not the number of tests but their design: each test must come from a requirement, and each missing pair requires understanding why it is missing.

Variants

Three variants

They differ in what the other conditions are allowed to do between the two tests of a pair.

Unique cause

Only the condition under study changes; the others keep their value. This is the original form, and the strictest. It becomes impossible when the same condition appears twice in the decision, like a in (a && b) || (!a && c).

Masking

Other conditions may change, if their change cannot affect the outcome: they are masked. In A && B, when A is false, B does not count. This variant handles repeated conditions; the aerospace certification authorities accept it (CAST-6 paper).

Short-circuit

For languages with short-circuit evaluation, such as C and C++, a condition that is not evaluated is treated as masked. This variant follows the actual execution of the code.

The variants do not always give the same percentage on the same code. Check which one your tool applies, and that it is accepted on your project.

Pitfalls

The pitfalls

Confusing it with multiple condition

MC/DC does not test every combination: it shows the effect of each condition, with far fewer tests.

Writing tests for coverage

In critical software, coverage is measured on requirements-based tests. A missing pair points to an incomplete requirement, a forgotten test or a useless condition: it is not a reason to add a test with no requirement behind it.

Forgetting decisions outside if

For DO-178C, ok = a && b; or return a || b; are decisions too. Not all tools count them.

Overly long decisions

Each added condition requires at least one more test and one more pair. A decision with eight conditions often deserves to be simplified.

Repeated conditions

A variable that appears twice in the same decision makes unique cause impossible: masking is needed, or the decision must be rewritten.

Not checking the results

A pair proves something only if both tests check the expected result. Coverage measures what was executed, not what was checked.

Standards

What the standards say

MC/DC is required for the functions whose failure would be the most serious.

DO-178C

Required for level A software, in addition to decision and statement coverage. The DO-178C page

ISO 26262

Recommended for all ASILs, and highly recommended for ASIL D. The ISO 26262 page

Other standards

IEC 61508 and other functional safety standards list it too. All standards compared

In every case, whatever remains uncovered must be dealt with: by an additional test derived from a requirement, or by a written justification.

Measurement

How a tool measures it

  1. Instrument each decision: at each evaluation, the tool records the combination of values taken by its conditions.
  2. Accumulate the tests: the combinations from all test campaigns add up; a pair can combine two tests from different campaigns.
  3. Look for the pairs: for each condition, the tool looks in the recorded combinations for a pair that shows its effect.
  4. Report: decision by decision, the conditions without a pair, and the combinations that would need to be added.

On an embedded target, this instrumentation uses more memory than statement instrumentation: it is one of the criteria for choosing a tool. The GCC compiler also measures MC/DC since version 14, with gcov; see Testwell CTC++ or gcov?

Testwell CTC++

MC/DC with Testwell CTC++

Testwell CTC++ measures MC/DC and multiple condition coverage of C and C++ code (Java as an option):

  • the report shows, decision by decision, the missing conditions and combinations;
  • on the host as well as on the embedded target, whatever the compiler;
  • uncovered parts are justified in the code, and the justifications appear in the reports;
  • the tool is certified by TÜV SÜD for IEC 61508, ISO 26262, EN 50716, ISO 25119 and IEC 62304.

On video, by Verifysoft Technology GmbH: MC/DC and multicondition coverage ↗ (8 min).

Testwell CTC++ →
Certification →

Clear, actionable reports1 min 20 s · silent animation
TiCS

Tracking coverage with TiCS

TiCS takes in the coverage measured by Testwell CTC++ or by another coverage tool:

  • coverage is shown per test level, and in total;
  • it feeds into the TQI, alongside the other code quality indicators;
  • its evolution can be followed from one version to the next.

TiCS →
Guide: code coverage →

Coverage, level by level1 min 36 s · silent animation

Key points

  • MC/DC requires showing that each condition changes the outcome of its decision on its own.
  • The method: truth table, independence pairs, smallest set of rows, one requirements-based test per row.
  • For N conditions, between N + 1 and 2N tests, instead of 2N for every combination.
  • Three variants, unique cause, masking and short-circuit, which do not always count the same way.
  • Required by DO-178C at level A, recommended by ISO 26262, highly for ASIL D.
FAQ

Frequently asked questions

Why "modified"?

Because MC/DC starts from condition/decision coverage and modifies it: it adds the requirement that each condition show its effect on the outcome.

Does 100% MC/DC guarantee there are no defects?

No. It guarantees that each condition has been tested in a situation where it decides the outcome. A wrong requirement, a faulty calculation or a test that checks nothing still get through.

MC/DC or multiple condition?

The standard sets the level. Multiple condition coverage tests every combination and quickly becomes unrealistic beyond four or five conditions; MC/DC delivers most of its value for a number of tests that stays reasonable.

And a decision with a single condition?

MC/DC then amounts to decision coverage: two tests, one where it is true, the other where it is false.

Can MC/DC be measured with gcov?

Yes, since GCC 14: the code is compiled with the -fcondition-coverage option, and gcov produces the report. For a comparison with a dedicated tool, especially on an embedded target, see Testwell CTC++ or gcov?

Should you aim for 100% MC/DC?

Where the standard requires it, everything that is not covered must be dealt with, by a test or by a justification. Elsewhere, MC/DC is kept for the code whose failure would have the most serious consequences.

Measure the MC/DC of your code

A free trial of Testwell CTC++ on your own C or C++ code, on the host or on the embedded target.

Free trial →

Code coverage  ·  Coverage levels  ·  Testwell CTC++  ·  DO-178C  ·  Standards  ·  Learn

Sources: Kelly J. Hayhurst, Dan S. Veerhusen, John J. Chilenski and Leanna K. Rierson, A Practical Tutorial on Modified Condition/Decision Coverage (NASA/TM-2001-210876, 2001) ↗; John J. Chilenski and Steven P. Miller, Applicability of Modified Condition/Decision Coverage to Software Testing (Software Engineering Journal, 1994); Certification Authorities Software Team, CAST-6, Rationale for Accepting Masking MC/DC in Certification Projects; GCC, Invoking gcov ↗.