diff options
Diffstat (limited to 'libc/test/src')
35 files changed, 111 insertions, 71 deletions
diff --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h index 5c5419c..902ff04 100644 --- a/libc/test/src/math/FmaTest.h +++ b/libc/test/src/math/FmaTest.h @@ -48,7 +48,8 @@ class FmaTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest { InStorageType get_random_bit_pattern() { InStorageType bits{0}; for (InStorageType i = 0; i < sizeof(InStorageType) / 2; ++i) { - bits = (bits << 2) + static_cast<uint16_t>(LIBC_NAMESPACE::rand()); + bits = static_cast<InStorageType>( + (bits << 2) + static_cast<uint16_t>(LIBC_NAMESPACE::rand())); } return bits; } @@ -57,7 +58,7 @@ public: using FmaFunc = OutType (*)(InType, InType, InType); void test_subnormal_range(FmaFunc func) { - constexpr InStorageType COUNT = 100'001; + constexpr InStorageType COUNT = 10'001; constexpr InStorageType RAW_STEP = (IN_MAX_SUBNORMAL_U - IN_MIN_SUBNORMAL_U) / COUNT; constexpr InStorageType STEP = (RAW_STEP == 0 ? 1 : RAW_STEP); @@ -75,7 +76,7 @@ public: } void test_normal_range(FmaFunc func) { - constexpr InStorageType COUNT = 100'001; + constexpr InStorageType COUNT = 10'001; constexpr InStorageType RAW_STEP = (IN_MAX_NORMAL_U - IN_MIN_NORMAL_U) / COUNT; constexpr InStorageType STEP = (RAW_STEP == 0 ? 1 : RAW_STEP); diff --git a/libc/test/src/math/HypotTest.h b/libc/test/src/math/HypotTest.h index dc73581..b37abf7 100644 --- a/libc/test/src/math/HypotTest.h +++ b/libc/test/src/math/HypotTest.h @@ -71,8 +71,9 @@ public: void test_subnormal_range(Func func) { constexpr StorageType COUNT = 10'001; - for (unsigned scale = 0; scale < 4; ++scale) { - StorageType max_value = MAX_SUBNORMAL << scale; + constexpr unsigned SCALE = (sizeof(T) < 4) ? 1 : 4; + for (unsigned scale = 0; scale < SCALE; ++scale) { + StorageType max_value = static_cast<StorageType>(MAX_SUBNORMAL << scale); StorageType step = (max_value - MIN_SUBNORMAL) / COUNT + 1; for (int signs = 0; signs < 4; ++signs) { for (StorageType v = MIN_SUBNORMAL, w = max_value; diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 4aafe03..ec4c09c 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -3169,7 +3169,6 @@ add_fp_unittest( libc.hdr.signal_macros libc.src.math.nanf libc.src.__support.FPUtil.fp_bits - libc.src.__support.macros.sanitizer # FIXME: The nan tests currently have death tests, which aren't supported for # hermetic tests. UNIT_TEST_ONLY @@ -3185,7 +3184,6 @@ add_fp_unittest( libc.hdr.signal_macros libc.src.math.nan libc.src.__support.FPUtil.fp_bits - libc.src.__support.macros.sanitizer # FIXME: The nan tests currently have death tests, which aren't supported for # hermetic tests. UNIT_TEST_ONLY @@ -3201,7 +3199,6 @@ add_fp_unittest( libc.hdr.signal_macros libc.src.math.nanl libc.src.__support.FPUtil.fp_bits - libc.src.__support.macros.sanitizer # FIXME: The nan tests currently have death tests, which aren't supported for # hermetic tests. UNIT_TEST_ONLY @@ -3217,7 +3214,6 @@ add_fp_unittest( libc.hdr.signal_macros libc.src.math.nanf16 libc.src.__support.FPUtil.fp_bits - libc.src.__support.macros.sanitizer # FIXME: The nan tests currently have death tests, which aren't supported for # hermetic tests. UNIT_TEST_ONLY @@ -3233,7 +3229,6 @@ add_fp_unittest( libc.hdr.signal_macros libc.src.math.nanf128 libc.src.__support.FPUtil.fp_bits - libc.src.__support.macros.sanitizer # FIXME: The nan tests currently have death tests, which aren't supported for # hermetic tests. UNIT_TEST_ONLY diff --git a/libc/test/src/math/smoke/nan_test.cpp b/libc/test/src/math/smoke/nan_test.cpp index e8376c0..9010b74 100644 --- a/libc/test/src/math/smoke/nan_test.cpp +++ b/libc/test/src/math/smoke/nan_test.cpp @@ -8,7 +8,6 @@ #include "hdr/signal_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/macros/sanitizer.h" #include "src/math/nan.h" #include "test/UnitTest/FEnvSafeTest.h" #include "test/UnitTest/FPMatcher.h" @@ -44,8 +43,8 @@ TEST_F(LlvmLibcNanTest, RandomString) { run_test("123 ", 0x7ff8000000000000); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST_F(LlvmLibcNanTest, InvalidInput) { EXPECT_DEATH([] { LIBC_NAMESPACE::nan(nullptr); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/math/smoke/nanf128_test.cpp b/libc/test/src/math/smoke/nanf128_test.cpp index a63ce88..40b347d 100644 --- a/libc/test/src/math/smoke/nanf128_test.cpp +++ b/libc/test/src/math/smoke/nanf128_test.cpp @@ -8,7 +8,6 @@ #include "hdr/signal_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/macros/sanitizer.h" #include "src/__support/uint128.h" #include "src/math/nanf128.h" #include "test/UnitTest/FEnvSafeTest.h" @@ -55,8 +54,8 @@ TEST_F(LlvmLibcNanf128Test, RandomString) { QUIET_NAN); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST_F(LlvmLibcNanf128Test, InvalidInput) { EXPECT_DEATH([] { LIBC_NAMESPACE::nanf128(nullptr); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/math/smoke/nanf16_test.cpp b/libc/test/src/math/smoke/nanf16_test.cpp index 694470b..e05f79c 100644 --- a/libc/test/src/math/smoke/nanf16_test.cpp +++ b/libc/test/src/math/smoke/nanf16_test.cpp @@ -8,7 +8,6 @@ #include "hdr/signal_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/macros/sanitizer.h" #include "src/math/nanf16.h" #include "test/UnitTest/FEnvSafeTest.h" #include "test/UnitTest/FPMatcher.h" @@ -43,8 +42,8 @@ TEST_F(LlvmLibcNanf16Test, RandomString) { run_test("123 ", 0x7e00); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST_F(LlvmLibcNanf16Test, InvalidInput) { EXPECT_DEATH([] { LIBC_NAMESPACE::nanf16(nullptr); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/math/smoke/nanf_test.cpp b/libc/test/src/math/smoke/nanf_test.cpp index cb57f65..c2fef72 100644 --- a/libc/test/src/math/smoke/nanf_test.cpp +++ b/libc/test/src/math/smoke/nanf_test.cpp @@ -8,7 +8,6 @@ #include "hdr/signal_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/macros/sanitizer.h" #include "src/math/nanf.h" #include "test/UnitTest/FEnvSafeTest.h" #include "test/UnitTest/FPMatcher.h" @@ -43,8 +42,8 @@ TEST_F(LlvmLibcNanfTest, RandomString) { run_test("123 ", 0x7fc00000); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST_F(LlvmLibcNanfTest, InvalidInput) { EXPECT_DEATH([] { LIBC_NAMESPACE::nanf(nullptr); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/math/smoke/nanl_test.cpp b/libc/test/src/math/smoke/nanl_test.cpp index 3bcb914..b1d46df 100644 --- a/libc/test/src/math/smoke/nanl_test.cpp +++ b/libc/test/src/math/smoke/nanl_test.cpp @@ -8,7 +8,6 @@ #include "hdr/signal_macros.h" #include "src/__support/FPUtil/FPBits.h" -#include "src/__support/macros/sanitizer.h" #include "src/math/nanl.h" #include "test/UnitTest/FEnvSafeTest.h" #include "test/UnitTest/FPMatcher.h" @@ -71,8 +70,8 @@ TEST_F(LlvmLibcNanlTest, RandomString) { run_test("123 ", expected); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST_F(LlvmLibcNanlTest, InvalidInput) { EXPECT_DEATH([] { LIBC_NAMESPACE::nanl(nullptr); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/stdfix/IdivTest.h b/libc/test/src/stdfix/IdivTest.h index 0e9cc40..28c39f4 100644 --- a/libc/test/src/stdfix/IdivTest.h +++ b/libc/test/src/stdfix/IdivTest.h @@ -71,7 +71,7 @@ public: } }; -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) #define LIST_IDIV_TESTS(Name, T, XType, func) \ using LlvmLibcIdiv##Name##Test = IdivTest<T, XType>; \ TEST_F(LlvmLibcIdiv##Name##Test, InvalidNumbers) { \ @@ -88,4 +88,4 @@ public: testSpecialNumbers(&func); \ } \ static_assert(true, "Require semicolon.") -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/string/memchr_test.cpp b/libc/test/src/string/memchr_test.cpp index 1455183..4a7c88b 100644 --- a/libc/test/src/string/memchr_test.cpp +++ b/libc/test/src/string/memchr_test.cpp @@ -122,11 +122,11 @@ TEST(LlvmLibcMemChrTest, SignedCharacterFound) { ASSERT_EQ(actual[0], c); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcMemChrTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::memchr(nullptr, 1, 1); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp index 3dfbced..99d08a4 100644 --- a/libc/test/src/string/memcmp_test.cpp +++ b/libc/test/src/string/memcmp_test.cpp @@ -66,13 +66,13 @@ TEST(LlvmLibcMemcmpTest, SizeSweep) { } } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcMemcmpTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::memcmp(nullptr, nullptr, 1); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp index 8c43ac8..03a3d13 100644 --- a/libc/test/src/string/memcpy_test.cpp +++ b/libc/test/src/string/memcpy_test.cpp @@ -73,12 +73,12 @@ TEST(LlvmLibcMemcpyTest, CheckAccess) { #endif // !defined(LIBC_FULL_BUILD) && defined(LIBC_TARGET_OS_IS_LINUX) -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcMemcpyTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::memcpy(nullptr, nullptr, 1); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/memmove_test.cpp b/libc/test/src/string/memmove_test.cpp index 0d47655..60ac680 100644 --- a/libc/test/src/string/memmove_test.cpp +++ b/libc/test/src/string/memmove_test.cpp @@ -104,13 +104,13 @@ TEST(LlvmLibcMemmoveTest, SizeSweep) { } } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcMemmoveTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::memmove(nullptr, nullptr, 2); }, WITH_SIGNAL(-1)); } -#endif // LIBC_TARGET_OS_IS_LINUX +#endif // LIBC_ADD_NULL_CHECKS } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/mempcpy_test.cpp b/libc/test/src/string/mempcpy_test.cpp index 24482a8..7351a82 100644 --- a/libc/test/src/string/mempcpy_test.cpp +++ b/libc/test/src/string/mempcpy_test.cpp @@ -27,11 +27,11 @@ TEST(LlvmLibcMempcpyTest, ZeroCount) { ASSERT_EQ(static_cast<char *>(result), dest + 0); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcMempcpyTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::mempcpy(nullptr, nullptr, 1); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/memrchr_test.cpp b/libc/test/src/string/memrchr_test.cpp index c73a479..140395b 100644 --- a/libc/test/src/string/memrchr_test.cpp +++ b/libc/test/src/string/memrchr_test.cpp @@ -114,11 +114,11 @@ TEST(LlvmLibcMemRChrTest, ZeroLengthShouldReturnNullptr) { ASSERT_STREQ(call_memrchr(src, 'd', 0), nullptr); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcMemRChrTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::memrchr(nullptr, 'd', 1); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/memset_test.cpp b/libc/test/src/string/memset_test.cpp index 9562d2d2..8268d31 100644 --- a/libc/test/src/string/memset_test.cpp +++ b/libc/test/src/string/memset_test.cpp @@ -60,13 +60,13 @@ TEST(LlvmLibcMemsetTest, CheckAccess) { #endif // !defined(LIBC_FULL_BUILD) && defined(LIBC_TARGET_OS_IS_LINUX) -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcMemsetTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::memset(nullptr, 0, 1); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) } // namespace LIBC_NAMESPACE_DECL diff --git a/libc/test/src/string/stpncpy_test.cpp b/libc/test/src/string/stpncpy_test.cpp index f5c61e2..8344926 100644 --- a/libc/test/src/string/stpncpy_test.cpp +++ b/libc/test/src/string/stpncpy_test.cpp @@ -73,11 +73,11 @@ TEST_F(LlvmLibcStpncpyTest, CopyTwoWithNull) { check_stpncpy(dst, src, 2, expected, 1); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST_F(LlvmLibcStpncpyTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::stpncpy(nullptr, nullptr, 1); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/strcat_test.cpp b/libc/test/src/string/strcat_test.cpp index 20f8d11..baaf455 100644 --- a/libc/test/src/string/strcat_test.cpp +++ b/libc/test/src/string/strcat_test.cpp @@ -37,11 +37,11 @@ TEST(LlvmLibcStrCatTest, NonEmptyDest) { ASSERT_STREQ(dest, "xyzabc"); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcStrCatTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::strcat(nullptr, nullptr); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/strcoll_test.cpp b/libc/test/src/string/strcoll_test.cpp index 268e232..1be7568 100644 --- a/libc/test/src/string/strcoll_test.cpp +++ b/libc/test/src/string/strcoll_test.cpp @@ -30,11 +30,11 @@ TEST(LlvmLibcStrcollTest, SimpleTest) { ASSERT_GT(result, 0); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcStrcollTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::strcoll(nullptr, nullptr); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/strcpy_test.cpp b/libc/test/src/string/strcpy_test.cpp index ead60be..0041d38 100644 --- a/libc/test/src/string/strcpy_test.cpp +++ b/libc/test/src/string/strcpy_test.cpp @@ -44,11 +44,11 @@ TEST(LlvmLibcStrCpyTest, OffsetDest) { ASSERT_STREQ(dest, "xyzabc"); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcStrCpyTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::strcpy(nullptr, nullptr); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/strsep_test.cpp b/libc/test/src/string/strsep_test.cpp index 6f02ce3..06318de 100644 --- a/libc/test/src/string/strsep_test.cpp +++ b/libc/test/src/string/strsep_test.cpp @@ -53,11 +53,11 @@ TEST(LlvmLibcStrsepTest, DelimitersShouldNotBeIncludedInToken) { } } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcStrsepTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::strsep(nullptr, nullptr); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/string/strspn_test.cpp b/libc/test/src/string/strspn_test.cpp index adf9a45..82f9b2a 100644 --- a/libc/test/src/string/strspn_test.cpp +++ b/libc/test/src/string/strspn_test.cpp @@ -85,11 +85,11 @@ TEST(LlvmLibcStrSpnTest, DuplicatedCharactersToBeSearchedForShouldStillMatch) { EXPECT_EQ(LIBC_NAMESPACE::strspn("aaaa", "aa"), size_t{4}); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcStrSpnTest, CrashOnNullPtr) { ASSERT_DEATH([]() { LIBC_NAMESPACE::strspn(nullptr, nullptr); }, WITH_SIGNAL(-1)); } -#endif // defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#endif // defined(LIBC_ADD_NULL_CHECKS) diff --git a/libc/test/src/wchar/CMakeLists.txt b/libc/test/src/wchar/CMakeLists.txt index f420ecc..fad89dc 100644 --- a/libc/test/src/wchar/CMakeLists.txt +++ b/libc/test/src/wchar/CMakeLists.txt @@ -99,7 +99,22 @@ add_libc_test( libc.src.string.memset libc.src.wchar.mbrlen libc.hdr.types.mbstate_t + libc.hdr.types.wchar_t libc.test.UnitTest.ErrnoCheckingTest +) + +add_libc_test( + mbsinit_test + SUITE + libc_wchar_unittests + SRCS + mbsinit_test.cpp + DEPENDS + libc.src.string.memset + libc.src.wchar.mbsinit + libc.src.wchar.mbrtowc + libc.hdr.types.mbstate_t + libc.hdr.types.wchar_t ) add_libc_test( diff --git a/libc/test/src/wchar/mbsinit_test.cpp b/libc/test/src/wchar/mbsinit_test.cpp new file mode 100644 index 0000000..ecb48aa --- /dev/null +++ b/libc/test/src/wchar/mbsinit_test.cpp @@ -0,0 +1,33 @@ +//===-- Unittests for mbsinit ---------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "hdr/types/wchar_t.h" +#include "src/string/memset.h" +#include "src/wchar/mbrtowc.h" +#include "src/wchar/mbsinit.h" +#include "test/UnitTest/Test.h" + +TEST(LlvmLibcMBSInitTest, EmptyState) { + mbstate_t ps; + LIBC_NAMESPACE::memset(&ps, 0, sizeof(mbstate_t)); + ASSERT_NE(LIBC_NAMESPACE::mbsinit(&ps), 0); + ASSERT_NE(LIBC_NAMESPACE::mbsinit(nullptr), 0); +} + +TEST(LlvmLibcMBSInitTest, ConversionTest) { + const char *src = "\xf0\x9f\xa4\xa3"; // 4 byte emoji + wchar_t dest[2]; + mbstate_t ps; + LIBC_NAMESPACE::memset(&ps, 0, sizeof(mbstate_t)); + + ASSERT_NE(LIBC_NAMESPACE::mbsinit(&ps), 0); + LIBC_NAMESPACE::mbrtowc(dest, src, 2, &ps); // partial conversion + ASSERT_EQ(LIBC_NAMESPACE::mbsinit(&ps), 0); + LIBC_NAMESPACE::mbrtowc(dest, src + 2, 2, &ps); // complete conversion + ASSERT_NE(LIBC_NAMESPACE::mbsinit(&ps), 0); // state should be reset now +} diff --git a/libc/test/src/wchar/wcpncpy_test.cpp b/libc/test/src/wchar/wcpncpy_test.cpp index bb72211..6c6faf8 100644 --- a/libc/test/src/wchar/wcpncpy_test.cpp +++ b/libc/test/src/wchar/wcpncpy_test.cpp @@ -84,10 +84,10 @@ TEST(LlvmLibcWCPNCpyTest, CopyAndFill) { ASSERT_EQ(dest + 1, res); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcWCPNCpyTest, NullptrCrash) { // Passing in a nullptr should crash the program. EXPECT_DEATH([] { LIBC_NAMESPACE::wcpncpy(nullptr, nullptr, 1); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/wchar/wcscmp_test.cpp b/libc/test/src/wchar/wcscmp_test.cpp index 6572aad..ace95e83 100644 --- a/libc/test/src/wchar/wcscmp_test.cpp +++ b/libc/test/src/wchar/wcscmp_test.cpp @@ -86,7 +86,7 @@ TEST(LlvmLibcWcscmpTest, StringArgumentSwapChangesSign) { ASSERT_LT(result, 0); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcWcscmpTest, NullptrCrash) { // Passing in a nullptr should crash the program. EXPECT_DEATH([] { LIBC_NAMESPACE::wcscmp(L"aaaaaaaaaaaaaa", nullptr); }, @@ -94,4 +94,4 @@ TEST(LlvmLibcWcscmpTest, NullptrCrash) { EXPECT_DEATH([] { LIBC_NAMESPACE::wcscmp(nullptr, L"aaaaaaaaaaaaaa"); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/wchar/wcsncmp_test.cpp b/libc/test/src/wchar/wcsncmp_test.cpp index 28bbb52..c36c4db 100644 --- a/libc/test/src/wchar/wcsncmp_test.cpp +++ b/libc/test/src/wchar/wcsncmp_test.cpp @@ -93,7 +93,7 @@ TEST(LlvmLibcWcsncmpTest, StringArgumentSwapChangesSignWithSufficientLength) { ASSERT_LT(result, 0); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcWcsncmpTest, NullptrCrash) { // Passing in a nullptr should crash the program. EXPECT_DEATH([] { LIBC_NAMESPACE::wcsncmp(L"aaaaaaaaaaaaaa", nullptr, 3); }, @@ -101,7 +101,7 @@ TEST(LlvmLibcWcsncmpTest, NullptrCrash) { EXPECT_DEATH([] { LIBC_NAMESPACE::wcsncmp(nullptr, L"aaaaaaaaaaaaaa", 3); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS // This group is actually testing wcsncmp functionality diff --git a/libc/test/src/wchar/wcspbrk_test.cpp b/libc/test/src/wchar/wcspbrk_test.cpp index bca9bff..4c85ca4 100644 --- a/libc/test/src/wchar/wcspbrk_test.cpp +++ b/libc/test/src/wchar/wcspbrk_test.cpp @@ -61,7 +61,7 @@ TEST(LlvmLibcWCSPBrkTest, FindsFirstInBreakset) { EXPECT_EQ(LIBC_NAMESPACE::wcspbrk(src, L"43"), src + 2); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcWCSPBrkTest, NullptrCrash) { // Passing in a nullptr should crash the program. EXPECT_DEATH([] { LIBC_NAMESPACE::wcspbrk(L"aaaaaaaaaaaaaa", nullptr); }, @@ -69,4 +69,4 @@ TEST(LlvmLibcWCSPBrkTest, NullptrCrash) { EXPECT_DEATH([] { LIBC_NAMESPACE::wcspbrk(nullptr, L"aaaaaaaaaaaaaa"); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/wchar/wcsrchr_test.cpp b/libc/test/src/wchar/wcsrchr_test.cpp index 707dfb6..52c28ac 100644 --- a/libc/test/src/wchar/wcsrchr_test.cpp +++ b/libc/test/src/wchar/wcsrchr_test.cpp @@ -60,9 +60,9 @@ TEST(LlvmLibcWCSRChrTest, EmptyStringShouldOnlyMatchNullTerminator) { ASSERT_EQ(LIBC_NAMESPACE::wcsrchr(src, L'*'), nullptr); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcWCSRChrTest, NullptrCrash) { // Passing in a nullptr should crash the program. EXPECT_DEATH([] { LIBC_NAMESPACE::wcsrchr(nullptr, L'a'); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/wchar/wcstol_test.cpp b/libc/test/src/wchar/wcstol_test.cpp index 9ae32ba..2dd0bc7 100644 --- a/libc/test/src/wchar/wcstol_test.cpp +++ b/libc/test/src/wchar/wcstol_test.cpp @@ -12,4 +12,4 @@ #include "WcstolTest.h" -WCSTOL_TEST(Wcstol, LIBC_NAMESPACE::wcstol)
\ No newline at end of file +WCSTOL_TEST(Wcstol, LIBC_NAMESPACE::wcstol) diff --git a/libc/test/src/wchar/wcstoll_test.cpp b/libc/test/src/wchar/wcstoll_test.cpp index c24c1f6..00a241a 100644 --- a/libc/test/src/wchar/wcstoll_test.cpp +++ b/libc/test/src/wchar/wcstoll_test.cpp @@ -12,4 +12,4 @@ #include "WcstolTest.h" -WCSTOL_TEST(Wcstoll, LIBC_NAMESPACE::wcstoll)
\ No newline at end of file +WCSTOL_TEST(Wcstoll, LIBC_NAMESPACE::wcstoll) diff --git a/libc/test/src/wchar/wcstoul_test.cpp b/libc/test/src/wchar/wcstoul_test.cpp index ab0afb9..63b630d 100644 --- a/libc/test/src/wchar/wcstoul_test.cpp +++ b/libc/test/src/wchar/wcstoul_test.cpp @@ -12,4 +12,4 @@ #include "WcstolTest.h" -WCSTOL_TEST(Wcstoul, LIBC_NAMESPACE::wcstoul)
\ No newline at end of file +WCSTOL_TEST(Wcstoul, LIBC_NAMESPACE::wcstoul) diff --git a/libc/test/src/wchar/wcstoull_test.cpp b/libc/test/src/wchar/wcstoull_test.cpp index adba4f1..12895d3 100644 --- a/libc/test/src/wchar/wcstoull_test.cpp +++ b/libc/test/src/wchar/wcstoull_test.cpp @@ -12,4 +12,4 @@ #include "WcstolTest.h" -WCSTOL_TEST(Wcstoull, LIBC_NAMESPACE::wcstoull)
\ No newline at end of file +WCSTOL_TEST(Wcstoull, LIBC_NAMESPACE::wcstoull) diff --git a/libc/test/src/wchar/wmemcmp_test.cpp b/libc/test/src/wchar/wmemcmp_test.cpp index 5b07ca7..c9c0839 100644 --- a/libc/test/src/wchar/wmemcmp_test.cpp +++ b/libc/test/src/wchar/wmemcmp_test.cpp @@ -67,7 +67,7 @@ TEST(LlvmLibcWMemcmpTest, LhsRhsAreTheSameLong) { EXPECT_EQ(LIBC_NAMESPACE::wmemcmp(lhs, rhs, 15), 0); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcWMemcmpTest, NullptrCrash) { // Passing in a nullptr should crash the program. EXPECT_DEATH([] { LIBC_NAMESPACE::wmemcmp(L"aaaaaaaaaaaaaa", nullptr, 15); }, @@ -75,4 +75,4 @@ TEST(LlvmLibcWMemcmpTest, NullptrCrash) { EXPECT_DEATH([] { LIBC_NAMESPACE::wmemcmp(nullptr, L"aaaaaaaaaaaaaa", 15); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS diff --git a/libc/test/src/wchar/wmemmove_test.cpp b/libc/test/src/wchar/wmemmove_test.cpp index d23aa0f..102fc04 100644 --- a/libc/test/src/wchar/wmemmove_test.cpp +++ b/libc/test/src/wchar/wmemmove_test.cpp @@ -99,7 +99,7 @@ TEST(LlvmLibcWMemmoveTest, DstFollowSrc) { EXPECT_TRUE(buffer[3] == expected[3]); } -#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) +#if defined(LIBC_ADD_NULL_CHECKS) TEST(LlvmLibcWMemmoveTest, NullptrCrash) { wchar_t buffer[] = {L'a', L'b'}; // Passing in a nullptr should crash the program. @@ -108,4 +108,4 @@ TEST(LlvmLibcWMemmoveTest, NullptrCrash) { EXPECT_DEATH([&buffer] { LIBC_NAMESPACE::wmemmove(nullptr, buffer, 2); }, WITH_SIGNAL(-1)); } -#endif // LIBC_HAS_ADDRESS_SANITIZER +#endif // LIBC_ADD_NULL_CHECKS |