summaryrefslogtreecommitdiff
path: root/netfpga10g/tests/pcie_rx_test.vhd
blob: 4180b81957ae52b28fdd88fc674efd53d9c71b5f (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322

LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
 
ENTITY pcie_rx_test IS
END pcie_rx_test;
 
ARCHITECTURE behavior OF pcie_rx_test IS 
 
    COMPONENT pcie_rx
    PORT(
         clk : IN  std_logic;
         frame : IN  std_logic_vector(63 downto 0);
         sof : IN  std_logic;
         eof : IN  std_logic;
         valid : IN  std_logic;
         read : OUT  std_logic;
         write : OUT  std_logic;
         complete : OUT  std_logic;
         data : OUT  std_logic_vector(63 downto 0);
         address : OUT  std_logic_vector(63 downto 3);
         tag : OUT  std_logic_vector(4 downto 0);
         remote : OUT  std_logic_vector(15 downto 0);
         bar0 : IN  std_logic
        );
    END COMPONENT;
    

   signal clk : std_logic := '0';
   
   signal frame : std_logic_vector(63 downto 0) := (others => '0');
   signal sof : std_logic := '0';
   signal eof : std_logic := '0';
   signal valid : std_logic := '0';
   
   signal read : std_logic;
   signal write : std_logic;
   signal complete : std_logic;
   signal data : std_logic_vector(63 downto 0);
   signal address : std_logic_vector(63 downto 3);
   signal tag : std_logic_vector(4 downto 0);
   signal remote : std_logic_vector(15 downto 0);
   signal bar0 : std_logic := '0';

   constant clk_period : time := 10 ns;
   
   constant ADDR_0 : std_logic_vector(63 downto 3) := std_logic_vector(to_unsigned(0, 61));
   constant ADDR_1 : std_logic_vector(63 downto 3) := std_logic_vector(to_unsigned(1, 61));
   constant ADDR_2 : std_logic_vector(63 downto 3) := std_logic_vector(to_unsigned(2, 61));
   
   constant TAG_0 : std_logic_vector(4 downto 0) := "0" & x"0";
   constant TAG_A : std_logic_vector(4 downto 0) := "0" & x"A";
   constant TAG_B : std_logic_vector(4 downto 0) := "0" & x"B";
   
   constant ID_0 : std_logic_vector(15 downto 0) := x"0000";
   constant ID_A : std_logic_vector(15 downto 0) := x"AAAA";
   constant ID_B : std_logic_vector(15 downto 0) := x"BBBB";
   
   constant DATA_0 : std_logic_vector(63 downto 0) := x"0000000000000000";
   constant DATA_A : std_logic_vector(63 downto 0) := x"AAAAAAAAAAAAAAAA";
   constant DATA_B : std_logic_vector(63 downto 0) := x"BBBBBBBBBBBBBBBB";
   
   signal test_fail : std_logic := '0';
 
BEGIN
 
	-- Instantiate the Unit Under Test (UUT)
   uut: pcie_rx PORT MAP (
          clk => clk,
          frame => frame,
          sof => sof,
          eof => eof,
          valid => valid,
          read => read,
          write => write,
          complete => complete,
          data => data,
          address => address,
          tag => tag,
          remote => remote,
          bar0 => bar0
        );

   -- Clock process definitions
   clk_process :process
   begin
		clk <= '0';
		wait for clk_period/2;
		clk <= '1';
		wait for clk_period/2;
   end process;
 

   -- Stimulus process
   stim_proc: process
   begin
        bar0 <= '1';
        
        wait for clk_period;
        
        -- expect nothing
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_0 then
                test_fail <= '1';
        end if;
        
        -- read: addr = 1, tag = A, remote = A
        frame <= "0" & "00" & "00000" &
                 x"00" &
                 "000000" & "0000000010" &
                 ID_A & "000" & TAG_A & x"FF";
         sof <= '1';
         eof <= '0';
         valid <= '1';
         
         wait for clk_period;
        
        -- remote = A
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= ADDR_1(31 downto 3) & "000" & x"00000000";
        sof <= '0';
        eof <= '1';
        valid <= '1';
        
        wait for clk_period;
        
        -- read: addr = 1, tag = A, remote = A
        if read /= '1' or
           write /= '0' or
           complete /= '0' or
           data /= DATA_0 or
           address /= ADDR_1 or
           tag /= TAG_A or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        -- write: data = A, addr = 2
        frame <= "0" & "10" & "00000" &
                 x"00" &
                 "000000" & "0000000010" &
                 ID_B & x"00" & x"FF";
        sof <= '1';
        eof <= '0';
        valid <= '1';
         
        wait for clk_period;
         
        -- remote stays A
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= ADDR_2(31 downto 3) & "000" & DATA_A(63 downto 32);
        sof <= '0';
        eof <= '0';
        valid <= '1';
        
        wait for clk_period;
         
        -- expect nothing
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= DATA_A(31 downto 0) & x"00000000";
        sof <= '0';
        eof <= '1';
        valid <= '1';
        
        wait for clk_period;
         
        -- write: data = A, addr = 2
        if read /= '0' or
           write /= '1' or
           complete /= '0' or
           data /= DATA_A or
           address /= ADDR_2 or
           tag /= TAG_0 or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= (others => '0');
        sof <= '0';
        eof <= '0';
        valid <= '0';
        
        wait for clk_period;
        
        -- expect nothing
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        -- complete: length = 2x32b, data = A + B, tag = B
        frame <= "0" & "10" & "01010" &
                 x"00" &
                 "000000" & "0000000100" &
                 ID_B & x"0004";
         sof <= '1';
         eof <= '0';
         valid <= '1';
         
         wait for clk_period;
        
        -- expect nothing
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= ID_B & "000" & TAG_B & x"00" &
                 DATA_A(63 downto 32);
        sof <= '0';
        eof <= '0';
        valid <= '1';
        
        wait for clk_period;
        
        -- nothing
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= DATA_A(31 downto 0) & DATA_B(63 downto 32);
        sof <= '0';
        eof <= '0';
        valid <= '1';
        
        wait for clk_period;
        
        -- completion: data = A, tag = B
        if read /= '0' or
           write /= '0' or
           complete /= '1' or
           data /= DATA_A or
           address /= ADDR_0 or
           tag /= TAG_B or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= (others => '0');
        sof <= '0';
        eof <= '0';
        valid <= '0';
        
        wait for clk_period;
        
        -- nothing
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= DATA_B(31 downto 0) & x"01234567";
        sof <= '0';
        eof <= '1';
        valid <= '1';
        
        wait for clk_period;
        
        -- completion: data = B, tag = B
        if read /= '0' or
           write /= '0' or
           complete /= '1' or
           data /= DATA_B or
           address /= ADDR_0 or
           tag /= TAG_B or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        frame <= (others => '0');
        sof <= '0';
        eof <= '0';
        valid <= '0';
        
        wait for clk_period;
        
        -- nothing
        if read /= '0' or
           write /= '0' or
           complete /= '0' or
           remote /= ID_A then
                test_fail <= '1';
        end if;
        
        
        
        
        
        wait;
   end process;

END;