update packaging and test
This commit is contained in:
79
tests/modules.py
Normal file
79
tests/modules.py
Normal file
@ -0,0 +1,79 @@
|
||||
import os.path
|
||||
import logging
|
||||
import cppyy
|
||||
from cppyy import gbl as cpp
|
||||
import pysysc
|
||||
from pysysc.structural import Connection, Module, Signal, Simulation
|
||||
|
||||
num_of_mem = 100
|
||||
|
||||
class TopModule(cpp.scc.PyScModule):
|
||||
|
||||
def __init__(self, name):
|
||||
super().__init__(self, name)
|
||||
###############################################################################
|
||||
# instantiate
|
||||
###############################################################################
|
||||
self.clk_gen = Module(cpp.ClkGen).create("clk_gen")
|
||||
self.rst_gen = Module(cpp.ResetGen).create("rst_gen")
|
||||
self.initiator = Module(cpp.Initiator).create("initiator")
|
||||
self.memories = [Module(cpp.Memory).create("mem%d"%idx) for idx in range(0,num_of_mem)]
|
||||
self.router = Module(cpp.Router[num_of_mem]).create("router")
|
||||
###############################################################################
|
||||
# connect them
|
||||
###############################################################################
|
||||
self.clk = Signal("clk").src(self.clk_gen.clk_o).sink(self.initiator.clk_i).sink(self.router.clk_i)
|
||||
[self.clk.sink(m.clk_i) for m in self.memories]
|
||||
self.rst = Signal("rst").src(self.rst_gen.reset_o).sink(self.initiator.reset_i).sink(self.router.reset_i)
|
||||
[self.rst.sink(m.reset_i) for m in self.memories]
|
||||
Connection().src(self.initiator.socket).sink(self.router.target_socket)
|
||||
[Connection().src(self.router.initiator_socket.at(idx)).sink(m.socket) for idx,m in enumerate(self.memories)]
|
||||
super().method("TickMethod", [self.clk.signal.pos_edge()])
|
||||
|
||||
|
||||
def EndOfElaboration(self):
|
||||
print("Elaboration finished")
|
||||
|
||||
def StartOfSimulation(self):
|
||||
print("Simulation started")
|
||||
|
||||
def EndOfSimulation(self):
|
||||
print("Simulation finished")
|
||||
|
||||
def TickMethod(self):
|
||||
print("Simulation tick")
|
||||
|
||||
###############################################################################
|
||||
# setup and load
|
||||
###############################################################################
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
build_type='Debug'
|
||||
###############################################################################
|
||||
#myDir = os.path.dirname( os.path.realpath(__file__))
|
||||
myDir = os.path.dirname( os.path.realpath(__file__)+'/../../PySysC-SC')
|
||||
pysysc.read_config_from_conan(os.path.join(myDir, 'conanfile.txt'), build_type)
|
||||
pysysc.load_systemc()
|
||||
###############################################################################
|
||||
logging.debug("Loading SC-Components lib")
|
||||
pysysc.add_include_path(os.path.join(myDir, 'sc-components/incl'))
|
||||
pysysc.add_library('scc.h', os.path.join(myDir, 'build/%s/lib/libsc-components.so'%build_type))
|
||||
###############################################################################
|
||||
logging.debug("Loading Components lib")
|
||||
pysysc.add_include_path(os.path.join(myDir, 'components'))
|
||||
pysysc.add_library('components.h', os.path.join(myDir, 'build/%s/lib/libcomponents.so'%build_type))
|
||||
###############################################################################
|
||||
# configure
|
||||
###############################################################################
|
||||
Simulation.setup(logging.root.level)
|
||||
###############################################################################
|
||||
# instantiate
|
||||
###############################################################################
|
||||
#from modules import TopModule
|
||||
dut = Module(TopModule).create("dut")
|
||||
###############################################################################
|
||||
# run if it is standalone
|
||||
###############################################################################
|
||||
if __name__ == "__main__":
|
||||
Simulation.configure(enable_vcd=False)
|
||||
Simulation.run()
|
||||
logging.debug("Done")
|
@ -7,6 +7,8 @@ from cppyy import gbl as cpp
|
||||
proj_home='../../PySysC-SC'
|
||||
conan_res = scpy.read_config_from_conan(os.path.join(proj_home, 'conanfile.txt'))
|
||||
scpy.load_systemc()
|
||||
scpy.add_include_path(os.path.join(proj_home, 'sc-components/incl'))
|
||||
scpy.add_library('scc.h', os.path.join(proj_home, 'build/Debug/lib/libscc.so'))
|
||||
scpy.add_include_path(os.path.join(proj_home, 'components'))
|
||||
scpy.add_library('components.h', os.path.join(proj_home, 'build/Debug/lib/libcomponents.so'))
|
||||
|
||||
|
@ -12,22 +12,50 @@ from cppyy import gbl as cpp
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
initialized=False
|
||||
|
||||
not_initialized=True
|
||||
|
||||
def setUp(self):
|
||||
proj_home='../PySysC-SC'
|
||||
conan_res = scpy.read_config_from_conan(os.path.join(proj_home, 'conanfile.txt'))
|
||||
scpy.load_systemc()
|
||||
scpy.add_include_path(os.path.join(proj_home, 'components'))
|
||||
scpy.add_library('components.h', os.path.join(proj_home, 'build/Debug/lib/libcomponents.so'))
|
||||
|
||||
self.initiator = cpp.Initiator(cpp.sc_core.sc_module_name("initiator"))
|
||||
self.memories = [cpp.Memory(cpp.sc_core.sc_module_name(name)) for name in ["mem0", "mem1", "mem2", "mem3"]]
|
||||
self.router = cpp.Router[4](cpp.sc_core.sc_module_name("router"))
|
||||
self.initiator.socket.bind(self.router.target_socket)
|
||||
for idx,m in enumerate(self.memories):
|
||||
self.router.initiator_socket.at(idx).bind(m.socket)
|
||||
print("Initialized")
|
||||
if Test.not_initialized:
|
||||
proj_home='../../PySysC-SC'
|
||||
conan_path=os.path.join(proj_home, 'conanfile.txt')
|
||||
conan_res = scpy.read_config_from_conan(conan_path)
|
||||
scpy.load_systemc()
|
||||
scpy.add_include_path(os.path.join(proj_home, 'sc-components/incl'))
|
||||
scpy.add_library('scc.h', os.path.join(proj_home, 'build/Debug/lib/libscc.so'))
|
||||
scpy.add_include_path(os.path.join(proj_home, 'components'))
|
||||
scpy.add_library('components.h', os.path.join(proj_home, 'build/Debug/lib/libcomponents.so'))
|
||||
|
||||
|
||||
###############################################################################
|
||||
# instantiate
|
||||
###############################################################################
|
||||
Test.clkgen = cpp.ClkGen(cpp.sc_core.sc_module_name("clk_gen"))
|
||||
Test.rstgen = cpp.ResetGen(cpp.sc_core.sc_module_name("rst_gen"))
|
||||
Test.initiator = cpp.Initiator(cpp.sc_core.sc_module_name("initiator"))
|
||||
Test.memories = [cpp.Memory(cpp.sc_core.sc_module_name(name)) for name in ["mem0", "mem1", "mem2", "mem3"]]
|
||||
Test.router = cpp.Router[4](cpp.sc_core.sc_module_name("router"))
|
||||
###############################################################################
|
||||
# signals
|
||||
###############################################################################
|
||||
Test.sig_clk = cpp.sc_core.sc_signal[cpp.sc_core.sc_time]("clk")
|
||||
Test.sig_rst = cpp.sc_core.sc_signal[cpp.sc_dt.sc_logic]("rst")
|
||||
###############################################################################
|
||||
# connect it
|
||||
###############################################################################
|
||||
Test.clkgen.clk_o(Test.sig_clk)
|
||||
Test.rstgen.reset_o(Test.sig_rst)
|
||||
Test.initiator.socket.bind(Test.router.target_socket)
|
||||
Test.initiator.clk_i(Test.sig_clk)
|
||||
Test.initiator.reset_i(Test.sig_rst)
|
||||
Test.router.clk_i(Test.sig_clk)
|
||||
Test.router.reset_i(Test.sig_rst)
|
||||
for idx,m in enumerate(Test.memories):
|
||||
Test.router.initiator_socket.at(idx).bind(m.socket)
|
||||
m.clk_i(Test.sig_clk)
|
||||
m.reset_i(Test.sig_rst)
|
||||
|
||||
Test.not_initialized=False
|
||||
|
||||
def tearDown(self):
|
||||
#cpp.sc_core.sc_stop()
|
||||
@ -35,26 +63,28 @@ class Test(unittest.TestCase):
|
||||
|
||||
|
||||
def testSCTimeRepr(self):
|
||||
self.assertEqual(str(cpp.sc_core.sc_time_stamp()), '0 s')
|
||||
cur_time=cpp.sc_core.sc_time_stamp()
|
||||
cur_time_str=cur_time.to_string()
|
||||
self.assertEqual(cur_time_str, '0 s')
|
||||
|
||||
def testMembers(self):
|
||||
members = scpy.get_members(initiator)
|
||||
members = scpy.get_members(Test.initiator)
|
||||
print("members")
|
||||
methods = scpy.get_methods(initiator)
|
||||
methods = scpy.get_methods(Test.initiator)
|
||||
print("methods")
|
||||
|
||||
ports = scpy.get_ports(initiator)
|
||||
ports = scpy.get_ports(Test.initiator)
|
||||
print("ports")
|
||||
intors = scpy.get_inititator_sockets(initiator)
|
||||
intors = scpy.get_inititator_sockets(Test.initiator)
|
||||
print("intors")
|
||||
tgts = scpy.get_target_sockets(initiator)
|
||||
tgts = scpy.get_target_sockets(Test.initiator)
|
||||
print("tgts")
|
||||
childs = scpy.get_submodules(initiator)
|
||||
childs = scpy.get_submodules(Test.initiator)
|
||||
print("childs")
|
||||
self.assertTrue(len(intors)==1, "Wrong numbers of initiator sockets")
|
||||
|
||||
def testConnection(self):
|
||||
self.assertFalse(isinstance(self.intors[0][0], cpp.sc_core.sc_object), " intor[0] connects to sc_object", )
|
||||
intors = scpy.get_inititator_sockets(Test.initiator)
|
||||
self.assertFalse(isinstance(intors[0][0], cpp.sc_core.sc_object), " intor[0] connects to sc_object", )
|
||||
|
||||
# def testSim(self):
|
||||
# cpp.sc_core.sc_in_action=True
|
||||
|
Reference in New Issue
Block a user