[libc-commits] [libc] [libc][NFC] Add few options to allow users to skip building and running some tests. (PR #199474)
via libc-commits
libc-commits at lists.llvm.org
Fri May 29 08:50:22 PDT 2026
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/199474
>From c61565fcf3ae469271efb254add43b7f13a286fa Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 25 May 2026 18:43:57 +0000
Subject: [PATCH 1/4] [libc][NFC] Add few options to allow users to skip
building and running some tests.
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 6 ++++++
libc/test/CMakeLists.txt | 16 +++++++++++++---
libc/test/UnitTest/LibcTest.h | 9 +++++++++
libc/test/shared/CMakeLists.txt | 11 +++++++++++
4 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 89db3f0af50e0..258b9ddaf72bc 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -19,6 +19,12 @@ function(_get_common_test_compile_options output_var c_test flags)
${config_flags}
${arch_flags})
+ # EXPECT_DEATH and ASSERT_DEATH might be quite slow. LIBC_TEST_SKIP_DEATH_TESTS
+ # will make those tests no-op to reduce the overall test time.
+ if(LIBC_TEST_SKIP_DEATH_TESTS)
+ list(APPEND compile_options "-DLIBC_TEST_SKIP_DEATH_TESTS")
+ endif()
+
if(LLVM_LIBC_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND compile_options "-fpie")
diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index de14aaf97de76..df340fcdde668 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -26,20 +26,30 @@ configure_lit_site_cfg(
"CMAKE_CROSSCOMPILING_EMULATOR"
)
-add_lit_testsuite(check-libc
+add_custom_target(check-libc-build)
+add_lit_testsuite(check-libc-lit
"Running libc tests via lit"
${LIBC_BUILD_DIR}/test
)
+add_dependencies(check-libc-lit check-libc-build)
if (TARGET check-hdrgen)
add_dependencies(check-libc check-hdrgen)
endif()
if(LIBC_ENABLE_UNITTESTS AND NOT LIBC_TEST_HERMETIC_TEST_ONLY)
- add_dependencies(check-libc libc-unit-tests-build)
+ add_dependencies(check-libc-build libc-unit-tests-build)
endif()
if(LIBC_ENABLE_HERMETIC_TESTS AND NOT LIBC_TEST_UNIT_TEST_ONLY)
- add_dependencies(check-libc libc-hermetic-tests-build)
+ add_dependencies(check-libc-build libc-hermetic-tests-build)
+endif()
+
+add_custom_target(check-libc)
+if(LIBC_TEST_CHECK_LIBC_BUILD_ONLY)
+ message(STATUS "check-libc target will now only build all the tests. Use ninja check-libc-lit to run all the tests.")
+ add_dependencies(check-libc check-libc-build)
+else()
+ add_dependencies(check-libc check-libc-lit)
endif()
add_subdirectory(UnitTest)
diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h
index 8e41d3eeefcd5..133c198d42f15 100644
--- a/libc/test/UnitTest/LibcTest.h
+++ b/libc/test/UnitTest/LibcTest.h
@@ -495,11 +495,20 @@ CString libc_make_test_file_path_func(const char *file_name);
#define ASSERT_EXITS(FUNC, EXIT) \
LIBC_TEST_PROCESS_(testProcessExits, FUNC, EXIT, return)
+#ifdef LIBC_TEST_SKIP_DEATH_TESTS
+
+#define EXPECT_DEATH(FUNC, SIG)
+#define ASSERT_DEATH(FUNC, SIG)
+
+#else
+
#define EXPECT_DEATH(FUNC, SIG) \
LIBC_TEST_PROCESS_(testProcessKilled, FUNC, SIG, )
#define ASSERT_DEATH(FUNC, SIG) \
LIBC_TEST_PROCESS_(testProcessKilled, FUNC, SIG, return)
+#endif // LIBC_TEST_SKIP_DEATH_TESTS
+
#endif // ENABLE_SUBPROCESS_TESTS
////////////////////////////////////////////////////////////////////////////////
diff --git a/libc/test/shared/CMakeLists.txt b/libc/test/shared/CMakeLists.txt
index e86b0a45eb77c..7a5c3a369c2fc 100644
--- a/libc/test/shared/CMakeLists.txt
+++ b/libc/test/shared/CMakeLists.txt
@@ -1,5 +1,15 @@
add_custom_target(libc-shared-tests)
+# Shared math tests include the entire math library headers into a single file
+# so it might take some time to compile the tests. We do have dedicated
+# precommit CIs to build and test shared tests. So we provide a cmake option
+# LIBC_TEST_SKIP_SHARED_TESTS to reduce redundant testings and reduce test time
+# for other precommit CIs.
+if(LIBC_TEST_SKIP_SHARED_TESTS)
+ if(LIBC_CMAKE_VERBOSE_LOGGING)
+ message(STATUS "LIBC_TEST_SKIP_SHARED_MATH_TESTS is set. Skipping libc-shared-tests.")
+ endif()
+else()
add_fp_unittest(
shared_math_test
SUITE
@@ -802,6 +812,7 @@ add_fp_unittest(
libc.src.__support.math.totalordermagf16
libc.src.__support.math.totalordermagl
)
+endif() # LIBC_TEST_SKIP_SHARED_MATH_TESTS
add_fp_unittest(
shared_str_to_num_test
>From f8191e744f883aaab94e743cd07a1f1cfb06befa Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Mon, 25 May 2026 18:50:22 +0000
Subject: [PATCH 2/4] Add check-hdrgen to check-libc-lit instead of check-libc.
---
libc/test/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index df340fcdde668..c6f648ddcaef7 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -34,7 +34,7 @@ add_lit_testsuite(check-libc-lit
add_dependencies(check-libc-lit check-libc-build)
if (TARGET check-hdrgen)
- add_dependencies(check-libc check-hdrgen)
+ add_dependencies(check-libc-lit check-hdrgen)
endif()
if(LIBC_ENABLE_UNITTESTS AND NOT LIBC_TEST_HERMETIC_TEST_ONLY)
>From 3db7fc9373d7713561d489d8120853d2bdb7ccad Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 26 May 2026 22:46:04 +0000
Subject: [PATCH 3/4] Add logging message for LIBC_TEST_SKIP_DEATH_TESTS.
---
libc/cmake/modules/LLVMLibCTestRules.cmake | 3 +++
1 file changed, 3 insertions(+)
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 258b9ddaf72bc..25f40da8d0781 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -22,6 +22,9 @@ function(_get_common_test_compile_options output_var c_test flags)
# EXPECT_DEATH and ASSERT_DEATH might be quite slow. LIBC_TEST_SKIP_DEATH_TESTS
# will make those tests no-op to reduce the overall test time.
if(LIBC_TEST_SKIP_DEATH_TESTS)
+ if(LIBC_CMAKE_VERBOSE_LOGGING)
+ message(STATUS "LIBC_TEST_SKIP_DEATH_TESTS is set. EXPECT_DEATH/ASSERT_DEATH are no-op.")
+ endif()
list(APPEND compile_options "-DLIBC_TEST_SKIP_DEATH_TESTS")
endif()
>From a1e320fca4f8714262905ce85359435c5d76683c Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Fri, 29 May 2026 15:49:48 +0000
Subject: [PATCH 4/4] Remove check-libc-lit, and just use check-libc to be
consistent with other projects.
---
libc/test/CMakeLists.txt | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index c6f648ddcaef7..09a60427b157f 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -27,14 +27,14 @@ configure_lit_site_cfg(
)
add_custom_target(check-libc-build)
-add_lit_testsuite(check-libc-lit
+add_lit_testsuite(check-libc
"Running libc tests via lit"
${LIBC_BUILD_DIR}/test
)
-add_dependencies(check-libc-lit check-libc-build)
+add_dependencies(check-libc check-libc-build)
if (TARGET check-hdrgen)
- add_dependencies(check-libc-lit check-hdrgen)
+ add_dependencies(check-libc check-hdrgen)
endif()
if(LIBC_ENABLE_UNITTESTS AND NOT LIBC_TEST_HERMETIC_TEST_ONLY)
@@ -44,14 +44,6 @@ if(LIBC_ENABLE_HERMETIC_TESTS AND NOT LIBC_TEST_UNIT_TEST_ONLY)
add_dependencies(check-libc-build libc-hermetic-tests-build)
endif()
-add_custom_target(check-libc)
-if(LIBC_TEST_CHECK_LIBC_BUILD_ONLY)
- message(STATUS "check-libc target will now only build all the tests. Use ninja check-libc-lit to run all the tests.")
- add_dependencies(check-libc check-libc-build)
-else()
- add_dependencies(check-libc check-libc-lit)
-endif()
-
add_subdirectory(UnitTest)
if(LIBC_TARGET_OS_IS_GPU)
More information about the libc-commits
mailing list