1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| \* Eric Villasenor
register file test bench */
`include "register_file_if.vh"
`timescale 1 ns / 1 ns
module register_file_tb;
parameter PERIOD = 10;
logic CLK = 0, nRST;
int v1 = 1; int v2 = 4721; int v3 = 25119;
always #(PERIOD/2) CLK++;
register_file_if rfif (); test PROG (CLK, nRST,rfif,v1,v2,v3); `ifndef MAPPED register_file DUT(CLK, nRST, rfif); `else register_file DUT( .rfif.rdat2 (rfif.rdat2), .rfif.rdat1 (rfif.rdat1), .rfif.wdat (rfif.wdat), .rfif.rsel2 (rfif.rsel2), .rfif.rsel1 (rfif.rsel1), .rfif.wsel (rfif.wsel), .rfif.WEN (rfif.WEN), .nRST (nRST), .CLK (CLK) ); `endif
endmodule
program test ( input logic CLK, output logic nRST,
register_file_if.tb rfif, input logic [31:0] v1, input logic [31:0] v2, input logic [31:0] v3 ); reg [5:0] i; reg [3:0] testcase = 0; initial begin rfif.wsel = 0; rfif.wdat = '0; rfif.WEN = 0; rfif.rsel1 = 0; rfif.rsel2 = 0; @(posedge CLK) nRST = 1'b0;
@(posedge CLK) nRST = 1'b0;
@(posedge CLK) nRST = 1'b1; rfif.wsel = 0; rfif.WEN = 1; rfif.wdat = '1; rfif.rsel1 = 0; rfif.rsel2 = 1; testcase ++; @(posedge CLK) nRST = 1'b0; @(posedge CLK) nRST = 1'b1; for (i = 0; i < 32; i = i + 1) begin @(posedge CLK) rfif.wsel = i; @(posedge CLK) rfif.rsel1 = i; rfif.rsel2 = 31-i; end @(posedge CLK) nRST = 1'b1; rfif.wsel = 1; rfif.WEN = 1; rfif.wdat = '0; rfif.rsel1 = 0; rfif.rsel2 = 1; testcase ++; @(posedge CLK) nRST = 1'b0; @(posedge CLK) nRST = 1'b1; for (i = 0; i < 32; i = i + 1) begin @(posedge CLK) rfif.wsel = i; @(posedge CLK) rfif.rsel1 = i; rfif.rsel2 = 31-i; end @(posedge CLK) nRST = 1'b0; @(posedge CLK) nRST = 1'b1; rfif.wsel = 1; rfif.WEN = 1; rfif.wdat = '1; rfif.rsel1 = 1; rfif.rsel2 = 0; testcase ++; @(posedge CLK) nRST = 1'b0; @(posedge CLK) nRST = 1'b1; for (i = 0; i < 32; i = i + 1) begin @(posedge CLK) rfif.wsel = i; @(posedge CLK) rfif.rsel1 = i; rfif.rsel2 = 31-i; end @(posedge CLK) @(posedge CLK) nRST = 1'b0; @(posedge CLK) @(posedge CLK) $finish; end endprogram
|