How to use the cocotb.triggers function in cocotb

To help you get started, we’ve selected a few cocotb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cocotb / cocotb / tests / test_cases / test_external / test_external.py View on Github external
@cocotb.test(expect_error=cocotb.triggers.TriggerException if cocotb.SIM_NAME.startswith(("xmsim", "ncsim")) and cocotb.LANGUAGE in ["vhdl"] else False)
async def test_await_after_function(dut):
    """
    Test that awaiting a Trigger works after returning
    from @external functions that call @functions that consume
    simulation time
    """
    clk_gen = cocotb.fork(Clock(dut.clk, 100, units='ns').start())

    value = await external(calls_cocotb_function)(dut)
    assert value == 2

    await Timer(10, units="ns")
    await RisingEdge(dut.clk)
github cocotb / cocotb / tests / test_cases / test_cocotb / test_deprecated.py View on Github external
def get_value():
        yield cocotb.triggers.Timer(1, units='ns')
        raise cocotb.result.ReturnValue(42)
github cocotb / cocotb / tests / test_cases / test_cocotb / test_cocotb_35.py View on Github external
async def example():
        nonlocal ran
        await cocotb.triggers.Timer(1, 'ns')
        ran = True
github cocotb / cocotb / tests / test_cases / test_cocotb / test_concurrency_primitives.py View on Github external
def raise_soon():
        yield Timer(1)
        yield cocotb.triggers.First(raise_inner())
github cocotb / cocotb / tests / test_cases / test_cocotb / test_handle.py View on Github external
def test_bad_attr(dut):
    yield cocotb.triggers.NullTrigger()
    try:
        _ = dut.stream_in_data.whoops
    except AttributeError as e:
        assert 'whoops' in str(e)
    else:
        assert False, "Expected AttributeError"
github cocotb / cocotb / cocotb / triggers.py View on Github external
A single object that could be right of an :keyword:`await` expression in cocotb.
        timeout_time (numbers.Real or decimal.Decimal):
            Simulation time duration before timeout occurs.
        timeout_unit (str or None, optional):
            Units of timeout_time, accepts any units that :class:`~cocotb.triggers.Timer` does.

    Returns:
        First trigger that completed if timeout did not occur.

    Raises:
        :exc:`SimTimeoutError`: If timeout occurs.

    .. versionadded:: 1.3
    """

    timeout_timer = cocotb.triggers.Timer(timeout_time, timeout_unit)
    res = await First(timeout_timer, trigger)
    if res is timeout_timer:
        raise cocotb.result.SimTimeoutError
    else:
        return res
github cocotb / cocotb / cocotb / decorators.py View on Github external
async def f(*args, **kwargs):
                running_co = co(*args, **kwargs)

                try:
                    res = await cocotb.triggers.with_timeout(running_co, self.timeout_time, self.timeout_unit)
                except cocotb.result.SimTimeoutError:
                    running_co.kill()
                    raise
                else:
                    return res
github cocotb / cocotb / cocotb / scheduler.py View on Github external
if isinstance(result, Trigger):
            return result

        if isinstance(result, cocotb.decorators.RunningTask):
            if not result.has_started():
                return self._trigger_from_unstarted_coro(result)
            else:
                return self._trigger_from_started_coro(result)

        if inspect.iscoroutine(result):
            return self._trigger_from_unstarted_coro(cocotb.decorators.RunningTask(result))

        if isinstance(result, list):
            return self._trigger_from_list(result)

        if isinstance(result, cocotb.triggers.Waitable):
            return self._trigger_from_waitable(result)

        if sys.version_info >= (3, 6) and inspect.isasyncgen(result):
            raise TypeError(
                "{} is an async generator, not a coroutine. "
                "You likely used the yield keyword instead of await.".format(
                    result.__qualname__))

        raise TypeError(
            "Coroutine yielded an object of type {}, which the scheduler can't "
            "handle: {!r}\n"
            "Did you forget to decorate with @cocotb.coroutine?"
            .format(type(result), result)
        )
github cocotb / cocotb / cocotb / decorators.py View on Github external
def join(self):
        """Return a trigger that will fire when the wrapped coroutine exits."""
        return cocotb.triggers.Join(self)
github cocotb / cocotb / cocotb / scheduler.py View on Github external
def _trigger_from_list(self, result: list) -> Trigger:
        return self._trigger_from_waitable(cocotb.triggers.First(*result))