用于测试RISC-V编译器的Python脚本,支持单个文件和批量测试,包含运行、调试和性能对比功能。
python test.py <command> <source> [options] [compiler_cmds...]run: 运行测试debug: 调试模式(生成带调试信息的可执行文件)bench: 性能对比测试(需要提供多个编译器命令)
source: 源文件(.sy)或包含多个测试文件的目录compiler_cmds: 编译指令--lib: 指定静态库路径(默认使用脚本目录下的lib/libsysy_riscv.a)--simulator: 指定模拟器(默认qemu-riscv64)--runs: benchmark运行次数(默认3)--in: 指定输入文件 (不指定时从标准输入读取)--out: 指定期望输出文件
- 单个文件测试:
test.py run test.sy --in test.in --out test.out -- compiler -S- 调试模式:
test.py debug test.sy -- compiler -S- 批量测试目录中的所有文件:
test.py run tests -- compiler -S- 性能对比测试:
test.py bench test.sy --in test.in -- compiler -O0 ";" compiler -O2 ";" compiler -O3- Python 3.x
- RISC-V工具链(riscv64-linux-gnu-gcc)
- QEMU模拟器(qemu-riscv64, qemu-user)
- 批量测试时,测试文件需要与对应的.in/.out文件同名
- 期望输出文件的最后一行应为期望的返回值
- 性能对比测试需要至少两个不同的编译器命令, 用分号分隔
- 用riscv64-linux-gnu-gcc/clang编译
.sy文件需要指定参数-x c -Wno-implicit-function-declaration;starttime,stoptime在库文件中的实际名称是_sysy_starttime和_sysy_starttime