How to use the cocotb.outcomes.Error 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_cocotb / test_cocotb_35.py View on Github external
async def test_coro_from_async(dut):
    """ Test that async coroutines are able to call regular ones """
    v = await produce.coro(Value(1))
    assert v == 1

    try:
        await produce.coro(Error(SomeException))
    except SomeException:
        pass
    else:
        assert False
github cocotb / cocotb / cocotb / scheduler.py View on Github external
# this can't go in the else above, as that causes unwanted exception
        # chaining
        if coro_completed:
            self.unschedule(coroutine)

        # Don't handle the result if we're shutting down
        if self._terminate:
            return

        if not coro_completed:
            try:
                result = self._trigger_from_any(result)
            except TypeError as exc:
                # restart this coroutine with an exception object telling it that
                # it wasn't allowed to yield that
                result = NullTrigger(outcome=outcomes.Error(exc))

            self._resume_coro_upon(coroutine, result)

        # We do not return from here until pending threads have completed, but only
        # from the main thread, this seems like it could be problematic in cases
        # where a sim might change what this thread is.

        if self._main_thread is threading.current_thread():

            for ext in self._pending_threads:
                ext.thread_start()
                if _debug:
                    self.log.debug("Blocking from %s on %s" % (threading.current_thread(), ext.thread))
                state = ext.thread_wait()
                if _debug:
                    self.log.debug("Back from wait on self %s with newstate %d" % (threading.current_thread(), state))
github cocotb / cocotb / cocotb / regression.py View on Github external
def tear_down(self) -> None:
        # prevent re-entering the tear down procedure
        if not self._tearing_down:
            self._tearing_down = True
        else:
            return

        # fail remaining tests
        while True:
            test = self.next_test()
            if test is None:
                break
            self._record_result(
                test=test,
                outcome=Error(SimFailure),
                wall_time_s=0,
                sim_time_ns=0)

        # Write out final log messages
        self._log_test_summary()
        self._log_sim_summary()
        self.log.info("Shutting down...")

        # Generate output reports
        self.xunit.write()
        if self._cov:
            self._cov.stop()
            self.log.info("Writing coverage data")
            self._cov.save()
            self._cov.html_report()
        if cocotb._library_coverage is not None:
github cocotb / cocotb / cocotb / outcomes.py View on Github external
def capture(fn, *args, **kwargs):
    """ Obtain an `Outcome` representing the result of a function call """
    try:
        return Value(fn(*args, **kwargs))
    except BaseException as e:
        e = remove_traceback_frames(e, ['capture'])
        return Error(e)
github cocotb / cocotb / cocotb / scheduler.py View on Github external
if trigger_coros != [coro]:
                # should never happen
                raise InternalError(
                    "More than one coroutine waiting on an unprimed trigger")

            try:
                trigger.prime(self.react)
            except Exception as e:
                # discard the trigger we associated, it will never fire
                self._trigger2coros.pop(trigger)

                # replace it with a new trigger that throws back the exception
                self._resume_coro_upon(
                    coro,
                    NullTrigger(name="Trigger.prime() Error", outcome=outcomes.Error(e))
                )
github cocotb / cocotb / cocotb / scheduler.py View on Github external
async def wrapper():
            # This function runs in the scheduler thread
            try:
                _outcome = outcomes.Value(await coro)
            except BaseException as e:
                _outcome = outcomes.Error(e)
            event.outcome = _outcome
            # Notify the current (scheduler) thread that we are about to wake
            # up the background (`@external`) thread, making sure to do so
            # before the background thread gets a chance to go back to sleep by
            # calling thread_suspend.
            # We need to do this here in the scheduler thread so that no more
            # coroutines run until the background thread goes back to sleep.
            t.thread_resume()
            event.set()