cli 教程
本教程介绍如何构建 floating-conformance 可执行文件,并通过它运行四个符合性运行器:既可以直接调用,也可以借助 just conformance 工具链,由它下载整套语料并规划执行。
| 我想要 | 使用 |
|---|---|
| 构建可执行文件并查看其用法 | run … tooling/src/cli -- --help |
| 运行 decTest、ITL、MPFR 或 TestFloat 数据 | --backend gda, itl, mpfr, testfloat |
| 并行运行完整的固定版本语料 | just conformance … |
| 在脚本中使用结果 | 退出码与 --json |
| 查看某个运行器的选项 | 各运行器的教程 |
快速入门
该可执行文件仅支持 native 目标,需从仓库的检出副本构建,而不是通过 moon add 安装。在仓库根目录下构建它并打印用法行:
sh tools/run_moon_clean_exec.sh run --release --target native tooling/src/cli -- --help
usage: floating-conformance --backend <gda|testfloat|mpfr|itl> [backend options]
运行仓库中提交的 GDA 冒烟测试文件(即 gda 运行器的默认路径):
sh tools/run_moon_clean_exec.sh run --release --target native tooling/src/cli -- --backend gda
运行器打印一份摘要;当所有可执行行都通过时,进程以 0 退出。
日常任务
选择后端
分发器自身选项之后的所有参数都会传给运行器:
floating-conformance --backend gda --json testdata/decimal_gda/smoke.decTest
floating-conformance --backend itl testdata/interval/smoke.itl
floating-conformance --backend mpfr --json testdata/binary/mpfr-4.2.2-elementary.txt
floating-conformance --backend testfloat --function f64_mul --rounding rnear_even vectors.tv
(floating-conformance 代指构建出的可执行文件,例如 _build/conformance/gda/native/release/build/gda-conformance.exe。)
用工具链代替直接调用
对于完整语料,让 tools/conformance.py 来构建可执行文件、获取固定版本的数据、规划各阶段并行运行各分片:
just conformance build decimal_gda
just conformance smoke binary
just conformance run interval
just gate decimal_gda 8
解读退出码
0 表示成功,1 表示有失败的用例(对 itl 还包括诊断用例;在严格模式下还包括不支持的用例),2 表示用法、文件或解析错误。脚本应检查退出码;使用 --json 时,再解析标准输出上的那一个 JSON 对象。
深入了解
- 每个运行器都有各自的选项;参见 gda_expr_cli、itl_expr_cli、mpfr_expr_cli 和 testfloat_expr_cli 的教程。
- 若要在 MoonBit 代码中执行语料而不启动进程,可直接调用前端,例如 gda_expr。
常见陷阱
--help属于分发器。--backend gda --help打印分发器的用法并以0退出;它不会显示运行器的选项。- 默认路径是相对路径。 运行器默认读取
testdata/下的文件;请在仓库根目录下运行。 - 每次调用只能使用一个后端。
--backend只能给出一次。 - 空目录不是错误。
gda运行器拒绝没有.decTest后缀的指定文件(not a .decTest file: PATH,退出码2),但目录只贡献其直接包含的.decTest文件,因此不含任何此类文件的目录会产生一次以0退出的空运行。
后续步骤
- cli API:确切的选项与退出码。
- internal/runner_cli:共享的选项解析器。
- cli 设计:分层结构。
- 验证:已发布的语料声明。