1 ------------------------------------------------------------------------------- 3 --! @author Hipolito Guzman-Miranda 4 --! @brief Compares signals with expected values in file 5 ------------------------------------------------------------------------------- 7 --! Use IEEE standard definitions library 9 --! Use std_logic* signal types 10 use ieee.std_logic_1164.
all;
11 --! Allows use of arithmetical operations between integers and vectors 13 -- Allows writing strings to lines and lines to files 15 -- Allows writing std_logic_vector(s) to line(s) in BIN, HEX, OCT and reading BIN, HEX, OCT vector(s) from line(s) 16 use ieee.std_logic_textio.
all;
17 -- For print() function 19 -- To use the slv2hexstring conversion function 22 --! @brief Compares input data with values in file and reports errors 24 --! @detailed Reads file at \c GOLD_OUTPUT_FILE, expecting \c GOLD_OUTPUT_NIBBLES chars in 25 --! each line. Data is expected in hex format: 4 bits per character (nibble). 26 --! Reads input \c data and internally reorders it so it can compare 27 --! accumulated data with a complete line in \c GOLD_OUTPUT_FILE outputs it with a 28 --! width of DATA_WIDTH bits. \c data is only sampled when \c valid is active. If 29 --! \c VERBOSE is \c true, will report both correct (OK) data with erroneous 33 SIMULATION_LABEL : := "datacompare";
--! Allow to separate messages from different instances in SIMULATION 34 VERBOSE : := false;
--! Report correct data and not only erroneous data 35 DEBUG : := false;
--! Print debug info (developers only) 39 ERROR_MARGIN : := 0 --! Comparison is ok if data differs by this value or less 42 clk : in ;
--! Expects input data aligned to this clock 44 valid : in ;
--! Active high, indicates data is valid 45 endsim : in --! Active high, tells the process to close its open files 49 --! @brief Architecture accumulates input data in a vector and compares with contents of file lines 54 signal received_data : := 0;
56 --! Define this outside the process so we can check endfile(gold_file_pointer) in a concurrent assertion 57 file gold_file_pointer : text;
58 shared variable gold_file_isopen : := false;
-- It would be nice if file types had an 'isopen attribute :( 63 report "datacompare(" & SIMULATION_LABEL & "): GOLD_OUTPUT_NIBBLES must be a positive non-zero integer" 67 report "datacompare(" & SIMULATION_LABEL & "): DATA_WIDTH must be a positive non-zero integer" 78 -- If endsim arrives while the file is still open something went wrong 79 assert not (endsim = '1' and gold_file_isopen) 80 report "datacompare(" & SIMULATION_LABEL & "): endsim asserted before expected, seen only " & 'image(received_data) & "valid data" 83 --! @brief Reads the file line by line, accumulates data and compares 85 --! @detailed Also reports errors and checks for unexpected conditions 86 datacompare_read :
process 88 --file gold_file_pointer : text; 89 variable current_line : line;
92 variable chunk_idx : range 0 to NUM_CHUNKS := 0;
-- Points to current data chunk in line 93 variable error_count : := 0;
-- Store differences between received and expected data 94 variable correct_count : := 0;
-- Store number of correct data 100 file_open(gold_file_pointer, GOLD_OUTPUT_FILE, READ_MODE);
101 gold_file_isopen := true;
108 -- Before converting line to std_logic_vector, assert that number of nibbles read matches expected 109 -- Since a line is a pointer (technically an "access", in VHDL) to a string, 110 -- current_line.all is a string, so check its length 112 report "datagen: unexpected number of nibbles in gold output file, got " & 'image(current_line.all'LENGTH) & ", expected " & 'image(GOLD_OUTPUT_NIBBLES) 115 hread (current_line, expected_data);
-- Interpret the line as hex data and put it in a std_logic_vector 118 wait until rising_edge(clk);
119 if (valid = '1') then 121 current_data(DATA_WIDTH*(chunk_idx+1)-1 downto DATA_WIDTH*chunk_idx) := data;
-- Put input data in the correct chunk 122 chunk_idx := chunk_idx + 1;
123 received_data <= received_data + 1;
127 if (abs((current_data) - (expected_data)) > ERROR_MARGIN) then 128 report "datacompare(" & SIMULATION_LABEL & "): ERROR: received " & slv2hexstring (current_data) & ", expecting " & slv2hexstring (expected_data) 130 error_count := error_count + 1;
133 report "datacompare(" & SIMULATION_LABEL & "): data OK, received " & slv2hexstring (current_data) & ", expecting " & slv2hexstring (expected_data) severity note;
135 correct_count := correct_count + 1;
142 file_close(gold_file_pointer);
143 gold_file_isopen := false;
145 wait until (falling_edge(clk) or (endsim='1'));
152 assert correct_count > 0 153 report "datacompare(" & SIMULATION_LABEL & "): simulation finished but correct data is not > 0. correct data: " & 'image(correct_count) severity failure;
155 report "datacompare(" & SIMULATION_LABEL & "): test end, errors: " & 'image(error_count) & " correct data: " & 'image(correct_count) severity note;
159 end process datacompare_read;
GOLD_OUTPUT_FILEstring := "../test/datacompare_test.txt"
File where data is stored.
SIMULATION_LABELstring := "datacompare"
Allow to separate messages from different instances in SIMULATION.
GOLD_OUTPUT_NIBBLESinteger := 2
Maximum hex chars for each output data.
VERBOSEboolean := false
Report correct data and not only erroneous data.
Compares input data with values in file and reports errors.
Common datatypes and component declarations.
text gold_file_pointer
Define this outside the process so we can check endfile(gold_file_pointer) in a concurrent assertion...
DEBUGboolean := false
Print debug info (developers only)
integer := 4* GOLD_OUTPUT_NIBBLES/ DATA_WIDTH NUM_CHUNKS
Each line in output file equals to NUM_CHUNKS data of DATA_WIDTH.
ERROR_MARGINinteger := 0
Comparison is ok if data differs by this value or less.
in datastd_logic_vector( DATA_WIDTH- 1 downto 0)
Data to compare with data in file.
_library_ ieeeieee
Use IEEE standard definitions library.
DATA_WIDTHinteger := 8
Width of inout data.
in clkstd_logic
Expects input data aligned to this clock.
Allows for text output in simulation.
in endsimstd_logic
Active high, tells the process to close its open files.
in validstd_logic
Active high, indicates data is valid.