Testbench cleanup for cocotb 2.0
Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
@@ -27,39 +27,23 @@ COCOTB_HDL_TIMEUNIT = 1ns
|
||||
COCOTB_HDL_TIMEPRECISION = 1ps
|
||||
|
||||
DUT = test_ptp_clock
|
||||
TOPLEVEL = $(DUT)
|
||||
MODULE = $(DUT)
|
||||
COCOTB_TEST_MODULES = $(DUT)
|
||||
COCOTB_TOPLEVEL = $(DUT)
|
||||
MODULE = $(COCOTB_TEST_MODULES)
|
||||
TOPLEVEL = $(COCOTB_TOPLEVEL)
|
||||
VERILOG_SOURCES += $(DUT).v
|
||||
|
||||
ifeq ($(SIM), icarus)
|
||||
PLUSARGS += -fst
|
||||
|
||||
COMPILE_ARGS += $(foreach v,$(filter PARAM_%,$(.VARIABLES)),-P $(TOPLEVEL).$(subst PARAM_,,$(v))=$($(v)))
|
||||
|
||||
ifeq ($(WAVES), 1)
|
||||
VERILOG_SOURCES += iverilog_dump.v
|
||||
COMPILE_ARGS += -s iverilog_dump
|
||||
endif
|
||||
COMPILE_ARGS += $(foreach v,$(filter PARAM_%,$(.VARIABLES)),-P $(COCOTB_TOPLEVEL).$(subst PARAM_,,$(v))=$($(v)))
|
||||
else ifeq ($(SIM), verilator)
|
||||
COMPILE_ARGS += -Wno-SELRANGE -Wno-WIDTH
|
||||
|
||||
COMPILE_ARGS += $(foreach v,$(filter PARAM_%,$(.VARIABLES)),-G$(subst PARAM_,,$(v))=$($(v)))
|
||||
|
||||
ifeq ($(WAVES), 1)
|
||||
COMPILE_ARGS += --trace-fst
|
||||
VERILATOR_TRACE = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(shell cocotb-config --makefiles)/Makefile.sim
|
||||
|
||||
iverilog_dump.v:
|
||||
echo 'module iverilog_dump();' > $@
|
||||
echo 'initial begin' >> $@
|
||||
echo ' $$dumpfile("$(TOPLEVEL).fst");' >> $@
|
||||
echo ' $$dumpvars(0, $(TOPLEVEL));' >> $@
|
||||
echo 'end' >> $@
|
||||
echo 'endmodule' >> $@
|
||||
|
||||
clean::
|
||||
@rm -rf iverilog_dump.v
|
||||
@rm -rf dump.fst $(TOPLEVEL).fst
|
||||
include $(shell cocotb-config --makefiles)/Makefile.sim
|
||||
@@ -68,11 +68,11 @@ class TB:
|
||||
await RisingEdge(self.dut.clk)
|
||||
|
||||
def get_ts_tod_ns(self):
|
||||
ts = self.dut.ts_tod.value.integer
|
||||
ts = int(self.dut.ts_tod.value)
|
||||
return Decimal(ts >> 48).scaleb(9) + (Decimal(ts & 0xffffffffffff) / Decimal(2**16))
|
||||
|
||||
def get_ts_rel_ns(self):
|
||||
ts = self.dut.ts_rel.value.integer
|
||||
ts = int(self.dut.ts_rel.value)
|
||||
return Decimal(ts) / Decimal(2**16)
|
||||
|
||||
|
||||
@@ -127,9 +127,9 @@ async def run_load_timestamps(dut):
|
||||
|
||||
await RisingEdge(dut.clk)
|
||||
|
||||
assert dut.ts_tod.value.integer == (12345678 << 16) + (tb.ptp_clock.period_ns << 16) + (tb.ptp_clock.period_fns >> 16)
|
||||
assert dut.ts_rel.value.integer == (12345678 << 16) + (tb.ptp_clock.period_ns << 16) + (tb.ptp_clock.period_fns >> 16)
|
||||
assert dut.ts_step.value.integer == 1
|
||||
assert int(dut.ts_tod.value) == (12345678 << 16) + (tb.ptp_clock.period_ns << 16) + (tb.ptp_clock.period_fns >> 16)
|
||||
assert int(dut.ts_rel.value) == (12345678 << 16) + (tb.ptp_clock.period_ns << 16) + (tb.ptp_clock.period_fns >> 16)
|
||||
assert int(dut.ts_step.value) == 1
|
||||
|
||||
start_time = Decimal(get_sim_time('fs')).scaleb(-6)
|
||||
start_ts_tod = tb.get_ts_tod_ns()
|
||||
@@ -184,10 +184,10 @@ async def run_seconds_increment(dut):
|
||||
for k in range(3000):
|
||||
await RisingEdge(dut.clk)
|
||||
|
||||
if dut.pps.value.integer:
|
||||
if int(dut.pps.value):
|
||||
saw_pps = True
|
||||
assert dut.ts_tod.value.integer >> 48 == 1
|
||||
assert dut.ts_tod.value.integer & 0xffffffffffff < 10*2**16
|
||||
assert int(dut.ts_tod.value) >> 48 == 1
|
||||
assert int(dut.ts_tod.value) & 0xffffffffffff < 10*2**16
|
||||
|
||||
assert saw_pps
|
||||
|
||||
|
||||
Reference in New Issue
Block a user