Introduction to the Test Bench Generator
Repository: https://github.com/StanfordAHA/TestBenchGenerator
The Test Bench Generator is a Python script that produces a C++ Verilator harness for testing the RTL generated by CGRAGenerator.
The generated harness is specalized to a bitstream, uses file based IO,
supports tracing (waveforms), and two modes for configuration the CGRA
(use_jtag
).
The generator relies on IO collateral (.io.json
) produced by PnR to specify
the mapping between inputs/outputs to pads (including the reset pin).
It also includes pre and post processing scripts for input and output files for the CGRAFlow integration test bench.
Help
$ python generate_harness.py --help
usage: generate_harness.py [-h] --pnr-io-collateral <collateral_file>.io.json
--bitstream <BITSTREAM_FILE>
[--trace-file TRACE_FILE]
[--max-clock-cycles MAX_CLOCK_CYCLES]
[--wrapper-module-name WRAPPER_MODULE_NAME]
[--chunk-size CHUNK_SIZE]
[--output-file-name OUTPUT_FILE_NAME] [--use-jtag]
[--verify-config] [--trace]
[--trace-file-name TRACE_FILE_NAME] [--quiet]
Test the cgra
optional arguments:
-h, --help show this help message and exit
--pnr-io-collateral <collateral_file>.io.json
Collateral file generated by SMT-PNR
--bitstream <BITSTREAM_FILE>
Bitstream file containing the CGRA configuration
--trace-file TRACE_FILE
Trace file
--max-clock-cycles MAX_CLOCK_CYCLES
Max number of clock cyles to run
--wrapper-module-name WRAPPER_MODULE_NAME
Name of the wrapper module
--chunk-size CHUNK_SIZE
Size in bits of the data in the input/output files
--output-file-name OUTPUT_FILE_NAME
Name of the generated harness file
--use-jtag Should this test harness use JTAG to write config
--verify-config Should this test harness read back all the config
after writing
--trace Dump a .vcd using verilator. **NOTE**: If you add the
--trace flag, you must use it both with
generate_harness.py and verilate.py. Also, you must
either use --force-rebuild with verilate.py or be sure
to remove any existing verilator binary, e.g. rm -r
CGRAGenerator/verilator/generator_z_tb/build/*. One
way to do this would be through a make clean rule
--trace-file-name TRACE_FILE_NAME
--quiet Silence cycle counter
$ python verilate.py --help
usage: verilate.py [-h] [--top-module-name TOP_MODULE_NAME]
[--harness HARNESS] [--verilog-directory VERILOG_DIRECTORY]
[--force-rebuild] [--output-directory OUTPUT_DIRECTORY]
[--trace]
Verilator wrapper
optional arguments:
-h, --help show this help message and exit
--top-module-name TOP_MODULE_NAME
Top module name
--harness HARNESS Path to harness file
--verilog-directory VERILOG_DIRECTORY
Directory containing verilog files to include in the
verilator command
--force-rebuild Run verilator even if there's an existing binary
--output-directory OUTPUT_DIRECTORY
Directory to place verilator output files
--trace Dump a .vcd using verilator. **NOTE**: If you add the
--trace flag, you must use it both with
generate_harness.py and verilate.py. Also, you must
either use --force-rebuild with verilate.py or be sure
to remove any existing verilator binary, e.g. rm -r
CGRAGenerator/verilator/generator_z_tb/build/*. One
way to do this would be through a make clean rule
Example Usage
python generate_harness.py \
--pnr-io-collateral tests/conv_bw/conv_bw.io.json \
--bitstream tests/conv_bw/conv_bw_pnr_bitstream \
--max-clock-cycles 5000000 \
--output-file-name build/harness.cpp
python verilate.py \
--harness build/harness.cpp \
--verilog-directory ../CGRAGenerator/hardware/generator_z/top/genesis_verif/ \
--output-directory build \
--top-module-name top
Pages
- Harness Generation - Overview of how harness are generated
- .io.json format - Overview of the file format for collateral generated by PnR
- Pre/Post Processing - Overview of pre/post processing scripts
- Roadmap - Plans for new features and internal changes