Professional Documents
Culture Documents
14 Verilog Testbenches
14 Verilog Testbenches
Adapted from Digital Design and Computer Architecture, David Money Harris & Sarah L. Harris 2007 Elsevier
Carnegie Mellon
Applying inputs
Carnegie Mellon
Carnegie Mellon
Carnegie Mellon
Testbenches
Not synthesizeable
Types of testbenches:
Simple testbench
Self-checking testbench
Self-checking testbench with testvectors
Carnegie Mellon
Example
Carnegie Mellon
Example
module sillyfunction(input a, b, c,
output y);
assign y = ~b & ~c | a & ~b;
endmodule
Carnegie Mellon
Simple Testbench
module testbench1(); // Testbench has no inputs, outputs
reg a, b, c;
// Will be assigned in initial block
wire y;
one at a time
//
c = 0; #10; //
//
#10;
//
sequential block
apply inputs, wait 10ns
apply inputs, wait 10ns
etc .. etc..
c = 0; #10;
Carnegie Mellon
Simple Testbench
Carnegie Mellon
Self-checking Testbench
module testbench2();
reg a, b, c;
wire y;
// instantiate device under test
sillyfunction dut(.a(a), .b(b), .c(c), .y(y));
// apply inputs one at a time
initial begin
a = 0; b = 0; c = 0; #10; // apply input, wait
if (y !== 1) $display("000 failed."); // check
c = 1; #10;
// apply input, wait
if (y !== 0) $display("001 failed."); // check
b = 1; c = 0; #10;
// etc.. etc..
if (y !== 0) $display("010 failed."); // check
end
endmodule
10
Carnegie Mellon
Self-checking Testbench
Carnegie Mellon
Testbench:
12
Carnegie Mellon
HOLD MARGIN
Apply inputs
after some
delay from the
clock
SETUP
MARGIN
Check outputs
before the next
clock edge
Carnegie Mellon
Testvectors File
14
Carnegie Mellon
15
Carnegie Mellon
initial
// Will execute at the beginning once
begin
$readmemb("example.tv", testvectors); // Read vectors
vectornum = 0; errors = 0;
// Initialize
reset = 1; #27; reset = 0;
// Apply reset wait
end
16
Carnegie Mellon
This is important
Inputs should not change at the same time with clock
17
Carnegie Mellon
18
Carnegie Mellon
19
Carnegie Mellon
Golden Models
20
Carnegie Mellon
Carnegie Mellon
22