def issue_588_coroutine_list(dut): """ Yield a list of triggers and coroutines.""" # Record simulation time. current_time = utils.get_sim_time("ns") # Yield a list, containing a RisingEdge trigger and a coroutine. yield [sample_coroutine(dut), triggers.Timer(100, "ns")] # Make sure that only 5 ns passed, because the sample coroutine # terminated first. new_time = utils.get_sim_time("ns") if int(new_time - current_time) != 5: raise result.TestFailure("Did not yield coroutine in list.")
async def issue_588_coroutine_list(dut): """ Yield a list of triggers and coroutines.""" # Record simulation time. current_time = utils.get_sim_time("ns") # Yield a list, containing a RisingEdge trigger and a coroutine. coro = cocotb.fork(sample_coroutine(dut)) await triggers.First(coro, triggers.Timer(100, "ns")) coro.kill() # Make sure that only 5 ns passed, because the sample coroutine # terminated first. new_time = utils.get_sim_time("ns") assert int(new_time - current_time) == 5, "Did not yield coroutine in list."
def sample_coroutine(dut): """ Very simple coroutine that waits 5 ns.""" yield triggers.Timer(5, "ns") dut._log.info("Sample coroutine yielded.")
def Timer(*args, **kwargs): assert cocotb_wrapper.using_cocotb() return cocotb_triggers.Timer(*args, **kwargs)