Example #1
0
def test_virtual():
    import os
    import tempfile

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.edalizer import Edalizer
    from fusesoc.librarymanager import Library
    from fusesoc.vlnv import Vlnv

    flags = {"tool": "icarus"}

    build_root = tempfile.mkdtemp(prefix="export_")
    work_root = os.path.join(build_root, "work")

    core_dir = os.path.join(os.path.dirname(__file__), "capi2_cores",
                            "virtual")

    cm = CoreManager(Config())
    cm.add_library(Library("virtual", core_dir))

    root_core = cm.get_core(Vlnv("::user"))

    edalizer = Edalizer(
        toplevel=root_core.name,
        flags=flags,
        core_manager=cm,
        work_root=work_root,
    )
    edalizer.run()

    deps = cm.get_depends(root_core.name, {})
    deps_names = [str(c) for c in deps]

    assert deps_names == ["::impl2:0", "::user:0"]
Example #2
0
def test_copyto():
    import os
    import tempfile

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.edalizer import Edalizer
    from fusesoc.librarymanager import Library
    from fusesoc.vlnv import Vlnv

    flags = {"tool": "icarus"}

    work_root = tempfile.mkdtemp(prefix="copyto_")

    core_dir = os.path.join(os.path.dirname(__file__), "cores", "misc", "copytocore")
    lib = Library("misc", core_dir)

    cm = CoreManager(Config())
    cm.add_library(lib)

    core = cm.get_core(Vlnv("::copytocore"))

    edalizer = Edalizer(
        toplevel=core.name,
        flags=flags,
        core_manager=cm,
        cache_root=None,
        work_root=work_root,
        export_root=None,
        system_name=None,
    )
    edalizer.run()

    eda_api = edalizer.edalize

    assert eda_api["files"] == [
        {
            "file_type": "user",
            "core": "::copytocore:0",
            "logical_name": "",
            "name": "copied.file",
            "is_include_file": False,
        },
        {
            "file_type": "tclSource",
            "core": "::copytocore:0",
            "logical_name": "",
            "name": "subdir/another.file",
            "is_include_file": False,
        },
    ]
    assert os.path.exists(os.path.join(work_root, "copied.file"))
    assert os.path.exists(os.path.join(work_root, "subdir", "another.file"))
Example #3
0
def test_export():
    import os
    import tempfile

    from fusesoc.edalizer import Edalizer
    from fusesoc.core import Core

    core = Core(
        os.path.join(os.path.dirname(__file__), 'cores', 'wb_intercon',
                     'wb_intercon-1.0.core'))

    build_root = tempfile.mkdtemp(prefix='export_')
    export_root = os.path.join(build_root, 'exported_files')
    eda_api = Edalizer(core.name, {
        'tool': 'icarus'
    }, [core],
                       cache_root=None,
                       work_root=os.path.join(build_root, 'work'),
                       export_root=export_root).edalize

    for f in [
            'wb_intercon_1.0/dummy_icarus.v',
            'wb_intercon_1.0/bench/wb_mux_tb.v',
            'wb_intercon_1.0/bench/wb_upsizer_tb.v',
            'wb_intercon_1.0/bench/wb_intercon_tb.v',
            'wb_intercon_1.0/bench/wb_arbiter_tb.v',
            'wb_intercon_1.0/rtl/verilog/wb_data_resize.v',
            'wb_intercon_1.0/rtl/verilog/wb_mux.v',
            'wb_intercon_1.0/rtl/verilog/wb_arbiter.v',
            'wb_intercon_1.0/rtl/verilog/wb_upsizer.v',
    ]:
        assert os.path.isfile(os.path.join(export_root, f))
