Module 6: First Complete Environment | Lesson 57

FIFO Verification Lab

Build a complete UVM FIFO testbench that generates reads and writes, observes the DUT, maintains an expected queue, and verifies data ordering.

Learning objectives

  • Translate FIFO requirements into concrete verification scenarios.
  • Build a transaction-based UVM environment for FIFO read and write operations.
  • Use a SystemVerilog queue as a simple reference model.
  • Perform in-order expected-versus-observed checking.
  • Verify FIFO reset, empty, full, ordering, and mixed read/write behavior.
  • Debug a FIFO mismatch by tracing the first incorrect transaction.

Step 1: Understand what makes a FIFO interesting

In Lesson 56, the counter verification problem was mostly about state: given an enable operation, did the counter reach the correct value?

A FIFO adds another important dimension: ordering.

A FIFO must return data in the same order in which valid data was accepted.

WRITE A


WRITE B
WRITE C


    FIFO


READ -> A
READ -> B
READ -> C

If the DUT returns C before A, it is wrong even though all three values eventually appear.

Core verification idea: FIFO verification is not just “did the data come out?” It is “did the correct data come out, in the correct order, under the correct conditions?”

Step 2: Start with the FIFO specification

Before writing UVM code, define the behavior that the testbench must prove.

For this lab, assume a synchronous FIFO with a depth of four entries.

Requirement Expected behavior
Reset FIFO becomes empty.
Valid write while not full Data is accepted into the FIFO.
Read while not empty The oldest stored data is returned.
FIFO becomes empty empty indicates that no valid data remains.
FIFO becomes full full indicates that another write cannot be accepted according to the specification.
Write then read Data is returned in first-in, first-out order.

The exact behavior of simultaneous read/write, write-while-full, and read-while-empty must come from the DUT specification. Do not assume a universal answer for those cases.

Step 3: Look at the DUT interface

A simple FIFO interface might contain:

interface fifo_if(input logic clk);


logic       reset;

logic       write;
logic       read;
logic [7:0] wdata;
logic [7:0] rdata;

logic       full;
logic       empty;

endinterface

The DUT might conceptually look like this:

module fifo #(


parameter int DEPTH = 4
) (
input  logic       clk,
input  logic       reset,

input  logic       write,
input  logic       read,
input  logic [7:0] wdata,
output logic [7:0] rdata,

output logic       full,
output logic       empty
);

// FIFO implementation intentionally omitted.

endmodule

The implementation is not the focus of this lesson. Your verification environment should be able to determine whether the implementation obeys its external contract without depending on its internal pointers or storage array.

Step 4: Model FIFO operations as transactions

A transaction should describe a meaningful FIFO operation rather than mirror every interface signal.

class fifo_transaction extends uvm_sequence_item;


