示例#1
0
def get_synth(tool, core, export=False):
    from fusesoc.coremanager import CoreManager
    from fusesoc.main import _import

    return _import('build', core.main.backend)(core,
                                               export=export,
                                               toplevel=None)
示例#2
0
def get_sim(sim, core, export=False):
    from fusesoc.coremanager import CoreManager
    from fusesoc.main import _import

    CoreManager().tool = sim
    toplevel = core.get_toplevel({})
    return _import('simulator', sim)(core, export=export, toplevel=toplevel)
示例#3
0
def test_empty_eda_api():
    import tempfile
    from fusesoc.main import _import

    (h, eda_api_file) = tempfile.mkstemp()

    with pytest.raises(RuntimeError):
        backend = _import('icarus')(eda_api_file=eda_api_file)
示例#4
0
def test_incomplete_eda_api():
    import tempfile
    import yaml
    from fusesoc.main import _import

    (h, eda_api_file) = tempfile.mkstemp()
    contents = []
    
    with open(eda_api_file,'w') as f:
        f.write(yaml.dump({'version' : '0.1.1'}))

    with pytest.raises(RuntimeError) as excinfo:
        backend = _import('icarus')(eda_api_file=eda_api_file)
    assert "Missing required parameter 'name'" in str(excinfo.value)

    with open(eda_api_file,'w') as f:
        f.write(yaml.dump({'version' : '0.1.1',
                           'name' : 'corename'}))

    backend = _import('icarus')(eda_api_file=eda_api_file)
示例#5
0
def get_synth(tool, core, export=False):
    import os.path
    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.main import _import

    flags = {'flow': 'synth', 'tool': tool}

    eda_api = CoreManager().get_eda_api(core.name, flags)
    work_root = os.path.join(Config().build_root, core.name.sanitized_name,
                             'bld-' + tool)
    return _import(core.main.backend)(eda_api=eda_api, work_root=work_root)
示例#6
0
def test_quartus():
    tests_dir = os.path.dirname(__file__)
    params = vlogparams + vlogdefines

    core = get_core("sockit")

    backend = _import('build', core.main.backend)(core, export=False)
    backend.configure(params)

    tcl_file = core.name.sanitized_name + '.tcl'
    ref_dir = os.path.join(tests_dir, __name__)

    assert '' == compare_file(ref_dir, backend.work_root, tcl_file)
示例#7
0
def test_verilator_run():
    import os.path
    import tempfile
    from fusesoc.main import _import
    ref_dir_cc = os.path.join(ref_dir, 'cc')
    dummy_exe = 'V'+core.verilator.top_module

    work_root    = tempfile.mkdtemp()
    eda_api_file = os.path.join(ref_dir_cc, core.name.sanitized_name)+ '.eda.yml'
    backend = _import(tool)(eda_api_file=eda_api_file, work_root=work_root)
    shutil.copy(os.path.join(ref_dir, dummy_exe),
                os.path.join(work_root, dummy_exe))

    backend.run(params)

    compare_files(ref_dir, work_root, ['run.cmd'])
示例#8
0
def get_sim(sim, core, export=False):
    import os.path
    from fusesoc.coremanager import CoreManager
    from fusesoc.config import Config
    from fusesoc.main import _import

    flags = {'flow': 'sim', 'tool': sim}

    eda_api = CoreManager().get_eda_api(core.name, flags)
    export_root = os.path.join(Config().build_root, core.name.sanitized_name,
                               'src')
    work_root = os.path.join(Config().build_root, core.name.sanitized_name,
                             'sim-' + sim)

    CoreManager().setup(core.name,
                        flags,
                        export=export,
                        export_root=export_root)
    return _import(sim)(eda_api=eda_api, work_root=work_root)
示例#9
0
def get_backend(core, flags, export):
    import os.path
    import tempfile
    import yaml
    from fusesoc.main import _import

    if export:
        export_root = os.path.join(build_root, core.name.sanitized_name, 'src')
    else:
        export_root = None
    work_root = os.path.join(build_root, core.name.sanitized_name,
                             core.get_work_root(flags))
    eda_api = common_cm.setup(core.name, flags, work_root, export_root)

    (h, eda_api_file) = tempfile.mkstemp()
    with open(eda_api_file, 'w') as f:
        f.write(yaml.dump(eda_api))

    return _import(flags['tool'])(eda_api_file=eda_api_file,
                                  work_root=work_root)
