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
|
------------------------------------------------------------------------------
-- Copyright (c) 2018 by Paul Scherrer Institute, Switzerland
-- All rights reserved.
-- Authors: Oliver Bruendler, Benoit Stef
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Libraries
------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library work;
use work.psi_tb_txt_util.all;
------------------------------------------------------------------------------
-- Package Header
------------------------------------------------------------------------------
package psi_tb_compare_pkg is
-- returns an index string in the form "[3]"
function IndexString( Index : integer) return string;
-- std_logic_vector compare to integer
procedure StdlvCompareInt ( Expected : in integer;
Actual : in std_logic_vector;
Msg : in string;
IsSigned : in boolean := true;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ");
-- std_logic_vector compare to std_logic_vector
procedure StdlvCompareStdlv (Expected : in std_logic_vector;
Actual : in std_logic_vector;
Msg : in string;
Prefix : in string := "###ERROR###: ");
-- std_logic compare std_logic
procedure StdlCompare( Expected : in integer range 0 to 1;
Actual : in std_logic;
Msg : in string;
Prefix : in string := "###ERROR###: ");
-- integer compare to integer
procedure IntCompare( Expected : in integer;
Actual : in integer;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ");
-- real compare to real
procedure RealCompare( Expected : in real;
Actual : in real;
Msg : in string;
Tolerance : in real := 0.0;
Prefix : in string := "###ERROR###: ");
-- signed compare to signed
procedure SignCompare ( Expected : in signed;
Actual : in signed;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ");
-- unsigned compare to unsigned
procedure UsignCompare (Expected : in unsigned;
Actual : in unsigned;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ");
-- signed compare to integer
procedure SignCompareInt ( Expected : in integer;
Actual : in signed;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ");
-- unsigned compare to integer
procedure UsignCompareInt ( Expected : in integer;
Actual : in unsigned;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ");
end psi_tb_compare_pkg;
------------------------------------------------------------------------------
-- Package Body
------------------------------------------------------------------------------
package body psi_tb_compare_pkg is
-- *** IndexString ***
function IndexString( Index : integer) return string is
begin
return "[" & to_string(Index) & "]";
end function;
-- *** StdlvCompareInt ***
procedure StdlvCompareInt ( Expected : in integer;
Actual : in std_logic_vector;
Msg : in string;
IsSigned : in boolean := true;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ") is
variable ActualInt_v : integer;
variable ExpectedStdlv32_v : std_logic_vector(31 downto 0);
variable ActualStdlv32_v : std_logic_vector(31 downto 0);
begin
-- Convert Input
if IsSigned then
ActualInt_v := to_integer(signed(Actual));
ExpectedStdlv32_v := std_logic_vector(to_signed(Expected, 32));
ActualStdlv32_v := std_logic_vector(to_signed(ActualInt_v, 32));
else
ActualInt_v := to_integer(unsigned(Actual));
ExpectedStdlv32_v := std_logic_vector(to_unsigned(Expected, 32));
ActualStdlv32_v := std_logic_vector(to_unsigned(ActualInt_v, 32));
end if;
-- Assertion
assert (ActualInt_v >= Expected-Tolerance) and (ActualInt_v <= Expected+Tolerance)
report Prefix & Msg &
" [Expected " & integer'image(Expected) & "(0x" & hstr(ExpectedStdlv32_v) & ")" &
", Received " & integer'image(ActualInt_v) & "(0x" & hstr(ActualStdlv32_v) & ")" &
", Tolerance " & integer'image(Tolerance) & "]"
severity error;
end procedure;
-- *** StdlvCompareStdlv ***
procedure StdlvCompareStdlv ( Expected : in std_logic_vector;
Actual : in std_logic_vector;
Msg : in string;
Prefix : in string := "###ERROR###: ") is
constant Expected_c : std_logic_vector(Expected'length-1 downto 0) := Expected;
constant Actual_c : std_logic_vector(Actual'length-1 downto 0) := Actual;
begin
-- Assertion
assert Actual_c = Expected_c
report Prefix & Msg &
" [Expected " & str(Expected_c) & "(0x" & hstr(Expected_c) & ")" &
", Received " & str(Actual_c) & "(0x" & hstr(Actual_c) & ")" & "]"
severity error;
end procedure;
-- *** StdlCompare ***
procedure StdlCompare( Expected : in integer range 0 to 1;
Actual : in std_logic;
Msg : in string;
Prefix : in string := "###ERROR###: ") is
variable ExStdl_v : std_logic;
begin
if Expected = 0 then
ExStdl_v := '0';
else
ExStdl_v := '1';
end if;
assert Actual = ExStdl_v
report Prefix & Msg &
" [Expected " & str(ExStdl_v) &
", Received " & str(Actual) & "]"
severity error;
end procedure;
-- *** IntCompare ***
procedure IntCompare( Expected : in integer;
Actual : in integer;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ") is
begin
assert (Actual >= Expected-Tolerance) and (Actual <= Expected+Tolerance)
report Prefix & Msg &
" [Expected " & to_string(Expected) &
", Received " & to_string(Actual) &
", Tolerance " & to_string(Tolerance) & "]"
severity error;
end procedure;
-- *** RealCompare ***
procedure RealCompare( Expected : in real;
Actual : in real;
Msg : in string;
Tolerance : in real := 0.0;
Prefix : in string := "###ERROR###: ") is
begin
assert (Actual >= Expected-Tolerance) and (Actual <= Expected+Tolerance)
report Prefix & Msg &
" [Expected " & to_string(Expected) &
", Received " & to_string(Actual) &
", Tolerance " & to_string(Tolerance) & "]"
severity error;
end procedure;
-- *** SignCompare ***
procedure SignCompare( Expected : in signed;
Actual : in signed;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ") is
begin
assert (Actual >= Expected-Tolerance) and (Actual <= Expected+Tolerance)
report Prefix & Msg &
" [Expected " & to_string(Expected) &
", Received " & to_string(Actual) &
", Tolerance " & to_string(Tolerance) & "]"
severity error;
end procedure;
-- *** UsignCompare ***
procedure UsignCompare( Expected : in unsigned;
Actual : in unsigned;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ") is
begin
assert (Actual >= Expected-Tolerance) and (Actual <= Expected+Tolerance)
report Prefix & Msg &
" [Expected " & to_string(Expected) &
", Received " & to_string(Actual) &
", Tolerance " & to_string(Tolerance) & "]"
severity error;
end procedure;
-- *** SignCompareInt ***
procedure SignCompareInt ( Expected : in integer;
Actual : in signed;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ") is
begin
StdlvCompareInt ( Expected => Expected,
Actual => std_logic_vector(Actual),
Msg => Msg,
IsSigned => true,
Tolerance => Tolerance,
Prefix => Prefix);
end procedure;
-- *** UsignCompareInt ***
procedure UsignCompareInt ( Expected : in integer;
Actual : in unsigned;
Msg : in string;
Tolerance : in integer := 0;
Prefix : in string := "###ERROR###: ") is
begin
StdlvCompareInt ( Expected => Expected,
Actual => std_logic_vector(Actual),
Msg => Msg,
IsSigned => false,
Tolerance => Tolerance,
Prefix => Prefix);
end procedure;
end psi_tb_compare_pkg;
|