@@ -202,6 +202,47 @@ def process():
202202 sim .add_process (process )
203203 sim .run ()
204204
205+ class ElasticBufferTestCase (FHDLTestCase ):
206+ def test_paramcheck (self ):
207+ with self .assertRaises (TypeError ):
208+ e = ElasticBuffer (0 , 2 , "i" , "o" )
209+ with self .assertRaises (TypeError ):
210+ e = ElasticBuffer ("i" , 2 , "i" , "o" )
211+ with self .assertRaises (TypeError ):
212+ e = ElasticBuffer (1 , 1 , "i" , "o" )
213+ with self .assertRaises (TypeError ):
214+ e = ElasticBuffer (1 , "i" , "i" , "o" )
215+ e = ElasticBuffer (1 , 2 , "i" , "o" )
216+
217+ def test_smoke_po2 (self ):
218+ self .check_smoke (8 , 8 )
219+
220+ def test_smoke_nonpo2 (self ):
221+ self .check_smoke (8 , 7 )
222+
223+ def check_smoke (self , width , depth ):
224+ m = Module ()
225+ m .domains += ClockDomain ("sync" )
226+ e = m .submodules .dut = ElasticBuffer (width , depth , "sync" , "sync" )
227+
228+ with Simulator (m , vcd_file = open ("test.vcd" , "w" )) as sim :
229+ sim .add_clock (1e-6 )
230+ def process ():
231+ pipeline_filled = False
232+ expected_out = 1
233+ yield Tick ()
234+ for i in range (depth * 4 ):
235+ yield e .i .eq (i )
236+ if (yield e .o ):
237+ pipeline_filled = True
238+ if pipeline_filled :
239+ self .assertEqual ((yield e .o ), expected_out )
240+ expected_out = (expected_out + 1 ) % (2 ** width )
241+ yield Tick ()
242+ self .assertEqual (pipeline_filled , True )
243+ sim .add_process (process )
244+ sim .run ()
245+
205246# TODO: test with distinct clocks
206247# (since we can currently only test symmetric aspect ratio)
207248class GearboxTestCase (FHDLTestCase ):
0 commit comments