Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
4.7 KiB

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