Skip to content

Commit

Permalink
Random test for slave and master connected
Browse files Browse the repository at this point in the history
  • Loading branch information
slaweksiluk committed Mar 2, 2018
1 parent aa19622 commit c561515
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 41 deletions.
24 changes: 22 additions & 2 deletions vunit/vhdl/verification_components/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def gen_wb_slave_tests(obj, dat_width, num_cycles, max_ack_dly, rand_stall):
obj.add_config(name=config_name,
generics=dict(
dat_width=dat_width,
adr_width=8,
adr_width=32,
max_ack_dly=max_ack_dly,
rand_stall=rand_stall,
num_cycles=num_cycles))
Expand All @@ -34,7 +34,27 @@ def gen_wb_slave_tests(obj, dat_width, num_cycles, max_ack_dly, rand_stall):
tb_wishbone_slave = lib.test_bench("tb_wishbone_slave")

for test in tb_wishbone_slave.get_tests():
gen_wb_slave_tests(test, [8, 32], [1, 10], [0, 1, 2], [False, True])
gen_wb_slave_tests(test, [8, 32], [1, 64], [0, 1, 2], [False, True])


def gen_wb_master_tests(obj, dat_width, num_cycles, max_ack_dly, rand_stall):
for dat_width, num_cycles, max_ack_dly, rand_stall \
in product(dat_width, num_cycles, max_ack_dly, rand_stall):
config_name = "dat_width=%i,num_cycles=%i,max_ack_dly=%i,rand_stall=%s" % \
(dat_width, num_cycles, max_ack_dly, rand_stall)
obj.add_config(name=config_name,
generics=dict(
dat_width=dat_width,
adr_width=32,
max_ack_dly=max_ack_dly,
rand_stall=rand_stall,
num_cycles=num_cycles))

tb_wishbone_master = lib.test_bench("tb_wishbone_master")

for test in tb_wishbone_master.get_tests():
gen_wb_master_tests(test, [8], [1, 64], [0, 1, 2], [False, True])


ui.main()

Expand Down
14 changes: 6 additions & 8 deletions vunit/vhdl/verification_components/src/wishbone_master.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
-- You can obtain one at http://mozilla.org/MPL/2.0/.
--
-- Slawomir Siluk [email protected] 2018
-- Wishbome Master Block Pipelined Bus Functional Model
-- Wishbome Master BFM for pipelined block transfers
-- TODO:
-- - stall input
-- - how to handle read req msg received while some writes
-- are still in progress?


-- * Random strobe option
library ieee;
use ieee.std_logic_1164.all;

Expand All @@ -34,6 +30,7 @@ entity wishbone_master is
cyc : out std_logic;
stb : out std_logic;
we : out std_logic;
stall : in std_logic;
ack : in std_logic
);
end entity;
Expand Down Expand Up @@ -88,7 +85,7 @@ begin
cyc <= '1';
stb <= '1';
we <= '0';
wait until rising_edge(clk);
wait until rising_edge(clk) and stall = '0';
stb <= '0';
push(acknowledge_queue, request_msg);
pending_acks := pending_acks +1;
Expand All @@ -102,7 +99,7 @@ begin
cyc <= '1';
stb <= '1';
we <= '1';
wait until rising_edge(clk);
wait until rising_edge(clk) and stall = '0';
info(bus_handle.p_logger, "wr req");
stb <= '0';
push(acknowledge_queue, request_msg);
Expand All @@ -121,6 +118,7 @@ begin
received_acks := 0;
rd_cycle := false;
wr_cycle := false;
wait until rising_edge(clk);
end if;

