-
Notifications
You must be signed in to change notification settings - Fork 43
Feat(tests): build test infrastructure #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chen2021673
wants to merge
8
commits into
master
Choose a base branch
from
CTest-clean
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
145f2ce
feat: expand test infrastructure
luoyueyuguang b1362bb
feat: refactor test infrastructure with unified CMake macros
luoyueyuguang 3f0d407
fix: make distributed labels selectable
luoyueyuguang deaf898
refactor(tests): migrate to device-parametrized TEST_P infrastructure
chen2021673 fc98438
refactor(tests): remove platform distinction, unify test infrastructure
chen2021673 56c341e
docs: add test usage guide and rename doc files for consistency
chen2021673 72bc022
fix(tests): prevent GlobalEnv double-init crash in multi-suite binaries
chen2021673 88b5359
refactor(tests): streamline test fixtures and framework APIs
chen2021673 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
|
kilinchange marked this conversation as resolved.
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # ============================================================================ | ||
| # InfiniTrain Test Macros | ||
| # ============================================================================ | ||
| # Unified test configuration interface to reduce boilerplate. | ||
| # | ||
| # Usage: | ||
| # 1. Include this file in tests/CMakeLists.txt | ||
| # 2. Use infini_train_add_test macro to register tests | ||
| # | ||
| # Examples: | ||
| # infini_train_add_test( | ||
| # test_tensor_create | ||
| # SOURCES test_tensor_create.cc | ||
| # LABELS cpu cuda | ||
| # ) | ||
| # ============================================================================ | ||
|
|
||
| include_guard(GLOBAL) | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # Load GoogleTest module (provides gtest_discover_tests) | ||
| # ----------------------------------------------------------------------------- | ||
| include(GoogleTest) | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # infini_train_add_test - Test registration macro | ||
| # ----------------------------------------------------------------------------- | ||
| # Features: | ||
| # 1. Create executable target | ||
| # 2. Configure compile options, link libraries, and include paths | ||
| # 3. Use gtest_discover_tests to auto-discover test cases | ||
| # 4. Set test labels | ||
| # | ||
| # Arguments: | ||
| # SOURCES: Source file list (required) | ||
| # LABELS: Test labels, e.g. "cpu" "cuda" "distributed" (optional, default "cpu") | ||
| # TEST_FILTER: gtest test filter pattern (optional) | ||
| # | ||
| # Examples: | ||
| # # Single-label test (one liner) | ||
| # infini_train_add_test(test_example SOURCES test_example.cc LABELS cpu) | ||
| # | ||
| # # Filter same binary by label suffix (one call per label) | ||
| # infini_train_add_test(test_example SOURCES test_example.cc LABELS cpu TEST_FILTER "-*CUDA*") | ||
| # infini_train_add_test(test_example_cuda SOURCES test_example.cc LABELS cuda TEST_FILTER "*CUDA*") | ||
| # ----------------------------------------------------------------------------- | ||
| macro(infini_train_add_test) | ||
| cmake_parse_arguments(ARG "" "TEST_NAME;TEST_FILTER" "SOURCES;LABELS" ${ARGN}) | ||
|
|
||
| if(NOT ARG_TEST_NAME) | ||
| set(ARG_TEST_NAME ${ARG_UNPARSED_ARGUMENTS}) | ||
| endif() | ||
|
|
||
| if(NOT ARG_SOURCES) | ||
| message(FATAL_ERROR "infini_train_add_test: TEST_NAME and SOURCES are required") | ||
| endif() | ||
|
|
||
| # 1. Create executable target | ||
| add_executable(${ARG_TEST_NAME} ${ARG_SOURCES} $<TARGET_OBJECTS:test_main>) | ||
|
|
||
| # 2. Disable -Werror so tests can run under relaxed warning levels | ||
| target_compile_options(${ARG_TEST_NAME} PRIVATE -Wno-error) | ||
|
|
||
| # 3. Link Google Test (uses custom main from test_main that initializes GlobalEnv) | ||
| target_link_libraries(${ARG_TEST_NAME} PRIVATE GTest::gtest) | ||
|
|
||
| # 4. Add include paths | ||
| target_include_directories(${ARG_TEST_NAME} PRIVATE | ||
| ${glog_SOURCE_DIR}/src | ||
| ) | ||
|
|
||
| # 5. Link project library (reuses framework linking strategy) | ||
| link_infini_train_exe(${ARG_TEST_NAME}) | ||
|
|
||
| # 6. Auto-discover gtest cases and register as ctest tests | ||
| set(labels "cpu") | ||
| if(ARG_LABELS) | ||
| set(labels "${ARG_LABELS}") | ||
| endif() | ||
|
|
||
| if(ARG_TEST_FILTER) | ||
| gtest_discover_tests(${ARG_TEST_NAME} | ||
| EXTRA_ARGS --gtest_output=xml:%T.xml | ||
| TEST_FILTER "${ARG_TEST_FILTER}" | ||
| DISCOVERY_TIMEOUT 10 | ||
| PROPERTIES LABELS "${labels}" TIMEOUT 10 | ||
| ) | ||
| else() | ||
| gtest_discover_tests(${ARG_TEST_NAME} | ||
| EXTRA_ARGS --gtest_output=xml:%T.xml | ||
| PROPERTIES LABELS "${labels}" TIMEOUT 10 | ||
| ) | ||
| endif() | ||
| endmacro() | ||
|
|
||
| # ----------------------------------------------------------------------------- | ||
| # infini_train_add_test_suite - Register cpu/cuda/distributed targets in one call | ||
| # ----------------------------------------------------------------------------- | ||
| # Calls infini_train_add_test three times (or fewer) with the correct | ||
| # TEST_FILTER and LABELS derived from the label list. | ||
| # | ||
| # Arguments: | ||
| # <name> Base name; each target is named <name>_<label> | ||
| # SOURCES Source file list (required) | ||
| # LABELS Subset of {cpu cuda} (optional, default: both) | ||
| # | ||
| # Examples: | ||
| # infini_train_add_test_suite(test_tensor SOURCES ${TENSOR_TEST_SOURCES}) | ||
| # infini_train_add_test_suite(test_lora SOURCES test_lora.cc LABELS cpu) | ||
| # ----------------------------------------------------------------------------- | ||
| macro(infini_train_add_test_suite) | ||
| cmake_parse_arguments(SUITE "" "" "SOURCES;LABELS" ${ARGN}) | ||
| set(_suite_name ${SUITE_UNPARSED_ARGUMENTS}) | ||
|
|
||
| if(NOT SUITE_LABELS) | ||
| set(SUITE_LABELS cpu cuda) | ||
| endif() | ||
|
|
||
| foreach(_label IN LISTS SUITE_LABELS) | ||
| string(TOUPPER ${_label} _label_upper) | ||
| set(_filter "${_label_upper}/*") | ||
| infini_train_add_test(${_suite_name}_${_label} | ||
| SOURCES ${SUITE_SOURCES} | ||
| LABELS ${_label} | ||
| TEST_FILTER "${_filter}" | ||
| ) | ||
| endforeach() | ||
| endmacro() |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.