Skip to content

Commit

Permalink
Merge pull request VUnit#561 from eschmidscs/bugfix/check_axi_stream
Browse files Browse the repository at this point in the history
Bugfix/check axi stream
  • Loading branch information
kraigher authored Oct 10, 2019
2 parents a2f189f + cc41997 commit 214de98
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 54 deletions.
11 changes: 11 additions & 0 deletions vunit/vhdl/verification_components/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ def gen_avalon_master_tests(obj, *args):
for test in tb_wishbone_master.get_tests():
gen_wb_tests(test, [8, 32], [1, 64], [0.3, 1.0], [0.3, 1.0], [0.4, 0.0])

tb_axi_stream = lib.test_bench("tb_axi_stream")

for id_length in [0, 8]:
for dest_length in [0, 8]:
for user_length in [0, 8]:
for test in tb_axi_stream.get_tests("*check"):
test.add_config(name="id_l=%d dest_l=%d user_l=%d" % (id_length, dest_length, user_length),
generics=dict(g_id_length=id_length,
g_dest_length=dest_length,
g_user_length=user_length))

tb_axi_stream_protocol_checker = lib.test_bench("tb_axi_stream_protocol_checker")

for data_length in [0, 8]:
Expand Down
32 changes: 20 additions & 12 deletions vunit/vhdl/verification_components/src/axi_stream_pkg.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -708,19 +708,27 @@ package body axi_stream_pkg is
end if;
else
push_string(check_msg, msg);
normalized_data(expected'length-1 downto 0) := expected;
push_std_ulogic_vector(check_msg, normalized_data);
if normalized_data'length > 0 then
normalized_data(expected'length-1 downto 0) := expected;
push_std_ulogic_vector(check_msg, normalized_data);
normalized_keep(tkeep'length-1 downto 0) := tkeep;
push_std_ulogic_vector(check_msg, normalized_keep);
normalized_strb(tstrb'length-1 downto 0) := tstrb;
push_std_ulogic_vector(check_msg, normalized_strb);
end if;
push_std_ulogic(check_msg, tlast);
normalized_keep(tkeep'length-1 downto 0) := tkeep;
push_std_ulogic_vector(check_msg, normalized_keep);
normalized_strb(tstrb'length-1 downto 0) := tstrb;
push_std_ulogic_vector(check_msg, normalized_strb);
normalized_id(tid'length-1 downto 0) := tid;
push_std_ulogic_vector(check_msg, normalized_id);
normalized_dest(tdest'length-1 downto 0) := tdest;
push_std_ulogic_vector(check_msg, normalized_dest);
normalized_user(tuser'length-1 downto 0) := tuser;
push_std_ulogic_vector(check_msg, normalized_user);
if normalized_id'length > 0 then
normalized_id(tid'length-1 downto 0) := tid;
push_std_ulogic_vector(check_msg, normalized_id);
end if;
if normalized_dest'length > 0 then
normalized_dest(tdest'length-1 downto 0) := tdest;
push_std_ulogic_vector(check_msg, normalized_dest);
end if;
if normalized_user'length > 0 then
normalized_user(tuser'length-1 downto 0) := tuser;
push_std_ulogic_vector(check_msg, normalized_user);
end if;
send(net, axi_stream.p_actor, check_msg);
end if;
end procedure;
Expand Down
8 changes: 3 additions & 5 deletions vunit/vhdl/verification_components/src/axi_stream_slave.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ begin
tready <= '0';

report_msg := new_string_ptr(pop_string(msg));
check_equal(tdata, pop_std_ulogic_vector(msg), "TDATA mismatch, " & to_string(report_msg));
check_equal(tlast, pop_std_ulogic(msg), "TLAST mismatch, " & to_string(report_msg));
if tkeep'length > 0 then
if tdata'length > 0 then
check_equal(tdata, pop_std_ulogic_vector(msg), "TDATA mismatch, " & to_string(report_msg));
check_equal(tkeep, pop_std_ulogic_vector(msg), "TKEEP mismatch, " & to_string(report_msg));
end if;
if tstrb'length > 0 then
check_equal(tstrb, pop_std_ulogic_vector(msg), "TSTRB mismatch, " & to_string(report_msg));
end if;
check_equal(tlast, pop_std_ulogic(msg), "TLAST mismatch, " & to_string(report_msg));
if tid'length > 0 then
check_equal(tid, pop_std_ulogic_vector(msg), "TID mismatch, " & to_string(report_msg));
end if;
Expand Down
133 changes: 96 additions & 37 deletions vunit/vhdl/verification_components/test/tb_axi_stream.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,39 @@ use work.stream_slave_pkg.all;
use work.sync_pkg.all;

entity tb_axi_stream is
generic(runner_cfg : string);
generic(
runner_cfg : string;
g_id_length : natural := 8;
g_dest_length : natural := 8;
g_user_length : natural := 8
);
end entity;

architecture a of tb_axi_stream is
constant master_axi_stream : axi_stream_master_t := new_axi_stream_master(
data_length => 8, id_length => 8, dest_length => 8, user_length => 8,
data_length => 8, id_length => g_id_length, dest_length => g_dest_length, user_length => g_user_length,
logger => get_logger("master"), actor => new_actor("master"),
monitor => default_axi_stream_monitor, protocol_checker => default_axi_stream_protocol_checker
);
constant master_stream : stream_master_t := as_stream(master_axi_stream);
constant master_sync : sync_handle_t := as_sync(master_axi_stream);

constant slave_axi_stream : axi_stream_slave_t := new_axi_stream_slave(
data_length => 8, id_length => 8, dest_length => 8, user_length => 8,
data_length => 8, id_length => g_id_length, dest_length => g_dest_length, user_length => g_user_length,
logger => get_logger("slave"), actor => new_actor("slave"),
monitor => default_axi_stream_monitor, protocol_checker => default_axi_stream_protocol_checker
);
constant slave_stream : stream_slave_t := as_stream(slave_axi_stream);
constant slave_sync : sync_handle_t := as_sync(slave_axi_stream);

constant monitor : axi_stream_monitor_t := new_axi_stream_monitor(
data_length => 8, id_length => 8, dest_length => 8, user_length => 8,
data_length => 8, id_length => g_id_length, dest_length => g_dest_length, user_length => g_user_length,
logger => get_logger("monitor"), actor => new_actor("monitor"),
protocol_checker => default_axi_stream_protocol_checker
);

constant protocol_checker : axi_stream_protocol_checker_t := new_axi_stream_protocol_checker(
data_length => 8, id_length => 8, dest_length => 8, user_length => 8,
data_length => 8, id_length => g_id_length, dest_length => g_dest_length, user_length => g_user_length,
logger => get_logger("protocol_checker"),
max_waits => 8
);
Expand Down Expand Up @@ -299,30 +304,72 @@ begin
end loop;

elsif run("test passing check") then
push_axi_stream(net, master_axi_stream, x"12", tlast => '1', tkeep => "1", tstrb => "1", tid => x"23", tdest => x"34", tuser => x"45");
check_axi_stream(net, slave_axi_stream, x"12", '1', "1", "1", x"23", x"34", x"45", "checking axi stream");
if id'length > 0 then
id := x"23";
end if;
if dest'length > 0 then
dest := x"34";
end if;
if user'length > 0 then
user := x"45";
end if;
push_axi_stream(net, master_axi_stream, x"12", tlast => '1', tkeep => "1", tstrb => "1", tid => id, tdest => dest, tuser => user);
check_axi_stream(net, slave_axi_stream, x"12", '1', "1", "1", id, dest, user, "checking axi stream");

elsif run("test passing reduced check") then
push_axi_stream(net, master_axi_stream, x"12", tlast => '1', tkeep => "1", tstrb => "1", tid => x"23", tdest => x"34", tuser => x"45");
if id'length > 0 then
id := x"23";
end if;
if dest'length > 0 then
dest := x"34";
end if;
if user'length > 0 then
user := x"45";
end if;
push_axi_stream(net, master_axi_stream, x"12", tlast => '1', tkeep => "1", tstrb => "1", tid => id, tdest => dest, tuser => user);
check_axi_stream(net, slave_axi_stream, x"12", '1', msg => "reduced checking axi stream");

elsif run("test failing check") then

push_axi_stream(net, master_axi_stream, x"11", tlast => '0', tkeep => "0", tstrb => "0", tid => x"22", tdest => x"33", tuser => x"44");
if id'length > 0 then
id := x"22";
end if;
if dest'length > 0 then
dest := x"33";
end if;
if user'length > 0 then
user := x"44";
end if;
push_axi_stream(net, master_axi_stream, x"11", tlast => '1', tkeep => "0", tstrb => "0", tid => id, tdest => dest, tuser => user);
-- Delay mocking the logger to prevent 'invalid checks' from failing the checks below
wait until rising_edge (aclk) and tvalid = '1';

mocklogger := get_logger("check");
mock(mocklogger);

check_axi_stream(net, slave_axi_stream, x"12", '1', "1", "1", x"23", x"34", x"45", "checking axi stream");
if id'length > 0 then
id := x"23";
end if;
if dest'length > 0 then
dest := x"34";
end if;
if user'length > 0 then
user := x"45";
end if;
check_axi_stream(net, slave_axi_stream, x"12", '0', "1", "1", id, dest, user, "checking axi stream");

check_log(mocklogger, "TDATA mismatch, checking axi stream - Got 0001_0001 (17). Expected 0001_0010 (18).", error);
check_log(mocklogger, "TLAST mismatch, checking axi stream - Got 0. Expected 1.", error);
check_log(mocklogger, "TLAST mismatch, checking axi stream - Got 1. Expected 0.", error);
check_log(mocklogger, "TKEEP mismatch, checking axi stream - Got 0 (0). Expected 1 (1).", error);
check_log(mocklogger, "TSTRB mismatch, checking axi stream - Got 0 (0). Expected 1 (1).", error);
check_log(mocklogger, "TID mismatch, checking axi stream - Got 0010_0010 (34). Expected 0010_0011 (35).", error);
check_log(mocklogger, "TDEST mismatch, checking axi stream - Got 0011_0011 (51). Expected 0011_0100 (52).", error);
check_log(mocklogger, "TUSER mismatch, checking axi stream - Got 0100_0100 (68). Expected 0100_0101 (69).", error);
if id'length > 0 then
check_log(mocklogger, "TID mismatch, checking axi stream - Got 0010_0010 (34). Expected 0010_0011 (35).", error);
end if;
if dest'length > 0 then
check_log(mocklogger, "TDEST mismatch, checking axi stream - Got 0011_0011 (51). Expected 0011_0100 (52).", error);
end if;
if user'length > 0 then
check_log(mocklogger, "TUSER mismatch, checking axi stream - Got 0100_0100 (68). Expected 0100_0101 (69).", error);
end if;

unmock(mocklogger);

Expand All @@ -340,9 +387,9 @@ begin
tlast => last,
tkeep => "1",
tstrb => "1",
tid => std_logic_vector(to_unsigned(42, 8)),
tdest => std_logic_vector(to_unsigned(i+1, 8)),
tuser => std_logic_vector(to_unsigned(i*2, 8)));
tid => std_logic_vector(to_unsigned(42, id'length)),
tdest => std_logic_vector(to_unsigned(i+1, dest'length)),
tuser => std_logic_vector(to_unsigned(i*2, user'length)));
end loop;

last := '0';
Expand All @@ -355,9 +402,9 @@ begin
tlast => last,
tkeep => "1",
tstrb => "1",
tid => std_logic_vector(to_unsigned(42, 8)),
tdest => std_logic_vector(to_unsigned(i+1, 8)),
tuser => std_logic_vector(to_unsigned(i*2, 8)),
tid => std_logic_vector(to_unsigned(42, id'length)),
tdest => std_logic_vector(to_unsigned(i+1, dest'length)),
tuser => std_logic_vector(to_unsigned(i*2, user'length)),
msg => "check blocking",
blocking => false);
end loop;
Expand All @@ -376,18 +423,18 @@ begin
tlast => '1',
tkeep => "0",
tstrb => "0",
tid => std_logic_vector(to_unsigned(42, 8)),
tdest => std_logic_vector(to_unsigned(4, 8)),
tuser => std_logic_vector(to_unsigned(7, 8)));
tid => std_logic_vector(to_unsigned(42, id'length)),
tdest => std_logic_vector(to_unsigned(4, dest'length)),
tuser => std_logic_vector(to_unsigned(7, user'length)));

check_axi_stream(net, slave_axi_stream,
expected => std_logic_vector(to_unsigned(6, 8)),
tlast => '0',
tkeep => "1",
tstrb => "1",
tid => std_logic_vector(to_unsigned(44, 8)),
tdest => std_logic_vector(to_unsigned(5, 8)),
tuser => std_logic_vector(to_unsigned(8, 8)),
tid => std_logic_vector(to_unsigned(44, id'length)),
tdest => std_logic_vector(to_unsigned(5, dest'length)),
tuser => std_logic_vector(to_unsigned(8, g_user_length)),
msg => "check non-blocking",
blocking => false);

Expand All @@ -400,12 +447,18 @@ begin
wait until rising_edge(aclk) and tvalid = '1';

check_log(mocklogger, "TDATA mismatch, check non-blocking - Got 0000_0011 (3). Expected 0000_0110 (6).", error);
check_log(mocklogger, "TLAST mismatch, check non-blocking - Got 1. Expected 0.", error);
check_log(mocklogger, "TKEEP mismatch, check non-blocking - Got 0 (0). Expected 1 (1).", error);
check_log(mocklogger, "TSTRB mismatch, check non-blocking - Got 0 (0). Expected 1 (1).", error);
check_log(mocklogger, "TID mismatch, check non-blocking - Got 0010_1010 (42). Expected 0010_1100 (44).", error);
check_log(mocklogger, "TDEST mismatch, check non-blocking - Got 0000_0100 (4). Expected 0000_0101 (5).", error);
check_log(mocklogger, "TUSER mismatch, check non-blocking - Got 0000_0111 (7). Expected 0000_1000 (8).", error);
check_log(mocklogger, "TLAST mismatch, check non-blocking - Got 1. Expected 0.", error);
if id'length > 0 then
check_log(mocklogger, "TID mismatch, check non-blocking - Got 0010_1010 (42). Expected 0010_1100 (44).", error);
end if;
if dest'length > 0 then
check_log(mocklogger, "TDEST mismatch, check non-blocking - Got 0000_0100 (4). Expected 0000_0101 (5).", error);
end if;
if user'length > 0 then
check_log(mocklogger, "TUSER mismatch, check non-blocking - Got 0000_0111 (7). Expected 0000_1000 (8).", error);
end if;

unmock(mocklogger);

Expand Down Expand Up @@ -440,12 +493,18 @@ begin
check_true(aclk, not_valid, not_valid_keep, "Invalid keep not X");
not_valid_strb <= '1' when tstrb = std_logic_vector'("X") else '0';
check_true(aclk, not_valid, not_valid_strb, "Invalid strb not X");
not_valid_id <= '1' when tid = std_logic_vector'("XXXXXXXX") else '0';
check_true(aclk, not_valid, not_valid_id, "Invalid id not X");
not_valid_dest <= '1' when tdest = std_logic_vector'("XXXXXXXX") else '0';
check_true(aclk, not_valid, not_valid_dest, "Invalid dest not X");
not_valid_user <= '1' when tuser = std_logic_vector'("00000000") else '0';
check_true(aclk, not_valid, not_valid_user, "Invalid user not 0");
GEN_CHECK_INVALID_ID: if g_id_length > 0 generate
not_valid_id <= '1' when tid = std_logic_vector'("XXXXXXXX") else '0';
check_true(aclk, not_valid, not_valid_id, "Invalid id not X");
end generate;
GEN_CHECK_INVALID_DEST: if g_dest_length > 0 generate
not_valid_dest <= '1' when tdest = std_logic_vector'("XXXXXXXX") else '0';
check_true(aclk, not_valid, not_valid_dest, "Invalid dest not X");
end generate;
GEN_CHECK_INVALID_USER: if g_user_length > 0 generate
not_valid_user <= '1' when tuser = std_logic_vector'("00000000") else '0';
check_true(aclk, not_valid, not_valid_user, "Invalid user not 0");
end generate;

axi_stream_slave_inst : entity work.axi_stream_slave
generic map(
Expand Down

0 comments on commit 214de98

Please sign in to comment.