I need to implement the testbench for the 4 flipflops module that are in the design.sv interface. The modules foo1, foo2 and bar2 are working properly (you can see this when you run, the expected values are the same as the output values) except the bar1. I don't know why this is happening. https://www.edaplayground.com/x/XaWu
//testbench for the bar1 flip flop.
module general_tb3 (
);
logic a, b, c, clk;
logic x, y, w;
bar1 uut(a, b, c, clk, x, y, w);
initial
begin
$dumpfile("dump.vcd");
$dumpvars(1);
end
function logic output_x3;
input a, b;
begin
output_x3 <= a | b;
end
endfunction
function logic output_y3;
input a, b, c;
begin
output_y3 <= ~((a | b) & c);
end
endfunction
function logic output_w3;
input a, b, c;
begin
output_w3 <= a | ~((a | b) & c);
end
endfunction
// Seção de testes com atribuição de valores para f e f_expected
initial
begin
#10000 $display("\nBar1 tests");
#10000 $display ("| a | b | c | clk | x | y | w | x_expected | y_expected| w_expected|");
a = 0; b = 0; c = 0; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 0), output_y3(0, 0, 0), output_w3(0, 0, 0) );
a = 0; b = 0; c = 0; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 0), output_y3(0, 0, 0), output_w3(0, 0, 0) );
a = 0; b = 0; c = 1; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 0), output_y3(0, 0, 1), output_w3(0, 0, 1) );
a = 0; b = 0; c = 1; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 0), output_y3(0, 0, 1), output_w3(0, 0, 1) );
a = 0; b = 1; c = 0; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 0), output_y3(0, 1, 0), output_w3(0, 1, 0) );
a = 0; b = 1; c = 0; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 1), output_y3(0, 1, 0), output_w3(0, 1, 0) );
a = 0; b = 1; c = 1; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 1), output_y3(0, 1, 1), output_w3(0, 1, 1) );
a = 0; b = 1; c = 1; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(0, 1), output_y3(0, 1, 1), output_w3(0, 1, 1) );
a = 1; b = 0; c = 0; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 0), output_y3(1, 0, 0), output_w3(1, 0, 0) );
a = 1; b = 0; c = 0; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 0), output_y3(1, 0, 0), output_w3(1, 0, 0) );
a = 1; b = 0; c = 1; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 0), output_y3(1, 0, 1), output_w3(1, 0, 1) );
a = 1; b = 0; c = 1; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 0), output_y3(1, 0, 1), output_w3(1, 0, 1) );
a = 1; b = 1; c = 0; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 1), output_y3(1, 1, 0), output_w3(1, 1, 0) );
a = 1; b = 1; c = 0; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 1), output_y3(1, 1, 0), output_w3(1, 1, 0) );
a = 1; b = 1; c = 1; clk = 0;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 1), output_y3(1, 1, 1), output_w3(1, 1, 1) );
a = 1; b = 1; c = 1; clk = 1;
#10000 $display("| %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h | %0h |", a, b, c, clk, x, y, w, output_x3(1, 1), output_y3(1, 1, 1), output_w3(1, 1, 1) );
end
endmodule
Design for this flip flop:
module bar1 (a, b, c, clk, x, y, w);
input a, b, c, clk;
output reg x, y, w;
always @(negedge clk)
begin
x <= a | b;
y <= ~(x & c);
w <= a | y;
end
endmodule
OUTPUTS:
# KERNEL: Bar1 tests
# KERNEL: | a | b | c | clk | x | y | w | x_expected | y_expected| w_expected|
# KERNEL: | 0 | 0 | 0 | 0 | 0 | 1 | x | x | x | x |
# KERNEL: | 0 | 0 | 0 | 1 | 0 | 1 | x | 0 | 1 | 1 |
# KERNEL: | 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 |
# KERNEL: | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
# KERNEL: | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | 1 | 1 |
# KERNEL: | 0 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 |
# KERNEL: | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
# KERNEL: | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 |
# KERNEL: | 1 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
# KERNEL: | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
# KERNEL: | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
# KERNEL: | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
# KERNEL: | 1 | 1 | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 |
# KERNEL: | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
# KERNEL: | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 1 |
# KERNEL: | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
Consider this testbench design.
Create the clock separate from the other input signals. Then, drive everything on the edge of a clock.
Use a
forloop to drive your other inputs.Model your design using the
x_expsignal. This is generated with the same timing as the designxsignal.Use the opposite edge of the clock to display all the values; this avoids race conditions.
You can add expected values for
yandw.Here is the output:
To get rid of unknown values at the start of simulation, you could use a reset signal for your design.