Übungen der VHDL-Einführung
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.

test_utility.vhd 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use ieee.float_pkg.all;
  5. library std;
  6. use std.textio.all;
  7. package test_utility is
  8. constant TEST_FAIL : string := "[ FAIL ]";
  9. constant TEST_OK : string := "[ OK ]" & LF;
  10. type real_array is array ( natural range <> ) of real;
  11. procedure assert_eq( a : in std_logic; b : in std_logic );
  12. procedure assert_eq( a : in std_logic_vector; b : in std_logic_vector );
  13. procedure assert_near( variable a : in real;
  14. variable b : in real;
  15. variable abs_err : in real );
  16. procedure assert_element_near( variable a : in real;
  17. variable b : in real;
  18. variable abs_err : in real;
  19. variable index : in integer );
  20. end package test_utility;
  21. package body test_utility is
  22. procedure assert_eq( a : in std_logic; b : in std_logic ) is
  23. begin
  24. assert( a = b )
  25. report TEST_FAIL & "assert_eq" & LF &
  26. " a: " & to_string( a ) & LF &
  27. " b: " & to_string( b ) & LF
  28. severity error;
  29. end procedure assert_eq;
  30. procedure assert_eq( a : in std_logic_vector; b : in std_logic_vector ) is
  31. begin
  32. assert( a = b )
  33. report TEST_FAIL & "assert_eq" & LF &
  34. " a: " & to_string( a ) & LF &
  35. " b: " & to_string( b ) & LF
  36. severity error;
  37. end procedure assert_eq;
  38. procedure assert_near( variable a : in real;
  39. variable b : in real;
  40. variable abs_err : in real ) is
  41. variable abs_diff : real;
  42. begin
  43. abs_diff := abs( a - b );
  44. assert( abs_diff <= abs_err )
  45. report TEST_FAIL & "assert_near" & LF &
  46. " a: " & to_string( a ) & LF &
  47. " b: " & to_string( b ) & LF &
  48. " " & to_string( abs_diff ) & " > " & to_string( abs_err ) & LF
  49. severity error;
  50. end procedure assert_near;
  51. procedure assert_element_near( variable a : in real;
  52. variable b : in real;
  53. variable abs_err : in real;
  54. variable index : in integer ) is
  55. variable abs_diff : real;
  56. begin
  57. abs_diff := abs( a - b );
  58. assert( abs_diff <= abs_err )
  59. report TEST_FAIL & "assert_element_near" & LF &
  60. " element: " & integer'image( index ) & LF &
  61. " a: " & to_string( a ) & LF &
  62. " b: " & to_string( b ) & LF &
  63. " " & to_string( abs_diff ) & " > " & to_string( abs_err ) & LF
  64. severity error;
  65. end procedure assert_element_near;
  66. end package body test_utility;