- sync_rtl/common/: skid_buffer, pipeline_reg, defines (valid/ready) - sync_rtl/mod_add/: modular adder example with Verilator C++ TB - test_framework/: Python-driven Verilator compile/sim/compare pipeline - test_framework/modules/mod_add/: 50-vector test plan, full鏈路 PASS - .trellis/spec/: RTL and test_framework conventions documented
2.4 KiB
2.4 KiB
Test Framework Structure
Directory Layout
test_framework/
├── run_all.py # CLI entry: --module, --case, --list, --quick
├── config.json # Verilator path, clock period, timeouts
├── lib/
│ ├── test_runner.py # Discovery, compile, run, compare pipeline
│ ├── sim_controller.py # Verilator compiles/run wrapper
│ ├── vector_gen.py # Base class for vector generators
│ ├── result_checker.py # Hex-file comparison
│ └── reporter.py # Terminal + HTML output
├── modules/
│ └── <module>/
│ ├── test_plan.json # Module test definition
│ ├── gen_vectors.py # Vector generator (subclass of VectorGenerator)
│ └── vectors/ # Generated hex files (auto-cleaned)
└── reports/
├── latest/
└── history/
test_plan.json Schema
{
"module": "<name>",
"rtl_top": "sync_rtl/<path>/<top>.v",
"rtl_deps": ["sync_rtl/common/<dep>.v"],
"tb_cpp": "sync_rtl/<path>/TB/tb_<top>.cpp",
"simulator": "verilator",
"timeout_s": 30,
"cases": [{
"id": "<case_id>",
"description": "<what this tests>",
"params": {},
"num_vectors": 50,
"tolerance": "bit_exact"
}]
}
rtl_top: top module basename (without .v) is used as Verilator--top-modulertl_deps: listed beforertl_topin Verilator command linetolerance: "bit_exact" uses result_checker.py; otherwise delegates to gen_vectors.compare_results()
Vector Generator Contract
Each module's gen_vectors.py must:
- Subclass
VectorGeneratorfromtest_framework.lib.vector_gen - Implement
generate_one(params) -> dictreturning{"input": {...}, "expected": {...}} - Override
write_hex_file(vectors, filepath)for input format - Override
write_expected_file(vectors, filepath)for expected format
The framework auto-discovers the generator class by scanning for subclasses of VectorGenerator.
Adding a New Module
- Create
test_framework/modules/<name>/test_plan.json - Create
test_framework/modules/<name>/gen_vectors.py - Create
sync_rtl/<name>/<name>_sync.v(RTL) - Create
sync_rtl/<name>/TB/tb_<name>.cpp(Verilator C++ TB) - Run
python3 test_framework/run_all.py --listto verify discovery - Run
python3 test_framework/run_all.py --module <name>to test