Feat(tests): build test infrastructure#144
Conversation
f174886 to
073a4b6
Compare
073a4b6 to
20b735c
Compare
| } | ||
|
|
||
| TEST_P(TensorCopyTest, CopiesCPUToCUDA) { | ||
| ONLY_CUDA(); |
There was a problem hiding this comment.
这种语义上就不应该有 cpu 的版本,但实际上还是注册了 cpu 的版本,虽然被 skip 了,但感觉还是有点怪:
- not use cuda 时这个函数不应该被编译;
- 即使 use cuda,也不应该注册 cpu 版本(那也没有 TEST_P 的必要了),可能需要改一下注册函数体现这种例外。
There was a problem hiding this comment.
对的,现在这样skip是因为编译期感知不到测例内部的信息。如果要在编译期进行控制,那就需要用#ifdef USE_CUDA + TEST_F/TEST,另外也不能用infini_train_add_test_suite,要用CUDA-only test 注册方式。我觉得如果这种ONLY_CUDA/ONLY_CPU的测例确认是极少数的话可以不这么搞,用冗余滞后的跳过逻辑保留注册清晰度?
There was a problem hiding this comment.
需要用#ifdef USE_CUDA + TEST_F/TEST,另外也不能用infini_train_add_test_suite,要用CUDA-only test 注册方式。
是的,我的意思也是倾向这么实现,考虑到后面还要支持其他平台,还是在编译期就直接拦截不应该被编译的 suite,否则之后每个平台都会带上一批与当前平台无关的测试编译,引入不必要的平台耦合(不排除后续可能会有在测例中直接调用 runtime api 的情况,可能导致编译就直接无法通过)。
There was a problem hiding this comment.
好的,我做修改。ONLY_CPU()测试也做同样改动吗?
- Add infini_train_add_test CMake macro for simplified test registration - Integrate gtest_discover_tests for automatic test case discovery - Refactor all test directories to use unified macro (autograd, optimizer, hook, slow, lora) - Reduce test CMakeLists.txt code by 68% - Add LoRA tests (12 test cases) - Delete TEST_REPORT.md - Test labels: cpu/cuda/distributed/slow for flexible test execution - Add shared test_macros.cmake in tests/common/ BREAKING CHANGE: Test registration now uses macro instead of manual add_test() Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Replace TEST_F with TEST_P across all test suites so each suite runs on both CPU and CUDA without duplicating test logic. Adds InfiniTrainTestP, TensorTestBaseP, AutogradTestBaseP, and DistributedInfiniTrainTestP base classes with automatic CUDA/NCCL skip guards. Introduces INFINI_TRAIN_REGISTER_TEST* C++ macros and infini_train_add_test_suite CMake macro to eliminate repetitive INSTANTIATE_TEST_SUITE_P / infini_train_add_test boilerplate. Removes deprecated test/, slow/, and split optimizer test files; consolidates optimizer tests into a single binary with creation + step suites.
- Simplify CMakeLists: single CTest target per suite, remove label splitting - Migrate old test/ directory into tests/ and delete test/
- Add docs/test_usage_guide.md with build/run/write instructions - Rename hook_mechanism.md → hook_mechanism_design.md - Rename lora_usage.md → lora_usage_guide.md - Add googletest as submodule in .gitmodules - Add infini_run tool target in CMakeLists.txt, remove stale comments
Add IsInitialized() to GlobalEnv and guard SetUpTestSuite so a second test class in the same process skips re-initialization instead of hitting CHECK(!initialized_). Also print try_compile output on compile-fail test to surface header-not-found vs real type errors.
- Add requires_grad default parameter to Tensor ctor so tests can construct autograd-enabled tensors without a fixture helper. - Remove InfiniTrainTest::createTensor, AutogradTestBase, and FillConstantTensor; call sites use std::make_shared<Tensor>(...) and Tensor::Fill(value) directly. - Replace gtest_main with a custom tests/common/test_main.cc that initializes GlobalEnv once before RUN_ALL_TESTS, eliminating the need for GlobalEnv::IsInitialized and per-suite SetUpTestSuite init guards. - Gate CUDA test registration on USE_CUDA: when disabled, the CUDA parameterization is simply not instantiated instead of skipped at runtime. - Move test_macros.cmake to cmake/ and include test headers via full project-root paths. - Drop tests' dependency on example/*/config.h; TransformerModule tests now construct TransformerConfig directly. - Add SanitizeGPT2Config / SanitizeLLaMA3Config in example/.
| #endif | ||
|
|
||
| #include "infini_train/include/device.h" | ||
| #include "gtest/gtest.h" |
There was a problem hiding this comment.
gtest 作为 third_party 头文件,应当放在本项目头文件上方的单独分组中。
| #include "infini_train/include/autograd/transform.h" | ||
| #include "infini_train/include/tensor.h" | ||
| #include "tests/common/test_utils.h" | ||
| #include "gtest/gtest.h" |
There was a problem hiding this comment.
https://gxtctab8no8.feishu.cn/docx/ARFVdldxPo87zHxIXe4c5LMwnNl#share-NPX0dbmvDoyvkExhH1QclVMknch
third_party 头文件引用(gtest.h)和本项目的内部实现头文件引用(test_utils.h)的位置需要修正,其他文件同理。
- Move gtest header into its own include group between stdlib and project headers across all test sources, per project convention that third-party headers sit separately above project includes. - Split device-specific tests in tests/tensor/ into cpu_only/ and cuda_only/ subdirectories, each built as an independent test target; CUDA-only tests are skipped when USE_CUDA=OFF.
Summary
This PR refactors InfiniTrain’s test infrastructure around CTest and GoogleTest.
It consolidates the old test/ and tests/ layout into a single tests/ directory, introduces shared CMake utilities for test registration, and migrates applicable tests to device-parameterized TEST_P so CPU/CUDA cases can share the same test logic where appropriate.
Closes #120.
Changes
How to run
Impact
This is mainly a test infrastructure refactor. It is not intended to change training/runtime behavior, but it does change how tests are organized and registered.
Result
ctest --output-on-failurectest -L cpu --output-on-failurectest -L cuda --output-on-failure