pp.557-558
今度はstimulus generatorとresponse checkerとを分ける。さらに、ファイル操作の処理をプロシージャ化してstimulus generatorから分ける。
library ieee; use ieee.std_logic_1164.all; use std.textio.all; entity hash_calculator_tb is end; architecture testbench of hash_calculator_tb is constant DUV_DELAY: time := 10 ns; -- NOTE: Update the path below to match your system's directory structure: --constant GOLDEN_DATA_PATH: string := "c:\effective_coding_with_vhdl\code_examples\chapter_20\"; signal message: string(1 to 32); signal hash: std_logic_vector(31 downto 0); signal hash_golden: std_logic_vector(31 downto 0); file golden_data: text open read_mode is "golden.txt"; -- ファイルオブジェクトからDUVへの入力値とDUVからの出力期待値とを読み出して返すためのプロシージャ。 procedure read_golden_vectors( signal message_sig: out string; signal hash_sig: out std_logic_vector ) is variable current_line: line; variable hash_golden: std_logic_vector(31 downto 0); variable message_golden: string(1 to 32); begin -- Read input vector and expected respose readline(golden_data, current_line); read(current_line, message_golden); read(current_line, hash_golden); -- Return values message_sig <= message_golden; hash_sig <= hash_golden; end; begin duv: entity work.hash_calculator port map ( message => message, hash => hash ); stimulus_generator: process begin while not endfile(golden_data) loop -- Called procedure will assign read values to signals passed as arguments -- プロシージャをコールして、DUVへの入力値をDUVへ与え、DUVからの出力期待値をresponse checkerへ与える。 read_golden_vectors(message, hash_golden); wait for DUV_DELAY; end loop; report "End of testbench. All tests passed!"; std.env.finish; end process; response_checker: process --variable hash_sample: std_logic_vector(31 downto 0); begin -- Sample DUV output wait on message'transaction; -- DUVから実際に出力された値を取っておいて、 -- hash_sample := hash; -- Check DUV response wait for DUV_DELAY; assert hash = hash_golden report "hash for message " & message & " UNMATCHES golden output" severity failure; assert hash /= hash_golden report "hash for message " & message & " MATCHES golden output" severity note; end process; end;