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

Subversion Repositories pltbutils

[/] [pltbutils/] [trunk/] [src/] [vhdl/] [pltbutils_user_cfg_pkg.vhd] - Blame information for rev 43

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

Line No. Rev Author Line
1 21 pela
----------------------------------------------------------------------
2
----                                                              ----
3
---- PlTbUtils User Configuration Package                         ----
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 file defines the user's customizations.                 ----
14
----                                                              ----
15
---- If the user wishes to modify anything in this file, it is    ----
16
---- recommended that he/she first copies it to another directory ----
17
---- and modifies the copy. Also make sure that the simulator     ----
18
---- read the modified file instead of the original.              ----
19
---- This makes it easier to update pltbutils to new versions     ----
20
---- without destroying the customizations.                       ----
21
----                                                              ----
22
---- To Do:                                                       ----
23
---- -                                                            ----
24
----                                                              ----
25
---- Author(s):                                                   ----
26
---- - Per Larsson, pela@opencores.org                            ----
27
----                                                              ----
28
----------------------------------------------------------------------
29
----                                                              ----
30
---- Copyright (C) 2014 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 35 pela
--use std.textio.all;
58 21 pela
--use std.env.all; -- Uncomment if using stop or finish in custom_stopsim() below.
59
use work.txt_util.all;
60
 
61
package pltbutils_user_cfg_pkg is
62
 
63
  --- Constants ---
64
  -- The user is free to modify the values to fit his/her requirements.
65
  constant C_PLTBUTILS_USE_STD_STARTSIM_MSG     : boolean := true;
66
  constant C_PLTBUTILS_USE_STD_ENDSIM_MSG       : boolean := true;
67
  constant C_PLTBUTILS_USE_STD_STARTTEST_MSG    : boolean := true;
68
  constant C_PLTBUTILS_USE_STD_ENDTEST_MSG      : boolean := true;
69
  constant C_PLTBUTILS_USE_STD_CHECK_MSG        : boolean := true;
70
  constant C_PLTBUTILS_USE_STD_ERROR_MSG        : boolean := true;
71
  constant C_PLTBUTILS_USE_STD_STOPSIM          : boolean := true;
72
  constant C_PLTBUTILS_USE_CUSTOM_STARTSIM_MSG  : boolean := false;
73
  constant C_PLTBUTILS_USE_CUSTOM_ENDSIM_MSG    : boolean := false;
74
  constant C_PLTBUTILS_USE_CUSTOM_STARTTEST_MSG : boolean := false;
75
  constant C_PLTBUTILS_USE_CUSTOM_ENDTEST_MSG   : boolean := false;
76
  constant C_PLTBUTILS_USE_CUSTOM_CHECK_MSG     : boolean := false;
77
  constant C_PLTBUTILS_USE_CUSTOM_ERROR_MSG     : boolean := false;
78
  constant C_PLTBUTILS_USE_CUSTOM_STOPSIM       : boolean := false;
79
 
80
  --- Procedure declarations ---
81
  -- The user should NOT modify these.
82
 
83 35 pela
  procedure custom_stopsim(
84
    constant timestamp          : in time
85
  );
86
 
87 21 pela
  procedure custom_startsim_msg(
88
    constant testcase_name      : in string;
89
    constant timestamp          : in time
90
  );
91
 
92
  procedure custom_endsim_msg(
93
    constant testcase_name      : in string;
94
    constant timestamp          : in time;
95
    constant num_tests          : in integer;
96
    constant num_checks         : in integer;
97
    constant num_errors         : in integer;
98
    constant show_success_fail  : in boolean
99
  );
100
 
101
  procedure custom_starttest_msg(
102
    constant test_num           : in integer;
103
    constant test_name          : in string;
104
    constant timestamp          : in time
105
  );
106
 
107
  procedure custom_endtest_msg(
108
    constant test_num           : in integer;
109
    constant test_name          : in string;
110
    constant timestamp          : in time;
111
    constant num_checks_in_test : in integer;
112
    constant num_errors_in_test : in integer
113
  );
114
 
115
  procedure custom_check_msg(
116
    constant rpt                : in string;
117 35 pela
    constant timestamp          : in time;
118 21 pela
    constant expr               : in boolean;
119
    constant actual             : in string;
120
    constant expected           : in string;
121
    constant mask               : in string;
122
    constant test_num           : in integer;
123
    constant test_name          : in string;
124
    constant check_num          : in integer;
125
    constant err_cnt_in_test    : in integer
126
  );
127
 
128
  procedure custom_error_msg(
129
    constant rpt                : in string;
130
    constant timestamp          : in time;
131
    constant test_num           : in integer;
132
    constant test_name          : in string;
133
    constant err_cnt_in_test    : in integer
134
  );
135 35 pela
 
136 21 pela
  --- User's function and procedure declarations ---
137
  -- Example for use with TeamCity. Remove, modify or replace
138
  -- to suit other other continous integration tools or scripts, if you need to.
139
  function tcfilter(
140
    constant s : string
141
  ) return string;
142
 
143
end package pltbutils_user_cfg_pkg;
144
 
145
package body pltbutils_user_cfg_pkg is
146
 
147
  --- Procedure definitions ---
148
  -- The user should NOT modify the arguments,
149
  -- but the behaviour is free to modify to fit the user's requirements.
150 35 pela
 
151
  procedure custom_stopsim(
152
    constant timestamp          : in time
153
  ) is
154
  begin
155
    -- The best way to stop a simulation differs between different simulators.
156
    -- Below are some examples. Modify to suit your simulator.
157
 
158
    -- Works with some simulators that supports VHDL-2008. 
159
    -- Requires that 'use std.env.all' at the top of the file is uncommented.
160
    --stop;
161
 
162
    -- Works with some simulators that support VHDL-2008. 
163
    -- Requires that 'use std.env.all' at the top of the file is uncommented.
164
    --finish;
165
 
166
    -- Works in all simulators known by the author, but ugly.
167
    assert false
168
    report "--- FORCE END OF SIMULATION ---" &
169
           " (ignore this false failure message, it's not a real failure)"
170
    severity failure;
171
 
172
  end procedure custom_stopsim;
173 21 pela
 
174
  -- Example custom messages for TeamCity.
175
  -- Edit to suit other continous integration tools or scripts, if you need to.
176
  -- General TeamCity information: http://www.jetbrains.com/teamcity/
177
  --                               http://en.wikipedia.org/wiki/Teamcity
178
  -- TeamCity test reporting:      http://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingTests
179
 
180
  procedure custom_startsim_msg(
181
    constant testcase_name      : in string;
182
    constant timestamp          : in time
183
  ) is
184
  begin
185
    print("##teamcity[testSuiteStarted name='" & tcfilter(testcase_name) & "']");
186
  end procedure custom_startsim_msg;
187
 
188
  procedure custom_endsim_msg(
189
    constant testcase_name      : in string;
190
    constant timestamp          : in time;
191
    constant num_tests          : in integer;
192
    constant num_checks         : in integer;
193
    constant num_errors         : in integer;
194
    constant show_success_fail  : in boolean
195
  ) is
196
  begin
197
    -- TeamCity ignores all arguments except testcase_name
198
    print("##teamcity[testSuiteFinished name='" & tcfilter(testcase_name) & "']");
199
  end procedure custom_endsim_msg;
200
 
201
  procedure custom_starttest_msg(
202
    constant test_num           : in integer;
203
    constant test_name          : in string;
204
    constant timestamp          : in time
205
  ) is
206
  begin
207
    -- TeamCity ignores test_num and timestamp
208
    print("##teamcity[testStarted name='" & tcfilter(test_name) & "']");
209
  end procedure custom_starttest_msg;
210
 
211
  procedure custom_endtest_msg(
212
    constant test_num           : in integer;
213
    constant test_name          : in string;
214
    constant timestamp          : in time;
215
    constant num_checks_in_test : in integer;
216
    constant num_errors_in_test : in integer
217
  ) is
218
  begin
219
    -- TeamCity ignores all arguments except test_name
220
    print("##teamcity[testFinished name='" & tcfilter(test_name) & "']");
221
  end procedure custom_endtest_msg;
222
 
