#!/usr/bin/env python3 """Current-run software verification entrypoint for 6400-front-rear-v1.""" from __future__ import annotations import argparse import json from pathlib import Path import subprocess import sys import tempfile ROOT = Path(__file__).resolve().parents[1] CLOSURE = ROOT / "products/6400-control/source-closure.json" TESTBENCHES = ( "host_port_selector_tb", "bmc_ascii_snapshot_tb", "thermal_control_core_tb", ) PWM_TESTBENCH = "pwm_bitmap_engine_tb" UART_CANDIDATE_SOURCES = ( "src/common/uart_rx_byte.v", "src/common/uart_tx_byte.v", "src/common/uart_rx_byte_fractional.v", "src/common/uart_tx_byte_fractional.v", ) def sources() -> list[str]: value = json.loads(CLOSURE.read_text(encoding="utf-8")) return [item for item in value["sources"] if item.endswith(".v")] def run(argv: list[str]) -> None: print("+ " + " ".join(argv), flush=True) subprocess.run(argv, cwd=ROOT, check=True) def generate(check: bool = True) -> None: argv = ["python3", "tools/generate_6400_v1.py"] if check: argv.append("--check") run(argv) def lint() -> None: run([ "verilator", "--lint-only", "--Wall", "-Wno-fatal", "-Wno-MULTITOP", "-I.", "--top-module", "prod2u_6400_v1_top", *sources(), ]) script = "read_verilog -I. " + " ".join(sources()) + "; hierarchy -check -top prod2u_6400_v1_top; proc; check" run(["yosys", "-q", "-p", script]) def simulation() -> None: with tempfile.TemporaryDirectory(prefix="prod2u-6400-sim-") as directory: temp = Path(directory) for name in TESTBENCHES: output = temp / f"{name}.vvp" run([ "iverilog", "-g2012", "-Wall", "-I.", "-s", name, "-o", str(output), *sources(), f"tests/sim/{name}.v", ]) run(["vvp", str(output)]) run([ "iverilog", "-g2012", "-Wall", "-I.", "-s", "prod2u_6400_v1_top", "-o", str(temp / "top.vvp"), *sources(), ]) output = temp / "uart_baud_candidates_tb.vvp" run([ "iverilog", "-g2012", "-Wall", "-I.", "-s", "uart_baud_candidates_tb", "-o", str(output), *UART_CANDIDATE_SOURCES, "tests/sim/uart_baud_candidates_tb.v", ]) run(["vvp", str(output)]) def pwm_acceptance() -> None: with tempfile.TemporaryDirectory(prefix="prod2u-6400-pwm-") as directory: output = Path(directory) / f"{PWM_TESTBENCH}.vvp" run([ "iverilog", "-g2012", "-Wall", "-I.", "-s", PWM_TESTBENCH, "-o", str(output), *sources(), f"tests/sim/{PWM_TESTBENCH}.v", ]) run(["vvp", str(output)]) def unit() -> None: run([ "pytest", "-q", "tests/unit/test_6400_v1_contract.py", "tests/unit/test_6400_v1_source_closure.py", ]) def cocotb_integration() -> None: run(["python3", "tests/cocotb/run_6400_v1_integration.py"]) def bmc_fuzz() -> None: run(["python3", "tests/cocotb/run_6400_bmc_fuzz.py"]) def pi_differential() -> None: run(["python3", "tests/cocotb/run_6400_pi_differential.py"]) def main() -> int: parser = argparse.ArgumentParser() parser.add_argument( "action", choices=("generate", "lint", "sim", "cocotb", "bmc", "pwm", "pi", "unit", "all"), ) args = parser.parse_args() if args.action in ("generate", "all"): generate() if args.action in ("lint", "all"): lint() if args.action in ("sim", "all"): simulation() if args.action in ("pwm", "all"): pwm_acceptance() if args.action in ("cocotb", "all"): cocotb_integration() if args.action in ("bmc", "all"): bmc_fuzz() if args.action in ("pi", "all"): pi_differential() if args.action in ("unit", "all"): unit() return 0 if __name__ == "__main__": try: sys.exit(main()) except subprocess.CalledProcessError as exc: sys.exit(exc.returncode)