Module 6: Production Environments | Intermediate UVM

Error Injection

Deliberately create fault conditions and verify that the DUT and verification environment respond correctly.

Learning objectives

  • Explain why error injection is necessary in production-quality verification environments.
  • Distinguish error stimulus, DUT error handling, and verification-environment diagnostics.
  • Choose an appropriate injection point for protocol, data, timing, and functional errors.
  • Implement a configurable UVM error-injection mechanism without contaminating normal stimulus behavior.
  • Verify error status, responses, interrupts, recovery, and side effects.
  • Use callbacks, configuration, or specialized sequences appropriately for different injection mechanisms.
  • Make negative tests reset-aware and prevent expected errors from being reported as accidental testbench failures.

Step 1: Understand why error injection matters

A verification environment is not complete if it only demonstrates that the DUT works when every input is legal.

Real systems encounter malformed requests, invalid addresses, parity failures, timeouts, protocol violations, overflow conditions, unsupported commands, and other fault conditions. The DUT may be required to reject the operation, record an error, raise an interrupt, return an error response, or recover without corrupting unrelated state.

Error injection deliberately creates those conditions so the environment can verify the specified response.

Normal stimulus
  |
  v
DUT
  |
  v


Expected functional result

Injected fault
|
v
DUT
|
+---- error response
+---- status update
+---- interrupt
+---- recovery
+---- state preservation 

The key question is not simply "Can I make the DUT fail?". The verification question is:

"When this specific fault occurs, does the DUT produce exactly the behavior required by the specification?"

Step 2: Separate injection from checking

Error injection and error checking are related but different responsibilities.

Responsibility Question Typical owner
Injection How do we deliberately create the fault? Sequence, driver, callback, fault-injection component
Observation What did the DUT actually do? Monitor, register model, assertions
Expected behavior What should happen for this injected fault? Test/sequence/checker configuration
Comparison Did actual behavior match the specification? Scoreboard/checker/assertion
Diagnostics Was the failure reported clearly? UVM reporting infrastructure

Keeping these responsibilities separate prevents a common mistake: modifying the checker so that it ignores the behavior produced by an injected error.

Critical distinction: an expected DUT error is not automatically a testbench error. The test should expect the specified fault response while still failing if the DUT responds incorrectly.

Step 3: Identify useful injection points

The best injection point is the earliest practical point where the desired fault can be introduced without changing unrelated behavior.

Fault type Possible injection point Example
Invalid transaction Sequence Unsupported command or illegal field value
Protocol violation Driver/callback/interface layer Unexpected handshake behavior
Corrupted data Driver or transaction transformation Flip a payload bit or parity bit
Register fault condition RAL-based sequence Write an invalid value or unsupported access
Timing fault Driver/interface behavior Delay a response beyond the allowed limit
Environmental fault Dedicated fault component Interrupt, reset, or external error condition

Do not automatically inject every fault by modifying the driver. A malformed transaction may belong in a sequence; a controlled protocol violation may belong at the driver/interface boundary; a register-defined error may be easiest to produce through the register model.

Step 4: Start with a deterministic fault scenario

Begin with one fault whose expected result is unambiguous.

For example, suppose a bus protocol defines an invalid command encoding that the DUT must reject with an error response and set an error-status bit.

Test


|
+-- Configure error reporting
|
+-- Generate invalid command
|
+-- Observe bus response
|
+-- Read error status
|
+-- Verify status/response
|
+-- Clear error condition
|
+-- Verify recovery 

The first test should answer four questions:

  1. Was the intended error actually injected?
  2. Did the DUT recognize it?
  3. Did the DUT produce the required observable response?
  4. Did the DUT recover according to the specification?

Step 5: Represent fault intent explicitly

Instead of scattering special-case flags throughout the environment, represent the requested injection as data.

typedef enum {


ERR_NONE,
ERR_INVALID_CMD,
ERR_BAD_PARITY,
ERR_BAD_ADDRESS,
ERR_TIMEOUT,
ERR_PROTOCOL
} error_kind_e;

class error_injection_cfg extends uvm_object;
`uvm_object_utils(error_injection_cfg)

bit            enabled = 0;
error_kind_e   kind    = ERR_NONE;
int unsigned   count   = 1;

function new(string name = "error_injection_cfg");
super.new(name);
endfunction
endclass

This gives the test a typed way to request a fault while allowing the component responsible for injection to decide how that fault is physically created.

For example:

error_injection_cfg cfg;


cfg = error_injection_cfg::type_id::create("cfg");
cfg.enabled = 1;
cfg.kind    = ERR_INVALID_CMD;
cfg.count   = 1;

uvm_config_db#(error_injection_cfg)::set(
this,
"env.bus",
"error_cfg",
cfg
);

Configuration is useful for stable policy. Per-test scenario intent can also be expressed directly in sequences when the fault is part of a particular stimulus flow.

Step 6: Inject transaction-level errors in the sequence

If the fault is simply an illegal or unusual transaction value, the cleanest solution may be a dedicated negative-test sequence.

class invalid_command_seq extends bus_base_seq;


`uvm_object_utils(invalid_command_seq)

