Where the Right Answer Comes From

A check is only as good as its expected value. Meet the ways a bench can know the right answer: constants, a reference model and rules. Add a scoreboard to hold answers that arrive later. Learn what each costs and what each cannot see.

You Will Be Able To

  • Name four ways a bench can know the right answer.
  • Give the cost and the blind spot of each.
  • Choose a source of truth for a given check.
Lesson
B2.3
Time
20 min
Runs on
Your browser
Check
5 questions

Four hand-written checks pass, a rule reports twelve failures, and a second model of the adder reports twenty-four. All three looked at the same broken adder. Which one is telling the truth?

Three Sources of Truth, and a Place to Keep AnswersStep through the ways a bench can know the right answer. Each is cheap somewhere and blind somewhere else.
  • File
  • Model
  • Test
  • Scoreboard
  • DUT
  • Result
  • Analysis
  • Data
Three Sources of Truth, and a Place to Keep AnswersStep through the ways a bench can know the right answer. Each is cheap somewhere and blind somewhere else. file Constant "3 + 4 must be 7",written by hand model Reference model a second, simplerdescription test Rule a fact that mustalways hold scoreboard Scoreboard keeps expectedanswers until the realones arrive dut Design under test adder4 result Compare right or wrong a few casesevery casein orderone propertyactual
  1. file Constant"3 + 4 must be 7", written by hand
    • a few cases → Compare
  2. result Compareright or wrong
  3. model Reference modela second, simpler description
    • every case → Scoreboard
  4. scoreboard Scoreboardkeeps expected answers until the real ones arrive
    • in order → Compare
  5. test Rulea fact that must always hold
    • one property → Compare
  6. dut Design under testadder4
    • actual → Compare
  1. A constant

    Someone works out the answer by hand. Cheap and clear, but it covers only the cases written down.

  2. A reference model

    A second description of the same behaviour computes the answer for any input.

  3. A scoreboard

    When answers come out later, or in bursts, the expected ones wait in a scoreboard until they can be matched.

  4. A rule

    Some facts must always hold, whatever the inputs. A rule checks one such fact and nothing more.

Read the diagram as text
  • Constant: "3 + 4 must be 7", written by hand
  • Reference model: a second, simpler description
  • Rule: a fact that must always hold
  • Scoreboard: keeps expected answers until the real ones arrive
  • Design under test: adder4
  • Compare: right or wrong
  • Constant → Compare: a few cases
  • Reference model → Scoreboard: every case
  • Scoreboard → Compare: in order
  • Rule → Compare: one property
  • Design under test → Compare: actual

Where an expected value can come from. Real benches use several at once.

Before You Start

Read The Simplest Test That Can Fail first. It showed that the expected value must be worked out apart from the design. The Parts of a Testbench named the checker. This lesson is about what it compares with.

Five questions this page answers
Question
1What are the ways a bench can know the right answer?
2What does each one cost to build?
3What can each one never see?
4When do you need a scoreboard?
5Why do real benches use several at once?

The Idea: Every Check Borrows Its Truth

A checker compares the design with an expected value, so the expected value is the truth of the check. If it is wrong, or missing for some inputs, the check is wrong or missing too. Where that truth comes from is a design decision with costs.

There are three basic sources. You can write the answer down by hand, as a constant. You can build a second, simpler description that computes the answer: a reference model. Or you can state a fact that must always hold: a rule. One example is "the low bit of a sum is the XOR of the low bits".

A fourth piece is not a source but a store. When a design answers later, or several answers are in flight, the expected values must wait somewhere until the real ones arrive. That store is a scoreboard.

New Words

New words on this page
WordMeaning
Reference modelA second, simpler description of the design's behaviour, used to compute expected values.
RuleA fact about the outputs that must always hold, checked on its own. An assertion is a rule written in the language.
AssertionA rule written into the code, checked by the simulator every time it applies.
ScoreboardA store that keeps expected results until the design's real results arrive, then matches them.
Blind spotThe kinds of bug a check can never see, whatever the design does.

Cost and Blind Spot of Each

