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 _Apb4SlaveShim:
|
||||
"""Lightweight accessor for the APB4 slave side of the DUT."""
|
||||
|
||||
@@ -141,17 +142,23 @@ async def test_apb4_address_decoding(dut) -> None:
|
||||
|
||||
assert _get_int(entry["outputs"]["PSEL"], index) == 1, f"{master_name} should assert PSEL for write"
|
||||
assert _get_int(entry["outputs"]["PWRITE"], index) == 1, f"{master_name} should see write intent"
|
||||
assert _get_int(entry["outputs"]["PADDR"], index) == address, f"{master_name} must receive write address"
|
||||
assert _get_int(entry["outputs"]["PWDATA"], index) == write_data, f"{master_name} must receive write data"
|
||||
assert _get_int(entry["outputs"]["PSTRB"], index) == strobe_mask, f"{master_name} must receive full strobes"
|
||||
assert _get_int(entry["outputs"]["PADDR"], index) == address, (
|
||||
f"{master_name} must receive write address"
|
||||
)
|
||||
assert _get_int(entry["outputs"]["PWDATA"], index) == write_data, (
|
||||
f"{master_name} must receive write data"
|
||||
)
|
||||
assert _get_int(entry["outputs"]["PSTRB"], index) == strobe_mask, (
|
||||
f"{master_name} must receive full strobes"
|
||||
)
|
||||
|
||||
for other_name, other_idx in _all_index_pairs(masters):
|
||||
if other_name == master_name and other_idx == index:
|
||||
continue
|
||||
other_entry = masters[other_name]
|
||||
assert (
|
||||
_get_int(other_entry["outputs"]["PSEL"], other_idx) == 0
|
||||
), f"{other_name}{other_idx} should remain idle during {txn['label']}"
|
||||
assert _get_int(other_entry["outputs"]["PSEL"], other_idx) == 0, (
|
||||
f"{other_name}{other_idx} should remain idle during {txn['label']}"
|
||||
)
|
||||
|
||||
assert int(slave.PREADY.value) == 1, "Slave ready should reflect selected master"
|
||||
assert int(slave.PSLVERR.value) == 0, "No error expected during write"
|
||||
@@ -179,16 +186,20 @@ async def test_apb4_address_decoding(dut) -> None:
|
||||
await Timer(1, units="ns")
|
||||
|
||||
assert _get_int(entry["outputs"]["PSEL"], index) == 1, f"{master_name} must assert PSEL for read"
|
||||
assert _get_int(entry["outputs"]["PWRITE"], index) == 0, f"{master_name} should deassert write for reads"
|
||||
assert _get_int(entry["outputs"]["PADDR"], index) == address, f"{master_name} must receive read address"
|
||||
assert _get_int(entry["outputs"]["PWRITE"], index) == 0, (
|
||||
f"{master_name} should deassert write for reads"
|
||||
)
|
||||
assert _get_int(entry["outputs"]["PADDR"], index) == address, (
|
||||
f"{master_name} must receive read address"
|
||||
)
|
||||
|
||||
for other_name, other_idx in _all_index_pairs(masters):
|
||||
if other_name == master_name and other_idx == index:
|
||||
continue
|
||||
other_entry = masters[other_name]
|
||||
assert (
|
||||
_get_int(other_entry["outputs"]["PSEL"], other_idx) == 0
|
||||
), f"{other_name}{other_idx} must stay idle during read of {txn['label']}"
|
||||
assert _get_int(other_entry["outputs"]["PSEL"], other_idx) == 0, (
|
||||
f"{other_name}{other_idx} must stay idle during read of {txn['label']}"
|
||||
)
|
||||
|
||||
assert int(slave.PRDATA.value) == read_data, "Slave should observe readback data from master"
|
||||
assert int(slave.PREADY.value) == 1, "Slave ready should follow responding master"
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import json
|
||||
from pathlib import Path
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from peakrdl_busdecoder.cpuif.apb4.apb4_cpuif_flat import APB4CpuifFlat
|
||||
@@ -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
|
||||
@@ -43,21 +44,25 @@ def test_apb4_smoke(tmp_path: Path, rdl_file: str, top_name: str) -> None:
|
||||
|
||||
runner = get_runner("verilator")
|
||||
sim_build = build_root / "sim_build"
|
||||
|
||||
|
||||
build_log_file = build_root / "build.log"
|
||||
sim_log_file = build_root / "simulation.log"
|
||||
|
||||
try:
|
||||
runner.build(
|
||||
sources=sources,
|
||||
hdl_toplevel=module_path.stem,
|
||||
build_dir=sim_build,
|
||||
log_file=str(build_root / "build.log"),
|
||||
log_file=str(build_log_file),
|
||||
)
|
||||
except SystemExit as e:
|
||||
# Print build log on failure for easier debugging
|
||||
log_path = build_root / "build.log"
|
||||
if log_path.exists():
|
||||
logging.error("\n\n=== Build Log ===\n")
|
||||
logging.error(log_path.read_text())
|
||||
logging.error("\n=== End Build Log ===\n")
|
||||
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
|
||||
|
||||
@@ -66,15 +71,16 @@ def test_apb4_smoke(tmp_path: Path, rdl_file: str, top_name: str) -> None:
|
||||
hdl_toplevel=module_path.stem,
|
||||
test_module="tests.cocotb.apb4.smoke.test_register_access",
|
||||
build_dir=sim_build,
|
||||
log_file=str(build_root / "simulation.log"),
|
||||
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
|
||||
log_path = build_root / "simulation.log"
|
||||
if log_path.exists():
|
||||
logging.error("\n\n=== Simulation Log ===\n")
|
||||
logging.error(log_path.read_text())
|
||||
logging.error("\n=== End Simulation Log ===\n")
|
||||
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
|
||||
|
||||
@@ -45,10 +45,10 @@ def _apb4_master(dut, base: str):
|
||||
async def test_depth_1(dut):
|
||||
"""Test max_decode_depth=1 - should have interface for inner1 only."""
|
||||
s_apb = _apb4_slave(dut)
|
||||
|
||||
|
||||
# At depth 1, we should have m_apb_inner1 but not deeper interfaces
|
||||
inner1 = _apb4_master(dut, "m_apb_inner1")
|
||||
|
||||
|
||||
# Default slave side inputs
|
||||
s_apb.PSEL.value = 0
|
||||
s_apb.PENABLE.value = 0
|
||||
@@ -57,13 +57,13 @@ async def test_depth_1(dut):
|
||||
s_apb.PWDATA.value = 0
|
||||
s_apb.PPROT.value = 0
|
||||
s_apb.PSTRB.value = 0
|
||||
|
||||
|
||||
inner1.PRDATA.value = 0
|
||||
inner1.PREADY.value = 0
|
||||
inner1.PSLVERR.value = 0
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x0 (should select inner1)
|
||||
inner1.PREADY.value = 1
|
||||
s_apb.PADDR.value = 0x0
|
||||
@@ -72,9 +72,9 @@ async def test_depth_1(dut):
|
||||
s_apb.PWRITE.value = 1
|
||||
s_apb.PSEL.value = 1
|
||||
s_apb.PENABLE.value = 1
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(inner1.PSEL.value) == 1, "inner1 must be selected"
|
||||
assert int(inner1.PWRITE.value) == 1, "Write should propagate"
|
||||
assert int(s_apb.PREADY.value) == 1, "Ready should mirror master"
|
||||
@@ -84,11 +84,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_apb = _apb4_slave(dut)
|
||||
|
||||
|
||||
# At depth 2, we should have m_apb_reg1 and m_apb_inner2
|
||||
reg1 = _apb4_master(dut, "m_apb_reg1")
|
||||
inner2 = _apb4_master(dut, "m_apb_inner2")
|
||||
|
||||
|
||||
# Default slave side inputs
|
||||
s_apb.PSEL.value = 0
|
||||
s_apb.PENABLE.value = 0
|
||||
@@ -97,17 +97,17 @@ async def test_depth_2(dut):
|
||||
s_apb.PWDATA.value = 0
|
||||
s_apb.PPROT.value = 0
|
||||
s_apb.PSTRB.value = 0
|
||||
|
||||
|
||||
reg1.PRDATA.value = 0
|
||||
reg1.PREADY.value = 0
|
||||
reg1.PSLVERR.value = 0
|
||||
|
||||
|
||||
inner2.PRDATA.value = 0
|
||||
inner2.PREADY.value = 0
|
||||
inner2.PSLVERR.value = 0
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x0 (should select reg1)
|
||||
reg1.PREADY.value = 1
|
||||
s_apb.PADDR.value = 0x0
|
||||
@@ -116,18 +116,18 @@ async def test_depth_2(dut):
|
||||
s_apb.PWRITE.value = 1
|
||||
s_apb.PSEL.value = 1
|
||||
s_apb.PENABLE.value = 1
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg1.PSEL.value) == 1, "reg1 must be selected for address 0x0"
|
||||
assert int(inner2.PSEL.value) == 0, "inner2 should not be selected"
|
||||
|
||||
|
||||
# Reset
|
||||
s_apb.PSEL.value = 0
|
||||
s_apb.PENABLE.value = 0
|
||||
reg1.PREADY.value = 0
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x10 (should select inner2)
|
||||
inner2.PREADY.value = 1
|
||||
s_apb.PADDR.value = 0x10
|
||||
@@ -136,9 +136,9 @@ async def test_depth_2(dut):
|
||||
s_apb.PWRITE.value = 1
|
||||
s_apb.PSEL.value = 1
|
||||
s_apb.PENABLE.value = 1
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(inner2.PSEL.value) == 1, "inner2 must be selected for address 0x10"
|
||||
assert int(reg1.PSEL.value) == 0, "reg1 should not be selected"
|
||||
|
||||
@@ -147,12 +147,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_apb = _apb4_slave(dut)
|
||||
|
||||
|
||||
# At depth 0, we should have all leaf registers: reg1, reg2, reg2b
|
||||
reg1 = _apb4_master(dut, "m_apb_reg1")
|
||||
reg2 = _apb4_master(dut, "m_apb_reg2")
|
||||
reg2b = _apb4_master(dut, "m_apb_reg2b")
|
||||
|
||||
|
||||
# Default slave side inputs
|
||||
s_apb.PSEL.value = 0
|
||||
s_apb.PENABLE.value = 0
|
||||
@@ -161,14 +161,14 @@ async def test_depth_0(dut):
|
||||
s_apb.PWDATA.value = 0
|
||||
s_apb.PPROT.value = 0
|
||||
s_apb.PSTRB.value = 0
|
||||
|
||||
|
||||
for master in [reg1, reg2, reg2b]:
|
||||
master.PRDATA.value = 0
|
||||
master.PREADY.value = 0
|
||||
master.PSLVERR.value = 0
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x0 (should select reg1)
|
||||
reg1.PREADY.value = 1
|
||||
s_apb.PADDR.value = 0x0
|
||||
@@ -177,19 +177,19 @@ async def test_depth_0(dut):
|
||||
s_apb.PWRITE.value = 1
|
||||
s_apb.PSEL.value = 1
|
||||
s_apb.PENABLE.value = 1
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg1.PSEL.value) == 1, "reg1 must be selected for address 0x0"
|
||||
assert int(reg2.PSEL.value) == 0, "reg2 should not be selected"
|
||||
assert int(reg2b.PSEL.value) == 0, "reg2b should not be selected"
|
||||
|
||||
|
||||
# Reset
|
||||
s_apb.PSEL.value = 0
|
||||
s_apb.PENABLE.value = 0
|
||||
reg1.PREADY.value = 0
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x10 (should select reg2)
|
||||
reg2.PREADY.value = 1
|
||||
s_apb.PADDR.value = 0x10
|
||||
@@ -198,19 +198,19 @@ async def test_depth_0(dut):
|
||||
s_apb.PWRITE.value = 1
|
||||
s_apb.PSEL.value = 1
|
||||
s_apb.PENABLE.value = 1
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg2.PSEL.value) == 1, "reg2 must be selected for address 0x10"
|
||||
assert int(reg1.PSEL.value) == 0, "reg1 should not be selected"
|
||||
assert int(reg2b.PSEL.value) == 0, "reg2b should not be selected"
|
||||
|
||||
|
||||
# Reset
|
||||
s_apb.PSEL.value = 0
|
||||
s_apb.PENABLE.value = 0
|
||||
reg2.PREADY.value = 0
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
# Write to address 0x14 (should select reg2b)
|
||||
reg2b.PREADY.value = 1
|
||||
s_apb.PADDR.value = 0x14
|
||||
@@ -219,9 +219,9 @@ async def test_depth_0(dut):
|
||||
s_apb.PWRITE.value = 1
|
||||
s_apb.PSEL.value = 1
|
||||
s_apb.PENABLE.value = 1
|
||||
|
||||
|
||||
await Timer(1, units="ns")
|
||||
|
||||
|
||||
assert int(reg2b.PSEL.value) == 1, "reg2b must be selected for address 0x14"
|
||||
assert int(reg1.PSEL.value) == 0, "reg1 should not be selected"
|
||||
assert int(reg2.PSEL.value) == 0, "reg2 should not be selected"
|
||||
|
||||
Reference in New Issue
Block a user