An ECU that works on a clean bus has only passed half its tests. In the vehicle, messages go missing when another ECU resets, frames are corrupted by electrical noise, and a sender's software has bugs. The ECU's specification says what it must do in each case: use a substitute value, store a DTC, warn the driver, recover. Fault injection checks that it really does, by producing each fault on purpose.

The faults to inject

FaultWhat it simulatesTypical required reaction
Timeout: message stopsSender reset, bus-off, unplugged ECUSubstitute value after N missing cycles; communication DTC (a U-code such as U0100 for the engine ECU)
Frozen counterSender task stuck, repeated frameData treated as invalid, as for a timeout
Wrong CRCCorrupted or manipulated frameFrame discarded; DTC if it persists
Invalid value (e.g. 0xFFFF)Sender reports "not available" or a sensor faultSubstitute value; function degraded
Out-of-range valueSender bug or scaling errorPlausibility check rejects it
Wrong lengthWrong software variant on the senderFrame discarded
Wrong cycle timeOverloaded sender, wrong configurationDepends: often treated as timeout if too slow
Error frames, bus-offWiring or transceiver faults, bad bitrateECU stays off the bus while bus-off, then recovers

The exact reaction, the number of cycles before it, and the DTC are in the ECU's requirements or the network's communication specification. Your test checks the ECU against those, not against this table.

Injecting message faults in Python

This generator produces the frames of one protected message, the ESP speed message from the restbus guide, and applies faults inside time windows:

Python
DATA_ID = [0x5D, 0x12, 0xA7, 0x3C, 0xE1, 0x48, 0x9B, 0x06, 0x71, 0xC4, 0x2F, 0x88, 0xD3, 0x6A, 0xB5, 0x19]


def crc8h2f(data):
    crc = 0xFF
    for byte in data:
        crc ^= byte
        for _ in range(8):
            crc = ((crc << 1) ^ 0x2F) & 0xFF if crc & 0x80 else (crc << 1) & 0xFF
    return crc ^ 0xFF


def esp_speed_frames(seconds, faults, speed=50.0, cycle=0.020):
    """ESP_Speed frames (time, data) with faults applied inside their time windows."""
    def active(name, t):
        return any(kind == name and start <= t < end for kind, start, end in faults)

    t, counter = 0.0, 0
    while t < seconds:
        if active("timeout", t):                       # the sender stops
            t += cycle
            continue
        raw = 0xFFFF if active("invalid_value", t) else round(speed * 100)
        body = bytes([counter & 0x0F, raw & 0xFF, raw >> 8, 0, 0, 0, 0])
        crc = crc8h2f(body + bytes([DATA_ID[counter & 0x0F]]))
        if active("bad_crc", t):
            crc ^= 0xFF
        data = bytes([crc]) + body
        yield t, data[:6] if active("short_frame", t) else data
        if not active("freeze_counter", t):            # a stuck counter repeats its value
            counter += 1
        t += 2 * cycle if active("slow", t) else cycle  # the sender runs at half rate


FAULTS = [
    ("timeout", 0.50, 0.70),
    ("freeze_counter", 1.00, 1.10),
    ("bad_crc", 1.50, 1.56),
    ("invalid_value", 2.00, 2.02),
    ("short_frame", 2.50, 2.52),
    ("slow", 3.00, 6.00),
]

On a bench, send these frames from a restbus instead of the healthy ones. To check that the faults really are faults, write them to a log and run the DBC signal checker on it:

Python
with open("injected.log", "w") as log:
    for t, data in esp_speed_frames(6.0, FAULTS):
        log.write(f"({1_700_000_000 + t:.6f}) can0 1A0#{data.hex().upper()}\n")

db = cantools.database.load_file("checks.dbc")
for finding in check_log(db, load_log("injected.log"), protection={"ESP_Speed": check_esp_speed}):
    print(finding)

Output:

