Exemple #1
0
def _initialise_testbench(root_handle):
    """
    This function is called after the simulator has elaborated all
    entities and is ready to run the test.

    The test must be defined by the environment variables
        MODULE
        TESTCASE
    """
    _rlock.acquire()

    memcheck_port = os.getenv('MEMCHECK')
    if memcheck_port is not None:
        mem_debug(int(memcheck_port))

    # Seed the Python random number generator to make this repeatable
    seed = os.getenv('RANDOM_SEED')
    if seed is None:
        seed = int(time.time())
        log.info("Seeding Python random module with %d" % (seed))
    else:
        seed = int(seed)
        log.info("Seeding Python random module with supplied seed %d" % (seed))
    random.seed(seed)

    exec_path = os.getenv('SIM_ROOT')
    if exec_path is None:
        exec_path = 'Unknown'

    version = os.getenv('VERSION')
    if version is None:
        log.info("Unable to determine Cocotb version from %s" % exec_path)
    else:
        log.info("Running tests with Cocotb v%s from %s" % (version, exec_path))

    # Create the base handle type
    dut = cocotb.handle.SimHandle(root_handle)

    process_plusargs()

    module_str = os.getenv('MODULE')
    test_str = os.getenv('TESTCASE')

    if not module_str:
        raise ImportError("Environment variables defining the module(s) to \
                        execute not defined.  MODULE=\"%s\"\"" % (module_str))

    modules = module_str.split(',')

    global regression

    regression = RegressionManager(dut, modules, tests=test_str)
    regression.initialise()
    regression.execute()

    _rlock.release()
    return True
Exemple #2
0
def _initialise_testbench(root_name):
    """Initialize testbench.

    This function is called after the simulator has elaborated all
    entities and is ready to run the test.

    The test must be defined by the environment variables
    :envvar:`MODULE` and :envvar:`TESTCASE`.

    The environment variable :envvar:`COCOTB_HOOKS`, if present, contains a
    comma-separated list of modules to be executed before the first test.
    """
    _rlock.acquire()

    memcheck_port = os.getenv('MEMCHECK')
    if memcheck_port is not None:
        mem_debug(int(memcheck_port))

    log.info("Running tests with cocotb v%s from %s" %
             (__version__, os.path.dirname(__file__)))

    # Create the base handle type

    process_plusargs()

    # Seed the Python random number generator to make this repeatable
    global RANDOM_SEED
    RANDOM_SEED = os.getenv('RANDOM_SEED')

    if RANDOM_SEED is None:
        if 'ntb_random_seed' in plusargs:
            RANDOM_SEED = eval(plusargs['ntb_random_seed'])
        elif 'seed' in plusargs:
            RANDOM_SEED = eval(plusargs['seed'])
        else:
            RANDOM_SEED = int(time.time())
        log.info("Seeding Python random module with %d" % (RANDOM_SEED))
    else:
        RANDOM_SEED = int(RANDOM_SEED)
        log.info("Seeding Python random module with supplied seed %d" %
                 (RANDOM_SEED))
    random.seed(RANDOM_SEED)

    # Setup DUT object
    from cocotb import simulator

    handle = simulator.get_root_handle(root_name)
    if not handle:
        raise RuntimeError("Can not find root handle ({})".format(root_name))

    dut = cocotb.handle.SimHandle(handle)

    # start Regression Manager
    global regression_manager
    regression_manager = RegressionManager.from_discovery(dut)
    regression_manager.execute()

    _rlock.release()
    return True
