Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 36 ยท Testing and Verification

Simulink Coverage: Decision, Condition, MC/DC and Reports

Measure how thoroughly tests exercise a Simulink model with Simulink Coverage: decision, condition, MC/DC, lookup table and signal range metrics, reports and closing coverage gaps.

Passing tests say that the cases you wrote work. They do not say how much of the design you exercised. Model coverage measures which parts of the model (switch branches, Stateflow transitions, logic conditions) your tests actually executed. Untested parts are either missing tests, dead logic or a design error, so coverage is a standard requirement in safety standards such as ISO 26262 and DO-178C. Simulink Coverage is a commercial product and cannot run here; the stand-ins below compute the same metrics for small logic examples.

What coverage tells you (and what it does not)

  • 100 percent coverage means every element was executed at least once, not that the outputs were correct. Coverage tells you where the tests are thin; the assessments and baselines decide pass or fail.
  • Low coverage points to: missing tests, requirements that were not tested, unreachable ("dead") logic, or a model that is more complex than necessary.
  • Aim for the level your standard or team demands, and justify gaps in writing.

Coverage metrics

Metric Question it answers
Cyclomatic complexity How many independent paths exist (a complexity number, not a coverage percent)
Decision coverage (DC) Did every decision (Switch, If, Saturation, Stateflow transition/state) take each outcome (true and false) at least once?
Condition coverage (CC) Did each condition inside a logical expression take both true and false?
Modified Condition/Decision Coverage (MC/DC) Did each condition independently change the outcome of the decision?
Execution coverage Was each block, state or function executed?
Lookup table coverage Was each interval (breakpoint cell) of a lookup table used?
Signal range coverage The minimum and maximum of selected signals (for review, not a percentage)
Signal size coverage The sizes of variable-size signals
Relational boundary Were relational operators tested near their boundaries (a >= b near equality)?
Saturate on integer overflow Did a block saturate?

Decision and condition are the basis. MC/DC is the strongest of the three and is required for the most critical avionics software (DO-178C level A).

Enabling and running coverage

  1. In Model Settings > Coverage (older releases: Analysis > Coverage > Settings), tick Enable coverage analysis, pick the metrics (Decision, Condition, MCDC...) and choose which model parts to cover (Cover referenced models, Include subsystems, Exclude blocks).
  2. Run a simulation. When it ends, an HTML coverage report opens: a summary table, a per-block table and the model with colored highlighting (green = full, red = missing).
  3. From the Test Manager, tick Coverage > Record coverage for system under test to collect coverage during test runs and merge results from many tests into one cumulative report.
  4. Command line:
MATLAB
testObj = cvtest('controller');
testObj.settings.decision = 1; testObj.settings.mcdc = 1;
data = cvsim(testObj);
cvhtml('coverage_report', data);

In the model, Analysis > Coverage > Highlight Model with Coverage Results colors blocks directly on the diagram.

flowchart LR
    T["Test cases"] --> R["Run with coverage"]
    R --> C["Coverage report"]
    C --> G["Gaps?"]
    G -->|"yes"| N["Add tests, remove dead logic, justify"]
    N --> T
    G -->|"no"| D["Done"]

Coverage is a loop: run, find gaps, close them, repeat.

Understanding MC/DC

For a decision made of conditions, for example (A and B) or C, MC/DC requires a set of tests in which each condition is shown to affect the outcome on its own: there exists a pair of tests that differ only in that condition and give different outcomes. For n conditions you typically need about n + 1 test vectors, not 2^n.

The Python stand-in below computes MC/DC independence pairs for a decision by exhaustive search and tells you which condition is covered by a test set. It is our own checker.

Python Stand-in: which conditions does a test set cover under MC/DC?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Four tests are enough for three conditions, while two tests that merely give both outcomes (decision coverage) leave every condition without an independence pair. That is why MC/DC finds weak tests that decision coverage passes.

Decision and condition coverage of a Switch

A Switch block with the criterion u2 >= threshold has one decision with two outcomes: pass u1 or pass u3. Decision coverage is 100 percent when your tests make the criterion both true and false. A Logical Operator block with several inputs adds conditions. A Stateflow chart adds decisions at each transition and state, and execution metrics for each state and function.

The next stand-in counts decision outcomes from a log of a controller with a saturation and a mode switch, to show how gaps appear.

Python Stand-in: decision coverage from a simulation log

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The report shows which outcomes are missing (the saturation is never active and the ramp never ends in a hold), and the fix is to add tests with a command above 100 and with a command close to the current state.

Closing coverage gaps

  1. Read the report: find red blocks and the missing outcome.
  2. Is it reachable? Use the Simulink Design Verifier (see formal verification) to generate a test case for the missing objective, or to prove that it is unreachable.
  3. Add tests if it is a real behavior that was not tested; in the Test Manager add a case or an iteration.
  4. Fix the design if the logic is dead (remove it) or redundant.
  5. Justify and exclude: for defensive code that cannot be reached in the model (for example a Stateflow default branch), mark it as justified (filter or Coverage Filter with a rationale) so the reports stay clean and auditable.

In Simulink Coverage Filter: Analysis > Coverage > Create Filter, which stores filter rules in a .cvf file with a rationale for each exclusion, applied at report time.

Common mistakes

  • Treating coverage as correctness: it says nothing about expected results.
  • Chasing 100 percent by writing tests with no assessments.
  • Covering only the plant model: coverage should be measured on the controller under test (the harness), not on the simulation plant.
  • Forgetting referenced models and library blocks, which are excluded by default unless you enable them.
  • Not merging results, so each test looks incomplete on its own.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does decision coverage require?

    Decision coverage looks at the outcomes of decisions such as switch criteria and transition conditions.
  2. 2. Which metric is the strongest of decision, condition and MC/DC?

    MC/DC shows that each condition independently influences the decision, which is stricter than decision or condition coverage.
  3. 3. How many test vectors does MC/DC typically need for n conditions?

    Independence pairs can share vectors, so roughly n + 1 tests are enough.
  4. 4. A report shows a never-executed Stateflow transition. What should you do first?

    The gap is a missing test, dead logic, or defensive code that needs a documented justification.

Summary

  • Coverage measures which parts of the model your tests executed; it does not judge correctness.
  • Decision, condition and MC/DC metrics (plus execution, lookup table and signal range) are collected via Model Settings > Coverage, the Test Manager or cvsim.
  • MC/DC needs each condition to independently change the outcome; about n + 1 tests suffice.
  • Close gaps by adding tests, removing dead logic, generating tests with Design Verifier or justifying exclusions with a coverage filter.

Next: Model Advisor and modeling standards