The Specification and the Design Under Test

Every check needs a reference, and the first reference is the specification. Learn what a specification promises and what it leaves out. Draw the edge of the design under test, and treat an ambiguous sentence as the first bug.

You Will Be Able To

  • Say what a specification is and what it is not.
  • List the features, interfaces and corner cases a specification implies.
  • Mark the edge of a design under test: what a bench may drive and see.
  • Raise an ambiguity as a question before writing any test.
Lesson
B1.3
Time
20 min
Runs on
Your browser
Check
5 questions

Three engineers get the same two-line specification for a counter. Each builds it, each tests it, and each design passes its own tests. Put the three side by side and they disagree within ten clocks. Nobody wrote a bug, and yet two of them are wrong.

A Sentence, a Box, and the Gap BetweenStep through. The specification is words. The design under test is a box with pins. Everything between them is somebody's reading.
  • File
  • Neutral
  • Clock / reset
  • I/O
  • DUT
  • Analysis
  • Data
  • Clock
A Sentence, a Box, and the Gap BetweenStep through. The specification is words. The design under test is a box with pins. Everything between them is somebody's reading. file Specification "counts up whenenable is high; after9 back to 0" neutral A reading every clock? everypress? after 9 what? clock reset clk, rst input pins io en input pin dut Design under test counter io count[3:0] output pins readbuilddrivedriveobserve
  1. file Specification"counts up when enable is high; after 9 back to 0"
    • read → A reading
  2. neutral A readingevery clock? every press? after 9 what?
    • build → Design under test
  3. dut Design under testcounter
    • observe → count[3:0]
  4. clock reset clk, rstinput pins
    • drive → Design under test
  5. io eninput pin
    • drive → Design under test
  6. io count[3:0]output pins
  1. The words

    A specification says what the design must do, in human language.

  2. The reading

    Someone turns the words into behaviour. Two people can read the same sentence two ways.

  3. The box

    The design under test is what was built. A bench may drive its input pins and watch its output pins.

Read the diagram as text
  • Specification: "counts up when enable is high; after 9 back to 0"
  • A reading: every clock? every press? after 9 what?
  • clk, rst: input pins
  • en: input pin
  • Design under test: counter
  • count[3:0]: output pins
  • Specification → A reading: read
  • A reading → Design under test: build
  • clk, rst → Design under test: drive
  • en → Design under test: drive
  • Design under test → count[3:0]: observe

The specification of this lesson's counter, the box that was built from it, and the reading in between.

Before You Start

Read Verification, Validation and Test first: verification compares a design with its specification. You should know what a counter is; Modulo-N, Up/Down and Loadable Counters is a refresher.

Five questions this page answers
Question
1What does a specification promise, and what does it not say?
2What three kinds of statement should you pull out of a specification?
3What is the design under test, and where does it end?
4Why is an ambiguous sentence a bug?
5How can one sentence give three correct-looking designs?

The Idea: The Reference Has to Be Read

Verification compares a design with its specification. But a specification is written in human language, and human language is loose. Before anyone can check a design, someone has to read the words and decide what behaviour they mean.

The designer reads the specification and builds. The verification engineer reads the same words separately and checks. That second reading is the whole point: two people catch misreadings that one would keep. When the two readings disagree, the specification itself is often the cause.

So the first job of verification starts before any code. Pull out what the document promises, mark what it leaves open, and ask about every gap.

New Words

New words on this page
WordMeaning
Design under test (DUT)The design being checked. The bench drives its inputs and watches its outputs.
FeatureOne thing the design must do, such as "counts up" or "wraps after 9".
InterfaceThe pins of the DUT and the rules for using them: names, widths, timing.
Corner caseAn unusual input or moment where behaviour is easy to get wrong: a limit, a collision, a reset in the middle.
AmbiguityA sentence that can honestly be read in more than one way.
BoundaryThe edge of the DUT: what lies inside it, and what the bench supplies from outside.

What a Specification Promises

A specification says what the design must do, seen from its pins. It names the interfaces and the behaviour at them. A good one also says what must never happen. It is not the RTL, and it should not say how to build the logic.

Reading the counter's two lines
KindWhat the two lines giveWhat they leave open
Featurecounts up; goes back to 0 "after 9"after the value 9, or after nine counts?
Interfacean enable input and a count outputwidth of count; is there a reset, and is it synchronous?
Timing"when enable is high"once per clock while high, or once per press?
Corner casenone statedenable low: hold? reset while counting? enable high for a long time?

