summaryrefslogtreecommitdiff
path: root/testsuite/gna/bug01/tb.vhdl
blob: 34be7ef3484fd0236b792fe5c5b18fff90cba1b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

ENTITY TestBenchAutomated IS
-- Generics passed in
generic (m: integer := 3; n: integer := 5; h: integer := 4; DATA_SIZE: integer :=5);
END TestBenchAutomated;

ARCHITECTURE behavior OF TestBenchAutomated IS 

     -- Component Declaration for the Unit Under Test (UUT)
     COMPONENT TopLevelM_M
     generic (m: integer := 3; n: integer := 5; h: integer := 4; DATA_SIZE: integer :=5);
     PORT(
            clk : IN  std_logic;
            next_in : IN  std_logic; --User input
            rst_in : IN  std_logic;  --User input
            OUTPUT : OUT  SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0) --Calculated DATA output
          );
     END COMPONENT;


    --Inputs
    signal clk : std_logic := '0';
    signal next_in : std_logic := '0';
    signal rst_in : std_logic := '0';

    --Outputs
    signal OUTPUT : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0);

    -- Clock period definitions
    constant clk_period : time := 10 ns;

    --Variable to be used in assert section
     type Vector is record
            OUTPUT_test : SIGNED((DATA_SIZE+DATA_SIZE)+(m-1)-1 downto 0);
     end record;

type VectorArray is array (natural range <>) of Vector;

constant Vectors : VectorArray := (
     -- Values to be compaired to calculated output
    (OUTPUT_test =>"000000110000"), -- 48
    (OUTPUT_test =>"000011110110"), -- 246
    (OUTPUT_test =>"000101001000"), -- 382 <--- Purposefully incorrect value, Should be '000100001000' = 264
    (OUTPUT_test =>"111111010011"), -- -45
    (OUTPUT_test =>"111101001100"), -- -180
    (OUTPUT_test =>"111111001111"), -- -49
    (OUTPUT_test =>"000000101011"), -- 43  Purposefully incorrect value, Should be '000010101011' = 171
    (OUTPUT_test =>"000000010011"), -- 19
    (OUTPUT_test =>"111111100101"), -- -27
    (OUTPUT_test =>"111110111011"), -- -69
    (OUTPUT_test =>"111110111011"), -- -69
    (OUTPUT_test =>"000000101101"), -- 45
    (OUTPUT_test =>"111011011110"), -- -290
    (OUTPUT_test =>"000001010110"), -- 86
    (OUTPUT_test =>"000011110010"), -- 242
    (OUTPUT_test =>"000000111110"),  -- 125
    (OUTPUT_test =>"111111001001"), -- -55
    (OUTPUT_test =>"000100010101"), -- 277
    (OUTPUT_test =>"111111100011"), -- -29
    (OUTPUT_test =>"111101111101"));-- -131 



BEGIN

    -- Instantiate the Unit Under Test (UUT)
    uut: TopLevelM_M PORT MAP (
             clk => clk,
             next_in => next_in,
             rst_in => rst_in,
             OUTPUT => OUTPUT
          );

    -- Clock process definitions
  clk_process :process
        begin
            clk <= '0';
            wait for clk_period/2;
            clk <= '1';
            wait for clk_period/2;
        end process;
    -- Process to simulate user input and to check output is correct
Test :process
    variable  i : integer;
        begin
            wait for 100 ns;
            rst_in <= '1';
            wait for clk_period*3;
            rst_in <= '0';

    --Loops through enough times to cover matrix and more to show it freezes in S_Wait state
    for i in 0 to 50 loop 

            for i in Vectors'range loop

                next_in <= '1';
                wait for clk_period*5;
                next_in <= '0';
                wait for clk_period*4; --Appropriate amount of clock cycles needed for calculations to be displayed at output
                --Check the output is the same as expected
                assert OUTPUT = Vectors(i).OUTPUT_test
                report "Incorrect Output on vector line" & integer'image(i) &
                lf & "Expected:" & integer'image(i)(to_integer((Vectors(i).OUTPUT_test))) --& lf &
                --"But got" & integer'image(i)(to_integer(signed(OUTPUT)))
                severity error;

            end loop;
        end loop;

        wait;

    end process;
END;