Files
retroSoC/tests/test_hp_platform.py
T
maksyuki cf6bcf7a45 feat: refactor GA2D tests and update to Phase 4 specifications
- Updated resource_controller_tb.sv to verify resource STATUS bit layout after HP handoff.
- Modified test_ga2d.py to reflect changes for GA2D Phase 4, including memory map generation and source file handling.
- Introduced new test_ga2d_dma.py for independent FILL/COPY reference-model coverage.
- Updated test_ga2d_platform.py to check for the activation of the private AXI64 master and IRQ routing.
- Adjusted test_ga2d_register_parity.py to validate new scalar encodings for Phase 4.
- Enhanced test_hp_boot_bundle.py to ensure HP boot uses the private GA2D mailbox and resource lifecycle.
- Updated test_hp_platform.py to verify GA2D lifecycle markers and cache handshake budget.
- Modified test_performance_log.py to include GA2D workload and configuration facts in performance logs.
- Adjusted test_publication_retrieval.py and test_publication_software.py to reflect changes in GA2D stages.
- Updated test_script_tools.py to ensure GA2D formal filelists are correctly scoped.
- Refactored test_soc_topology.py to validate the private master policy and active shell in GA2D Phase 4.
2026-09-14 21:46:26 +08:00

197 lines
7.1 KiB
Python

