1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- library ieee;
- use ieee.std_logic_1164.all;
- use ieee.numeric_std.all;
- use ieee.float_pkg.all;
-
- library std;
- use std.textio.all;
-
- package test_utility is
- constant TEST_FAIL : string := "[ FAIL ]";
- constant TEST_OK : string := "[ OK ]" & LF;
-
- type real_array is array ( natural range <> ) of real;
-
- procedure assert_eq( variable a : in std_logic_vector; variable b : in std_logic_vector );
-
- procedure assert_near( variable a : in real;
- variable b : in real;
- variable abs_err : in real );
-
- procedure assert_element_near( variable a : in real;
- variable b : in real;
- variable abs_err : in real;
- variable index : in integer );
-
- end package test_utility;
-
- package body test_utility is
-
- procedure assert_eq( variable a : in std_logic_vector; variable b : in std_logic_vector ) is
- begin
-
- assert( a = b )
- report TEST_FAIL & "assert_eq" & LF &
- " a: " & to_string( a ) & LF &
- " b: " & to_string( b ) & LF
- severity error;
- end procedure assert_eq;
-
- procedure assert_near( variable a : in real;
- variable b : in real;
- variable abs_err : in real ) is
- variable abs_diff : real;
- begin
- abs_diff := abs( a - b );
- assert( abs_diff <= abs_err )
- report TEST_FAIL & "assert_near" & LF &
- " a: " & to_string( a ) & LF &
- " b: " & to_string( b ) & LF &
- " " & to_string( abs_diff ) & " > " & to_string( abs_err ) & LF
- severity error;
- end procedure assert_near;
-
- procedure assert_element_near( variable a : in real;
- variable b : in real;
- variable abs_err : in real;
- variable index : in integer ) is
- variable abs_diff : real;
- begin
- abs_diff := abs( a - b );
- assert( abs_diff <= abs_err )
- report TEST_FAIL & "assert_element_near" & LF &
- " element: " & integer'image( index ) & LF &
- " a: " & to_string( a ) & LF &
- " b: " & to_string( b ) & LF &
- " " & to_string( abs_diff ) & " > " & to_string( abs_err ) & LF
- severity error;
- end procedure assert_element_near;
-
- end package body test_utility;
|