add colorized build/sim log propgate on error to all runners (#26)
* add colorized build/sim log propgate on error to all runners * add doctoring Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -11,6 +11,7 @@ from cocotb.triggers import Timer
|
||||
|
||||
from tests.cocotb_lib.handle_utils import SignalHandle, resolve_handle
|
||||
|
||||
|
||||
class _AxilSlaveShim:
|
||||
"""Accessor for AXI4-Lite slave ports on the DUT."""
|
||||
|
||||
@@ -167,12 +168,12 @@ async def test_axi4lite_address_decoding(dut) -> None:
|
||||
if other_name == master_name and other_idx == index:
|
||||
continue
|
||||
other_entry = masters[other_name]
|
||||
assert (
|
||||
_get_int(other_entry["outputs"]["AWVALID"], other_idx) == 0
|
||||
), f"{other_name}{other_idx} AWVALID should remain low during {txn['label']}"
|
||||
assert (
|
||||
_get_int(other_entry["outputs"]["WVALID"], other_idx) == 0
|
||||
), f"{other_name}{other_idx} WVALID should remain low during {txn['label']}"
|
||||
assert _get_int(other_entry["outputs"]["AWVALID"], other_idx) == 0, (
|
||||
f"{other_name}{other_idx} AWVALID should remain low during {txn['label']}"
|
||||
)
|
||||
assert _get_int(other_entry["outputs"]["WVALID"], other_idx) == 0, (
|
||||
f"{other_name}{other_idx} WVALID should remain low during {txn['label']}"
|
||||
)
|
||||
|
||||
slave.AWVALID.value = 0
|
||||
slave.WVALID.value = 0
|
||||
@@ -198,9 +199,9 @@ async def test_axi4lite_address_decoding(dut) -> None:
|
||||
if other_name == master_name and other_idx == index:
|
||||
continue
|
||||
other_entry = masters[other_name]
|
||||
assert (
|
||||
_get_int(other_entry["outputs"]["ARVALID"], other_idx) == 0
|
||||
), f"{other_name}{other_idx} ARVALID should remain low during read of {txn['label']}"
|
||||
assert _get_int(other_entry["outputs"]["ARVALID"], other_idx) == 0, (
|
||||
f"{other_name}{other_idx} ARVALID should remain low during read of {txn['label']}"
|
||||
)
|
||||
|
||||
assert int(slave.RVALID.value) == 1, "Slave should observe RVALID when master responds"
|
||||
assert int(slave.RDATA.value) == read_data, "Read data must fold back to slave"
|
||||
|
||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -15,7 +16,7 @@ except ImportError: # pragma: no cover
|
||||
from cocotb_tools.runner import get_runner
|
||||
|
||||
from tests.cocotb_lib import RDL_CASES
|
||||
from tests.cocotb_lib.utils import get_verilog_sources, prepare_cpuif_case
|
||||
from tests.cocotb_lib.utils import get_verilog_sources, prepare_cpuif_case, colorize_cocotb_log
|
||||
|
||||
|
||||
@pytest.mark.simulation
|
||||
@@ -44,16 +45,42 @@ def test_axi4lite_smoke(tmp_path: Path, rdl_file: str, top_name: str) -> None:
|
||||
runner = get_runner("verilator")
|
||||
sim_build = build_root / "sim_build"
|
||||
|
||||
runner.build(
|
||||
sources=sources,
|
||||
hdl_toplevel=module_path.stem,
|
||||
build_dir=sim_build,
|
||||
)
|
||||
build_log_file = build_root / "build.log"
|
||||
sim_log_file = build_root / "simulation.log"
|
||||
|
||||
runner.test(
|
||||
hdl_toplevel=module_path.stem,
|
||||
test_module="tests.cocotb.axi4lite.smoke.test_register_access",
|
||||
build_dir=sim_build,
|
||||
log_file=str(build_root / "simulation.log"),
|
||||
extra_env={"RDL_TEST_CONFIG": json.dumps(config)},
|
||||
)
|
||||
try:
|
||||
runner.build(
|
||||
sources=sources,
|
||||
hdl_toplevel=module_path.stem,
|
||||
build_dir=sim_build,
|
||||
log_file=str(build_log_file),
|
||||
)
|
||||
except SystemExit as e:
|
||||
# Print build log on failure for easier debugging
|
||||
if build_log_file.exists():
|
||||
logging.error(f"""
|
||||
=== Build Log ===
|
||||
{colorize_cocotb_log(build_log_file.read_text())}
|
||||
=== End Build Log ===
|
||||
""")
|
||||
if e.code != 0:
|
||||
raise
|
||||
|
||||
try:
|
||||
runner.test(
|
||||
hdl_toplevel=module_path.stem,
|
||||
test_module="tests.cocotb.axi4lite.smoke.test_register_access",
|
||||
build_dir=sim_build,
|
||||
log_file=str(sim_log_file),
|
||||
extra_env={"RDL_TEST_CONFIG": json.dumps(config)},
|
||||
)
|
||||
except SystemExit as e:
|
||||
# Print simulation log on failure for easier debugging
|
||||
if sim_log_file.exists():
|
||||
logging.error(f"""
|
||||
=== Simulation Log ===
|
||||
{colorize_cocotb_log(sim_log_file.read_text())}
|
||||
=== End Simulation Log ===
|
||||
""")
|
||||
if e.code != 0:
|
||||
raise
|
||||
|
||||
@@ -63,10 +63,10 @@ def _axil_master(dut, base: str):
|
||||
async def test_depth_1(dut):
|
||||
"""Test max_decode_depth=1 - should have interface for inner1 only."""
|
||||
s_axil = _axil_slave(dut)
|
||||
|
||||
|
||||
# At depth 1, we should have m_axil_inner1 but not deeper interfaces
|
||||
inner1 = _axil_master(dut, "m_axil_inner1")
|
||||
|
||||
|
||||
# Default slave side inputs
|
||||
s_axil.AWVALID.value = 0
|
||||
s_axil.AWADDR.value = 0
|
||||
@@ -79,7 +79,7 @@ async def test_depth_1(dut):
|
||||
s_axil.ARADDR.value = 0
|
||||
s_axil.ARPROT.value = 0
|
||||
s_axil.RREADY.value = 0
|
||||
|
||||
|
||||
inner1.AWREADY.value = 0
|
||||
inner1.WREADY.value = 0
|
||||
inner1.BVALID.value = 0
|
||||
@@ -88,9 +88,9 @@ async def test_depth_1(dut):
|
||||
inner1.RVALID.value = 0
|
||||
inner1.RDATA.value = 0
|
||||
inner1.RRESP.value = 0
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x0 (should select inner1)
|
||||
inner1.AWREADY.value = 1
|
||||
inner1.WREADY.value = 1
|
||||
@@ -99,9 +99,9 @@ async def test_depth_1(dut):
|
||||
s_axil.WVALID.value = 1
|
||||
s_axil.WDATA.value = 0x12345678
|
||||
s_axil.WSTRB.value = 0xF
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(inner1.AWVALID.value) == 1, "inner1 write address valid must be set"
|
||||
assert int(inner1.WVALID.value) == 1, "inner1 write data valid must be set"
|
||||
|
||||
@@ -110,11 +110,11 @@ async def test_depth_1(dut):
|
||||
async def test_depth_2(dut):
|
||||
"""Test max_decode_depth=2 - should have interfaces for reg1 and inner2."""
|
||||
s_axil = _axil_slave(dut)
|
||||
|
||||
|
||||
# At depth 2, we should have m_axil_reg1 and m_axil_inner2
|
||||
reg1 = _axil_master(dut, "m_axil_reg1")
|
||||
inner2 = _axil_master(dut, "m_axil_inner2")
|
||||
|
||||
|
||||
# Default slave side inputs
|
||||
s_axil.AWVALID.value = 0
|
||||
s_axil.AWADDR.value = 0
|
||||
@@ -127,7 +127,7 @@ async def test_depth_2(dut):
|
||||
s_axil.ARADDR.value = 0
|
||||
s_axil.ARPROT.value = 0
|
||||
s_axil.RREADY.value = 0
|
||||
|
||||
|
||||
for master in [reg1, inner2]:
|
||||
master.AWREADY.value = 0
|
||||
master.WREADY.value = 0
|
||||
@@ -137,9 +137,9 @@ async def test_depth_2(dut):
|
||||
master.RVALID.value = 0
|
||||
master.RDATA.value = 0
|
||||
master.RRESP.value = 0
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x0 (should select reg1)
|
||||
reg1.AWREADY.value = 1
|
||||
reg1.WREADY.value = 1
|
||||
@@ -148,19 +148,19 @@ async def test_depth_2(dut):
|
||||
s_axil.WVALID.value = 1
|
||||
s_axil.WDATA.value = 0xABCDEF01
|
||||
s_axil.WSTRB.value = 0xF
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg1.AWVALID.value) == 1, "reg1 must be selected for address 0x0"
|
||||
assert int(inner2.AWVALID.value) == 0, "inner2 should not be selected"
|
||||
|
||||
|
||||
# Reset
|
||||
s_axil.AWVALID.value = 0
|
||||
s_axil.WVALID.value = 0
|
||||
reg1.AWREADY.value = 0
|
||||
reg1.WREADY.value = 0
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x10 (should select inner2)
|
||||
inner2.AWREADY.value = 1
|
||||
inner2.WREADY.value = 1
|
||||
@@ -169,9 +169,9 @@ async def test_depth_2(dut):
|
||||
s_axil.WVALID.value = 1
|
||||
s_axil.WDATA.value = 0x23456789
|
||||
s_axil.WSTRB.value = 0xF
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(inner2.AWVALID.value) == 1, "inner2 must be selected for address 0x10"
|
||||
assert int(reg1.AWVALID.value) == 0, "reg1 should not be selected"
|
||||
|
||||
@@ -180,12 +180,12 @@ async def test_depth_2(dut):
|
||||
async def test_depth_0(dut):
|
||||
"""Test max_decode_depth=0 - should have interfaces for all leaf registers."""
|
||||
s_axil = _axil_slave(dut)
|
||||
|
||||
|
||||
# At depth 0, we should have all leaf registers: reg1, reg2, reg2b
|
||||
reg1 = _axil_master(dut, "m_axil_reg1")
|
||||
reg2 = _axil_master(dut, "m_axil_reg2")
|
||||
reg2b = _axil_master(dut, "m_axil_reg2b")
|
||||
|
||||
|
||||
# Default slave side inputs
|
||||
s_axil.AWVALID.value = 0
|
||||
s_axil.AWADDR.value = 0
|
||||
@@ -198,7 +198,7 @@ async def test_depth_0(dut):
|
||||
s_axil.ARADDR.value = 0
|
||||
s_axil.ARPROT.value = 0
|
||||
s_axil.RREADY.value = 0
|
||||
|
||||
|
||||
for master in [reg1, reg2, reg2b]:
|
||||
master.AWREADY.value = 0
|
||||
master.WREADY.value = 0
|
||||
@@ -208,9 +208,9 @@ async def test_depth_0(dut):
|
||||
master.RVALID.value = 0
|
||||
master.RDATA.value = 0
|
||||
master.RRESP.value = 0
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x0 (should select reg1)
|
||||
reg1.AWREADY.value = 1
|
||||
reg1.WREADY.value = 1
|
||||
@@ -219,20 +219,20 @@ async def test_depth_0(dut):
|
||||
s_axil.WVALID.value = 1
|
||||
s_axil.WDATA.value = 0x11111111
|
||||
s_axil.WSTRB.value = 0xF
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg1.AWVALID.value) == 1, "reg1 must be selected for address 0x0"
|
||||
assert int(reg2.AWVALID.value) == 0, "reg2 should not be selected"
|
||||
assert int(reg2b.AWVALID.value) == 0, "reg2b should not be selected"
|
||||
|
||||
|
||||
# Reset
|
||||
s_axil.AWVALID.value = 0
|
||||
s_axil.WVALID.value = 0
|
||||
reg1.AWREADY.value = 0
|
||||
reg1.WREADY.value = 0
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x10 (should select reg2)
|
||||
reg2.AWREADY.value = 1
|
||||
reg2.WREADY.value = 1
|
||||
@@ -241,20 +241,20 @@ async def test_depth_0(dut):
|
||||
s_axil.WVALID.value = 1
|
||||
s_axil.WDATA.value = 0x22222222
|
||||
s_axil.WSTRB.value = 0xF
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg2.AWVALID.value) == 1, "reg2 must be selected for address 0x10"
|
||||
assert int(reg1.AWVALID.value) == 0, "reg1 should not be selected"
|
||||
assert int(reg2b.AWVALID.value) == 0, "reg2b should not be selected"
|
||||
|
||||
|
||||
# Reset
|
||||
s_axil.AWVALID.value = 0
|
||||
s_axil.WVALID.value = 0
|
||||
reg2.AWREADY.value = 0
|
||||
reg2.WREADY.value = 0
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x14 (should select reg2b)
|
||||
reg2b.AWREADY.value = 1
|
||||
reg2b.WREADY.value = 1
|
||||
@@ -263,9 +263,9 @@ async def test_depth_0(dut):
|
||||
s_axil.WVALID.value = 1
|
||||
s_axil.WDATA.value = 0x33333333
|
||||
s_axil.WSTRB.value = 0xF
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg2b.AWVALID.value) == 1, "reg2b must be selected for address 0x14"
|
||||
assert int(reg1.AWVALID.value) == 0, "reg1 should not be selected"
|
||||
assert int(reg2.AWVALID.value) == 0, "reg2 should not be selected"
|
||||
|
||||
Reference in New Issue
Block a user