コード例 #1
0
ファイル: test_scheduler.py プロジェクト: marlonjames/cocotb
async def test_start_scheduling(dut):
    """Test that start resumes calling task before control is yielded to simulator."""
    sim_resumed = False
    coro_started = False

    def react_wrapper(trigger):
        """Function to prime trigger with."""
        nonlocal sim_resumed
        log = logging.getLogger("cocotb.test")
        log.debug("react_wrapper start")
        sim_resumed = False
        cocotb.scheduler._react(trigger)
        sim_resumed = True
        log.debug("react_wrapper end")

    async def coro():
        nonlocal coro_started
        coro_started = True

    t = Timer(1, 'step')
    # pre-prime with wrapper function instead of letting scheduler prime it normally
    t.prime(react_wrapper)
    await t
    # react_wrapper is now on the stack
    assert sim_resumed is False
    await cocotb.start(coro())
    assert sim_resumed is False
    assert coro_started is True
    await Timer(1, 'step'
                )  # await a GPITrigger to ensure control returns to simulator
    assert sim_resumed is True
コード例 #2
0
ファイル: test_scheduler.py プロジェクト: marlonjames/cocotb
async def test_start_soon_scheduling(dut):
    """Test order of scheduling when using start_soon."""
    coro_scheduled = False

    def react_wrapper(trigger):
        """Function to prime trigger with."""
        log = logging.getLogger("cocotb.test")
        log.debug("react_wrapper start")
        assert coro_scheduled is False
        cocotb.scheduler._react(trigger)
        assert coro_scheduled is True
        log.debug("react_wrapper end")

    async def coro():
        nonlocal coro_scheduled
        coro_scheduled = True

    t = Timer(1, 'step')
    # pre-prime with wrapper function instead of letting scheduler prime it normally
    t.prime(react_wrapper)
    await t
    # react_wrapper is now on the stack
    cocotb.start_soon(
        coro())  # coro() should run before returning to the simulator
    await Timer(1, 'step'
                )  # await a GPITrigger to ensure control returns to simulator
    assert coro_scheduled is True