Exemple #3
0
def _initialise_testbench(root_name):
    """
    This function is called after the simulator has elaborated all
    entities and is ready to run the test.

    The test must be defined by the environment variables
        MODULE
        TESTCASE
    """
    _rlock.acquire()

    memcheck_port = os.getenv('MEMCHECK')
    if memcheck_port is not None:
        mem_debug(int(memcheck_port))

    # Seed the Python random number generator to make this repeatable
    seed = os.getenv('RANDOM_SEED')
    if seed is None:
        seed = int(time.time())
        log.info("Seeding Python random module with %d" % (seed))
    else:
        seed = int(seed)
        log.info("Seeding Python random module with supplied seed %d" % (seed))
    random.seed(seed)

    exec_path = os.getenv('SIM_ROOT')
    if exec_path is None:
        exec_path = 'Unknown'

    version = os.getenv('VERSION')
    if version is None:
        log.info("Unable to determine Cocotb version from %s" % exec_path)
    else:
        log.info("Running tests with Cocotb v%s from %s" % (version, exec_path))

    # Create the base handle type

    process_plusargs()

    module_str = os.getenv('MODULE')
    test_str = os.getenv('TESTCASE')

    if not module_str:
        raise ImportError("Environment variables defining the module(s) to \
                        execute not defined.  MODULE=\"%s\"\"" % (module_str))

    modules = module_str.split(',')

    global regression

    regression = RegressionManager(root_name, modules, tests=test_str)
    regression.initialise()
    regression.execute()

    _rlock.release()
    return True
Exemple #4
0
def _initialise_testbench_(argv_):
    # The body of this function is split in two because no coverage is collected on
    # the function that starts the coverage. By splitting it in two we get coverage
    # on most of the function.

    global argc, argv
    argv = argv_
    argc = len(argv)

    root_name = os.getenv("TOPLEVEL")
    if root_name is not None:
        if root_name == "":
            root_name = None
        elif '.' in root_name:
            # Skip any library component of the toplevel
            root_name = root_name.split(".", 1)[1]

    # sys.path normally includes "" (the current directory), but does not appear to when python is embedded.
    # Add it back because users expect to be able to import files in their test directory.
    # TODO: move this to gpi_embed.cpp
    sys.path.insert(0, "")

    _setup_logging()

    # From https://www.python.org/dev/peps/pep-0565/#recommended-filter-settings-for-test-runners
    # If the user doesn't want to see these, they can always change the global
    # warning settings in their test module.
    if not sys.warnoptions:
        warnings.simplefilter("default")

    from cocotb import simulator

    global SIM_NAME, SIM_VERSION
    SIM_NAME = simulator.get_simulator_product().strip()
    SIM_VERSION = simulator.get_simulator_version().strip()

    cocotb.log.info("Running on {} version {}".format(SIM_NAME, SIM_VERSION))

    memcheck_port = os.getenv('MEMCHECK')
    if memcheck_port is not None:
        mem_debug(int(memcheck_port))

    log.info("Running tests with cocotb v%s from %s" %
             (__version__, os.path.dirname(__file__)))

    # Create the base handle type

    process_plusargs()

    global scheduler
    scheduler = Scheduler()

    # Seed the Python random number generator to make this repeatable
    global RANDOM_SEED
    RANDOM_SEED = os.getenv('RANDOM_SEED')

    if RANDOM_SEED is None:
        if 'ntb_random_seed' in plusargs:
            RANDOM_SEED = eval(plusargs['ntb_random_seed'])
        elif 'seed' in plusargs:
            RANDOM_SEED = eval(plusargs['seed'])
        else:
            RANDOM_SEED = int(time.time())
        log.info("Seeding Python random module with %d" % (RANDOM_SEED))
    else:
        RANDOM_SEED = int(RANDOM_SEED)
        log.info("Seeding Python random module with supplied seed %d" % (RANDOM_SEED))
    random.seed(RANDOM_SEED)

    # Setup DUT object
    from cocotb import simulator

    handle = simulator.get_root_handle(root_name)
    if not handle:
        raise RuntimeError("Can not find root handle ({})".format(root_name))

    global top
    top = cocotb.handle.SimHandle(handle)

    try:
        import pytest
    except ImportError:
        log.warning("Pytest not found, assertion rewriting will not occur")
    else:
        try:
            # Install the assertion rewriting hook, which must be done before we
            # import the test modules.
            from _pytest.config import Config
            from _pytest.assertion import install_importhook
            pytest_conf = Config.fromdictargs([], {})
            install_importhook(pytest_conf)
        except Exception:
            log.exception(
                "Configuring the assertion rewrite hook using pytest {} failed. "
                "Please file a bug report!".format(pytest.__version__))

    # start Regression Manager
    global regression_manager
    regression_manager = RegressionManager.from_discovery(top)
    regression_manager.execute()

    return True
