외부 파일에서 자극 데이터 읽는 것은 VHDL에서 DUT(시험 대상 장치) 제어하는 강력한 방법입니다. 일반 텍스트 파일에 신호 값과 시뮬레이션 시간 시퀀스를 스크립팅하면 테스트벤치 로직 수정 없이 테스트 패턴 빠르게 교체 가능. VHDL 파일 접근 시리즈 두 번째 글에서 TEXTIO 라이브러리로 자극 파일 읽고 4입력 멀티플렉서에 값 적용하는 법 시연.
테스트 케이스 개요
DUT는 8비트 데이터 워드 가진 표준 비동기 4:1 멀티플렉서. 테스트벤치는 출력 검증 안 하고 입력을 구동해 파형 수동 검토 가능하게만 함. 참조용 엔티티 선언 아래 재현.
entity mux_4 is port( din_0 : in unsigned(7 downto 0); din_1 : in unsigned(7 downto 0); din_2 : in unsigned(7 downto 0); din_3 : in unsigned(7 downto 0); sel : in unsigned(1 downto 0); dout : out unsigned(7 downto 0)); end entity;
DUT 연결 신호들 테스트벤치 아키텍처에 선언, DUT 레이블로 인스턴스화:
signal din_0 : unsigned(7 downto 0); signal din_1 : unsigned(7 downto 0); signal din_2 : unsigned(7 downto 0); signal din_3 : unsigned(7 downto 0); signal sel : unsigned(1 downto 0); signal dout : unsigned(7 downto 0); DUT: entity work.mux_4(rtl) port map ( din_0 => din_0, din_1 => din_1, din_2 => din_2, din_3 => din_3, sel => sel, dout => dout );
자극 파일 설계
많은 포맷 가능하지만 아래 예제가 명확하고 인간 가독성 좋은 레이아웃 보여줌. 각 줄이 한 시뮬레이션 단계 표현, 포함 내용:
wait_time – 이전 단계부터 지연(예: 10 ns)
sel – 2비트 셀렉터 값
din_0 ~ din_3 – 16진수 8비트 데이터 값
선택적 후행 주석(# 시작)으로 콘솔 출력
줄 처음에 오는 주석은 테스트벤치 무시; 데이터 셋 뒤 따르는 주석은 시뮬레이터 콘솔에 출력.
# Column description: # wait_time | sel | din_0 | din_1 | din_2 | din_3 # Optional console printout 0 ns 0 AA BB CC DD # Setting initial values 10 ns 1 AA BB CC DD # Testing by changing the selector signal 10 ns 2 AA BB CC DD 10 ns 3 AA BB CC DD 10 ns 3 A1 B1 C1 D1 # Testing by changing all data inputs 10 ns 3 A2 B2 C2 D2 10 ns 3 A3 B3 C3 D3 10 ns 3 00 00 00 D2 # Changing all unselected inputs 10 ns 3 01 02 03 D2 10 ns 3 11 22 33 D2 1 ns 0 CC DD EE FF # Changing all inputs fast 1 ns 1 DD EE FF CC 1 ns 2 EE FF CC DD 1 ns 3 FF CC DD EE 10 ns 0 00 00 00 00 # Simulation stop
TEXTIO로 파일 읽기
아래는 자극 파일 열고 각 줄 파싱해 DUT 입력에 값 할당, 주석 처리하는 핵심 프로세스. 예제는 잘 포맷된 파일 가정(열 사이 공백 1개, # 문자 뒤 공백 1개).
PROC_SEQUENCER : process file text_file : text open read_mode is "stimulus.txt"; variable text_line : line; variable ok : boolean; variable char : character; variable wait_time : time; variable selector : sel'subtype; variable data : dout'subtype; begin while not endfile(text_file) loop readline(text_file, text_line); -- Skip empty lines and single-line comments if text_line.all'length = 0 or text_line.all(1) = '#' then next; end if; read(text_line, wait_time, ok); assert ok report "Read 'wait_time' failed for line: " & text_line.all severity failure; hread(text_line, selector, ok); assert ok report "Read 'sel' failed for line: " & text_line.all severity failure; sel <= selector; hread(text_line, data, ok); assert ok report "Read 'din_0' failed for line: " & text_line.all severity failure; din_0 <= data; hread(text_line, data, ok); assert ok report "Read 'din_1' failed for line: " & text_line.all severity failure; din_1 <= data; hread(text_line, data, ok); assert ok report "Read 'din_2' failed for line: " & text_line.all severity failure; din_2 <= data; hread(text_line, data, ok); assert ok report "Read 'din_3' failed for line: " & text_line.all severity failure; din_3 <= data; wait for wait_time; -- Print trailing comment to console, if any read(text_line, char, ok); -- Skip expected newline read(text_line, char, ok); if char = '#' then read(text_line, char, ok); -- Skip expected newline report text_line.all; end if; end loop; finish; end process;
시뮬레이션 출력
ModelSim 실행 시 콘솔에 누적 시뮬레이션 시간과 함께 후행 주석 표시. 다음 발췌는 출력된 노트 시퀀스:
# ** Note: Setting initial values # Time: 0 ns Iteration: 1 Instance: /file_stim_tb # ** Note: Testing by changing the selector signal # Time: 10 ns Iteration: 0 Instance: /file_stim_tb # ** Note: Testing by changing all data inputs # Time: 40 ns Iteration: 0 Instance: /file_stim_tb # ** Note: Changing all unselected inputs # Time: 70 ns Iteration: 0 Instance: /file_stim_tb # ** Note: Changing all inputs fast # Time: 91 ns Iteration: 0 Instance: /file_stim_tbf # ** Note: Simulation stop # Time: 104 ns Iteration: 0 Instance: /file_stim_tb # Break in Process PROC_SEQUENCER at file_stim_tb.vhd line 98
테스트벤치 생성 파형은 파일에서 타이밍과 데이터 값 미러링, 설계자가 DUT 동작 시각적으로 검증 가능.
핵심 요약
외부 자극 파일로 테스트벤치 코드 변경 없이 테스트 시퀀스 세밀 제어 가능.
TEXTIO 사용으로 테스트벤치 간결해지지만 엄격한 파일 포맷 규율 필요.
항상 자가 검사 메커니즘 포함 - 행동 모델과 비교하거나 자극 파일에 기대 출력 임베딩.
위 예제 따라 VHDL TEXTIO 완전 활용해 복잡한 테스트 시나리오 구동하면서 깔끔하고 유지보수 쉬운 테스트벤치 구조 유지 가능.