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

Subversion Repositories pltbutils

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

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 25 pela
    variable v_expected_tests_cnt  : integer := 0;
128 2 pela
    variable v_expected_checks_cnt : integer := 0;
129
    variable v_expected_errors_cnt : integer := 0;
130
  begin
131
 
132
    print("<Testing startsim()>");
133
    startsim("tc1", pltbutils_sc);
134
    wait until rising_edge(clk);
135
    assert test_num  = 0
136
      report "test_num after startsim() incorrect"
137
      severity error;
138
    print("<Done testing startsim()>");
139
 
140 25 pela
    print("<Testing starttest() with auto-incrementing test_num>");
141
    starttest("TestName1", pltbutils_sc);
142
    v_expected_tests_cnt := v_expected_tests_cnt + 1;
143 2 pela
    wait until rising_edge(clk);
144
    assert test_num  = 1
145 25 pela
      report "test_num after starttest() incorrect"
146 2 pela
      severity error;
147 25 pela
    print("<Done testing starttest() with auto-incrementing test_num()>");
148 2 pela
 
149 25 pela
    print("<Testing endtest()>");
150
    endtest(pltbutils_sc);
151
    print("<Done testing endtest()>");
152
 
153
    print("<Testing starttest() with explicit test_num>");
154
    starttest(3, "TestName2", pltbutils_sc);
155
    v_expected_tests_cnt := v_expected_tests_cnt + 1;
156 2 pela
    wait until rising_edge(clk);
157
    assert test_num  = 3
158
      report "test_num after startsim() incorrect"
159
      severity error;
160 25 pela
    print("<Done testing starttest() with explicit test_num>");
161 2 pela
 
162
    print("<Testing waitclks()>");
163
    clk_cnt_clr <= true;
164
    wait until rising_edge(clk);
165
    clk_cnt_clr <= false;
166
    wait until rising_edge(clk);
167
    waitclks(10, clk, pltbutils_sc);
168
    assert clk_cnt = 10
169
      report "clk_cnt after waitclks() incorrect:" & integer'image(clk_cnt) &
170
             " expected:" & integer'image(10)
171
      severity error;
172
    print("<Done testing waitclks()>");
173
 
174
    print("<Testing check() integer>");
175
    s_i <= 0;
176
    wait until rising_edge(clk);
177
    check("Testing correct integer = 0", s_i, 0, pltbutils_sc);
178
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
179
    expected_checks_cnt   <= v_expected_checks_cnt;
180
    s_i <= 1;
181
    wait until rising_edge(clk);
182
    check("Testing correct integer = 1", s_i, 1, pltbutils_sc);
183
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
184
    expected_checks_cnt   <= v_expected_checks_cnt;
185
    s_i <= 17;
186
    wait until rising_edge(clk);
187
    check("Testing incorrect integer = 17", s_i, 18, pltbutils_sc);
188
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
189
    expected_checks_cnt   <= v_expected_checks_cnt;
190
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
191
    expected_errors_cnt   <= v_expected_errors_cnt;
192
    s_i <= -1;
193
    wait until rising_edge(clk);
194
    check("Testing negative integer = -1", s_i, -1, pltbutils_sc);
195
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
196
    expected_checks_cnt   <= v_expected_checks_cnt;
197
 
198
    print("<Done testing check() integer>");
199
 
200
    print("<Testing check() std_logic>");
201
    s_sl <= '0';
202
    wait until rising_edge(clk);
203
    check("Testing correct std_logic = '0'", s_sl, '0', pltbutils_sc);
204
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
205
    expected_checks_cnt   <= v_expected_checks_cnt;
206
    s_sl <= '1';
207
    wait until rising_edge(clk);
208
    check("Testing correct std_logic = '1'", s_sl, '1', pltbutils_sc);
209
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
210
    expected_checks_cnt   <= v_expected_checks_cnt;
211
    s_sl <= 'X';
212
    wait until rising_edge(clk);
213
    check("Testing incorrect std_logic = '1'", s_sl, '1', pltbutils_sc);
214
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
215
    expected_checks_cnt   <= v_expected_checks_cnt;
216
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
217
    expected_errors_cnt   <= v_expected_errors_cnt;
218
    print("<Done testing check() std_logic>");
219
 
220
    print("<Testing check() std_logic against integer>");
221
    s_sl <= '0';
222
    wait until rising_edge(clk);
223
    check("Testing correct std_logic = '0'", s_sl, 0, pltbutils_sc);
224
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
225
    expected_checks_cnt   <= v_expected_checks_cnt;
226
    s_sl <= '1';
227
    wait until rising_edge(clk);
228
    check("Testing correct std_logic = '1'", s_sl, 1, pltbutils_sc);
229
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
230
    expected_checks_cnt   <= v_expected_checks_cnt;
231
    s_sl <= 'X';
232
    wait until rising_edge(clk);