"""HP platform configuration and generated-source boundary tests."""
from __future__ import annotations
import json
import shutil
import subprocess
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
def test_hp_profile_and_locked_generator_contract() -> None:
lock = json.loads((ROOT / "dependencies/dependencies.lock.json").read_text(encoding="utf-8"))
vexii = lock["sources"]["vexiiriscv"]
assert vexii["revision"] == "ef7da4134ff11ec6a681d0632123b232b853b046"
assert vexii["recursive"] is True
assert vexii["destination"].startswith(".cache/")
profile = (ROOT / "configs/ci/ihp130-hp.mk").read_text(encoding="utf-8")
assert "HAVE_HP" in profile and "YES" in profile
assert "rv32imafdc_zicbom_max" in profile
assert "APP" in profile and "hp_boot" in profile
assert "LINK_TYPE" in profile and "ld2_all_sram" in profile
generator = (ROOT / "scripts/vexiiriscv/GenerateRetroSocHp.scala").read_text(
encoding="utf-8"
)
for requirement in (
'param.addISA("m", "a", "f", "d", "c", "s", "u", "zicbom", "zicntr", "zihpm")',
"param.decoders = 2",
"param.lanes = 2",
"param.fetchL1Ways = 4",
"param.lsuL1Ways = 4",
"param.resetVector = 0x38000000L",
"param.plugins(hartId = 1)",
):
assert requirement in generator
def test_makefile_uses_path_resolved_sbt() -> None:
makefile = (ROOT / "Makefile").read_text(encoding="utf-8")
assert "SBT ?= sbt" in makefile
assert "/nfs/home/miaoyuchi/sbt/bin/sbt" not in makefile
def test_hp_linux_simulation_uses_explicit_fast_flash_acceptance() -> None:
makefile = (ROOT / "Makefile").read_text(encoding="utf-8")
verilator_makefile = (ROOT / "rtl/mini/mk/verilator.mk").read_text(encoding="utf-8")
emulator = (ROOT / "rtl/mini/dv/verilator/csrc/main.cpp").read_text(encoding="utf-8")
assert "HP_LINUX_SIM_TIME ?= 7200" in makefile
assert "hp-linux-sim: hp-bundle comp" in makefile
assert "VERILATOR_SIM_ARGS=--fast-flash sim" in makefile
for marker in (
"VERILATOR_FAST_FLASH=enabled",
"retroSoC HP Linux ready",
"HP_LINUX_READY",
"SIM_TEST_PASS code=0",
):
assert f"--require '{marker}'" in makefile
assert "VERILATOR_SIM_ARGS ?=" in verilator_makefile
assert "$(VERILATOR_SIM_ARGS) -t $(SOC_SIM_TIME)" in verilator_makefile
assert '("fast-flash"' in emulator
def test_hp_address_and_sysctrl_contract() -> None:
document = json.loads(
(ROOT / "rtl/mini/address_map/memory_map.json").read_text(encoding="utf-8")
)
regions = {region["symbol"]: region for region in document["regions"]}
assert regions["HP_ACLINT"]["base"] == "0x02000000"
assert regions["HP_PLIC"]["base"] == "0x0C000000"
assert regions["APB4_UART1"]["base"] == "0x10018000"
assert regions["APB4_HP_MAILBOX"]["base"] == "0x10019000"
assert regions["APB4_RESOURCE_CTRL"]["base"] == "0x2000A000"
registers = {register["symbol"]: register["offset"] for register in document["sysctrl_registers"]}
assert registers["HP_CTRL"] == "0xA4"
assert registers["HP_STATUS"] == "0xA8"
assert registers["DEBUG_SELECT"] == "0xAC"
def test_generated_vexii_rtl_is_not_tracked() -> None:
tracked = subprocess.run(
["git", "ls-files", "*vexii_riscv_hp_generated*"],
cwd=ROOT,
check=True,
capture_output=True,
text=True,
).stdout
assert tracked == ""
def test_hp_smoke_payload_uses_hart1_platform_abi() -> None:
source = (ROOT / "app/ports/linux/smoke/start.S").read_text(encoding="utf-8")
assert "0x10018000" in source
assert "0x10019000" in source
assert "0x4c4e5801" in source.lower()
assert "HP_SMOKE_READY" in source
assert "0x10012000" in source
assert "0x2000a000" in source.lower()
assert "cbo.clean" in source
assert "cbo.inval" in source
assert source.count(".balign 64") >= 4
for marker in ("HP_GA2D_START", "HP_GA2D_PASS", "HP_GA2D_FAIL", "HP_GA2D_CACHE"):
assert marker in source
def test_hp_smoke_simulation_requires_ga2d_result_and_cache_lifecycle_markers() -> None:
makefile = (ROOT / "Makefile").read_text(encoding="utf-8")
target = makefile.split("hp-smoke-sim: hp-smoke-bundle comp", 1)[1].split("\nifeq", 1)[0]
assert "HP_SMOKE_SIM_TIME ?= 300" in makefile
assert "SOC_SIM_TIME=$(HP_SMOKE_SIM_TIME)" in target
assert "VERILATOR_SIM_ARGS=--fast-flash" in target
for marker in (
"SIM_TEST_PASS code=0",
"HP_LINUX_READY",
"HP_GA2D_PASS",
"HP_GA2D_CACHE_CLEAN",
):
assert f"--require '{marker}'" in target
def test_hp_cache_handshake_budget_covers_cbo_and_mailbox_round_trip() -> None:
source = (ROOT / "rtl/mini/top/retrosoc.sv").read_text(encoding="utf-8")
assert "HpCacheHandshakeTimeout = 16'hffff" in source
assert ".timeout_i (HpCacheHandshakeTimeout)" in source
def test_hp_lifecycle_flush_preserves_unadmitted_lp_requests() -> None:
source = (ROOT / "rtl/mini/top/soc_data_plane.sv").read_text(encoding="utf-8")
lp_data_cdc = source.split(") u_lp_data_cdc (", 1)[1].split(");", 1)[0]
assert ".clear_i (1'b0)" in lp_data_cdc
assert "HP lifecycle flush invalidates HP transport" in lp_data_cdc
def test_linux_build_uses_external_opensbi_platform_and_actual_initrd_end() -> None:
build = (ROOT / "scripts/build_hp_linux.py").read_text(encoding="utf-8")
assert '"tinyconfig"' in build
assert 'environment.pop("MAKEOVERRIDES", None)' in build
assert '"PLATFORM=retrosoc_hp"' in build
assert 'f"PLATFORM_DIR={external / \'opensbi\'}"' in build
assert '"fdtput"' in build
assert '"linux,initrd-end"' in build
platform = (
ROOT / "app/ports/linux/opensbi/retrosoc_hp/platform.c"
).read_text(encoding="utf-8")
assert "s_hart_index_to_id[] = {1U}" in platform
assert "RETROSOC_HP_UART_BASE" in platform
assert "aclint_mtimer_cold_init" in platform
def test_hp_linux_device_tree_compiles_and_can_patch_initrd_end(tmp_path: Path) -> None:
dtc = shutil.which("dtc")
fdtput = shutil.which("fdtput")
fdtget = shutil.which("fdtget")
if dtc is None or fdtput is None or fdtget is None:
return
dtb = tmp_path / "retrosoc_hp.dtb"
subprocess.run(
[
dtc,
"-I",
"dts",
"-O",
"dtb",
"-o",
str(dtb),
str(ROOT / "app/ports/linux/linux/retrosoc_hp.dts"),
],
check=True,
capture_output=True,
text=True,
)
subprocess.run(
[fdtput, "-t", "x", str(dtb), "/chosen", "linux,initrd-end", "0x39123456"],
check=True,
)
initrd_end = subprocess.check_output(
[fdtget, "-t", "x", str(dtb), "/chosen", "linux,initrd-end"], text=True
).strip()
hart_id = subprocess.check_output(
[fdtget, "-t", "x", str(dtb), "/cpus/cpu@1", "reg"], text=True
).strip()
assert initrd_end == "39123456"
assert hart_id == "1"
dts = (ROOT / "app/ports/linux/linux/retrosoc_hp.dts").read_text(encoding="utf-8")
assert '"zicbom"' in dts
assert "riscv,cbom-block-size = <64>;" in dts