Example #4
0
def test_copyto():
    import os
    import tempfile

    from fusesoc.edalizer import Edalizer
    from fusesoc.core import Core

    core = Core(
        os.path.join(os.path.dirname(__file__), 'cores', 'misc',
                     'copytocore.core'))
    flags = {'tool': 'icarus'}

    work_root = tempfile.mkdtemp(prefix='copyto_')

    eda_api = Edalizer(core.name, flags, [core], None, work_root, None).edalize

    assert eda_api['files'] == [{
        'file_type': 'user',
        'core': '::copytocore:0',
        'logical_name': '',
        'name': 'copied.file',
        'is_include_file': False
    }, {
        'file_type': 'tclSource',
        'core': '::copytocore:0',
        'logical_name': '',
        'name': 'subdir/another.file',
        'is_include_file': False
    }]
    assert os.path.exists(os.path.join(work_root, 'copied.file'))
    assert os.path.exists(os.path.join(work_root, 'subdir', 'another.file'))
Example #5
0
def test_copyto():
    import os
    import tempfile

    from fusesoc.edalizer import Edalizer
    from fusesoc.core import Core

    core = Core(
        os.path.join(os.path.dirname(__file__), "cores", "misc",
                     "copytocore.core"))
    flags = {"tool": "icarus"}

    work_root = tempfile.mkdtemp(prefix="copyto_")

    eda_api = Edalizer(core.name, flags, [core], None, work_root, None).edalize

    assert eda_api["files"] == [
        {
            "file_type": "user",
            "core": "::copytocore:0",
            "logical_name": "",
            "name": "copied.file",
            "is_include_file": False,
        },
        {
            "file_type": "tclSource",
            "core": "::copytocore:0",
            "logical_name": "",
            "name": "subdir/another.file",
            "is_include_file": False,
        },
    ]
    assert os.path.exists(os.path.join(work_root, "copied.file"))
    assert os.path.exists(os.path.join(work_root, "subdir", "another.file"))
Example #6
0
def test_generators():
    import os
    import tempfile

    from fusesoc.edalizer import Edalizer
    from fusesoc.core import Core

    tests_dir = os.path.dirname(__file__)
    cores_dir = os.path.join(tests_dir, "capi2_cores", "misc")

    core1 = Core(os.path.join(cores_dir, 'generators.core'))
    core2 = Core(os.path.join(cores_dir, 'generate.core'))

    build_root = tempfile.mkdtemp(prefix='export_')
    cache_root = tempfile.mkdtemp(prefix='export_cache_')
    export_root = os.path.join(build_root, 'exported_files')
    eda_api = Edalizer(core2.name, {
        'tool': 'icarus'
    }, [core1, core2],
                       cache_root=cache_root,
                       work_root=os.path.join(build_root, 'work'),
                       export_root=export_root).edalize
    gendir = os.path.join(cache_root, "generated",
                          "generate-testgenerate_without_params_0")
    assert os.path.isfile(os.path.join(gendir, "generated.core"))
    assert os.path.isfile(
        os.path.join(gendir, "testgenerate_without_params_input.yml"))
    gendir = os.path.join(cache_root, "generated",
                          "generate-testgenerate_with_params_0")
    assert os.path.isfile(os.path.join(gendir, "generated.core"))
    assert os.path.isfile(
        os.path.join(gendir, "testgenerate_with_params_input.yml"))
Example #7
0
def test_export():
    import os
    import tempfile

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.edalizer import Edalizer
    from fusesoc.librarymanager import Library
    from fusesoc.vlnv import Vlnv

    flags = {"tool": "icarus"}

    build_root = tempfile.mkdtemp(prefix="export_")
    export_root = os.path.join(build_root, "exported_files")
    work_root = os.path.join(build_root, "work")

    core_dir = os.path.join(os.path.dirname(__file__), "cores")

    cm = CoreManager(Config())
    cm.add_library(Library("cores", core_dir))

    core = cm.get_core(Vlnv("::wb_intercon"))

    edalizer = Edalizer(
        toplevel=core.name,
        flags=flags,
        core_manager=cm,
        cache_root=None,
        work_root=work_root,
        export_root=export_root,
        system_name=None,
    )
    edalizer.run()

    for f in [
            "wb_intercon_1.0/dummy_icarus.v",
            "wb_intercon_1.0/bench/wb_mux_tb.v",
            "wb_intercon_1.0/bench/wb_upsizer_tb.v",
            "wb_intercon_1.0/bench/wb_intercon_tb.v",
            "wb_intercon_1.0/bench/wb_arbiter_tb.v",
            "wb_intercon_1.0/rtl/verilog/wb_data_resize.v",
            "wb_intercon_1.0/rtl/verilog/wb_mux.v",
            "wb_intercon_1.0/rtl/verilog/wb_arbiter.v",
            "wb_intercon_1.0/rtl/verilog/wb_upsizer.v",
    ]:
        assert os.path.isfile(os.path.join(export_root, f))
