Skip to content

Commit 4f1bce2

Browse files
feat: refactor test infrastructure with unified CMake macros
- 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>
1 parent 1e12d2e commit 4f1bce2

35 files changed

Lines changed: 2330 additions & 315 deletions

CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ include_directories(${gflags_SOURCE_DIR}/include)
4242
set(WITH_GFLAGS OFF CACHE BOOL "Disable glog finding system gflags" FORCE)
4343
set(WITH_GTEST OFF CACHE BOOL "Disable glog finding system gtest" FORCE)
4444
add_subdirectory(third_party/glog)
45-
add_compile_definitions(GLOG_USE_GLOG_EXPORT=1)
45+
# add_compile_definitions(GLOG_USE_GLOG_EXPORT=1)
4646
include_directories(${glog_SOURCE_DIR}/src)
47-
include_directories(${glog_BINARY_DIR}/glog)
47+
# include_directories(${glog_BINARY_DIR}/glog)
4848

4949
# eigen
5050
if(USE_OMP)
@@ -66,8 +66,10 @@ endif()
6666
# Framework core sources (*.cc), excluding cpu kernels (they are built separately)
6767
file(GLOB_RECURSE SRC ${PROJECT_SOURCE_DIR}/infini_train/src/*.cc)
6868
list(FILTER SRC EXCLUDE REGEX ".*kernels/cpu/.*")
69-
list(FILTER SRC EXCLUDE REGEX ".*runtime/cuda/.*")
70-
list(FILTER SRC EXCLUDE REGEX ".*ccl/cuda/.*")
69+
if(NOT USE_CUDA)
70+
list(FILTER SRC EXCLUDE REGEX ".*runtime/cuda/.*")
71+
list(FILTER SRC EXCLUDE REGEX ".*ccl/cuda/.*")
72+
endif()
7173
if(NOT USE_NCCL)
7274
list(FILTER SRC EXCLUDE REGEX ".*infini_train/src/core/ccl/cuda/.*")
7375
endif()

TEST_REPORT.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

tests/CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# Tests CMakeLists.txt
22
# This file manages the test infrastructure for InfiniTrain
33

4-
# Add test subdirectories
4+
# Include shared test macros (must be before any test subdirectory)
5+
include(${CMAKE_CURRENT_SOURCE_DIR}/common/test_macros.cmake)
6+
7+
# Common test utilities
58
add_subdirectory(common)
69

710
# Tensor tests
811
add_subdirectory(tensor)
912

10-
# Optimizer tests
13+
# Optimizer tests
1114
add_subdirectory(optimizer)
1215

1316
# Autograd operator tests
1417
add_subdirectory(autograd)
1518

19+
# LoRA tests
20+
add_subdirectory(lora)
21+
1622
# Hook tests
1723
add_subdirectory(hook)
1824

tests/autograd/CMakeLists.txt

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,56 @@
1-
# Autograd operators test
2-
3-
add_executable(test_autograd
4-
test_autograd.cc
5-
)
6-
target_link_libraries(test_autograd
7-
PRIVATE
8-
GTest::gtest
9-
GTest::gtest_main
10-
)
11-
target_include_directories(test_autograd PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../common)
12-
13-
target_link_libraries(test_autograd PRIVATE
14-
"-Wl,--whole-archive"
15-
infini_train
16-
infini_train_cpu_kernels
17-
"-Wl,--no-whole-archive"
18-
)
19-
20-
add_test(NAME autograd_cpu COMMAND test_autograd)
21-
set_tests_properties(autograd_cpu PROPERTIES LABELS "cpu")
22-
23-
add_test(NAME autograd_cuda COMMAND test_autograd --gtest_filter=AutogradTest.*CUDA)
24-
set_tests_properties(autograd_cuda PROPERTIES LABELS "cuda")
25-
26-
add_test(NAME autograd_distributed COMMAND test_autograd --gtest_filter=AutogradTest.*Distributed)
27-
set_tests_properties(autograd_distributed PROPERTIES LABELS "cuda;distributed")
1+
# ============================================================================
2+
# Autograd tests
3+
# ============================================================================
4+
# 重构版本:使用 infini_train_add_test 宏简化配置
5+
#
6+
# 新增测试只需 1 行:
7+
# infini_train_add_test(test_name SOURCES test_name.cc LABELS cpu)
8+
# ============================================================================
9+
10+
# -----------------------------------------------------------------------------
11+
# Elementwise tests
12+
# -----------------------------------------------------------------------------
13+
infini_train_add_test(test_autograd_elementwise_forward SOURCES test_autograd_elementwise_forward.cc LABELS cpu)
14+
infini_train_add_test(test_autograd_elementwise_backward SOURCES test_autograd_elementwise_backward.cc LABELS cpu)
15+
16+
# -----------------------------------------------------------------------------
17+
# Matmul tests
18+
# -----------------------------------------------------------------------------
19+
infini_train_add_test(test_autograd_matmul_forward SOURCES test_autograd_matmul_forward.cc LABELS cpu)
20+
infini_train_add_test(test_autograd_matmul_backward SOURCES test_autograd_matmul_backward.cc LABELS cpu)
21+
22+
# -----------------------------------------------------------------------------
23+
# Reduction tests
24+
# -----------------------------------------------------------------------------
25+
infini_train_add_test(test_autograd_reduction_forward SOURCES test_autograd_reduction_forward.cc LABELS cpu)
26+
infini_train_add_test(test_autograd_reduction_backward SOURCES test_autograd_reduction_backward.cc LABELS cpu)
27+
28+
# -----------------------------------------------------------------------------
29+
# Linear tests
30+
# -----------------------------------------------------------------------------
31+
infini_train_add_test(test_autograd_linear_forward SOURCES test_autograd_linear_forward.cc LABELS cpu)
32+
infini_train_add_test(test_autograd_linear_backward SOURCES test_autograd_linear_backward.cc LABELS cpu)
33+
34+
# -----------------------------------------------------------------------------
35+
# Softmax tests
36+
# -----------------------------------------------------------------------------
37+
infini_train_add_test(test_autograd_softmax_forward SOURCES test_autograd_softmax_forward.cc LABELS cpu)
38+
infini_train_add_test(test_autograd_softmax_backward SOURCES test_autograd_softmax_backward.cc LABELS cpu)
39+
40+
# -----------------------------------------------------------------------------
41+
# Transform tests
42+
# -----------------------------------------------------------------------------
43+
infini_train_add_test(test_autograd_transform_forward SOURCES test_autograd_transform_forward.cc LABELS cpu)
44+
infini_train_add_test(test_autograd_transform_backward SOURCES test_autograd_transform_backward.cc LABELS cpu)
45+
46+
# -----------------------------------------------------------------------------
47+
# Normalization tests
48+
# -----------------------------------------------------------------------------
49+
infini_train_add_test(test_autograd_normalization_forward SOURCES test_autograd_normalization_forward.cc LABELS cpu)
50+
infini_train_add_test(test_autograd_normalization_backward SOURCES test_autograd_normalization_backward.cc LABELS cpu)
51+
52+
# -----------------------------------------------------------------------------
53+
# Legacy combined tests
54+
# 注意:使用 gtest_discover_tests,所有 TEST_F 都会被自动发现
55+
# -----------------------------------------------------------------------------
56+
infini_train_add_test(test_autograd_legacy SOURCES test_autograd.cc LABELS cpu cuda distributed)

0 commit comments

Comments
 (0)