[libc-commits] [libc] e2f8f77 - [libc] Enable the 'stdlib' unit tests to be hermetic
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Wed May 3 09:37:59 PDT 2023
Author: Joseph Huber
Date: 2023-05-03T11:37:48-05:00
New Revision: e2f8f77e159ba345b5f1dc8531342da7c0d3370e
URL: https://github.com/llvm/llvm-project/commit/e2f8f77e159ba345b5f1dc8531342da7c0d3370e
DIFF: https://github.com/llvm/llvm-project/commit/e2f8f77e159ba345b5f1dc8531342da7c0d3370e.diff
LOG: [libc] Enable the 'stdlib' unit tests to be hermetic
This changes the `stdlib` tests to the new `add_libc_test` framework.
This applies to all but the exit tests.
Depends on D149691
Reviewed By: sivachandra, michaelrj
Differential Revision: https://reviews.llvm.org/D149705
Added:
Modified:
libc/test/UnitTest/RoundingModeUtils.cpp
libc/test/src/CMakeLists.txt
libc/test/src/stdlib/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/test/UnitTest/RoundingModeUtils.cpp b/libc/test/UnitTest/RoundingModeUtils.cpp
index 8cc6834d89edb..e2fde1d03de8f 100644
--- a/libc/test/UnitTest/RoundingModeUtils.cpp
+++ b/libc/test/UnitTest/RoundingModeUtils.cpp
@@ -8,7 +8,7 @@
#include "RoundingModeUtils.h"
-#include <fenv.h>
+#include "src/__support/FPUtil/FEnvImpl.h"
namespace __llvm_libc {
namespace fputil {
@@ -34,15 +34,15 @@ int get_fe_rounding(RoundingMode mode) {
}
ForceRoundingMode::ForceRoundingMode(RoundingMode mode) {
- old_rounding_mode = fegetround();
+ old_rounding_mode = fputil::get_round();
rounding_mode = get_fe_rounding(mode);
if (old_rounding_mode != rounding_mode)
- fesetround(rounding_mode);
+ fputil::set_round(rounding_mode);
}
ForceRoundingMode::~ForceRoundingMode() {
if (old_rounding_mode != rounding_mode)
- fesetround(old_rounding_mode);
+ fputil::set_round(old_rounding_mode);
}
} // namespace testing
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt
index f3f8ca88190e0..7e7d7fd610984 100644
--- a/libc/test/src/CMakeLists.txt
+++ b/libc/test/src/CMakeLists.txt
@@ -1,7 +1,7 @@
function(add_fp_unittest name)
cmake_parse_arguments(
"MATH_UNITTEST"
- "NEED_MPFR" # Optional arguments
+ "NEED_MPFR;HERMETIC_TEST_ONLY" # Optional arguments
"" # Single value arguments
"LINK_LIBRARIES" # Multi-value arguments
${ARGN}
@@ -14,13 +14,21 @@ function(add_fp_unittest name)
endif()
endif()
+ if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
+ set(test_type HERMETIC_TEST_ONLY)
+ endif()
if(MATH_UNITTEST_NEED_MPFR)
+ if(MATH_UNITTEST_HERMETIC_TEST_ONLY)
+ message(FATAL "Hermetic math test cannot require MPFR.")
+ endif()
+ set(test_type UNIT_TEST_ONLY)
list(APPEND MATH_UNITTEST_LINK_LIBRARIES libcMPFRWrapper libc_math_test_utils -lmpfr -lgmp)
endif()
list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers)
add_libc_unittest(
${name}
+ ${test_type}
LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}"
"${MATH_UNITTEST_UNPARSED_ARGUMENTS}"
)
diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt
index 4664a581aec55..01d3257b148db 100644
--- a/libc/test/src/stdlib/CMakeLists.txt
+++ b/libc/test/src/stdlib/CMakeLists.txt
@@ -1,9 +1,9 @@
-add_custom_target(libc_stdlib_unittests)
+add_custom_target(libc-stdlib-tests)
-add_libc_unittest(
+add_libc_test(
atof_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
atof_test.cpp
DEPENDS
@@ -20,10 +20,10 @@ add_header_library(
libc.src.__support.CPP.type_traits
)
-add_libc_unittest(
+add_libc_test(
atoi_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
atoi_test.cpp
DEPENDS
@@ -31,10 +31,10 @@ add_libc_unittest(
libc.src.stdlib.atoi
)
-add_libc_unittest(
+add_libc_test(
atol_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
atol_test.cpp
DEPENDS
@@ -42,10 +42,10 @@ add_libc_unittest(
libc.src.stdlib.atol
)
-add_libc_unittest(
+add_libc_test(
atoll_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
atoll_test.cpp
DEPENDS
@@ -56,23 +56,25 @@ add_libc_unittest(
add_fp_unittest(
strtod_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
strtod_test.cpp
DEPENDS
libc.src.errno.errno
libc.src.stdlib.strtod
+ libc.src.__support.FPUtil.fenv_impl
)
add_fp_unittest(
strtof_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
strtof_test.cpp
DEPENDS
libc.src.errno.errno
libc.src.stdlib.strtof
+ libc.src.__support.FPUtil.fenv_impl
)
add_header_library(
@@ -85,10 +87,10 @@ add_header_library(
libc.src.errno.errno
)
-add_libc_unittest(
+add_libc_test(
strtol_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
strtol_test.cpp
DEPENDS
@@ -96,10 +98,10 @@ add_libc_unittest(
.strtol_test_support
)
-add_libc_unittest(
+add_libc_test(
strtold_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
strtold_test.cpp
DEPENDS
@@ -108,10 +110,10 @@ add_libc_unittest(
libc.src.stdlib.strtold
)
-add_libc_unittest(
+add_libc_test(
strtoll_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
strtoll_test.cpp
DEPENDS
@@ -119,10 +121,10 @@ add_libc_unittest(
.strtol_test_support
)
-add_libc_unittest(
+add_libc_test(
strtoul_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
strtoul_test.cpp
DEPENDS
@@ -130,10 +132,10 @@ add_libc_unittest(
.strtol_test_support
)
-add_libc_unittest(
+add_libc_test(
strtoull_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
strtoull_test.cpp
DEPENDS
@@ -141,40 +143,40 @@ add_libc_unittest(
.strtol_test_support
)
-add_libc_unittest(
+add_libc_test(
abs_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
abs_test.cpp
DEPENDS
libc.src.stdlib.abs
)
-add_libc_unittest(
+add_libc_test(
labs_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
labs_test.cpp
DEPENDS
libc.src.stdlib.labs
)
-add_libc_unittest(
+add_libc_test(
llabs_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
llabs_test.cpp
DEPENDS
libc.src.stdlib.llabs
)
-add_libc_unittest(
+add_libc_test(
div_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
div_test.cpp
HDRS
@@ -184,10 +186,10 @@ add_libc_unittest(
libc.src.stdlib.div
)
-add_libc_unittest(
+add_libc_test(
ldiv_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
ldiv_test.cpp
HDRS
@@ -197,10 +199,10 @@ add_libc_unittest(
libc.src.stdlib.ldiv
)
-add_libc_unittest(
+add_libc_test(
lldiv_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
lldiv_test.cpp
HDRS
@@ -210,10 +212,10 @@ add_libc_unittest(
libc.src.stdlib.lldiv
)
-add_libc_unittest(
+add_libc_test(
bsearch_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
bsearch_test.cpp
DEPENDS
@@ -221,10 +223,10 @@ add_libc_unittest(
libc.src.stdlib.bsearch
)
-add_libc_unittest(
+add_libc_test(
qsort_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
qsort_test.cpp
DEPENDS
@@ -232,10 +234,10 @@ add_libc_unittest(
libc.src.stdlib.qsort
)
-add_libc_unittest(
+add_libc_test(
rand_test
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
rand_test.cpp
DEPENDS
@@ -246,10 +248,12 @@ add_libc_unittest(
if(LLVM_LIBC_FULL_BUILD)
- add_libc_unittest(
+ add_libc_test(
_Exit_test
+ # The EXPECT_EXITS test is only availible for unit tests.
+ UNIT_TEST_ONLY
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
_Exit_test.cpp
DEPENDS
@@ -258,10 +262,12 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.stdlib.exit
)
- add_libc_unittest(
+ add_libc_test(
atexit_test
+ # The EXPECT_EXITS test is only availible for unit tests.
+ UNIT_TEST_ONLY
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
atexit_test.cpp
DEPENDS
@@ -273,10 +279,12 @@ if(LLVM_LIBC_FULL_BUILD)
libc.src.__support.CPP.utility
)
- add_libc_unittest(
+ add_libc_test(
abort_test
+ # The EXPECT_DEATH test is only availible for unit tests.
+ UNIT_TEST_ONLY
SUITE
- libc_stdlib_unittests
+ libc-stdlib-tests
SRCS
abort_test.cpp
DEPENDS
More information about the libc-commits
mailing list