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.

141 lines
4.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 : string(1 to 4);
  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 : boolean;
  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. -- fill dictionary and check count
  40. report "INFO: Test 0: Fill dictionary";
  41. for i in 0 to 255 loop
  42. v_input := v_random.RandSlv(8);
  43. sv_dict.set(integer'image(i), v_input);
  44. v_scoreboard(i) := v_input;
  45. assert sv_dict.size = i+1
  46. report "ERROR: Dict should have " & to_string(i+1) & " entries"
  47. severity failure;
  48. end loop;
  49. report "INFO: Test successful";
  50. -- read all entries and check for correct data
  51. report "INFO: Test 1: Read dictionary";
  52. for i in 0 to 255 loop
  53. sv_dict.get(integer'image(i), v_output, v_error);
  54. assert v_output = v_scoreboard(i)
  55. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(i))
  56. severity failure;
  57. end loop;
  58. report "INFO: Test successful";
  59. -- overwrite a key/value pair
  60. report "INFO: Test 2: Overwrite a entry";
  61. v_input := v_random.RandSlv(8);
  62. sv_dict.set("128", v_input);
  63. v_scoreboard(128) := v_input;
  64. sv_dict.get("128", v_output, v_error);
  65. assert v_output = v_scoreboard(128)
  66. report "ERROR: Got 0x" & to_hstring(v_output) & ", expected 0x" & to_hstring(v_scoreboard(128))
  67. severity failure;
  68. report "INFO: Test successful";
  69. -- overwrite a key/value pair
  70. report "INFO: Test 3: Check hasKey() method";
  71. for i in 0 to 255 loop
  72. assert sv_dict.hasKey(integer'image(i))
  73. report "ERROR: Key" & integer'image(i) & " should exist in dictionary"
  74. severity failure;
  75. end loop;
  76. assert not(sv_dict.hasKey("AFFE"))
  77. report "ERROR: Key AFFE shouldn't exist in dictionary"
  78. severity failure;
  79. report "INFO: Test successful";
  80. -- Remove key/value pair from head of dictionary
  81. report "INFO: Test 4: Removing entry from head of dictionary";
  82. sv_dict.del("255", v_error);
  83. assert not(sv_dict.hasKey("255"))
  84. report "ERROR: Key 255 shouldn't exist in dictionary"
  85. severity failure;
  86. report "INFO: Test successful";
  87. -- Remove key/value pair from head of dictionary
  88. report "INFO: Test 5: Removing entry from middle of dictionary";
  89. sv_dict.del("127", v_error);
  90. assert not(sv_dict.hasKey("127"))
  91. report "ERROR: Key 127 shouldn't exist in dictionary"
  92. severity failure;
  93. report "INFO: Test successful";
  94. -- Remove key/value pair from head of dictionary
  95. report "INFO: Test 6: Removing entry from beginning of dictionary";
  96. sv_dict.del("0", v_error);
  97. assert not(sv_dict.hasKey("0"))
  98. report "ERROR: Key 0 shouldn't exist in dictionary"
  99. severity failure;
  100. report "INFO: Test successful";
  101. -- Remove key/value pair from head of dictionary
  102. report "INFO: Test 7: Clear all entries from dictionary";
  103. sv_dict.clear(v_error);
  104. assert sv_dict.size = 0
  105. report "ERROR: Dict should be empty"
  106. severity failure;
  107. report "INFO: Test successful";
  108. report "INFO: t_dict test finished successfully";
  109. wait;
  110. end process DictTestP;
  111. end architecture sim;