Пример #1
0
def init_coremanager(config, args_cores_root):
    logger.debug("Command line arguments: " + str(sys.argv))

    if os.getenv("FUSESOC_CORES"):
        logger.debug("FUSESOC_CORES: " + str(os.getenv("FUSESOC_CORES").split(':')))
    cm = CoreManager(config)

    # Get the environment variable for further cores
    env_cores_root = []
    if os.getenv("FUSESOC_CORES"):
        env_cores_root = os.getenv("FUSESOC_CORES").split(":")
    env_cores_root.reverse()

    core_libraries = [l['location'] for l in config.libraries.values()]
    for cores_root in config.cores_root + \
                       [config.systems_root] + \
                       env_cores_root + \
                       core_libraries + \
                       args_cores_root:
        try:
            cm.add_cores_root(cores_root)
        except (RuntimeError, IOError) as e:
            logger.warning("Failed to register cores root '{}'".format(str(e)))

    return cm
Пример #2
0
def run(args):
    cm = CoreManager()
    config = Config()
    for cores_root in [
            config.cores_root, config.systems_root, args.cores_root
    ]:
        try:
            cm.add_cores_root(cores_root)
        except (RuntimeError, IOError) as e:
            pr_warn("Failed to register cores root '{}'".format(str(e)))
    # Process global options
    if vars(args)['32']:
        config.archbits = 32
        logger.debug("Forcing 32-bit mode")
    elif vars(args)['64']:
        config.archbits = 64
        logger.debug("Forcing 64-bit mode")
    else:
        config.archbits = 64 if platform.architecture()[0] == '64bit' else 32
        logger.debug("Autodetected " + str(config.archbits) + "-bit mode")
    config.monochrome = vars(args)['monochrome']
    if config.monochrome:
        logger.debug("Monochrome output")
    else:
        logger.debug("Colorful output")
    config.verbose = vars(args)['verbose']
    if config.verbose:
        logger.debug("Verbose output")
    else:
        logger.debug("Concise output")
    # Run the function
    args.func(args)
Пример #3
0
def run(args):
    cm = CoreManager()
    config = Config()
    for cores_root in [config.cores_root,
                       config.systems_root,
                       args.cores_root]:
        try:
            cm.add_cores_root(cores_root)
        except (RuntimeError, IOError) as e:
            pr_warn("Failed to register cores root '{}'".format(str(e)))
    # Process global options
    if vars(args)['32']:
        config.archbits = 32
        logger.debug("Forcing 32-bit mode")
    elif vars(args)['64']:
        config.archbits = 64
        logger.debug("Forcing 64-bit mode")
    else:
        config.archbits = 64 if platform.architecture()[0] == '64bit' else 32
        logger.debug("Autodetected " + str(config.archbits) + "-bit mode")
    config.monochrome = vars(args)['monochrome']
    if config.monochrome:
        logger.debug("Monochrome output")
    else:
        logger.debug("Colorful output")
    config.verbose = vars(args)['verbose']
    if config.verbose:
        logger.debug("Verbose output")
    else:
        logger.debug("Concise output")
    # Run the function
    args.func(args)
Пример #4
0
def test_sim(capsys):
    class Args():
        sim = None
        testbench = None
        target = None
        keep = False
        backendargs = None
        setup = True
        build_only = False
        no_export = False

        def __init__(self, system):
            self.system = system

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager

    build_root = os.path.join(tests_dir, 'build')
    config = Config()
    config.build_root = build_root
    config.cache_root = cache_root

    common_cm = CoreManager(config)
    common_cm.add_cores_root(cores_root)
    args = Args(system="wb_common")
    with pytest.raises(SystemExit):
        sim(common_cm, args)
    out, err = capsys.readouterr()
    assert out == ""
    #Workaround since this test fails with Travis on Python2.7. No idea why
    import sys
    if sys.version_info[0] > 2:
        assert err == "No tool was supplied on command line or found in 'wb_common' core description\n"
Пример #5
0
def test_sim(capsys):

    class Args():
        sim = None
        testbench = None
        target = None
        keep = False
        backendargs = None
        setup = True
        build_only = False
        no_export = False
        def __init__(self, system):
            self.system = system

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager

    build_root = os.path.join(tests_dir, 'build')
    config = Config()
    config.build_root = build_root
    config.cache_root = cache_root

    common_cm = CoreManager(config)
    common_cm.add_cores_root(cores_root)
    args = Args(system="wb_common")
    with pytest.raises(SystemExit):
        sim(common_cm, args)
    out, err = capsys.readouterr()
    assert out == ""
    #Workaround since this test fails with Travis on Python2.7. No idea why
    import sys
    if sys.version_info[0] > 2:
        assert err == "No tool was supplied on command line or found in 'wb_common' core description\n"