-- No cycles, juest sleep
Expand Down
23 changes: 12 additions & 11 deletions vunit/vhdl/verification_components/test/tb_wishbone_master.gtkw
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[*]
[*] GTKWave Analyzer v3.3.86 (w)1999-2017 BSI
[*] Sat Jan 27 19:20:41 2018
[*] Fri Mar 2 13:57:11 2018
[*]
[dumpfile] "/home/slawek/git/github/vunit/vunit/vhdl/verification_components/vunit_out/test_output/vunit_lib.tb_wishbone_master.Test_block_read_202b7531a60c370a612dc5673435d50d290a40aa/ghdl/wave.ghw"
[dumpfile_mtime] "Sat Jan 27 19:20:28 2018"
[dumpfile_size] 2167
[savefile] "/home/slawek/git/github/vunit/vunit/vhdl/verification_components/test/tb_wishbone_master.gtkw"
[dumpfile] "/home/lab-buddy/git/github/vunit/vunit/vhdl/verification_components/vunit_out/test_output/vunit_lib.tb_wishbone_master.dat_width=8,num_cycles=10,max_ack_dly=1,rand_stall=True.wr_block_rd_block_8906412844b894c70796945e7fb1d829a571874f/ghdl/wave.ghw"
[dumpfile_mtime] "Fri Mar 2 13:56:52 2018"
[dumpfile_size] 3234
[savefile] "/home/lab-buddy/git/github/vunit/vunit/vhdl/verification_components/test/tb_wishbone_master.gtkw"
[timestart] 0
[size] 1000 600
[pos] -1 -1
*-26.057610 25000000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
*-26.057610 91400000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
[treeopen] top.
[treeopen] top.tb_wishbone_master.
[sst_width] 225
Expand All @@ -20,14 +20,15 @@
top.tb_wishbone_master.dut.cyc
top.tb_wishbone_master.dut.stb
top.tb_wishbone_master.dut.ack
@29
top.tb_wishbone_master.stall
@28
top.tb_wishbone_master.dut.we
top.tb_wishbone_master.dut.clk
#{top.tb_wishbone_master.sel[1:0]} top.tb_wishbone_master.sel[1] top.tb_wishbone_master.sel[0]
#{top.tb_wishbone_master.sel[1:0]} top.tb_wishbone_master.sel[0]
@22
#{top.tb_wishbone_master.dat_o[15:0]} top.tb_wishbone_master.dat_o[15] top.tb_wishbone_master.dat_o[14] top.tb_wishbone_master.dat_o[13] top.tb_wishbone_master.dat_o[12] top.tb_wishbone_master.dat_o[11] top.tb_wishbone_master.dat_o[10] top.tb_wishbone_master.dat_o[9] top.tb_wishbone_master.dat_o[8] top.tb_wishbone_master.dat_o[7] top.tb_wishbone_master.dat_o[6] top.tb_wishbone_master.dat_o[5] top.tb_wishbone_master.dat_o[4] top.tb_wishbone_master.dat_o[3] top.tb_wishbone_master.dat_o[2] top.tb_wishbone_master.dat_o[1] top.tb_wishbone_master.dat_o[0]
#{top.tb_wishbone_master.dat_i[15:0]} top.tb_wishbone_master.dat_i[15] top.tb_wishbone_master.dat_i[14] top.tb_wishbone_master.dat_i[13] top.tb_wishbone_master.dat_i[12] top.tb_wishbone_master.dat_i[11] top.tb_wishbone_master.dat_i[10] top.tb_wishbone_master.dat_i[9] top.tb_wishbone_master.dat_i[8] top.tb_wishbone_master.dat_i[7] top.tb_wishbone_master.dat_i[6] top.tb_wishbone_master.dat_i[5] top.tb_wishbone_master.dat_i[4] top.tb_wishbone_master.dat_i[3] top.tb_wishbone_master.dat_i[2] top.tb_wishbone_master.dat_i[1] top.tb_wishbone_master.dat_i[0]
#{top.tb_wishbone_master.dat_o[15:0]} top.tb_wishbone_master.dat_o[7] top.tb_wishbone_master.dat_o[6] top.tb_wishbone_master.dat_o[5] top.tb_wishbone_master.dat_o[4] top.tb_wishbone_master.dat_o[3] top.tb_wishbone_master.dat_o[2] top.tb_wishbone_master.dat_o[1] top.tb_wishbone_master.dat_o[0]
#{top.tb_wishbone_master.dat_i[15:0]} top.tb_wishbone_master.dat_i[7] top.tb_wishbone_master.dat_i[6] top.tb_wishbone_master.dat_i[5] top.tb_wishbone_master.dat_i[4] top.tb_wishbone_master.dat_i[3] top.tb_wishbone_master.dat_i[2] top.tb_wishbone_master.dat_i[1] top.tb_wishbone_master.dat_i[0]
#{top.tb_wishbone_master.adr[3:0]} top.tb_wishbone_master.adr[3] top.tb_wishbone_master.adr[2] top.tb_wishbone_master.adr[1] top.tb_wishbone_master.adr[0]
@421
top.tb_wishbone_master.slave_index
[pattern_trace] 1
[pattern_trace] 0
42 changes: 23 additions & 19 deletions vunit/vhdl/verification_components/test/tb_wishbone_master.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
--
-- Slawomir Siluk [email protected] 2018
-- TODO:
-- - generic num_block_cycles
-- - generic adr and dat width
-- - generic random test
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
Expand All @@ -22,12 +19,17 @@ library osvvm;
use osvvm.RandomPkg.all;