223
  procedure custom_check_msg(
224
    constant rpt                : in string;
225 35 pela
    constant timestamp          : in time;
226 21 pela
    constant expr               : in boolean;
227
    constant actual             : in string;
228
    constant expected           : in string;
229
    constant mask               : in string;
230
    constant test_num           : in integer;
231
    constant test_name          : in string;
232
    constant check_num          : in integer;
233
    constant err_cnt_in_test    : in integer
234
  ) is
235
    variable comparison_str     : string(1 to 32) := (others => ' ');
236
    variable comparison_str_len : integer := 1;
237
    variable actual_str         : string(1 to 32) := (others => ' ');
238
    variable actual_str_len     : integer := 1;
239
    variable expected_str       : string(1 to 32) := (others => ' ');
240
    variable expected_str_len   : integer := 1;
241
    variable mask_str           : string(1 to 32) := (others => ' ');
242
    variable mask_str_len       : integer := 1;
243
  begin
244
    if not expr then -- Output message only if the check fails
245
      if err_cnt_in_test <= 1 then -- TeamCity allows max one error message per test
246
        if actual /= "" then
247
          actual_str_len := 10 + actual'length;
248
          actual_str(1 to actual_str_len) := " actual='" & tcfilter(actual) & "'";
249
        end if;
250
        if expected /= "" then
251
          comparison_str_len := 26;
252
          comparison_str(1 to comparison_str_len) := " type='comparisonFailure' ";
253
          expected_str_len := 12 + expected'length;
254
          expected_str(1 to expected_str_len) := " expected='" & tcfilter(expected) & "'";
255
        end if;
256
        if mask /= "" then
257
          mask_str_len := 17 + mask'length;
258
          mask_str(1 to mask_str_len) := " details='mask=" & tcfilter(mask) & "' ";
259
        end if;
260
        print("##teamcity[testFailed" &
261
              comparison_str(1 to comparison_str_len) &
262
              "name='" & tcfilter(test_name) & "' " &
263
              "message='" & tcfilter(rpt) & "' " &
264
              expected_str(1 to expected_str_len) &
265
              actual_str(1 to actual_str_len) &
266
              mask_str(1 to mask_str_len) &
267
              "]");
268
      else
269
        print("(TeamCity error message filtered out, because max one message is allowed for each test)");
270
      end if;
271
    end if;
272
  end procedure custom_check_msg;
273
 
274
  procedure custom_error_msg(
275
    constant rpt                : in string;
276
    constant timestamp          : in time;
277
    constant test_num           : in integer;
278
    constant test_name          : in string;
279
    constant err_cnt_in_test    : in integer
280
  ) is
281
  begin
282
    if err_cnt_in_test <= 1 then -- TeamCity allows max one error message per test
283
      print("##teamcity[testFailed" &
284
            "name='" & tcfilter(test_name) & "' " &
285
            "message='" & tcfilter(rpt) & "']");
286
    else
287
      print("(TeamCity error message filtered out, because max one message is allowed for each test)");
288
    end if;
289
  end procedure custom_error_msg;
290
 
291
  --- User's function and procedure definitions ---
292
  -- Example for use with TeamCity. Remove, modify or replace
293
  -- to suit other other continous integration tools or scripts, if you need to.
294
 
295
  -- TeamCity string filter. Filters out characters which are not allowed in TeamCity messages.
296
  -- Search for "escaped values" in 
297
  --   http://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingTests
298
  -- The TeamCity escape character is not used, because that changes the length of the string.
299
  -- The VHDL code can be simplified if it doesn't have to deal with changes of string
300
  -- lengths. 
301
  function tcfilter(
302
    constant s : string
303
  ) return string is
304
    variable r : string(s'range) := (others => (' '));
305
  begin
306
    for i in s'range loop
307
      if s(i) = ''' then
308
        r(i) := '`';
309
      elsif s(i) = lf or s(i) = cr then
310
        r(i) := ' ';
311
      elsif s(i) = '|' then
312
        r(i) := '/';
313
      elsif s(i) = '[' then
314
        r(i) := '{';
315
      elsif s(i) = ']' then
316
        r(i) := '}';
317
      else
318
        r(i) := s(i);
319
      end if;
320
    end loop;
321
    return r;
322
  end function tcfilter;
323
 
324
end package body pltbutils_user_cfg_pkg;

powered by: WebSVN 2.1.0

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