What is Testbench?
Simulation-only code that drives inputs to the design under test and checks its outputs. Since it is never synthesized, delays, display statements and similar can be used freely.
Japanese name: テストベンチ
Simulation-only code that drives inputs to the design under test and checks its outputs. Since it is never synthesized, delays, display statements and similar can be used freely.
Japanese name: テストベンチ
A testbench is a top-level HDL module, usually without ports, that instantiates the design under test (DUT) and surrounds it with everything needed to exercise it. It generates the clock, for example always #5 clk = ~clk; which toggles every 5 time units and gives a 10 ns period with a 1 ns unit, applies reset, drives input stimulus, and observes the outputs. It may also read test vectors from files, write logs and dump waveforms. The DUT is the synthesizable design; the testbench exists only in simulation.
Because a testbench is never synthesized, it can use features that have no hardware meaning. Delay statements such as #10 advance simulation time, $display and file I/O print or record values, and the case-equality operator === compares X and Z bits literally, which lets a test detect an output that has become unknown. Synthesis ignores or rejects these constructs, so they must stay out of RTL. If they leak into the design code, simulation and hardware behavior can diverge in ways that are hard to debug.
A common testbench bug is changing a DUT input with a blocking assignment at exactly the same simulation time as the rising clock edge. Whether the DUT flip-flops capture the old or new value then depends on the order in which the simulator executes events, a race whose result can even differ between simulators. Safer practice is to drive inputs on the opposite clock edge or a little after the active edge, to use nonblocking assignments, or to use SystemVerilog clocking blocks, which define sampling and driving times explicitly.
For a small block, inspecting waveforms by eye may be enough, but this does not scale. A self-checking testbench computes or looks up the expected result for each input, often with a reference model, compares it automatically with the DUT output and reports mismatches as errors. Thousands of tests can then run unattended, for example overnight in regression. Larger projects build on this with constrained-random stimulus, scoreboards and coverage collection, and verification effort often matches or exceeds design effort.
Answer: B. A simulation-only description that drives inputs to the circuit under test and checks whether outputs are correct; it is not synthesized
A testbench is HDL code that instantiates the design under test (DUT), generates clocks, resets and input signals, and observes outputs. Because it is never synthesized, it can freely use simulation-only features such as delays, file I/O and display statements. It sometimes takes as much effort as the design itself, or more.
Answer: A. Whether the design captures the old or new value depends on execution order (a race); change inputs away from the clock edge or with nonblocking assignments
When the testbench updates an input at the same instant the design's flip-flops sample it, the captured value can be old or new depending on which the simulator executes first. This is a simulation race, and results may even differ between simulators. It is prevented by changing inputs on the falling edge or slightly after the edge, or by using nonblocking assignments or SystemVerilog clocking blocks.
No. A testbench is written only for simulation, so it freely uses delays, display statements, file I/O and other constructs that cannot become hardware.
DUT stands for design under test, the synthesizable module that the testbench instantiates, drives with stimulus and checks.
The == operator returns X when X or Z bits in either operand leave it undecided whether the operands match. The === operator compares X and Z literally and always returns 0 or 1, so testbenches use it to detect unknown outputs.
Testbench appears in 7 practice questions across 1 topic, including HDL & Verification.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.