Skip to content

Commit

Permalink
uniformized and simplified testbench scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
psychogenic committed Dec 6, 2024
1 parent 424cf3b commit c65bf40
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
7 changes: 4 additions & 3 deletions src/examples/basic/tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
from microcotb.triggers import RisingEdge, FallingEdge, ClockCycles, Timer
from microcotb.utils import get_sim_time

# get the @cocotb tests into a namespace
cocotb.RunnerModuleName = 'basic'
# get the detected @cocotb tests into a namespace
# so we can load multiple such modules
cocotb.set_runner_scope(__name__)

from ttboard.demoboard import DemoBoard, RPMode
from ttboard.cocotb.dut import DUT
Expand Down Expand Up @@ -146,7 +147,7 @@ def run():
tt.uio_oe_pico.value = 0 # all inputs

# get a runner
runner = cocotb.get_runner('basic')
runner = cocotb.get_runner(__name__)

# here's our DUT... you could subclass this and
# do cool things, like rename signals or access
Expand Down
7 changes: 4 additions & 3 deletions src/examples/tt_um_factory_test/tt_um_factory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
gc.collect()


# get the @cocotb tests into a namespace
cocotb.RunnerModuleName = 'tt_um_factory_test'
# get the detected @cocotb tests into a namespace
# so we can load multiple such modules
cocotb.set_runner_scope(__name__)

@cocotb.test()
async def test_loopback(dut):
Expand Down Expand Up @@ -145,7 +146,7 @@ def __init__(self):
TimeValue.ReBaseStringUnits = True # I like pretty strings


runner = cocotb.get_runner('tt_um_factory_test')
runner = cocotb.get_runner(__name__)

dut = DUT()
dut._log.info(f"enabled factory test project. Will test with {runner}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from microcotb.triggers import Timer, ClockCycles # RisingEdge, FallingEdge, Timer, ClockCycles


# get the @cocotb tests into a namespace
cocotb.RunnerModuleName = 'tt_um_psychogenic_neptune'
# get the detected @cocotb tests into a namespace
# so we can load multiple such modules
cocotb.set_runner_scope(__name__)

from ttboard.demoboard import DemoBoard, RPMode

Expand Down Expand Up @@ -202,7 +203,7 @@ def main():
TimeValue.ReBaseStringUnits = True

# create runner and DUT, and get tests going
runner = cocotb.get_runner('tt_um_psychogenic_neptune')
runner = cocotb.get_runner(__name__)
dut = DUT()
dut._log.info(f"enabled neptune project, will test with {runner}")
runner.test(dut)
Expand Down
9 changes: 8 additions & 1 deletion src/examples/tt_um_psychogenic_shaman/tb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
import hashlib
import random



# get the detected @cocotb tests into a namespace
# so we can load multiple such modules
cocotb.set_runner_scope(__name__)


GateLevelTest = False
DoLongLongTest = False
DoEverySizeBlockTest = False
Expand Down Expand Up @@ -619,7 +626,7 @@ def main():
dut = DUT()
tt.uio_oe_pico.value = dut.oe_pico_setting

runner = cocotb.get_runner('tt_um_psychogenic_shaman')
runner = cocotb.get_runner(__name__)
dut._log.info(f"enabled shaman project. Will test with\n{runner}")
runner.test(dut)

7 changes: 4 additions & 3 deletions src/examples/tt_um_rejunity_sn76489/tt_um_rejunity_sn76489.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
from microcotb.triggers import RisingEdge, FallingEdge, Timer, ClockCycles


# get the @cocotb tests into a namespace
cocotb.RunnerModuleName = 'tt_um_rejunity_snXXX'
# get the detected @cocotb tests into a namespace
# so we can load multiple such modules
cocotb.set_runner_scope(__name__)

# MASTER_CLOCK = 3_579_545 # NTSC frequency of SN as used in Sega Master System, 0xFE = 440 Hz
# MASTER_CLOCK = 3_546_895 # PAL ---- // ----
Expand Down Expand Up @@ -611,5 +612,5 @@ def main(selection=None, master_clock=None, internal_clock_div = None):

dut = DUT()
dut._log.info("enabled factory test project, running")
runner = cocotb.get_runner('tt_um_rejunity_snXXX')
runner = cocotb.get_runner(__name__)
runner.test(dut)
8 changes: 4 additions & 4 deletions src/examples/tt_um_rgbled_decoder/tt_um_rgbled_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
from microcotb.triggers import RisingEdge, FallingEdge, Timer, ClockCycles
from microcotb.utils import get_sim_time


# get the @cocotb tests into a namespace
cocotb.RunnerModuleName = 'tt_um_rgbled_decoder'
# get the detected @cocotb tests into a namespace
# so we can load multiple such modules
cocotb.set_runner_scope(__name__)


def time_delta_not(cond:str):
Expand Down Expand Up @@ -230,7 +230,7 @@ def main():

dut = DUT()
dut._log.info("enabled rgbled project, running")
runner = cocotb.get_runner('tt_um_rgbled_decoder')
runner = cocotb.get_runner(__name__)
runner.test(dut)


2 changes: 0 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ def stopClocking():

def run_testbench_basic():
import microcotb
# a uPython means to avoid having all
# decorators ever seen in the same test run:
import examples.basic as test
test.run()
return test
Expand Down

0 comments on commit c65bf40

Please sign in to comment.