Browse Source

clean up assert_* procedures, add new optional parameter for severity level

pull/1/head
T. Meissner 10 years ago
parent
commit
2b34512dec
2 changed files with 125 additions and 103 deletions
  1. +12
    -7
      README.md
  2. +113
    -96
      sim/AssertP.vhd

+ 12
- 7
README.md View File

@ -6,19 +6,24 @@ A LGPLv3 licensed library of reusable components for VHDL designs and testbenche
(Non) synthesible components for testbenches (Non) synthesible components for testbenches
##### AssertP ##### AssertP
Package with various assertion procedures
Package with various assertion procedures.
* `assert_true(x[, str])` checks if boolean x = false, prints string str to console str when given
* `assert_false(x[, str])` checks if boolean x = false, prints string str to console str when given
* `assert_equal(x, y[, str])` checks if x = y, prints string str to console str when given
* `assert_unequal(x, y[, str])` checks if x /= y, prints string str to console str when given
* `assert_true(x[, str, level])` checks if boolean x = false
* `assert_false(x[, str, level])` checks if boolean x = false
* `assert_equal(x, y[, str, level])` checks if x = y
* `assert_unequal(x, y[, str, level])` checks if x /= y
All of the assert_* procedures have following optional parameters:
* `str` print string str to console instead implemented one
* `level` severity level (note, warning, error, failure)
##### SimP ##### SimP
Package with various components general useful for simulation Package with various components general useful for simulation
* `wait_cycles(x, n)` waits for n rising edges on std_logic signal x * `wait_cycles(x, n)` waits for n rising edges on std_logic signal x
* `spi_master()` configurable master for SPI protocol
* `spi_slave()` configurable slave for SPI protocol
* `spi_master()` configurable master for SPI protocol, supports all cpol/cpha modes
* `spi_slave()` configurable slave for SPI protocol, supports all cpol/cpha modes
##### StringP ##### StringP
Package with various functions to convert to string Package with various functions to convert to string


+ 113
- 96
sim/AssertP.vhd View File

