Library of reusable VHDL components
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
7.0 KiB

  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. --+ including vhdl 2008 libraries
  5. --+ These lines can be commented out when using
  6. --+ a simulator with built-in VHDL 2008 support
  7. --library ieee_proposed;
  8. -- use ieee_proposed.standard_additions.all;
  9. -- use ieee_proposed.std_logic_1164_additions.all;
  10. -- use ieee_proposed.numeric_std_additions.all;
  11. library osvvm;
  12. use osvvm.RandomPkg.all;
  13. library libvhdl;
  14. use libvhdl.DictP.all;
  15. entity DictT is
  16. end entity DictT;
  17. architecture sim of DictT is
  18. type t_scoreboard is array (natural range <>) of std_logic_vector(7 downto 0);
  19. shared variable sv_dict : t_dict;
  20. shared variable sv_dact : t_dict;
  21. shared variable sv_duct : t_dict;
  22. begin
  23. DictInitP : process is
  24. begin
  25. sv_dict.init(false);
  26. sv_dact.init(false);
  27. sv_duct.init(false);
  28. wait;
  29. end process DictInitP;
  30. DictTestP : process is
  31. variable v_key : t_dict_key_ptr;
  32. variable v_random : RandomPType;
  33. variable v_input : std_logic_vector(7 downto 0);
  34. variable v_output : std_logic_vector(7 downto 0);
  35. variable v_scoreboard : t_scoreboard(0 to 511);
  36. variable v_error : t_dict_error;
  37. begin
  38. v_random.InitSeed(v_random'instance_name);
  39. -- check initial emptiness
  40. assert sv_dict.size = 0
  41. report "ERROR: Dict should be empty"
  42. severity failure;
  43. -- The dict shouldn_t accept an empty key string
  44. report "INFO: Test 0: Try to set an entry with empty key string";
  45. sv_dict.set("", x"0123456789", v_error);
  46. assert v_error = KEY_INVALID
  47. report "ERROR: Key '' should raise a KEY_INVALID error"
  48. severity failure;
  49. report "INFO: Test successful";
  50. -- fill dictionary and check count
  51. report "INFO: Test 1: Fill dictionary";
  52. for i in 0 to 255 loop
  53. v_input := v_random.RandSlv(8);
  54. sv_dict.set(integer'image(i), v_input, v_error);
  55. v_scoreboard(i) := v_input;
  56. assert sv_dict.size = i+1
  57. report "ERROR: Dict should have " & to_string(i+1) & " entries"
  58. severity failure;
  59. end loop;
  60. report "INFO: Test successful";
  61. -- read all entries and check for correct data
  62. report "INFO: Test 2: Read dictionary";
  63. for i in 0 to 255 loop
  64. sv_dict.get(integer'image(i), v_output, v_error);
  65. assert v_output = v_scoreboard(i)
  66. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  67. severity failure;
  68. end loop;
  69. report "INFO: Test successful";
  70. -- overwrite a key/value pair
  71. report "INFO: Test 3: Overwrite a entry";
  72. v_input := v_random.RandSlv(8);
  73. sv_dict.set("128", v_input, v_error);
  74. v_scoreboard(128) := v_input;
  75. sv_dict.get("128", v_output, v_error);
  76. assert v_output = v_scoreboard(128)
  77. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(128))
  78. severity failure;
  79. report "INFO: Test successful";
  80. -- check for existing keys
  81. report "INFO: Test 4: Check hasKey() method";
  82. for i in 0 to 255 loop
  83. assert sv_dict.hasKey(integer'image(i))
  84. report "ERROR: Key" & integer'image(i) & " should exist in dictionary"
  85. severity failure;
  86. end loop;
  87. assert not(sv_dict.hasKey("AFFE"))
  88. report "ERROR: Key AFFE shouldn't exist in dictionary"
  89. severity failure;
  90. report "INFO: Test successful";
  91. -- iterate up over all entries
  92. report "INFO: Test 5: Iterate up over all entries";
  93. sv_dict.setIter;
  94. for i in 0 to 255 loop
  95. v_key := new string'(sv_dict.iter(UP));
  96. assert v_key.all = integer'image(i)
  97. report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i)
  98. severity failure;
  99. sv_dict.get(v_key.all, v_output, v_error);
  100. assert v_key.all = integer'image(i) and v_output = v_scoreboard(i)
  101. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  102. severity failure;
  103. end loop;
  104. v_key := new string'(sv_dict.iter(UP));
  105. assert v_key.all = ""
  106. report "ERROR: Got key " & v_key.all & ", expected empty key"
  107. severity failure;
  108. report "INFO: Test successful";
  109. -- iterate down over all entries
  110. report "INFO: Test 6: Iterate down over all entries";
  111. sv_dict.setIter(HEAD);
  112. for i in 255 downto 0 loop
  113. v_key := new string'(sv_dict.iter(DOWN));
  114. assert v_key.all = integer'image(i)
  115. report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i)
  116. severity failure;
  117. sv_dict.get(v_key.all, v_output, v_error);
  118. assert v_key.all = integer'image(i) and v_output = v_scoreboard(i)
  119. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  120. severity failure;
  121. end loop;
  122. v_key := new string'(sv_dict.iter(DOWN));
  123. assert v_key.all = ""
  124. report "ERROR: Got key " & v_key.all & ", expected empty key"
  125. severity failure;
  126. deallocate(v_key);
  127. report "INFO: Test successful";
  128. -- merge 2 dictionaries
  129. -- fill dictionary and check count
  130. report "INFO: Test 7: Merge dictionaries";
  131. for i in 256 to 511 loop
  132. v_input := v_random.RandSlv(8);
  133. sv_dact.set(integer'image(i), v_input, v_error);
  134. v_scoreboard(i) := v_input;
  135. assert sv_dact.size = i-255
  136. report "ERROR: Dict should have " & to_string(i-255) & " entries"
  137. severity failure;
  138. end loop;
  139. -- merge dictionaries
  140. merge(sv_dict, sv_dact, sv_duct, v_error);
  141. -- read all entries and check for correct data
  142. for i in 0 to 511 loop
  143. sv_duct.get(integer'image(i), v_output, v_error);
  144. assert v_output = v_scoreboard(i)
  145. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  146. severity failure;
  147. end loop;
  148. report "INFO: Test successful";
  149. -- Remove key/value pair from head of dictionary
  150. report "INFO: Test 8: Removing entry from head of dictionary";
  151. sv_dict.del("255", v_error);
  152. assert not(sv_dict.hasKey("255"))
  153. report "ERROR: Key 255 shouldn't exist in dictionary"
  154. severity failure;
  155. report "INFO: Test successful";
  156. -- Remove key/value pair from head of dictionary
  157. report "INFO: Test 9: Removing entry from middle of dictionary";
  158. sv_dict.del("127", v_error);
  159. assert not(sv_dict.hasKey("127"))
  160. report "ERROR: Key 127 shouldn't exist in dictionary"
  161. severity failure;
  162. report "INFO: Test successful";
  163. -- Remove key/value pair from head of dictionary
  164. report "INFO: Test 10: Removing entry from beginning of dictionary";
  165. sv_dict.del("0", v_error);
  166. assert not(sv_dict.hasKey("0"))
  167. report "ERROR: Key 0 shouldn't exist in dictionary"
  168. severity failure;
  169. report "INFO: Test successful";
  170. -- Remove key/value pair from head of dictionary
  171. report "INFO: Test 11: Clear all entries from dictionary";
  172. sv_dict.clear(v_error);
  173. assert sv_dict.size = 0
  174. report "ERROR: Dict should be empty"
  175. severity failure;
  176. report "INFO: Test successful";
  177. report "INFO: t_dict test finished successfully";
  178. wait;
  179. end process DictTestP;
  180. end architecture sim;