PlTbUtils  1.3
PlTbUtils is a collection of functions, procedures and components for easily creating stimuli and checking response in automatic self-checking testbenches.
tb_example1.vhd
Go to the documentation of this file.
1 
35 
36 library ieee;
37 use ieee.std_logic_1164.all;
38 use ieee.numeric_std.all;
39 use work.txt_util.all;
40 use work.pltbutils_func_pkg.all;
41 use work.pltbutils_comp_pkg.all;
42 
45 entity tb_example1 is
46  generic (
47  G_WIDTH : integer := 8;
48  G_CLK_PERIOD : time := 10 ns;
49  G_DISABLE_BUGS : integer range 0 to 1 := 0
50  );
51 end entity tb_example1;
52 
53 architecture bhv of tb_example1 is
54 
57  signal pltbs : pltbs_t := C_PLTBS_INIT;
58 
59  -- DUT stimuli and response signals
60  signal clk : std_logic;
61  signal rst : std_logic;
62  signal carry_in : std_logic;
63  signal x : std_logic_vector(G_WIDTH-1 downto 0);
64  signal y : std_logic_vector(G_WIDTH-1 downto 0);
65  signal sum : std_logic_vector(G_WIDTH-1 downto 0);
66  signal carry_out : std_logic;
67 
68 begin
69 
70  dut0 : entity work.dut_example
71  generic map (
72  G_WIDTH => G_WIDTH,
74  )
75  port map (
76  clk_i => clk,
77  rst_i => rst,
78  carry_i => carry_in,
79  x_i => x,
80  y_i => y,
81  sum_o => sum,
83  );
84 
86  generic map(
88  )
89  port map(
90  clk_o => clk,
91  stop_sim_i => pltbs.stop_sim
92  );
93 
98  p_tc1 : process
99  variable pltbv : pltbv_t := C_PLTBV_INIT;
100  begin
101  startsim("tc1", "", pltbv, pltbs);
102  rst <= '1';
103  carry_in <= '0';
104  x <= (others => '0');
105  y <= (others => '0');
106 
107  starttest(1, "Reset test", pltbv, pltbs);
108  waitclks(2, clk, pltbv, pltbs);
109  check("Sum during reset", sum, 0, pltbv, pltbs);
110  check("Carry out during reset", carry_out, '0', pltbv, pltbs);
111  rst <= '0';
112  endtest(pltbv, pltbs);
113 
114  starttest(2, "Simple sum test", pltbv, pltbs);
115  carry_in <= '0';
116  x <= std_logic_vector(to_unsigned(1, x'length));
117  y <= std_logic_vector(to_unsigned(2, x'length));
118  waitclks(2, clk, pltbv, pltbs);
119  check("Sum", sum, 3, pltbv, pltbs);
120  check("Carry out", carry_out, '0', pltbv, pltbs);
121  endtest(pltbv, pltbs);
122 
123  starttest(3, "Simple carry in test", pltbv, pltbs);
124  print(G_DISABLE_BUGS=0, pltbv, pltbs, "Bug here somewhere");
125  carry_in <= '1';
126  x <= std_logic_vector(to_unsigned(1, x'length));
127  y <= std_logic_vector(to_unsigned(2, x'length));
128  waitclks(2, clk, pltbv, pltbs);
129  check("Sum", sum, 4, pltbv, pltbs);
130  check("Carry out", carry_out, '0', pltbv, pltbs);
131  print(G_DISABLE_BUGS=0, pltbv, pltbs, "");
132  endtest(pltbv, pltbs);
133 
134  starttest(4, "Simple carry out test", pltbv, pltbs);
135  carry_in <= '0';
136  x <= std_logic_vector(to_unsigned(2**G_WIDTH-1, x'length));
137  y <= std_logic_vector(to_unsigned(1, x'length));
138  waitclks(2, clk, pltbv, pltbs);
139  check("Sum", sum, 0, pltbv, pltbs);
140  check("Carry out", carry_out, '1', pltbv, pltbs);
141  endtest(pltbv, pltbs);
142 
143  endsim(pltbv, pltbs, true);
144  wait;
145  end process p_tc1;
146 
147 end architecture bhv;
in y_i std_logic_vector( G_WIDTH- 1 downto 0)
Definition: dut_example.vhd:53
G_WIDTH integer := 8
Definition: dut_example.vhd:45
G_DISABLE_BUGS integer range 0 to 1:= 1
Definition: dut_example.vhd:47
out carry_o std_logic
Definition: dut_example.vhd:56
in carry_i std_logic
Definition: dut_example.vhd:51
in x_i std_logic_vector( G_WIDTH- 1 downto 0)
Definition: dut_example.vhd:52
in rst_i std_logic
Definition: dut_example.vhd:50
out sum_o std_logic_vector( G_WIDTH- 1 downto 0)
Definition: dut_example.vhd:54
in clk_i std_logic
Definition: dut_example.vhd:49
Creates a clock for use in a testbench.
out clk_o std_logic
Clock output.
in stop_sim_i std_logic
Stops the clock when '1'.
G_PERIOD time := 10 ns
Clock period.
See pltbutils_comp.vhd for a description of the components.
This package defines fuctions and procedures for controlling stimuli to a DUT and checking response.
std_logic clk
Definition: tb_example1.vhd:60
pltbutils_clkgen clkgen0clkgen0
Definition: tb_example1.vhd:92
std_logic_vector( G_WIDTH- 1 downto 0) sum
Definition: tb_example1.vhd:65
std_logic carry_out
Definition: tb_example1.vhd:66
std_logic_vector( G_WIDTH- 1 downto 0) y
Definition: tb_example1.vhd:64
std_logic carry_in
Definition: tb_example1.vhd:62
pltbs_t := C_PLTBS_INIT pltbs
Definition: tb_example1.vhd:57
std_logic rst
Definition: tb_example1.vhd:61
std_logic_vector( G_WIDTH- 1 downto 0) x
Definition: tb_example1.vhd:63
This is an example which demonstrates how PlTbUtils can be used.
Definition: tb_example1.vhd:45
G_WIDTH integer := 8
Definition: tb_example1.vhd:47
G_CLK_PERIOD time := 10 ns
Definition: tb_example1.vhd:48
G_DISABLE_BUGS integer range 0 to 1:= 0
Definition: tb_example1.vhd:50
Defines useful functions an procedures for text handling text in VHDL.
Definition: txt_util.vhd:31