Two short lines leave six questions. That is normal. A verification engineer writes each question down and gets an answer from the person who owns the specification. The answer goes into the document, so the next reader does not need to ask.

The Boundary of the DUT

The design under test is a box. Its pins are the only things a bench can touch: it drives the inputs and watches the outputs. Everything the DUT needs from outside is the bench's job. That includes clock, reset and stimulus (the input values it applies), plus models of any neighbours.

Drawing that edge is a decision. Test the counter alone, and the bench drives en directly. Test it inside a bigger block, and en comes from other logic you do not control. Same counter, different edge, different checks. Later lessons look inside the box. For now, the box is closed and only its pins count.

The Rules

  1. Rule 1: A specification says what, at the pins.

    It is the reference for verification, so its gaps become gaps in every check.

  2. Rule 2: Pull out features, interfaces and corner cases.

    Each becomes a question, then a check.

  3. Rule 3: An ambiguity is the first bug.

    Raise it with whoever owns the specification and get the answer written into the document.

  4. Rule 4: Never resolve a question by reading the RTL.

    That copies the designer's reading into the check, and the check can no longer disagree.

  5. Rule 5: Draw the DUT boundary first.

    Decide what the bench drives, what it watches, and what lies outside.

Sources for These Rules

Spear and Tumbush (2012), section 1.1: a specification can be ambiguous, incomplete or conflicting. The designer interprets it, and the verifier reads it separately. Section 1.1.1: two designers reading one description differently at a block boundary.

Spear and Tumbush (2012), section 1.9: the testbench wraps around the DUT and supplies its stimulus.

Mehta (2018), section 15.2.1: the design specification follows the product requirements. Section 15.5.1: the test plan is formed from it.

The Lab: One Sentence, Three Counters

The lab builds the counter three times. Each module matches the two lines as one engineer read them. Reading 1 counts on every clock while enable is high and wraps after the value 9. Reading 2 takes "after 9" to mean "after nine counts", so it wraps after 8. Reading 3 counts once each time enable goes high, like a button counter.

Reading 3: it remembers the last value of en and counts only when en has just gone high.
en_was <= en;
if (en && !en_was) count <= (count == 9) ? 0 : count + 1;

The <= arrow updates a flip-flop at the clock edge. The ? : picks between two values: 0 if count is 9, otherwise count + 1. All three designs get the same enable pattern: high for 13 clocks, low for 2, then high again.

Printed by the lab (Icarus). Each number is the count after that clock.
enable    : 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1
reading 1 : 1 2 3 4 5 6 7 8 9 0 1 2 3 3 3 4
reading 2 : 1 2 3 4 5 6 7 8 0 1 2 3 4 4 4 5
reading 3 : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2
final     : reading 1 = 4, reading 2 = 5, reading 3 = 2
Three Readings, Same Enable
0123456789101112131415enreading 112345678901234reading 212345678012345reading 312reading 2 wrapsreading 1 wrapsen rises again
Scroll horizontally ↔

One column per clock, recorded from the lab on Icarus. Each count is the value after that clock.

Read the rows side by side. Reading 1 goes 8, 9, 0. Reading 2 goes 7, 8, 0, a clock earlier. Reading 3 counts once and then waits, because enable stayed high. It counts again only when enable rises at the end. The last row shows three different answers: 4, 5 and 2.

Each design is a faithful reading of the same two lines. A test written by its own author passes. Only a check against an agreed reading can tell which one the product needs, so rule 3 comes first.

Traps

The first trap is the obvious reading. Each engineer was sure the sentence meant one thing. Ambiguity is invisible to the person who reads it one way. That is why the question list is written down and sent, not kept in your head.

The second trap is asking the designer and taking their answer as the specification. The designer has already built one reading. Ask whoever owns the specification, and have the answer added to it.

The third trap is the missing sentence. Nothing in the two lines says what happens at reset, or with enable low. Silence is also ambiguity. The corner-case row of the table is where most real bugs live.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. A real specification runs to hundreds of pages.

  1. Review meetings

    Designers, verification engineers and architects read the specification together and log every question.

  2. From questions to a plan

    Each answered feature becomes rows of a verification plan: what to drive, what to check, how to know it was covered.

Where This Goes Next

This lesson read the reference. These lessons turn it into checks.

