-- --------------
-- Test bench for LED Blinker 
-- --------------
-- Lucas GRELAUD

LIBRARY ieee;
USE ieee.std_logic_arith.ALL;
USE ieee.std_logic_unsigned.ALL;
USE ieee.std_logic_1164.ALL;

ENTITY led_blink_tb IS -- entity declaration
END led_blink_tb;

-----------------------------------------------------------------

ARCHITECTURE TB OF led_blink_tb IS

    SIGNAL T_clock : STD_LOGIC;
    SIGNAL T_reset : STD_LOGIC;
    SIGNAL T_led : STD_LOGIC;

    COMPONENT LED_BLINKER
        PORT (
            CLK : IN STD_LOGIC;
            RESET_N : IN STD_LOGIC;
            LED_STATE : OUT STD_LOGIC
        );
    END COMPONENT LED_BLINKER;

BEGIN

    U_blinker : LED_BLINKER PORT MAP(T_clock, T_reset, T_led);

    PROCESS
    BEGIN
        WHILE now <= 10 ms LOOP
            T_clock <= '1'; -- clock cycle 20 ns
            WAIT FOR 10 ns;
            T_clock <= '0';
            WAIT FOR 10 ns;
        END LOOP;
        WAIT;
    END PROCESS;

    PROCESS

        VARIABLE err_cnt : INTEGER := 0;

    BEGIN

        -- case 1		
        T_reset <= '0';
        WAIT FOR 500000 ns;
        T_reset <= '1';
        ASSERT (T_led = '0') REPORT "Failed Case 1" SEVERITY error;
        IF (T_led /= '0') THEN
            err_cnt := err_cnt + 1;
        END IF;

        -- case 2
        WAIT FOR 1 ms;
        ASSERT (T_led = '0') REPORT "Failed Case 2" SEVERITY error;
        IF (T_led /= '0') THEN
            err_cnt := err_cnt + 1;
        END IF;

        -- case 3
        WAIT FOR 1 ms;
        ASSERT (T_led = '1') REPORT "Failed Case 3" SEVERITY error;
        IF (T_led /= '1') THEN
            err_cnt := err_cnt + 1;
        END IF;
        -- summary of all the tests	
        IF (err_cnt = 0) THEN
            ASSERT false
            REPORT "Testbench of FSM completely successfully!"
                SEVERITY note;
        ELSE
            ASSERT true
            REPORT "Something wrong, Check again pls!"

                SEVERITY error;
        END IF;

        WAIT;

    END PROCESS;

END TB;

----------------------------------------------------------------------
CONFIGURATION CFG_TB OF led_blink_TB IS
    FOR TB
    END FOR;
END CFG_TB;