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

Subversion Repositories scalable_arbiter

[/] [scalable_arbiter/] [trunk/] [bench/] [verilog/] [tb_arbiter.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 simply applies the vectors in the pattern file,
20
// and tests that the output matches the expected values. This
21
// test is usful to verify basic behavior, but it is difficult
22
// to generate vectors for large configurations.
23
 
24
`define WIDTH 8
25
`define SELECT_WIDTH 8
26
`define TURNAROUND 3
27
//`define TURNAROUND 6 for arbiter x2
28
`define TICK 10
29
`define HALF_TICK 5
30
`define TEST_VEC_COUNT 241
31
`define TEST_VEC_MULT 2
32
`define PATTERN_FILE "tb_arbiter.txt"
33
 
34
module tb_arbiter;
35
 
36
reg reset;
37
reg clock;
38
 
39
reg [`WIDTH-1:0] req;
40
wire [`WIDTH-1:0] grant;
41
wire [`SELECT_WIDTH-1:0] select;
42
wire valid;
43
 
44
reg [`WIDTH-1:0] pattern[(`TEST_VEC_MULT*`TEST_VEC_COUNT)-1:0];
45
reg [`WIDTH-1:0] grant_expected;
46
 
47
integer test_i;
48
integer grant_i;
49
integer grant_count;
50
integer failures;
51
integer monitor_exceptions;
52
 
53
//
54
// UUT
55
//
56
 
57
arbiter #(
58
        .width(`WIDTH),
59
        .select_width(`SELECT_WIDTH)
60
) arbiter (
61
        .enable(1'b1),
62
        .req(req),
63
        .grant(grant),
64
        .select(select),
65
        .valid(valid),
66
 
67
        .clock(clock),
68
        .reset(reset)
69
);
70
 
71
//
72
// clock
73
//
74
 
75
always @(clock)
76
        #`HALF_TICK clock <= !clock;
77
 
78
//
79
// test monitors
80
//
81
 
82
always @(grant)
83
begin
84
        grant_count = 0;
85
        for(grant_i = 0; grant_i < `WIDTH; grant_i = grant_i + 1)
86
        begin
87
                if(grant[grant_i])
88
                begin
89
                        grant_count = grant_count + 1;
90
 
91
                        if(!req[grant_i])
92
                        begin
93
                                monitor_exceptions = monitor_exceptions + 1;
94
 
95
                                $display("EXCEPTION @%e: grant line %d with no req",
96
                                        $realtime, grant_i);
97
                        end
98
 
99
                        if(select != grant_i)
100
                        begin
101
                                monitor_exceptions = monitor_exceptions + 1;
102
 
103
                                $display("EXCEPTION @%e: select of %d does not match grant of line %d",
104
                                        $realtime, select, grant_i);
105
                        end
106
                end
107
        end
108
 
109
        if(grant_count > 1)
110
        begin
111
                monitor_exceptions = monitor_exceptions + 1;
112
 
113
                $display("EXCEPTION @%e: grant %h asserts multiple lines",
114
                        $realtime, grant);
115
        end
116
end
117
 
118
//
119
// test sequence
120
//
121
 
122
initial
123
begin
124
        $readmemb(`PATTERN_FILE, pattern);
125
        failures = 0;
126
        monitor_exceptions = 0;
127
 
128
        clock = 1;
129
        req = 0;
130
        reset = 1;
131
        #`TICK @(negedge clock) reset = 0;
132
 
133
        // apply reqs, and test grants against exepcted values
134
        for(test_i = 0; test_i < `TEST_VEC_COUNT; test_i = test_i + 1)
135
        begin
136
                #`TICK;
137
 
138
                req = pattern[test_i*`TEST_VEC_MULT];
139
                grant_expected = pattern[test_i*`TEST_VEC_MULT + 1];
140
 
141
                #(`TURNAROUND*`TICK);
142
 
143
                if(grant != grant_expected)
144
                begin
145
                        failures = failures + 1;
146
 
147
                        $display("FAILED %d: req %h, grant %h (expected %h)",
148
                                test_i, req, grant, grant_expected);
149
                end
150
                else
151
                begin
152
                        $display("ok %d: req %h, grant %h (expected %h)",
153
                                test_i, req, grant, grant_expected);
154
                end
155
        end
156
 
157
        $display("%d failures", failures);
158
        $display("%d monitor exceptions", monitor_exceptions);
159
 
160
        if(failures == 0 && monitor_exceptions == 0)
161
                $display("PASS");
162
        else
163
                $display("FAIL");
164
end
165
 
166
endmodule

powered by: WebSVN 2.1.0

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