Library of reusable VHDL components
vhdl
osvvm
fpga
ghdl
testbenches
psl
coverage

AssertP.vhd 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. --+ including vhdl 2008 libraries
  4. --+ These lines can be commented out when using
  5. --+ a simulator with built-in VHDL 2008 support
  6. --library ieee_proposed;
  7. -- use ieee_proposed.standard_additions.all;
  8. -- use ieee_proposed.std_logic_1164_additions.all;
  9. package AssertP is
  10. procedure assert_true ( a : in boolean;
  11. str : in string := "a should be evaluate to true";
  12. level : in severity_level := failure);
  13. procedure assert_false ( a : in boolean;
  14. str : in string := "a should be evaluate to false";
  15. level : in severity_level := failure);
  16. procedure assert_equal (a, b : in integer;
  17. str : in string := "";
  18. level : in severity_level := failure);
  19. procedure assert_equal ( a, b : in std_logic_vector;
  20. str : in string := "";
  21. level : in severity_level := failure);
  22. procedure assert_equal ( a, b : in string;
  23. str : in string := "";
  24. level : in severity_level := failure);
  25. procedure assert_unequal (a, b : in integer;
  26. str : in string := "";
  27. level : in severity_level := failure);
  28. procedure assert_unequal ( a, b : in std_logic_vector;
  29. str : in string := "";
  30. level : in severity_level := failure);
  31. procedure assert_unequal ( a, b : in string;
  32. str : in string := "";
  33. level : in severity_level := failure);
  34. end package AssertP;
  35. package body AssertP is
  36. procedure assert_true ( a : in boolean;
  37. str : in string := "a should be evaluate to true";
  38. level : in severity_level := failure) is
  39. begin
  40. assert a
  41. report str
  42. severity level;
  43. end procedure assert_true;
  44. procedure assert_false ( a : in boolean;
  45. str : in string := "a should be evaluate to false";
  46. level : in severity_level := failure) is
  47. begin
  48. assert not(a)
  49. report str
  50. severity level;
  51. end procedure assert_false;
  52. procedure assert_equal ( a, b : in integer;
  53. str : in string := "";
  54. level : in severity_level := failure) is
  55. begin
  56. if (str'length = 0) then
  57. assert a = b
  58. report to_string(a) & " should be equal to " & integer'image(b)
  59. severity level;
  60. else
  61. assert a = b
  62. report str
  63. severity level;
  64. end if;
  65. end procedure assert_equal;
  66. procedure assert_equal ( a, b : in std_logic_vector;
  67. str : in string := "";
  68. level : in severity_level := failure) is
  69. begin
  70. if (str'length = 0) then
  71. assert a = b
  72. report "FAILURE: 0x" & to_hstring(a) & " should be equal to 0x" & to_hstring(b)
  73. severity level;
  74. else
  75. assert a = b
  76. report str
  77. severity level;
  78. end if;
  79. end procedure assert_equal;
  80. procedure assert_equal ( a,b : in string;
  81. str : in string := "";
  82. level : in severity_level := failure) is
  83. begin
  84. if (str'length = 0) then
  85. assert a = b
  86. report "FAILURE: " & a & " should be equal to " & b
  87. severity level;
  88. else
  89. assert a = b
  90. report str
  91. severity level;
  92. end if;
  93. end procedure assert_equal;
  94. procedure assert_unequal ( a, b : in integer;
  95. str : in string := "";
  96. level : in severity_level := failure) is
  97. begin
  98. if (str'length = 0) then
  99. assert a /= b
  100. report to_string(a) & " should not be equal to " & integer'image(b)
  101. severity level;
  102. else
  103. assert a /= b
  104. report str
  105. severity level;
  106. end if;
  107. end procedure assert_unequal;
  108. procedure assert_unequal ( a, b : in std_logic_vector;
  109. str : in string := "";
  110. level : in severity_level := failure) is
  111. begin
  112. if (str'length = 0) then
  113. assert a /= b
  114. report "FAILURE: " & to_hstring(a) & " should not be equal to " & to_hstring(b)
  115. severity level;
  116. else
  117. assert a /= b
  118. report str
  119. severity level;
  120. end if;
  121. end procedure assert_unequal;
  122. procedure assert_unequal ( a,b : in string;
  123. str : in string := "";
  124. level : in severity_level := failure) is
  125. begin
  126. if (str'length = 0) then
  127. assert a /= b
  128. report "FAILURE: " & a & " should not be equal to " & b
  129. severity level;
  130. else
  131. assert a /= b
  132. report str
  133. severity level;
  134. end if;
  135. end procedure assert_unequal;
  136. end package body AssertP;