Inverter: Self-Checking Testbench
module inv_tb();
logic data_in;
logic data_out;
logic data_out_expected;
logic errors = 0;
inv not_dut(.a(data_in), .q(data_out));
initial begin
$dumpfile("inv_tb.vcd");
$dumpvars(0, inv_tb);
data_out_expected = 1;
data_in = 0; #1;
$write("data_in: %b, ", data_in);
$display("data_out: %b", data_out);
if (data_out !== data_out_expected) begin
errors = 1;
$display("Error: input = %b, output = %b (expected: %b)",
data_in, data_out, data_out_expected);
end
data_out_expected = 0;
data_in = 1; #1;
$write("data_in: %b, ", data_in);
$display("data_out: %b", data_out);
if (data_out !== data_out_expected) begin
errors = 1;
$display("Error: input = %b, output = %b (expected: %b)",
data_in, data_out, data_out_expected);
end
$display("Tests: %s", errors ? "FAILED!" : "passed.");
$finish;
end
endmodule
69