|
@ -2,19 +2,12 @@ library ieee; |
|
|
use ieee.std_logic_1164.all; |
|
|
use ieee.std_logic_1164.all; |
|
|
use ieee.numeric_std.all; |
|
|
use ieee.numeric_std.all; |
|
|
|
|
|
|
|
|
--+ including vhdl 2008 libraries |
|
|
|
|
|
--+ These lines can be commented out when using |
|
|
|
|
|
--+ a simulator with built-in VHDL 2008 support |
|
|
|
|
|
--library ieee_proposed; |
|
|
|
|
|
-- use ieee_proposed.standard_additions.all; |
|
|
|
|
|
-- use ieee_proposed.std_logic_1164_additions.all; |
|
|
|
|
|
-- use ieee_proposed.numeric_std_additions.all; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library osvvm; |
|
|
library osvvm; |
|
|
use osvvm.RandomPkg.all; |
|
|
use osvvm.RandomPkg.all; |
|
|
|
|
|
|
|
|
library libvhdl; |
|
|
library libvhdl; |
|
|
use libvhdl.DictP.all; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -28,6 +21,20 @@ architecture sim of DictT is |
|
|
|
|
|
|
|
|
type t_scoreboard is array (natural range <>) of std_logic_vector(7 downto 0); |
|
|
type t_scoreboard is array (natural range <>) of std_logic_vector(7 downto 0); |
|
|
|
|
|
|
|
|
|
|
|
function to_string(d : string) return string is |
|
|
|
|
|
begin |
|
|
|
|
|
return d; |
|
|
|
|
|
end function to_string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package StringSlvDict is new libvhdl.DictP |
|
|
|
|
|
generic map (KEY_TYPE => string, |
|
|
|
|
|
VALUE_TYPE => std_logic_vector, |
|
|
|
|
|
key_to_string => to_string, |
|
|
|
|
|
value_to_string => to_hstring); |
|
|
|
|
|
|
|
|
|
|
|
use StringSlvDict.all; |
|
|
|
|
|
|
|
|
shared variable sv_dict : t_dict; |
|
|
shared variable sv_dict : t_dict; |
|
|
shared variable sv_dact : t_dict; |
|
|
shared variable sv_dact : t_dict; |
|
|
shared variable sv_duct : t_dict; |
|
|
shared variable sv_duct : t_dict; |
|
@ -36,6 +43,7 @@ architecture sim of DictT is |
|
|
begin |
|
|
begin |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DictInitP : process is |
|
|
DictInitP : process is |
|
|
begin |
|
|
begin |
|
|
sv_dict.init(false); |
|
|
sv_dict.init(false); |
|
@ -47,11 +55,11 @@ begin |
|
|
|
|
|
|
|
|
DictTestP : process is |
|
|
DictTestP : process is |
|
|
variable v_key : t_dict_key_ptr; |
|
|
variable v_key : t_dict_key_ptr; |
|
|
|
|
|
variable v_last_key : t_dict_key_ptr; |
|
|
variable v_random : RandomPType; |
|
|
variable v_random : RandomPType; |
|
|
variable v_input : std_logic_vector(7 downto 0); |
|
|
variable v_input : std_logic_vector(7 downto 0); |
|
|
variable v_output : std_logic_vector(7 downto 0); |
|
|
variable v_output : std_logic_vector(7 downto 0); |
|
|
variable v_scoreboard : t_scoreboard(0 to 511); |
|
|
variable v_scoreboard : t_scoreboard(0 to 511); |
|
|
variable v_error : t_dict_error; |
|
|
|
|
|
begin |
|
|
begin |
|
|
v_random.InitSeed(v_random'instance_name); |
|
|
v_random.InitSeed(v_random'instance_name); |
|
|
|
|
|
|
|
@ -60,19 +68,11 @@ begin |
|
|
report "ERROR: Dict should be empty" |
|
|
report "ERROR: Dict should be empty" |
|
|
severity failure; |
|
|
severity failure; |
|
|
|
|
|
|
|
|
-- The dict shouldn_t accept an empty key string |
|
|
|
|
|
report "INFO: Test 0: Try to set an entry with empty key string"; |
|
|
|
|
|
sv_dict.set("", x"0123456789", v_error); |
|
|
|
|
|
assert v_error = KEY_INVALID |
|
|
|
|
|
report "ERROR: Key '' should raise a KEY_INVALID error" |
|
|
|
|
|
severity failure; |
|
|
|
|
|
report "INFO: Test successful"; |
|
|
|
|
|
|
|
|
|
|
|
-- fill dictionary and check count |
|
|
-- fill dictionary and check count |
|
|
report "INFO: Test 1: Fill dictionary"; |
|
|
report "INFO: Test 1: Fill dictionary"; |
|
|
for i in 0 to 255 loop |
|
|
for i in 0 to 255 loop |
|
|
v_input := v_random.RandSlv(8); |
|
|
v_input := v_random.RandSlv(8); |
|
|
sv_dict.set(integer'image(i), v_input, v_error); |
|
|
|
|
|
|
|
|
sv_dict.set(integer'image(i), v_input); |
|
|
v_scoreboard(i) := v_input; |
|
|
v_scoreboard(i) := v_input; |
|
|
assert sv_dict.size = i+1 |
|
|
assert sv_dict.size = i+1 |
|
|
report "ERROR: Dict should have " & to_string(i+1) & " entries" |
|
|
report "ERROR: Dict should have " & to_string(i+1) & " entries" |
|
@ -83,7 +83,7 @@ begin |
|
|
-- read all entries and check for correct data |
|
|
-- read all entries and check for correct data |
|
|
report "INFO: Test 2: Read dictionary"; |
|
|
report "INFO: Test 2: Read dictionary"; |
|
|
for i in 0 to 255 loop |
|
|
for i in 0 to 255 loop |
|
|
sv_dict.get(integer'image(i), v_output, v_error); |
|
|
|
|
|
|
|
|
sv_dict.get(integer'image(i), v_output); |
|
|
assert v_output = v_scoreboard(i) |
|
|
assert v_output = v_scoreboard(i) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
severity failure; |
|
|
severity failure; |
|
@ -93,9 +93,9 @@ begin |
|
|
-- overwrite a key/value pair |
|
|
-- overwrite a key/value pair |
|
|
report "INFO: Test 3: Overwrite a entry"; |
|
|
report "INFO: Test 3: Overwrite a entry"; |
|
|
v_input := v_random.RandSlv(8); |
|
|
v_input := v_random.RandSlv(8); |
|
|
sv_dict.set("128", v_input, v_error); |
|
|
|
|
|
|
|
|
sv_dict.set("128", v_input); |
|
|
v_scoreboard(128) := v_input; |
|
|
v_scoreboard(128) := v_input; |
|
|
sv_dict.get("128", v_output, v_error); |
|
|
|
|
|
|
|
|
sv_dict.get("128", v_output); |
|
|
assert v_output = v_scoreboard(128) |
|
|
assert v_output = v_scoreboard(128) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(128)) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(128)) |
|
|
severity failure; |
|
|
severity failure; |
|
@ -121,14 +121,15 @@ begin |
|
|
assert v_key.all = integer'image(i) |
|
|
assert v_key.all = integer'image(i) |
|
|
report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i) |
|
|
report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i) |
|
|
severity failure; |
|
|
severity failure; |
|
|
sv_dict.get(v_key.all, v_output, v_error); |
|
|
|
|
|
|
|
|
sv_dict.get(v_key.all, v_output); |
|
|
assert v_key.all = integer'image(i) and v_output = v_scoreboard(i) |
|
|
assert v_key.all = integer'image(i) and v_output = v_scoreboard(i) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
severity failure; |
|
|
severity failure; |
|
|
end loop; |
|
|
end loop; |
|
|
|
|
|
v_last_key := v_key; |
|
|
v_key := new string'(sv_dict.iter(UP)); |
|
|
v_key := new string'(sv_dict.iter(UP)); |
|
|
assert v_key.all = "" |
|
|
|
|
|
report "ERROR: Got key " & v_key.all & ", expected empty key" |
|
|
|
|
|
|
|
|
assert v_key.all = v_last_key.all |
|
|
|
|
|
report "ERROR: Got key " & v_key.all & ", expected key" & v_last_key.all |
|
|
severity failure; |
|
|
severity failure; |
|
|
report "INFO: Test successful"; |
|
|
report "INFO: Test successful"; |
|
|
|
|
|
|
|
@ -140,14 +141,15 @@ begin |
|
|
assert v_key.all = integer'image(i) |
|
|
assert v_key.all = integer'image(i) |
|
|
report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i) |
|
|
report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i) |
|
|
severity failure; |
|
|
severity failure; |
|
|
sv_dict.get(v_key.all, v_output, v_error); |
|
|
|
|
|
|
|
|
sv_dict.get(v_key.all, v_output); |
|
|
assert v_key.all = integer'image(i) and v_output = v_scoreboard(i) |
|
|
assert v_key.all = integer'image(i) and v_output = v_scoreboard(i) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
severity failure; |
|
|
severity failure; |
|
|
end loop; |
|
|
end loop; |
|
|
|
|
|
v_last_key := v_key; |
|
|
v_key := new string'(sv_dict.iter(DOWN)); |
|
|
v_key := new string'(sv_dict.iter(DOWN)); |
|
|
assert v_key.all = "" |
|
|
|
|
|
report "ERROR: Got key " & v_key.all & ", expected empty key" |
|
|
|
|
|
|
|
|
assert v_key.all = v_last_key.all |
|
|
|
|
|
report "ERROR: Got key " & v_key.all & ", expected key" & v_last_key.all |
|
|
severity failure; |
|
|
severity failure; |
|
|
deallocate(v_key); |
|
|
deallocate(v_key); |
|
|
report "INFO: Test successful"; |
|
|
report "INFO: Test successful"; |
|
@ -157,17 +159,17 @@ begin |
|
|
report "INFO: Test 7: Merge dictionaries"; |
|
|
report "INFO: Test 7: Merge dictionaries"; |
|
|
for i in 256 to 511 loop |
|
|
for i in 256 to 511 loop |
|
|
v_input := v_random.RandSlv(8); |
|
|
v_input := v_random.RandSlv(8); |
|
|
sv_dact.set(integer'image(i), v_input, v_error); |
|
|
|
|
|
|
|
|
sv_dact.set(integer'image(i), v_input); |
|
|
v_scoreboard(i) := v_input; |
|
|
v_scoreboard(i) := v_input; |
|
|
assert sv_dact.size = i-255 |
|
|
assert sv_dact.size = i-255 |
|
|
report "ERROR: Dict should have " & to_string(i-255) & " entries" |
|
|
report "ERROR: Dict should have " & to_string(i-255) & " entries" |
|
|
severity failure; |
|
|
severity failure; |
|
|
end loop; |
|
|
end loop; |
|
|
-- merge dictionaries |
|
|
-- merge dictionaries |
|
|
merge(sv_dict, sv_dact, sv_duct, v_error); |
|
|
|
|
|
|
|
|
merge(sv_dict, sv_dact, sv_duct); |
|
|
-- read all entries and check for correct data |
|
|
-- read all entries and check for correct data |
|
|
for i in 0 to 511 loop |
|
|
for i in 0 to 511 loop |
|
|
sv_duct.get(integer'image(i), v_output, v_error); |
|
|
|
|
|
|
|
|
sv_duct.get(integer'image(i), v_output); |
|
|
assert v_output = v_scoreboard(i) |
|
|
assert v_output = v_scoreboard(i) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i)) |
|
|
severity failure; |
|
|
severity failure; |
|
@ -176,7 +178,7 @@ begin |
|
|
|
|
|
|
|
|
-- Remove key/value pair from head of dictionary |
|
|
-- Remove key/value pair from head of dictionary |
|
|
report "INFO: Test 8: Removing entry from head of dictionary"; |
|
|
report "INFO: Test 8: Removing entry from head of dictionary"; |
|
|
sv_dict.del("255", v_error); |
|
|
|
|
|
|
|
|
sv_dict.del("255"); |
|
|
assert not(sv_dict.hasKey("255")) |
|
|
assert not(sv_dict.hasKey("255")) |
|
|
report "ERROR: Key 255 shouldn't exist in dictionary" |
|
|
report "ERROR: Key 255 shouldn't exist in dictionary" |
|
|
severity failure; |
|
|
severity failure; |
|
@ -184,7 +186,7 @@ begin |
|
|
|
|
|
|
|
|
-- Remove key/value pair from head of dictionary |
|
|
-- Remove key/value pair from head of dictionary |
|
|
report "INFO: Test 9: Removing entry from middle of dictionary"; |
|
|
report "INFO: Test 9: Removing entry from middle of dictionary"; |
|
|
sv_dict.del("127", v_error); |
|
|
|
|
|
|
|
|
sv_dict.del("127"); |
|
|
assert not(sv_dict.hasKey("127")) |
|
|
assert not(sv_dict.hasKey("127")) |
|
|
report "ERROR: Key 127 shouldn't exist in dictionary" |
|
|
report "ERROR: Key 127 shouldn't exist in dictionary" |
|
|
severity failure; |
|
|
severity failure; |
|
@ -192,7 +194,7 @@ begin |
|
|
|
|
|
|
|
|
-- Remove key/value pair from head of dictionary |
|
|
-- Remove key/value pair from head of dictionary |
|
|
report "INFO: Test 10: Removing entry from beginning of dictionary"; |
|
|
report "INFO: Test 10: Removing entry from beginning of dictionary"; |
|
|
sv_dict.del("0", v_error); |
|
|
|
|
|
|
|
|
sv_dict.del("0"); |
|
|
assert not(sv_dict.hasKey("0")) |
|
|
assert not(sv_dict.hasKey("0")) |
|
|
report "ERROR: Key 0 shouldn't exist in dictionary" |
|
|
report "ERROR: Key 0 shouldn't exist in dictionary" |
|
|
severity failure; |
|
|
severity failure; |
|
@ -200,7 +202,7 @@ begin |
|
|
|
|
|
|
|
|
-- Remove key/value pair from head of dictionary |
|
|
-- Remove key/value pair from head of dictionary |
|
|
report "INFO: Test 11: Clear all entries from dictionary"; |
|
|
report "INFO: Test 11: Clear all entries from dictionary"; |
|
|
sv_dict.clear(v_error); |
|
|
|
|
|
|
|
|
sv_dict.clear; |
|
|
assert sv_dict.size = 0 |
|
|
assert sv_dict.size = 0 |
|
|
report "ERROR: Dict should be empty" |
|
|
report "ERROR: Dict should be empty" |
|
|
severity failure; |
|
|
severity failure; |
|
|