VHDL-verification
Package to ease directed testing of HDL entities
Constants | Signals | Files | Shared Variables | Processes
data_comparison Architecture Reference

Architecture accumulates input data in a vector and compares with contents of file lines. More...

Detailed Description

Architecture accumulates input data in a vector and compares with contents of file lines.

Definition at line 50 of file datacompare.vhd.

Processes

datacompare_read  ( )
 Reads the file line by line, accumulates data and compares.

Constants

NUM_CHUNKS  integer := 4 * GOLD_OUTPUT_NIBBLES / DATA_WIDTH
 Each line in output file equals to NUM_CHUNKS data of DATA_WIDTH.

Signals

received_data  integer := 0

Shared Variables

gold_file_isopen  shared boolean := := false

Files

gold_file_pointer  text
 Define this outside the process so we can check endfile(gold_file_pointer) in a concurrent assertion.

Member Function Documentation

◆ datacompare_read()

datacompare_read ( )
Process

Reads the file line by line, accumulates data and compares.

Also reports errors and checks for unexpected conditions

Definition at line 86 of file datacompare.vhd.

datacompare_read : process
86 
87  --file gold_file_pointer : text;
88  variable current_line : line;
89  variable expected_data : std_logic_vector (GOLD_OUTPUT_NIBBLES*4-1 downto 0); -- Data read from file
90  variable current_data : std_logic_vector (GOLD_OUTPUT_NIBBLES*4-1 downto 0); -- Data read from input
91  variable chunk_idx : integer range 0 to NUM_CHUNKS := 0; -- Points to current data chunk in line
92  variable error_count : integer := 0; -- Store differences between received and expected data
93  variable correct_count : integer := 0; -- Store number of correct data
94 
95  begin
96 
97  print ("datacompare(" & SIMULATION_LABEL & "): NUM_CHUNKS: " & integer'image(NUM_CHUNKS));
98  print ("datacompare(" & SIMULATION_LABEL & "): opening gold_output file " & GOLD_OUTPUT_FILE);
99  file_open(gold_file_pointer, GOLD_OUTPUT_FILE, READ_MODE);
100  gold_file_isopen := true;
101 
102  while (not endfile(gold_file_pointer)) loop
103 
104  print (DEBUG, "datacompare(" & SIMULATION_LABEL & "): reading line");
105  readline (gold_file_pointer, current_line); -- Read the whole line from the file
106 
107  -- Before converting line to std_logic_vector, assert that number of nibbles read matches expected
108  -- Since a line is a pointer (technically an "access", in VHDL) to a string,
109  -- current_line.all is a string, so check its length
110  assert current_line.all'LENGTH = GOLD_OUTPUT_NIBBLES
111  report "datagen: unexpected number of nibbles in gold output file, got " & integer'image(current_line.all'LENGTH) & ", expected " & integer'image(GOLD_OUTPUT_NIBBLES)
112  severity failure;
113 
114  hread (current_line, expected_data); -- Interpret the line as hex data and put it in a std_logic_vector
115 
116  while ((chunk_idx < NUM_CHUNKS)) loop
117  wait until rising_edge(clk);
118  if (valid = '1') then
119  print (DEBUG, "datacompare(" & SIMULATION_LABEL & "): chunk_idx: " & integer'image(chunk_idx));
120  current_data(DATA_WIDTH*(chunk_idx+1)-1 downto DATA_WIDTH*chunk_idx) := data; -- Put input data in the correct chunk
121  chunk_idx := chunk_idx + 1;
122  received_data <= received_data + 1;
123  end if;
124  end loop;
125 
126  if (abs(signed(current_data) - signed(expected_data)) > ERROR_MARGIN) then
127  report "datacompare(" & SIMULATION_LABEL & "): ERROR: received " & slv2hexstring (current_data) & ", expecting " & slv2hexstring (expected_data)
128  severity error;
129  error_count := error_count + 1;
130  else
131  if (VERBOSE = true) then
132  report "datacompare(" & SIMULATION_LABEL & "): data OK, received " & slv2hexstring (current_data) & ", expecting " & slv2hexstring (expected_data) severity note;
133  end if;
134  correct_count := correct_count + 1;
135  end if;
136 
137  chunk_idx := 0;
138 
139  end loop;
140 
141  file_close(gold_file_pointer);
142  gold_file_isopen := false;
143 
144  wait until (falling_edge(clk) or (endsim='1'));
145 
146  print (VERBOSE, "datacompare(" & SIMULATION_LABEL & "): " & integer'image(received_data) & " data received");
147  print (VERBOSE, "datacompare(" & SIMULATION_LABEL & "): No more data in output file, closing it");
148 
149  wait until endsim='1';
150 
151  assert correct_count > 0
152  report "datacompare(" & SIMULATION_LABEL & "): simulation finished but correct data is not > 0. correct data: " & integer'image(correct_count) severity failure;
153 
154  report "datacompare(" & SIMULATION_LABEL & "): test end, errors: " & integer'image(error_count) & " correct data: " & integer'image(correct_count) severity note;
155 
156  wait;
157 
158  end process datacompare_read;
159 
GOLD_OUTPUT_FILEstring := "../test/datacompare_test.txt"
File where data is stored.
Definition: datacompare.vhd:36
SIMULATION_LABELstring := "datacompare"
Allow to separate messages from different instances in SIMULATION.
Definition: datacompare.vhd:33
GOLD_OUTPUT_NIBBLESinteger := 2
Maximum hex chars for each output data.
Definition: datacompare.vhd:37
VERBOSEboolean := false
Report correct data and not only erroneous data.
Definition: datacompare.vhd:34
text gold_file_pointer
Define this outside the process so we can check endfile(gold_file_pointer) in a concurrent assertion...
Definition: datacompare.vhd:57
DEBUGboolean := false
Print debug info (developers only)
Definition: datacompare.vhd:35
integer := 4* GOLD_OUTPUT_NIBBLES/ DATA_WIDTH NUM_CHUNKS
Each line in output file equals to NUM_CHUNKS data of DATA_WIDTH.
Definition: datacompare.vhd:52
ERROR_MARGINinteger := 0
Comparison is ok if data differs by this value or less.
Definition: datacompare.vhd:40
in datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Data to compare with data in file.
Definition: datacompare.vhd:43
DATA_WIDTHinteger := 8
Width of inout data.
Definition: datacompare.vhd:38
in clkstd_logic
Expects input data aligned to this clock.
Definition: datacompare.vhd:42
in endsimstd_logic
Active high, tells the process to close its open files.
Definition: datacompare.vhd:46
in validstd_logic
Active high, indicates data is valid.
Definition: datacompare.vhd:44

The documentation for this class was generated from the following file: