Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.25 KB | None | 0 0
  1. Library ieee;
  2. Use ieee.std_logic_1164.all;
  3.  
  4. Entity test_two_bit_comparator is
  5.   -- empty
  6. End test_two_bit_comparator;
  7.  
  8. Architecture arch of test_two_bit_comparator is
  9.  
  10.     -- First, get our external comparator
  11.     component two_bit_comparator
  12.         Port (
  13.                 InputA, InputB : in std_logic_vector(1 downto 0);
  14.                 AEqualsB    : out std_logic
  15.         );
  16.     end component two_bit_comparator;
  17.    
  18.     -- Now, let's create a helper function
  19.     procedure test_values(
  20.         -- define parameters
  21.         Signal in0, in1, in2, in3 : out std_logic;
  22.         Signal compResult   : in std_logic;
  23.         testValue0, testValue1, testValue2, testValue3, expectedResult  : in std_logic
  24.     )
  25.    
  26.         is begin
  27.             in0 <= testValue0;
  28.             in1 <= testValue1;
  29.             in2 <= testValue2;
  30.             in3 <= testValue3;
  31.         wait for 25 ns;
  32.        
  33.         if(not(compResult = expectedResult)) then
  34.             report "TEST FAILED! The simulation is now halted." severity failure;
  35.         end if;
  36.        
  37.         wait for 25 ns;
  38.     end procedure test_values;
  39.  
  40.     -- Now we can build our wirings
  41.    
  42.     Signal p0, p1, p2, p3, pout : std_logic;
  43.     begin
  44.               -- [ [1] [0] ] in the table is [ [p0] [p1] ]
  45.         my_test_two_bit_comp : two_bit_comparator port map(InputA(0) => p1, InputB(0) => p3,
  46.                                     InputA(1) => p0, InputB(1) => p2, AEqualsB => pout);
  47.  
  48.    
  49.         test_process : process begin
  50.             test_values(p0,p1,p2,p3,pout,'0','0','0','0','1');
  51.             test_values(p0,p1,p2,p3,pout,'0','0','0','1','0');
  52.             test_values(p0,p1,p2,p3,pout,'0','0','1','0','0');
  53.             test_values(p0,p1,p2,p3,pout,'0','0','1','1','0');
  54.  
  55.             test_values(p0,p1,p2,p3,pout,'0','1','0','0','0');
  56.             test_values(p0,p1,p2,p3,pout,'0','1','0','1','1');
  57.             test_values(p0,p1,p2,p3,pout,'0','1','1','0','0');
  58.             test_values(p0,p1,p2,p3,pout,'0','1','1','1','0');
  59.  
  60.             test_values(p0,p1,p2,p3,pout,'1','0','0','0','1');
  61.             test_values(p0,p1,p2,p3,pout,'1','0','0','1','1');
  62.             test_values(p0,p1,p2,p3,pout,'1','0','1','0','0');
  63.             test_values(p0,p1,p2,p3,pout,'1','0','1','1','0');
  64.  
  65.             test_values(p0,p1,p2,p3,pout,'1','1','0','0','1');
  66.             test_values(p0,p1,p2,p3,pout,'1','1','0','1','1');
  67.             test_values(p0,p1,p2,p3,pout,'1','1','1','0','1');
  68.             test_values(p0,p1,p2,p3,pout,'1','1','1','1','0');
  69.        
  70.             report "None! TEST SUCCESSFUL! End of simulation." severity failure;
  71.         end process test_process;
  72.        
  73. End arch;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement