update packaging and test

This commit is contained in:
Eyck Jentzsch 2020-12-23 09:17:31 +01:00
parent ae9e64e9fa
commit 90b9c3fc5d
8 changed files with 182 additions and 42 deletions

View File

@ -1,16 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project> <?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">pysysc-env</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property> <pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_ADDITIONAL_GRAMMAR_VALIDATION">3.6</pydev_property> <pydev_property name="org.python.pydev.PYTHON_ADDITIONAL_GRAMMAR_VALIDATION">3.6</pydev_property>
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH"> <pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
<path>/${PROJECT_DIR_NAME}</path> <path>/${PROJECT_DIR_NAME}</path>
</pydev_pathproperty> </pydev_pathproperty>
</pydev_project> </pydev_project>

View File

@ -2,4 +2,3 @@ recursive-include projectname *.py
include README.md include README.md
include LICENSE include LICENSE
include requirements.txt include requirements.txt

View File

@ -1,16 +1,24 @@
# PySysC # PySysC
A Python package to use SystemC from Python A Python 3 package to use SystemC from Python
## How to setup the environment ## How to setup the environment
The installation for PySysC is as follows (using bash shell):
``` ```
pyenv install 3.6.3 # create virtual environment
pyenv virtualenv 3.6.3 pysysc python3 -m venv pysysc-env
pyenv activate pysysc # and enable it
STDCXX=11 MAKE_NPROCS=32 pip install --verbose cppyy --no-binary=cppyy-cling . pysysc-env/bin/activate
pip install conan # install needed packages
python3 -m pip install wheel
# install cppyy, C++ std version needs to match the version used to build the SystemC library
STDCXX=11 python3 -m pip install cppyy
# clone of PySysC
git clone https://git.minres.com/SystemC/PySysC.git
# install PySysC, for development PySysC use 'python3 -m pip install -e`
python3 -m pip install -e PySysC
``` ```
## TODO ## TODO

View File

@ -2,7 +2,9 @@ import json
import cppyy import cppyy
import os.path import os.path
from pathlib import Path from pathlib import Path
from sysconfig import get_paths
import sys import sys
import re
import tempfile import tempfile
import conans.client.conan_api as conan import conans.client.conan_api as conan
from contextlib import (redirect_stdout, redirect_stderr) from contextlib import (redirect_stdout, redirect_stderr)
@ -122,12 +124,13 @@ def _load_systemc_cci():
return False return False
def _load_pythonization_lib(): def _load_pythonization_lib():
import pysysc info = get_paths()
path = os.path.dirname(os.path.dirname(pysysc.__file__)) for file in os.listdir(info['platlib']):
for file in os.listdir(path): if re.match(r'pysyscsc.*\.so', file):
if file.endswith(".so"): cppyy.load_library(os.path.join(info['platlib'], file))
cppyy.load_library(os.path.join(path, file)) full_path = os.path.join(info['data'], 'include/site/python%d.%d/PySysC/PyScModule.h' % sys.version_info[:2])
cppyy.include(os.path.join(path, "PyScModule.h")) if os.path.isfile(full_path):
cppyy.include(full_path)
return return

View File

@ -13,7 +13,8 @@ pysyscsc = Extension('pysyscsc',
include_dirs = [sysc_home+'/include'], include_dirs = [sysc_home+'/include'],
libraries = ['systemc'], libraries = ['systemc'],
library_dirs = [sysc_home+'/lib'], library_dirs = [sysc_home+'/lib'],
sources = ['PyScModule.cpp']) sources = ['PyScModule.cpp'],
depends = ['PyScModule.h'])
setup(name='PySysC', setup(name='PySysC',
@ -33,7 +34,11 @@ setup(name='PySysC',
author_email='info@minres.com', author_email='info@minres.com',
license='Apache-2.0', license='Apache-2.0',
packages=['pysysc'], packages=['pysysc'],
data_files=[('.',['PyScModule.h'])], package_data={
'pysyscsc': ['PyScModule.h'],
},
#data_files=[('include',['PyScModule.h'])],
headers=['PyScModule.h'],
include_package_data=True, include_package_data=True,
install_requires=[ install_requires=[
'cppyy', 'cppyy',

79
tests/modules.py Normal file
View 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")

View File

@ -7,6 +7,8 @@ from cppyy import gbl as cpp
proj_home='../../PySysC-SC' proj_home='../../PySysC-SC'
conan_res = scpy.read_config_from_conan(os.path.join(proj_home, 'conanfile.txt')) conan_res = scpy.read_config_from_conan(os.path.join(proj_home, 'conanfile.txt'))
scpy.load_systemc() 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_include_path(os.path.join(proj_home, 'components'))
scpy.add_library('components.h', os.path.join(proj_home, 'build/Debug/lib/libcomponents.so')) scpy.add_library('components.h', os.path.join(proj_home, 'build/Debug/lib/libcomponents.so'))

View File

@ -12,22 +12,50 @@ from cppyy import gbl as cpp
class Test(unittest.TestCase): class Test(unittest.TestCase):
initialized=False
not_initialized=True
def setUp(self): def setUp(self):
proj_home='../PySysC-SC' if Test.not_initialized:
conan_res = scpy.read_config_from_conan(os.path.join(proj_home, 'conanfile.txt')) 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.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_include_path(os.path.join(proj_home, 'components'))
scpy.add_library('components.h', os.path.join(proj_home, 'build/Debug/lib/libcomponents.so')) 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")) # instantiate
self.initiator.socket.bind(self.router.target_socket) ###############################################################################
for idx,m in enumerate(self.memories): Test.clkgen = cpp.ClkGen(cpp.sc_core.sc_module_name("clk_gen"))
self.router.initiator_socket.at(idx).bind(m.socket) Test.rstgen = cpp.ResetGen(cpp.sc_core.sc_module_name("rst_gen"))
print("Initialized") 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): def tearDown(self):
#cpp.sc_core.sc_stop() #cpp.sc_core.sc_stop()
@ -35,26 +63,28 @@ class Test(unittest.TestCase):
def testSCTimeRepr(self): 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): def testMembers(self):
members = scpy.get_members(initiator) members = scpy.get_members(Test.initiator)
print("members") print("members")
methods = scpy.get_methods(initiator) methods = scpy.get_methods(Test.initiator)
print("methods") print("methods")
ports = scpy.get_ports(Test.initiator)
ports = scpy.get_ports(initiator)
print("ports") print("ports")
intors = scpy.get_inititator_sockets(initiator) intors = scpy.get_inititator_sockets(Test.initiator)
print("intors") print("intors")
tgts = scpy.get_target_sockets(initiator) tgts = scpy.get_target_sockets(Test.initiator)
print("tgts") print("tgts")
childs = scpy.get_submodules(initiator) childs = scpy.get_submodules(Test.initiator)
print("childs") print("childs")
self.assertTrue(len(intors)==1, "Wrong numbers of initiator sockets") self.assertTrue(len(intors)==1, "Wrong numbers of initiator sockets")
def testConnection(self): 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): # def testSim(self):
# cpp.sc_core.sc_in_action=True # cpp.sc_core.sc_in_action=True