Example #8
0
def test_generators():
    import os
    import tempfile

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.edalizer import Edalizer
    from fusesoc.librarymanager import Library
    from fusesoc.vlnv import Vlnv

    tests_dir = os.path.dirname(__file__)
    cores_dir = os.path.join(tests_dir, "capi2_cores", "misc", "generate")

    lib = Library("edalizer", cores_dir)

    cm = CoreManager(Config())
    cm.add_library(lib)

    core = cm.get_core(Vlnv("::generate"))

    build_root = tempfile.mkdtemp(prefix="export_")
    cache_root = tempfile.mkdtemp(prefix="export_cache_")
    export_root = os.path.join(build_root, "exported_files")

    edalizer = Edalizer(
        toplevel=core.name,
        flags={"tool": "icarus"},
        core_manager=cm,
        cache_root=cache_root,
        work_root=os.path.join(build_root, "work"),
        export_root=export_root,
        system_name=None,
    )
    edalizer.run()

    gendir = os.path.join(cache_root, "generated",
                          "generate-testgenerate_without_params_0")
    assert os.path.isfile(os.path.join(gendir, "generated.core"))
    assert os.path.isfile(
        os.path.join(gendir, "testgenerate_without_params_input.yml"))
    gendir = os.path.join(cache_root, "generated",
                          "generate-testgenerate_with_params_0")
    assert os.path.isfile(os.path.join(gendir, "generated.core"))
    assert os.path.isfile(
        os.path.join(gendir, "testgenerate_with_params_input.yml"))
Example #9
0
def test_generators():
    import os
    import tempfile

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.edalizer import Edalizer
    from fusesoc.librarymanager import Library
    from fusesoc.vlnv import Vlnv

    tests_dir = os.path.dirname(__file__)
    cores_dir = os.path.join(tests_dir, "capi2_cores", "misc", "generate")

    lib = Library("edalizer", cores_dir)

    cm = CoreManager(Config())
    cm.add_library(lib)

    core = cm.get_core(Vlnv("::generate"))

    build_root = tempfile.mkdtemp(prefix="export_")
    export_root = os.path.join(build_root, "exported_files")

    edalizer = Edalizer(
        toplevel=core.name,
        flags={"tool": "icarus"},
        core_manager=cm,
        work_root=os.path.join(build_root, "work"),
        export_root=export_root,
        system_name=None,
    )
    edalizer.run()

    name_to_core = {str(core.name): core for core in edalizer.cores}
    for flavour in ["testgenerate_with_params", "testgenerate_without_params"]:
        core_name = f"::generate-{flavour}:0"
        assert core_name in name_to_core
        core = name_to_core[core_name]

        # ttptttg temporary directory should be removed by now
        assert not os.path.isdir(core.core_root)
Example #10
0
def test_export():
    import os
    import tempfile

    from fusesoc.edalizer import Edalizer
    from fusesoc.core import Core

    core = Core(
        os.path.join(os.path.dirname(__file__), "cores", "wb_intercon",
                     "wb_intercon-1.0.core"))

    build_root = tempfile.mkdtemp(prefix="export_")
    export_root = os.path.join(build_root, "exported_files")
    eda_api = Edalizer(
        core.name,
        {
            "tool": "icarus"
        },
        [core],
        cache_root=None,
        work_root=os.path.join(build_root, "work"),
        export_root=export_root,
    ).edalize

    for f in [
            "wb_intercon_1.0/dummy_icarus.v",
            "wb_intercon_1.0/bench/wb_mux_tb.v",
            "wb_intercon_1.0/bench/wb_upsizer_tb.v",
            "wb_intercon_1.0/bench/wb_intercon_tb.v",
            "wb_intercon_1.0/bench/wb_arbiter_tb.v",
            "wb_intercon_1.0/rtl/verilog/wb_data_resize.v",
            "wb_intercon_1.0/rtl/verilog/wb_mux.v",
            "wb_intercon_1.0/rtl/verilog/wb_arbiter.v",
            "wb_intercon_1.0/rtl/verilog/wb_upsizer.v",
    ]:
        assert os.path.isfile(os.path.join(export_root, f))