function new(string name = "invalid_command_seq");
super.new(name);
endfunction

task body();
bus_item req;


req = bus_item::type_id::create("req");

start_item(req);

req.cmd  = 4'hF;       // Reserved/invalid command.
req.addr = 'h100;
req.data = 'h1234;

finish_item(req);


endtask
endclass

This is preferable to adding an inject_invalid_command branch to every normal sequence. The normal stimulus remains readable, while the negative sequence makes the intentional fault obvious.

Use the right abstraction: if the protocol itself allows a transaction to contain an invalid field, inject the invalid field through the transaction stimulus. Do not corrupt lower-level signals merely because the driver happens to have access to them.

Step 7: Use callbacks when the injection point belongs to a reusable component

Lessons 47 and 48 introduced UVM callbacks. They can be useful when a reusable component needs a controlled extension point for fault injection without creating a special driver subclass for every test.

class bus_error_callback extends uvm_callback;


`uvm_object_utils(bus_error_callback)

bit inject_error = 0;

function new(string name = "bus_error_callback");
super.new(name);
endfunction

virtual function void modify_item(bus_item item);
if (inject_error)
item.data[0] = ~item.data[0];
endfunction
endclass

The driver can expose a narrowly defined callback hook at the appropriate point in its processing flow.

For example, conceptually:

`uvm_do_callbacks(bus_driver, bus_error_callback,
              modify_item(req))

The exact callback hook must be designed into the reusable component. Callbacks are not a requirement for error injection, and they should not become a hidden mechanism that silently changes normal transactions.

A good callback-based injection mechanism should make it obvious:

  • when injection is enabled;
  • which error is being injected;
  • how many times it will occur;
  • which transactions are eligible; and
  • when injection returns to normal behavior.

Step 8: Verify the DUT response, not merely the injected fault

Successfully changing a transaction does not prove that error verification works.

Suppose bad parity is injected. The test may need to verify:

Bad parity injected
   |
   v


DUT detects error
|
+---- correct error response
|
+---- error status set
|
+---- interrupt generated
|
+---- original data not committed
|
+---- interface recovers 

Which of these checks are required depends on the specification.

For the interrupt behavior introduced in Lesson 58, an injected error may intentionally become the cause of an interrupt:

Injected fault
 |
 v


Error status
|
v
Error interrupt expected
|
v
Interrupt monitor
|
v
Interrupt checker 

The expected interrupt should be created because the test intentionally injected a fault that the specification says must generate an interrupt—not because the checker blindly accepts any interrupt observed during the test.

Step 9: Keep expected errors separate from testbench failures

Negative tests create a subtle reporting problem. A DUT may intentionally return an error response, while the testbench must still remain healthy.

For example:

Expected:


invalid command
|
v
DUT error response
|
v
test passes

Unexpected:
invalid command
|
v
DUT accepts command
|
v
scoreboard mismatch
|
v
test fails 

Do not solve this by globally suppressing uvm_error messages. Instead, model the expected behavior explicitly.

A negative-test expectation might contain:

class expected_error extends uvm_object;


