How to use the cocotb.triggers.Timer 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_handle.py View on Github external
async def test_string_handle_takes_bytes(dut):
    dut.stream_in_string.value = b"bytes"
    await cocotb.triggers.Timer(10, 'ns')
    val = dut.stream_in_string.value
    assert isinstance(val, bytes)
    assert val == b"bytes"
github cocotb / cocotb / tests / test_cases / test_closedown / test_closedown.py View on Github external
async def test_after_system_task_fail(dut):
    """
    Test to run after failed test.
    """
    await Timer(1, units='ns')
github cocotb / cocotb / tests / test_cases / test_multi_dimension_array / test_cocotb_array.py View on Github external
def test_in_2d_arr_unpacked(dut):
    yield Timer(10)
    print("Setting: dut.in_2d_arr_unpacked type %s" % type(dut.in_2d_arr_unpacked))
    dut.in_2d_arr_unpacked = [365, 365, 365]
    yield Timer(10)
    print("Getting: dut.out_2d_arr_unpacked type %s" % type(dut.out_2d_arr_unpacked))
    if dut.out_2d_arr_unpacked != [365, 365, 365]:
        raise TestFailure("Failed to readback dut.out_2d_arr_unpacked")
github cocotb / cocotb / tests / test_cases / test_cocotb / test_scheduler.py View on Github external
def test_kill_twice(dut):
    """
    Test that killing a coroutine that has already been killed does not crash
    """
    clk_gen = cocotb.fork(Clock(dut.clk, 100).start())
    yield Timer(1)
    clk_gen.kill()
    yield Timer(1)
    clk_gen.kill()
github cocotb / cocotb / tests / test_cases / test_cocotb / test_cocotb_35.py View on Github external
async def test_trigger_await_gives_self(dut):
    """ Test that await returns the trigger itself for triggers """
    t = Timer(1)
    t2 = await t
    assert t2 is t
github cocotb / cocotb / tests / test_cases / test_cocotb / test_scheduler.py View on Github external
def test_coroutine_kill(dut):
    """Test that killing a coroutine causes pending routine continue"""
    global test_flag
    clk_gen = cocotb.scheduler.add(clock_gen(dut.clk))
    yield Timer(100)
    clk_gen_two = cocotb.fork(clock_yield(clk_gen))
    yield Timer(100)
    clk_gen.kill()
    if test_flag is not False:
        raise TestFailure
    yield Timer(1000)
    if test_flag is not True:
        raise TestFailure
github cocotb / cocotb / tests / test_cases / test_cocotb / test_timing_triggers.py View on Github external
try:
        # Yield for 2.5 timesteps, should throw exception
        yield Timer(2.5*time_step, units='fs')
        raise TestFailure("Timers should throw exception if time cannot be achieved with simulator resolution")
    except ValueError:
        dut._log.info("As expected, unable to create a timer of 2.5 simulator time steps")

    time_fs = get_sim_time(units='fs')

    yield Timer(3, "ns")

    if get_sim_time(units='fs') != time_fs+3000000.0:
        raise TestFailure("Expected a delay of 3 ns")

    time_fs = get_sim_time(units='fs')
    yield Timer(1.5, "ns")

    if get_sim_time(units='fs') != time_fs+1500000.0:
        raise TestFailure("Expected a delay of 1.5 ns")

    time_fs = get_sim_time(units='fs')
    yield Timer(10.0, "ps")

    if get_sim_time(units='fs') != time_fs+10000.0:
        raise TestFailure("Expected a delay of 10 ps")

    time_fs = get_sim_time(units='fs')
    yield Timer(1.0, "us")

    if get_sim_time(units='fs') != time_fs+1000000000.0:
        raise TestFailure("Expected a delay of 1 us")
github cocotb / cocotb / examples / demo / demo.py View on Github external
dut.log.info(str(clk))

    cgen = cocotb.scheduler.add(clock_generator(clk))
    yield reset_dut(clk, reset, enable)
    dut.log.info("Reset DUT complete, continuing test...")
    cmon = cocotb.scheduler.add(clock_monitor(clk, count))

    dut.log.info("Blocking test until the clock generator finishes...")
    yield cgen.join()

    sync = Event()
    cocotb.scheduler.add(waiting_coroutine(sync))
    yield Timer(10000)
    dut.log.info("Waking up the waiting coroutine with an event...")
    sync.set()
    yield Timer(10000)


    result = yield Timer(1000000)
    dut.log.warning("test complete!")