Example #11
0
def run_backend(
    cm,
    export,
    do_configure,
    do_build,
    do_run,
    flags,
    system_name,
    system,
    backendargs,
    build_root_arg,
):
    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
    build_root = build_root_arg or os.path.join(
        cm.config.build_root, core.name.sanitized_name
    )
    logger.debug("Setting build_root to {}".format(build_root))
    if export:
        export_root = os.path.join(build_root, "src")
    else:
        export_root = None
    try:
        work_root = os.path.join(build_root, 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 not os.path.exists(eda_api_file):
        do_configure = True

    if do_configure:
        try:
            cores = cm.get_depends(core.name, flags)
        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)
        try:
            edalizer = Edalizer(
                core.name,
                flags,
                cores,
                cache_root=cm.config.cache_root,
                work_root=work_root,
                export_root=export_root,
                system_name=system_name,
            )
        except SyntaxError as e:
            logger.error(e.msg)
            exit(1)
        except RuntimeError as e:
            logger.error("Setup failed : {}".format(str(e)))
            exit(1)
        edalizer.to_yaml(eda_api_file)

    # Frontend/backend separation

    try:
        if do_configure:
            edam = edalizer.edalize
        else:
            import yaml

            edam = yaml.safe_load(open(eda_api_file))
        backend = get_edatool(tool)(edam=edam, work_root=work_root)

    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)
