rtps-fpga/src/Tests/Level_0/L0_rtps_writer_test1_vrkdp.vhd
Greek 981ca09149 Change Type-Dependant Code Interface, and Code refactoring
The instantiation of the KEY related entities is moved outside the DDS
Endpoints (Currently only changed in DDS Writer). Define new KEY_HOLDER
entity that is responsible for all Key related type-specific code.
Fix syntax of DDS Writer, and misc code refactoring.
2021-03-09 14:56:54 +01:00

475 lines
18 KiB
VHDL

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
library osvvm; -- Utility Library
context osvvm.OsvvmContext;
use work.rtps_package.all;
use work.user_config.all;
use work.rtps_config_package.all;
use work.rtps_test_package.all;
-- This testbench tests the metatraffic operation behaviour of the RTPS Writer. (Remote Endpoint matching and Memory behaviour)
-- This testbench is using external names to access the memory of the rtps_reader directly and check the contents at the supposed locations.
-- This testbench covers following:
-- * Mathing Endpoint
-- * Memory Full Behaviour
-- * Unmatching Endpoint
-- * Unmatching Participant
-- * Updating previously matched Endpoint
-- * Unknown Metatraffic Operation
entity L0_rtps_writer_test1_vrkdp is
end entity;
architecture testbench of L0_rtps_writer_test1_vrkdp is
-- *CONSTANT DECLARATION*
constant MAX_REMOTE_ENDPOINTS : natural := 3;
-- *TYPE DECLARATION*
type TEST_STAGE_TYPE is (IDLE, BUSY);
type TEST_RAM_TYPE is array (0 to (MAX_REMOTE_ENDPOINTS*READER_ENDPOINT_FRAME_SIZE_A)-1) of std_logic_vector(WORD_WIDTH-1 downto 0);
-- *SIGNAL DECLARATION*
signal clk, empty_user, empty_meta, rd_meta, last_word_in_meta : std_logic := '0';
signal reset : std_logic := '1';
signal data_in_meta : std_logic_vector(WORD_WIDTH-1 downto 0) := (others => '0');
signal start_hc : std_logic := '0';
signal stim_stage : TEST_STAGE_TYPE := IDLE;
shared variable stimulus : TEST_PACKET_TYPE := EMPTY_TEST_PACKET;
signal packet_sent : std_logic := '0';
signal cnt_stim : natural := 0;
signal start : std_logic := '0';
shared variable SB_mem : work.ScoreBoardPkg_MemoryTest.ScoreBoardPType;
signal stim_done, mem_check_done, test_done : std_logic := '0';
-- *FUNCTION DECLARATION*
procedure wait_on_sent is
begin
wait until rising_edge(packet_sent);
end procedure;
procedure wait_on_mem_check is
begin
if (mem_check_done /= '1') then
wait until mem_check_done = '1';
end if;
end procedure;
procedure wait_on_completion is
begin
if (test_done /= '1') then
wait until test_done = '1';
end if;
end procedure;
begin
-- Unit Under Test
uut : entity work.rtps_writer(arch)
generic map (
RELIABILTY_QOS => RELIABLE_RELIABILITY_QOS,
LIVELINESS_QOS => AUTOMATIC_LIVELINESS_QOS,
DURABILITY_QOS => VOLATILE_DURABILITY_QOS,
DESTINATION_ORDER_QOS => BY_RECEPTION_TIMESTAMP_DESTINATION_ORDER_QOS,
ACKNACK_RESPONSE_DELAY => DURATION_ZERO,
ACKNACK_SUPPRESSION_DELAY => DURATION_ZERO,
LEASE_DURATION => DURATION_INFINITE,
HEARTBEAT_PERIOD => DURATION_INFINITE,
ENTITYID => DEFAULT_WRITER_ENTITYID,
WITH_KEY => TRUE,
PUSH_MODE => TRUE,
INLINE_QOS => gen_inline_qos(NUM_READERS+7),
MAX_REMOTE_ENDPOINTS => MAX_REMOTE_ENDPOINTS
)
port map (
clk => clk,
reset => reset,
time => TIME_ZERO,
empty_user => '1',
rd_user => open,
data_in_user => (others => '0'),
last_word_in_user => '0',
empty_meta => empty_meta or packet_sent,
rd_meta => rd_meta,
data_in_meta => data_in_meta,
last_word_in_meta => last_word_in_meta,
alive_sig => open,
wr_rtps => open,
full_rtps => '0',
last_word_out_rtps => open,
data_out_rtps => open,
liveliness_assertion => '0',
data_available => '0',
start_hc => start_hc,
opcode_hc => open,
ack_hc => '0',
seq_nr_hc => open,
done_hc => '0',
ret_hc => ERROR,
get_data_hc => open,
data_in_hc => (others => '0'),
valid_in_hc => '0',
ready_in_hc => open,
last_word_in_hc => '0',
cc_instance_handle => HANDLE_NIL,
cc_kind => ALIVE,
cc_source_timestamp => TIME_INVALID,
cc_seq_nr => SEQUENCENUMBER_UNKNOWN
);
stimulus_prc : process
variable RV : RandomPType;
variable p0, p1, participant : PARTICIPANT_DATA_TYPE := DEFAULT_PARTICIPANT_DATA;
variable e0, e1, e2, e3, endpoint : ENDPOINT_DATA_TYPE := DEFAULT_ENDPOINT_DATA;
-- Wrapper to use procedure as function
impure function gen_rand_loc_2 return LOCATOR_TYPE is
variable ret : LOCATOR_TYPE := EMPTY_LOCATOR;
begin
gen_rand_loc(RV, ret);
return ret;
end function;
impure function gen_rand_guid_prefix return GUIDPREFIX_TYPE is
variable ret : GUIDPREFIX_TYPE;
begin
ret := (0 => RV.RandSlv(WORD_WIDTH), 1 => RV.RandSlv(WORD_WIDTH), 2 => RV.RandSlv(WORD_WIDTH));
return ret;
end function;
procedure start_test is
begin
start <= '1';
wait until rising_edge(clk);
start <= '0';
wait until rising_edge(clk);
end procedure;
begin
SetAlertLogName("rtps_writer - (Volatile, Reliable, Keyed, By Reception Timestamp, Push Mode) - Level 0 - Metatraffic Handling");
SetAlertEnable(FAILURE, TRUE);
SetAlertEnable(ERROR, TRUE);
SetAlertEnable(WARNING, TRUE);
SetLogEnable(DEBUG, FALSE);
SetLogEnable(PASSED, FALSE);
SetLogEnable(INFO, TRUE);
RV.InitSeed(RV'instance_name);
p0.guidPrefix := gen_rand_guid_prefix;
p1.guidPrefix := gen_rand_guid_prefix;
-- Endpoint 1
e0 := DEFAULT_ENDPOINT_DATA;
e0.participant := p0;
e0.entityid := RV.RandSlv(ENTITYID_WIDTH);
e0.unicastLocatorList := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
-- Endpoint 2
e1 := DEFAULT_ENDPOINT_DATA;
e1.participant := p0;
e1.entityid := RV.RandSlv(ENTITYID_WIDTH);
e1.unicastLocatorList := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
e1.reliability := BEST_EFFORT_RELIABILITY_QOS;
-- Endpoint 3
e2 := DEFAULT_ENDPOINT_DATA;
e2.participant := p1;
e2.entityid := RV.RandSlv(ENTITYID_WIDTH);
e2.unicastLocatorList := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
e2.expectsInlineQoS(0) := '1';
e2.durability := TRANSIENT_LOCAL_DURABILITY_QOS;
e2.reliability := BEST_EFFORT_RELIABILITY_QOS;
-- Endpoint 4
e3 := DEFAULT_ENDPOINT_DATA;
e3.participant := p1;
e3.entityid := RV.RandSlv(ENTITYID_WIDTH);
e3.unicastLocatorList := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
e3.expectsInlineQoS(0) := '1';
Log("Initiating Test", INFO);
stim_done <= '0';
start <= '0';
reset <= '1';
wait until rising_edge(clk);
wait until rising_edge(clk);
reset <= '0';
Log("Insert Endpoint 0 Participant 0", INFO);
endpoint := e0;
endpoint.nr := 0;
endpoint.match := MATCH;
gen_endpoint_match_frame(endpoint, stimulus);
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p0e0,0,0]
Log("Insert Endpoint 1 Participant 0", INFO);
endpoint := e1;
endpoint.nr := 1;
endpoint.match := MATCH;
gen_endpoint_match_frame(endpoint, stimulus);
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p0e0,p0e1,0]
Log("Insert Endpoint 2 Participant 1", INFO);
endpoint := e2;
endpoint.nr := 2;
endpoint.match := MATCH;
gen_endpoint_match_frame(endpoint, stimulus);
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p0e0,p0e1,p1e2]
Log("Ignore Endpoint 3 Participant 1 [Memory Full]", INFO);
endpoint := e3;
endpoint.match := MATCH;
gen_endpoint_match_frame(endpoint, stimulus);
-- Re-check Mem-State
endpoint := e0;
endpoint.nr := 0;
endpoint.match := MATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
endpoint := e1;
endpoint.nr := 1;
endpoint.match := MATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
endpoint := e2;
endpoint.nr := 2;
endpoint.match := MATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p0e0,p0e1,p1e3]
Log("Remove Endpoint 2 Participant 1", INFO);
endpoint := e2;
endpoint.nr := 2;
endpoint.match := UNMATCH;
gen_endpoint_match_frame(endpoint, stimulus);
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p0e0,p0e1,0]
Log("Insert Endpoint 3 Participant 1", INFO);
endpoint := e3;
endpoint.nr := 2;
endpoint.match := MATCH;
gen_endpoint_match_frame(endpoint, stimulus);
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p0e0,p0e1,p1e3]
Log("Remove Participant 0", INFO);
participant := p0;
participant.match := UNMATCH;
gen_participant_match_frame(participant, stimulus);
-- Remove Endpoint 0
endpoint := e0;
endpoint.nr := 0;
endpoint.match := UNMATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
-- Remove Endpoint 1
endpoint := e1;
endpoint.nr := 1;
endpoint.match := UNMATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [0,0,p1e3]
Log("Insert Endpoint 2 Participant 1", INFO);
endpoint := e2;
endpoint.nr := 0;
endpoint.match := MATCH;
gen_endpoint_match_frame(endpoint, stimulus);
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p1e2,0,p1e3]
Log("Unknown Metatraffic Operation followed by insertion of Enpoint 0 Participant 0", INFO);
for i in 0 to 9 loop
stimulus.data(i) := RV.RandSlv(WORD_WIDTH);
end loop;
stimulus.last(9) := '1';
stimulus.length := 10;
endpoint := e0;
endpoint.nr := 1;
endpoint.match := MATCH;
gen_endpoint_match_frame(endpoint, stimulus);
-- Re-check Mem-State
endpoint := e2;
endpoint.nr := 0;
endpoint.match := MATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
endpoint := e0;
endpoint.nr := 1;
endpoint.match := MATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
endpoint := e3;
endpoint.nr := 2;
endpoint.match := MATCH;
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p1e2,p0e0,p1e3]
Log("Update Endpoint 2 Participant 1", INFO);
endpoint := e2;
endpoint.nr := 0;
endpoint.match := MATCH;
endpoint.unicastLocatorList := (numLocators => int(1,CDR_LONG_WIDTH), locator => (0 => gen_rand_loc_2, others => EMPTY_LOCATOR));
gen_endpoint_match_frame(endpoint, stimulus);
SB_mem.Push(gen_reader_endpoint_mem_frame_a(endpoint));
start_test;
wait_on_sent;
stimulus := EMPTY_TEST_PACKET;
wait_on_mem_check;
-- MEMORY STATE [p1e2,p0e0,p1e3]
stim_done <= '1';
wait_on_completion;
TranscriptOpen(RESULTS_FILE, APPEND_MODE);
SetTranscriptMirror;
ReportAlerts;
TranscriptClose;
std.env.stop;
wait;
end process;
clock_prc : process
begin
clk <= '0';
wait for 25 ns;
clk <= '1';
wait for 25 ns;
end process;
in_empty_prc : process
begin
empty_meta <= '0';
wait until rd_meta = '1';
wait until rising_edge(clk);
empty_meta <= '1';
wait until rising_edge(clk);
end process;
alert_prc : process(all)
begin
if rising_edge(clk) then
alertif(empty_meta = '1' and rd_meta = '1', "Input FIFO read signal high while empty signal high", ERROR);
alertif(start_hc = '1', "Unexpected History Cache Operation initiated", ERROR);
end if;
end process;
input_prc : process(all)
begin
data_in_meta <= stimulus.data(cnt_stim);
last_word_in_meta <= stimulus.last(cnt_stim);
if rising_edge(clk) then
if (reset = '1') then
cnt_stim <= 0;
stim_stage <= IDLE;
packet_sent <= '1';
else
case (stim_stage) is
when IDLE =>
if (start = '1' and stimulus.length /= 0) then
stim_stage <= BUSY;
packet_sent <= '0';
end if;
when BUSY =>
if (rd_meta = '1') then
if (cnt_stim = stimulus.length-1) then
stim_stage <= IDLE;
packet_sent <= '1';
cnt_stim <= 0;
else
cnt_stim <= cnt_stim + 1;
end if;
end if;
end case;
end if;
end if;
end process;
done_proc : process(clk)
begin
if rising_edge(clk) then
if (stim_done = '1' and SB_mem.empty) then
test_done <= '1';
else
test_done <= '0';
end if;
end if;
end process;
mem_check_prc : process
alias mem is <<signal uut.mem_ctrl_inst.ram_inst.mem : TEST_RAM_TYPE>>;
alias mem_op_done is <<signal uut.mem_op_done : std_logic>>;
alias idle_sig is <<signal uut.idle_sig : std_logic>>;
variable reference : TEST_READER_ENDPOINT_MEMORY_FRAME_TYPE_A;
begin
mem_check_done <= '0';
-- SAFEGUARD: (Prevent Fall-through Behavior)
if (reset /= '0') then
wait until reset = '0';
end if;
-- Wait for Packet to be sent
wait until rising_edge(packet_sent);
-- Wait for UUT IDLE state
if (idle_sig /= '1') then
wait until idle_sig = '1';
end if;
-- Wait for ongoing memory operation
if (mem_op_done /= '1') then
wait until mem_op_done = '1';
end if;
while (not SB_mem.empty) loop
SB_mem.Pop(reference);
for i in 0 to reference'length-1 loop
AffirmIf(?? (mem(reference(i).addr) ?= reference(i).data), "Address: " & integer'image(reference(i).addr) & " Received: " & to_hstring(mem(reference(i).addr)) & " Expected: " & to_hstring(reference(i).data));
end loop;
end loop;
-- Toggle High for one clock cycle
mem_check_done <= '1';
wait until rising_edge(clk);
end process;
watchdog : process
begin
wait for 1 ms;
Alert("Test timeout", FAILURE);
std.env.stop;
end process;
end architecture;