`uvm_object_utils(fifo_transaction)

rand bit       write;
rand bit       read;
rand bit [7:0] wdata;

bit [7:0]      rdata;
bit            full;
bit            empty;

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

endclass

Here the transaction contains both stimulus information and observed information because the same object type is being used for this introductory lab.

The distinction must still remain clear:

Stimulus fields
write
read
wdata
   |
   v
 DRIVER
   |
   v
  DUT
   |
   v
MONITOR
   |
   +---- rdata
   +---- full
   +---- empty
   |
   v


SCOREBOARD

In a larger environment, you may choose separate request and response/observed transaction types. The important concept is that the checker must compare what the DUT actually produced against what the specification predicted.

Step 5: Build the FIFO verification flow

The complete lab architecture is an extension of the counter environment.

                    fifo_test
                    |
                    v
             fifo_sequence
                    |
                    v
              fifo_sequencer
                    |
                    v
                fifo_driver
                    |
                    v
                +-------+
                | FIFO  |
                |  DUT  |
                +-------+
                    |
                    v
               fifo_monitor
                    |
                    v
             analysis_port
                    |
                    v
             fifo_scoreboard
                    |
                    v
              PASS / ERROR

The major new piece is the scoreboard's expected-data queue.

Write transaction
   |
   v


expected_queue.push_back(wdata)

Read transaction
|
v
expected = expected_queue.pop_front()
|
v
compare expected with DUT rdata

This is a simple reference model for FIFO ordering.

Step 6: Understand the expected queue

SystemVerilog queues are particularly useful for modeling an in-order FIFO.

bit [7:0] expected_queue[$];

When the DUT successfully accepts a write:

expected_queue.push_back(transaction.wdata);

When the DUT successfully performs a read:

expected = expected_queue.pop_front();

Consider this sequence:

WRITE 8'hA1


WRITE 8'hB2
WRITE 8'hC3

The expected queue becomes:

Front


|
v
+------+------+
| A1   | B2   | C3 |
+------+------+
^
Back

The first read removes A1, not C3.

READ -> expected = pop_front()


READ -> expected = B2
READ -> expected = C3

This gives the scoreboard an independent representation of FIFO ordering.

Why this is powerful: The scoreboard does not need to know where the DUT stores data. It only needs to know the external FIFO rule: accepted writes enter at the back, accepted reads remove from the front.

Step 7: Generate a deterministic FIFO scenario

Start with a directed sequence. The first test should make the expected queue easy to calculate by hand.

Reset


WRITE A1
WRITE B2
WRITE C3

READ
READ
READ

The expected behavior is:

Operation Expected queue Expected read data
Reset Empty -
Write A1 A1 -
Write B2 A1, B2 -
Write C3 A1, B2, C3 -
Read B2, C3 A1
Read C3 B2
Read Empty C3

If the DUT returns C3, B2, A1, all the data is present but the FIFO is still broken.

Step 8: Write the sequence

A directed sequence can create the known write/read pattern:

class fifo_smoke_sequence
extends uvm_sequence #(fifo_transaction);


`uvm_object_utils(fifo_smoke_sequence)

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

task body();
fifo_transaction req;


// Write A1
req = fifo_transaction::type_id::create("write_a1");
start_item(req);
req.write = 1'b1;
req.read  = 1'b0;
req.wdata = 8'hA1;
finish_item(req);

// Write B2
req = fifo_transaction::type_id::create("write_b2");
start_item(req);
req.write = 1'b1;
req.read  = 1'b0;
req.wdata = 8'hB2;
finish_item(req);

// Write C3
req = fifo_transaction::type_id::create("write_c3");
start_item(req);
req.write = 1'b1;
req.read  = 1'b0;
req.wdata = 8'hC3;
finish_item(req);

// Read three entries
repeat (3) begin
  req = fifo_transaction::type_id::create("read");
  start_item(req);
  req.write = 1'b0;
  req.read  = 1'b1;
  finish_item(req);
end


endtask

endclass

At this stage, clarity is more valuable than compact code. Later you can create helper tasks for repeated writes and reads.

Step 9: Drive the FIFO protocol

The driver translates a transaction into interface activity.

class fifo_driver extends uvm_driver #(fifo_transaction);


`uvm_component_utils(fifo_driver)

virtual fifo_if vif;

function new(string name = "fifo_driver",
uvm_component parent = null);
super.new(name, parent);
endfunction

task run_phase(uvm_phase phase);
fifo_transaction req;


forever begin
  seq_item_port.get_next_item(req);

  @(negedge vif.clk);

  vif.write <= req.write;
  vif.read  <= req.read;
  vif.wdata <= req.wdata;

  @(negedge vif.clk);

  vif.write <= 1'b0;
  vif.read  <= 1'b0;

  seq_item_port.item_done();
end


endtask

endclass

This example is intentionally simplified. A real FIFO driver must follow the actual DUT protocol, including any requirement to wait for full or empty before declaring an operation accepted.

That distinction matters for the scoreboard too.

Step 10: Monitor accepted operations and results

The monitor observes the interface and reconstructs what actually happened.

A simplified monitor might sample after the DUT's active clock edge:

task run_phase(uvm_phase phase);


fifo_transaction observed;

forever begin
@(negedge vif.clk);


observed = fifo_transaction::type_id::create("observed");

observed.write = vif.write;
observed.read  = vif.read;
observed.wdata = vif.wdata;
observed.rdata = vif.rdata;
observed.full  = vif.full;
observed.empty = vif.empty;

analysis_port.write(observed);


end

endtask

The exact acceptance rule depends on the FIFO protocol. For example, if a write is accepted only when write && !full, the monitor/checker must use that rule rather than assuming every write pulse succeeded.

The monitor should therefore answer:

  • Was a write requested?
  • Was it accepted?
  • Was a read requested?
  • Was it accepted?
  • What data was observed?
  • What were the FIFO status signals?

Step 11: Build the queue-based scoreboard

The scoreboard maintains an independent expected queue.

class fifo_scoreboard extends uvm_scoreboard;


`uvm_component_utils(fifo_scoreboard)