Example #12
0
def run_backend(
    cm,
    export,
    do_configure,
    do_build,
    do_run,
    flags,
    system_name,
    system,
    backendargs,
    build_root_arg,
    verbose,
):
    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
    build_root = build_root_arg or os.path.join(cm.config.build_root,
                                                core.name.sanitized_name)
    logger.debug(f"Setting build_root to {build_root}")
    if export:
        export_root = os.path.join(build_root, "src")
    else:
        export_root = None
    try:
        work_root = os.path.join(build_root, 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 not os.path.exists(eda_api_file):
        do_configure = True

    try:
        backend_class = get_edatool(tool)
    except ImportError:
        logger.error(f"Backend {tool!r} not found")
        exit(1)

    edalizer = Edalizer(
        toplevel=core.name,
        flags=flags,
        core_manager=cm,
        cache_root=cm.config.cache_root,
        work_root=work_root,
        export_root=export_root,
        system_name=system_name,
    )

    if do_configure:
        try:
            edalizer.run()
            edam = edalizer.edalize
            parsed_args = edalizer.parse_args(backend_class, backendargs, edam)
            edalizer.add_parsed_args(backend_class, parsed_args)

        except SyntaxError as e:
            logger.error(e.msg)
            exit(1)
        except RuntimeError as e:
            logger.error("Setup failed : {}".format(str(e)))
            exit(1)
        edalizer.to_yaml(eda_api_file)
    else:
        edam = yaml_fread(eda_api_file)
        parsed_args = edalizer.parse_args(backend_class, backendargs, edam)

    # Frontend/backend separation

    try:
        backend = backend_class(edam=edam,
                                work_root=work_root,
                                verbose=verbose)

    except RuntimeError as e:
        logger.error(str(e))
        exit(1)
    except FileNotFoundError as e:
        logger.error(f'Could not find EDA API file "{e.filename}"')
        exit(1)

    if do_configure:
        try:
            backend.configure([])
            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(parsed_args)
        except RuntimeError as e:
            logger.error("Failed to run {} : {}".format(
                str(core.name), str(e)))
            exit(1)
Example #13
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:
            cores = cm.get_depends(core.name, flags)
        except DependencyError as e:
            logger.error(e.msg + "\nFailed to resolve dependencies for {}".format(system))
            exit(1)
        try:
            edalizer = Edalizer(core.name,
                                flags,
                                cores,
                                work_root=work_root,
                                export_root=export_root)
        except SyntaxError as e:
            logger.error(e.msg)
            exit(1)
        except RuntimeError as e:
            logger.error("Setup failed : {}".format(str(e)))
            exit(1)
        edalizer.to_yaml(eda_api_file)

    #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)
Example #14
0
def test_deptree(tmp_path):
    import os

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.edalizer import Edalizer
    from fusesoc.librarymanager import Library
    from fusesoc.vlnv import Vlnv

    flags = {"tool": "icarus"}

    tests_dir = os.path.dirname(__file__)
    deptree_cores_dir = os.path.join(tests_dir, "capi2_cores", "deptree")
    lib = Library("deptree", deptree_cores_dir)

    cm = CoreManager(Config())
    cm.add_library(lib)

    root_core = cm.get_core(Vlnv("::deptree-root"))

    # This is an array of (child, parent) core name tuples and
    # is used for checking that the flattened list of core
    # names is consistent with the dependencies.
    dependencies = (
        # Dependencies of the root core
        ("::deptree-child3:0", "::deptree-root:0"),
        ("::deptree-child2:0", "::deptree-root:0"),
        ("::deptree-child1:0", "::deptree-root:0"),
        ("::deptree-child-a:0", "::deptree-root:0"),
        # Dependencies of child1 core
        ("::deptree-child3:0", "::deptree-child1:0"),
        # Dependencies of child-a core
        ("::deptree-child4:0", "::deptree-child-a:0"),
    )

    # The ordered files that we expect from each core.
    expected_core_files = {
        "::deptree-child3:0": (
            "child3-fs1-f1.sv",
            "child3-fs1-f2.sv",
        ),
        "::deptree-child2:0": (
            "child2-fs1-f1.sv",
            "child2-fs1-f2.sv",
        ),
        "::deptree-child1:0": (
            "child1-fs1-f1.sv",
            "child1-fs1-f2.sv",
        ),
        "::deptree-child4:0": ("child4.sv", ),
        "::deptree-child-a:0": (
            # Files from filesets are always included before any
            # files from generators with "position: append".
            # This is because generated files are often dependent on files
            # that are not generated, and it convenient to be able to
            # include them in the same core.
            "child-a2.sv",
            "generated-child-a.sv",
            "generated-child-a-append.sv",
        ),
        "::deptree-root:0": (
            "root-fs1-f1.sv",
            "root-fs1-f2.sv",
            "root-fs2-f1.sv",
            "root-fs2-f2.sv",
        ),
    }

    # Use Edalizer to get the files.
    # This is necessary because we need to run generators.
    work_root = str(tmp_path / "work")
    os.mkdir(work_root)
    edalizer = Edalizer(
        toplevel=root_core.name,
        flags=flags,
        work_root=work_root,
        core_manager=cm,
    )
    edam = edalizer.run()

    # Check dependency tree (after running all generators)
    deps = cm.get_depends(root_core.name, {})
    deps_names = [str(c) for c in deps]

    all_core_names = set()
    for child, parent in dependencies:
        assert child in deps_names
        assert parent in deps_names
        all_core_names.add(child)
        all_core_names.add(parent)
    # Confirm that we don't have any extra or missing core names.
    assert all_core_names == set(deps_names)
    # Make sure there are no repeats in deps_names
    assert len(all_core_names) == len(deps_names)

    # Now work out what order we expect to get the filenames.
    # The order of filenames within each core in deterministic.
    # Each fileset in order. Followed by each generator in order.
    # The order between the cores is taken the above `dep_names`.
    expected_filenames = []
    # A generator-created core with "position: first"
    expected_filenames.append("generated-child-a-first.sv")
    for dep_name in deps_names:
        expected_filenames += list(expected_core_files[dep_name])
    # A generator-created core with "position: last"
    expected_filenames.append("generated-child-a-last.sv")

    edalized_filenames = [os.path.basename(f["name"]) for f in edam["files"]]

    assert edalized_filenames == expected_filenames