OpenCores
URL https://opencores.org/ocsvn/rio/rio/trunk

Subversion Repositories rio

[/] [rio/] [branches/] [2.0.0-development/] [bench/] [vhdl/] [TestRioLogicalCommon.vhd] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 36 magro732
-------------------------------------------------------------------------------
2
-- 
3
-- RapidIO IP Library Core
4
-- 
5
-- This file is part of the RapidIO IP library project
6
-- http://www.opencores.org/cores/rio/
7
-- 
8
-- Description
9
-- Contains automatic test code to verify a RioLogicalCommon implementation.
10
-- 
11
-- To Do:
12
-- -
13
-- 
14
-- Author(s): 
15
-- - Magnus Rosenius, magro732@opencores.org 
16
-- 
17
-------------------------------------------------------------------------------
18
-- 
19
-- Copyright (C) 2013 Authors and OPENCORES.ORG 
20
-- 
21
-- This source file may be used and distributed without 
22
-- restriction provided that this copyright statement is not 
23
-- removed from the file and that any derivative work contains 
24
-- the original copyright notice and the associated disclaimer. 
25
-- 
26
-- This source file is free software; you can redistribute it 
27
-- and/or modify it under the terms of the GNU Lesser General 
28
-- Public License as published by the Free Software Foundation; 
29
-- either version 2.1 of the License, or (at your option) any 
30
-- later version. 
31
-- 
32
-- This source is distributed in the hope that it will be 
33
-- useful, but WITHOUT ANY WARRANTY; without even the implied 
34
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
35
-- PURPOSE. See the GNU Lesser General Public License for more 
36
-- details. 
37
-- 
38
-- You should have received a copy of the GNU Lesser General 
39
-- Public License along with this source; if not, download it 
40
-- from http://www.opencores.org/lgpl.shtml 
41
-- 
42
-------------------------------------------------------------------------------
43
 
44
 
45
-------------------------------------------------------------------------------
46
-- TestRioLogicalCommon.
47
-------------------------------------------------------------------------------
48
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.numeric_std.all;
51
use ieee.math_real.all;
52
library std;
53
use std.textio.all;
54
use work.rio_common.all;
55 48 magro732
use work.TestPortPackage.all;
56 36 magro732
 
57
 
58
-------------------------------------------------------------------------------
59
-- Entity for TestRioLogicalCommon.
60
-------------------------------------------------------------------------------
61
entity TestRioLogicalCommon is
62
end entity;
63
 
64
 
65
-------------------------------------------------------------------------------
66
-- Architecture for TestRioLogicalCommon.
67
-------------------------------------------------------------------------------
68
architecture TestRioLogicalCommonImpl of TestRioLogicalCommon is
69
 
70 48 magro732
  signal outboundMessageEmpty : std_logic;
71
  signal outboundMessageWrite : std_logic;
72
  signal outboundMessageMessage : TestPortMessagePacketBuffer;
73
  signal outboundMessageAck : std_logic;
74
 
75
  signal inboundMessageEmpty : std_logic;
76
  signal inboundMessageWrite : std_logic;
77
  signal inboundMessageMessage : TestPortMessagePacketBuffer;
78
  signal inboundMessageAck : std_logic;
79
 
80 36 magro732
  signal clk : std_logic;
81
  signal areset_n : std_logic;
82
  signal enable : std_logic;
83
 
84
  signal writeFrameFull : std_logic;
85
  signal writeFrame : std_logic;
86
  signal writeFrameAbort : std_logic;
87
  signal writeContent : std_logic;
88
  signal writeContentData : std_logic_vector(31 downto 0);
89
 
90
  signal readFrameEmpty : std_logic;
91
  signal readFrame : std_logic;
92
  signal readFrameRestart : std_logic;
93
  signal readFrameAborted : std_logic;
94
  signal readContentEmpty : std_logic;
95
  signal readContent : std_logic;
96
  signal readContentEnd : std_logic;
97
  signal readContentData : std_logic_vector(31 downto 0);
