-
Notifications
You must be signed in to change notification settings - Fork 13
/
ringbuffer_tb.v
135 lines (125 loc) · 2.57 KB
/
ringbuffer_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
`timescale 1 ns / 100 ps
module ringbuffer_tb ();
reg write_clock_enable;
reg read_clock_enable;
reg clock;
reg reset;
reg [1:0] write_data;
wire [1:0] read_data;
wire empty;
wire overflow;
ringbuffer #(.AW(2), .DW(2))
RINGBUFFER (
.reset(reset),
.clock(clock),
.read_data(read_data),
.read_clock_enable(read_clock_enable),
.write_data(write_data),
.write_clock_enable(write_clock_enable),
.empty(empty),
.overflow(overflow));
always
#1 clock = ~clock;
initial begin
$dumpfile ("ringbuffer_tb.vcd");
$dumpvars (0, ringbuffer_tb);
clock = 0;
write_clock_enable = 0;
read_clock_enable = 0;
reset = 0;
write_data = 2'b11;
#6;
reset = 1;
#6
if (read_data != 0) begin
$display("After reset read_data != 0");
$stop;
end
if (~empty) begin
$display("Ringbuffer is not empty after reset");
$stop;
end
if (overflow) begin
$display("Ringbuffer is overflowed after reset");
$stop;
end
// try to read even if the buffer is empty
#1;
read_clock_enable = 1;
#2;
read_clock_enable = 0;
#1;
if (read_data != 0) begin
$display("read_data increase even the ringbuffer is empty and a malicious read_clock_enable was triggered");
$stop;
end
// check write, read, write, write, write,read, read, write, read, read
#1;
write_clock_enable = 1;
#2;
write_clock_enable = 0;
#1;
if (empty || overflow) begin
$display("buffer should not empty nor overflowed");
$stop;
end
#2;
read_clock_enable = 1;
#2;
if (~empty) begin
$display("buffer is empty, but not signaling emptyness");
$stop;
end
if (read_data != 2'b11) begin
$display("read_data doesn\'t increase after read");
$stop;
end
#2;
read_clock_enable = 0;
#2;
// ringbuffer is now empty again, read_data & write_data should show = 1
#2;
write_clock_enable = 1;
#2;
write_clock_enable = 0;
#2;
write_clock_enable = 1;
#2;
write_clock_enable = 0;
#2;
// buffer should be full
write_clock_enable = 1;
#2;
write_clock_enable = 0;
if (~overflow) begin
$display("overflow not signaled even it\'s full");
$stop;
end
#2;
read_clock_enable = 1;
#2;
read_clock_enable = 0;
if (overflow) begin
$display("overflow should *NOT* signaled anymore");
$stop;
end
#2;
read_clock_enable = 1;
#2;
read_clock_enable = 0;
#2;
read_clock_enable = 1;
#2;
read_clock_enable = 0;
#2;
read_clock_enable = 1;
#2;
read_clock_enable = 0;
if (~empty) begin
$display("buffer should empty, but it doesn\'t signaling this");
$stop;
end
#2;
$finish;
end
endmodule