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

Subversion Repositories pltbutils

[/] [pltbutils/] [trunk/] [bench/] [vhdl/] [tb_pltbutils.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 pela
----------------------------------------------------------------------
2
----                                                              ----
3
---- PlTbUtils Testbench                                          ----
4
----                                                              ----
5
---- This file is part of the PlTbUtils project                   ----
6
---- http://opencores.org/project,pltbutils                       ----
7
----                                                              ----
8
---- Description                                                  ----
9
---- PlTbUtils is a collection of functions, procedures and       ----
10
---- components for easily creating stimuli and checking response ----
11
---- in automatic self-checking testbenches.                      ----
12
----                                                              ----
13
---- This is a testbench file, which is used to verify            ----
14
---- - pltbutils_func_pkg                                         ----
15
---- - pltbutils_comp                                           ----
16
---- This testbench is NOT selfchecking or automatic.             ----
17
---- Manually check the transcript and waveform, when simulating. ----
18
---- It prints some informative text in the transcript, to help   ----
19
---- with the manual inspection.                                  ----
20
----                                                              ----
21
----                                                              ----
22
---- To Do:                                                       ----
23
---- -                                                            ----
24
----                                                              ----
25
---- Author(s):                                                   ----
26
---- - Per Larsson, pela@opencores.org                            ----
27
----                                                              ----
28
----------------------------------------------------------------------
29
----                                                              ----
30
---- Copyright (C) 2013 Authors and OPENCORES.ORG                 ----
31
----                                                              ----
32
---- This source file may be used and distributed without         ----
33
---- restriction provided that this copyright statement is not    ----
34
---- removed from the file and that any derivative work contains  ----
35
---- the original copyright notice and the associated disclaimer. ----
36
----                                                              ----
37
---- This source file is free software; you can redistribute it   ----
38
---- and/or modify it under the terms of the GNU Lesser General   ----
39
---- Public License as published by the Free Software Foundation; ----
40
---- either version 2.1 of the License, or (at your option) any   ----
41
---- later version.                                               ----
42
----                                                              ----
43
---- This source is distributed in the hope that it will be       ----
44
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ----
45
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ----
46
---- PURPOSE. See the GNU Lesser General Public License for more  ----
47
---- details.                                                     ----
48
----                                                              ----
49
---- You should have received a copy of the GNU Lesser General    ----
50
---- Public License along with this source; if not, download it   ----
51
---- from http://www.opencores.org/lgpl.shtml                     ----
52
----                                                              ----
53
----------------------------------------------------------------------
54
library ieee;
55
use ieee.std_logic_1164.all;
56
use ieee.numeric_std.all;
57
use std.textio.all;
58
use work.txt_util.all;
59
use work.pltbutils_func_pkg.all;
60
use work.pltbutils_comp_pkg.all;
61
 
62
entity tb_pltbutils is
63
  generic (
64
    G_CLK_PERIOD  : time := 10 ns
65
  );
66
end entity tb_pltbutils;
67
 
68
architecture bhv of tb_pltbutils is
69
 
70
  -- Simulation status- and control signals
71
  signal test_num       : integer;
72
  signal test_name      : string(pltbutils_sc.test_name'range);
73
  signal info           : string(pltbutils_sc.info'range);
74
  signal checks         : integer;
75
  signal errors         : integer;
76
  signal stop_sim       : std_logic;
77
 
78
  -- Expected number of checks and number of errors to be reported
79
  -- by pltbutils. The counting is made by variables, but the
80
  -- variables are copied to these signals for easier viewing in
81
  -- the simulator's waveform window.
82
  signal expected_checks_cnt : integer := 0;
83
  signal expected_errors_cnt : integer := 0;
84
 
85
  -- DUT stimuli and response signals
86
  signal clk            : std_logic;
87
  signal clk_cnt        : integer := 0;
88
  signal clk_cnt_clr    : boolean := false;
89
  signal s_i            : integer;
90
  signal s_sl           : std_logic;
91
  signal s_slv          : std_logic_vector(7 downto 0);
92
  signal s_u            : unsigned(7 downto 0);
93
  signal s_s            : unsigned(7 downto 0);
94
 
95
begin
96
 
97
  -- Simulation status and control for viewing in waveform window
98
  test_num  <= pltbutils_sc.test_num;
99
  test_name <= pltbutils_sc.test_name;
100
  info      <= pltbutils_sc.info;
101
  checks    <= pltbutils_sc.chk_cnt;
102
  errors    <= pltbutils_sc.err_cnt;
103
  stop_sim  <= pltbutils_sc.stop_sim;
104
 
105
  -- Clock generator
106
  clkgen0 : pltbutils_clkgen
107
    generic map(
108
      G_PERIOD      => G_CLK_PERIOD
109
    )
110
    port map(
111
      clk_o         => clk,
112
      stop_sim_i    => stop_sim
113
    );
114
 
115
  -- Clock cycle counter
116
  p_clk_cnt : process (clk_cnt_clr, clk)
117
  begin
118
    if clk_cnt_clr then
119
      clk_cnt <= 0;
120
    elsif rising_edge(clk) then
121
      clk_cnt <= clk_cnt + 1;
122
    end if;
123
  end process p_clk_cnt;
124
 
125
  -- Testcase
126
  p_tc1 : process
127
    variable v_expected_checks_cnt : integer := 0;
128
    variable v_expected_errors_cnt : integer := 0;
129
  begin
130
 
131
    print("<Testing startsim()>");
132
    startsim("tc1", pltbutils_sc);
133
    wait until rising_edge(clk);
134
    assert test_num  = 0
135
      report "test_num after startsim() incorrect"
136
      severity error;
137
    print("<Done testing startsim()>");
138
 
139
    print("<Testing testname() with auto-incrementing test_num>");
140
    testname("TestName1", pltbutils_sc);
141
    wait until rising_edge(clk);
142
    assert test_num  = 1
143
      report "test_num after startsim() incorrect"
144
      severity error;
145
    print("<Done testing testname() with auto-incrementing test_num()>");
146
 
147
    print("<Testing testname() with explicit test_num>");
148
    testname(3, "TestName2", pltbutils_sc);
149
    wait until rising_edge(clk);
150
    assert test_num  = 3
151
      report "test_num after startsim() incorrect"
152
      severity error;
153
    print("<Done testing testname() with explicit test_num>");
154
 
155
    print("<Testing waitclks()>");
156
    clk_cnt_clr <= true;
157
    wait until rising_edge(clk);
158
    clk_cnt_clr <= false;
159
    wait until rising_edge(clk);
160
    waitclks(10, clk, pltbutils_sc);
161
    assert clk_cnt = 10
162
      report "clk_cnt after waitclks() incorrect:" & integer'image(clk_cnt) &
163
             " expected:" & integer'image(10)
164
      severity error;
165
    print("<Done testing waitclks()>");
166
 
167
    print("<Testing check() integer>");
168
    s_i <= 0;
169
    wait until rising_edge(clk);
170
    check("Testing correct integer = 0", s_i, 0, pltbutils_sc);
171
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
172
    expected_checks_cnt   <= v_expected_checks_cnt;
173
    s_i <= 1;
174
    wait until rising_edge(clk);
175
    check("Testing correct integer = 1", s_i, 1, pltbutils_sc);
176
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
177
    expected_checks_cnt   <= v_expected_checks_cnt;
178
    s_i <= 17;
179
    wait until rising_edge(clk);
180
    check("Testing incorrect integer = 17", s_i, 18, pltbutils_sc);
181
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
182
    expected_checks_cnt   <= v_expected_checks_cnt;
183
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
184
    expected_errors_cnt   <= v_expected_errors_cnt;
185
    s_i <= -1;
186
    wait until rising_edge(clk);
187
    check("Testing negative integer = -1", s_i, -1, pltbutils_sc);
188
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
189
    expected_checks_cnt   <= v_expected_checks_cnt;
190
 
191
    print("<Done testing check() integer>");
192
 
193
    print("<Testing check() std_logic>");
194
    s_sl <= '0';
195
    wait until rising_edge(clk);
196
    check("Testing correct std_logic = '0'", s_sl, '0', pltbutils_sc);
197
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
198
    expected_checks_cnt   <= v_expected_checks_cnt;
199
    s_sl <= '1';
200
    wait until rising_edge(clk);
201
    check("Testing correct std_logic = '1'", s_sl, '1', pltbutils_sc);
202
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
203
    expected_checks_cnt   <= v_expected_checks_cnt;
204
    s_sl <= 'X';
205
    wait until rising_edge(clk);
206
    check("Testing incorrect std_logic = '1'", s_sl, '1', pltbutils_sc);
207
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
208
    expected_checks_cnt   <= v_expected_checks_cnt;
209
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
210
    expected_errors_cnt   <= v_expected_errors_cnt;
211
    print("<Done testing check() std_logic>");
212
 
213
    print("<Testing check() std_logic against integer>");
214
    s_sl <= '0';
215
    wait until rising_edge(clk);
216
    check("Testing correct std_logic = '0'", s_sl, 0, pltbutils_sc);
217
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
218
    expected_checks_cnt   <= v_expected_checks_cnt;
219
    s_sl <= '1';
220
    wait until rising_edge(clk);
221
    check("Testing correct std_logic = '1'", s_sl, 1, pltbutils_sc);
222
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
223
    expected_checks_cnt   <= v_expected_checks_cnt;
224
    s_sl <= 'X';
225
    wait until rising_edge(clk);
226
    check("Testing incorrect std_logic = '1'", s_sl, 1, pltbutils_sc);
227
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
228
    expected_checks_cnt   <= v_expected_checks_cnt;
229
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
230
    expected_errors_cnt   <= v_expected_errors_cnt;
231
    s_sl <= '1';
232
    wait until rising_edge(clk);
233
    check("Testing std_logic = '1' with incorrect expected", s_sl, 2, pltbutils_sc);
234
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
235
    expected_checks_cnt   <= v_expected_checks_cnt;
236
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
237
    expected_errors_cnt   <= v_expected_errors_cnt;
238
    print("<Done testing check() std_logic against integer>");
239
 
240
    print("<Testing check() std_logic_vector>");
241
    s_slv <= x"00";
242
    wait until rising_edge(clk);
243
    check("Testing correct std_logic_vector = x'00'", s_slv, x"00", pltbutils_sc);
244
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
245
    expected_checks_cnt   <= v_expected_checks_cnt;
246
    s_slv <= x"47";
247
    wait until rising_edge(clk);
248
    check("Testing correct std_logic_vector = x'47'", s_slv, x"47", pltbutils_sc);
249
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
250
    expected_checks_cnt   <= v_expected_checks_cnt;
251
    s_slv <= x"11";
252
    wait until rising_edge(clk);
253
    check("Testing incorrect std_logic_vector = x'11'", s_slv, x"10", pltbutils_sc);
254
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
255
    expected_checks_cnt   <= v_expected_checks_cnt;
256
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
257
    expected_errors_cnt   <= v_expected_errors_cnt;
258
    print("<Done testing check() std_logic_vector>");
259
 
260
    print("<Testing check() std_logic_vector with mask>");
261
    s_slv <= x"47";
262
    wait until rising_edge(clk);
263
    check("Testing std_logic_vector = x'47' with correct nibble mask", s_slv, x"57", x"0F", pltbutils_sc);
264
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
265
    expected_checks_cnt   <= v_expected_checks_cnt;
266
    s_slv <= x"47";
267
    wait until rising_edge(clk);
268
    check("Testing std_logic_vector = x'47' with incorrect nibble mask", s_slv, x"57", x"F0", pltbutils_sc);
269
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
270
    expected_checks_cnt   <= v_expected_checks_cnt;
271
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
272
    expected_errors_cnt   <= v_expected_errors_cnt;
273
    print("<Done testing check() std_logic_vector with mask>");
274
 
275
    print("<Testing check() std_logic_vector against integer>");
276
    s_slv <= x"00";
277
    wait until rising_edge(clk);
278
    check("Testing correct std_logic_vector = x'00'", s_slv, 0, pltbutils_sc);
279
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
280
    expected_checks_cnt   <= v_expected_checks_cnt;
281
    s_slv <= x"47";
282
    wait until rising_edge(clk);
283
    check("Testing correct std_logic_vector = x'47'", s_slv, 16#47#, pltbutils_sc);
284
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
285
    expected_checks_cnt   <= v_expected_checks_cnt;
286
    s_slv <= x"11";
287
    wait until rising_edge(clk);
288
    check("Testing incorrect std_logic_vector = x'11'", s_slv, 16#10#, pltbutils_sc);
289
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
290
    expected_checks_cnt   <= v_expected_checks_cnt;
291
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
292
    expected_errors_cnt   <= v_expected_errors_cnt;
293
    s_slv <= x"FF";
294
    wait until rising_edge(clk);
295
    check("Testing negative std_logic_vector = x'FF'", s_slv, -1, pltbutils_sc);
296
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
297
    expected_checks_cnt   <= v_expected_checks_cnt;
298
    print("<Done testing check() std_logic_vector against integer>");
299
 
300
    print("<Testing check() std_logic_vector with mask against integer>");
301
    s_slv <= x"47";
302
    wait until rising_edge(clk);
303
    check("Testing std_logic_vector = x'47' with correct nibble mask", s_slv, 16#57#, x"0F", pltbutils_sc);
304
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
305
    expected_checks_cnt   <= v_expected_checks_cnt;
306
    s_slv <= x"47";
307
    wait until rising_edge(clk);
308
    check("Testing std_logic_vector = x'47' with incorrect nibble mask", s_slv, 16#57#, x"F0", pltbutils_sc);
309
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
310
    expected_checks_cnt   <= v_expected_checks_cnt;
311
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
312
    expected_errors_cnt   <= v_expected_errors_cnt;
313
    print("<Done testing check() std_logic_vector with mask against integer>");
314
 
315
    print("<Testing check() unsigned>");
316
    s_u <= x"00";
317
    wait until rising_edge(clk);
318
    check("Testing correct unsigned = x'00'", s_u, x"00", pltbutils_sc);
319
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
320
    expected_checks_cnt   <= v_expected_checks_cnt;
321
    s_u <= x"47";
322
    wait until rising_edge(clk);
323
    check("Testing correct unsigned = x'47'", s_u, x"47", pltbutils_sc);
324
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
325
    expected_checks_cnt   <= v_expected_checks_cnt;
326
    s_u <= x"11";
327
    wait until rising_edge(clk);
328
    check("Testing incorrect unsigned = x'11'", s_u, x"10", pltbutils_sc);
329
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
330
    expected_checks_cnt   <= v_expected_checks_cnt;
331
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
332
    expected_errors_cnt   <= v_expected_errors_cnt;
333
    print("<Done testing check() unsigned>");
334
 
335
    print("<Testing check() unsigned against integer>");
336
    s_u <= x"00";
337
    wait until rising_edge(clk);
338
    check("Testing correct unsigned = x'00'", s_u, 0, pltbutils_sc);
339
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
340
    expected_checks_cnt   <= v_expected_checks_cnt;
341
    s_u <= x"47";
342
    wait until rising_edge(clk);
343
    check("Testing correct unsigned = x'47'", s_u, 16#47#, pltbutils_sc);
344
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
345
    expected_checks_cnt   <= v_expected_checks_cnt;
346
    s_u <= x"11";
347
    wait until rising_edge(clk);
348
    check("Testing incorrect unsigned = x'11'", s_u, 16#10#, pltbutils_sc);
349
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
350
    expected_checks_cnt   <= v_expected_checks_cnt;
351
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
352
    expected_errors_cnt   <= v_expected_errors_cnt;
353
    print("<Done testing check() unsigned against integer>");
354
 
355
    print("<Testing check() signed>");
356
    s_s <= x"00";
357
    wait until rising_edge(clk);
358
    check("Testing correct signed = x'00'", s_s, x"00", pltbutils_sc);
359
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
360
    expected_checks_cnt   <= v_expected_checks_cnt;
361
    s_s <= x"47";
362
    wait until rising_edge(clk);
363
    check("Testing correct signed = x'47'", s_s, x"47", pltbutils_sc);
364
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
365
    expected_checks_cnt   <= v_expected_checks_cnt;
366
    s_s <= x"11";
367
    wait until rising_edge(clk);
368
    check("Testing incorrect signed = x'11'", s_s, x"10", pltbutils_sc);
369
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
370
    expected_checks_cnt   <= v_expected_checks_cnt;
371
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
372
    expected_errors_cnt   <= v_expected_errors_cnt;
373
    s_s <= x"FF";
374
    wait until rising_edge(clk);
375
    check("Testing negative signed = x'FF'", s_s, x"FF", pltbutils_sc);
376
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
377
    expected_checks_cnt   <= v_expected_checks_cnt;
378
    print("<Done testing check() signed>");
379
 
380
    print("<Testing check() signed against integer>");
381
    s_s <= x"00";
382
    wait until rising_edge(clk);
383
    check("Testing correct signed = x'00'", s_s, 0, pltbutils_sc);
384
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
385
    expected_checks_cnt   <= v_expected_checks_cnt;
386
    s_s <= x"47";
387
    wait until rising_edge(clk);
388
    check("Testing correct signed = x'47'", s_s, 16#47#, pltbutils_sc);
389
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
390
    expected_checks_cnt   <= v_expected_checks_cnt;
391
    s_s <= x"11";
392
    wait until rising_edge(clk);
393
    check("Testing incorrect signed = x'11'", s_s, 16#10#, pltbutils_sc);
394
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
395
    expected_checks_cnt   <= v_expected_checks_cnt;
396
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
397
    expected_errors_cnt   <= v_expected_errors_cnt;
398
    s_s <= x"FF";
399
    wait until rising_edge(clk);
400
    print("The following check fails in ModelSim for unknown reason." &
401
          " It causes mismatch between expected number of errors" &
402
          " and the number presented by endsim()");
403
    check("Testing negative signed = x'FF'", s_s, -1, pltbutils_sc);
404
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
405
    expected_checks_cnt   <= v_expected_checks_cnt;
406
    print("<Done testing check() signed against integer>");
407
 
408
    print("<Testing check() boolean expression>");
409
    s_i <= 0;
410
    wait until rising_edge(clk);
411
    check("Testing correct boolean expression 0 = 16#00#", s_i = 16#00#, pltbutils_sc);
412
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
413
    expected_checks_cnt   <= v_expected_checks_cnt;
414
    s_i <= 47;
415
    wait until rising_edge(clk);
416
    check("Testing incorrect boolean expression 47 < 16#10#", s_i < 16#10#, pltbutils_sc);
417
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
418
    expected_checks_cnt   <= v_expected_checks_cnt;
419
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
420
    expected_errors_cnt   <= v_expected_errors_cnt;
421
    print("<Done testing check() boolean expresson>");
422
 
423
    wait until rising_edge(clk);
424
    print("<Testing endsim()>");
425
    print("Expected number of checks: " & str(v_expected_checks_cnt));
426
    print("Expected number of errors: " & str(v_expected_errors_cnt));
427
    wait until rising_edge(clk);
428
    endsim(pltbutils_sc, true);
429
    wait until rising_edge(clk);
430
    print("<Done testing endsim()>");
431
    wait;
432
  end process p_tc1;
433
end architecture bhv;

powered by: WebSVN 2.1.0

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