Section 8.37

Reset injection

Definition

Reset injection is a form of fault injection §10.28 that deliberately resets a device while it is working, for example while it writes an update to storage, and then checks that the device restarts into a valid state. A reset restarts the processor and abandons whatever the program held in RAM, while persistent storage, such as flash memory §6.6, keeps whatever had been written by then. The test chooses where the resets fall: at chosen points in the code, at chosen times, or after a chosen number of storage operations.

The idea

An update procedure writes a new image, the complete program or data to be installed, then a commit record §8.21 that makes the new image current, then erases the old image. A loss of power, or a watchdog timer §6.16, a hardware timer that resets a device that has stopped responding, can stop the procedure at any moment. The recovery code that runs after such a reset is rarely exercised in normal use, so its bugs survive until a device in the field fails. Reset injection exercises it on purpose.

The key observation is that stored state changes only during writes to persistent storage, where an erase counts as a write. Call the start and the end of each such write its durable-write boundaries. A reset anywhere between the end of one write and the start of the next leaves the same stored state and starts the same recovery. A reset between the start and the end of one write leaves that write torn, meaning partly done. What a campaign covers is therefore measured by which of these intervals its resets fell into, not by how many resets it performed: a thousand resets in the same gap test one case a thousand times.

Testing a ladder is a fair picture: what matters is which rungs have carried weight, not how many times someone stood on the first rung. The picture stops at one point. Some cases lie inside a rung: a reset in the middle of a write leaves a torn write §8.19, and some kinds of reset cannot produce that case at all.

How it works

  1. Model the durable operations. List in order every write, erase and selector change that the procedure makes to persistent storage, including those made by the storage library, such as garbage collection §8.16, which copies live records and erases old areas to reclaim space, and those made by the recovery code.

  2. Know the reset kind. A software reset requested by the program, a watchdog reset, a reset from a debug probe (the adapter used to program and debug the chip) and a reset through the reset pin all restart the processor, but they can differ in what they leave behind: whether RAM keeps its content, whether peripherals restart, and whether a flash write or erase already in progress completes. Find out from the device documentation, or by measurement, what each kind leaves. A real loss of power differs again; the power-loss injection §8.38 entry treats it.

  3. Choose a trigger. A hook compiled into a test build can reset immediately before or after operation kk: exact, but the code under test is changed. A timer can reset a chosen time after the procedure starts: the code is unchanged, but where the reset lands is uncertain. A counter in the storage driver can reset at the kk-th write: exact for boundaries between operations.

  4. Record where each reset actually landed. The target, not the test host, is the authority. Firmware can set a GPIO §6.22 (general-purpose input/output) pin at the start of each durable operation and clear it at the end, and a logic analyzer, an instrument that records digital signals against one clock, captures those pins and the reset line together. A host that sends “reset now” at a known time does not know when the reset took effect.

  5. Check recovery against invariants. After each reset, let the device recover, then check the conditions every valid state must meet: exactly one current image, the old one or the new one and never a mixture; version numbers that never go backward; storage structures that are consistent.

  6. Reset the recovery too. Recovery also writes to storage, and a second reset can fall inside it. Inject resets during recovery, and during recovery from that.

  7. Keep a coverage map, with one row per class of stored state: what the class is, whether it was reached, the evidence for where the reset landed with its uncertainty, and the recovery outcome. A class that the chosen reset kind cannot reach is reported as a gap, not filled in from neighboring rows.

Worked example

A procedure makes three durable operations: W1W_1 writes the new image, W2W_2 writes the commit record and W3W_3 erases the old image. Resets that fall only between complete operations leave one of 3+1=43 + 1 = 4 stored states: before W1W_1, after W1W_1, after W2W_2 and after W3W_3. A reset can also tear each of the three operations, which adds 3 more classes, each with many possible partial contents, for 4+3=74 + 3 = 7 classes in all. A reset after W2W_2 is not a test of a torn W2W_2.

Labels taken from the host can be wrong. The host sends “reset” 10 ms after the procedure starts, and the target’s markers show W2W_2 running from 11 ms to 12 ms. The reset line shows that the reset took effect at 15 ms, 15−10=515 - 10 = 5 ms after the command. The host’s log says “reset during W2W_2”; the measured trace says “after W2W_2”. Only the measured label belongs in the coverage map.

Random timing covers short windows poorly. Suppose the procedure lasts 100 ms, W2W_2 lasts 0.1 ms, and each reset falls at a uniformly random time within the procedure, every moment being equally likely, using a reset kind that can tear a write. One reset lands inside W2W_2 with probability 0.1/100=0.0010.1 / 100 = 0.001. Over 500 resets the expected number of hits is 500×0.001=0.5500 \times 0.001 = 0.5, and the probability of no hit at all is (1−0.001)500≈0.61(1 - 0.001)^{500} \approx 0.61. A campaign of 500 random resets more likely than not never tears the commit record.

Stated precisely

For nn durable operations performed one after another, resets between complete operations leave n+1n + 1 stored states, one for each number of completed operations from 0 to nn. If each operation can also be torn, there are at least 2n+12n + 1 classes: n+1n + 1 clean ones and nn torn ones, and each torn class can contain many partial contents. For n=3n = 3 there are 3+1=43 + 1 = 4 clean classes and 2×3+1=72 \times 3 + 1 = 7 classes in all. Writes made by recovery add classes of their own for each nested reset.

A campaign establishes this statement: for each class it lists, at least one reset with a measured landing point in that class was followed by a recovery that met the stated invariants. Extending the statement to a reset at any moment needs three assumptions.

  1. The model lists every durable operation, including those of the storage library and of recovery.

  2. The state after a reset depends only on which operations completed and how a torn one was left, not on anything else that survives the reset, such as RAM contents or a write still running inside an external memory chip.

  3. Each class was reached with a reset kind that leaves the same state as the real failure being guarded against.

A finite campaign is evidence for the classes it reached. A proof over all states needs a model of all of them and a justified match between the model and the hardware.

Limits and common mistakes

On many microcontrollers §6.1 the processor stalls when it fetches instructions from flash memory while that flash is being written, so a program running from flash cannot request a reset in the middle of its own write. A software reset then lands only between operations and cannot produce a torn write. Torn-write classes need power-loss injection, or a storage simulator that models partial writes.

A reset may leave RAM contents in place. Recovery code that reads leftover RAM can pass every reset test and still fail after a real loss of power, which does not preserve RAM reliably.

An external memory chip may continue its own write after the processor resets, because the processor’s reset does not reach it.

Instrumentation §14.24 changes timing. Hooks and marker pins add instructions, which can move a race or hide one.

A count of resets, or of successful boots, is not coverage.

Passing every injected reset is evidence for the classes reached with the reset kinds used. It is not a proof that every stop at every moment is safe.

Questions answered

Does the injection coverage include every relevant durable-write boundary?

That can be established only by a coverage map, never by a count of resets or of successful boots. Build the map in three steps. First, list in order every durable operation of the procedure: writes, erases and selector changes, including those made by the storage library, for example during garbage collection, and those made by recovery itself. Second, derive the classes of stored state a reset can leave: for nn operations, n+1n + 1 states between complete operations and nn classes of torn operations. Third, show for each class at least one reset whose landing point, measured from markers on the target rather than taken from the host’s command time, fell in that class, together with the recovery result. Classes that the reset kind used cannot reach, typically torn writes when the reset comes from software, must be listed as gaps or covered by power-loss injection.

Related entries: Crash consistency (§8.4), Power-loss injection (§8.38), Counter quantization (§11.35), Fault injection (§10.28), Torn write (§8.19), Watchdog timer (§6.16).