1 ----------------------------------------------------------------------------------
3 -- Uni : University of York
4 -- Course : Electronic Engineering
5 -- Module : Computer Architectures
6 -- Engineers : Y3839090 & Y3840426
8 -- Create Date : 23:08:04 02/23/2017
9 -- Design Name : Param_Registers_TB - TestBench
10 -- Description : A 16 bit 8 register dual read single write register array.
12 ----------------------------------------------------------------------------------
14 USE ieee.std_logic_1164.
ALL;
17 ENTITY Param_Registers_TB
IS
18 END Param_Registers_TB
;
20 ARCHITECTURE behavior
OF Param_Registers_TB
IS
24 constant num_reg
: natural
:= 8;
25 constant data_size
: natural
:= 16;
27 -- Component Declaration for the Unit Under Test (UUT)
28 COMPONENT Pram_Registers
34 addr_A
: IN std_logic_vector(log2
(num_reg
)-1 downto 0);
35 addr_B
: IN std_logic_vector(log2
(num_reg
)-1 downto 0);
36 addr_C
: IN std_logic_vector(log2
(num_reg
)-1 downto 0); -- Address to write to
37 data_in
: IN std_logic_vector(data_size
-1 downto 0); -- Data to write
40 A_out
: OUT std_logic_vector(data_size
-1 downto 0);
41 B_out
: OUT std_logic_vector(data_size
-1 downto 0)
47 signal addr_A
: std_logic_vector(log2
(num_reg
)-1 downto 0) := (others => '0');
48 signal addr_B
: std_logic_vector(log2
(num_reg
)-1 downto 0) := (others => '0');
49 signal addr_C
: std_logic_vector(log2
(num_reg
)-1 downto 0) := (others => '0');
50 signal data_in
: std_logic_vector(data_size
-1 downto 0) := (others => '0');
51 signal wr_en
: std_logic := '0';
52 signal clk
: std_logic := '0';
55 signal A_out
: std_logic_vector(data_size
-1 downto 0);
56 signal B_out
: std_logic_vector(data_size
-1 downto 0);
58 -- Clock period definitions
59 constant clk_period
: time := 10 ns
;
61 type TEST_VECTOR
is RECORD
62 wr_en
: std_logic; -- Write enable
63 addr_A
: std_logic_vector(log2
(num_reg
)-1 downto 0); -- A address to read from
64 addr_B
: std_logic_vector(log2
(num_reg
)-1 downto 0); -- B address to read from
65 addr_C
: std_logic_vector(log2
(num_reg
)-1 downto 0); -- C address to write to
66 data_in
: std_logic_vector(data_size
-1 downto 0); -- Data to write at addr_C
67 A_out
: std_logic_vector(data_size
-1 downto 0); -- Expected data to be read from addr_A
68 B_out
: std_logic_vector(data_size
-1 downto 0); -- Expected data to be read from addr_B
71 type TEST_VECTOR_ARRAY
is ARRAY(NATURAL
range <>) of TEST_VECTOR
;
73 constant test_vectors
: TEST_VECTOR_ARRAY
:=
75 -- wr_en, addr_A, addr_B, addr_C, data_in, A_out, B_out
76 ('0', "000", "000", "000", X"0000", X"0000", X"0000"),
77 ('1', "
000"
, "
000"
, "
001"
, X"FFFF"
, X"
0000"
, X"
0000"
),
78 ('1', "000", "000", "010", X"1111", X"0000", X"0000"),
79 ('0', "
001"
, "
010"
, "
000"
, X"
0000"
, X"FFFF"
, X"
1111"
),
80 ('1', "000", "000", "111", X"0011", X"0000", X"0000"),
81 ('1', "
111"
, "
111"
, "
110"
, X"
8800"
, X"
0011"
, X"
0011"
),
82 ('1', "111", "110", "000", X"AAAA", X"0011", X"8800"),
83 ('0', "
000"
, "
000"
, "
000"
, X"
0000"
, X"
0000"
, X"
0000"
),
85 ('1', "000", "001", "010", X"1111", X"0000", X"FFFF"),
86 ('1', "
001"
, "
010"
, "
011"
, X"
2222"
, X"FFFF"
, X"
1111"
),
87 ('1', "010", "011", "100", X"3333", X"1111", X"2222"),
88 ('1', "
011"
, "
100"
, "
101"
, X"
4444"
, X"
2222"
, X"
3333"
),
89 ('1', "100", "101", "110", X"5555", X"3333", X"4444"),
90 ('1', "
101"
, "
110"
, "
111"
, X"
6666"
, X"
4444"
, X"
5555"
),
91 ('0', "110", "111", "000", X"0000", X"5555", X"6666")
98 -- Instantiate the Unit Under Test (UUT)
102 data_size => data_size
115 -- Clock process definitions
119 wait for clk_period/2;
121 wait for clk_period/2;
129 -- hold reset state for 100 ns.
132 -- Loop over all of our test data sets
133 for i in test_vectors'range loop
135 -- assign test inputs
136 wr_en <= test_vectors(i).wr_en;
137 addr_A <= test_vectors(i).addr_A;
138 addr_B <= test_vectors(i).addr_B;
139 addr_C <= test_vectors(i).addr_C;
140 data_in <= test_vectors(i).data_in;
143 -- wait for a clock cycle
147 -- check that output A is the same as the expected
148 assert A_out = test_vectors(i).A_out
149 report " [ERR!] Test " & integer'image(i) & " : A output is not what was expected!"
152 -- check that output A is the same as the expected
153 assert B_out = test_vectors(i).B_out
154 report " [ERR!] Test " & integer'image(i) & " : B output is not what was expected!"
157 -- check that output A is the same as the expected
158 assert (B_out /= test_vectors(i).B_out or A_out /= test_vectors(i).A_out)
159 report " [ OK ] Test " & integer'image(i) & " passed!"