RTLLM-verified / Memory /Shifter /LFSR /testbench.v
suryagunukula's picture
Initial release
035592e
Raw History Blame Contribute Delete
2.06 kB
module lfsr_tb();
reg clk_tb;
reg rst_tb;
wire [3:0] out_tb;
reg hard_orig_ok;
reg [3:0] hard_prev;
integer hard_err = 0;
LFSR DUT(
.out(out_tb),
.clk(clk_tb),
.rst(rst_tb)
);
initial
begin
clk_tb = 0;
rst_tb = 1;
#15;
rst_tb = 0;
#200;
// $display("Failed: out=%b (expected 1101)", out_tb);
hard_orig_ok = (out_tb == 4'b1101);
// additional check (clk rises at 5, 15, ..., 215, 225, ...): every-cycle sequence, then a mid-run reset.
#3; // t=218, mid-cycle
hard_prev = out_tb;
repeat (20) begin
#10; // one rising edge later
if (out_tb !== {hard_prev[2:0], ~(hard_prev[3] ^ hard_prev[2])}) begin
hard_err = hard_err + 1;
$display("HARD %0t: out=%b after %b (expected %b)", $time, out_tb, hard_prev, {hard_prev[2:0], ~(hard_prev[3] ^ hard_prev[2])});
end
hard_prev = out_tb;
end
rst_tb = 1; // t=418: rst high across the edges at 425 and 435
#10;
if (out_tb !== 4'b0000) begin hard_err = hard_err + 1; $display("HARD %0t: out=%b after an edge with rst=1 (expected 0000)", $time, out_tb); end
#10;
if (out_tb !== 4'b0000) begin hard_err = hard_err + 1; $display("HARD %0t: out=%b while rst=1 (expected 0000)", $time, out_tb); end
#2 rst_tb = 0; // t=440, mid-cycle
#8; // t=448
hard_prev = 4'b0000;
repeat (16) begin
hard_prev = {hard_prev[2:0], ~(hard_prev[3] ^ hard_prev[2])};
if (out_tb !== hard_prev) begin
hard_err = hard_err + 1;
$display("HARD %0t: out=%b after reset (expected %b)", $time, out_tb, hard_prev);
end
#10;
end
if (hard_orig_ok && hard_err == 0) begin
$display("=========== Your Design Passed ===========");
end
else begin
$display("=========== Failed ===========");
end
$finish;
end
always
begin
#5;
clk_tb = ~ clk_tb;
end
endmodule