98
 
99 48 magro732
  signal inboundStb : std_logic;
100
  signal inboundAdr : std_logic_vector(3 downto 0);
101
  signal inboundDat : std_logic_vector(31 downto 0);
102
  signal inboundStall : std_logic;
103
 
104
  signal outboundStb : std_logic_vector(0 downto 0);
105
  signal outboundAdr : std_logic_vector(0 downto 0);
106
  signal outboundDat : std_logic_vector(31 downto 0);
107
  signal outboundStall : std_logic_vector(0 downto 0);
108 36 magro732
 
109
begin
110
 
111
  -----------------------------------------------------------------------------
112
  -- Clock generation.
113
  -----------------------------------------------------------------------------
114
  ClockGenerator: process
115
  begin
116
    clk <= '0';
117
    wait for 20 ns;
118
    clk <= '1';
119
    wait for 20 ns;
120
  end process;
121
 
122
 
123
  -----------------------------------------------------------------------------
124
  -- Serial port emulator.
125
  -----------------------------------------------------------------------------
126
  TestDriver: process
127
 
128 48 magro732
    -----------------------------------------------------------------------------
129
    -- Procedures to handle outbound and inbound packets.
130
    -----------------------------------------------------------------------------
131
    procedure OutboundFrame(constant frame : in RioFrame;
132
                            constant abort : in boolean := false) is
133
    begin
134
      TestPortPacketBufferWrite(outboundMessageWrite, outboundMessageMessage, outboundMessageAck,
135
                                frame, abort);
136
    end procedure;
137
    procedure InboundFrame(constant frame : in RioFrame;
138
                           constant abort : in boolean := false) is
139
    begin
140
      TestPortPacketBufferWrite(inboundMessageWrite, inboundMessageMessage, inboundMessageAck,
141
                                frame, abort);
142
    end procedure;
143
 
144 36 magro732
    ---------------------------------------------------------------------------
145
    -- 
146
    ---------------------------------------------------------------------------
147 48 magro732
    procedure InboundPayload(constant header : in std_logic_vector(15 downto 0);
148
                             constant dstId : in std_logic_vector(15 downto 0);
149
                             constant srcId : in std_logic_vector(15 downto 0);
150
                             constant payload : in RioPayload) is
151
      variable adr : std_logic_vector(3 downto 0);
152 36 magro732
    begin
153 48 magro732
      wait until clk = '1';
154
      while (inboundStb = '0') loop
155
        wait until clk = '1';
156
      end loop;
157
      adr := inboundAdr;
158
      TestCompare(inboundStb, '1', "stb header");
159
      TestCompare(inboundAdr, header(3 downto 0), "adr");
160
      TestCompare(inboundDat, x"0000" & header, "header");
161
 
162
      wait until clk = '1';
163
      TestCompare(inboundStb, '1', "stb dstId");
164
      TestCompare(inboundAdr, adr, "adr dstId");
165
      TestCompare(inboundDat, x"0000" & dstId, "dstId");
166
      wait until clk = '1';
167
      TestCompare(inboundStb, '1', "stb srcId");
168
      TestCompare(inboundAdr, adr, "adr srcId");
169
      TestCompare(inboundDat, x"0000" & srcId, "srcId");
170
 
171
      for i in 0 to (payload.length/2)-1 loop
172
        wait until clk = '1';
173
        TestCompare(inboundStb, '1', "stb payload");
174
        TestCompare(inboundAdr, adr, "adr payload");
175
        TestCompare(inboundDat, payload.data(2*i) & payload.data(2*i+1), "payload");
176
      end loop;
177
 
178
      if ((payload.length mod 2) = 1) then
179
        -- Check the last half-word of payload that has CRC appended to it.
180
        wait until clk = '1';
181
        TestCompare(inboundStb, '1', "stb payload");
182
        TestCompare(inboundAdr, adr, "adr payload");
183
        TestCompare(inboundDat(31 downto 16), payload.data(payload.length-1), "payload");
184
      else