Example
ESP_Speed: mean period 27.9 ms, DBC says 20 ms
ESP_Speed: no frame for 220 ms after t=0.48 s
ESP_Speed.VehicleSpeed = 655.35 at t=2.00 s, range 0..300
ESP_Speed: 6 bytes at t=2.50 s, DBC says 8
ESP_Speed: counter 8 -> 8 at t=1.02 s
ESP_Speed: counter 8 -> 8 at t=1.04 s
ESP_Speed: counter 8 -> 8 at t=1.06 s
ESP_Speed: counter 8 -> 8 at t=1.08 s
ESP_Speed: counter 8 -> 8 at t=1.10 s
ESP_Speed: wrong CRC at t=1.50 s
ESP_Speed: wrong CRC at t=1.52 s
ESP_Speed: wrong CRC at t=1.54 s
ESP_Speed: wrong CRC at t=2.50 s

Every planted fault shows up. Two details are worth noticing: the shortened frame at 2.50 s also fails the CRC check, because its CRC no longer matches the bytes that remain, and the slow sender only shows in the mean period, because 40 ms gaps are below the 60 ms timeout limit. Check your injector this way before using it on an ECU; a fault that the injector does not actually produce makes a test pass for the wrong reason.

Checking the reaction

For each injected fault, check three things:

  1. The immediate behaviour. Watch the ECU's own messages, decoded with its DBC: does the dependent output switch to its substitute value or degraded state, and after how many cycles?
  2. The diagnostic reaction. Read DTCs with 19 02 FF and check the right DTC appears, with testFailed set while the fault is active. Check the timing too: DTCs are usually debounced, so a fault that lasts less than the debounce time must not set a confirmed DTC. Inject one fault just shorter and one just longer than that limit. The DTC guide explains the status bits.
  3. The recovery. End the fault and check that the function returns, that testFailed clears, and that the DTC stays stored as confirmed if the requirement says so.

Inject one fault at a time. Two simultaneous faults make it impossible to tell which caused the reaction, unless combinations are exactly what you are testing.

Physical-layer faults

Message faults test the software. Wiring and transceiver faults need hardware: a HIL bench's fault injection unit switches relays in the wiring harness. The standard set for a CAN bus:

FaultHow
CAN high or CAN low openDisconnect one wire to the ECU
CAN high shorted to ground or to batteryRelay to ground or supply
CAN low shorted to ground or to batteryRelay to ground or supply
CAN high shorted to CAN lowRelay between the wires
Missing or extra terminationSwitch a 120 Ω resistor in or out
Supply voltage dropsProgrammable power supply profiles

Check what the ECU does during the fault, and that it recovers afterwards, including leaving bus-off. The error frames and bus-off guide explains the error counters you will see.

Error frames can also be produced on purpose by some CAN interfaces and by HIL bus interfaces, which lets you push an ECU into error-passive or bus-off without touching the wiring.

Making it repeatable

  • Write each fault as a test case with the message, the fault, its duration and the expected reaction from the requirements.
  • Record the bus during every fault test. When a test fails, the recording shows whether the fault was injected as intended.
  • Start each test from a cleared fault memory (14 FF FF FF) and a defined state.
  • Run the fault tests on every software release; fault handling is code that rarely runs in the field and is easy to break.

Frequently asked questions

What is fault injection in ECU testing?

Producing faults on purpose, such as missing messages, corrupted CRCs, invalid signal values or wiring shorts, to check that the ECU detects them and reacts as its requirements specify, with substitute values, DTCs and recovery.

How do I test a CAN message timeout?

Stop sending the message in the restbus for longer than the receiver's timeout, then check the receiver's substitute behaviour, its DTC and its recovery when the message returns. Also test a gap just shorter than the timeout, which must not trigger a reaction.

What is DTC debouncing?

A delay or counter that a fault must exceed before the ECU confirms the DTC, so short disturbances do not set faults. Test both sides of the limit: a fault just shorter must not confirm the DTC, a fault just longer must.

Can I inject error frames with a normal CAN interface?

Some CAN interfaces can send error frames on demand, and HIL bus interfaces usually can. Many simple interfaces cannot. Shorting CAN high to CAN low through a fault injection relay is another way to disturb the bus.

References