uvm_analysis_imp #(fifo_transaction,
fifo_scoreboard) analysis_imp;

bit [7:0] expected_queue[$];

int checks;
int errors;

function new(string name = "fifo_scoreboard",
uvm_component parent = null);
super.new(name, parent);
analysis_imp = new("analysis_imp", this);
endfunction

function void write(fifo_transaction t);


bit [7:0] expected;

// Reset clears the reference model.
if (t.reset) begin
  expected_queue.delete();

  `uvm_info(
    "SB",
    "Reference FIFO cleared by reset",
    UVM_MEDIUM
  )

  return;
end

// Model an accepted write.
if (t.write && !t.full) begin
  expected_queue.push_back(t.wdata);

  `uvm_info(
    "SB",
    $sformatf(
      "Expected write: 0x%02h queue_depth=%0d",
      t.wdata,
      expected_queue.size()
    ),
    UVM_MEDIUM
  )
end

// Model an accepted read.
if (t.read && !t.empty) begin

  if (expected_queue.size() == 0) begin
    errors++;

    `uvm_error(
      "FIFO_SB",
      "DUT accepted a read but reference queue is empty"
    )

  end
  else begin

    expected = expected_queue.pop_front();
    checks++;

    if (t.rdata !== expected) begin
      errors++;

      `uvm_error(
        "FIFO_SB",
        $sformatf(
          "FIFO mismatch: expected=0x%02h observed=0x%02h",
          expected,
          t.rdata
        )
      )
    end
    else begin

      `uvm_info(
        "FIFO_SB",
        $sformatf(
          "FIFO match: data=0x%02h",
          t.rdata
        ),
        UVM_MEDIUM
      )

    end
  end
end


endfunction

function void report_phase(uvm_phase phase);


super.report_phase(phase);

if (errors == 0) begin
  `uvm_info(
    "FIFO_PASS",
    $sformatf(
      "FIFO scoreboard passed: checks=%0d remaining_expected=%0d",
      checks,
      expected_queue.size()
    ),
    UVM_LOW
  )
