組み合わせ論理回路のためのテストベンチ / モジュラーテストベンチ

pp.539-541

組み合わせ論理回路のためのテストベンチ / リニアテストベンチ -のときは、DUVへ与える信号の生成部と、DUVから出力された信号の照合部とを1つのプロセスにしていたが、今度は下のように個別のプロセスに分ける。ただしTEST_DATA排列を介して両プロセスがcouplingしているのであまりよくはないとの由。

library ieee;
use ieee.std_logic_1164.all;

entity bcd_to_7seg_tb is
end;

architecture testbench of bcd_to_7seg_tb is
    signal bcd: std_logic_vector(3 downto 0);
    signal seven_seg: std_logic_vector(6 downto 0);

    type test_data_type is record
        bcd: std_logic_vector(3 downto 0);
        seven_segment: std_logic_vector(6 downto 0);
    end record;

    type test_data_array_type is array (natural range <>) of test_data_type;
    constant TEST_DATA: test_data_array_type := (
        (x"0", "0111111"),
        (x"1", "0000110"),
        (x"2", "1011011"),
        (x"3", "1001111"),
        (x"4", "1100110"),
        (x"5", "1101101"),
        (x"6", "1111101"),
        (x"7", "0000111"),
        (x"8", "1111111"),
        (x"9", "1101111"),
        (x"a", (others => '0')),
        (x"b", (others => '0')),
        (x"c", (others => '0')),
        (x"d", (others => '0')),
        (x"e", (others => '0')),
        (x"f", (others => '0'))
    );

    signal test_vector_index: integer range 0 to TEST_DATA'length-1 := 0;

    constant DUV_DELAY: time := 5 ms;
    constant TEST_INTERVAL: time := 10 ms;
begin
    
   -- DUVを実体化する。
    duv: entity work.bcd_to_7seg
        port map(
            bcd => bcd,
            seven_seg => seven_seg
        );

   -- DUVに与える信号を生成する。
    stimuli_generator: process
    begin
        for i in TEST_DATA'range loop
            bcd <= TEST_DATA(i).bcd;
            test_vector_index <= i;
            wait for TEST_INTERVAL;
        end loop;

        report "End of testbench. All tests passed. \(^o^)/";
        std.env.finish;
    end process;

   -- DUVから出力された信号を照合する。
    response_checker: process
    begin
        wait on test_vector_index;

        wait for DUV_DELAY;
        assert seven_seg = TEST_DATA(test_vector_index).seven_segment
            report "DUV output NOT EQUAL to golden test data."
            severity failure;

        wait for TEST_INTERVAL - DUV_DELAY;
        assert seven_seg'stable(TEST_INTERVAL - DUV_DELAY)
            report "DUV.seven_seg NOT stable."
            severity failure;
    end process;

end;