chore(dev): 调整test用例结构

master
jing 5 days ago
parent b26c40f6ad
commit 10ea8aad14

2
.gitignore vendored

@ -27,7 +27,7 @@ compile_commands.json
*.dll
*.exe
*.out
!test/test_case/*.out
!test/test_case/**/*.out
*.app
*.pdb
*.ilk

@ -91,7 +91,7 @@ cmake --build build -j "$(nproc)"
跑完整编译流程自检:从 SysY 源码生成 AArch64 汇编,完成汇编、链接,在 QEMU 下运行结果程序,并与 `test/test_case` 下同名 `.out` 自动比对:
```bash
./scripts/verify_asm.sh test/test_case/function/simple_add.sy test/test_result/function/asm --run
./scripts/verify_asm.sh test/test_case/functional/simple_add.sy test/test_result/function/asm --run
```
如果最终看到 `输出匹配: test/test_case/simple_add.out`,说明当前示例用例 `return a + b` 的完整链路已经跑通。

@ -28,7 +28,7 @@ Lab1 聚焦前端第一步:词法/语法分析。
1. 主要覆盖 `int main() { ... }` 这一固定函数形态。
2. 只包含少量声明/返回/表达式能力(用于演示完整流程)。
3. 示例用例位于 `test/test_case/function/simple_add.sy`。
3. 示例用例位于 `test/test_case/functional/simple_add.sy`。
## 5. 构建与生成流程
@ -68,7 +68,7 @@ cmake --build build -j "$(nproc)"
```bash
# 仅输出语法树
./build/bin/compiler --emit-parse-tree test/test_case/function/simple_add.sy
./build/bin/compiler --emit-parse-tree test/test_case/functional/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/function/simple_add.sy
./build/bin/compiler --emit-ir test/test_case/functional/simple_add.sy
```
如需打印语法树:
```bash
./build/bin/compiler --emit-parse-tree test/test_case/function/simple_add.sy
./build/bin/compiler --emit-parse-tree test/test_case/functional/simple_add.sy
```
推荐使用统一脚本验证 “IR -> LLVM 后端 -> 可执行程序” 整体链路。`--run` 模式下会自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,用于验证 IR 的正确性:
```bash
./scripts/verify_ir.sh test/test_case/function/simple_add.sy test/test_result/function/ir --run
./scripts/verify_ir.sh test/test_case/functional/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/function/simple_add.sy
./build/bin/compiler --emit-asm test/test_case/functional/simple_add.sy
```
推荐使用统一脚本验证 “源码 -> 汇编 -> 可执行程序” 整体链路。`--run` 模式下会自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,用于验证后端代码生成的正确性:
```bash
./scripts/verify_asm.sh test/test_case/function/simple_add.sy test/test_result/function/asm --run
./scripts/verify_asm.sh test/test_case/functional/simple_add.sy test/test_result/function/asm --run
```
若最终输出 `输出匹配: test/test_case/simple_add.out`,说明当前示例用例 `return a + b` 的完整后端链路已经跑通。

@ -95,7 +95,7 @@ cmake --build build -j "$(nproc)"
### 6.1 观察 IR
```bash
./build/bin/compiler --emit-ir test/test_case/function/simple_add.sy
./build/bin/compiler --emit-ir test/test_case/functional/simple_add.sy
```
这条命令只适合先观察单个样例的 IR 形态。完成 Lab4 后,不能只检查 `simple_add`,还应覆盖 `test/test_case` 下全部测试用例。
@ -103,8 +103,8 @@ cmake --build build -j "$(nproc)"
### 6.2 语义回归
```bash
./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
./scripts/verify_ir.sh test/test_case/functional/simple_add.sy test/test_result/function/ir --run
./scripts/verify_asm.sh test/test_case/functional/simple_add.sy test/test_result/function/asm --run
```
目标:脚本自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,确保优化后程序行为与优化前保持一致。

@ -79,13 +79,13 @@ cmake --build build -j "$(nproc)"
项目编译后可先用当前示例用例检查后端链路是否仍能运行:
```bash
./build/bin/compiler --emit-asm test/test_case/function/simple_add.sy
./build/bin/compiler --emit-asm test/test_case/functional/simple_add.sy
```
推荐继续使用统一脚本验证 “源码 -> 汇编 -> 可执行程序” 整体链路。`--run` 模式下会自动读取同名 `.in`,并将程序输出与退出码和同名 `.out` 比对,用于检查单个用例的完整结果:
```bash
./scripts/verify_asm.sh test/test_case/function/simple_add.sy test/test_result/function/asm --run
./scripts/verify_asm.sh test/test_case/functional/simple_add.sy test/test_result/function/asm --run
```
建议在功能回归之外,再观察优化前后汇编输出差异。可按自己的实现方式保留调试日志、优化开关,或直接对比生成的汇编文本,重点关注:

@ -59,8 +59,8 @@ cmake --build build -j "$(nproc)"
### 7.1 功能回归
```bash
./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
./scripts/verify_ir.sh test/test_case/functional/simple_add.sy test/test_result/function/ir --run
./scripts/verify_asm.sh test/test_case/functional/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/function/simple_add.sy
./build/bin/compiler --emit-asm test/test_case/function/simple_add.sy
./build/bin/compiler --emit-ir test/test_case/functional/simple_add.sy
./build/bin/compiler --emit-asm test/test_case/functional/simple_add.sy
```
这里的 `simple_add` 只用于展示如何观察单个样例的输出差异;实际评估优化效果时,仍应结合更多测试用例,必要时覆盖全部测试集。

@ -1,5 +1,5 @@
#!/usr/bin/env bash
# ./scripts/verify_ir.sh test/test_case/function/simple_add.sy test/test_result/function/ir --run
# ./scripts/verify_ir.sh test/test_case/functional/simple_add.sy test/test_result/function/ir --run
set -euo pipefail

@ -62,5 +62,5 @@ void PrintHelp(std::ostream& os) {
<< " - 默认输出 IR\n"
<< " - 若使用 --emit-parse-tree/--emit-ir/--emit-asm则仅输出显式选择的阶段\n"
<< " - 可使用重定向写入文件:\n"
<< " compiler --emit-asm test/test_case/function/simple_add.sy > out.s\n";
<< " compiler --emit-asm test/test_case/functional/simple_add.sy > out.s\n";
}

@ -0,0 +1,5 @@
110 70 30
278 174 70
446 278 110
614 382 150
0

@ -0,0 +1,19 @@
ok
ok
ok
ok
ok
ok
ok
ok
0x1.e691e6p+1 3
0x1.e691e6p+3 12
0x1.11b21p+5 28
0x1.e691e6p+5 50
0x1.7c21fcp+6 78
0x1.11b21p+7 113
0x1.7487b2p+7 153
0x1.e691e6p+7 201
0x1.33e85p+8 254
10: 0x1.333334p+0 0x1.333334p+1 0x1.ccccccp+1 0x1.333334p+2 0x1.8p+2 0x1.ccccccp+2 0x1.0cccccp+3 0x1.333334p+3 0x1.599998p+3 0x1p+0
0

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -0,0 +1,51 @@
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
......................##..........................
.....................####.........................
....................#....#........................
...................##....##.......................
...................##....##.......................
....................#....#........................
.....................####.........................
......................##..........................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
0
Loading…
Cancel
Save