Lösung des Praktikums Systementwurf
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.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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( variable a : in std_logic_vector; variable b : in std_logic_vector );
  12. procedure assert_near( variable a : in real;
  13. variable b : in real;
  14. variable abs_err : in real );
  15. procedure assert_element_near( variable a : in real;
  16. variable b : in real;
  17. variable abs_err : in real;
  18. variable index : in integer );
  19. end package test_utility;
  20. package body test_utility is
  21. procedure assert_eq( variable a : in std_logic_vector; variable b : in std_logic_vector ) is
  22. begin
  23. assert( a = b )
  24. report TEST_FAIL & "assert_eq" & LF &
  25. " a: " & to_string( a ) & LF &
  26. " b: " & to_string( b ) & LF
  27. severity error;
  28. end procedure assert_eq;
  29. procedure assert_near( variable a : in real;
  30. variable b : in real;
  31. variable abs_err : in real ) is
  32. variable abs_diff : real;
  33. begin
  34. abs_diff := abs( a - b );
  35. assert( abs_diff <= abs_err )
  36. report TEST_FAIL & "assert_near" & LF &
  37. " a: " & to_string( a ) & LF &
  38. " b: " & to_string( b ) & LF &
  39. " " & to_string( abs_diff ) & " > " & to_string( abs_err ) & LF
  40. severity error;
  41. end procedure assert_near;
  42. procedure assert_element_near( variable a : in real;
  43. variable b : in real;
  44. variable abs_err : in real;
  45. variable index : in integer ) is
  46. variable abs_diff : real;
  47. begin
  48. abs_diff := abs( a - b );
  49. assert( abs_diff <= abs_err )
  50. report TEST_FAIL & "assert_element_near" & LF &
  51. " element: " & integer'image( index ) & LF &
  52. " a: " & to_string( a ) & LF &
  53. " b: " & to_string( b ) & LF &
  54. " " & to_string( abs_diff ) & " > " & to_string( abs_err ) & LF
  55. severity error;
  56. end procedure assert_element_near;
  57. end package body test_utility;