Black Box, Grey Box, White Box

A bench can watch only the pins, or reach inside the design. Learn what each view buys and what it costs. Then see one FIFO bug found from outside and from inside, and why reaching inside makes a bench fragile.

You Will Be Able To

  • Define black-box, grey-box and white-box checking.
  • Say what each view finds early and what it costs.
  • Explain why a check that reaches inside the design is fragile.
Lesson
B2.4
Time
18 min
Runs on
Your browser
Check
5 questions

A FIFO bug happens at cycle 4: a register is off by one. A check that watches only the pins notices at cycle 8, when a wrong byte comes out. A check that reads the register sees it at cycle 4. Why would anyone choose the slower one?

Three Places to Put a ProbeStep through. The same FIFO can be watched at its pins, at an interface inside it, or at a single register deep inside.
  • I/O
  • Channel / handshake
  • Storage
  • Monitor
  • Data
  • Analysis
Three Places to Put a ProbeStep through. The same FIFO can be watched at its pins, at an interface inside it, or at a single register deep inside. io Pins push, pop, din, dout,full, empty channel Storage writeport an interface insidethe design storage count register one register deepinside monitor Black box sees the pins only monitor Grey box also sees named innerinterfaces monitor White box reads any signalinside insidedeeperprobeprobeprobe
  1. monitor Black boxsees the pins only
    • probe → Pins
  2. io Pinspush, pop, din, dout, full, empty
    • inside → Storage write port
  3. monitor Grey boxalso sees named inner interfaces
    • probe → Storage write port
  4. channel Storage write portan interface inside the design
    • deeper → count register
  5. monitor White boxreads any signal inside
    • probe → count register
  6. storage count registerone register deep inside
  1. Black box

    The bench sees only the pins, exactly as the specification describes them.

  2. Grey box

    It also watches an interface inside the design, one that is documented and unlikely to change.

  3. White box

    It reads any internal signal by name, such as one register. It sees the most and depends the most on how the design is built.

Read the diagram as text
  • Pins: push, pop, din, dout, full, empty
  • Storage write port: an interface inside the design
  • count register: one register deep inside
  • Black box: sees the pins only
  • Grey box: also sees named inner interfaces
  • White box: reads any signal inside
  • Pins → Storage write port: inside
  • Storage write port → count register: deeper
  • Black box → Pins: probe
  • Grey box → Storage write port: probe
  • White box → count register: probe

Three views of the same FIFO. The deeper the probe, the earlier it sees a bug, and the more it depends on the design's insides.

Before You Start

Read Where the Right Answer Comes From first: a check compares with an expected value. The Specification and the Design Under Test drew the boundary of the design under test.

Five questions this page answers
Question
1What can a black-box check see, and what can it not?
2What does a white-box check gain by reaching inside?
3Why does reaching inside make a bench fragile?
4What is a grey-box check, and when is it the right choice?
5How does one bug look from outside and from inside?

The Idea: How Far Inside to Look

Until now the design under test has been a closed box. The bench drove its inputs and watched its outputs, and nothing else. That is a black-box view: the bench knows only what the specification says about the pins.

In simulation, every signal inside the design is visible. A bench can read a register by its name, or watch an interface between two parts of the design. That is a white-box view. It sees a bug at the moment it happens, instead of when its effect reaches a pin.

Seeing more is not free. A check that names an internal register depends on how the design is built. Rename the register, or build the design another way, and the check breaks, even though the design still meets its specification.

New Words

New words on this page
WordMeaning
Black boxA view of the design through its pins only, as the specification describes them.
White boxA view that reads any signal inside the design by name.
Grey boxA view that adds a few documented interfaces inside the design to the pins.
ProbeA point where the bench reads a signal.
FragileBreaks when something unrelated to correctness changes, such as a signal's name.
MaskedHidden: a wrong value inside that never reaches a pin during the test.

What Each View Buys and Costs

Three views of one design
ViewBuysCosts
Black boxChecks only the specification; survives any redesign; reusable on the next chipSees a bug only when it reaches a pin, maybe much later, maybe never
Grey boxEarlier sight at a few stable inner interfacesDepends on those interfaces staying as documented
White boxSees a bug at its source, at the exact cycleBreaks when the design's insides change; checks how it is built, not only what it does

