組み合わせ論理回路のためのテストベンチ / カップリングを解消したテストベンチ

pp.539-540

前回はstimuli_generatorとresponse_checkerとがカップリングしていたが今度は分ける。

↓ これがテストベンチ:

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", "0000000"),
        (x"b", "0000000"),
        (x"c", "0000000"),
        (x"d", "0000000"),
        (x"e", "0000000"),
        (x"f", "0000000")
    );

    constant DUV_DELAY: time := 12 ns;
    constant TEST_PERIOD: time := 20 ns;

    function predictor(bcd: std_logic_vector(3 downto 0))
        return std_logic_vector
    is begin
        for i in TEST_DATA'range loop
            if TEST_DATA(i).bcd = bcd then
                return TEST_DATA(i).seven_segment;
            end if;
        end loop;
        report "Predictor error: input not found.";
    end;

begin
    duv: entity work.bcd_to_7seg
        port map(
            bcd => bcd,
            seven_seg => seven_seg
        );

    stimuli_generator: process begin
        for i in TEST_DATA'range loop
            bcd <= TEST_DATA(i).bcd;
            wait for TEST_PERIOD;
        end loop;

        report "End of testbench. All tests passed.";
        std.env.finish;
    end process;

    response_checker: process
       --variable bcd_sample: std_logic_vector(3 downto 0);
    begin
        wait on bcd;
       --bcd_sample := bcd;

        wait for DUV_DELAY;
        assert seven_seg = predictor(bcd)
            report "DUV output NOT EQUAL to golden test data."
            severity failure;
    end process;
end;

↓ これが実行結果: