Skip to content

Commit

Permalink
[pymtl.tools.transl] add BitStruct tests (issue #133)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlockhart committed May 2, 2015
1 parent d346588 commit b62304b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
58 changes: 57 additions & 1 deletion pymtl/tools/simulation/SimulationTool_struct_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import pytest
import pymtl.model.ConnectionEdge

from pymtl import *
from random import randrange
from pymtl import *

from SimulationTool_comb_test import verify_bit_blast, set_ports
from SimulationTool_seq_test import setup_sim, local_setup_sim
Expand Down Expand Up @@ -745,6 +746,61 @@ def __init__( s, config ):
sim.cycle()
for j in range( 4 ): model.b[j] == i+j

#=======================================================================
# BitStructs
#=======================================================================
# Helper classes/methods.

class BitStructGlobal( BitStructDefinition ):
def __init__( s, src_nbits, dest_nbits ):
s.src = BitField( src_nbits )
s.dest = BitField( dest_nbits )

class BitStructConnect( Model ):
def __init__( s, MsgType ):
s.in_ = InPort ( MsgType )
s.out = OutPort( MsgType )
s.connect( s.in_.src, s.out.dest )
s.connect( s.in_.dest, s.out.src )

def bitstruct_verifier( model, sim, src, dest ):
max_ = 2**src
for i in range( 10 ):
src, dest = randrange(0,max_), randrange(0,max_)
model.in_.src .value = src
model.in_.dest.value = dest
sim.cycle()
print model.in_.src, model.out.src, src
print model.in_.dest, model.out.dest, dest
assert model.out.src == dest
assert model.out.dest == src

#-----------------------------------------------------------------------
# BitStructGlobal
#-----------------------------------------------------------------------
@pytest.mark.parametrize('src,dest', [(8,8),(16,16)])
def test_BitStructGlobal( setup_sim, src, dest ):
model = BitStructConnect( BitStructGlobal( src, dest ) )
model, sim = setup_sim( model )
bitstruct_verifier( model, sim, src, dest )

#-----------------------------------------------------------------------
# BitStructLocal
#-----------------------------------------------------------------------
@pytest.mark.parametrize('src,dest', [(8,8),(16,16)])
def test_BitStructLocal( setup_sim, src, dest ):
class BitStructLocal( BitStructDefinition ):
def __init__( s, src_nbits, dest_nbits ):
s.src = BitField( src_nbits )
s.dest = BitField( dest_nbits )
model = BitStructConnect( BitStructLocal( src, dest ) )
model, sim = setup_sim( model )
bitstruct_verifier( model, sim, src, dest )


# alejandro innarutu
# kevin thompson




4 changes: 4 additions & 0 deletions pymtl/tools/translation/verilog_structural_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
# FIXME: wire-to-wire connections do not try to infer directionality
test_WireToWire2,

# FIXME: generated verilog wrappers can't import BitStructs defined in
# a nested scope (not global)
test_BitStructLocal,

]]

#-----------------------------------------------------------------------
Expand Down

0 comments on commit b62304b

Please sign in to comment.