Four ways to know the answer
WayCostsCannot see
ConstantAlmost nothing per caseEvery case nobody wrote down; a wrong hand calculation
Reference modelA second design to write and maintainA misreading of the specification it shares with the design
RuleOne line per factAny wrong value that still obeys the rule
ScoreboardStorage and matching logicNothing by itself: it is only as good as the model feeding it

No row is free of blind spots. That is why real benches combine them. A model with a scoreboard handles the bulk. Rules guard local facts that must never break. A few constants give cases a reader can check by hand.

A model that shares the designer's misreading is the most dangerous blind spot. If one person writes both from the same notes, both can be wrong in the same way and agree perfectly. That is the second reading of the specification at work again.

The Rules

  1. Rule 1: The expected value is the truth of a check.

    A check cannot be better than where its answer comes from.

  2. Rule 2: Constants cover only what was written down.

    They are clear and cheap, and blind to every other case.

  3. Rule 3: A reference model covers every input it is given.

    It costs a second design, and must be written from the specification, not the RTL.

  4. Rule 4: A rule checks one fact, everywhere.

    It points at the place the fact broke, and misses wrong values that obey it.

  5. Rule 5: A scoreboard holds answers across time.

    Use one when results come out later, or several are in flight.

Sources for These Rules

Spear and Tumbush (2012), section 1.5: automatic stimulus needs an automatic prediction, generally a scoreboard or a reference model. Section 1.6: the stimulus also goes to a high-level model that predicts the result.

Spear and Tumbush (2012), section 1.10.2: assertions look at signals across a command. Section 1.10.3: the scoreboard predicts results and the checker compares them with the monitor.

Mehta (2018), section 2.1.3: an assertion points at the source of a failure instead of its effect at the outputs.

The Lab: One Adder, Three Truths

The lab checks the buggy adder of the first lesson three ways at once. The reference model is one line: in the bench, i + j is computed by the simulator, not by the adder. Two rules check facts that must hold for every pair. Four constants are written by hand.

Inside the loop over all 256 pairs: one model compare and two rules.
if ({cout, sum} !== i + j) m_wrong++;          // reference model
if (sum[0] !== (a[0] ^ b[0])) r1++;            // rule: the low bit
if (!cout && sum < a) r2++;                    // rule: never smaller

The ^ is XOR. !cout means "no carry out". Each line adds 1 to its own count when its truth disagrees with the adder.

Printed by the lab (Icarus).
reference model: 24 of 256 sums wrong
rule "low bit": 0 violations
rule "never smaller": 12 violations
constants: 0 of 4 hand-written cases wrong

The reference model finds all 24 wrong sums: rule 3 at work, since it was given every input. The low-bit rule finds none, because the bug is in bit 3 and bit 0 is always right. The "never smaller" rule finds 12: the wrong sums that came out smaller than a. The other 12 wrong sums are still not smaller than a, so they obey it. That is rule 4's blind spot.

The constants find nothing. The pairs 1 + 1, 3 + 4, 9 + 6 and 15 + 1 never set up the bug. So rule 2 applies: four right answers, and silence about the other 252 pairs.

Why Rules Are Still Worth Writing

If a model finds everything, why write rules? Because a model tells you that an output is wrong, often many cycles after the cause. A rule placed inside the design fires where and when the fact breaks. Debug starts at the cause instead of tracing back from the output.

Rules are also cheap to add and hard to get wrong. A model is a second design and can have its own bugs. Most benches use a model for the answers and rules for the facts that must never break.

Traps

The first trap is a model copied from the RTL. It is quicker to write the model by reading the design's code. Then every misreading in the design is in the model too, and they agree. Write the model from the specification.

The second trap is a scoreboard that never empties. Expected answers wait for real ones; if the design drops one, its expected value waits for ever. At the end of a test, anything still in the scoreboard is an error. How a Test Ends comes back to it.

The third trap is believing a rule's silence. A rule that never fails may never have applied. A rule about a full FIFO says nothing in a run where the FIFO never filled.

Where This Goes Next

This lesson chose a source of truth. These lessons build each one.

