test(test): 添加测试用例
This commit is contained in:
@@ -28,7 +28,7 @@ Lab1 聚焦前端第一步:词法/语法分析。
|
||||
|
||||
1. 主要覆盖 `int main() { ... }` 这一固定函数形态。
|
||||
2. 只包含少量声明/返回/表达式能力(用于演示完整流程)。
|
||||
3. 示例用例位于 `test/test_case/simple_add.sy`。
|
||||
3. 示例用例位于 `test/test_case/function/simple_add.sy`。
|
||||
|
||||
## 5. 构建与生成流程
|
||||
|
||||
@@ -68,7 +68,7 @@ cmake --build build -j "$(nproc)"
|
||||
|
||||
```bash
|
||||
# 仅输出语法树
|
||||
./build/bin/compiler --emit-parse-tree test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-parse-tree test/test_case/function/simple_add.sy
|
||||
```
|
||||
|
||||
但最终不能只检查 `simple_add`。完成 Lab1 后,应至少对 `test/test_case` 下全部 `.sy` 用例逐个验证解析是否成功;如有需要,也可以自行编写批量测试脚本统一执行。
|
||||
|
||||
@@ -49,20 +49,20 @@ cmake --build build -j "$(nproc)"
|
||||
可先用单个样例检查 IR 输出是否基本正确:
|
||||
|
||||
```bash
|
||||
./build/bin/compiler --emit-ir test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-ir test/test_case/function/simple_add.sy
|
||||
```
|
||||
|
||||
如需打印语法树:
|
||||
|
||||
```bash
|
||||
./build/bin/compiler --emit-parse-tree test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-parse-tree test/test_case/function/simple_add.sy
|
||||
```
|
||||
|
||||
推荐使用统一脚本验证 “IR -> LLVM 后端 -> 可执行程序” 整体链路。`--run` 模式下会自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,用于验证 IR 的正确性:
|
||||
|
||||
|
||||
```bash
|
||||
./scripts/verify_ir.sh test/test_case/simple_add.sy test/test_result/ir --run
|
||||
./scripts/verify_ir.sh test/test_case/function/simple_add.sy test/test_result/function/ir --run
|
||||
```
|
||||
|
||||
但最终不能只检查 `simple_add`。完成 Lab2 后,应对 `test/test_case` 下全部测试用例逐个回归,确认 IR 生成与 `--run` 链路都能通过;如有需要,也可以自行编写批量测试脚本统一执行。
|
||||
|
||||
@@ -47,13 +47,13 @@ cmake --build build -j "$(nproc)"
|
||||
可先用单个样例检查汇编输出是否基本正确:
|
||||
|
||||
```bash
|
||||
./build/bin/compiler --emit-asm test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-asm test/test_case/function/simple_add.sy
|
||||
```
|
||||
|
||||
推荐使用统一脚本验证 “源码 -> 汇编 -> 可执行程序” 整体链路。`--run` 模式下会自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,用于验证后端代码生成的正确性:
|
||||
|
||||
```bash
|
||||
./scripts/verify_asm.sh test/test_case/simple_add.sy test/test_result/asm --run
|
||||
./scripts/verify_asm.sh test/test_case/function/simple_add.sy test/test_result/function/asm --run
|
||||
```
|
||||
|
||||
若最终输出 `输出匹配: test/test_case/simple_add.out`,说明当前示例用例 `return a + b` 的完整后端链路已经跑通。
|
||||
|
||||
@@ -79,13 +79,13 @@ cmake --build build -j "$(nproc)"
|
||||
项目编译后可先用当前示例用例检查后端链路是否仍能运行:
|
||||
|
||||
```bash
|
||||
./build/bin/compiler --emit-asm test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-asm test/test_case/function/simple_add.sy
|
||||
```
|
||||
|
||||
推荐继续使用统一脚本验证 “源码 -> 汇编 -> 可执行程序” 整体链路。`--run` 模式下会自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,用于检查单个用例的完整结果:
|
||||
|
||||
```bash
|
||||
./scripts/verify_asm.sh test/test_case/simple_add.sy test/test_result/asm --run
|
||||
./scripts/verify_asm.sh test/test_case/function/simple_add.sy test/test_result/function/asm --run
|
||||
```
|
||||
|
||||
建议在功能回归之外,再观察优化前后汇编输出差异。可按自己的实现方式保留调试日志、优化开关,或直接对比生成的汇编文本,重点关注:
|
||||
|
||||
@@ -95,7 +95,7 @@ cmake --build build -j "$(nproc)"
|
||||
### 6.1 观察 IR
|
||||
|
||||
```bash
|
||||
./build/bin/compiler --emit-ir test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-ir test/test_case/function/simple_add.sy
|
||||
```
|
||||
|
||||
这条命令只适合先观察单个样例的 IR 形态。完成 Lab5 后,不能只检查 `simple_add`,还应覆盖 `test/test_case` 下全部测试用例。
|
||||
@@ -103,8 +103,8 @@ cmake --build build -j "$(nproc)"
|
||||
### 6.2 语义回归
|
||||
|
||||
```bash
|
||||
./scripts/verify_ir.sh test/test_case/simple_add.sy test/test_result/ir --run
|
||||
./scripts/verify_asm.sh test/test_case/simple_add.sy test/test_result/asm --run
|
||||
./scripts/verify_ir.sh test/test_case/function/simple_add.sy test/test_result/function/ir --run
|
||||
./scripts/verify_asm.sh test/test_case/function/simple_add.sy test/test_result/function/asm --run
|
||||
```
|
||||
|
||||
目标:脚本自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,确保优化后程序行为与优化前保持一致。
|
||||
|
||||
@@ -59,8 +59,8 @@ cmake --build build -j "$(nproc)"
|
||||
### 7.1 功能回归
|
||||
|
||||
```bash
|
||||
./scripts/verify_ir.sh test/test_case/simple_add.sy test/test_result/ir --run
|
||||
./scripts/verify_asm.sh test/test_case/simple_add.sy test/test_result/asm --run
|
||||
./scripts/verify_ir.sh test/test_case/function/simple_add.sy test/test_result/function/ir --run
|
||||
./scripts/verify_asm.sh test/test_case/function/simple_add.sy test/test_result/function/asm --run
|
||||
```
|
||||
|
||||
`--run` 模式下脚本会自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对。
|
||||
@@ -71,8 +71,8 @@ cmake --build build -j "$(nproc)"
|
||||
|
||||
```bash
|
||||
# 对比优化前后 IR/汇编输出(按你实现的开关或日志方式执行)
|
||||
./build/bin/compiler --emit-ir test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-asm test/test_case/simple_add.sy
|
||||
./build/bin/compiler --emit-ir test/test_case/function/simple_add.sy
|
||||
./build/bin/compiler --emit-asm test/test_case/function/simple_add.sy
|
||||
```
|
||||
|
||||
这里的 `simple_add` 只用于展示如何观察单个样例的输出差异;实际评估优化效果时,仍应结合更多测试用例,必要时覆盖全部测试集。
|
||||
|
||||
Reference in New Issue
Block a user