def _initialise_testbench(root_name):
    """
    This function is called after the simulator has elaborated all
    entities and is ready to run the test.

    The test must be defined by the environment variables
        MODULE
        TESTCASE

    The environment variable COCOTB_HOOKS contains a comma-separated list of
        modules that should be executed before the first test.
    """
    _rlock.acquire()

    memcheck_port = os.getenv('MEMCHECK')
    if memcheck_port is not None:
        mem_debug(int(memcheck_port))

    exec_path = os.getenv('COCOTB_PY_DIR')
    if exec_path is None:
        exec_path = 'Unknown'

    version = os.getenv('VERSION')
    if version is None:
        log.info("Unable to determine Cocotb version from %s" % exec_path)
    else:
        log.info("Running tests with Cocotb v%s from %s" %
                 (version, exec_path))

    # Create the base handle type

    process_plusargs()

    # Seed the Python random number generator to make this repeatable
    seed = os.getenv('RANDOM_SEED')

    if seed is None:
        if 'ntb_random_seed' in plusargs:
            seed = eval(plusargs['ntb_random_seed'])
        elif 'seed' in plusargs:
            seed = eval(plusargs['seed'])
        else:
            seed = int(time.time())
        log.info("Seeding Python random module with %d" % (seed))
    else:
        seed = int(seed)
        log.info("Seeding Python random module with supplied seed %d" % (seed))
    random.seed(seed)

    module_str = os.getenv('MODULE')
    test_str = os.getenv('TESTCASE')
    hooks_str = os.getenv('COCOTB_HOOKS', '')

    if not module_str:
        raise ImportError("Environment variables defining the module(s) to " +
                          "execute not defined.  MODULE=\"%s\"" % (module_str))

    modules = module_str.split(',')
    hooks = hooks_str.split(',') if hooks_str else []

    global regression_manager

    regression_manager = RegressionManager(root_name, modules, tests=test_str, seed=seed, hooks=hooks)
    regression_manager.initialise()
    regression_manager.execute()

    _rlock.release()
    return True
