-
Notifications
You must be signed in to change notification settings - Fork 18
/
if_else_tb.v
179 lines (128 loc) · 3.51 KB
/
if_else_tb.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
`define assert(signal, value) if ((signal) !== (value)) begin $display("ASSERTION FAILED in %m: signal != value"); $finish(1); end
module test();
reg clk;
reg rst;
wire valid;
// Depth 16, width 32 RAM
reg [4:0] dbg_addr;
wire [31:0] dbg_data;
reg [4:0] dbg_wr_addr;
reg [31:0] dbg_wr_data;
reg dbg_wr_en;
wire [4:0] waddr;
wire [31:0] wdata;
wire [0:0] wen;
wire [4:0] raddr0;
wire [4:0] raddr1;
wire [31:0] rdata0;
wire [31:0] rdata1;
initial begin
#1 dbg_wr_addr = 4;
#1 dbg_wr_data = 3;
#1 dbg_wr_en = 1;
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 dbg_wr_addr = 3;
#1 dbg_wr_data = 23;
#1 dbg_wr_en = 1;
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 dbg_wr_en = 0;
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 dbg_addr = 0;
#1 clk = 0;
#1 rst = 1;
#1 clk = 1;
`assert(dbg_data, 32'hxxxxxxxx)
`assert(valid, 1'd0)
#1 rst = 0;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
`assert(valid, 1'd0)
#1 clk = 0;
#1 clk = 1;
`assert(valid, 1'd0)
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
#1 $display("Should overwrite value, dbg_data = %d", dbg_data);
`assert(dbg_data, 32'd23)
`assert(valid, 1'd1)
// Now reset and write new value with c[0] ]!= 3
#1 dbg_wr_addr = 4;
#1 dbg_wr_data = 2;
#1 dbg_wr_en = 1;
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 dbg_wr_addr = 3;
#1 dbg_wr_data = 18;
#1 dbg_wr_en = 1;
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 dbg_wr_en = 0;
$display("dbg_data = %d", dbg_data);
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
$display("dbg_data = %d", dbg_data);
#1 clk = 0;
#1 clk = 1;
#1 rst = 1;
#1 dbg_addr = 0;
$display("dbg_data = %d", dbg_data);
#1 clk = 0;
#1 rst = 1;
#1 clk = 1;
$display("dbg_data = %d", dbg_data);
#1 rst = 0;
`assert(dbg_data, 32'd23)
`assert(valid, 1'd0)
$display("dbg_data = %d", dbg_data);
#1 clk = 0;
#1 clk = 1;
#1 clk = 0;
#1 clk = 1;
$display("dbg_data = %d", dbg_data);
#1 clk = 0;
#1 clk = 1;
$display("dbg_data = %d", dbg_data);
#1 clk = 0;
#1 clk = 1;
#1 $display("Should not overwrite value");
$display("dbg_data = %d", dbg_data);
`assert(dbg_data, 32'd23)
`assert(valid, 1'd1)
#1 $display("Passed");
end
RAM2 mem(.clk(clk),
.rst(rst),
.raddr_0(raddr0),
.rdata_0(rdata0),
.raddr_1(raddr1),
.rdata_1(rdata1),
.debug_write_addr(dbg_wr_addr),
.debug_write_data(dbg_wr_data),
.debug_write_en(dbg_wr_en),
.debug_addr(dbg_addr),
.debug_data(dbg_data),
.wen(wen),
.wdata(wdata),
.waddr(waddr));
if_else ss(.clk(clk), .rst(rst), .valid(valid), .mem_waddr_0(waddr), .mem_wdata_0(wdata), .mem_wen_0(wen), .mem_raddr_0(raddr0), .mem_rdata_0(rdata0));
endmodule