示例#10
0
def test_verilator_configure():
    import os.path
    import tempfile
    from fusesoc.main import _import

    for mode in ['cc', 'sc', 'lint-only']:
        work_root    = tempfile.mkdtemp()
        eda_api_file = os.path.join(ref_dir, mode, core.name.sanitized_name) + '.eda.yml'

        backend = _import(tool)(eda_api_file=eda_api_file, work_root=work_root)

        if mode is 'cc':
            _params = params
        else:
            _params = []
        backend.configure(_params)

        compare_files(ref_dir, work_root, ['Makefile'])

        compare_files(os.path.join(ref_dir, mode),
                      work_root,
                      ['config.mk', core.sanitized_name+'.vc'])
示例#11
0
def test_verilator():
    tests_dir = os.path.dirname(__file__)
    params = '--vlogparam_bool --vlogparam_int=42 --vlogparam_str=hello'
    params += ' --vlogdefine_bool --vlogdefine_int=42 --vlogdefine_str=hello'

    Config().build_root = os.path.join(tests_dir, 'build')
    Config().cache_root = os.path.join(tests_dir, 'cache')
    cores_root = os.path.join(tests_dir, 'cores')

    CoreManager().add_cores_root(cores_root)
    core = _get_core("mor1kx-generic")

    sim_name = 'verilator'
    CoreManager().tool = sim_name
    backend = _import('simulator', sim_name)(core, export=False)
    backend.configure(params.split())

    ref_dir = os.path.join(tests_dir, __name__)
    work_root = backend.work_root

    assert '' == compare_file(ref_dir, work_root, 'config.mk')
    assert '' == compare_file(ref_dir, work_root, 'Makefile')
    assert '' == compare_file(ref_dir, work_root, core.sanitized_name + '.vc')
示例#12
0
def test_ise():
    tests_dir = os.path.dirname(__file__)
    params = '--vlogparam_bool --vlogparam_int=42 --vlogparam_str=hello'
    params += ' --vlogdefine_bool --vlogdefine_int=42 --vlogdefine_str=hello'

    Config().build_root = os.path.join(tests_dir, 'build')
    Config().cache_root = os.path.join(tests_dir, 'cache')
    cores_root = os.path.join(tests_dir, 'cores')

    CoreManager().add_cores_root(cores_root)
    core = _get_core("atlys")

    backend = _import('build', core.main.backend)(core, export=False)
    backend.configure(params.split())

    tcl_file = core.name.sanitized_name + '.tcl'
    reference_tcl = os.path.join(tests_dir, __name__, tcl_file)
    generated_tcl = os.path.join(backend.work_root, tcl_file)

    assert os.path.exists(generated_tcl)

    with open(reference_tcl) as f1, open(generated_tcl) as f2:
        diff = ''.join(difflib.unified_diff(f1.readlines(), f2.readlines()))
        assert diff == ''
示例#13
0
def get_sim(sim, core):
    from fusesoc.coremanager import CoreManager
    from fusesoc.main import _import

    CoreManager().tool = sim
    return _import('simulator', sim)(core, export=False)
示例#14
0
import difflib
import os
import pytest

from fusesoc.main import _import
from test_common import compare_file, get_core, vlogdefines, vlogparams

tests_dir = os.path.dirname(__file__)
params = vlogparams + vlogdefines
core = get_core("c3demo")
backend = _import('build', core.main.backend)(core, export=False)
ref_dir = os.path.join(tests_dir, __name__)
work_root = backend.work_root


def test_icestorm_configure():

    backend.configure(params)

    ys_file = core.name.sanitized_name + '.ys'

    assert '' == compare_file(ref_dir, work_root, "Makefile")
    assert '' == compare_file(ref_dir, work_root, "config.mk")
    assert '' == compare_file(ref_dir, work_root, ys_file)


def test_icestorm_build():
    os.environ['PATH'] = os.path.join(
        tests_dir, 'mock_commands') + ':' + os.environ['PATH']
    backend.build(params)