TestSimpleState.vhd
-------------------------------------------------------------------------------
-- Copyright (c) 2017 by Stefan Milch. All rights reserved.
-------------------------------------------------------------------------------
--! @file TestSimpleState.vhd
--! @brief Test shell for module SimpleState. \n
--!
-------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use std.textio.all;
entity TestSimpleState is
generic (
BoardIdx : integer := 0 -- 0: ZYBO, 1: ARTY
);
end TestSimpleState;
architecture behavior of TestSimpleState is
-- Component Declaration for the Unit Under Test (UUT)
component SimpleState
generic (
BoardIdx : integer := 0; -- 0: ZYBO, 1: ARTY
Simulation : boolean := false
);
port (
EXT_CLK : in std_logic; --! 100/125 MHz system clock
BTN : in std_logic_vector(3 downto 0); --! Button inputs, high acitve
LED : out std_logic_vector(3 downto 0) --! LED outputs, high acitve
);
end component;
-- Time definitions
type tCycle is array(0 to 1) of time;
constant cycleTimes : tCycle := (0 => 8 ns, 1 => 10 ns);
constant Clk_period : time := cycleTimes(BoardIdx); -- clock period of selected board
--Inputs
signal Button : std_logic_vector(3 downto 0) := (others => '0');
signal Ext_Clk : std_logic := '0';
--Outputs
signal Led : std_logic_vector(3 downto 0);
--Test
file report_file : text;
signal TestCase : integer;
signal TestErr : std_logic := '0';
--! print to output file
procedure tb_report(constant report_text : in string) is
variable line_out: line;
begin
write(line_out,report_text);
writeline(report_file, line_out);
end tb_report;
--! wait a number of cycles
procedure WaitCycles(constant cycles : in integer) is
variable i : integer;
begin
for i in 1 to cycles loop
wait until rising_edge(Ext_Clk);
end loop;
end WaitCycles;
begin
-- Instantiate the Unit Under Test (UUT)
uut: SimpleState
generic map (
BoardIdx => BoardIdx,
Simulation => true
)
port map (
EXT_CLK => Ext_Clk,
BTN => Button,
LED => Led
);
--! Generate system clock
p_clk : process
begin
wait for Clk_period/2;
Ext_Clk <= not Ext_Clk;
end process;
--! Check for test bench time out
p_control : process
begin
wait for 20 ms;
-- the test bench should already have terminated!
assert false
report "Test timed out!"
severity failure;
end process;
-- Stimulus process
stim_proc: process
variable expected_time : time;
begin
-- prepare reporting
file_open(report_file,"../../../TestSimpleState.log",WRITE_MODE);
tb_report("Testing SimpleState:");
tb_report("====================");
TestCase <= 1;
TestCase <= 0;
WaitCycles(1);
TestErr <= not TestErr;
WaitCycles(1);
TestErr <= not TestErr;
WaitCycles(500);
if (TestErr = '0') then
tb_report("Test completed successfully");
else
tb_report("Test completed with error(s)");
end if;
file_close(report_file);
assert false
report "Test terminated. This is not a failiure!"
severity failure;
wait;
end process;
end;