The last cell hides a deeper cost. A white-box check often states how the designer built the logic, not what the specification asks. Then it inherits the designer's reading, and loses the independence that makes verification work.

Most good benches are black box at heart. They add a few grey or white probes where a bug would otherwise hide for a long time. Rules written as assertions inside the design are the usual way to add that inside view.

The Rules

  1. Rule 1: Check against the pins first.

    A black-box check tests only the specification and survives redesign.

  2. Rule 2: Look inside where a bug would hide.

    A white-box probe finds a bug at its source, when its effect would reach a pin late or never.

  3. Rule 3: Prefer documented inner interfaces.

    A grey-box probe on a stable, named interface gives early sight with less fragility.

  4. Rule 4: Every internal name a check uses is a dependency.

    When the design changes inside, those checks must change too.

Sources for These Rules

Mehta (2018), section 2.1.3: traditional debug starts from the effect at the outputs and traces back. An assertion inside points at the source. Section 6.2.2: assertions give black-box verification white-box observability.

Verification Academy UVM Cookbook, "Connections to DUT Interfaces": access to internal signals shapes the bench. It must be planned if white-box testing is needed. Its glossary defines white box as treating the DUT as semi-transparent.

The three names are common practice; companies draw the lines slightly differently.

The Lab: One Bug, Seen Twice

The lab's FIFO has a bug in its count register. When a push and a pop happen in the same clock, it adds 1 for the push and forgets the pop. The FIFO now believes it holds one more byte than it does.

The count update in this lab's fifo4. Both happening at once should leave count unchanged.
if (push && !full) count <= count + 1;   // forgets a pop in the same cycle
else if (pop && !empty) count <= count - 1;

Two checks watch the same run. The black-box check knows only the pins: each byte read must be the oldest byte written. The white-box check reaches inside with dut.count. The bench placed one copy of the FIFO and named it dut, so dut.count is the path to that copy's count register. It compares that with the number of bytes really held.

Printed by the lab (Icarus).
white box, cycle 4: dut.count is 4, but 3 bytes are held
black box, cycle 8: read 11, but the FIFO should be empty
end: white-box findings 4, black-box findings 1

The white-box line comes first, at cycle 4. The push and the pop happen together, and count says 4 while 3 bytes are held. Rule 2 at work: the bug is seen at its source, at the exact cycle. The black-box line comes at cycle 8, when the FIFO is really empty but believes it holds one byte. A read hands out a stale 11.

Both checks found the bug. The white-box one named the register and the cycle. The black-box one named only a wrong byte, four cycles later. In a bigger design the gap could be thousands of cycles. Or the wrong value could be masked and never reach a pin.

Why Most Checks Stay Outside

If white box finds bugs sooner, why not use it everywhere? Because the bench would be welded to one version of the design. Designs change inside all the time, for speed, area or power, without changing their specification. Every rename and restructure would break a white-box bench. A black-box bench would still pass.

There is also reuse. A black-box bench for this FIFO works on any FIFO with the same pins, from any designer. At chip level, the inside of a block may not even be visible, because the block arrived from another company.

Traps

The first trap is checking the implementation instead of the specification. A white-box check that says "count must equal what the RTL computes" only restates the RTL. Check internal values against what the bench itself knows, as the lab does.

The second trap is the hard-coded path. A bench full of dut.u_core.u_fifo.count paths fails to compile the day the hierarchy changes. Keep internal probes few, and gather them in one place.

The third trap is trusting a black-box pass too far. A wrong internal value can be masked by later logic in every test you ran. The pins look right today, and a different test shows the bug next month.

Where This Goes Next

This lesson chose where to look. These lessons teach the tools for each view.

Where each idea is taught in depth
The idea from this pageWhere it is taught
A rule pinned to a wire inside the designAssertions: Checks That Travel With the Design
Rules inside the design, written as assertionsWhy Assertions
Interfaces that give a bench its view of the pinsInterfaces and Modports
Black, grey and white box at chip levelWhere You May Look: Black, Grey and White Box
How a test decides it is overHow a Test Ends

Try It

Run the lab. Note the cycle of each first finding.

