-
Notifications
You must be signed in to change notification settings - Fork 0
/
testbench.v
77 lines (65 loc) · 1.65 KB
/
testbench.v
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
`timescale 1ns/1ps
module testbench();
reg reset;
wire clk, done;
wire [31:0] iaddr, idata, daddr, drdata, dwdata;
wire [3:0] dwe;
// To check reg values
integer i, s, fail, log_file, exp_file;
reg [31:0] dtmp, exp_reg;
control u0(
.reset(reset),
.done(done),
.clk(clk)
);
cpu u1(
.clk(clk),
.reset(reset),
.iaddr(iaddr),
.idata(idata),
.daddr(daddr),
.drdata(drdata),
.dwdata(dwdata),
.dwe(dwe),
.done(done)
);
imem u2(
.iaddr(iaddr),
.idata(idata)
);
dmem u3(
.clk(clk),
.daddr(daddr),
.drdata(drdata),
.dwdata(dwdata),
.dwe(dwe)
);
initial begin
$dumpfile("testbench.vcd");
$dumpvars(0, testbench);
reset = 1;
#100
reset = 0;
log_file = $fopen("cpu_tb.log", "a");
exp_file = $fopen({`TESTDIR,"/expout.txt"}, "r");
@(posedge clk);
for (i=0; i<200; i=i+1) begin
@(posedge clk);
end
$display("RUNNING TEST FROM ", `TESTDIR);
fail = 0;
// Dump top dmem
for (i=0; i<32; i=i+1) begin
s = $fscanf(exp_file, "%d\n", exp_reg);
dtmp = {u3.mem3[i], u3.mem2[i], u3.mem1[i], u3.mem0[i]};
if(exp_reg !== dtmp) begin
$display("FAIL: Expected Reg[%d] = %x vs. Got Reg[%d] = %x", i, $signed(exp_reg), i, dtmp);
fail = fail + 1;
end
end
if(fail != 0) begin
$display("FAILED. %d registers do not match.\n", fail);
end
$finish;
end
endmodule