Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"
def example():
yield Timer(10, 'ns')
return 1
async def test_after_system_task_fail(dut):
"""
Test to run after failed test.
"""
await Timer(1, units='ns')
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")
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()
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
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
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")
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!")