185
        if (payload.length >= 38) then
186
          -- Ignore the last word since it contains only CRC and padding.
187
          wait until clk = '1';
188
          TestCompare(inboundStb, '1', "stb crc+pad");
189
          TestCompare(inboundAdr, adr, "adr crc+pad");
190
          TestCompare(inboundDat(15 downto 0), x"0000", "crc+pad");
191
        end if;
192
      end if;
193
 
194
      wait until clk = '1';
195
      TestCompare(inboundStb, '0', "stb end");
196 36 magro732
    end procedure;
197
 
198
    ---------------------------------------------------------------------------
199
    -- 
200
    ---------------------------------------------------------------------------
201 48 magro732
    procedure OutboundPayload(constant header : in std_logic_vector(15 downto 0);
202
                              constant dstId : in std_logic_vector(15 downto 0);
203
                              constant srcId : in std_logic_vector(15 downto 0);
204
                              constant payload : in RioPayload) is
205 36 magro732
    begin
206 48 magro732
      if ((payload.length mod 2) = 1) then
207
        outboundAdr(0) <= '1';
208
      else
209
        outboundAdr(0) <= '0';
210
      end if;
211
 
212
      outboundStb(0) <= '1';
213
      outboundDat <= "UUUUUUUUUUUUUUUU" & header;
214
      wait until clk = '1';
215
      while (outboundStall(0) = '1') loop
216
        wait until clk = '1';
217
      end loop;
218
 
219
      outboundDat <= "UUUUUUUUUUUUUUUU" & dstId;
220
      wait until clk = '1';
221
      while (outboundStall(0) = '1') loop
222
        wait until clk = '1';
223
      end loop;
224
 
225
      outboundDat <= "UUUUUUUUUUUUUUUU" & srcId;
226
      wait until clk = '1';
227
      while (outboundStall(0) = '1') loop
228
        wait until clk = '1';
229
      end loop;
230
 
231
      for i in 0 to (payload.length/2)-1 loop
232
        outboundDat <= payload.data(2*i) & payload.data(2*i+1);
233
        wait until clk = '1';
234
        while (outboundStall(0) = '1') loop
235
          wait until clk = '1';
236
        end loop;
237
      end loop;
238
 
239
      if ((payload.length mod 2) = 1) then
240
        outboundDat <= payload.data(payload.length-1) & "UUUUUUUUUUUUUUUU";
241
        wait until clk = '1';
242
        while (outboundStall(0) = '1') loop
243
          wait until clk = '1';
244
        end loop;
245
      end if;
246
 
247
      outboundStb(0) <= '0';
248
      outboundAdr(0) <= 'U';
249
      outboundDat <= (others=>'U');
250
      wait until clk = '1';
251 36 magro732
    end procedure;
252
 
253 48 magro732
    ---------------------------------------------------------------------------
254
    -- 
255
    ---------------------------------------------------------------------------
256 36 magro732
    variable seed1 : positive := 1;
257
    variable seed2: positive := 1;
258
 
259
    variable frame : RioFrame;
260 48 magro732
    variable payload : RioPayload;
261 36 magro732
 
262
  begin
263
    areset_n <= '0';
264
    enable <= '1';
265
 
266 48 magro732
    writeFrameFull <= '0';
267
    inboundStall <= '0';
268
    outboundStb(0) <= '0';
269
 
270 36 magro732
    wait until clk'event and clk = '1';
271
    wait until clk'event and clk = '1';
272
    areset_n <= '1';
273
    wait until clk'event and clk = '1';
274
    wait until clk'event and clk = '1';
275
 
276
    ---------------------------------------------------------------------------
277 51 magro732
    TestSpec("-----------------------------------------------------------------");
278
    TestSpec("TG_RioLogicalCommon");
279
    TestSpec("-----------------------------------------------------------------");
280
    TestSpec("TG_RioLogicalCommon-TC1");
281
    TestSpec("Description: Test all sizes of packets in the inbound direction.");
282
    TestSpec("Requirement: ");