@ -9,25 +9,39 @@ library libvhdl;
package AssertP is package AssertP is
procedure assert_true (a : in boolean);
procedure assert_true (a : in boolean; str : in string);
procedure assert_true ( a : in boolean;
str : in string := "a should be evaluate to true";
level : in severity_level := failure);
procedure assert_false (a : in boolean);
procedure assert_false (a : in boolean; str : in string);
procedure assert_false ( a : in boolean;
str : in string := "a should be evaluate to false";
level : in severity_level := failure);
procedure assert_equal (a : in integer; b : in integer);
procedure assert_equal (a : in integer; b : in integer; str : in string);
procedure assert_equal (a : in std_logic_vector; b : in std_logic_vector);
procedure assert_equal (a : in std_logic_vector; b : in std_logic_vector; str : in string);
procedure assert_equal (a : in string; b : in string);
procedure assert_equal (a : in string; b : in string; str : in string);
procedure assert_equal (a, b : in integer;
str : in string := "";
level : in severity_level := failure);
procedure assert_unequal (a : in integer; b : in integer);
procedure assert_unequal (a : in integer; b : in integer; str : in string);
procedure assert_unequal (a : in std_logic_vector; b : in std_logic_vector);
procedure assert_unequal (a : in std_logic_vector; b : in std_logic_vector; str : in string);
procedure assert_unequal (a : in string; b : in string);
procedure assert_unequal (a : in string; b : in string; str : in string);
procedure assert_equal ( a, b : in std_logic_vector;
str : in string := "";
level : in severity_level := failure);
procedure assert_equal ( a, b : in string;
str : in string := "";
level : in severity_level := failure);
procedure assert_unequal (a, b : in integer;
str : in string := "";
level : in severity_level := failure);
procedure assert_unequal ( a, b : in std_logic_vector;
str : in string := "";
level : in severity_level := failure);
procedure assert_unequal ( a, b : in string;
str : in string := "";
level : in severity_level := failure);
end package AssertP; end package AssertP;
@ -37,116 +51,119 @@ end package AssertP;
package body AssertP is package body AssertP is
procedure assert_true (a : in boolean) is
procedure assert_true ( a : in boolean;
str : in string := "a should be evaluate to true";
level : in severity_level := failure) is
begin begin
assert a assert a
report "FAILURE: a should be evaluate to true"
severity failure;
report str
severity level;
end procedure assert_true; end procedure assert_true;
procedure assert_true (a : in boolean; str : in string) is
begin
assert a
report "FAILURE: " & str
severity failure;
end procedure assert_true;
procedure assert_false (a : in boolean) is
procedure assert_false ( a : in boolean;
str : in string := "a should be evaluate to false";
level : in severity_level := failure) is
begin begin
assert not(a) assert not(a)
report "FAILURE: a should be evaluate to false"
severity failure;
report str
severity level;
end procedure assert_false; end procedure assert_false;
procedure assert_false (a : in boolean; str : in string) is
begin
assert not(a)
report "FAILURE: " & str
severity failure;
end procedure assert_false;
procedure assert_equal (a : in integer; b : in integer) is
procedure assert_equal ( a, b : in integer;
str : in string := "";
level : in severity_level := failure) is
begin begin
assert a = b
report "FAILURE: " & integer'image(a) & " should be equal to " & integer'image(b)
severity failure;
if (str'length = 0) then
assert a = b
report integer'image(a) & " should be equal to " & integer'image(b)
severity level;
else
assert a = b
report str
severity level;
end if;
end procedure assert_equal; end procedure assert_equal;
procedure assert_equal (a : in integer; b : in integer; str : in string) is
begin
assert a = b
report "FAILURE: " & str
severity failure;
end procedure assert_equal;
procedure assert_equal (a : in std_logic_vector; b : in std_logic_vector) is
begin
assert a = b
report "FAILURE: " & to_string(a) & " should be equal to " & to_string(b)
severity failure;
end procedure assert_equal;
procedure assert_equal (a : in std_logic_vector; b : in std_logic_vector; str : in string) is
procedure assert_equal ( a, b : in std_logic_vector;
str : in string := "";
level : in severity_level := failure) is
begin begin
assert a = b
report "FAILURE: " & str
severity failure;
if (str'length = 0) then
assert a = b
report "FAILURE: " & to_string(a) & " should be equal to " & to_string(b)
severity level;
else
assert a = b
report str
severity level;
end if;
end procedure assert_equal; end procedure assert_equal;
procedure assert_equal (a : in string; b : in string) is
begin
assert a = b
report "FAILURE: " & a & " should be equal to " & b
severity failure;
end procedure assert_equal;
procedure assert_equal (a : in string; b : in string; str : in string) is
procedure assert_equal ( a,b : in string;
str : in string := "";
level : in severity_level := failure) is
begin begin
assert a = b
report "FAILURE: " & str
severity failure;
if (str'length = 0) then
assert a = b
report "FAILURE: " & a & " should be equal to " & b
severity level;
else
assert a = b
report str
severity level;
end if;
end procedure assert_equal; end procedure assert_equal;
procedure assert_unequal (a : in integer; b : in integer) is
begin
assert a /= b
report "FAILURE: " & integer'image(a) & " should be unequal to " & integer'image(b)
severity failure;
end procedure assert_unequal;
procedure assert_unequal (a : in integer; b : in integer; str : in string) is
procedure assert_unequal ( a, b : in integer;
str : in string := "";
level : in severity_level := failure) is
begin begin
assert a /= b
report "FAILURE: " & str
severity failure;
if (str'length = 0) then
assert a /= b
report integer'image(a) & " should not be equal to " & integer'image(b)
severity level;
else
assert a /= b
report str
severity level;
end if;
end procedure assert_unequal; end procedure assert_unequal;
procedure assert_unequal (a : in std_logic_vector; b : in std_logic_vector) is
begin
assert a /= b
report "FAILURE: " & to_string(a) & " should be unequal to " & to_string(b)
severity failure;
end procedure assert_unequal;
procedure assert_unequal (a : in std_logic_vector; b : in std_logic_vector; str : in string) is
procedure assert_unequal ( a, b : in std_logic_vector;
str : in string := "";
level : in severity_level := failure) is
begin begin
assert a /= b
report "FAILURE: " & str
severity failure;
if (str'length = 0) then
assert a /= b
report "FAILURE: " & to_string(a) & " should not be equal to " & to_string(b)
severity level;
else
assert a /= b
report str
severity level;
end if;
end procedure assert_unequal; end procedure assert_unequal;
procedure assert_unequal (a : in string; b : in string) is
begin
assert a /= b
report "FAILURE: " & a & " should be unequal to " & b
severity failure;
end procedure assert_unequal;
procedure assert_unequal (a : in string; b : in string; str : in string) is
begin
assert a /= b
report "FAILURE: " & str
severity failure;
procedure assert_unequal ( a,b : in string;
str : in string := "";
level : in severity_level := failure) is
begin
if (str'length = 0) then
assert a /= b
report "FAILURE: " & a & " should not be equal to " & b
severity level;
else
assert a /= b
report str
severity level;
end if;
end procedure assert_unequal; end procedure assert_unequal;


Loading…
Cancel
Save