entity tb_wishbone_master is
generic (runner_cfg : string);
generic (
runner_cfg : string;
dat_width : positive := 8;
adr_width : positive := 4;
num_cycles : positive := 1;
max_ack_dly : natural := 0;
rand_stall : boolean := false
);
end entity;

architecture a of tb_wishbone_master is
constant dat_width : positive := 8;
constant adr_width : positive := 4;

signal clk : std_logic := '0';
signal adr : std_logic_vector(adr_width-1 downto 0);
Expand All @@ -37,22 +39,22 @@ architecture a of tb_wishbone_master is
signal cyc : std_logic := '0';
signal stb : std_logic := '0';
signal we : std_logic := '0';
signal stall : std_logic := '0';
signal ack : std_logic := '0';

constant master_logger : logger_t := get_logger("master");
constant tb_logger : logger_t := get_logger("tb");
constant bus_handle : bus_master_t := new_bus(data_length => dat_width,
address_length => adr_width, logger => master_logger);

constant num_block_cycles : natural := 3;
begin

main_stim : process
variable tmp : std_logic_vector(dat_i'range);
variable value : std_logic_vector(dat_i'range) := x"ab";
variable bus_rd_ref1 : bus_reference_t;
variable bus_rd_ref2 : bus_reference_t;
type bus_reference_arr_t is array (0 to num_block_cycles-1) of bus_reference_t;
type bus_reference_arr_t is array (0 to num_cycles-1) of bus_reference_t;
variable rd_ref : bus_reference_arr_t;
begin
test_runner_setup(runner, runner_cfg);
Expand All @@ -75,43 +77,39 @@ begin
-- check_equal(tmp, value, "read data");
elsif run("wr block rd single") then
info(tb_logger, "Writing...");
for i in 0 to num_block_cycles-1 loop
for i in 0 to num_cycles-1 loop
write_bus(net, bus_handle, i,
std_logic_vector(to_unsigned(i, dat_i'length)));
end loop;

for i in 1 to num_block_cycles loop
for i in 1 to num_cycles loop
wait until ack = '1' and rising_edge(clk);
end loop;
wait until rising_edge(clk);

info(tb_logger, "Reading...");
for i in 0 to num_block_cycles-1 loop
for i in 0 to num_cycles-1 loop
read_bus(net, bus_handle, i, tmp);
check_equal(tmp, std_logic_vector(to_unsigned(i, dat_i'length)), "read data");
end loop;

elsif run("wr block rd block") then
info(tb_logger, "Writing...");
for i in 0 to num_block_cycles-1 loop
for i in 0 to num_cycles-1 loop
write_bus(net, bus_handle, i,
std_logic_vector(to_unsigned(i, dat_i'length)));
end loop;

-- Sleeping is needed to avoid wr and rd cycles coalescing
info(tb_logger, "Sleeping...");
for i in 1 to num_block_cycles loop
wait until ack = '1' and rising_edge(clk);
end loop;
wait until rising_edge(clk);

info(tb_logger, "Reading...");
for i in 0 to num_block_cycles-1 loop
for i in 0 to num_cycles-1 loop
read_bus(net, bus_handle, i, rd_ref(i));
end loop;

info(tb_logger, "Get reads by references...");
for i in 0 to num_block_cycles-1 loop
for i in 0 to num_cycles-1 loop
await_read_bus_reply(net, rd_ref(i), tmp);
check_equal(tmp, std_logic_vector(to_unsigned(i, dat_i'length)), "read data");
end loop;
Expand All @@ -122,7 +120,7 @@ begin
test_runner_cleanup(runner);
wait;
end process;
test_runner_watchdog(runner, 300 ns);
test_runner_watchdog(runner, 100 us);
set_format(display_handler, verbose, true);
show(tb_logger, display_handler, verbose);
show(default_logger, display_handler, verbose);
Expand All @@ -142,10 +140,15 @@ begin
cyc => cyc,
stb => stb,
we => we,
stall => stall,
ack => ack
);

dut_slave : entity work.wishbone_slave
generic map (
max_ack_dly => max_ack_dly,
rand_stall => rand_stall
)
port map (
clk => clk,
adr => adr,
Expand All @@ -155,6 +158,7 @@ begin
cyc => cyc,
stb => stb,
we => we,
stall => stall,
ack => ack
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ begin
test_runner_cleanup(runner);
wait;
end process;
test_runner_watchdog(runner, 1 us);
test_runner_watchdog(runner, 100 us);
set_format(display_handler, verbose, true);
show(tb_logger, display_handler, verbose);
show(default_logger, display_handler, verbose);
Expand Down

0 comments on commit c561515

Please sign in to comment.