283
    TestSpec("-----------------------------------------------------------------");
284
    TestSpec("Step 1:");
285
    TestSpec("Action: Add inbound packets in all allowed sized.");
286
    TestSpec("Result: The payload of the inbound packets should be received on ");
287
    TestSpec("        the other side without CRC.");
288
    TestSpec("-----------------------------------------------------------------");
289 36 magro732
    ---------------------------------------------------------------------------
290 51 magro732
    TestCaseStart("TG_RioLogicalCommon-TC1-Step1");
291 36 magro732
    ---------------------------------------------------------------------------
292 48 magro732
    -- REMARK: Use random data...
293
    for j in 1 to 133 loop
294
      payload.length := j;
295
      for i in 0 to payload.length-1 loop
296
        payload.data(i) := std_logic_vector(to_unsigned(i, 16));
297
      end loop;
298
      frame := RioFrameCreate(ackId=>"00000", vc=>'0', crf=>'0', prio=>"00",
299
                              tt=>"01", ftype=>FTYPE_WRITE_CLASS,
300
                              destId=>x"beef", sourceId=>x"dead",
301
                              payload=>payload);
302
      InboundFrame(frame);
303
    end loop;
304 36 magro732
 
305 48 magro732
    for j in 1 to 133 loop
306
      payload.length := j;
307
      InboundPayload(x"0015", x"beef", x"dead", payload);
308
    end loop;
309 36 magro732
 
310 48 magro732
    TestWait(inboundMessageEmpty, '1', "inboundMessage empty");
311 38 magro732
 
312 36 magro732
    ---------------------------------------------------------------------------
313 51 magro732
    --TestSpec("-----------------------------------------------------------------");
314
    --TestSpec("Step 2:");
315
    --TestSpec("Action: Send an inbound frame that are too long.");
316
    --TestSpec("Result: The tail of the packet should be discarded.");
317
    --TestSpec("-----------------------------------------------------------------");
318 38 magro732
    ---------------------------------------------------------------------------
319 51 magro732
    --TestCaseStart("TG_RioLogicalCommon-TC1-Step2");
320 38 magro732
    ---------------------------------------------------------------------------
321
 
322
    ---------------------------------------------------------------------------
323 51 magro732
    TestSpec("-----------------------------------------------------------------");
324
    TestSpec("TG_RioLogicalCommon-TC2");
325
    TestSpec("Description: Test all sizes of packets in the outbound direction.");
326
    TestSpec("Requirement: ");
327
    TestSpec("-----------------------------------------------------------------");
328
    TestSpec("Step 1:");
329
    TestSpec("Action: Add outbound packets in all allowed sized.");
330
    TestSpec("Result: The payload of the outbound packets should be received on ");
331
    TestSpec("        the other side with CRC added.");
332
    TestSpec("-----------------------------------------------------------------");
333 38 magro732
    ---------------------------------------------------------------------------
334 51 magro732
    TestCaseStart("TG_RioLogicalCommon-TC2-Step1");
335 38 magro732
    ---------------------------------------------------------------------------
336
 
337 48 magro732
    for j in 1 to 133 loop
338
      payload.length := j;
339
      for i in 0 to payload.length-1 loop
340
        payload.data(i) := std_logic_vector(to_unsigned(i, 16));
341
      end loop;
342
      frame := RioFrameCreate(ackId=>"00000", vc=>'0', crf=>'0', prio=>"00",
343
                              tt=>"01", ftype=>FTYPE_WRITE_CLASS,
344
                              destId=>x"beef", sourceId=>x"dead",
345
                              payload=>payload);
346
      OutboundFrame(frame);
347
    end loop;
348 38 magro732
 
349 48 magro732
    for j in 1 to 133 loop
350
      payload.length := j;
351
      OutboundPayload(x"0015", x"beef", x"dead", payload);
352
    end loop;
353 38 magro732
 
354 48 magro732
    TestWait(outboundMessageEmpty, '1', "outboundMessage empty");