Пример #6
0
def run(args):
    level = logging.DEBUG if args.verbose else logging.INFO

    setup_logging(level=level, monchrome=args.monochrome)
    logger.debug("Command line arguments: " + str(sys.argv))
    if os.getenv("FUSESOC_CORES"):
        logger.debug("FUSESOC_CORES: " +
                     str(os.getenv("FUSESOC_CORES").split(':')))
    if args.verbose:
        logger.debug("Verbose output")
    else:
        logger.debug("Concise output")

    if args.monochrome:
        logger.debug("Monochrome output")
    else:
        logger.debug("Colorful output")

    if args.config:
        config = Config(file=args.config)
    else:
        config = Config()
    cm = CoreManager(config)

    # Get the environment variable for further cores
    env_cores_root = []
    if os.getenv("FUSESOC_CORES"):
        env_cores_root = os.getenv("FUSESOC_CORES").split(":")
    env_cores_root.reverse()

    for cores_root in [
            config.cores_root, config.systems_root, env_cores_root,
            args.cores_root
    ]:
        try:
            cm.add_cores_root(cores_root)
        except (RuntimeError, IOError) as e:
            logger.warning("Failed to register cores root '{}'".format(str(e)))

    for library in config.libraries.values():
        try:
            cm.add_cores_root(library['location'])
        except (RuntimeError, IOError) as e:
            logger.warning("Failed to register cores root '{}'".format(str(e)))

    # Process global options
    if vars(args)['32']:
        config.archbits = 32
        logger.debug("Forcing 32-bit mode")
    elif vars(args)['64']:
        config.archbits = 64
        logger.debug("Forcing 64-bit mode")
    else:
        config.archbits = 64 if platform.architecture()[0] == '64bit' else 32
        logger.debug("Autodetected " + str(config.archbits) + "-bit mode")
    # Run the function
    args.func(cm, args)
Пример #7
0
def get_core(core):
    from fusesoc.coremanager import CoreManager
    from fusesoc.config import Config
    from fusesoc.main import _get_core

    config = Config()
    config.build_root = build_root
    config.cache_root = cache_root
    cm = CoreManager(config)
    cm.add_cores_root(cores_root)

    return _get_core(cm, core)
Пример #8
0
def main():

    # VUnit steals the command line args so we use an environment variable
    # to determine which core we're picking up
    toplevel = os.getenv("CORE", "")
    if not toplevel:
        sys.stderr.write("Need to provide CORE environment variable")
        sys.exit(1)

    # Create VUnit instance by parsing command line arguments
    vu = VUnit.from_argv()

    #Create singleton instances for core manager and configuration handler
    #Configuration manager is not needed in this example
    cm = CoreManager()

    # Assume we're running in the same directory containing the cores
    cm.add_cores_root(".")

    #Get the sorted list of dependencies starting from the top-level core
    try:
        cores = cm.get_depends(toplevel)
    except DependencyError as e:
        print("'{}' or any of its dependencies requires '{}', but this core was not found".format(top_core, e.value))
        sys.exit(2)

    #Iterate over cores, filesets and files and add all relevant sources files to vunit
    incdirs = set()
    src_files = []

    #'usage' is a list of tags to look for in the filesets.
    # Only look at filesets where any of these tags are present
    usage = ['sim']
    for core_name in cores:
        core = cm.get_core(core_name)
        core.setup()
        basepath = core.files_root
        for fs in core.file_sets:
            if (set(fs.usage) & set(usage)) and ((core_name == toplevel) or not fs.private):
                for file in fs.file:
                    if file.is_include_file:
                        #TODO: incdirs not used right now
                        incdirs.add(os.path.join(basepath, os.path.dirname(file.name)))
                    else:
                        try:
                            vu.library(file.logical_name)
                        except KeyError:
                            vu.add_library(file.logical_name)
                        vu.add_source_file(os.path.join(basepath, file.name), file.logical_name)
    # Run vunit function
    vu.main()
Пример #9
0
def test_eda_api_vpi():
    import os.path
    import tempfile

    from fusesoc.config import Config
    from fusesoc.coremanager import CoreManager
    from fusesoc.vlnv import Vlnv

    tests_dir = os.path.dirname(__file__)
    build_root = tempfile.mkdtemp()
    cache_root = os.path.join(tests_dir, 'cache')
    cores_root = os.path.join(tests_dir, 'capi2_cores')
    work_root = os.path.join(build_root, 'work')
    export_root = os.path.join(build_root, 'src')
    config = Config()
    config.build_root = build_root
    config.cache_root = cache_root
    cm = CoreManager(config)
    cm.add_cores_root(cores_root)
    eda_api = cm.setup(Vlnv("vpi"), {'tool': 'icarus'}, work_root, export_root)
    expected = {
        'files': [],
        'hooks': {},
        'name':
        'vpi_0',
        'parameters': [],
        'tool_options': {
            'icarus': {}
        },
        'toplevel':
        'not_used',
        'version':
        '0.1.2',
        'vpi': [{
            'src_files': ['../src/vpi_0/f1', '../src/vpi_0/f3'],
            'include_dirs': ['../src/vpi_0/'],
            'libs': ['some_lib'],
            'name': 'vpi1'
        }, {
            'src_files': ['../src/vpi_0/f4'],
            'include_dirs': [],
            'libs': [],
            'name': 'vpi2'
        }]
    }
    assert eda_api == expected
