data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv
1: b'%Warning-STMTDLY: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:17: Unsupported: Ignoring delay on this delayed statement.\n        forever #5 clk = ~clk;\n                ^\n                  ... Use "/* verilator lint_off STMTDLY */" and lint_on around source to disable this message.\n%Warning-STMTDLY: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:56: Unsupported: Ignoring delay on this delayed statement.\n        #10;\n        ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:65: syntax error, unexpected \'@\'\n        @(negedge clk);\n        ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:74: syntax error, unexpected \'@\'\n        @(posedge clk);\n        ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:83: syntax error, unexpected \'@\'\n        @(posedge clk);\n        ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:92: syntax error, unexpected \'@\'\n        @(posedge clk);\n        ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:102: syntax error, unexpected \'@\'\n            @(posedge clk);\n            ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:114: syntax error, unexpected \'@\'\n        @(posedge clk);\n        ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:126: syntax error, unexpected \'@\'\n        @(posedge clk);\n        ^\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:138: Unsupported: wait statements\n        wait (tb_rtl_doublecrack.dut.state == 3\'b110);\n        ^~~~\n%Error: data/full_repos/permissive/426864978/lab3/task5/tb_rtl_doublecrack.sv:144: syntax error, unexpected \'@\'\n        @(posedge clk);\n        ^\n%Error: Exiting due to 9 error(s), 2 warning(s)\n        ... See the manual and https://verilator.org for more assistance.\n'
module tb_rtl_doublecrack();

    logic clk, rst_n, en, rdy, key_valid, err;
    logic [23:0] key;
    logic [7:0] ct_addr, ct_rddata;


    logic [7:0] ciphertext [255:0];
    logic [7:0] exp_pt [255:0];

    doublecrack dut(.*);

    initial begin
        clk = 1;
        forever #5 clk = ~clk;
    end

    task state_checker;
        input [31:0] index;
        input [2:0] exp_state;
        begin
            if (tb_rtl_doublecrack.dut.state !== exp_state) begin
                $display("ERROR %dA: Expected state is %d, actual state is %d", index, exp_state, tb_rtl_doublecrack.dut.state);
                err = 1'b1;
            end
        end
    endtask


    `define IDLE        3'b000
    `define READ_CT     3'b001
    `define WRITE_CT    3'b010
    `define EN_CRACK    3'b011
    `define DEN_CRACK   3'b100
    `define CRACKING    3'b101
    `define DONE        3'b110


    `define KEY_MAX     24'hFFFFFF

    initial begin
        err = 1'b0;






        $readmemh("crack_res1.txt", exp_pt);
        $readmemh("test1.memh", ciphertext);


        rst_n = 1'bx; en = 1'bx;
        #10;
        state_checker(1, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'bx) begin
            $display("ERROR 1: Expected rdy is %d, actual rdy is %d", 1'bx, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        rst_n = 1'b0; en = 1'b0;
        @(negedge clk);
        state_checker(2, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b0) begin
            $display("ERROR 2: Expected rdy is %d, actual rdy is %d", 1'b0, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        rst_n = 1'b1;
        @(posedge clk);
        state_checker(3, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b0) begin
            $display("ERROR 3: Expected rdy is %d, actual rdy is %d", 1'b0, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        en = 1'b1; ct_rddata = ciphertext[tb_rtl_doublecrack.dut.ct_addr];
        @(posedge clk);
        state_checker(4, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b1) begin
            $display("ERROR 4A: Expected rdy is %d, actual rdy is %d", 1'b1, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        en = 1'b0;
        @(posedge clk);
        state_checker(5, `READ_CT);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b0) begin
            $display("ERROR 5A: Expected rdy is %d, actual rdy is %d", 1'b0, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        ct_rddata = ciphertext[tb_rtl_doublecrack.dut.ct_addr];
        while (tb_rtl_doublecrack.dut.state !== `EN_CRACK) begin
            @(posedge clk);
            @(posedge clk);
            ct_rddata = ciphertext[tb_rtl_doublecrack.dut.ct_addr];
        end
        for (int i = 0; i <= tb_rtl_doublecrack.dut.message_length; i++) begin
           if (ciphertext[i] !== tb_rtl_doublecrack.dut.ct_copy[i]) begin 
                $display("CT MEM [%d] ERROR: Expected ct_copy is %h, actual ct_copy is %h", i[7:0], ciphertext[i], tb_rtl_doublecrack.dut.ct_copy[i]);
                err = 1'b1;
            end
        end


        @(posedge clk);
        state_checker(7, `DEN_CRACK);
        if (tb_rtl_doublecrack.dut.en_c1 !== 1'b1) begin
            $display("ERROR 7A: Expected en_c1 is %d, actual en_c1 is %d", 1'b1, tb_rtl_doublecrack.dut.en_c1);
            err = 1'b1;
        end
        if (tb_rtl_doublecrack.dut.en_c2 !== 1'b1) begin
            $display("ERROR 7B: Expected en_c2 is %d, actual en_c2 is %d", 1'b1, tb_rtl_doublecrack.dut.en_c2);
            err = 1'b1;
        end


        @(posedge clk);
        state_checker(8, `CRACKING);
        if (tb_rtl_doublecrack.dut.en_c1 !== 1'b0) begin
            $display("ERROR 8A: Expected en_c1 is %d, actual en_c1 is %d", 1'b0, tb_rtl_doublecrack.dut.en_c1);
            err = 1'b1;
        end
        if (tb_rtl_doublecrack.dut.en_c2 !== 1'b0) begin
            $display("ERROR 8B: Expected en_c2 is %d, actual en_c2 is %d", 1'b0, tb_rtl_doublecrack.dut.en_c2);
            err = 1'b1;
        end


        wait (tb_rtl_doublecrack.dut.state == `DONE);
        if (tb_rtl_doublecrack.dut.key_valid_c1 !== 1'b1) begin
            $display("ERROR 9A: Expected key_valid_c1 is %d, actual key_valid_c1 is %d", 1'b1, tb_rtl_doublecrack.dut.key_valid_c1);
            err = 1'b1;
        end

        @(posedge clk);
        if (tb_rtl_doublecrack.dut.key_valid !== 1'b1) begin
            $display("ERROR 9B: Expected key_valid is %d, actual key_valid is %d", 1'b1, tb_rtl_doublecrack.dut.key_valid);
            err = 1'b1;
        end


        for (int i = 0; i <= 8'h35; i++) begin
           if (exp_pt[i] !== tb_rtl_doublecrack.dut.pt.altsyncram_component.m_default.altsyncram_inst.mem_data[i]) begin 
                $display("PT MEM [%d] ERROR: Expected pt is %h, actual pt is %h", i[7:0], exp_pt[i], tb_rtl_doublecrack.dut.pt.altsyncram_component.m_default.altsyncram_inst.mem_data[i]);
                err = 1'b1;
            end
        end

        if (~err)
            $display("SUCCESS: All tests passed.");
        $stop;
    end

endmodule
module tb_rtl_doublecrack();


    logic clk, rst_n, en, rdy, key_valid, err;
    logic [23:0] key;
    logic [7:0] ct_addr, ct_rddata;


    logic [7:0] ciphertext [255:0];
    logic [7:0] exp_pt [255:0];

    doublecrack dut(.*);

    initial begin
        clk = 1;
        forever #5 clk = ~clk;
    end

    task state_checker;
        input [31:0] index;
        input [2:0] exp_state;
        begin
            if (tb_rtl_doublecrack.dut.state !== exp_state) begin
                $display("ERROR %dA: Expected state is %d, actual state is %d", index, exp_state, tb_rtl_doublecrack.dut.state);
                err = 1'b1;
            end
        end
    endtask


    `define IDLE        3'b000
    `define READ_CT     3'b001
    `define WRITE_CT    3'b010
    `define EN_CRACK    3'b011
    `define DEN_CRACK   3'b100
    `define CRACKING    3'b101
    `define DONE        3'b110


    `define KEY_MAX     24'hFFFFFF

    initial begin
        err = 1'b0;






        $readmemh("crack_res1.txt", exp_pt);
        $readmemh("test1.memh", ciphertext);


        rst_n = 1'bx; en = 1'bx;
        #10;
        state_checker(1, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'bx) begin
            $display("ERROR 1: Expected rdy is %d, actual rdy is %d", 1'bx, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        rst_n = 1'b0; en = 1'b0;
        @(negedge clk);
        state_checker(2, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b0) begin
            $display("ERROR 2: Expected rdy is %d, actual rdy is %d", 1'b0, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        rst_n = 1'b1;
        @(posedge clk);
        state_checker(3, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b0) begin
            $display("ERROR 3: Expected rdy is %d, actual rdy is %d", 1'b0, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        en = 1'b1; ct_rddata = ciphertext[tb_rtl_doublecrack.dut.ct_addr];
        @(posedge clk);
        state_checker(4, `IDLE);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b1) begin
            $display("ERROR 4A: Expected rdy is %d, actual rdy is %d", 1'b1, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        en = 1'b0;
        @(posedge clk);
        state_checker(5, `READ_CT);
        if (tb_rtl_doublecrack.dut.rdy !== 1'b0) begin
            $display("ERROR 5A: Expected rdy is %d, actual rdy is %d", 1'b0, tb_rtl_doublecrack.dut.rdy);
            err = 1'b1;
        end


        ct_rddata = ciphertext[tb_rtl_doublecrack.dut.ct_addr];
        while (tb_rtl_doublecrack.dut.state !== `EN_CRACK) begin
            @(posedge clk);
            @(posedge clk);
            ct_rddata = ciphertext[tb_rtl_doublecrack.dut.ct_addr];
        end
        for (int i = 0; i <= tb_rtl_doublecrack.dut.message_length; i++) begin
           if (ciphertext[i] !== tb_rtl_doublecrack.dut.ct_copy[i]) begin 
                $display("CT MEM [%d] ERROR: Expected ct_copy is %h, actual ct_copy is %h", i[7:0], ciphertext[i], tb_rtl_doublecrack.dut.ct_copy[i]);
                err = 1'b1;
            end
        end


        @(posedge clk);
        state_checker(7, `DEN_CRACK);
        if (tb_rtl_doublecrack.dut.en_c1 !== 1'b1) begin
            $display("ERROR 7A: Expected en_c1 is %d, actual en_c1 is %d", 1'b1, tb_rtl_doublecrack.dut.en_c1);
            err = 1'b1;
        end
        if (tb_rtl_doublecrack.dut.en_c2 !== 1'b1) begin
            $display("ERROR 7B: Expected en_c2 is %d, actual en_c2 is %d", 1'b1, tb_rtl_doublecrack.dut.en_c2);
            err = 1'b1;
        end


        @(posedge clk);
        state_checker(8, `CRACKING);
        if (tb_rtl_doublecrack.dut.en_c1 !== 1'b0) begin
            $display("ERROR 8A: Expected en_c1 is %d, actual en_c1 is %d", 1'b0, tb_rtl_doublecrack.dut.en_c1);
            err = 1'b1;
        end
        if (tb_rtl_doublecrack.dut.en_c2 !== 1'b0) begin
            $display("ERROR 8B: Expected en_c2 is %d, actual en_c2 is %d", 1'b0, tb_rtl_doublecrack.dut.en_c2);
            err = 1'b1;
        end


        wait (tb_rtl_doublecrack.dut.state == `DONE);
        if (tb_rtl_doublecrack.dut.key_valid_c1 !== 1'b1) begin
            $display("ERROR 9A: Expected key_valid_c1 is %d, actual key_valid_c1 is %d", 1'b1, tb_rtl_doublecrack.dut.key_valid_c1);
            err = 1'b1;
        end

        @(posedge clk);
        if (tb_rtl_doublecrack.dut.key_valid !== 1'b1) begin
            $display("ERROR 9B: Expected key_valid is %d, actual key_valid is %d", 1'b1, tb_rtl_doublecrack.dut.key_valid);
            err = 1'b1;
        end


        for (int i = 0; i <= 8'h35; i++) begin
           if (exp_pt[i] !== tb_rtl_doublecrack.dut.pt.altsyncram_component.m_default.altsyncram_inst.mem_data[i]) begin 
                $display("PT MEM [%d] ERROR: Expected pt is %h, actual pt is %h", i[7:0], exp_pt[i], tb_rtl_doublecrack.dut.pt.altsyncram_component.m_default.altsyncram_inst.mem_data[i]);
                err = 1'b1;
            end
        end

        if (~err)
            $display("SUCCESS: All tests passed.");
        $stop;
    end

endmodule