testbench.v 1017 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
module testbench;
    reg clk;

    initial begin
        // $dumpfile("testbench.vcd");
        // $dumpvars(0, testbench);

        #5 clk = 0;
        repeat (10000) begin
            #5 clk = 1;
            #5 clk = 0;
        end

        $display("OKAY");    
    end
   
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
   function [31:0] xorshift32;
        input [31:0] arg;
        begin
                xorshift32 = arg;
                // Xorshift32 RNG, doi:10.18637/jss.v008.i14
                xorshift32 = xorshift32 ^ (xorshift32 << 13);
                xorshift32 = xorshift32 ^ (xorshift32 >> 17);
                xorshift32 = xorshift32 ^ (xorshift32 <<  5);
        end
    endfunction

    reg [31:0] rng = 123456789;
    always @(posedge clk) rng <= xorshift32(rng);

    wire dinA = xorshift32(rng * 5);
    wire dinC = xorshift32(rng * 7);
33
    
34
    wire doutB;
35 36 37 38 39

    top uut (
        .clk (clk ),
        .a (dinA ),
        .c (dinC),
40
        .b (doutB )
41 42
    );
    
43
	assert_dff ff_test(.clk(clk), .test(doutB), .pat(1'b1));
44 45
    
endmodule