--------------------------------------------------------------- -- Test Bench for GCD Calculator (ESD book Figure 2.9) -- by Weijun Zhang, 04/2001 -- -- three cases tested --------------------------------------------------------------- Library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use work.all; entity test_GCD is -- entity declaration end test_GCD; ---------------------------------------------------------------- architecture Bench of test_GCD is component gcd port( clk: in std_logic; rst: in std_logic; go_i: in std_logic; x_i: in unsigned(3 downto 0); y_i: in unsigned(3 downto 0); d_o: out unsigned(3 downto 0) ); end component; signal T_clk,T_rst,T_go_i: std_logic; signal T_x_i, T_y_i, T_d_o: unsigned(3 downto 0); begin U1: GCD port map(T_clk,T_rst,T_go_i,T_x_i,T_y_i,T_d_o); Clk_sig: process begin T_clk<='1'; -- clock signal wait for 5 ns; T_clk<='0'; wait for 5 ns; end process; process variable err_cnt: integer :=0 ; begin -- case 1: input 0C & 80, output should be 4 T_rst<='1'; T_go_i<='0'; T_x_i<="1100"; T_y_i<="1000"; wait for 20 ns; T_rst<='0'; wait for 30 ns; T_go_i<='1'; wait for 200 ns; assert(T_d_o=4) report "Error1" severity error; if (T_d_o/=4) then err_cnt := err_cnt + 1; end if; -- case 2: input 0C & 02, output should be 2 T_rst<='1'; T_go_i<='0'; T_x_i<="1100"; T_y_i<="0010"; wait for 20 ns; T_rst<='0'; wait for 30 ns; T_go_i<='1'; wait for 200 ns; assert(T_d_o=2) report "Error2" severity error; if (T_d_o/=2) then err_cnt := err_cnt + 1; end if; -- case 3: input 05 & 0A, output should be 5 T_rst<='1'; T_go_i<='0'; T_x_i<="0101"; T_y_i<="1010"; wait for 20 ns; T_rst<='0'; wait for 30 ns; T_go_i<='1'; wait for 200 ns; assert(T_d_o=5) report "Error2" severity error; if (T_d_o/=5) then err_cnt := err_cnt + 1; end if; -- summary of all the tests to see if any error if (err_cnt=0) then assert false report "Testbench of GCD completed successfully!" severity note; else assert true report "Something wrong, try again" severity error; end if; wait; end process; end Bench; ----------------------------------------------------------------- configuration CFG_TB of test_GCD is for Bench end for; end CFG_TB; -----------------------------------------------------------------