Where each idea is taught in depth
The idea from this pageWhere it is taught
A rule checked at every clock edge, as an assertionAssertions: Checks That Travel With the Design
Writing rules as assertionsWhy Assertions
Building a scoreboard for a FIFOBuild the Monitor and Scoreboard
Queues, the usual store inside a scoreboardQueues and Ordering
Scoreboard accounting at the end of a test, in UVMScoreboard Accounting and Drain Checks
How far inside the design a check may lookBlack Box, Grey Box, White Box

Try It

Run the lab and compare the four counts.

Replace the hand-written case 3 + 4 with 3 + 5. Predict the constants line.

Write a third rule of your own, such as "a + 0 is a". Does it catch the bug?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: reference model: 24 of 256 sums wrong rule "low bit": 0 violations rule "never smaller": 12 violations constants: 0 of 4 hand-written cases wrong

Check Yourself

Predict the outputThe hand-written cases are now 1 + 1 = 2 and 3 + 5 = 8. What is the last line printed?
// adder4: a 4-bit adder, written one bit at a time (a ripple-carry adder).
module adder4 (input logic [3:0] a, b, output logic [3:0] sum, output logic cout);
  logic c1, c2, c3;
  assign sum[0] = a[0] ^ b[0];
  assign c1     = a[0] & b[0];
  assign sum[1] = a[1] ^ b[1] ^ c1;
  assign c2     = (a[1] & b[1]) | (a[1] & c1) | (b[1] & c1);
  assign sum[2] = a[2] ^ b[2] ^ c2;
  assign c3     = (a[2] & b[2]) | (a[2] & c2);           // one term is missing
  assign sum[3] = a[3] ^ b[3] ^ c3;
  assign cout   = (a[3] & b[3]) | (a[3] & c3) | (b[3] & c3);
endmodule

module tb;
  logic [3:0] a, b, sum;
  logic cout;
  int t_wrong = 0, m_wrong = 0, r1 = 0, r2 = 0;
  adder4 dut (.a, .b, .sum, .cout);
  initial begin
    for (int i = 0; i < 16; i++)
      for (int j = 0; j < 16; j++) begin
        a = i; b = j; #1;
        // 2. A reference model: a second, simpler description that computes every answer.
        //    (The constants of way 1 are checked at the end.)
        if ({cout, sum} !== i + j) m_wrong++;
        // 3. Rules: facts that must always hold, whatever the inputs.
        if (sum[0] !== (a[0] ^ b[0])) r1++;          // the low bit is a[0] xor b[0]
        if (!cout && sum < a) r2++;                   // with no carry out, the sum is never smaller than a
      end
    $display("reference model: %0d of 256 sums wrong", m_wrong);
    $display("rule \"low bit\": %0d violations", r1);
    $display("rule \"never smaller\": %0d violations", r2);
    // 1. Constants: answers written down by hand for a few cases.
    a = 1; b = 1; #1 if ({cout, sum} !== 2) t_wrong++;
    a = 3; b = 5; #1 if ({cout, sum} !== 8) t_wrong++;
    $display("constants: %0d of 2 hand-written cases wrong", t_wrong);
  end
endmodule
ConceptWhat is the blind spot of a reference model?
ConceptWhen does a bench need a scoreboard?
ConceptIn the lab, why did the "never smaller" rule find only 12 of the 24 wrong sums?
ConceptWhy are rules worth writing even when a model finds every wrong output?

Common Mistakes

Wrong Write the reference model by reading the RTL.

The model inherits the design's misreadings, and the two agree when both are wrong.

Fix Write the model from the specification, ideally by someone other than the designer.

Wrong Rely on a few hand-written expected values.

They cover only the cases written down; the bug may need another one.

Fix Use a model for the bulk of cases and keep constants for hand-checkable examples.

Wrong Treat a rule that never fails as proof.

A rule checks one fact, and only when its situation happens.

Fix Combine rules with a model, and check that each rule's situation was reached.

Remember

  • The expected value is the truth of a check; a check is never better than its source.
  • Constants are cheap and cover only what was written; a model covers every input but costs a second design.
  • Rules check one fact everywhere and miss wrong values that obey it; a scoreboard stores answers across time.
  • Real benches combine them, and write models from the specification, not the RTL.

Practice

Report a problem with this page