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.

89 lines
2.4 KiB

  1. -- Copyright (c) 2014 - 2022 by Torsten Meissner
  2. --
  3. -- Licensed under the Apache License, Version 2.0 (the "License");
  4. -- you may not use this file except in compliance with the License.
  5. -- You may obtain a copy of the License at
  6. --
  7. -- https://www.apache.org/licenses/LICENSE-2.0
  8. --
  9. -- Unless required by applicable law or agreed to in writing, software
  10. -- distributed under the License is distributed on an "AS IS" BASIS,
  11. -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. -- See the License for the specific language governing permissions and
  13. -- limitations under the License.
  14. library ieee;
  15. use ieee.std_logic_1164.all;
  16. use ieee.numeric_std.all;
  17. library osvvm;
  18. use osvvm.RandomPkg.all;
  19. library libvhdl;
  20. use libvhdl.AssertP.all;
  21. entity StackT is
  22. end entity StackT;
  23. architecture sim of StackT is
  24. constant C_STACK_DEPTH : natural := 64;
  25. package SlvStack is new libvhdl.StackP
  26. generic map (
  27. STACK_TYPE => std_logic_vector(63 downto 0),
  28. MAX_LEN => C_STACK_DEPTH,
  29. to_string => to_hstring
  30. );
  31. shared variable sv_stack : SlvStack.t_stack;
  32. begin
  33. StackInitP : process is
  34. begin
  35. sv_stack.init(false);
  36. wait;
  37. end process StackInitP;
  38. StackTestP : process is
  39. variable v_data : std_logic_vector(63 downto 0);
  40. variable v_random : RandomPType;
  41. type t_scoreboard is array (natural range <>) of std_logic_vector(63 downto 0);
  42. variable v_scoreboard : t_scoreboard(0 to C_STACK_DEPTH-1);
  43. begin
  44. -- Check initial emptiness
  45. assert_true(sv_stack.is_empty, "Stack should be empty!");
  46. -- Fill stack
  47. v_random.InitSeed(v_random'instance_name);
  48. for i in 0 to C_STACK_DEPTH-1 loop
  49. v_data := v_random.RandSlv(64);
  50. v_scoreboard(i) := v_data;
  51. sv_stack.push(v_data);
  52. end loop;
  53. -- Check that it's full
  54. assert_true(sv_stack.is_full, "Stack should be full!");
  55. -- Check number of entries
  56. assert_equal(sv_stack.fillstate, C_STACK_DEPTH, "Stack should have" & integer'image(C_STACK_DEPTH) & "entries");
  57. -- Empty the stack
  58. for i in C_STACK_DEPTH-1 downto 0 loop
  59. sv_stack.pop(v_data);
  60. assert_equal(v_data, v_scoreboard(i));
  61. end loop;
  62. -- Check emptiness
  63. assert_true(sv_stack.is_empty, "Stack should be empty!");
  64. report "INFO: t_stack test finished successfully";
  65. wait;
  66. end process StackTestP;
  67. end architecture sim;