-
Notifications
You must be signed in to change notification settings - Fork 11
/
testbench.txt
270 lines (117 loc) · 4.15 KB
/
testbench.txt
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
-- Test bench, VHDL 93 style
-- Automaticall generated by a Pyhton Script
-- (c) Dilawar Singh, 2011
-- dilawawr@ee.iitb.ac.in
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
use work.<entity>
entity tb_<entity> is
end entity tb_<entity>;
architecture stimulus of tb_<entity> is
component <component> is
port (
<ports>
);
end component fib;
function str_to_stdvec(inp: string) return std_ulogic_vector is
variable temp: std_ulogic_vector(inp'range) := (others => 'X');
begin
for i in inp'range loop
if (inp(i) = '1') then
temp(i) := '1';
elsif (inp(i) = '0') then
temp(i) := '0';
end if;
end loop;
return temp;
end function str_to_stdvec;
function stdvec_to_str(inp: std_ulogic_vector) return string is
variable temp: string(inp'left+1 downto 1) := (others => 'X');
begin
for i in inp'reverse_range loop
if (inp(i) = '1') then
temp(i+1) := '1';
elsif (inp(i) = '0') then
temp(i+1) := '0';
end if;
end loop;
return temp;
end function stdvec_to_str;
signal Clk,Clr: std_ulogic;
signal Load: std_ulogic;
signal Data_in: std_ulogic_vector(15 downto 0);
signal S: std_ulogic_vector(15 downto 0);
signal done: std_ulogic := '0';
constant PERIOD: time := 50 ns;
begin
UUT: fib port map(Clk=>Clk,Clr=>Clr,Load=>Load,
Data_in=>Data_in,S=>S);
Clock: process
variable c: std_ulogic := '0';
begin
while (done = '0') loop
wait for PERIOD/2;
c := not c;
Clk <= c;
end loop;
end process Clock;
Read_input: process
file vector_file: text;
variable stimulus_in: std_ulogic_vector(33 downto 0);
variable S_expected: std_ulogic_vector(15 downto 0);
variable str_stimulus_in: string(34 downto 1);
variable err_cnt: integer := 0;
variable file_line: line;
begin
file_open(vector_file,"tfib93.vec",READ_MODE);
wait until rising_edge(Clk);
while not endfile(vector_file) loop
readline (vector_file,file_line);
read (file_line,str_stimulus_in) ;
assert (false)
report "Vector: " & str_stimulus_in
severity note;
stimulus_in := str_to_stdvec (str_stimulus_in);
wait for 1 ns;
--Get input side of vector...
Clr <= stimulus_in(33);
Load <= stimulus_in(32);
Data_in <= stimulus_in(31 downto 16);
--Put output side (expected values) into a variable...
S_expected := stimulus_in(15 downto 0);
wait until falling_edge(Clk);
-- Check the expected value against the results...
if (S /= S_expected) then
err_cnt := err_cnt + 1;
assert false
report "Vector failure!" & lf &
"Expected S to be " & stdvec_to_str(S_expected) & lf &
"but its value was " & stdvec_to_str(S) & lf
severity note;
end if;
end loop;
file_close(vector_file);
done <= '1';
if (err_cnt = 0) then
assert false
report "No errors." & lf & lf
severity note;
else
assert false
report "There were errors in the test." & lf
severity note;
end if;
wait;
end process Read_input;
end architecture stimulus;
-- Add a configuration statement. This statement actually states the
-- default configuration, and so it is optional.
configuration build1 of testfib is
for stimulus
for DUT: fib use entity work.fib(behavior)
port map(Clk=>Clk,Clr=>Clr,Load=>Load,
Data_in=>Data_in,S=>S);
end for;
end for;
end configuration build1;