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.

188 lines
6.1 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. begin
  21. DictInitP : process is
  22. begin
  23. sv_dict.init(false);
  24. wait;
  25. end process DictInitP;
  26. DictTestP : process is
  27. variable v_key : t_dict_key_ptr;
  28. variable v_random : RandomPType;
  29. variable v_input : std_logic_vector(7 downto 0);
  30. variable v_output : std_logic_vector(7 downto 0);
  31. variable v_scoreboard : t_scoreboard(0 to 256);
  32. variable v_error : t_dict_error;
  33. begin
  34. v_random.InitSeed(v_random'instance_name);
  35. -- check initial emptiness
  36. assert sv_dict.size = 0
  37. report "ERROR: Dict should be empty"
  38. severity failure;
  39. -- The dict shouldn_t accept an empty key string
  40. report "INFO: Test 0: Try to set an entry with empty key string";
  41. sv_dict.set("", x"0123456789", v_error);
  42. assert v_error = KEY_INVALID
  43. report "ERROR: Key '' should raise a KEY_INVALID error"
  44. severity failure;
  45. report "INFO: Test successful";
  46. -- fill dictionary and check count
  47. report "INFO: Test 1: Fill dictionary";
  48. for i in 0 to 255 loop
  49. v_input := v_random.RandSlv(8);
  50. sv_dict.set(integer'image(i), v_input, v_error);
  51. v_scoreboard(i) := v_input;
  52. assert sv_dict.size = i+1
  53. report "ERROR: Dict should have " & to_string(i+1) & " entries"
  54. severity failure;
  55. end loop;
  56. report "INFO: Test successful";
  57. -- read all entries and check for correct data
  58. report "INFO: Test 2: Read dictionary";
  59. for i in 0 to 255 loop
  60. sv_dict.get(integer'image(i), v_output, v_error);
  61. assert v_output = v_scoreboard(i)
  62. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  63. severity failure;
  64. end loop;
  65. report "INFO: Test successful";
  66. -- overwrite a key/value pair
  67. report "INFO: Test 3: Overwrite a entry";
  68. v_input := v_random.RandSlv(8);
  69. sv_dict.set("128", v_input, v_error);
  70. v_scoreboard(128) := v_input;
  71. sv_dict.get("128", v_output, v_error);
  72. assert v_output = v_scoreboard(128)
  73. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(128))
  74. severity failure;
  75. report "INFO: Test successful";
  76. -- check for existing keys
  77. report "INFO: Test 4: Check hasKey() method";
  78. for i in 0 to 255 loop
  79. assert sv_dict.hasKey(integer'image(i))
  80. report "ERROR: Key" & integer'image(i) & " should exist in dictionary"
  81. severity failure;
  82. end loop;
  83. assert not(sv_dict.hasKey("AFFE"))
  84. report "ERROR: Key AFFE shouldn't exist in dictionary"
  85. severity failure;
  86. report "INFO: Test successful";
  87. -- iterate up over all entries
  88. report "INFO: Test 5: Iterate up over all entries";
  89. sv_dict.setFirst;
  90. for i in 0 to 255 loop
  91. v_key := new string'(sv_dict.iter(UP));
  92. assert v_key.all = integer'image(i)
  93. report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i)
  94. severity failure;
  95. sv_dict.get(v_key.all, v_output, v_error);
  96. assert v_key.all = integer'image(i) and v_output = v_scoreboard(i)
  97. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  98. severity failure;
  99. end loop;
  100. v_key := new string'(sv_dict.iter(UP));
  101. assert v_key.all = ""
  102. report "ERROR: Got key " & v_key.all & ", expected empty key"
  103. severity failure;
  104. report "INFO: Test successful";
  105. -- iterate down over all entries
  106. report "INFO: Test 6: Iterate down over all entries";
  107. sv_dict.setLast;
  108. for i in 255 downto 0 loop
  109. v_key := new string'(sv_dict.iter(DOWN));
  110. assert v_key.all = integer'image(i)
  111. report "ERROR: Got key " & v_key.all & ", expected " & integer'image(i)
  112. severity failure;
  113. sv_dict.get(v_key.all, v_output, v_error);
  114. assert v_key.all = integer'image(i) and v_output = v_scoreboard(i)
  115. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  116. severity failure;
  117. end loop;
  118. v_key := new string'(sv_dict.iter(DOWN));
  119. assert v_key.all = ""
  120. report "ERROR: Got key " & v_key.all & ", expected empty key"
  121. severity failure;
  122. deallocate(v_key);
  123. report "INFO: Test successful";
  124. -- Remove key/value pair from head of dictionary
  125. report "INFO: Test 7: Removing entry from head of dictionary";
  126. sv_dict.del("255", v_error);
  127. assert not(sv_dict.hasKey("255"))
  128. report "ERROR: Key 255 shouldn't exist in dictionary"
  129. severity failure;
  130. report "INFO: Test successful";
  131. -- Remove key/value pair from head of dictionary
  132. report "INFO: Test 8: Removing entry from middle of dictionary";
  133. sv_dict.del("127", v_error);
  134. assert not(sv_dict.hasKey("127"))
  135. report "ERROR: Key 127 shouldn't exist in dictionary"
  136. severity failure;
  137. report "INFO: Test successful";
  138. -- Remove key/value pair from head of dictionary
  139. report "INFO: Test 9: Removing entry from beginning of dictionary";
  140. sv_dict.del("0", v_error);
  141. assert not(sv_dict.hasKey("0"))
  142. report "ERROR: Key 0 shouldn't exist in dictionary"
  143. severity failure;
  144. report "INFO: Test successful";
  145. -- Remove key/value pair from head of dictionary
  146. report "INFO: Test 10: Clear all entries from dictionary";
  147. sv_dict.clear(v_error);
  148. assert sv_dict.size = 0
  149. report "ERROR: Dict should be empty"
  150. severity failure;
  151. report "INFO: Test successful";
  152. report "INFO: t_dict test finished successfully";
  153. wait;
  154. end process DictTestP;
  155. end architecture sim;