`uvm_object_utils(expected_error)

error_kind_e kind;
int unsigned transaction_id;
bit expect_response_error;
bit expect_status;
bit expect_interrupt;

function new(string name = "expected_error");
super.new(name);
endfunction
endclass

The checker can then distinguish:

  • the expected error response;
  • an incorrect response to the injected fault;
  • an unrelated unexpected error; and
  • a verification-environment failure.

Step 10: Test error recovery and side effects

Error handling is rarely complete when the DUT merely detects a fault.

Ask what should happen to system state afterward.

  • Was the invalid operation committed or rejected?
  • Was data partially written?
  • Was an error status bit set?
  • Was the status bit sticky?
  • Was an interrupt generated?
  • Did the interrupt clear correctly?
  • Can a subsequent valid transaction complete?
  • Was unrelated state preserved?

A particularly useful pattern is fault → recovery → normal operation.

valid operation
  |
  v


baseline behavior
|
v
inject fault
|
v
verify error handling
|
v
perform valid operation
|
v
verify recovery 

This catches designs that correctly detect an error but remain stuck in an invalid state afterward.

Step 11: Combine error injection with reset

Lesson 57 established that reset can invalidate in-flight transactions and checker state. Error injection makes this even more important.

Consider:

Inject fault
 |
 v


Error becomes pending
|
+------ RESET ------+
|
v
What survives? 

The test must follow the DUT specification for:

  • pending error status;
  • interrupt state;
  • partially completed operations;
  • error counters;
  • in-flight transactions; and
  • error-injection configuration itself.

The injection mechanism should also return to a known state after reset or between tests. A previous test must not accidentally leave fault injection enabled for a later scenario.

Step 12: Add coverage for error scenarios

Error injection becomes much more valuable when the regression can demonstrate which fault classes and operating modes have actually been exercised.

Useful coverage dimensions include:

  • error type;
  • protocol mode;
  • operating state;
  • interrupt enabled versus masked;
  • error during normal traffic versus idle;
  • error before versus after reset;
  • single versus repeated errors; and
  • recovery success.

For example:

covergroup error_cg;


cp_error:
coverpoint error_kind;

cp_irq_enable:
coverpoint irq_enabled;

cp_recovery:
coverpoint recovery_success;

error_x_irq:
cross cp_error, cp_irq_enable;

endgroup

Do not create every possible cross automatically. Select combinations that correspond to meaningful verification requirements.

Step 13: Build a complete negative-test flow

A reusable error test can be organized into the following sequence:

1. Configure DUT
   |


2. Configure injection
|
3. Establish expected error behavior
|
4. Generate normal stimulus
|
5. Inject fault
|
6. Observe DUT response
|
7. Check status/response/interrupt
|
8. Clear or service error
|
9. Verify recovery
|
10. Disable injection
|
11. Run normal transaction
|
12. Confirm normal behavior returned 

The final normal transaction is important. It proves that the fault-injection mechanism and the DUT both returned to the expected state.

Common mistakes

  • Injecting faults everywhere: choose the smallest layer that naturally represents the desired fault.
  • Changing the normal driver for one negative test: prefer a dedicated sequence, configuration, or narrowly scoped extension mechanism.
  • Suppressing checker errors globally: expected DUT errors should be modeled explicitly, not hidden from the reporting system.
  • Checking only that an error occurred: verify the complete specified response, including status, interrupt, response code, state changes, and recovery.
  • Leaving injection enabled: ensure the mechanism has deterministic lifetime and cannot silently affect later tests.
  • Assuming every error should generate an interrupt: only expect an interrupt when the specification requires one.
  • Ignoring error aggregation: multiple faults may share one status or interrupt indication.
  • Ignoring reset: reset can clear, preserve, or transform error state depending on the DUT.
  • Using callbacks without a defined hook: callbacks are extension points, not magic access to arbitrary driver behavior.
  • Injecting signal corruption when transaction corruption is sufficient: stay at the highest useful abstraction level unless the requirement specifically concerns physical protocol behavior.

Try it yourself

Suppose a DUT accepts bus commands and has an error status register plus an error interrupt.

Design a negative test for an invalid command.

  1. Define exactly what makes the command invalid.
  2. Choose where the error should be injected.
  3. Describe the expected bus response.
  4. Describe the expected status-register state.
  5. Decide whether an interrupt should occur.
  6. Define how the error is cleared.
  7. Perform a valid command afterward and verify recovery.

Challenge: Build a reusable fault injector

Create a reusable error-injection mechanism that supports at least three fault types:

  • invalid command;
  • corrupted data; and
  • delayed response.

For each fault, specify:

  1. the injection point;
  2. the configuration required;
  3. the expected DUT response;
  4. the monitor/checker evidence;
  5. the reset behavior; and
  6. the recovery behavior.

Extra challenge: implement one fault using a dedicated sequence and another using a callback. Explain why the two injection mechanisms belong at different abstraction levels.

Knowledge check

  1. What is the difference between error injection and error checking?

    Injection deliberately creates a fault condition. Checking determines whether the DUT's response matches the expected behavior for that fault.

  2. When is a dedicated negative sequence preferable to modifying the normal driver?

    When the desired fault can be represented naturally as unusual or illegal transaction stimulus. This keeps normal driver behavior reusable and easier to understand.

  3. Why should expected DUT errors not simply be suppressed?

    Because the test must still detect incorrect behavior. The expected error should be represented explicitly so the checker can distinguish the required response from an unexpected failure.

  4. Why verify a valid transaction after error recovery?

    It demonstrates that the DUT recovered rather than merely detecting the fault.

  5. Why might an injected error also require interrupt checking?

    If the specification requires the fault to produce an interrupt, the interrupt is part of the expected response and should be correlated with the injected event.

  6. What should happen to error expectations during reset?

    They should be discarded, preserved, or transformed according to the DUT's defined reset semantics. The checker must make that policy explicit.

Key takeaways

  • Error injection is deliberate negative stimulus used to verify fault detection, handling, and recovery.
  • Keep injection, observation, expected behavior, comparison, and diagnostics as separate responsibilities.
  • Choose the injection point according to the abstraction of the fault: sequence, driver, callback, register access, or dedicated fault component.
  • Represent injection intent explicitly so tests can control fault type, scope, and lifetime.
  • Do not confuse an expected DUT error with a verification-environment failure.
  • Verify the complete response: error indication, status, interrupt, side effects, clearing, and recovery.
  • Make injection deterministic and ensure it cannot silently leak into later scenarios.
  • Reset behavior must be explicitly defined for both DUT error state and checker expectations.
  • Use coverage to demonstrate which fault classes and operating conditions have actually been exercised.

What comes next?

Lesson 60, Low-Power Scenario Basics, extends the same negative-testing mindset into power-management behavior. Instead of injecting an invalid transaction, you will exercise transitions involving power state, reset, isolation, and retention, while verifying that the environment correctly handles changing availability and state across those transitions.