Fix the count update (both at once leave count unchanged). Predict the last line.

Remove the push-and-pop clock from the stimulus. Does either check still find the bug, and why?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: white box, cycle 4: dut.count is 4, but 3 bytes are held black box, cycle 8: read 11, but the FIFO should be empty end: white-box findings 4, black-box findings 1

Check Yourself

Predict the outputThe count update is fixed: a push and a pop together leave count unchanged. What is the last line printed?
// fifo4: a first-in first-out buffer, four entries deep. dout shows the oldest entry.
module fifo4 (input logic clk, rst, push, pop, input logic [7:0] din,
              output logic [7:0] dout, output logic full, empty);
  logic [7:0] mem [0:3];
  logic [1:0] wp, rp;           // write and read pointers
  logic [2:0] count;            // entries held
  assign full  = (count == 4);
  assign empty = (count == 0);
  assign dout  = mem[rp];
  always_ff @(posedge clk)
    if (rst) begin wp <= 0; rp <= 0; count <= 0; end
    else begin
      if (push && !full)  begin mem[wp] <= din; wp <= wp + 1; end
      if (pop  && !empty) rp <= rp + 1;
      count <= count + (push && !full) - (pop && !empty);
    end
endmodule

module tb;
  logic clk = 0, rst = 1, push = 0, pop = 0, full, empty;
  logic [7:0] din = 0, dout;
  int cycle = 0, held = 0, white = 0, black = 0;
  logic [7:0] model [$];
  fifo4 dut (.clk, .rst, .push, .pop, .din, .dout, .full, .empty);
  always #1 clk = ~clk;
  // At each clock edge, before the design moves: what the bench expects.
  always @(posedge clk) if (!rst) begin
    cycle++;
    // Black box: only the pins. A byte read must be the oldest byte written.
    if (pop && !empty) begin
      if (model.size() == 0 || dout !== model[0]) begin
        if (!black && model.size()) $display("black box, cycle %0d: read %h, expected %h", cycle, dout, model[0]);
        if (!black && !model.size()) $display("black box, cycle %0d: read %h, but the FIFO should be empty", cycle, dout);
        black++;
      end
      if (model.size()) void'(model.pop_front());
    end
    if (push && !full) model.push_back(din);
  end
  // White box: reach inside and compare the design's own count with the bytes really held.
  always @(negedge clk) if (!rst && dut.count != model.size()) begin
    if (!white) $display("white box, cycle %0d: dut.count is %0d, but %0d bytes are held", cycle, dut.count, model.size());
    white++;
  end
  initial begin
    @(negedge clk) rst = 0;
    // Write 11, 22, 33; then write 44 and read in the same cycle; then read until the FIFO says empty.
    push = 1; din = 8'h11; @(negedge clk); din = 8'h22; @(negedge clk); din = 8'h33; @(negedge clk);
    din = 8'h44; pop = 1; @(negedge clk);
    push = 0;
    repeat (6) @(negedge clk);
    pop = 0; @(negedge clk);
    $display("end: white-box findings %0d, black-box findings %0d", white, black);
    $finish;
  end
endmodule
ConceptWhat does a black-box check see?
ConceptWhy is a white-box check fragile?
ConceptIn the lab, why did the white-box check report first?
ConceptWhen is a grey-box probe the right choice?

Common Mistakes

Wrong Check every internal register by name.

Each rename or restructure breaks the bench, though the design still meets its specification.

Fix Check the pins first; add a few internal probes where bugs would hide.

Wrong Write a white-box check that restates the RTL.

It copies the designer's reading and can no longer disagree.

Fix Compare internal values with what the bench itself knows.

Wrong Assume a black-box pass means nothing is wrong inside.

A wrong internal value can be masked and never reach a pin in the tests run.

Fix Add inside checks where a bug could stay hidden, and measure what the tests reached.

Remember

  • Black box: pins only, checks the specification, survives redesign, sees bugs late or never.
  • White box: any internal signal, sees bugs at the source, breaks when the insides change.
  • Grey box: a few documented inner interfaces, a compromise between the two.
  • Good benches are black box at heart with a few inside probes where bugs would hide.

Practice

Report a problem with this page