233
    check("Testing incorrect std_logic = '1'", s_sl, 1, 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
    s_sl <= '1';
239
    wait until rising_edge(clk);
240
    check("Testing std_logic = '1' with incorrect expected", s_sl, 2, pltbutils_sc);
241
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
242
    expected_checks_cnt   <= v_expected_checks_cnt;
243
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
244
    expected_errors_cnt   <= v_expected_errors_cnt;
245
    print("<Done testing check() std_logic against integer>");
246
 
247
    print("<Testing check() std_logic_vector>");
248
    s_slv <= x"00";
249
    wait until rising_edge(clk);
250
    check("Testing correct std_logic_vector = x'00'", s_slv, x"00", pltbutils_sc);
251
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
252
    expected_checks_cnt   <= v_expected_checks_cnt;
253
    s_slv <= x"47";
254
    wait until rising_edge(clk);
255
    check("Testing correct std_logic_vector = x'47'", s_slv, x"47", pltbutils_sc);
256
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
257
    expected_checks_cnt   <= v_expected_checks_cnt;
258
    s_slv <= x"11";
259
    wait until rising_edge(clk);
260
    check("Testing incorrect std_logic_vector = x'11'", s_slv, x"10", pltbutils_sc);
261
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
262
    expected_checks_cnt   <= v_expected_checks_cnt;
263
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
264
    expected_errors_cnt   <= v_expected_errors_cnt;
265
    print("<Done testing check() std_logic_vector>");
266
 
267
    print("<Testing check() std_logic_vector with mask>");
268
    s_slv <= x"47";
269
    wait until rising_edge(clk);
270
    check("Testing std_logic_vector = x'47' with correct nibble mask", s_slv, x"57", x"0F", pltbutils_sc);
271
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
272
    expected_checks_cnt   <= v_expected_checks_cnt;
273
    s_slv <= x"47";
274
    wait until rising_edge(clk);
275
    check("Testing std_logic_vector = x'47' with incorrect nibble mask", s_slv, x"57", x"F0", pltbutils_sc);
276
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
277
    expected_checks_cnt   <= v_expected_checks_cnt;
278
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
279
    expected_errors_cnt   <= v_expected_errors_cnt;
280
    print("<Done testing check() std_logic_vector with mask>");
281
 
282
    print("<Testing check() std_logic_vector against integer>");
283
    s_slv <= x"00";
284
    wait until rising_edge(clk);
285
    check("Testing correct std_logic_vector = x'00'", s_slv, 0, pltbutils_sc);
286
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
287
    expected_checks_cnt   <= v_expected_checks_cnt;
288
    s_slv <= x"47";
289
    wait until rising_edge(clk);
290
    check("Testing correct std_logic_vector = x'47'", s_slv, 16#47#, pltbutils_sc);
291
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
292
    expected_checks_cnt   <= v_expected_checks_cnt;
293
    s_slv <= x"11";
294
    wait until rising_edge(clk);
295
    check("Testing incorrect std_logic_vector = x'11'", s_slv, 16#10#, pltbutils_sc);
296
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
297
    expected_checks_cnt   <= v_expected_checks_cnt;
298
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
299
    expected_errors_cnt   <= v_expected_errors_cnt;
300
    s_slv <= x"FF";
301
    wait until rising_edge(clk);
302
    check("Testing negative std_logic_vector = x'FF'", s_slv, -1, pltbutils_sc);
303
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
304
    expected_checks_cnt   <= v_expected_checks_cnt;
305
    print("<Done testing check() std_logic_vector against integer>");
306
 
307
    print("<Testing check() std_logic_vector with mask against integer>");
308
    s_slv <= x"47";
309
    wait until rising_edge(clk);
310
    check("Testing std_logic_vector = x'47' with correct nibble mask", s_slv, 16#57#, x"0F", pltbutils_sc);
311
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
312
    expected_checks_cnt   <= v_expected_checks_cnt;
313
    s_slv <= x"47";
314
    wait until rising_edge(clk);
315
    check("Testing std_logic_vector = x'47' with incorrect nibble mask", s_slv, 16#57#, x"F0", pltbutils_sc);
316
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
317
    expected_checks_cnt   <= v_expected_checks_cnt;
318
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
319
    expected_errors_cnt   <= v_expected_errors_cnt;
320
    print("<Done testing check() std_logic_vector with mask against integer>");
321
 
322
    print("<Testing check() unsigned>");
323
    s_u <= x"00";
324
    wait until rising_edge(clk);
325
    check("Testing correct unsigned = x'00'", s_u, x"00", pltbutils_sc);
326
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
327
    expected_checks_cnt   <= v_expected_checks_cnt;
328
    s_u <= x"47";
329
    wait until rising_edge(clk);
330
    check("Testing correct unsigned = x'47'", s_u, x"47", pltbutils_sc);
331
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
332
    expected_checks_cnt   <= v_expected_checks_cnt;
333
    s_u <= x"11";
334
    wait until rising_edge(clk);
335
    check("Testing incorrect unsigned = x'11'", s_u, x"10", pltbutils_sc);
336
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
337
    expected_checks_cnt   <= v_expected_checks_cnt;
338
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
339
    expected_errors_cnt   <= v_expected_errors_cnt;
340
    print("<Done testing check() unsigned>");
341
 
342
    print("<Testing check() unsigned against integer>");
343
    s_u <= x"00";
344
    wait until rising_edge(clk);
345
    check("Testing correct unsigned = x'00'", s_u, 0, pltbutils_sc);
346
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
347
    expected_checks_cnt   <= v_expected_checks_cnt;
348
    s_u <= x"47";
349
    wait until rising_edge(clk);
350
    check("Testing correct unsigned = x'47'", s_u, 16#47#, pltbutils_sc);
351
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
352
    expected_checks_cnt   <= v_expected_checks_cnt;
353
    s_u <= x"11";
354
    wait until rising_edge(clk);
355
    check("Testing incorrect unsigned = x'11'", s_u, 16#10#, pltbutils_sc);
356
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
357
    expected_checks_cnt   <= v_expected_checks_cnt;
358
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
359
    expected_errors_cnt   <= v_expected_errors_cnt;
360
    print("<Done testing check() unsigned against integer>");
361
 
362
    print("<Testing check() signed>");
363
    s_s <= x"00";
364
    wait until rising_edge(clk);
365
    check("Testing correct signed = x'00'", s_s, x"00", pltbutils_sc);
366
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
367
    expected_checks_cnt   <= v_expected_checks_cnt;
368
    s_s <= x"47";
369
    wait until rising_edge(clk);
370
    check("Testing correct signed = x'47'", s_s, x"47", pltbutils_sc);
371
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
372
    expected_checks_cnt   <= v_expected_checks_cnt;
373
    s_s <= x"11";
374
    wait until rising_edge(clk);
375
    check("Testing incorrect signed = x'11'", s_s, x"10", pltbutils_sc);
376
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
377
    expected_checks_cnt   <= v_expected_checks_cnt;
378
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
379
    expected_errors_cnt   <= v_expected_errors_cnt;
380
    s_s <= x"FF";
381
    wait until rising_edge(clk);
382
    check("Testing negative signed = x'FF'", s_s, x"FF", pltbutils_sc);
383
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
384
    expected_checks_cnt   <= v_expected_checks_cnt;
385
    print("<Done testing check() signed>");
386
 
387
    print("<Testing check() signed against integer>");
388
    s_s <= x"00";
389
    wait until rising_edge(clk);
390
    check("Testing correct signed = x'00'", s_s, 0, pltbutils_sc);
391
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
392
    expected_checks_cnt   <= v_expected_checks_cnt;
393
    s_s <= x"47";
394
    wait until rising_edge(clk);
395
    check("Testing correct signed = x'47'", s_s, 16#47#, pltbutils_sc);
396
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
397
    expected_checks_cnt   <= v_expected_checks_cnt;
398
    s_s <= x"11";
399
    wait until rising_edge(clk);
400
    check("Testing incorrect signed = x'11'", s_s, 16#10#, pltbutils_sc);
401
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
402
    expected_checks_cnt   <= v_expected_checks_cnt;
403
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
404
    expected_errors_cnt   <= v_expected_errors_cnt;
405
    s_s <= x"FF";
406
    wait until rising_edge(clk);
407
    print("The following check fails in ModelSim for unknown reason." &
408
          " It causes mismatch between expected number of errors" &
409
          " and the number presented by endsim()");
410
    check("Testing negative signed = x'FF'", s_s, -1, pltbutils_sc);
411
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
412
    expected_checks_cnt   <= v_expected_checks_cnt;
413
    print("<Done testing check() signed against integer>");
414
 
415
    print("<Testing check() boolean expression>");
416
    s_i <= 0;
417
    wait until rising_edge(clk);
418
    check("Testing correct boolean expression 0 = 16#00#", s_i = 16#00#, pltbutils_sc);
419
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
420
    expected_checks_cnt   <= v_expected_checks_cnt;
421
    s_i <= 47;
422
    wait until rising_edge(clk);
423
    check("Testing incorrect boolean expression 47 < 16#10#", s_i < 16#10#, pltbutils_sc);
424
    v_expected_checks_cnt := v_expected_checks_cnt + 1;
425
    expected_checks_cnt   <= v_expected_checks_cnt;
426
    v_expected_errors_cnt := v_expected_errors_cnt + 1;
427
    expected_errors_cnt   <= v_expected_errors_cnt;
428
    print("<Done testing check() boolean expresson>");
429 25 pela
 
430
    print("<Testing endtest()>");
431
    endtest(pltbutils_sc);
432
    print("<Done testing endtest()>");
433 2 pela
 
434
    wait until rising_edge(clk);
435
    print("<Testing endsim()>");
436 25 pela
    print("Expected number of tests:  " & str(v_expected_tests_cnt));
437 2 pela
    print("Expected number of checks: " & str(v_expected_checks_cnt));
438
    print("Expected number of errors: " & str(v_expected_errors_cnt));
439
    wait until rising_edge(clk);
440
    endsim(pltbutils_sc, true);
441
    wait until rising_edge(clk);
442
    print("<Done testing endsim()>");
443
    wait;
444
  end process p_tc1;
445
end architecture bhv;

powered by: WebSVN 2.1.0

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