Exemple #6
0
def _initialise_testbench(argv_):
    """Initialize testbench.

    This function is called after the simulator has elaborated all
    entities and is ready to run the test.

    The test must be defined by the environment variables
    :envvar:`MODULE` and :envvar:`TESTCASE`.

    The environment variable :envvar:`COCOTB_HOOKS`, if present, contains a
    comma-separated list of modules to be executed before the first test.
    """
    _rlock.acquire()

    if "COCOTB_LIBRARY_COVERAGE" in os.environ:
        import coverage

        global _library_coverage
        _library_coverage = coverage.coverage(
            data_file=".coverage.cocotb",
            branch=True,
            include=["{}/*".format(os.path.dirname(__file__))])
        _library_coverage.start()

    global argc, argv
    argv = argv_
    argc = len(argv)

    root_name = os.getenv("TOPLEVEL")
    if root_name is not None:
        if root_name == "":
            root_name = None
        elif '.' in root_name:
            # Skip any library component of the toplevel
            root_name = root_name.split(".", 1)[1]

    # sys.path normally includes "" (the current directory), but does not appear to when python is embedded.
    # Add it back because users expect to be able to import files in their test directory.
    # TODO: move this to gpi_embed.cpp
    sys.path.insert(0, "")

    _setup_logging()

    # From https://www.python.org/dev/peps/pep-0565/#recommended-filter-settings-for-test-runners
    # If the user doesn't want to see these, they can always change the global
    # warning settings in their test module.
    if not sys.warnoptions:
        warnings.simplefilter("default")

    from cocotb import simulator

    global SIM_NAME, SIM_VERSION
    SIM_NAME = simulator.get_simulator_product().strip()
    SIM_VERSION = simulator.get_simulator_version().strip()

    cocotb.log.info("Running on {} version {}".format(SIM_NAME, SIM_VERSION))

    memcheck_port = os.getenv('MEMCHECK')
    if memcheck_port is not None:
        mem_debug(int(memcheck_port))

    log.info("Running tests with cocotb v%s from %s" %
             (__version__, os.path.dirname(__file__)))

    # Create the base handle type

    process_plusargs()

    global scheduler
    scheduler = Scheduler()

    # Seed the Python random number generator to make this repeatable
    global RANDOM_SEED
    RANDOM_SEED = os.getenv('RANDOM_SEED')

    if RANDOM_SEED is None:
        if 'ntb_random_seed' in plusargs:
            RANDOM_SEED = eval(plusargs['ntb_random_seed'])
        elif 'seed' in plusargs:
            RANDOM_SEED = eval(plusargs['seed'])
        else:
            RANDOM_SEED = int(time.time())
        log.info("Seeding Python random module with %d" % (RANDOM_SEED))
    else:
        RANDOM_SEED = int(RANDOM_SEED)
        log.info("Seeding Python random module with supplied seed %d" %
                 (RANDOM_SEED))
    random.seed(RANDOM_SEED)

    # Setup DUT object
    from cocotb import simulator

    handle = simulator.get_root_handle(root_name)
    if not handle:
        raise RuntimeError("Can not find root handle ({})".format(root_name))

    dut = cocotb.handle.SimHandle(handle)

    # start Regression Manager
    global regression_manager
    regression_manager = RegressionManager.from_discovery(dut)
    regression_manager.execute()

    _rlock.release()
    return True
Exemple #7
0
def _initialise_testbench(root_name):
    """Initialize testbench.

    This function is called after the simulator has elaborated all
    entities and is ready to run the test.

    The test must be defined by the environment variables
    :envvar:`MODULE` and :envvar:`TESTCASE`.

    The environment variable :envvar:`COCOTB_HOOKS`, if present, contains a
    comma-separated list of modules to be executed before the first test.
    """
    _rlock.acquire()

    memcheck_port = os.getenv('MEMCHECK')
    if memcheck_port is not None:
        mem_debug(int(memcheck_port))

    log.info("Running tests with cocotb v%s from %s" %
             (__version__, os.path.dirname(__file__)))

    # Create the base handle type

    process_plusargs()

    # Seed the Python random number generator to make this repeatable
    global RANDOM_SEED
    RANDOM_SEED = os.getenv('RANDOM_SEED')

    if RANDOM_SEED is None:
        if 'ntb_random_seed' in plusargs:
            RANDOM_SEED = eval(plusargs['ntb_random_seed'])
        elif 'seed' in plusargs:
            RANDOM_SEED = eval(plusargs['seed'])
        else:
            RANDOM_SEED = int(time.time())
        log.info("Seeding Python random module with %d" % (RANDOM_SEED))
    else:
        RANDOM_SEED = int(RANDOM_SEED)
        log.info("Seeding Python random module with supplied seed %d" %
                 (RANDOM_SEED))
    random.seed(RANDOM_SEED)

    module_str = os.getenv('MODULE')
    test_str = os.getenv('TESTCASE')
    hooks_str = os.getenv('COCOTB_HOOKS', '')

    if not module_str:
        raise ImportError("Environment variables defining the module(s) to " +
                          "execute not defined.  MODULE=\"%s\"" % (module_str))

    modules = module_str.split(',')
    hooks = hooks_str.split(',') if hooks_str else []

    global regression_manager

    regression_manager = RegressionManager(root_name,
                                           modules,
                                           tests=test_str,
                                           seed=RANDOM_SEED,
                                           hooks=hooks)
    regression_manager.initialise()
    regression_manager.execute()

    _rlock.release()
    return True