clkabcinscoutcout exp✓000✓001✓010✗011✓000✓001✓010✓011✓100✓101✓110✓111✓101✓010✓101✓111✓000✓010✓001✓011✓100✓110a b cin s cout0 0 0 0 00 0 1 1 00 1 0 1 00 1 1 0 11 0 0 1 01 0 1 0 11 1 0 0 11 1 1 1 1abcinscoutclk01TB010101ADDER0101CHECK00000010010001101000101011001110000000000
Lit wire with moving dashes: it carries a 1Tokens: a test vector going in, the result and the expected answer going to the checkerWaveforms: each signal against time, ✓ passed, ✗ and red band = mismatchCoverage boxes: how many times each input case was triedThe testbench reads each test vector, drives it onto the full adder's inputs on a rising clock edge and checks the outputs against the expected ones on the falling edge. The waveform screen draws every signal against time; a red band marks the vector where the adder's cout and the expected cout disagree. The coverage boxes count how often each input case was tried. Delays such as #5, $display and the value change dump (VCD) files that waveform viewers read are part of Verilog, IEEE Std 1364. Immediate assertions, constrained random stimulus and covergroups are part of SystemVerilog, IEEE Std 1800. Intel announced a pre-tax charge of US$475 million on 17 January 1995 to replace Pentium chips with the FDIV division bug, caused by missing entries in a lookup table.

Test before you build

  1. Making a chip takes months, and a wrong transistor cannot be patched later. So designers first simulate: a program, the simulator, runs the HDL (hardware description language) design on an ordinary computer and works out every signal, step by step.

The testbench

Waveforms and bugs

How much to test

What the simulator does

;; step 1/11 · why-simulate
;; about: Design under test
HDL design (Verilog)
   │  simulator
   ▼
every signal, worked out in software

found a bug?  edit the code, run again
             (minutes, not months)

The clock, the vector file and the rising-edge apply / falling-edge check pattern follow the self-checking testbench in Harris and Harris, Digital Design and Computer Architecture (2nd ed.), section 4.9. In Python, ^ and & on the numbers 0 and 1 are XOR and AND, and assert raises an AssertionError when its condition is false. The cocotb library lets you write testbenches like this in Python for real Verilog simulators.