355 38 magro732
 
356 48 magro732
    -----------------------------------------------------------------------------
357 51 magro732
    --TestSpec("-----------------------------------------------------------------");
358
    --TestSpec("Step 2:");
359
    --TestSpec("Action: Send an outbound frame that are too long.");
360
    --TestSpec("Result: The tail of the packet should be discarded.");
361
    --TestSpec("-----------------------------------------------------------------");
362 48 magro732
    -----------------------------------------------------------------------------
363 51 magro732
    --TestCaseStart("TG_RioLogicalCommon-TC1-Step2");
364 48 magro732
    -----------------------------------------------------------------------------
365 38 magro732
 
366
    ---------------------------------------------------------------------------
367 36 magro732
    -- Test completed.
368
    ---------------------------------------------------------------------------
369
 
370
    TestEnd;
371
  end process;
372
 
373
  -----------------------------------------------------------------------------
374 48 magro732
  -- Instantiate the test port.
375 36 magro732
  -----------------------------------------------------------------------------
376 38 magro732
 
377 48 magro732
  TestPortPacketBufferInst: TestPortPacketBuffer
378
    generic map(READ_CONTENT_END_DATA_VALID=>false)
379 36 magro732
    port map(
380
      clk=>clk, areset_n=>areset_n,
381 48 magro732
      readEmpty_o=>inboundMessageEmpty,
382
      readWrite_i=>inboundMessageWrite,
383
      readMessage_i=>inboundMessageMessage,
384
      readAck_o=>inboundMessageAck,
385
      writeEmpty_o=>outboundMessageEmpty,
386
      writeWrite_i=>outboundMessageWrite,
387
      writeMessage_i=>outboundMessageMessage,
388
      writeAck_o=>outboundMessageAck,
389 36 magro732
      readFrameEmpty_o=>readFrameEmpty,
390
      readFrame_i=>readFrame,
391 48 magro732
      readFrameRestart_i=>'0',
392
      readFrameAborted_o=>readFrameAborted,
393
      readWindowEmpty_o=>open,
394
      readWindowReset_i=>'0',
395
      readWindowNext_i=>readFrame,
396 36 magro732
      readContentEmpty_o=>readContentEmpty,
397
      readContent_i=>readContent,
398
      readContentEnd_o=>readContentEnd,
399
      readContentData_o=>readContentData,
400
      writeFrame_i=>writeFrame,
401
      writeFrameAbort_i=>writeFrameAbort,
402
      writeContent_i=>writeContent,
403
      writeContentData_i=>writeContentData);
404 48 magro732
 
405 36 magro732
  -----------------------------------------------------------------------------
406 48 magro732
  -- Instantiate the test object.
407 36 magro732
  -----------------------------------------------------------------------------
408
 
409
  TestObject: RioLogicalCommon
410 48 magro732
    generic map(PORTS=>1)
411 36 magro732
    port map(
412 48 magro732
      clk=>clk,
413
      areset_n=>areset_n,
414
      enable=>enable,
415
      readFrameEmpty_i=>readFrameEmpty,
416
      readFrame_o=>readFrame,
417
      readContent_o=>readContent,
418
      readContentEnd_i=>readContentEnd,
419
      readContentData_i=>readContentData,
420 36 magro732
      writeFrameFull_i=>writeFrameFull,
421
      writeFrame_o=>writeFrame,
422 48 magro732
      writeFrameAbort_o=>writeFrameAbort,
423 36 magro732
      writeContent_o=>writeContent,
424 48 magro732
      writeContentData_o=>writeContentData,
425
      inboundStb_o=>inboundStb,
426
      inboundAdr_o=>inboundAdr,
427
      inboundDat_o=>inboundDat,
428
      inboundStall_i=>inboundStall,
429
      outboundStb_i=>outboundStb,
430
      outboundAdr_i=>outboundAdr,
431
      outboundDat_i=>outboundDat,
432
      outboundStall_o=>outboundStall);
433 36 magro732
 
434
end architecture;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.