Example #1
0
def setup_backend(paramtypes, name, tool, tool_options, use_vpi=False):
    os.environ['PATH'] = os.path.join(
        tests_dir, 'mock_commands') + ':' + os.environ['PATH']
    (parameters, args) = param_gen(paramtypes)

    work_root = tempfile.mkdtemp(prefix=tool + '_')

    _vpi = []
    if use_vpi:
        _vpi = vpi
        for v in vpi:
            for f in v['src_files']:
                _f = os.path.join(work_root, f)
                if not os.path.exists(os.path.dirname(_f)):
                    os.makedirs(os.path.dirname(_f))
                with open(_f, 'a'):
                    os.utime(_f, None)

    eda_api_file = os.path.join(work_root, name + '.eda.yml')
    with open(eda_api_file, 'w') as f:
        f.write(
            yaml.dump({
                'name': name,
                'files': files,
                'parameters': parameters,
                'tool_options': {
                    tool: tool_options
                },
                'toplevel': 'top_module',
                'vpi': _vpi
            }))

    return (get_edatool(tool)(eda_api_file=eda_api_file), args, work_root)
Example #2
0
def test_empty_eda_api():
    import tempfile
    from fusesoc.edatools import get_edatool

    (h, eda_api_file) = tempfile.mkstemp()

    with pytest.raises(RuntimeError):
        backend = get_edatool('icarus')(eda_api_file=eda_api_file)
Example #3
0
def test_incomplete_eda_api():
    import tempfile
    import yaml
    from fusesoc.edatools import get_edatool

    (h, eda_api_file) = tempfile.mkstemp()
    contents = []

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

    with pytest.raises(RuntimeError) as excinfo:
        backend = get_edatool('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.2', 'name': 'corename'}))

    backend = get_edatool('icarus')(eda_api_file=eda_api_file)
Example #4
0
def setup_backend_minimal(name, tool, files):
    os.environ['PATH'] = os.path.join(
        tests_dir, 'mock_commands') + ':' + os.environ['PATH']

    work_root = tempfile.mkdtemp(prefix=tool + '_')

    eda_api_file = os.path.join(work_root, name + '.eda.yml')
    with open(eda_api_file, 'w') as f:
        f.write(
            yaml.dump({
                'name': name,
                'files': files,
                'toplevel': 'top_module',
            }))
    return (get_edatool(tool)(eda_api_file=eda_api_file), work_root)
Example #5
0
def test_verilator_run():
    import os.path
    import tempfile
    from fusesoc.edatools import get_edatool
    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 = get_edatool(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'])
Example #6
0
def test_verilator_configure():
    import os.path
    import tempfile
    from fusesoc.edatools import get_edatool

    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 = get_edatool(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'])
Example #7
0
def test_eda_api_hooks():
    import os.path
    import tempfile
    import yaml
    from fusesoc.edatools import get_edatool

    tests_dir = os.path.dirname(__file__)
    ref_dir = os.path.join(tests_dir, __name__)

    script = 'exit_1_script'
    hooks = {
        'pre_build': [{
            'cmd': ['sh', os.path.join(ref_dir, script)],
            'name': script
        }]
    }

    (h, eda_api_file) = tempfile.mkstemp(prefix='eda_api_hooks_')
    with open(eda_api_file, 'w') as f:
        f.write(yaml.dump({'hooks': hooks, 'name': script}))

    backend = get_edatool('icarus')(eda_api_file=eda_api_file)
    with pytest.raises(RuntimeError):
        backend.build()
Example #8
0
def test_eda_api_files():
    import tempfile
    import yaml

    from fusesoc.edatools import get_edatool
    files = [{
        'name': 'plain_file'
    }, {
        'name': 'subdir/plain_include_file',
        'is_include_file': True
    }, {
        'name': 'file_with_args',
        'file_type': 'verilogSource',
        'logical_name': 'libx'
    }, {
        'name': 'include_file_with_args',
        'is_include_file': True,
        'file_type': 'verilogSource',
        'logical_name': 'libx'
    }]
    (h, eda_api_file) = tempfile.mkstemp(prefix='eda_api_files_')
    with open(eda_api_file, 'w') as f:
        f.write(yaml.dump({'files': files, 'name': 'test_eda_api_files'}))

    backend = get_edatool('icarus')(eda_api_file=eda_api_file)
    (parsed_files, incdirs) = backend._get_fileset_files()

    assert len(parsed_files) == 2
    assert parsed_files[0].name == 'plain_file'
    assert parsed_files[0].file_type == ''
    assert parsed_files[0].logical_name == ''
    assert parsed_files[1].name == 'file_with_args'
    assert parsed_files[1].file_type == 'verilogSource'
    assert parsed_files[1].logical_name == 'libx'

    assert incdirs == ['subdir', '.']
Example #9
0
def run_backend(cm, export, do_configure, do_build, do_run, flags, system,
                backendargs):
    tool_error = "No tool was supplied on command line or found in '{}' core description"
    core = _get_core(cm, system)
    try:
        tool = core.get_tool(flags)
    except SyntaxError as e:
        logger.error(str(e))
        exit(1)
    if not tool:
        logger.error(tool_error.format(system))
        exit(1)
    flags['tool'] = tool
    if export:
        export_root = os.path.join(cm.config.build_root,
                                   core.name.sanitized_name, 'src')
    else:
        export_root = None
    try:
        work_root = os.path.join(cm.config.build_root,
                                 core.name.sanitized_name,
                                 core.get_work_root(flags))
    except SyntaxError as e:
        logger.error(e.msg)
        exit(1)
    eda_api_file = os.path.join(work_root,
                                core.name.sanitized_name + '.eda.yml')
    if do_configure:
        try:
            eda_api = cm.setup(core.name,
                               flags,
                               work_root=work_root,
                               export_root=export_root)
        except DependencyError as e:
            logger.error(
                e.msg +
                "\nFailed to resolve dependencies for {}".format(system))
            exit(1)
        except SyntaxError as e:
            logger.error(e.msg)
            exit(1)
        except RuntimeError as e:
            logger.error("Setup failed : {}".format(str(e)))
            exit(1)
        with open(eda_api_file, 'w') as f:
            f.write(yaml.dump(eda_api))

    #Frontend/backend separation

    try:
        backend = get_edatool(tool)(eda_api_file=eda_api_file)
    except ImportError:
        logger.error('Backend "{}" not found'.format(tool))
        exit(1)
    except RuntimeError as e:
        logger.error(str(e))
        exit(1)
    except FileNotFoundError as e:
        logger.error('Could not find EDA API file "{}"'.format(e.filename))
        exit(1)

    if do_configure:
        try:
            backend.configure(backendargs)
            print('')
        except RuntimeError as e:
            logger.error("Failed to configure the system")
            logger.error(str(e))
            exit(1)

    if do_build:
        try:
            backend.build()
        except RuntimeError as e:
            logger.error("Failed to build {} : {}".format(
                str(core.name), str(e)))
            exit(1)

    if do_run:
        try:
            backend.run(backendargs)
        except RuntimeError as e:
            logger.error("Failed to run {} : {}".format(
                str(core.name), str(e)))
            exit(1)