end
else begin
  `uvm_error(
    "FIFO_FAIL",
    $sformatf(
      "FIFO scoreboard failed: checks=%0d errors=%0d remaining_expected=%0d",
      checks,
      errors,
      expected_queue.size()
    )
  )
end


endfunction

endclass

The most important operation is:

expected = expected_queue.pop_front();


if (t.rdata !== expected)
report error;

This is the heart of in-order FIFO checking.

Why pop_front()? A FIFO removes the oldest expected item first. The queue operation mirrors the behavior being verified without depending on the DUT's internal implementation.

Step 12: Handle empty and full correctly

Boundary conditions are where FIFO verification becomes much more valuable.

Empty FIFO

After reset, the FIFO should be empty. A read request should follow the specification for an empty FIFO.

RESET


READ while EMPTY

Your checker should verify the defined behavior rather than blindly expecting data.

Full FIFO

For a depth-four FIFO:

WRITE A1


WRITE B2
WRITE C3
WRITE D4

FIFO is now FULL

A fifth write must be checked according to the DUT specification.

WRITE E5 while FULL

If the FIFO rejects the write, E5 must not enter the expected queue.

This gives us an important general rule:

Requested operation
    |
    v


Was it accepted?
|
+---+---+
|       |
YES      NO
|       |
v       v
Update    Do not
model     update model

Step 13: Verify ordering explicitly

Now create a test that makes ordering impossible to miss.

WRITE 8'h11


WRITE 8'h22
WRITE 8'h33
WRITE 8'h44

READ
READ
READ
READ

The only correct read sequence is:

11


22
33
44

Change the DUT implementation temporarily so that it returns the newest item first. The test should fail immediately.

This experiment demonstrates why a scoreboard must compare sequence and value, not just whether the expected set of values eventually appeared.

Step 14: Test mixed traffic

A FIFO becomes more interesting when reads and writes are interleaved.

WRITE A1


WRITE B2
READ
WRITE C3
READ
WRITE D4
WRITE E5
READ

Track the reference queue after every accepted operation:

WRITE A1     -> [A1]


WRITE B2     -> [A1, B2]
READ         -> [B2]
WRITE C3     -> [B2, C3]
READ         -> [C3]
WRITE D4     -> [C3, D4]
WRITE E5     -> [C3, D4, E5]
READ         -> [D4, E5]

Writing this table by hand is an excellent way to understand what the scoreboard is doing automatically.

Step 15: Connect the environment

The environment connects the monitor to the scoreboard.

function void connect_phase(uvm_phase phase);


super.connect_phase(phase);

agent.monitor.analysis_port.connect(
scoreboard.analysis_imp
);

endfunction

The complete data path is now:

Sequence


|
v
Sequencer
|
v
Driver
|
v
FIFO DUT
|
v
Monitor
|
v
Analysis Port
|
v
Scoreboard
|
+---- expected_queue
|
+---- expected vs observed
|
v
PASS / ERROR

The environment itself should not calculate FIFO correctness. Its job is to compose the components and connect them.

Step 16: Create a useful FIFO test plan

A small FIFO already gives you several meaningful verification scenarios.

Scenario What it verifies
Reset Known initial state and empty indication.
Single write/read Basic data storage and retrieval.
Multiple writes/reads FIFO ordering.
Fill to full Capacity and full indication.
Read to empty Empty indication and boundary behavior.
Read while empty Illegal or blocked operation behavior.
Write while full Illegal or blocked operation behavior.
Mixed traffic Ordering across changing occupancy.
Repeated fill/drain Pointer and state management over time.
Simultaneous read/write Protocol-specific boundary behavior.

This is already becoming a real verification plan rather than a single smoke test.

Step 17: Break the FIFO on purpose

As in the counter lab, deliberately introduce bugs.

Bug 1: Reverse the read order

Make the DUT return the newest item instead of the oldest item.

The scoreboard should report a data mismatch on the first read.

Bug 2: Lose one write

Prevent one accepted write from entering the DUT storage.

The scoreboard should identify the first read whose value no longer matches.

Bug 3: Incorrect full handling

Allow a fifth item into a four-entry FIFO when the specification says the write should be rejected.

The checker should detect incorrect occupancy or subsequent ordering behavior.

Bug 4: Incorrect empty handling

Make the DUT produce stale data during an empty read when the specification says the read must be blocked.

Your test should distinguish a valid read from an attempted invalid operation.

Verification quality test: If you can break FIFO ordering, capacity, or boundary behavior and the test still passes, your environment is not checking enough.

Step 18: Debug a FIFO mismatch

Suppose the scoreboard reports:

FIFO mismatch:


expected  = 0x22
observed  = 0x33

Follow the transaction path backward.

Was 0x22 actually written?
      |
      v


Was that write accepted?
|
v
Did the DUT preserve ordering?
|
v
Did the monitor sample the correct read?
|
v
Did the monitor capture rdata at the correct time?
|
v
Did the scoreboard update its queue correctly?

Do not assume the scoreboard is the problem simply because the error appeared there.

A monitor sampling one cycle too early can create a scoreboard failure even when the DUT is correct.

Use three sources of evidence together:

  • UVM logs — show transaction-level intent and observations.
  • Scoreboard state — shows what the reference model expected.
  • Waveform — shows the actual signal-level timing.

Step 19: Add constrained-random traffic later

Once the directed tests work, randomization becomes useful.

A random FIFO transaction might constrain the operation:

constraint valid_operation {


write != read;
}

Or you may intentionally allow both operations so that simultaneous read/write behavior is exercised:

rand bit write;


rand bit read;
rand bit [7:0] wdata;

The important point is that randomization comes after the reference model and basic checking are trusted.

Directed smoke tests
    |
    v


Basic scoreboard
|
v
Boundary tests
|
v
Mixed traffic
|
v
Constrained-random traffic
|
v
Coverage

Random stimulus is much more useful when failures are already observable and reproducible.

FIFO lab challenge

Build a complete UVM FIFO environment and prove that it catches ordering and boundary bugs.

  1. Create a fifo_if interface and connect it to a FIFO DUT.
  2. Create a fifo_transaction representing read/write operations.
  3. Build the sequencer, driver, and monitor.
  4. Connect the monitor to a scoreboard through an analysis port.
  5. Implement an expected-data queue using push_back() and pop_front().
  6. Verify a simple write/read sequence.
  7. Fill the FIFO and verify the full condition.
  8. Drain the FIFO and verify the empty condition.
  9. Run mixed read/write traffic.
  10. Inject a DUT bug that reverses FIFO ordering.
  11. Prove that the scoreboard detects the bug.

Stretch challenge

Add a transaction counter and occupancy model:

occupancy = occupancy + accepted_write


occupancy = occupancy - accepted_read

Then check that:

occupancy == 0  -> empty


occupancy == 4  -> full
0 < occupancy < 4 -> neither full nor empty

Use the actual FIFO specification to determine how simultaneous accepted read/write operations affect occupancy.

Common mistakes

Mistake Why it causes trouble Better approach
Queueing every requested write A write may be rejected because the FIFO is full. Model accepted operations according to the protocol.
Reading from the expected queue on every read request An empty read may not be accepted. Apply the DUT's acceptance rules.
Comparing only the set of returned values Incorrect ordering can go undetected. Compare values in FIFO order.
Sampling rdata at the wrong time The monitor may capture stale or transitional data. Define the protocol's valid sampling point.
Assuming full/empty behavior Different FIFO protocols define boundary operations differently. Verify against the actual specification.
Testing only one write and one read Basic functionality can pass while ordering is broken. Use multiple distinct data values.
Starting with random traffic Failures become harder to reproduce and understand. Start with deterministic scenarios.
Letting the scoreboard inspect DUT internals The checker becomes coupled to the implementation. Predict behavior from the external specification.

Key takeaways

  • A FIFO introduces ordering as a central verification requirement.
  • A SystemVerilog queue provides a simple and powerful reference model for in-order FIFO behavior.
  • push_back() models an accepted write; pop_front() models an accepted read.
  • The scoreboard must model accepted operations, not merely requested operations.
  • Full, empty, reset, and simultaneous operations must be defined by the DUT specification.
  • Use distinctive data values such as A1, B2, C3, and D4 to make ordering failures obvious.
  • Directed tests establish confidence first; constrained-random traffic can expand the search space afterward.
  • A strong FIFO testbench should detect deliberately injected ordering and boundary-condition bugs.

Core mental model

A FIFO scoreboard is an independent model of what data should exist in the DUT.

             ACCEPTED WRITE
                |
                v
         +--------------+
         | Expected     |
         | Queue        |
         +--------------+
                |
                | pop_front()
                v
         Expected Data
                |
                | compare
                v


DUT ---> Monitor ---> Observed Data
|
v
PASS / ERROR

The most important idea is independence.

The DUT has its own storage, pointers, and implementation. The scoreboard has only the specification-level model. If both agree across directed, boundary, and randomized scenarios, you have meaningful verification evidence.

For a FIFO, correctness means: accepted data comes out in the correct order, under the correct conditions.

What comes next?

In Lesson 58, Coverage Collector Basics, you will add another dimension to the environment.

The scoreboard answers:

“Was the behavior correct?”

Coverage asks a different question:

“What behavior did we actually exercise?”

That distinction is essential. A test can pass every check while still exercising only a tiny portion of the design's behavior.