Where each idea is taught in depth
The idea from this pageWhere it is taught
Writing a self-checking test against the agreed readingThe Simplest Test That Can Fail
Finding corner cases on purposeCorner Cases and How to Think of Them
A specification turned into rules and a test plan, for a FIFOStart From the FIFO Rules
Writing a specification's rules as checks that run on every clockAn Assertion Plan
A chip specification that is data, not proseThe Specification Is Data

Try It

Run the lab and compare the three rows clock by clock.

Hold enable high for 10 clocks (change the pattern to ten 1s). Predict the last line.

Make enable alternate 1, 0, 1, 0. Which readings agree now, and why?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: enable : 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 reading 1 : 1 2 3 4 5 6 7 8 9 0 1 2 3 3 3 4 reading 2 : 1 2 3 4 5 6 7 8 0 1 2 3 4 4 4 5 reading 3 : 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 final : reading 1 = 4, reading 2 = 5, reading 3 = 2

Check Yourself

Predict the outputThe same three counters get enable held high for exactly 10 clocks. What is the last line the lab prints?
// The specification, all of it: "The counter counts up when enable is high. After 9 it goes back to 0."
// Three engineers built it. Each design matches the sentence as that engineer read it.
module reading1 (input logic clk, rst, en, output logic [3:0] count);   // up on every clock while en is high
  always_ff @(posedge clk)
    if (rst) count <= 0;
    else if (en) count <= (count == 9) ? 0 : count + 1;
endmodule
module reading2 (input logic clk, rst, en, output logic [3:0] count);   // "after 9" read as "after nine counts"
  always_ff @(posedge clk)
    if (rst) count <= 0;
    else if (en) count <= (count == 8) ? 0 : count + 1;
endmodule
module reading3 (input logic clk, rst, en, output logic [3:0] count);   // up once each time en goes high
  logic en_was;
  always_ff @(posedge clk)
    if (rst) begin count <= 0; en_was <= 0; end
    else begin
      en_was <= en;
      if (en && !en_was) count <= (count == 9) ? 0 : count + 1;
    end
endmodule

module tb;
  logic clk = 0, rst = 1, en = 0;
  logic [3:0] c1, c2, c3;
  string s1 = "", s2 = "", s3 = "";
  bit [9:0] pattern = 10'b1111111111;
  reading1 r1 (.clk, .rst, .en, .count(c1));
  reading2 r2 (.clk, .rst, .en, .count(c2));
  reading3 r3 (.clk, .rst, .en, .count(c3));
  always #1 clk = ~clk;
  initial begin
    @(negedge clk) rst = 0;
    for (int i = 9; i >= 0; i--) begin
      en = pattern[i];
      @(negedge clk);
      s1 = {s1, $sformatf("%0d ", c1)}; s2 = {s2, $sformatf("%0d ", c2)}; s3 = {s3, $sformatf("%0d ", c3)};
    end
    $display("enable    : 1 1 1 1 1 1 1 1 1 1");
    $display("reading 1 : %s", s1);
    $display("reading 2 : %s", s2);
    $display("reading 3 : %s", s3);
    $display("final     : reading 1 = %0d, reading 2 = %0d, reading 3 = %0d", c1, c2, c3);
    $finish;
  end
endmodule
ConceptWhat does a specification describe?
ConceptWhich of these is a corner case of the counter?
ConceptWhy should a verification engineer not settle an ambiguity by reading the RTL?
ConceptIn the lab, why do all three counters "pass" if each is tested by its own author?

Common Mistakes

Wrong Pick the reading that seems obvious and start testing.

An ambiguity is invisible to whoever reads it one way, so the test may check the wrong behaviour.

Fix Write down every open question and get answers from the owner of the specification.

Wrong Read the RTL to find out what the specification meant.

The check then copies the designer's reading and cannot disagree with it.

Fix Resolve the meaning from the specification and its owner, independently of the code.

Wrong Ignore what the specification does not mention.

Reset, limits and collisions are where bugs hide, and silence is ambiguity too.

Fix List the corner cases the specification implies and ask about each one.

Remember

  • A specification says what the design must do at its pins; it is the reference for verification.
  • Pull out features, interfaces and corner cases, and turn each gap into a written question.
  • An ambiguity is the first bug: one sentence can give several correct-looking designs.
  • The DUT is a box; the bench drives its inputs, watches its outputs and supplies everything outside.

Practice

Report a problem with this page