Section 18.4.1

Event-to-action coverage matrix

Definition

An event-to-action coverage matrix is a table with one row per kind of event a system can observe and columns that state, for each event, which hook reports it, the possible actions, such as allow, deny or observe only, and what has been shown for it, such as built, tested or enforced. A hook is a place in a program at which the system calls a function supplied from outside, a callback §14.22. Coverage, the fraction of a declared set of cases that tests exercised, is counted over the table’s cells.

Where it fits

Main entry: Coverage metric (§10.18).

The coverage metric entry explains coverage for code: the fraction of statements or branches that tests ran. A matrix has the same structure with cells as the items, and a coverage number means nothing until its universe, the declared set of cells, is named. Candidate universes are the event names alone; each event with each verdict; each event with each hook that can report it; each build configuration; and each reachable state §3.21, a condition the running system can actually be in, in which an event can occur.

In an invented example, a schema, the formal list of event names, declares three events: a pairing request, in which a peer device asks to create shared encryption keys; a change of security level §7.33, the degree of encryption and authentication §1.6 on the link; and a data write. Each can receive one of two verdicts, allow or deny, so the event-verdict universe has 3×2=63 \times 2 = 6 cells. A test campaign that produces one allowed instance of each event fills 3 cells, which is 3/6=50%3 / 6 = 50\%, although every row shows a check mark. Adding deny tests for the pairing request and the data write gives 5/6≈83%5 / 6 \approx 83\%. If the software can be built in two configurations, for example with and without an optional module, the universe has 12 cells, and the same tests run on one build cover 5/12≈42%5 / 12 \approx 42\%.

The interface of each hook fixes which actions its row can claim. In the Bluetooth Low Energy (BLE) §7.1 interface of the Zephyr real-time operating system (RTOS) §6.33, the authentication callback pairing_accept returns a value of the enumerated type enum bt_security_err, a list of named error codes, and any value other than the success code refuses the pairing request before any key is generated. The connection callback security_changed returns void, that is, nothing, and runs only after a security procedure on the connection has finished, so the application can only react afterwards, for example by disconnecting. A deny cell therefore means prevention for the first callback and at most detection followed by a reaction for the second. In the invented example, the cell for denying a change of security level is either excluded from a prevention claim with that reason, which gives 5/5=100%5 / 5 = 100\% of a 5-cell prevention universe, or tested and reported as detection.

Rows, callbacks and logical events are different counts. One callback can report several logical events: security_changed has an error argument, so the same callback reports both a successful change of security level and a failed attempt. One logical event can also reach the application through more than one callback. Neither the number of callbacks nor the number of rows is automatically the denominator of a coverage claim.

Each row has five separate statuses, and each needs its own evidence: declared in the schema; built into the program that was tested; reachable, meaning some input can make the event occur at run time; observed in a test; and enforced, meaning the hook’s verdict changed what happened. The entry on observation versus enforcement §1.20 explains the last distinction.

All data in this entry’s examples are invented.

Limits and common mistakes

Exercising a cell is not checking it. A cell counts as covered only when the observed action was compared with an expected action fixed in advance by a test oracle §10.5, the independent source of the expected result. The entry on coverage versus correctness §10.40 explains why full coverage can coexist with wrong behavior.

A cell stands for a whole class of inputs. Equivalence partitioning §10.32, which divides inputs into classes expected to behave alike, justifies testing one input per class only if every input in the class takes the same path, and a finite table does not list every input in every state.

A verdict recorded after its effect, for example after a packet was transmitted, is detection, not prevention of that transmission. The entry on detection versus prevention §1.21 treats this distinction.

Questions answered

What would complete coverage mean?

Complete coverage would mean that every cell of a declared universe has either been exercised by a test whose result was checked against an expected action, or been excluded with a stated, checkable reason, and that the claim names the universe. Without a named universe the word complete has no meaning, because the same tests can cover all of one universe and half of another. Typical universes are the event names; each event with each verdict; each event with each hook that reports it; each build configuration; and each reachable state.

For example, three events with two verdicts each form 3×2=63 \times 2 = 6 cells, and one allowed instance of each event covers 3/6=50%3 / 6 = 50\% even though every event appears once. Each exclusion needs its own reason: a deny cell for a hook that returns nothing and runs after the event cannot be prevention, so that cell is either excluded from a prevention claim or reported as detection. Because one callback can report several logical events, neither the number of callbacks nor the number of rows is automatically the denominator.

Related entries: Observation versus enforcement (§1.20), Coverage versus correctness (§10.40), Equivalence partitioning (§10.32), Probe and hook (§14.26), Detection versus prevention (§1.21), Test oracle (§10.5).