Пример #10
0
def run(args):
    cm = CoreManager()
    config = Config()

    # Get the environment variable for further cores
    env_cores_root = []
    if os.getenv("FUSESOC_CORES"):
        env_cores_root = os.getenv("FUSESOC_CORES").split(":")
    env_cores_root.reverse()

    for cores_root in [
            config.cores_root, config.systems_root, env_cores_root,
            args.cores_root
    ]:
        try:
            cm.add_cores_root(cores_root)
        except (RuntimeError, IOError) as e:
            logger.warning("Failed to register cores root '{}'".format(str(e)))
    # Process global options
    if vars(args)['32']:
        config.archbits = 32
        logger.debug("Forcing 32-bit mode")
    elif vars(args)['64']:
        config.archbits = 64
        logger.debug("Forcing 64-bit mode")
    else:
        config.archbits = 64 if platform.architecture()[0] == '64bit' else 32
        logger.debug("Autodetected " + str(config.archbits) + "-bit mode")
    config.monochrome = vars(args)['monochrome']
    if config.monochrome:
        logger.debug("Monochrome output")
    else:
        logger.debug("Colorful output")
    config.verbose = vars(args)['verbose']
    if config.verbose:
        logger.debug("Verbose output")
    else:
        logger.debug("Concise output")
    # Run the function
    args.func(args)
Пример #11
0
import os

tests_dir = os.path.dirname(__file__)
build_root = os.path.join(tests_dir, 'build')
cache_root = os.path.join(tests_dir, 'cache')
cores_root = os.path.join(tests_dir, 'cores')
library_root = os.path.join(tests_dir, 'libraries')

from fusesoc.config import Config
from fusesoc.coremanager import CoreManager

config = Config()
config.build_root = build_root
config.cache_root = cache_root
common_cm = CoreManager(config)
common_cm.add_cores_root(cores_root)


def compare_files(ref_dir, work_root, files):
    import difflib

    for f in files:
        reference_file = os.path.join(ref_dir, f)
        generated_file = os.path.join(work_root, f)

        assert os.path.exists(generated_file)

        with open(reference_file) as fref, open(generated_file) as fgen:
            assert fref.read() == fgen.read(), f

Пример #12
0
# Create VUnit instance by parsing command line arguments
vu = VUnit.from_args(args=args)

top_core = args.core[0]

#Create singleton instances for core manager and configuration handler
#Configuration manager is not needed in this example
cm = CoreManager()
#config = Config()

#Add core libraries that were picked up from fusesoc.conf by the config handler
#Not really necessary for this example as we can just add 'corelib' manually
try:
    #cm.add_cores_root(config.cores_root)
    cm.add_cores_root('corelib')
except (RuntimeError, IOError) as e:
    pr_warn("Failed to register cores root '{}'".format(str(e)))

#Get the sorted list of dependencies starting from the top-level core
try:
    cores = cm.get_depends(top_core)
except DependencyError as e:
    print("'{}' or any of its dependencies requires '{}', but this core was not found".format(top_core, e.value))
    exit(1)
#Hack 2. Disable for now. Should probably be hooked up to vunit_simulator
#CoreManager().tool = sim_name

#Iterate over cores, filesets and files and add all relevant sources files to vunit
incdirs = set()
src_files = []
Пример #13
0
# Create VUnit instance by parsing command line arguments
vu = VUnit.from_args(args=args)

top_core = args.core[0]

#Create singleton instances for core manager and configuration handler
#Configuration manager is not needed in this example
cm = CoreManager()
#config = Config()

#Add core libraries that were picked up from fusesoc.conf by the config handler
#Not really necessary for this example as we can just add 'corelib' manually
try:
    #cm.add_cores_root(config.cores_root)
    cm.add_cores_root('corelib')
except (RuntimeError, IOError) as e:
    pr_warn("Failed to register cores root '{}'".format(str(e)))

#Get the sorted list of dependencies starting from the top-level core
try:
    cores = cm.get_depends(top_core)
except DependencyError as e:
    print(
        "'{}' or any of its dependencies requires '{}', but this core was not found"
        .format(top_core, e.value))
    exit(1)
#Hack 2. Disable for now. Should probably be hooked up to vunit_simulator
#CoreManager().tool = sim_name

#Iterate over cores, filesets and files and add all relevant sources files to vunit