Skip to content
Snippets Groups Projects
Commit 69f6a96c authored by BRONES Romain's avatar BRONES Romain
Browse files

Update testbench

* New way to create test file. Introduced test with missing bpm, wrongly
  aligned frame
* We no longer auto test the frame in between the pack and unpack
* Adapt timeout and length
parent 38a43199
Branches
Tags
No related merge requests found
import numpy as np
# BPM data per sequence
bps=10
# Number of sequence
nseq=13
Nbpm=10
dty = np.dtype([("seqnum", "u2"), ("bpmid", "u2"), ("datax", "u4"), ("datay", "u4")])
# Generate a list of 16 bits words, 3 dimensions
seqdata = np.random.randint(0,2**16-1, (nseq,bps,5))
bpms=np.arange(Nbpm)+13
# Flatten last dimension, remove first sequence
seqframe = seqdata.reshape(nseq, bps*5)[1:]
def make_seq(start, nseq, bpms):
Nbpm=len(bpms)
data = np.zeros(Nbpm*nseq, dtype=dty)
data['seqnum']=np.arange(nseq, dtype="u2").repeat(Nbpm)+start
data['bpmid'] = np.tile(bpms, nseq)
data['datax']=np.random.randint(2**32-1, size=data.shape[0], dtype="u4")
data['datay']=np.random.randint(2**32-1, size=data.shape[0], dtype="u4")
return data
def make_zero(N):
data = np.zeros(N, dtype=dty)
return data
# extend to multiple of 64 bits frames
seqframe = np.hstack((seqframe, np.zeros((nseq-1, int(np.ceil(bps*5/4))*4 - bps*5), dtype=int)))
sequences = make_zero(3)
cseq= np.empty(0, dtype=dty)
s=0
blanksize=120
# Reshape to 64 bits words
seqframe = seqframe.reshape(nseq-1, seqframe.shape[1]//4, 4)
#%% 13 sequences, each followed by a blank
for n in range(13):
_s = make_seq(s,1, bpms)
sequences = np.concatenate([sequences, _s , make_zero(blanksize),])
if n!=0:
cseq = np.concatenate([cseq, _s ])
s+=1
# Generate input file
fp = open("testinput_001.txt", 'w')
for S, sdata in zip(range(nseq), seqdata):
for b, bdata in zip(range(bps), sdata):
fp.write("{:04X} ".format(S))
fp.write(("{:04X}"*5).format(*bdata[::-1]))
fp.write("\n")
fp.close()
#%% 13 sequences with missing BPM, each followed by a blank
# Generate frame file (for check)
fp = open("testframe_001.txt", 'w')
for sdata in seqframe:
for wdata in sdata:
fp.write(("{:04X}"*4).format(*wdata[::-1]))
fp.write("\n")
fp.close()
for n in range(13):
sequences = np.concatenate([sequences, make_seq(s,1, bpms[:-1]), make_zero(blanksize),])
s+=1
#%% 13 sequences, each followed by a blank
for n in range(13):
_s = make_seq(s,1, bpms)
sequences = np.concatenate([sequences, _s , make_zero(blanksize),])
if n!=0:
cseq = np.concatenate([cseq, _s ])
s+=1
#%% 13 sequences with one bpm not aligned, each followed by a blank
for n in range(13):
ws=make_seq(s,1, bpms)
ws[-4]['seqnum']=s+90
sequences = np.concatenate([sequences, ws, make_zero(blanksize),])
s+=1
#%% 13 sequences, each followed by a blank
for n in range(13):
_s = make_seq(s,1, bpms)
sequences = np.concatenate([sequences, _s , make_zero(blanksize),])
if n!=0:
cseq = np.concatenate([cseq, _s ])
s+=1
# Remove first sequence, used for startup
cseq = cseq[cseq['seqnum']!=1]
#%%
# Print to file
with open("testinput_002.txt", 'w') as fp:
for d in sequences:
fp.write("{:04X} {:04X}{:08X}{:08X}\n".format(*d))
with open("testoutput_002.txt", 'w') as fp:
for d in cseq:
fp.write("{:02X} {:04X}{:08X}{:08X}\n".format(*d))
# Generate output file
fp = open("testoutput_001.txt", 'w')
for S, sdata in zip(range(nseq-1), seqdata[2:]):
for b, bdata in zip(range(bps), sdata):
fp.write("{:02X} ".format(S+1))
fp.write(("{:04X}"*5).format(*bdata[::-1]))
fp.write("\n")
fp.close()
......@@ -5,7 +5,7 @@ set_property source_mgmt_mode All [current_project]
read_vhdl -vhdl2008 {sim/tb_ccn.vhd}
read_vhdl {hdl/ccn_unpack.vhd hdl/ccn_pack.vhd}
add_files -fileset sim_1 {sim/testinput_001.txt sim/testframe_001.txt sim/testoutput_001.txt }
add_files -fileset sim_1 {sim/testinput.txt sim/testoutput.txt }
set CCN_DPKT_W 80
set CCN_UPKT_W 80
......
......@@ -37,7 +37,6 @@ architecture testbench of tb_ccn is
-- Input packet axis
signal tb_s_axis_tuser : std_logic_vector(IPKT_TUSER_W-1 downto 0);
signal tb_s_axis_tdata : std_logic_vector(IPKT_TDATA_W-1 downto 0);
signal tb_s_axis_tlast : std_logic;
signal tb_s_axis_tvalid : std_logic;
signal tb_s_axis_tready : std_logic;
......@@ -227,14 +226,14 @@ begin
-- Configuration values
tb_pack_run <= '1';
tb_unpack_enable <= '1';
tb_pack_timeout <= x"0600";
tb_pack_timeout <= x"0040";
tb_pack_mac_dst <= x"010000DBAAFF";
tb_pack_mac_src <= x"050000DBAAFF";
tb_unpack_mac_dst <= x"010000DBAAFF";
tb_unpack_mac_src <= x"050000DBAAFF";
tb_pack_expect_pkt <= std_logic_vector(to_unsigned(10-1, tb_pack_expect_pkt'length));
tb_pack_mac_length <= std_logic_vector(to_unsigned(10*10+9, tb_pack_mac_length'length));
tb_unpack_mac_length<= std_logic_vector(to_unsigned(10*10+9, tb_pack_mac_length'length));
tb_pack_mac_length <= std_logic_vector(to_unsigned(10*10+10, tb_pack_mac_length'length));
tb_unpack_mac_length<= std_logic_vector(to_unsigned(10*10+10, tb_pack_mac_length'length));
wait until rising_edge(tb_clk);
-- Enable RX after a time
......@@ -255,7 +254,7 @@ begin
---------------
p_tx_send:process
file testinput : TEXT open READ_MODE is "testinput_001.txt";
file testinput : TEXT open READ_MODE is "testinput.txt";
variable linenum : natural :=0;
variable text_line : line;
variable readok : boolean;
......@@ -288,10 +287,11 @@ begin
assert readok
report "Read 'tdata' failed for line: " & integer'image(linenum) severity failure;
tb_s_axis_tdata <= vr_tdata;
tb_s_axis_tuser <= vr_tuser;
tb_s_axis_tvalid <= '1';
tb_s_axis_tlast <= '1';
-- Special on data=0, just let it roll as if no data ready
tb_s_axis_tvalid <= '1' when unsigned(vr_tdata) /= 0 else '0';
wait until rising_edge(tb_clk) and tb_s_axis_tready='1';
tb_s_axis_tvalid <= '0';
......@@ -307,7 +307,7 @@ begin
---------------
p_rx_recv:process
file testoutput : TEXT open READ_MODE is "testoutput_001.txt";
file testoutput : TEXT open READ_MODE is "testoutput.txt";
variable linenum : natural :=0;
variable text_line : line;
variable readok : boolean;
......@@ -360,65 +360,6 @@ begin
end loop;
end process p_rx_recv;
------------------
-- FRAME STREAM --
------------------
p_frame_stream:process
file testframe : TEXT open READ_MODE is "testframe_001.txt";
variable linenum : natural :=0;
variable text_line : line;
variable readok : boolean;
variable vr_tdata : std_logic_vector(FRAME_TDATA_W-1 downto 0);
variable masked_tdata : std_logic_vector(FRAME_TDATA_W-1 downto 0);
variable vr_cnt : natural := 0;
begin
while true loop
wait until
(rising_edge(tb_m_clk) and
eth_axis_tvalid = '1' and
eth_axis_tready = '1');
for I in 0 to FRAME_TDATA_W/8-1 loop
if eth_axis_tkeep(I) = '1' then
masked_tdata((I+1)*8-1 downto I*8) := eth_axis_tdata((I+1)*8-1 downto I*8);
else
masked_tdata((I+1)*8-1 downto I*8) := (others => '0');
end if;
end loop;
if vr_cnt > 2 then
if endfile(testframe) then
report "End of file reached." severity warning;
exit;
end if;
readline(testframe, text_line);
linenum := linenum+1;
hread(text_line, vr_tdata, readok);
assert readok
report "Read 'tdata' failed for line: " & integer'image(linenum) severity failure;
assert masked_tdata = vr_tdata
report "Frame check mismatch. Got " & to_hex_string(masked_tdata) & " ; Expected " & to_hex_string(vr_tdata)
severity warning;
if eth_axis_tlast = '1' then
vr_cnt := 0;
end if;
else
vr_cnt := vr_cnt+1;
end if;
end loop;
end process;
---------------------
-- TIMEREF COUNTER --
---------------------
......
......@@ -11,15 +11,18 @@
</db_ref>
</db_ref_list>
<zoom_setting>
<ZoomStartTime time="355363fs"></ZoomStartTime>
<ZoomEndTime time="1310364fs"></ZoomEndTime>
<Cursor1Time time="1440000fs"></Cursor1Time>
<ZoomStartTime time="0fs"></ZoomStartTime>
<ZoomEndTime time="101000001fs"></ZoomEndTime>
<Cursor1Time time="101000000fs"></Cursor1Time>
</zoom_setting>
<column_width_setting>
<NameColumnWidth column_width="276"></NameColumnWidth>
<ValueColumnWidth column_width="265"></ValueColumnWidth>
<ValueColumnWidth column_width="122"></ValueColumnWidth>
</column_width_setting>
<WVObjectSize size="42" />
<WVObjectSize size="43" />
<wave_markers>
<marker label="" time="5496332" />
</wave_markers>
<wvobject fp_name="divider58" type="divider">
<obj_property name="label">AXIS input</obj_property>
<obj_property name="DisplayName">label</obj_property>
......@@ -29,8 +32,9 @@
<obj_property name="ObjectShortName">s_axis_tdata[79:0]</obj_property>
</wvobject>
<wvobject type="array" fp_name="/tb_ccn/inst_dut_pack/s_axis_tuser">
<obj_property name="ElementShortName">s_axis_tuser[7:0]</obj_property>
<obj_property name="ObjectShortName">s_axis_tuser[7:0]</obj_property>
<obj_property name="ElementShortName">s_axis_tuser[15:0]</obj_property>
<obj_property name="ObjectShortName">s_axis_tuser[15:0]</obj_property>
<obj_property name="Radix">UNSIGNEDDECRADIX</obj_property>
</wvobject>
<wvobject type="logic" fp_name="/tb_ccn/inst_dut_pack/s_axis_tvalid">
<obj_property name="ElementShortName">s_axis_tvalid</obj_property>
......@@ -188,4 +192,8 @@
<obj_property name="ElementShortName">m_axis_tuser[0:0]</obj_property>
<obj_property name="ObjectShortName">m_axis_tuser[0:0]</obj_property>
</wvobject>
<wvobject type="logic" fp_name="/tb_ccn/inst_dut_pack/inst_fifo/s_axis_aresetn">
<obj_property name="ElementShortName">s_axis_aresetn</obj_property>
<obj_property name="ObjectShortName">s_axis_aresetn</obj_property>
</wvobject>
</wave_config>
testinput_002.txt
\ No newline at end of file
testoutput_002.txt
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment