Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

运行测试

VSAG 采用 Catch2 作为测试框架,测试分为两类:

  • 单元测试:与源码同目录,位于 src/ 下,聚焦单个类/函数的行为。
  • 功能测试:位于 tests/ 目录,覆盖跨模块、端到端的索引行为。典型用例包括 test_hnsw.cpptest_hgraph.cpptest_diskann.cpptest_ivf.cpptest_pyramid.cpptest_sindi.cpptest_brute_force.cpptest_multi_thread.cpptest_memleak.cpp 等。

构建并运行全部测试

make test 会以 Debug 配置重新编译(启用 ENABLE_TESTS=ON)并运行单元与功能测试:

make test

说明:

  1. 运行 src/ 下的单元测试;
  2. 运行 tests/ 下的功能测试;
  3. make test 并未开启覆盖率(ENABLE_COVERAGE=ON)。需要覆盖率报告时请使用 make cov:该目标仅完成带覆盖率插桩的编译,随后需要手动运行测试二进制以生成报告。

仅运行单个测试二进制

构建完成后,可直接运行单个测试:

./build-debug/tests/functional_tests "[hgraph]"
./build-debug/tests/functional_tests "[hnsw][concurrent]"

Catch2 支持按名字、tag、通配符等方式筛选用例,详见 --help

覆盖率

贡献时应保持 src/include/ 下代码的行覆盖率不低于 90%。在本地执行:

make cov
# 然后运行测试二进制以采集覆盖率,例如:
./build-debug/tests/functional_tests

报告会输出到 build-debug/coverage/ 下,可用浏览器打开 index.html 查看未覆盖的分支。

内存泄漏与多线程

  • test_memleak.cpp:基于 AddressSanitizer / LeakSanitizer,对索引的构造/销毁路径进行验证。
  • test_multi_thread.cpp:验证并发 Build / KnnSearch / RangeSearch 下的正确性。

Python 测试

tests/python/ 包含 pyvsag 的 pytest 用例。构建好 pyvsag 后:

make pyvsag PY_VERSION=3.10
cd tests/python && pytest -q

参考

  • 功能测试源代码目录:tests/
  • 脚本入口:Makefile 中的 testcovasan 目标