Feat(tests): build test infrastructure#144
Merged
Merged
Conversation
f174886 to
073a4b6
Compare
073a4b6 to
20b735c
Compare
kilinchange
requested changes
May 7, 2026
- 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/.
kilinchange
requested changes
May 11, 2026
| #endif | ||
|
|
||
| #include "infini_train/include/device.h" | ||
| #include "gtest/gtest.h" |
Collaborator
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" |
Collaborator
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.
Contributor
Author
kilinchange
approved these changes
May 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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