How to use the cocotb.result.TestFailure 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_multi_dimension_array / test_cocotb_array.py View on Github external
def test_in_vect_unpacked(dut):
    yield Timer(10)
    print("Setting: dut.in_vect_unpacked type %s" % type(dut.in_vect_unpacked))
    dut.in_vect_unpacked = [0x1, 0x0, 0x1]
    yield Timer(10)
    print("Getting: dut.out_vect_unpacked type %s" % type(dut.out_vect_unpacked))
    if dut.out_vect_unpacked != [0x1, 0x0, 0x1]:
        raise TestFailure("Failed to readback dut.out_vect_unpacked")
github cocotb / cocotb / tests / test_cases / test_discovery / test_discovery.py View on Github external
def access_integer(dut):
    """Integer should show as an IntegerObject"""
    bitfail = False
    tlog = logging.getLogger("cocotb.test")
    yield Timer(10)
    test_int = dut.stream_in_int
    if not isinstance(test_int, IntegerObject):
        raise TestFailure("dut.stream_in_int is not an integer but {} instead".format(type(test_int)))

    try:
        bit = test_int[3]
    except IndexError as e:
        tlog.info("Access to bit is an error as expected")
        bitfail = True

    if not bitfail:
        raise TestFailure("Access into an integer should be invalid")

    length = len(test_int)
    if length != 1:
        raise TestFailure("Length should be 1 not %d" % length)
github cocotb / cocotb / tests / test_cases / test_cocotb / test_edge_triggers.py View on Github external
def test_edge_count(dut):
    """Count the number of edges is as expected"""
    global edges_seen
    edges_seen = 0
    clk_period = 100
    edge_count = 10
    clock = cocotb.fork(do_clock(dut, edge_count, clk_period))
    test = cocotb.fork(do_edge_count(dut, dut.clk))

    yield Timer(clk_period * (edge_count + 1))

    if edge_count is not edges_seen:
        raise TestFailure("Correct edge count failed - saw %d wanted %d" %
                          (edges_seen, edge_count))
github cocotb / cocotb / tests / test_cases / test_cocotb / test_generator_coroutines.py View on Github external
def test_function_not_decorated_fork(dut):
    """Example of trying to fork a coroutine that isn't a coroutine"""
    yield Timer(500)
    try:
        cocotb.fork(normal_function(dut))
    except TypeError as exc:
        assert "isn't a coroutine" in str(exc)
    else:
        raise TestFailure()

    yield Timer(500)
github cocotb / cocotb / tests / test_cases / test_multi_dimension_array / test_cocotb_array.py View on Github external
def test_in_vect_packed(dut):
    yield Timer(10)
    print("Setting: dut.in_vect_packed type %s" % type(dut.in_vect_packed))
    dut.in_vect_packed = 0x5
    yield Timer(10)
    print("Getting: dut.out_vect_packed type %s" % type(dut.out_vect_packed))
    if dut.out_vect_packed != 0x5:
        raise TestFailure("Failed to readback dut.out_vect_packed")
github cocotb / cocotb / tests / test_cases / test_cocotb / test_generator_coroutines.py View on Github external
def test_function_not_a_coroutine(dut):
    """Example of trying to yield a coroutine that isn't a coroutine"""
    yield Timer(500)
    try:
        # failure should occur before we even try to yield or fork the coroutine
        coro = function_not_a_coroutine()
    except TypeError as exc:
        assert "isn't a valid coroutine" in str(exc)
    else:
        raise TestFailure
github cocotb / cocotb / tests / test_cases / issue_253 / issue_253.py View on Github external
def toggle_clock(dut):
    dut.clk = 0
    yield Timer(10)
    if dut.clk.value.integer != 0:
        raise TestFailure("Clock not set to 0 as expected")
    dut.clk = 1
    yield Timer(10)
    if dut.clk.value.integer != 1:
        raise TestFailure("Clock not set to 1 as expected")
github cocotb / cocotb / tests / test_cases / test_array / test_array.py View on Github external
def _check_type(tlog, hdl, expected):
    if not isinstance(hdl, expected):
        raise TestFailure(">{0!r} ({1})< should be >{2}<".format(hdl, hdl._type, expected))
    else:
        tlog.info("   Found %r (%s) with length=%d", hdl, hdl._type, len(hdl))
github optimsoc / optimsoc / test / cocotb / osdtestlib / debug_interconnect.py View on Github external
default_value = yield self.read_register(dest, src, 16,
                                                 DiPacket.BASE_REG.MOD_CS.value)

        yield self.write_register(dest, src, 16, DiPacket.BASE_REG.MOD_CS.value,
                                  1)

        after_write = yield self.read_register(dest, src, 16,
                                               DiPacket.BASE_REG.MOD_CS.value)

        if can_stall:
            if after_write != 1:
                raise TestFailure("Expected MOD_CS_ACTIVE of module %u to be "
                                  "1, but got 0x%x." % (dest, after_write))
        else:
            if after_write != default_value:
                raise TestFailure("Module %u cannot be stalled, but writing "
                                  "MOD_CS_ACTIVE still had an effect." % dest)

        # Check MOD_EVENT_DEST (write and read back)
        event_dest = random.randint(0, 0xFF)
        yield self.write_register(dest, src, 16,
                                  DiPacket.BASE_REG.MOD_EVENT_DEST.value,
                                  event_dest)
        yield self.assert_reg_value(dest, src, DiPacket.BASE_REG.MOD_EVENT_DEST.value,
                                    16,
                                    event_dest)
github cocotb / cocotb / cocotb / __init__.py View on Github external
def _sim_event(level, message):
    """Function that can be called externally to signal an event."""
    # SIM_INFO = 0
    SIM_TEST_FAIL = 1
    SIM_FAIL = 2
    from cocotb.result import TestFailure, SimFailure

    if level is SIM_TEST_FAIL:
        scheduler.log.error("Failing test at simulator request")
        scheduler.finish_test(TestFailure("Failure from external source: %s" %
                              message))
    elif level is SIM_FAIL:
        # We simply return here as the simulator will exit
        # so no cleanup is needed
        msg = ("Failing test at simulator request before test run completion: "
               "%s" % message)
        scheduler.log.error(msg)
        scheduler.finish_scheduler(SimFailure(msg))
    else:
        scheduler.log.error("Unsupported sim event")

    return True