OpenCores
URL https://opencores.org/ocsvn/scalable_arbiter/scalable_arbiter/trunk

Subversion Repositories scalable_arbiter

[/] [scalable_arbiter/] [trunk/] [bench/] [verilog/] [tb_abrbiter2.v] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 kendallc
/*
2
 * Copyright (c) 2008, Kendall Correll
3
 *
4
 * Permission to use, copy, modify, and distribute this software for any
5
 * purpose with or without fee is hereby granted, provided that the above
6
 * copyright notice and this permission notice appear in all copies.
7
 *
8
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
 */
16
 
17
`timescale 1ns / 1ps
18
 
19
// This bench applies req vectors, deasserts req lines as
20
// they are granted, and tests that each req is granted
21
// only once for each vector. It seems to be a pretty good
22
// test because it is similar to the arbiter's intended
23
// application, and it focuses on fairness, the most
24
// important aspect of the arbiter's behavior. This test
25
// also makes it easy to use large arbiter configurations,
26
// which tend to find more problems.
27
 
28
`define WIDTH 128
29
`define SELECT_WIDTH 7
30
`define TURNAROUND 3
31
//`define TURNAROUND 6 for arbiter x2
32
`define TICK 10
33
`define HALF_TICK 5
34
`define TEST_VEC_COUNT 8
35
`define PATTERN_FILE "tb_arbiter2.txt"
36
`define ROUND_COUNT 3
37
 
38
module tb_arbiter2;
39
 
40
reg reset;
41
reg clock;
42
 
43
reg [`WIDTH-1:0] req;
44
wire [`WIDTH-1:0] grant;
45
wire [`SELECT_WIDTH-1:0] select;
46
wire valid;
47
 
48
reg [`WIDTH-1:0] pattern[`TEST_VEC_COUNT-1:0];
49
 
50
integer test_i;
51
integer grant_i;
52
integer grant_count;
53
integer req_i;
54
integer req_count[`TEST_VEC_COUNT-1:0];
55
integer failures;
56
integer monitor_exceptions;
57
integer fill_i;
58
integer round;
59
integer reqs[`WIDTH-1:0];
60
integer grants[`ROUND_COUNT-1:0][`WIDTH-1:0];
61
 
62
//
63
// UUT
64
//
65
 
66
arbiter #(
67
        .width(`WIDTH),
68
        .select_width(`SELECT_WIDTH)
69
) arbiter (
70
        .enable(1'b1),
71
        .req(req),
72
        .grant(grant),
73
        .select(select),
74
        .valid(valid),
75
 
76
        .clock(clock),
77
        .reset(reset)
78
);
79
 
80
//
81
// clock
82
//
83
 
84
always @(clock)
85
        #`HALF_TICK clock <= !clock;
86
 
87
//
88
// test monitors
89
//
90
 
91
always @(grant)
92
begin
93
        grant_count = 0;
94
        for(grant_i = 0; grant_i < `WIDTH; grant_i = grant_i + 1)
95
        begin
96
                if(grant[grant_i])
97
                begin
98
                        grant_count = grant_count + 1;
99
                        grants[round][grant_i] = grants[round][grant_i] + 1;
100
 
101
                        if(!req[grant_i])
102
                        begin
103
                                monitor_exceptions = monitor_exceptions + 1;
104
 
105
                                $display("EXCEPTION @%e: grant line %d with no req",
106
                                        $realtime, grant_i);
107
                        end
108
 
109
                        if(select != grant_i)
110
                        begin
111
                                monitor_exceptions = monitor_exceptions + 1;
112
 
113
                                $display("EXCEPTION @%e: select of %d does not match grant of line %d",
114
                                        $realtime, select, grant_i);
115
                        end
116
                end
117
        end
118
 
119
        if(grant_count > 1)
120
        begin
121
                monitor_exceptions = monitor_exceptions + 1;
122
 
123
                $display("EXCEPTION @%e: grant %h asserts multiple lines",
124
                        $realtime, grant);
125
        end
126
end
127
 
128
//
129
// test sequence
130
//
131
 
132
initial
133
begin
134
        $readmemh(`PATTERN_FILE, pattern);
135
        failures = 0;
136
        monitor_exceptions = 0;
137
        fill_i = 0;
138
        round = 0;
139
        for(req_i = 0; req_i < `WIDTH; req_i = req_i + 1)
140
        begin
141
                reqs[req_i] = 0;
142
 
143
                grants[0][req_i] = 0;
144
                grants[1][req_i] = 0;
145
                grants[2][req_i] = 0;
146
        end
147
        // pre-calculate some values used in the test
148
        for(test_i = 0; test_i < `TEST_VEC_COUNT; test_i = test_i + 1)
149
        begin
150
                req_count[test_i] = 0;
151
                for(req_i = 0; req_i < `WIDTH; req_i = req_i + 1)
152
                begin
153
                        if(pattern[test_i][req_i])
154
                        begin
155
                                req_count[test_i] = req_count[test_i] + 1;
156
                                reqs[req_i] = reqs[req_i] + 1;
157
                        end
158
                end
159
        end
160
 
161
        clock = 1;
162
        req = 0;
163
        reset = 1;
164
        #`TICK @(negedge clock) reset = 0;
165
 
166
        // apply reqs, and turn off granted reqs permanently
167
        for(test_i = 0; test_i < `TEST_VEC_COUNT; test_i = test_i + 1)
168
        begin
169
                req = pattern[test_i];
170
 
171
                for(req_i = 0; req_i < req_count[test_i]; req_i = req_i + 1)
172
                begin
173
                        #(`TURNAROUND*`TICK);
174
 
175
                        req = req & ~grant;
176
                end
177
 
178
                // one clock to deassert the last req before we apply
179
                // the next req vector
180
                #`TICK;
181
        end
182
 
183
        // apply reqs, but only turn off granted reqs temporarily
184
        round = round + 1;
185
        for(test_i = 0; test_i < `TEST_VEC_COUNT; test_i = test_i + 1)
186
        begin
187
                req = pattern[test_i];
188
 
189
                for(req_i = 0; req_i < req_count[test_i]; req_i = req_i + 1)
190
                begin
191
                        #(`TURNAROUND*`TICK);
192
 
193
                        req = pattern[test_i] & ~grant;
194
                end
195
 
196
                // one clock to deassert the reqs before we apply the
197
                // next req vector
198
                req = 0;
199
                #`TICK;
200
        end
201
 
202
        // apply reqs, and fill behind with the next vector as reqs
203
        // are granted
204
        round = round + 1;
205
        req = pattern[0];
206
        fill_i = `WIDTH;
207
        for(test_i = 0; test_i < `TEST_VEC_COUNT; test_i = test_i + 1)
208
        begin
209
                for(req_i = 0; req_i < req_count[test_i]; req_i = req_i + 1)
210
                begin
211
                        #(`TURNAROUND*`TICK);
212
 
213
                        req = req & ~grant;
214
 
215
                        for(fill_i = fill_i; ~grant[fill_i%`WIDTH]; fill_i = fill_i + 1)
216
                        begin
217
                                req[fill_i%`WIDTH] = (fill_i/`WIDTH < `TEST_VEC_COUNT)
218
                                        ? pattern[fill_i/`WIDTH][fill_i%`WIDTH]
219
                                        : 1'b0;
220
                        end
221
                end
222
        end
223
 
224
        // check the results
225
        for(req_i = 0; req_i < `WIDTH; req_i = req_i + 1)
226
        begin
227
                if(reqs[req_i] != grants[0][req_i]
228
                        || reqs[req_i] != grants[1][req_i]
229
                        || reqs[req_i] != grants[2][req_i])
230
                begin
231
                        failures = failures + 1;
232
 
233
                        $display("FAILED %d: %d reqs, %d %d %d grants",
234
                                req_i, reqs[req_i], grants[0][req_i],
235
                                grants[1][req_i], grants[2][req_i]);
236
                end
237
                else
238
                begin
239
                        $display("ok %d: %d reqs, %d %d %d grants",
240
                                req_i, reqs[req_i], grants[0][req_i],
241
                                grants[1][req_i], grants[2][req_i]);
242
                end
243
        end
244
 
245
        $display("%d failures", failures);
246
        $display("%d monitor exceptions", monitor_exceptions);
247
 
248
        if(failures == 0 && monitor_exceptions == 0)
249
                $display("PASS");
250
        else
251
                $display("FAIL");
252
end
253
 
254
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.