data/full_repos/permissive/494148647/src/util/debounce_tb.v
1: b'%Warning-STMTDLY: data/full_repos/permissive/494148647/src/util/debounce_tb.v:40: Unsupported: Ignoring delay on this delayed statement.\n        forever #10 clk = ~clk;\n                ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Error: data/full_repos/permissive/494148647/src/util/debounce_tb.v:59: Unsupported or unknown PLI call: $dumpfile\n        $dumpfile("debounce_tb.vcd");\n        ^~~~~~~~~\n%Error: data/full_repos/permissive/494148647/src/util/debounce_tb.v:60: Unsupported or unknown PLI call: $dumpvars\n        $dumpvars(1, debounce_tb);\n        ^~~~~~~~~\n%Warning-STMTDLY: data/full_repos/permissive/494148647/src/util/debounce_tb.v:64: Unsupported: Ignoring delay on this delayed statement.\n        #1e6;\n        ^\n%Warning-STMTDLY: data/full_repos/permissive/494148647/src/util/debounce_tb.v:66: Unsupported: Ignoring delay on this delayed statement.\n        #1e6;\n        ^\n%Error: Exiting due to 2 error(s), 3 warning(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module debounce_tb#(
    parameter CTR_BITS = 20,
    parameter BOUNCE_COUNT_THRESH = 50000
    )();

    reg clk;
    wire btn, out;

    integer err_count = 0;
    integer count = 0;
    integer last_out_cnt = 0;
    integer seed;

    debounce#(
        .CTR_BITS(CTR_BITS)
    ) DUT (
        .clk(clk),
        .btn(btn),
        .out(out)
    );

    btn_bounce#(
        .ACTIVE_STATE(1'b1)
    ) button (
        .btn(btn)
    );


    initial begin
        clk = 1'b0;
        forever #10 clk = ~clk;
    end
    always @(posedge clk)
        count = count + 1;


    always @(out)
        if (last_out_cnt == 0)
            last_out_cnt = count;
        else begin
            if ((count - last_out_cnt) < BOUNCE_COUNT_THRESH) begin
                err_count += 1;
                $display("ERROR: output bounced in %d cycles", (count - last_out_cnt));
            end
            last_out_cnt = count;
        end


    initial begin
        $dumpfile("debounce_tb.vcd");
        $dumpvars(1, debounce_tb);

        seed = 732;

        #1e6;
        button.press(50e6, seed);
        #1e6;

        $display("testbench finished with %d errors", err_count);
        $finish;
    end

endmodule
module debounce_tb#(
    parameter CTR_BITS = 20,
    parameter BOUNCE_COUNT_THRESH = 50000
    )();


    reg clk;
    wire btn, out;

    integer err_count = 0;
    integer count = 0;
    integer last_out_cnt = 0;
    integer seed;

    debounce#(
        .CTR_BITS(CTR_BITS)
    ) DUT (
        .clk(clk),
        .btn(btn),
        .out(out)
    );

    btn_bounce#(
        .ACTIVE_STATE(1'b1)
    ) button (
        .btn(btn)
    );


    initial begin
        clk = 1'b0;
        forever #10 clk = ~clk;
    end
    always @(posedge clk)
        count = count + 1;


    always @(out)
        if (last_out_cnt == 0)
            last_out_cnt = count;
        else begin
            if ((count - last_out_cnt) < BOUNCE_COUNT_THRESH) begin
                err_count += 1;
                $display("ERROR: output bounced in %d cycles", (count - last_out_cnt));
            end
            last_out_cnt = count;
        end


    initial begin
        $dumpfile("debounce_tb.vcd");
        $dumpvars(1, debounce_tb);

        seed = 732;

        #1e6;
        button.press(50e6, seed);
        #1e6;

        $display("testbench finished with %d errors", err_count);
        $finish;
    end

endmodule