PlTbUtils  1.3
PlTbUtils is a collection of functions, procedures and components for easily creating stimuli and checking response in automatic self-checking testbenches.
pltbutils_user_cfg_pkg.vhd
Go to the documentation of this file.
1 
40 
41 library ieee;
42  use ieee.std_logic_1164.all;
43  use ieee.numeric_std.all;
44  use std.textio.all;
45  --use std.env.all; -- Uncomment if using stop or finish in custom_stopsim() below.
46  use work.txt_util.all;
47 
58 
60 
61  -- Constants
62  -- The user is free to modify the values to fit his/her requirements.
63 
64  constant C_PLTBUTILS_USE_STD_STARTSIM_MSG : boolean := true;
65  constant C_PLTBUTILS_USE_STD_ENDSIM_MSG : boolean := true;
66  constant C_PLTBUTILS_USE_STD_STARTTEST_MSG : boolean := true;
67  constant C_PLTBUTILS_USE_STD_SKIPTEST_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_SKIPTEST_MSG : boolean := false;
76  constant C_PLTBUTILS_USE_CUSTOM_ENDTEST_MSG : boolean := false;
77  constant C_PLTBUTILS_USE_CUSTOM_CHECK_MSG : boolean := false;
78  constant C_PLTBUTILS_USE_CUSTOM_ERROR_MSG : boolean := false;
79  constant C_PLTBUTILS_USE_CUSTOM_STOPSIM : boolean := false;
80 
81  -- Procedure declarations
82  -- The user should NOT modify these.
83 
84  procedure custom_stopsim(
85  constant timestamp : in time
86  );
87 
89  constant testcase_name : in string;
90  constant timestamp : in time
91  );
92 
93  procedure custom_endsim_msg(
94  constant testcase_name : in string;
95  constant timestamp : in time;
96  constant num_tests : in integer;
97  constant num_skip_tests : in integer;
98  constant num_checks : in integer;
99  constant num_errors : in integer;
100  constant show_success_fail : in boolean
101  );
102 
104  constant test_num : in integer;
105  constant test_name : in string;
106  constant timestamp : in time
107  );
108 
110  constant test_num : in integer;
111  constant test_name : in string;
112  constant timestamp : in time
113  );
114 
116  constant test_num : in integer;
117  constant test_name : in string;
118  constant timestamp : in time;
119  constant test_active : in boolean;
120  constant num_checks_in_test : in integer;
121  constant num_errors_in_test : in integer
122  );
123 
124  procedure custom_check_msg(
125  constant rpt : in string;
126  constant timestamp : in time;
127  constant expr : in boolean;
128  constant actual : in string;
129  constant expected : in string;
130  constant mask : in string;
131  constant test_num : in integer;
132  constant test_name : in string;
133  constant check_num : in integer;
134  constant err_cnt_in_test : in integer
135  );
136 
137  procedure custom_error_msg(
138  constant rpt : in string;
139  constant timestamp : in time;
140  constant test_num : in integer;
141  constant test_name : in string;
142  constant err_cnt_in_test : in integer
143  );
144 
145  function tcfilter(
146  constant s : string
147  ) return string;
148 
149 end package pltbutils_user_cfg_pkg;
150 
151 package body pltbutils_user_cfg_pkg is
152 
153  -- Procedure definitions
154  -- The user should NOT modify the arguments,
155  -- but the behaviour is free to modify to fit the user's requirements.
156 
158  procedure custom_stopsim(
159  constant timestamp : in time
160  ) is
161  begin
162  -- The best way to stop a simulation differs between different simulators.
163  -- Below are some examples. Modify to suit your simulator.
164 
165  -- Works with some simulators that supports VHDL-2008.
166  -- Requires that 'use std.env.all' at the top of the file is uncommented.
167  --stop;
168 
169  -- Works with some simulators that support VHDL-2008.
170  -- Requires that 'use std.env.all' at the top of the file is uncommented.
171  --finish;
172 
173  -- Works in all simulators known by the author, but ugly.
174  assert false
175  report "--- FORCE END OF SIMULATION ---" &
176  " (ignore this false failure message, it's not a real failure)"
177  severity failure;
178 
179  end procedure custom_stopsim;
180 
188  procedure custom_startsim_msg(
189  constant testcase_name : in string;
190  constant timestamp : in time
191  ) is
192  begin
193  print("##teamcity[testSuiteStarted name='" & tcfilter(testcase_name) & "']");
194  end procedure custom_startsim_msg;
195 
197  procedure custom_endsim_msg(
198  constant testcase_name : in string;
199  constant timestamp : in time;
200  constant num_tests : in integer;
201  constant num_skip_tests : in integer;
202  constant num_checks : in integer;
203  constant num_errors : in integer;
204  constant show_success_fail : in boolean
205  ) is
206  begin
207  -- TeamCity ignores all arguments except testcase_name
208  print("##teamcity[testSuiteFinished name='" & tcfilter(testcase_name) & "']");
209  end procedure custom_endsim_msg;
210 
212  procedure custom_starttest_msg(
213  constant test_num : in integer;
214  constant test_name : in string;
215  constant timestamp : in time
216  ) is
217  begin
218  -- TeamCity ignores test_num and timestamp
219  print("##teamcity[testStarted name='" & tcfilter(test_name) & "']");
220  end procedure custom_starttest_msg;
221 
223  procedure custom_skiptest_msg(
224  constant test_num : in integer;
225  constant test_name : in string;
226  constant timestamp : in time
227  ) is
228  begin
229  -- TeamCity ignores test_num and timestamp
230  print("##teamcity[testIgnored name='" & tcfilter(test_name) & "']");
231  end procedure custom_skiptest_msg;
232 
234  procedure custom_endtest_msg(
235  constant test_num : in integer;
236  constant test_name : in string;
237  constant timestamp : in time;
238  constant test_active : in boolean;
239  constant num_checks_in_test : in integer;
240  constant num_errors_in_test : in integer
241  ) is
242  begin
243 
244  if (test_active) then
245  -- TeamCity ignores all arguments except test_name
246  print("##teamcity[testFinished name='" & tcfilter(test_name) & "']");
247  end if;
248 
249  end procedure custom_endtest_msg;
250 
252  procedure custom_check_msg(
253  constant rpt : in string;
254  constant timestamp : in time;
255  constant expr : in boolean;
256  constant actual : in string;
257  constant expected : in string;
258  constant mask : in string;
259  constant test_num : in integer;
260  constant test_name : in string;
261  constant check_num : in integer;
262  constant err_cnt_in_test : in integer
263  ) is
264  variable l : line;
265  constant C_NO_TAGS_STR : string := "!NO_TAGS!";
266  variable no_tags : boolean := false;
267  begin
268  if not expr then -- Output message only if the check fails
269  if err_cnt_in_test <= 1 then -- TeamCity allows max one error message per test
270  if mask'length = C_NO_TAGS_STR'length then
271  if mask = C_NO_TAGS_STR then
272  no_tags := true;
273  end if;
274  end if;
275  if no_tags then
276  write(l, "##teamcity[testFailed name='" & tcfilter(test_name) & "'");
277  write(l, " message='" & tcfilter(rpt) & "'");
278  if actual /= "" or expected /= "" then
279  write(l, " details='" & tcfilter(actual));
280  if actual /= "" and expected /= "" then
281  write(l, string'(" "));
282  end if;
283  write(l, tcfilter(expected) & "'");
284  end if;
285  write(l, string'("]"));
286  else
287  write(l, "##teamcity[testFailed type='comparisonFailure' name='" & tcfilter(test_name) & "'");
288  if expected /= "" then
289  write(l, " expected='" & tcfilter(expected) & "'");
290  end if;
291  if actual /= "" then
292  write(l, " actual='" & tcfilter(actual) & "'");
293  end if;
294  if mask /= "" then
295  write(l, " details='mask=" & tcfilter(mask) & "'");
296  end if;
297  write(l, string'("]"));
298  end if;
299  print(l.all);
300  else
301  print("(TeamCity error message filtered out, because max one message is allowed for each test)");
302  end if;
303  end if;
304 
305  end procedure custom_check_msg;
306 
308  procedure custom_error_msg(
309  constant rpt : in string;
310  constant timestamp : in time;
311  constant test_num : in integer;
312  constant test_name : in string;
313  constant err_cnt_in_test : in integer
314  ) is
315  begin
316 
317  if (err_cnt_in_test <= 1) then -- TeamCity allows max one error message per test
318  print("##teamcity[testFailed" &
319  "name='" & tcfilter(test_name) & "' " &
320  "message='" & tcfilter(rpt) & "']");
321  else
322  print("(TeamCity error message filtered out, because max one message is allowed for each test)");
323  end if;
324 
325  end procedure custom_error_msg;
326 
327  -- User's function and procedure definitions
328  -- Example for use with TeamCity. Remove, modify or replace
329  -- to suit other other continous integration tools or scripts, if you need to.
330 
338 
339  function tcfilter(
340  constant s : string
341  ) return string is
342  variable r : string(s'range) := (others => (' '));
343  begin
344  for i in s'range loop
345 
346  if (s(i) = ''') then
347  r(i) := '`';
348  elsif (s(i) = lf or s(i) = cr) then
349  r(i) := ' ';
350  elsif (s(i) = '|') then
351  r(i) := '/';
352  elsif (s(i) = '[') then
353  r(i) := '{';
354  elsif (s(i) = ']') then
355  r(i) := '}';
356  else
357  r(i) := s(i);
358  end if;
359 
360  end loop;
361  return r;
362  end function tcfilter;
363 
364 end package body pltbutils_user_cfg_pkg;
PlTbUtils User Configuration Package: User's function and procedure declarations.
boolean := false C_PLTBUTILS_USE_CUSTOM_STARTTEST_MSG
boolean := false C_PLTBUTILS_USE_CUSTOM_STOPSIM
custom_startsim_msgtestcase_name,timestamp,
custom_check_msgrpt,timestamp,expr,actual,expected,mask,test_num,test_name,check_num,err_cnt_in_test,
boolean := false C_PLTBUTILS_USE_CUSTOM_CHECK_MSG
boolean := false C_PLTBUTILS_USE_CUSTOM_ENDSIM_MSG
boolean := true C_PLTBUTILS_USE_STD_STARTTEST_MSG
custom_starttest_msgtest_num,test_name,timestamp,
boolean := false C_PLTBUTILS_USE_CUSTOM_ERROR_MSG
boolean := false C_PLTBUTILS_USE_CUSTOM_ENDTEST_MSG
boolean := false C_PLTBUTILS_USE_CUSTOM_STARTSIM_MSG
boolean := true C_PLTBUTILS_USE_STD_ERROR_MSG
custom_error_msgrpt,timestamp,test_num,test_name,err_cnt_in_test,
custom_endtest_msgtest_num,test_name,timestamp,test_active,num_checks_in_test,num_errors_in_test,
boolean := true C_PLTBUTILS_USE_STD_ENDSIM_MSG
boolean := true C_PLTBUTILS_USE_STD_STOPSIM
boolean := true C_PLTBUTILS_USE_STD_SKIPTEST_MSG
boolean := true C_PLTBUTILS_USE_STD_CHECK_MSG
boolean := true C_PLTBUTILS_USE_STD_STARTSIM_MSG
custom_skiptest_msgtest_num,test_name,timestamp,
boolean := true C_PLTBUTILS_USE_STD_ENDTEST_MSG
custom_endsim_msgtestcase_name,timestamp,num_tests,num_skip_tests,num_checks,num_errors,show_success_fail,
boolean := false C_PLTBUTILS_USE_CUSTOM_SKIPTEST_MSG
Defines useful functions an procedures for text handling text in VHDL.
Definition: txt_util.vhd:31