Ejemplo n.º 1
0
def test_exceptions_forked(dut):
    """ Test exception propagation via cocotb.fork """
    @cocotb.coroutine
    def raise_inner():
        yield Timer(10)
        raise ValueError('It is soon now')

    @cocotb.coroutine
    def raise_soon():
        yield Timer(1)
        coro = cocotb.fork(raise_inner())
        yield coro.join()

    # it's ok to change this value if the traceback changes - just make sure
    # that when changed, it doesn't become harder to read.
    expected = textwrap.dedent(r"""
    Traceback \(most recent call last\):
      File ".*common\.py", line \d+, in _check_traceback
        yield running_coro
      File ".*test_generator_coroutines\.py", line \d+, in raise_soon
        yield coro\.join\(\)
      File ".*test_generator_coroutines\.py", line \d+, in raise_inner
        raise ValueError\('It is soon now'\)
    ValueError: It is soon now""").strip()

    yield _check_traceback(raise_soon(), ValueError, expected)
Ejemplo n.º 2
0
def test_exceptions_first(dut):
    """ Test exception propagation via cocotb.triggers.First """
    @cocotb.coroutine
    def raise_inner():
        yield Timer(10)
        raise ValueError('It is soon now')

    @cocotb.coroutine
    def raise_soon():
        yield Timer(1)
        yield cocotb.triggers.First(raise_inner())

    # it's ok to change this value if the traceback changes - just make sure
    # that when changed, it doesn't become harder to read.
    expected = textwrap.dedent(r"""
    Traceback \(most recent call last\):
      File ".*common\.py", line \d+, in _check_traceback
        yield running_coro
      File ".*test_concurrency_primitives\.py", line \d+, in raise_soon
        yield cocotb\.triggers\.First\(raise_inner\(\)\)
      File ".*triggers\.py", line \d+, in _wait
        return await first_trigger[^\n]*
      File ".*triggers.py", line \d+, in __await__
        return \(yield self\)
      File ".*triggers.py", line \d+, in __await__
        return \(yield self\)
      File ".*test_concurrency_primitives\.py", line \d+, in raise_inner
        raise ValueError\('It is soon now'\)
    ValueError: It is soon now""").strip()

    yield _check_traceback(raise_soon(), ValueError, expected)
Ejemplo n.º 3
0
def test_exceptions_direct(dut):
    """ Test exception propagation via a direct yield statement """
    @cocotb.coroutine
    def raise_inner():
        yield Timer(10)
        raise ValueError('It is soon now')

    @cocotb.coroutine
    def raise_soon():
        yield Timer(1)
        yield raise_inner()

    # it's ok to change this value if the traceback changes - just make sure
    # that when changed, it doesn't become harder to read.
    expected = textwrap.dedent(r"""
    Traceback \(most recent call last\):
      File ".*common\.py", line \d+, in _check_traceback
        await running_coro
      File ".*cocotb[\\\/]decorators.py", line \d+, in __await__
        return \(yield self\)
      File ".*test_generator_coroutines\.py", line \d+, in raise_soon
        yield raise_inner\(\)
      File ".*test_generator_coroutines\.py", line \d+, in raise_inner
        raise ValueError\('It is soon now'\)
    ValueError: It is soon now""").strip()

    yield _check_traceback(raise_soon(), ValueError, expected)
def test_exceptions_direct(dut):
    """Test exception propagation via a direct yield statement"""
    @cocotb.coroutine
    def raise_inner():
        yield Timer(10)
        raise ValueError("It is soon now")

    @cocotb.coroutine
    def raise_soon():
        yield Timer(1)
        yield raise_inner()

    yield _check_traceback(raise_soon(), ValueError,
                           r".*in raise_soon.*in raise_inner", re.DOTALL)
def test_exceptions_forked(dut):
    """Test exception propagation via cocotb.fork"""
    @cocotb.coroutine
    def raise_inner():
        yield Timer(10)
        raise ValueError("It is soon now")

    @cocotb.coroutine
    def raise_soon():
        yield Timer(1)
        coro = cocotb.start_soon(raise_inner())
        yield coro.join()

    yield _check_traceback(raise_soon(), ValueError,
                           r".*in raise_soon.*in raise_inner", re.DOTALL)