diff options
| author | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
|---|---|---|
| committer | Michael Kruse <llvm-project@meinersbur.de> | 2025-01-03 10:22:51 +0100 |
| commit | 38500d63e14ce340236840f60d356cdefb56a52c (patch) | |
| tree | 17edbec446ce9b50d2f215a483b83afb293a635d /libc/test/src | |
| parent | 1a3d5daaef7a6a63448a497da3eff7fc9e23df26 (diff) | |
| parent | 27f30029741ecf023baece7b3dde1ff9011ffefc (diff) | |
Merge branch 'main' into users/meinersbur/flang_runtime_split-headersusers/meinersbur/flang_runtime_split-headers
Diffstat (limited to 'libc/test/src')
64 files changed, 1063 insertions, 441 deletions
diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt index 8ac8f91e98d4..31008508d649 100644 --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -58,7 +58,9 @@ add_subdirectory(stdfix) add_subdirectory(stdio) add_subdirectory(stdlib) add_subdirectory(string) +add_subdirectory(strings) add_subdirectory(wchar) +add_subdirectory(time) # Depends on utilities in stdlib add_subdirectory(inttypes) @@ -75,15 +77,14 @@ if(NOT LLVM_LIBC_FULL_BUILD) return() endif() +add_subdirectory(arpa) add_subdirectory(assert) add_subdirectory(compiler) add_subdirectory(dirent) -add_subdirectory(network) +add_subdirectory(locale) add_subdirectory(setjmp) add_subdirectory(signal) add_subdirectory(spawn) -add_subdirectory(time) -add_subdirectory(locale) if(${LIBC_TARGET_OS} STREQUAL "linux") add_subdirectory(pthread) diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt index bcc86effd9a5..aeb8edf305d0 100644 --- a/libc/test/src/__support/CMakeLists.txt +++ b/libc/test/src/__support/CMakeLists.txt @@ -55,7 +55,9 @@ if(NOT LIBC_TARGET_OS_IS_GPU) ) endif() -if(LLVM_LIBC_FULL_BUILD) +# TODO: FreeListHeap uses the _end symbol which conflicts with the _end symbol +# defined by GPU start.cpp files so for now we exclude this test on GPU. +if(LLVM_LIBC_FULL_BUILD AND NOT LIBC_TARGET_OS_IS_GPU) add_libc_test( freelist_heap_test SUITE @@ -63,11 +65,9 @@ if(LLVM_LIBC_FULL_BUILD) SRCS fake_heap.s freelist_heap_test.cpp - freelist_malloc_test.cpp DEPENDS libc.src.__support.CPP.span libc.src.__support.freelist_heap - libc.src.stdlib.freelist_malloc libc.src.string.memcmp libc.src.string.memcpy ) diff --git a/libc/test/src/__support/CPP/atomic_test.cpp b/libc/test/src/__support/CPP/atomic_test.cpp index 5b105c8eb3d5..5c3f60e9a68c 100644 --- a/libc/test/src/__support/CPP/atomic_test.cpp +++ b/libc/test/src/__support/CPP/atomic_test.cpp @@ -32,3 +32,21 @@ TEST(LlvmLibcAtomicTest, CompareExchangeStrong) { ASSERT_FALSE(aint.compare_exchange_strong(desired, 100)); ASSERT_EQ(aint.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED), 100); } + +struct alignas(void *) TrivialData { + char a; + char b; + char padding[sizeof(void *) - 2]; +}; + +TEST(LlvmLibcAtomicTest, TrivialCompositeData) { + LIBC_NAMESPACE::cpp::Atomic<TrivialData> data({'a', 'b', {}}); + ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).a, 'a'); + ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).b, 'b'); + + auto old = data.exchange({'c', 'd', {}}); + ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).a, 'c'); + ASSERT_EQ(data.load(LIBC_NAMESPACE::cpp::MemoryOrder::RELAXED).b, 'd'); + ASSERT_EQ(old.a, 'a'); + ASSERT_EQ(old.b, 'b'); +} diff --git a/libc/test/src/__support/CPP/type_traits_test.cpp b/libc/test/src/__support/CPP/type_traits_test.cpp index fa5298a12d3f..4b3e48c6a6c0 100644 --- a/libc/test/src/__support/CPP/type_traits_test.cpp +++ b/libc/test/src/__support/CPP/type_traits_test.cpp @@ -439,6 +439,28 @@ TEST(LlvmLibcTypeTraitsTest, is_object) { TEST(LlvmLibcTypeTraitsTest, true_type) { EXPECT_TRUE((true_type::value)); } +struct CompilerLeadingPadded { + char b; + int a; +}; + +struct CompilerTrailingPadded { + int a; + char b; +}; + +struct alignas(long long) ManuallyPadded { + int b; + char padding[sizeof(long long) - sizeof(int)]; +}; + +TEST(LlvmLibcTypeTraitsTest, has_unique_object_representations) { + EXPECT_TRUE(has_unique_object_representations<int>::value); + EXPECT_FALSE(has_unique_object_representations_v<CompilerLeadingPadded>); + EXPECT_FALSE(has_unique_object_representations_v<CompilerTrailingPadded>); + EXPECT_TRUE(has_unique_object_representations_v<ManuallyPadded>); +} + // TODO type_identity // TODO void_t diff --git a/libc/test/src/__support/freelist_malloc_test.cpp b/libc/test/src/__support/freelist_malloc_test.cpp deleted file mode 100644 index 793e2498304f..000000000000 --- a/libc/test/src/__support/freelist_malloc_test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -//===-- Unittests for freelist_malloc -------------------------------------===// -// -// 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 "src/__support/freelist_heap.h" -#include "src/stdlib/aligned_alloc.h" -#include "src/stdlib/calloc.h" -#include "src/stdlib/free.h" -#include "src/stdlib/malloc.h" -#include "test/UnitTest/Test.h" - -using LIBC_NAMESPACE::Block; -using LIBC_NAMESPACE::freelist_heap; -using LIBC_NAMESPACE::FreeListHeap; -using LIBC_NAMESPACE::FreeListHeapBuffer; - -TEST(LlvmLibcFreeListMalloc, Malloc) { - constexpr size_t kAllocSize = 256; - constexpr size_t kCallocNum = 4; - constexpr size_t kCallocSize = 64; - - void *ptr1 = LIBC_NAMESPACE::malloc(kAllocSize); - auto *block = Block::from_usable_space(ptr1); - EXPECT_GE(block->inner_size(), kAllocSize); - - LIBC_NAMESPACE::free(ptr1); - ASSERT_NE(block->next(), static_cast<Block *>(nullptr)); - ASSERT_EQ(block->next()->next(), static_cast<Block *>(nullptr)); - size_t heap_size = block->inner_size(); - - void *ptr2 = LIBC_NAMESPACE::calloc(kCallocNum, kCallocSize); - ASSERT_EQ(ptr2, ptr1); - EXPECT_GE(block->inner_size(), kCallocNum * kCallocSize); - - for (size_t i = 0; i < kCallocNum * kCallocSize; ++i) - EXPECT_EQ(reinterpret_cast<uint8_t *>(ptr2)[i], uint8_t(0)); - - LIBC_NAMESPACE::free(ptr2); - EXPECT_EQ(block->inner_size(), heap_size); - - constexpr size_t ALIGN = kAllocSize; - void *ptr3 = LIBC_NAMESPACE::aligned_alloc(ALIGN, kAllocSize); - EXPECT_NE(ptr3, static_cast<void *>(nullptr)); - EXPECT_EQ(reinterpret_cast<uintptr_t>(ptr3) % ALIGN, size_t(0)); - auto *aligned_block = reinterpret_cast<Block *>(ptr3); - EXPECT_GE(aligned_block->inner_size(), kAllocSize); - - LIBC_NAMESPACE::free(ptr3); - EXPECT_EQ(block->inner_size(), heap_size); -} diff --git a/libc/test/src/__support/threads/linux/raw_mutex_test.cpp b/libc/test/src/__support/threads/linux/raw_mutex_test.cpp index 918f5d35c94f..dadc706421d0 100644 --- a/libc/test/src/__support/threads/linux/raw_mutex_test.cpp +++ b/libc/test/src/__support/threads/linux/raw_mutex_test.cpp @@ -12,7 +12,7 @@ #include "src/__support/OSUtil/syscall.h" #include "src/__support/threads/linux/raw_mutex.h" #include "src/__support/threads/sleep.h" -#include "src/__support/time/linux/clock_gettime.h" +#include "src/__support/time/clock_gettime.h" #include "src/stdlib/exit.h" #include "src/sys/mman/mmap.h" #include "src/sys/mman/munmap.h" diff --git a/libc/test/src/arpa/CMakeLists.txt b/libc/test/src/arpa/CMakeLists.txt new file mode 100644 index 000000000000..5c89828860ff --- /dev/null +++ b/libc/test/src/arpa/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(inet) diff --git a/libc/test/src/arpa/inet/CMakeLists.txt b/libc/test/src/arpa/inet/CMakeLists.txt new file mode 100644 index 000000000000..6e78e3a50e61 --- /dev/null +++ b/libc/test/src/arpa/inet/CMakeLists.txt @@ -0,0 +1,53 @@ +add_custom_target(libc_arpa_inet_unittests) + +add_libc_unittest( + htonl + SUITE + libc_arpa_inet_unittests + SRCS + htonl_test.cpp + CXX_STANDARD + 20 + DEPENDS + libc.src.arpa.inet.htonl + libc.src.arpa.inet.ntohl +) + +add_libc_unittest( + htons + SUITE + libc_arpa_inet_unittests + SRCS + htons_test.cpp + CXX_STANDARD + 20 + DEPENDS + libc.src.arpa.inet.htons + libc.src.arpa.inet.ntohs +) + +add_libc_unittest( + ntohl + SUITE + libc_arpa_inet_unittests + SRCS + ntohl_test.cpp + CXX_STANDARD + 20 + DEPENDS + libc.src.arpa.inet.htonl + libc.src.arpa.inet.ntohl +) + +add_libc_unittest( + ntohs + SUITE + libc_arpa_inet_unittests + SRCS + ntohs_test.cpp + CXX_STANDARD + 20 + DEPENDS + libc.src.arpa.inet.htons + libc.src.arpa.inet.ntohs +) diff --git a/libc/test/src/network/htonl_test.cpp b/libc/test/src/arpa/inet/htonl_test.cpp index f2e2541312c3..4cc1e4cb4e88 100644 --- a/libc/test/src/network/htonl_test.cpp +++ b/libc/test/src/arpa/inet/htonl_test.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "src/__support/endian_internal.h" -#include "src/network/htonl.h" -#include "src/network/ntohl.h" +#include "src/arpa/inet/htonl.h" +#include "src/arpa/inet/ntohl.h" #include "test/UnitTest/Test.h" TEST(LlvmLibcHtonl, SmokeTest) { diff --git a/libc/test/src/network/htons_test.cpp b/libc/test/src/arpa/inet/htons_test.cpp index 9668162523ce..6a95ec5587e9 100644 --- a/libc/test/src/network/htons_test.cpp +++ b/libc/test/src/arpa/inet/htons_test.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "src/__support/endian_internal.h" -#include "src/network/htons.h" -#include "src/network/ntohs.h" +#include "src/arpa/inet/htons.h" +#include "src/arpa/inet/ntohs.h" #include "test/UnitTest/Test.h" TEST(LlvmLibcHtons, SmokeTest) { diff --git a/libc/test/src/network/ntohl_test.cpp b/libc/test/src/arpa/inet/ntohl_test.cpp index b72456b7200e..42562486d5c0 100644 --- a/libc/test/src/network/ntohl_test.cpp +++ b/libc/test/src/arpa/inet/ntohl_test.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "src/__support/endian_internal.h" -#include "src/network/htonl.h" -#include "src/network/ntohl.h" +#include "src/arpa/inet/htonl.h" +#include "src/arpa/inet/ntohl.h" #include "test/UnitTest/Test.h" TEST(LlvmLibcNtohl, SmokeTest) { diff --git a/libc/test/src/network/ntohs_test.cpp b/libc/test/src/arpa/inet/ntohs_test.cpp index 1104356076b9..38b2c8d8fe40 100644 --- a/libc/test/src/network/ntohs_test.cpp +++ b/libc/test/src/arpa/inet/ntohs_test.cpp @@ -7,8 +7,8 @@ //===----------------------------------------------------------------------===// #include "src/__support/endian_internal.h" -#include "src/network/htons.h" -#include "src/network/ntohs.h" +#include "src/arpa/inet/htons.h" +#include "src/arpa/inet/ntohs.h" #include "test/UnitTest/Test.h" TEST(LlvmLibcNtohs, SmokeTest) { diff --git a/libc/test/src/complex/CImagTest.h b/libc/test/src/complex/CImagTest.h index 6d2f93500266..408460d97dfc 100644 --- a/libc/test/src/complex/CImagTest.h +++ b/libc/test/src/complex/CImagTest.h @@ -38,9 +38,14 @@ public: neg_min_denormal); EXPECT_FP_EQ(func(CFPT(1241.112 + max_denormal * 1.0i)), max_denormal); EXPECT_FP_EQ(func(CFPT(121.121 + zero * 1.0i)), zero); - EXPECT_FP_EQ(func(CFPT(neg_zero + zero * 1.0i)), zero); - EXPECT_FP_EQ(func(CFPT(neg_zero + neg_zero * 1.0i)), neg_zero); - EXPECT_FP_EQ(func(CFPT(zero + neg_zero * 1.0i)), neg_zero); + EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), 0.0); + EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), 0.0); + EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), -0.0); + EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), -0.0); + EXPECT_FP_EQ(func(CFPT(0.0)), 0.0); + EXPECT_FP_EQ(func(CFPT(-0.0)), 0.0); + EXPECT_FP_EQ(func(CFPT(0.0i)), 0.0); + EXPECT_FP_EQ(func(CFPT(-0.0i)), -0.0); } void testRoundedNumbers(CImagFunc func) { diff --git a/libc/test/src/complex/CMakeLists.txt b/libc/test/src/complex/CMakeLists.txt index 8f49e6d79e17..d6b62e4686a2 100644 --- a/libc/test/src/complex/CMakeLists.txt +++ b/libc/test/src/complex/CMakeLists.txt @@ -1,6 +1,126 @@ add_custom_target(libc-complex-unittests) add_libc_test( + conj_test + SUITE + libc-complex-unittests + SRCS + conj_test.cpp + DEPENDS + libc.src.complex.conj + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + conjf_test + SUITE + libc-complex-unittests + SRCS + conjf_test.cpp + DEPENDS + libc.src.complex.conjf + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + conjl_test + SUITE + libc-complex-unittests + SRCS + conjl_test.cpp + DEPENDS + libc.src.complex.conjl + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + conjf16_test + SUITE + libc-complex-unittests + SRCS + conjf16_test.cpp + DEPENDS + libc.src.complex.conjf16 + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + conjf128_test + SUITE + libc-complex-unittests + SRCS + conjf128_test.cpp + DEPENDS + libc.src.complex.conjf128 + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + cproj_test + SUITE + libc-complex-unittests + SRCS + cproj_test.cpp + DEPENDS + libc.src.complex.cproj + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + cprojf_test + SUITE + libc-complex-unittests + SRCS + cprojf_test.cpp + DEPENDS + libc.src.complex.cprojf + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + cprojl_test + SUITE + libc-complex-unittests + SRCS + cprojl_test.cpp + DEPENDS + libc.src.complex.cprojl + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + cprojf16_test + SUITE + libc-complex-unittests + SRCS + cprojf16_test.cpp + DEPENDS + libc.src.complex.cprojf16 + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( + cprojf128_test + SUITE + libc-complex-unittests + SRCS + cprojf128_test.cpp + DEPENDS + libc.src.complex.cprojf128 + LINK_LIBRARIES + LibcFPTestHelpers +) + +add_libc_test( creal_test SUITE libc-complex-unittests diff --git a/libc/test/src/complex/CRealTest.h b/libc/test/src/complex/CRealTest.h index a25555b506e2..80eafc9975f4 100644 --- a/libc/test/src/complex/CRealTest.h +++ b/libc/test/src/complex/CRealTest.h @@ -37,8 +37,14 @@ public: EXPECT_FP_EQ(func(CFPT(neg_min_denormal + 781.134i)), neg_min_denormal); EXPECT_FP_EQ(func(CFPT(max_denormal + 1241.112i)), max_denormal); EXPECT_FP_EQ(func(CFPT(zero + 121.121i)), zero); - EXPECT_FP_EQ(func(CFPT(neg_zero + neg_zero * 1.0i)), neg_zero); - EXPECT_FP_EQ(func(CFPT(neg_zero + zero * 1.0i)), zero); + EXPECT_FP_EQ(func(CFPT(0.0 + 0.0i)), 0.0); + EXPECT_FP_EQ(func(CFPT(-0.0 + 0.0i)), 0.0); + EXPECT_FP_EQ(func(CFPT(0.0 - 0.0i)), 0.0); + EXPECT_FP_EQ(func(CFPT(-0.0 - 0.0i)), -0.0); + EXPECT_FP_EQ(func(CFPT(0.0)), 0.0); + EXPECT_FP_EQ(func(CFPT(-0.0)), -0.0); + EXPECT_FP_EQ(func(CFPT(0.0i)), 0.0); + EXPECT_FP_EQ(func(CFPT(-0.0i)), -0.0); } void testRoundedNumbers(CRealFunc func) { diff --git a/libc/test/src/complex/ConjTest.h b/libc/test/src/complex/ConjTest.h new file mode 100644 index 000000000000..da4fb4fd137c --- /dev/null +++ b/libc/test/src/complex/ConjTest.h @@ -0,0 +1,131 @@ +//===-- Utility class to test different flavors of conj ---------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_COMPLEX_CONJTEST_H +#define LLVM_LIBC_TEST_SRC_COMPLEX_CONJTEST_H + +#include "test/UnitTest/FEnvSafeTest.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include "hdr/math_macros.h" + +template <typename CFPT, typename FPT> +class ConjTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { + + DECLARE_SPECIAL_CONSTANTS(FPT) + +public: + typedef CFPT (*ConjFunc)(CFPT); + + void testSpecialNumbers(ConjFunc func) { + EXPECT_CFP_EQ(func(CFPT(aNaN + 67.123i)), CFPT(aNaN - 67.123i)); + EXPECT_CFP_EQ(func(CFPT(neg_aNaN + 78.319i)), CFPT(neg_aNaN - 78.319i)); + EXPECT_CFP_EQ(func(CFPT(sNaN + 7813.131i)), CFPT(sNaN - 7813.131i)); + EXPECT_CFP_EQ(func(CFPT(neg_sNaN + 7824.152i)), CFPT(neg_sNaN - 7824.152i)); + EXPECT_CFP_EQ(func(CFPT(inf + 9024.2442i)), CFPT(inf - 9024.2442i)); + EXPECT_CFP_EQ(func(CFPT(neg_inf + 8923.124i)), CFPT(neg_inf - 8923.124i)); + EXPECT_CFP_EQ(func(CFPT(min_normal + 782.124i)), + CFPT(min_normal - 782.124i)); + EXPECT_CFP_EQ(func(CFPT(max_normal + 2141.2352i)), + CFPT(max_normal - 2141.2352i)); + EXPECT_CFP_EQ(func(CFPT(neg_max_normal + 341.134i)), + CFPT(neg_max_normal - 341.134i)); + EXPECT_CFP_EQ(func(CFPT(min_denormal + 781.142i)), + CFPT(min_denormal - 781.142i)); + EXPECT_CFP_EQ(func(CFPT(neg_min_denormal + 781.134i)), + CFPT(neg_min_denormal - 781.134i)); + EXPECT_CFP_EQ(func(CFPT(max_denormal + 1241.112i)), + CFPT(max_denormal - 1241.112i)); + EXPECT_CFP_EQ(func(CFPT(zero + 121.121i)), CFPT(zero - 121.121i)); + EXPECT_CFP_EQ(func(CFPT(67.123 + aNaN * 1.0i)), CFPT(67.123 - aNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(78.319 + neg_aNaN * 1.0i)), + CFPT(78.319 - neg_aNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(7813.131 + sNaN * 1.0i)), + CFPT(7813.131 - sNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(7824.152 + neg_sNaN * 1.0i)), + CFPT(7824.152 - neg_sNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(9024.2442 + inf * 1.0i)), + CFPT(9024.2442 - inf * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(8923.124 + neg_inf * 1.0i)), + CFPT(8923.124 - neg_inf * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(782.124 + min_normal * 1.0i)), + CFPT(782.124 - min_normal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(2141.2352 + max_normal * 1.0i)), + CFPT(2141.2352 - max_normal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(341.134 + neg_max_normal * 1.0i)), + CFPT(341.134 - neg_max_normal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(781.142 + min_denormal * 1.0i)), + CFPT(781.142 - min_denormal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(781.134 + neg_min_denormal * 1.0i)), + CFPT(781.134 - neg_min_denormal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(1241.112 + max_denormal * 1.0i)), + CFPT(1241.112 - max_denormal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(121.121 + zero * 1.0i)), + CFPT(121.121 - zero * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(0.0 - 0.0i)), CFPT(0.0 + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(0.0 + 0.0i)), CFPT(0.0 - 0.0i)); + // This test passes because the conjugate of -0.0 - 0.0i is CMPLX(-0.0, 0.0) + // which cannot be represented as -0.0 + 0.0i because -0.0 + 0.0i is + // actually CMPLX(-0.0, 0.0) + CMPLX(0.0, 0.0) = 0.0 + 0.0i so to represent + // CMPLX(-0.0, 0.0), we use -0.0 + EXPECT_CFP_EQ(func(CFPT(-0.0 - 0.0i)), CFPT(-0.0)); + // This test passes because -0.0 + 0.0i is actually + // CMPLX(-0.0, 0.0) + CMPLX(0.0, 0.0) = CMPLX(-0.0 + 0.0, 0.0) = 0.0 + 0.0i + EXPECT_CFP_EQ(func(CFPT(-0.0 + 0.0i)), CFPT(0.0 - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(0.0)), CFPT(0.0 - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(-0.0)), CFPT(-0.0 - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(0.0i)), CFPT(0.0 - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(-0.0i)), CFPT(-0.0)); + } + + void testRoundedNumbers(ConjFunc func) { + EXPECT_CFP_EQ(func((CFPT)(4523.1413 + 12413.1414i)), + CFPT(4523.1413 - 12413.1414i)); + EXPECT_CFP_EQ(func((CFPT)(-4523.1413 + 12413.1414i)), + CFPT(-4523.1413 - 12413.1414i)); + EXPECT_CFP_EQ(func((CFPT)(4523.1413 - 12413.1414i)), + CFPT(4523.1413 + 12413.1414i)); + EXPECT_CFP_EQ(func((CFPT)(-4523.1413 - 12413.1414i)), + CFPT(-4523.1413 + 12413.1414i)); + + EXPECT_CFP_EQ(func((CFPT)(3210.5678 + 9876.5432i)), + CFPT(3210.5678 - 9876.5432i)); + EXPECT_CFP_EQ(func((CFPT)(-3210.5678 + 9876.5432i)), + CFPT(-3210.5678 - 9876.5432i)); + EXPECT_CFP_EQ(func((CFPT)(3210.5678 - 9876.5432i)), + CFPT(3210.5678 + 9876.5432i)); + EXPECT_CFP_EQ(func((CFPT)(-3210.5678 - 9876.5432i)), + CFPT(-3210.5678 + 9876.5432i)); + + EXPECT_CFP_EQ(func((CFPT)(1234.4321 + 4321.1234i)), + CFPT(1234.4321 - 4321.1234i)); + EXPECT_CFP_EQ(func((CFPT)(-1234.4321 + 4321.1234i)), + CFPT(-1234.4321 - 4321.1234i)); + EXPECT_CFP_EQ(func((CFPT)(1234.4321 - 4321.1234i)), + CFPT(1234.4321 + 4321.1234i)); + EXPECT_CFP_EQ(func((CFPT)(-1234.4321 - 4321.1234i)), + CFPT(-1234.4321 + 4321.1234i)); + + EXPECT_CFP_EQ(func((CFPT)(6789.1234 + 8765.6789i)), + CFPT(6789.1234 - 8765.6789i)); + EXPECT_CFP_EQ(func((CFPT)(-6789.1234 + 8765.6789i)), + CFPT(-6789.1234 - 8765.6789i)); + EXPECT_CFP_EQ(func((CFPT)(6789.1234 - 8765.6789i)), + CFPT(6789.1234 + 8765.6789i)); + EXPECT_CFP_EQ(func((CFPT)(-6789.1234 - 8765.6789i)), + CFPT(-6789.1234 + 8765.6789i)); + } +}; + +#define LIST_CONJ_TESTS(U, T, func) \ + using LlvmLibcConjTest = ConjTest<U, T>; \ + TEST_F(LlvmLibcConjTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcConjTest, RoundedNumbers) { testRoundedNumbers(&func); } + +#endif // LLVM_LIBC_TEST_SRC_COMPLEX_CONJTEST_H diff --git a/libc/test/src/complex/CprojTest.h b/libc/test/src/complex/CprojTest.h new file mode 100644 index 000000000000..4e2f6cc58a5a --- /dev/null +++ b/libc/test/src/complex/CprojTest.h @@ -0,0 +1,131 @@ +//===-- Utility class to test different flavors of cproj --------*- C++ -*-===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_SRC_COMPLEX_CPROJTEST_H +#define LLVM_LIBC_TEST_SRC_COMPLEX_CPROJTEST_H + +#include "test/UnitTest/FEnvSafeTest.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include "hdr/math_macros.h" + +template <typename CFPT, typename FPT> +class CprojTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { + + DECLARE_SPECIAL_CONSTANTS(FPT) + +public: + typedef CFPT (*CprojFunc)(CFPT); + + void testSpecialNumbers(CprojFunc func) { + EXPECT_CFP_EQ(func(CFPT(inf + 9024.2442i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(inf - 9024.2442i)), CFPT(inf - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(neg_inf + 8923.124i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(neg_inf - 8923.124i)), CFPT(inf - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(9024.2442 + inf * 1.0i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(9024.2442 + neg_inf * 1.0i)), CFPT(inf - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(inf + neg_inf * 1.0i)), CFPT(inf - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(inf + inf * 1.0i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(neg_inf + neg_inf * 1.0i)), CFPT(inf - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(neg_inf + inf * 1.0i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(neg_inf + inf * 1.0i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(aNaN + inf * 1.0i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(aNaN + neg_inf * 1.0i)), CFPT(inf - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(90.24 + inf * 1.0i)), CFPT(inf + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(89.12 + neg_inf * 1.0i)), CFPT(inf - 0.0i)); + + EXPECT_CFP_EQ(func(CFPT(aNaN + 67.123i)), CFPT(aNaN + 67.123i)); + EXPECT_CFP_EQ(func(CFPT(neg_aNaN + 78.319i)), CFPT(neg_aNaN + 78.319i)); + EXPECT_CFP_EQ(func(CFPT(sNaN + 7813.131i)), CFPT(sNaN + 7813.131i)); + EXPECT_CFP_EQ(func(CFPT(neg_sNaN + 7824.152i)), CFPT(neg_sNaN + 7824.152i)); + EXPECT_CFP_EQ(func(CFPT(min_normal + 782.124i)), + CFPT(min_normal + 782.124i)); + EXPECT_CFP_EQ(func(CFPT(max_normal + 2141.2352i)), + CFPT(max_normal + 2141.2352i)); + EXPECT_CFP_EQ(func(CFPT(neg_max_normal + 341.134i)), + CFPT(neg_max_normal + 341.134i)); + EXPECT_CFP_EQ(func(CFPT(min_denormal + 781.142i)), + CFPT(min_denormal + 781.142i)); + EXPECT_CFP_EQ(func(CFPT(neg_min_denormal + 781.134i)), + CFPT(neg_min_denormal + 781.134i)); + EXPECT_CFP_EQ(func(CFPT(max_denormal + 1241.112i)), + CFPT(max_denormal + 1241.112i)); + EXPECT_CFP_EQ(func(CFPT(zero + 121.121i)), CFPT(zero + 121.121i)); + EXPECT_CFP_EQ(func(CFPT(67.123 + aNaN * 1.0i)), CFPT(67.123 + aNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(78.319 + neg_aNaN * 1.0i)), + CFPT(78.319 + neg_aNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(7813.131 + sNaN * 1.0i)), + CFPT(7813.131 + sNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(7824.152 + neg_sNaN * 1.0i)), + CFPT(7824.152 + neg_sNaN * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(782.124 + min_normal * 1.0i)), + CFPT(782.124 + min_normal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(2141.2352 + max_normal * 1.0i)), + CFPT(2141.2352 + max_normal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(341.134 + neg_max_normal * 1.0i)), + CFPT(341.134 + neg_max_normal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(781.142 + min_denormal * 1.0i)), + CFPT(781.142 + min_denormal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(781.134 + neg_min_denormal * 1.0i)), + CFPT(781.134 + neg_min_denormal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(1241.112 + max_denormal * 1.0i)), + CFPT(1241.112 + max_denormal * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(121.121 + zero * 1.0i)), + CFPT(121.121 + zero * 1.0i)); + EXPECT_CFP_EQ(func(CFPT(0.0 - 0.0i)), CFPT(0.0 - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(0.0 + 0.0i)), CFPT(0.0 + 0.0i)); + EXPECT_CFP_EQ(func(CFPT(-0.0 - 0.0i)), CFPT(-0.0 - 0.0i)); + EXPECT_CFP_EQ(func(CFPT(-0.0 + 0.0i)), CFPT(-0.0 + 0.0i)); + } + + void testRoundedNumbers(CprojFunc func) { + EXPECT_CFP_EQ(func((CFPT)(4523.1413 + 12413.1414i)), + CFPT(4523.1413 + 12413.1414i)); + EXPECT_CFP_EQ(func((CFPT)(-4523.1413 + 12413.1414i)), + CFPT(-4523.1413 + 12413.1414i)); + EXPECT_CFP_EQ(func((CFPT)(4523.1413 - 12413.1414i)), + CFPT(4523.1413 - 12413.1414i)); + EXPECT_CFP_EQ(func((CFPT)(-4523.1413 - 12413.1414i)), + CFPT(-4523.1413 - 12413.1414i)); + + EXPECT_CFP_EQ(func((CFPT)(3210.5678 + 9876.5432i)), + CFPT(3210.5678 + 9876.5432i)); + EXPECT_CFP_EQ(func((CFPT)(-3210.5678 + 9876.5432i)), + CFPT(-3210.5678 + 9876.5432i)); + EXPECT_CFP_EQ(func((CFPT)(3210.5678 - 9876.5432i)), + CFPT(3210.5678 - 9876.5432i)); + EXPECT_CFP_EQ(func((CFPT)(-3210.5678 - 9876.5432i)), + CFPT(-3210.5678 - 9876.5432i)); + + EXPECT_CFP_EQ(func((CFPT)(1234.4321 + 4321.1234i)), + CFPT(1234.4321 + 4321.1234i)); + EXPECT_CFP_EQ(func((CFPT)(-1234.4321 + 4321.1234i)), + CFPT(-1234.4321 + 4321.1234i)); + EXPECT_CFP_EQ(func((CFPT)(1234.4321 - 4321.1234i)), + CFPT(1234.4321 - 4321.1234i)); + EXPECT_CFP_EQ(func((CFPT)(-1234.4321 - 4321.1234i)), + CFPT(-1234.4321 - 4321.1234i)); + + EXPECT_CFP_EQ(func((CFPT)(6789.1234 + 8765.6789i)), + CFPT(6789.1234 + 8765.6789i)); + EXPECT_CFP_EQ(func((CFPT)(-6789.1234 + 8765.6789i)), + CFPT(-6789.1234 + 8765.6789i)); + EXPECT_CFP_EQ(func((CFPT)(6789.1234 - 8765.6789i)), + CFPT(6789.1234 - 8765.6789i)); + EXPECT_CFP_EQ(func((CFPT)(-6789.1234 - 8765.6789i)), + CFPT(-6789.1234 - 8765.6789i)); + } +}; + +#define LIST_CPROJ_TESTS(U, T, func) \ + using LlvmLibcCprojTest = CprojTest<U, T>; \ + TEST_F(LlvmLibcCprojTest, SpecialNumbers) { testSpecialNumbers(&func); } \ + TEST_F(LlvmLibcCprojTest, RoundedNumbers) { testRoundedNumbers(&func); } + +#endif // LLVM_LIBC_TEST_SRC_COMPLEX_CPROJTEST_H diff --git a/libc/test/src/complex/cimagf128_test.cpp b/libc/test/src/complex/cimagf128_test.cpp index 50ddc0ab0616..70ad0de3d38f 100644 --- a/libc/test/src/complex/cimagf128_test.cpp +++ b/libc/test/src/complex/cimagf128_test.cpp @@ -10,8 +10,4 @@ #include "src/complex/cimagf128.h" -#if defined(LIBC_TYPES_HAS_CFLOAT128) - LIST_CIMAG_TESTS(cfloat128, float128, LIBC_NAMESPACE::cimagf128) - -#endif // LIBC_TYPES_HAS_CFLOAT128 diff --git a/libc/test/src/complex/cimagf16_test.cpp b/libc/test/src/complex/cimagf16_test.cpp index 65a69787ddbd..3842381351ab 100644 --- a/libc/test/src/complex/cimagf16_test.cpp +++ b/libc/test/src/complex/cimagf16_test.cpp @@ -10,8 +10,4 @@ #include "src/complex/cimagf16.h" -#if defined(LIBC_TYPES_HAS_CFLOAT16) - LIST_CIMAG_TESTS(cfloat16, float16, LIBC_NAMESPACE::cimagf16) - -#endif // LIBC_TYPES_HAS_CFLOAT16 diff --git a/libc/test/src/complex/conj_test.cpp b/libc/test/src/complex/conj_test.cpp new file mode 100644 index 000000000000..97445fa06508 --- /dev/null +++ b/libc/test/src/complex/conj_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for conj ------------------------------------------------===// +// +// 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 "ConjTest.h" + +#include "src/complex/conj.h" + +LIST_CONJ_TESTS(_Complex double, double, LIBC_NAMESPACE::conj) diff --git a/libc/test/src/complex/conjf128_test.cpp b/libc/test/src/complex/conjf128_test.cpp new file mode 100644 index 000000000000..4c2a72c6d39d --- /dev/null +++ b/libc/test/src/complex/conjf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for conjf128 --------------------------------------------===// +// +// 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 "ConjTest.h" + +#include "src/complex/conjf128.h" + +LIST_CONJ_TESTS(cfloat128, float128, LIBC_NAMESPACE::conjf128) diff --git a/libc/test/src/complex/conjf16_test.cpp b/libc/test/src/complex/conjf16_test.cpp new file mode 100644 index 000000000000..374f9ec3e624 --- /dev/null +++ b/libc/test/src/complex/conjf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for conjf16 ---------------------------------------------===// +// +// 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 "ConjTest.h" + +#include "src/complex/conjf16.h" + +LIST_CONJ_TESTS(cfloat16, float16, LIBC_NAMESPACE::conjf16) diff --git a/libc/test/src/complex/conjf_test.cpp b/libc/test/src/complex/conjf_test.cpp new file mode 100644 index 000000000000..34b00b37996c --- /dev/null +++ b/libc/test/src/complex/conjf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for conjf -----------------------------------------------===// +// +// 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 "ConjTest.h" + +#include "src/complex/conjf.h" + +LIST_CONJ_TESTS(_Complex float, float, LIBC_NAMESPACE::conjf) diff --git a/libc/test/src/complex/conjl_test.cpp b/libc/test/src/complex/conjl_test.cpp new file mode 100644 index 000000000000..ec299f963154 --- /dev/null +++ b/libc/test/src/complex/conjl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for conjl -----------------------------------------------===// +// +// 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 "ConjTest.h" + +#include "src/complex/conjl.h" + +LIST_CONJ_TESTS(_Complex long double, long double, LIBC_NAMESPACE::conjl) diff --git a/libc/test/src/complex/cproj_test.cpp b/libc/test/src/complex/cproj_test.cpp new file mode 100644 index 000000000000..83e5760f9ca8 --- /dev/null +++ b/libc/test/src/complex/cproj_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for cproj -----------------------------------------------===// +// +// 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 "CprojTest.h" + +#include "src/complex/cproj.h" + +LIST_CPROJ_TESTS(_Complex double, double, LIBC_NAMESPACE::cproj) diff --git a/libc/test/src/complex/cprojf128_test.cpp b/libc/test/src/complex/cprojf128_test.cpp new file mode 100644 index 000000000000..7b41eb5cf5f9 --- /dev/null +++ b/libc/test/src/complex/cprojf128_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for cprojf128 -------------------------------------------===// +// +// 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 "CprojTest.h" + +#include "src/complex/cprojf128.h" + +LIST_CPROJ_TESTS(cfloat128, float128, LIBC_NAMESPACE::cprojf128) diff --git a/libc/test/src/complex/cprojf16_test.cpp b/libc/test/src/complex/cprojf16_test.cpp new file mode 100644 index 000000000000..db9b7b9316bc --- /dev/null +++ b/libc/test/src/complex/cprojf16_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for cprojf16 --------------------------------------------===// +// +// 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 "CprojTest.h" + +#include "src/complex/cprojf16.h" + +LIST_CPROJ_TESTS(cfloat16, float16, LIBC_NAMESPACE::cprojf16) diff --git a/libc/test/src/complex/cprojf_test.cpp b/libc/test/src/complex/cprojf_test.cpp new file mode 100644 index 000000000000..7123ed4e28d4 --- /dev/null +++ b/libc/test/src/complex/cprojf_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for cprojf ----------------------------------------------===// +// +// 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 "CprojTest.h" + +#include "src/complex/cprojf.h" + +LIST_CPROJ_TESTS(_Complex float, float, LIBC_NAMESPACE::cprojf) diff --git a/libc/test/src/complex/cprojl_test.cpp b/libc/test/src/complex/cprojl_test.cpp new file mode 100644 index 000000000000..0858bf460188 --- /dev/null +++ b/libc/test/src/complex/cprojl_test.cpp @@ -0,0 +1,13 @@ +//===-- Unittests for cprojl ----------------------------------------------===// +// +// 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 "CprojTest.h" + +#include "src/complex/cprojl.h" + +LIST_CPROJ_TESTS(_Complex long double, long double, LIBC_NAMESPACE::cprojl) diff --git a/libc/test/src/complex/crealf128_test.cpp b/libc/test/src/complex/crealf128_test.cpp index 7626eeebca27..0d1c26df7737 100644 --- a/libc/test/src/complex/crealf128_test.cpp +++ b/libc/test/src/complex/crealf128_test.cpp @@ -10,8 +10,4 @@ #include "src/complex/crealf128.h" -#if defined(LIBC_TYPES_HAS_CFLOAT128) - LIST_CREAL_TESTS(cfloat128, float128, LIBC_NAMESPACE::crealf128) - -#endif // LIBC_TYPES_HAS_CFLOAT128 diff --git a/libc/test/src/complex/crealf16_test.cpp b/libc/test/src/complex/crealf16_test.cpp index 97346aad615f..b8560d74d35b 100644 --- a/libc/test/src/complex/crealf16_test.cpp +++ b/libc/test/src/complex/crealf16_test.cpp @@ -10,8 +10,4 @@ #include "src/complex/crealf16.h" -#if defined(LIBC_TYPES_HAS_CFLOAT16) - LIST_CREAL_TESTS(cfloat16, float16, LIBC_NAMESPACE::crealf16) - -#endif // LIBC_TYPES_HAS_CFLOAT16 diff --git a/libc/test/src/ctype/isalnum_test.cpp b/libc/test/src/ctype/isalnum_test.cpp index 18ddd2b14b8c..cfc54e95e922 100644 --- a/libc/test/src/ctype/isalnum_test.cpp +++ b/libc/test/src/ctype/isalnum_test.cpp @@ -11,16 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcIsAlNum, SimpleTest) { - EXPECT_NE(LIBC_NAMESPACE::isalnum('a'), 0); - EXPECT_NE(LIBC_NAMESPACE::isalnum('B'), 0); - EXPECT_NE(LIBC_NAMESPACE::isalnum('3'), 0); - - EXPECT_EQ(LIBC_NAMESPACE::isalnum(' '), 0); - EXPECT_EQ(LIBC_NAMESPACE::isalnum('?'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isalnum('\0'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isalnum(-1), 0); -} +namespace { // TODO: Merge the ctype tests using this framework. constexpr char ALNUM_ARRAY[] = { @@ -38,6 +29,19 @@ bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return false; } +} // namespace + +TEST(LlvmLibcIsAlNum, SimpleTest) { + EXPECT_NE(LIBC_NAMESPACE::isalnum('a'), 0); + EXPECT_NE(LIBC_NAMESPACE::isalnum('B'), 0); + EXPECT_NE(LIBC_NAMESPACE::isalnum('3'), 0); + + EXPECT_EQ(LIBC_NAMESPACE::isalnum(' '), 0); + EXPECT_EQ(LIBC_NAMESPACE::isalnum('?'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isalnum('\0'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isalnum(-1), 0); +} + TEST(LlvmLibcIsAlNum, DefaultLocale) { // Loops through all characters, verifying that numbers and letters // return non-zero integer and everything else returns a zero. diff --git a/libc/test/src/ctype/isalpha_test.cpp b/libc/test/src/ctype/isalpha_test.cpp index e54b580dbe26..1e439cf973e3 100644 --- a/libc/test/src/ctype/isalpha_test.cpp +++ b/libc/test/src/ctype/isalpha_test.cpp @@ -11,16 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcIsAlpha, SimpleTest) { - EXPECT_NE(LIBC_NAMESPACE::isalpha('a'), 0); - EXPECT_NE(LIBC_NAMESPACE::isalpha('B'), 0); - - EXPECT_EQ(LIBC_NAMESPACE::isalpha('3'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isalpha(' '), 0); - EXPECT_EQ(LIBC_NAMESPACE::isalpha('?'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isalpha('\0'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isalpha(-1), 0); -} +namespace { // TODO: Merge the ctype tests using this framework. constexpr char ALPHA_ARRAY[] = { @@ -37,6 +28,19 @@ bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return false; } +} // namespace + +TEST(LlvmLibcIsAlpha, SimpleTest) { + EXPECT_NE(LIBC_NAMESPACE::isalpha('a'), 0); + EXPECT_NE(LIBC_NAMESPACE::isalpha('B'), 0); + + EXPECT_EQ(LIBC_NAMESPACE::isalpha('3'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isalpha(' '), 0); + EXPECT_EQ(LIBC_NAMESPACE::isalpha('?'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isalpha('\0'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isalpha(-1), 0); +} + TEST(LlvmLibcIsAlpha, DefaultLocale) { // Loops through all characters, verifying that letters return a // non-zero integer and everything else returns zero. diff --git a/libc/test/src/ctype/isdigit_test.cpp b/libc/test/src/ctype/isdigit_test.cpp index adea55e59c74..0ee132d7f851 100644 --- a/libc/test/src/ctype/isdigit_test.cpp +++ b/libc/test/src/ctype/isdigit_test.cpp @@ -11,16 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcIsDigit, SimpleTest) { - EXPECT_NE(LIBC_NAMESPACE::isdigit('3'), 0); - - EXPECT_EQ(LIBC_NAMESPACE::isdigit('a'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isdigit('B'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isdigit(' '), 0); - EXPECT_EQ(LIBC_NAMESPACE::isdigit('?'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isdigit('\0'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isdigit(-1), 0); -} +namespace { // TODO: Merge the ctype tests using this framework. constexpr char DIGIT_ARRAY[] = { @@ -34,6 +25,19 @@ bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return false; } +} // namespace + +TEST(LlvmLibcIsDigit, SimpleTest) { + EXPECT_NE(LIBC_NAMESPACE::isdigit('3'), 0); + + EXPECT_EQ(LIBC_NAMESPACE::isdigit('a'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isdigit('B'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isdigit(' '), 0); + EXPECT_EQ(LIBC_NAMESPACE::isdigit('?'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isdigit('\0'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isdigit(-1), 0); +} + TEST(LlvmLibcIsDigit, DefaultLocale) { // Loops through all characters, verifying that numbers and letters // return non-zero integer and everything else returns a zero. diff --git a/libc/test/src/ctype/islower_test.cpp b/libc/test/src/ctype/islower_test.cpp index f9414bd8cbd0..f877171abb9a 100644 --- a/libc/test/src/ctype/islower_test.cpp +++ b/libc/test/src/ctype/islower_test.cpp @@ -11,16 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcIsLower, SimpleTest) { - EXPECT_NE(LIBC_NAMESPACE::islower('a'), 0); - - EXPECT_EQ(LIBC_NAMESPACE::islower('B'), 0); - EXPECT_EQ(LIBC_NAMESPACE::islower('3'), 0); - EXPECT_EQ(LIBC_NAMESPACE::islower(' '), 0); - EXPECT_EQ(LIBC_NAMESPACE::islower('?'), 0); - EXPECT_EQ(LIBC_NAMESPACE::islower('\0'), 0); - EXPECT_EQ(LIBC_NAMESPACE::islower(-1), 0); -} +namespace { // TODO: Merge the ctype tests using this framework. constexpr char LOWER_ARRAY[] = { @@ -35,6 +26,19 @@ bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return false; } +} // namespace + +TEST(LlvmLibcIsLower, SimpleTest) { + EXPECT_NE(LIBC_NAMESPACE::islower('a'), 0); + + EXPECT_EQ(LIBC_NAMESPACE::islower('B'), 0); + EXPECT_EQ(LIBC_NAMESPACE::islower('3'), 0); + EXPECT_EQ(LIBC_NAMESPACE::islower(' '), 0); + EXPECT_EQ(LIBC_NAMESPACE::islower('?'), 0); + EXPECT_EQ(LIBC_NAMESPACE::islower('\0'), 0); + EXPECT_EQ(LIBC_NAMESPACE::islower(-1), 0); +} + TEST(LlvmLibcIsLower, DefaultLocale) { // Loops through all characters, verifying that numbers and letters // return non-zero integer and everything else returns a zero. diff --git a/libc/test/src/ctype/isupper_test.cpp b/libc/test/src/ctype/isupper_test.cpp index 94def1a9dccc..151ed23f0ac9 100644 --- a/libc/test/src/ctype/isupper_test.cpp +++ b/libc/test/src/ctype/isupper_test.cpp @@ -11,16 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcIsUpper, SimpleTest) { - EXPECT_NE(LIBC_NAMESPACE::isupper('B'), 0); - - EXPECT_EQ(LIBC_NAMESPACE::isupper('a'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isupper('3'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isupper(' '), 0); - EXPECT_EQ(LIBC_NAMESPACE::isupper('?'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isupper('\0'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isupper(-1), 0); -} +namespace { // TODO: Merge the ctype tests using this framework. constexpr char UPPER_ARRAY[] = { @@ -35,6 +26,19 @@ bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return false; } +} // namespace + +TEST(LlvmLibcIsUpper, SimpleTest) { + EXPECT_NE(LIBC_NAMESPACE::isupper('B'), 0); + + EXPECT_EQ(LIBC_NAMESPACE::isupper('a'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isupper('3'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isupper(' '), 0); + EXPECT_EQ(LIBC_NAMESPACE::isupper('?'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isupper('\0'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isupper(-1), 0); +} + TEST(LlvmLibcIsUpper, DefaultLocale) { // Loops through all characters, verifying that numbers and letters // return non-zero integer and everything else returns a zero. diff --git a/libc/test/src/ctype/isxdigit_test.cpp b/libc/test/src/ctype/isxdigit_test.cpp index d7253d549907..ec58f0da4922 100644 --- a/libc/test/src/ctype/isxdigit_test.cpp +++ b/libc/test/src/ctype/isxdigit_test.cpp @@ -11,17 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcIsXdigit, SimpleTest) { - EXPECT_NE(LIBC_NAMESPACE::isxdigit('a'), 0); - EXPECT_NE(LIBC_NAMESPACE::isxdigit('B'), 0); - EXPECT_NE(LIBC_NAMESPACE::isxdigit('3'), 0); - - EXPECT_EQ(LIBC_NAMESPACE::isxdigit('z'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isxdigit(' '), 0); - EXPECT_EQ(LIBC_NAMESPACE::isxdigit('?'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isxdigit('\0'), 0); - EXPECT_EQ(LIBC_NAMESPACE::isxdigit(-1), 0); -} +namespace { // TODO: Merge the ctype tests using this framework. constexpr char XDIGIT_ARRAY[] = { @@ -36,6 +26,20 @@ bool in_span(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return false; } +} // namespace + +TEST(LlvmLibcIsXdigit, SimpleTest) { + EXPECT_NE(LIBC_NAMESPACE::isxdigit('a'), 0); + EXPECT_NE(LIBC_NAMESPACE::isxdigit('B'), 0); + EXPECT_NE(LIBC_NAMESPACE::isxdigit('3'), 0); + + EXPECT_EQ(LIBC_NAMESPACE::isxdigit('z'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isxdigit(' '), 0); + EXPECT_EQ(LIBC_NAMESPACE::isxdigit('?'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isxdigit('\0'), 0); + EXPECT_EQ(LIBC_NAMESPACE::isxdigit(-1), 0); +} + TEST(LlvmLibcIsXdigit, DefaultLocale) { // Loops through all characters, verifying that numbers and letters // return non-zero integer and everything else returns a zero. diff --git a/libc/test/src/ctype/tolower_test.cpp b/libc/test/src/ctype/tolower_test.cpp index 59432c43297b..fbcc5b8ee0d9 100644 --- a/libc/test/src/ctype/tolower_test.cpp +++ b/libc/test/src/ctype/tolower_test.cpp @@ -11,16 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcToLower, SimpleTest) { - EXPECT_EQ(LIBC_NAMESPACE::tolower('a'), int('a')); - EXPECT_EQ(LIBC_NAMESPACE::tolower('B'), int('b')); - EXPECT_EQ(LIBC_NAMESPACE::tolower('3'), int('3')); - - EXPECT_EQ(LIBC_NAMESPACE::tolower(' '), int(' ')); - EXPECT_EQ(LIBC_NAMESPACE::tolower('?'), int('?')); - EXPECT_EQ(LIBC_NAMESPACE::tolower('\0'), int('\0')); - EXPECT_EQ(LIBC_NAMESPACE::tolower(-1), int(-1)); -} +namespace { // TODO: Merge the ctype tests using this framework. // Invariant: UPPER_ARR and LOWER_ARR are both the complete alphabet in the same @@ -45,6 +36,19 @@ int span_index(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return -1; } +} // namespace + +TEST(LlvmLibcToLower, SimpleTest) { + EXPECT_EQ(LIBC_NAMESPACE::tolower('a'), int('a')); + EXPECT_EQ(LIBC_NAMESPACE::tolower('B'), int('b')); + EXPECT_EQ(LIBC_NAMESPACE::tolower('3'), int('3')); + + EXPECT_EQ(LIBC_NAMESPACE::tolower(' '), int(' ')); + EXPECT_EQ(LIBC_NAMESPACE::tolower('?'), int('?')); + EXPECT_EQ(LIBC_NAMESPACE::tolower('\0'), int('\0')); + EXPECT_EQ(LIBC_NAMESPACE::tolower(-1), int(-1)); +} + TEST(LlvmLibcToLower, DefaultLocale) { for (int ch = -255; ch < 255; ++ch) { int char_index = span_index(ch, UPPER_ARR); diff --git a/libc/test/src/ctype/toupper_test.cpp b/libc/test/src/ctype/toupper_test.cpp index 045b00bbb4b9..409b3cd96ed1 100644 --- a/libc/test/src/ctype/toupper_test.cpp +++ b/libc/test/src/ctype/toupper_test.cpp @@ -11,16 +11,7 @@ #include "test/UnitTest/Test.h" -TEST(LlvmLibcToUpper, SimpleTest) { - EXPECT_EQ(LIBC_NAMESPACE::toupper('a'), int('A')); - EXPECT_EQ(LIBC_NAMESPACE::toupper('B'), int('B')); - EXPECT_EQ(LIBC_NAMESPACE::toupper('3'), int('3')); - - EXPECT_EQ(LIBC_NAMESPACE::toupper(' '), int(' ')); - EXPECT_EQ(LIBC_NAMESPACE::toupper('?'), int('?')); - EXPECT_EQ(LIBC_NAMESPACE::toupper('\0'), int('\0')); - EXPECT_EQ(LIBC_NAMESPACE::toupper(-1), int(-1)); -} +namespace { // TODO: Merge the ctype tests using this framework. // Invariant: UPPER_ARR and LOWER_ARR are both the complete alphabet in the same @@ -45,6 +36,19 @@ int span_index(int ch, LIBC_NAMESPACE::cpp::span<const char> arr) { return -1; } +} // namespace + +TEST(LlvmLibcToUpper, SimpleTest) { + EXPECT_EQ(LIBC_NAMESPACE::toupper('a'), int('A')); + EXPECT_EQ(LIBC_NAMESPACE::toupper('B'), int('B')); + EXPECT_EQ(LIBC_NAMESPACE::toupper('3'), int('3')); + + EXPECT_EQ(LIBC_NAMESPACE::toupper(' '), int(' ')); + EXPECT_EQ(LIBC_NAMESPACE::toupper('?'), int('?')); + EXPECT_EQ(LIBC_NAMESPACE::toupper('\0'), int('\0')); + EXPECT_EQ(LIBC_NAMESPACE::toupper(-1), int(-1)); +} + TEST(LlvmLibcToUpper, DefaultLocale) { for (int ch = -255; ch < 255; ++ch) { int char_index = span_index(ch, LOWER_ARR); diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt index ea75720df4f4..16e7d4957ba1 100644 --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -29,6 +29,17 @@ add_fp_unittest( ) add_fp_unittest( + cosf16_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + cosf16_test.cpp + DEPENDS + libc.src.math.cosf16 +) + +add_fp_unittest( cospif_test NEED_MPFR SUITE @@ -1550,6 +1561,19 @@ add_fp_unittest( ) add_fp_unittest( + sqrtf128_test + NEED_MPFR + SUITE + libc-math-unittests + SRCS + sqrtf128_test.cpp + HDRS + SqrtTest.h + DEPENDS + libc.src.math.sqrtf128 +) + +add_fp_unittest( generic_sqrtf_test NEED_MPFR SUITE diff --git a/libc/test/src/math/cosf16_test.cpp b/libc/test/src/math/cosf16_test.cpp new file mode 100644 index 000000000000..9e4687f0325c --- /dev/null +++ b/libc/test/src/math/cosf16_test.cpp @@ -0,0 +1,40 @@ +//===-- Exhaustive test for cosf16 ----------------------------------------===// +// +// 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 "src/math/cosf16.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" +#include "utils/MPFRWrapper/MPFRUtils.h" + +using LlvmLibcCosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; + +namespace mpfr = LIBC_NAMESPACE::testing::mpfr; + +// Range: [0, Inf] +static constexpr uint16_t POS_START = 0x0000U; +static constexpr uint16_t POS_STOP = 0x7c00u; + +// Range: [-Inf, 0] +static constexpr uint16_t NEG_START = 0x8000U; +static constexpr uint16_t NEG_STOP = 0xfc00U; + +TEST_F(LlvmLibcCosf16Test, PositiveRange) { + for (uint16_t v = POS_START; v <= POS_STOP; ++v) { + float16 x = FPBits(v).get_val(); + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x, + LIBC_NAMESPACE::cosf16(x), 0.5); + } +} + +TEST_F(LlvmLibcCosf16Test, NegativeRange) { + for (uint16_t v = NEG_START; v <= NEG_STOP; ++v) { + float16 x = FPBits(v).get_val(); + EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Cos, x, + LIBC_NAMESPACE::cosf16(x), 0.5); + } +} diff --git a/libc/test/src/math/smoke/CMakeLists.txt b/libc/test/src/math/smoke/CMakeLists.txt index 2c1c4dba7384..31f85a3ecfd2 100644 --- a/libc/test/src/math/smoke/CMakeLists.txt +++ b/libc/test/src/math/smoke/CMakeLists.txt @@ -13,6 +13,17 @@ add_fp_unittest( ) add_fp_unittest( + cosf16_test + SUITE + libc-math-smoke-tests + SRCS + cosf16_test.cpp + DEPENDS + libc.src.errno.errno + libc.src.math.cosf16 +) + +add_fp_unittest( cospif_test SUITE libc-math-smoke-tests diff --git a/libc/test/src/math/smoke/CanonicalizeTest.h b/libc/test/src/math/smoke/CanonicalizeTest.h index ef75f568b827..e500bc38f985 100644 --- a/libc/test/src/math/smoke/CanonicalizeTest.h +++ b/libc/test/src/math/smoke/CanonicalizeTest.h @@ -19,6 +19,7 @@ #include "hdr/math_macros.h" #define TEST_SPECIAL(x, y, expected, expected_exception) \ + LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT); \ EXPECT_EQ(expected, f(&x, &y)); \ EXPECT_FP_EXCEPTION(expected_exception); \ LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT) diff --git a/libc/test/src/math/smoke/FModTest.h b/libc/test/src/math/smoke/FModTest.h index ad9688fc01e7..8fbcc2a27654 100644 --- a/libc/test/src/math/smoke/FModTest.h +++ b/libc/test/src/math/smoke/FModTest.h @@ -18,6 +18,7 @@ #include "hdr/fenv_macros.h" #define TEST_SPECIAL(x, y, expected, dom_err, expected_exception) \ + LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT); \ EXPECT_FP_EQ(expected, f(x, y)); \ EXPECT_MATH_ERRNO((dom_err) ? EDOM : 0); \ EXPECT_FP_EXCEPTION(expected_exception); \ diff --git a/libc/test/src/math/smoke/cosf16_test.cpp b/libc/test/src/math/smoke/cosf16_test.cpp new file mode 100644 index 000000000000..9a51d1015da3 --- /dev/null +++ b/libc/test/src/math/smoke/cosf16_test.cpp @@ -0,0 +1,33 @@ +//===-- Unittests for cosf16 ----------------------------------------------===// +// +// 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 "src/errno/libc_errno.h" +#include "src/math/cosf16.h" +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +using LlvmLibcCosf16Test = LIBC_NAMESPACE::testing::FPTest<float16>; + +TEST_F(LlvmLibcCosf16Test, SpecialNumbers) { + LIBC_NAMESPACE::libc_errno = 0; + + EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cosf16(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cosf16(zero)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(1.0f, LIBC_NAMESPACE::cosf16(neg_zero)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cosf16(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::cosf16(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +} diff --git a/libc/test/src/math/sqrtf128_test.cpp b/libc/test/src/math/sqrtf128_test.cpp new file mode 100644 index 000000000000..25229f834d33 --- /dev/null +++ b/libc/test/src/math/sqrtf128_test.cpp @@ -0,0 +1,43 @@ +//===-- Unittests for sqrtf128 --------------------------------------------===// +// +// 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 "SqrtTest.h" + +#include "src/math/sqrtf128.h" + +#include "src/__support/integer_literals.h" + +LIST_SQRT_TESTS(float128, LIBC_NAMESPACE::sqrtf128) + +TEST_F(LlvmLibcSqrtTest, SpecialInputs) { + constexpr float128 INPUTS[] = { + 0x0.000000dee2f5b6a26c8f07f05442p-16382q, + 0x0.000000c86d174c5ad8ae54a548e7p-16382q, + 0x0.000020ab15cfe0b8e488e128f535p-16382q, + 0x0.0000219e97732a9970f2511989bap-16382q, + 0x0.000026e477546ae99ef57066f9fdp-16382q, + 0x0.00002d0f88d27a496b3e533f5067p-16382q, + 0x1.0000000000000000000000000001p+0q, + 0x1.0000000000000000000000000003p+0q, + 0x1.0000000000000000000000000005p+0q, + 0x1.2af17a4ae6f93d11310c49c11b59p+0q, + 0x1.c4f5074269525063a26051a0ad27p+0q, + 0x1.035cb5f298a801dc4be9b1f8cd97p+1q, + 0x1.274be02380427e709beab4dedeb4p+1q, + 0x1.64e797cfdbaa3f7e2f33279dbc6p+1q, + 0x1.d78d8352b48608b510bfd5c75315p+1q, + 0x1.fffffffffffffffffffffffffffbp+1q, + 0x1.fffffffffffffffffffffffffffdp+1q, + 0x1.ffffffffffffffffffffffffffffp+1q, + }; + + for (auto input : INPUTS) { + ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Sqrt, input, + LIBC_NAMESPACE::sqrtf128(input), 0.5); + } +} diff --git a/libc/test/src/network/CMakeLists.txt b/libc/test/src/network/CMakeLists.txt deleted file mode 100644 index 222205dfe247..000000000000 --- a/libc/test/src/network/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -add_custom_target(libc_network_unittests) - -add_libc_unittest( - htonl - SUITE - libc_network_unittests - SRCS - htonl_test.cpp - CXX_STANDARD - 20 - DEPENDS - libc.src.network.htonl - libc.src.network.ntohl -) - -add_libc_unittest( - htons - SUITE - libc_network_unittests - SRCS - htons_test.cpp - CXX_STANDARD - 20 - DEPENDS - libc.src.network.htons - libc.src.network.ntohs -) - -add_libc_unittest( - ntohl - SUITE - libc_network_unittests - SRCS - ntohl_test.cpp - CXX_STANDARD - 20 - DEPENDS - libc.src.network.htonl - libc.src.network.ntohl -) - -add_libc_unittest( - ntohs - SUITE - libc_network_unittests - SRCS - ntohs_test.cpp - CXX_STANDARD - 20 - DEPENDS - libc.src.network.htons - libc.src.network.ntohs -) diff --git a/libc/test/src/stdlib/CMakeLists.txt b/libc/test/src/stdlib/CMakeLists.txt index ff6034e43e9f..4ca2043ab4c9 100644 --- a/libc/test/src/stdlib/CMakeLists.txt +++ b/libc/test/src/stdlib/CMakeLists.txt @@ -431,8 +431,8 @@ if(LLVM_LIBC_FULL_BUILD) libc.src.stdlib.quick_exit ) - # Only the GPU has an in-tree 'malloc' implementation. - if(LIBC_TARGET_OS_IS_GPU) + # Only baremetal and GPU has an in-tree 'malloc' implementation. + if(LIBC_TARGET_OS_IS_BAREMETAL OR LIBC_TARGET_OS_IS_GPU) add_libc_test( malloc_test HERMETIC_TEST_ONLY diff --git a/libc/test/src/stdlib/StrtolTest.h b/libc/test/src/stdlib/StrtolTest.h index 6cfaddcbedeb..ed302f14d03e 100644 --- a/libc/test/src/stdlib/StrtolTest.h +++ b/libc/test/src/stdlib/StrtolTest.h @@ -200,8 +200,8 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test { char small_string[4] = {'\0', '\0', '\0', '\0'}; for (int base = 2; base <= 36; ++base) { for (int first_digit = 0; first_digit <= 36; ++first_digit) { - small_string[0] = - LIBC_NAMESPACE::internal::int_to_b36_char(first_digit); + small_string[0] = static_cast<char>( + LIBC_NAMESPACE::internal::int_to_b36_char(first_digit)); if (first_digit < base) { LIBC_NAMESPACE::libc_errno = 0; ASSERT_EQ(func(small_string, nullptr, base), @@ -217,11 +217,11 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test { for (int base = 2; base <= 36; ++base) { for (int first_digit = 0; first_digit <= 36; ++first_digit) { - small_string[0] = - LIBC_NAMESPACE::internal::int_to_b36_char(first_digit); + small_string[0] = static_cast<char>( + LIBC_NAMESPACE::internal::int_to_b36_char(first_digit)); for (int second_digit = 0; second_digit <= 36; ++second_digit) { - small_string[1] = - LIBC_NAMESPACE::internal::int_to_b36_char(second_digit); + small_string[1] = static_cast<char>( + LIBC_NAMESPACE::internal::int_to_b36_char(second_digit)); if (first_digit < base && second_digit < base) { LIBC_NAMESPACE::libc_errno = 0; ASSERT_EQ( @@ -244,14 +244,14 @@ struct StrtoTest : public LIBC_NAMESPACE::testing::Test { for (int base = 2; base <= 36; ++base) { for (int first_digit = 0; first_digit <= 36; ++first_digit) { - small_string[0] = - LIBC_NAMESPACE::internal::int_to_b36_char(first_digit); + small_string[0] = static_cast<char>( + LIBC_NAMESPACE::internal::int_to_b36_char(first_digit)); for (int second_digit = 0; second_digit <= 36; ++second_digit) { - small_string[1] = - LIBC_NAMESPACE::internal::int_to_b36_char(second_digit); + small_string[1] = static_cast<char>( + LIBC_NAMESPACE::internal::int_to_b36_char(second_digit)); for (int third_digit = 0; third_digit <= limit; ++third_digit) { - small_string[2] = - LIBC_NAMESPACE::internal::int_to_b36_char(third_digit); + small_string[2] = static_cast<char>( + LIBC_NAMESPACE::internal::int_to_b36_char(third_digit)); if (first_digit < base && second_digit < base && third_digit < base) { diff --git a/libc/test/src/string/CMakeLists.txt b/libc/test/src/string/CMakeLists.txt index b6b59a689cc8..a675373938e9 100644 --- a/libc/test/src/string/CMakeLists.txt +++ b/libc/test/src/string/CMakeLists.txt @@ -2,18 +2,6 @@ add_custom_target(libc-string-tests) add_subdirectory(memory_utils) -add_libc_test( - bcopy_test - SUITE - libc-string-tests - SRCS - bcopy_test.cpp - DEPENDS - libc.src.string.bcopy - LINK_LIBRARIES - LibcMemoryHelpers -) - add_header_library( strchr_test_support HDRS @@ -21,17 +9,6 @@ add_header_library( ) add_libc_test( - index_test - SUITE - libc-string-tests - SRCS - index_test.cpp - DEPENDS - libc.src.string.index - .strchr_test_support -) - -add_libc_test( memccpy_test SUITE libc-string-tests @@ -82,17 +59,6 @@ add_libc_test( ) add_libc_test( - rindex_test - SUITE - libc-string-tests - SRCS - rindex_test.cpp - DEPENDS - libc.src.string.rindex - .strchr_test_support -) - -add_libc_test( stpcpy_test SUITE libc-string-tests @@ -154,16 +120,6 @@ add_libc_test( ) add_libc_test( - strcasecmp_test - SUITE - libc-string-tests - SRCS - strcasecmp_test.cpp - DEPENDS - libc.src.string.strcasecmp -) - -add_libc_test( strcasestr_test SUITE libc-string-tests @@ -288,16 +244,6 @@ add_libc_test( ) add_libc_test( - strncasecmp_test - SUITE - libc-string-tests - SRCS - strncasecmp_test.cpp - DEPENDS - libc.src.string.strncasecmp -) - -add_libc_test( strncpy_test SUITE libc-string-tests @@ -428,39 +374,7 @@ add_libc_test( libc.src.string.memset_explicit ) -# Tests all implementations that can run on the target CPU. -function(add_libc_multi_impl_test name) - get_property(fq_implementations GLOBAL PROPERTY ${name}_implementations) - foreach(fq_config_name IN LISTS fq_implementations) - get_target_property(required_cpu_features ${fq_config_name} REQUIRE_CPU_FEATURES) - cpu_supports(can_run "${required_cpu_features}") - if(can_run) - string(FIND ${fq_config_name} "." last_dot_loc REVERSE) - math(EXPR name_loc "${last_dot_loc} + 1") - string(SUBSTRING ${fq_config_name} ${name_loc} -1 target_name) - add_libc_test( - ${target_name}_test - SUITE - libc-string-tests - COMPILE_OPTIONS - ${LIBC_COMPILE_OPTIONS_NATIVE} - LINK_LIBRARIES - LibcMemoryHelpers - ${ARGN} - DEPENDS - ${fq_config_name} - libc.src.__support.macros.sanitizer - ) - get_fq_target_name(${fq_config_name}_test fq_target_name) - else() - message(STATUS "Skipping test for '${fq_config_name}' insufficient host cpu features '${required_cpu_features}'") - endif() - endforeach() -endfunction() - -add_libc_multi_impl_test(bcmp SRCS bcmp_test.cpp) -add_libc_multi_impl_test(bzero SRCS bzero_test.cpp) -add_libc_multi_impl_test(memcmp SRCS memcmp_test.cpp) -add_libc_multi_impl_test(memcpy SRCS memcpy_test.cpp) -add_libc_multi_impl_test(memmove SRCS memmove_test.cpp) -add_libc_multi_impl_test(memset SRCS memset_test.cpp) +add_libc_multi_impl_test(memcmp libc-string-tests SRCS memcmp_test.cpp) +add_libc_multi_impl_test(memcpy libc-string-tests SRCS memcpy_test.cpp) +add_libc_multi_impl_test(memmove libc-string-tests SRCS memmove_test.cpp) +add_libc_multi_impl_test(memset libc-string-tests SRCS memset_test.cpp) diff --git a/libc/test/src/strings/CMakeLists.txt b/libc/test/src/strings/CMakeLists.txt new file mode 100644 index 000000000000..10f96b8531f6 --- /dev/null +++ b/libc/test/src/strings/CMakeLists.txt @@ -0,0 +1,58 @@ +add_custom_target(libc-strings-tests) + +add_libc_test( + bcopy_test + SUITE + libc-strings-tests + SRCS + bcopy_test.cpp + DEPENDS + libc.src.strings.bcopy + LINK_LIBRARIES + LibcMemoryHelpers +) + +add_libc_test( + index_test + SUITE + libc-strings-tests + SRCS + index_test.cpp + DEPENDS + libc.src.strings.index + libc.test.src.string.strchr_test_support +) + +add_libc_test( + rindex_test + SUITE + libc-strings-tests + SRCS + rindex_test.cpp + DEPENDS + libc.src.strings.rindex + libc.test.src.string.strchr_test_support +) + +add_libc_test( + strcasecmp_test + SUITE + libc-strings-tests + SRCS + strcasecmp_test.cpp + DEPENDS + libc.src.strings.strcasecmp +) + +add_libc_test( + strncasecmp_test + SUITE + libc-strings-tests + SRCS + strncasecmp_test.cpp + DEPENDS + libc.src.strings.strncasecmp +) + +add_libc_multi_impl_test(bcmp libc-strings-tests SRCS bcmp_test.cpp) +add_libc_multi_impl_test(bzero libc-strings-tests SRCS bzero_test.cpp) diff --git a/libc/test/src/string/bcmp_test.cpp b/libc/test/src/strings/bcmp_test.cpp index c639040685e1..794f9a1b8bd9 100644 --- a/libc/test/src/string/bcmp_test.cpp +++ b/libc/test/src/strings/bcmp_test.cpp @@ -6,11 +6,11 @@ // //===----------------------------------------------------------------------===// -#include "memory_utils/memory_check_utils.h" #include "src/__support/macros/config.h" -#include "src/string/bcmp.h" +#include "src/strings/bcmp.h" #include "test/UnitTest/Test.h" #include "test/UnitTest/TestLogger.h" +#include "test/src/string/memory_utils/memory_check_utils.h" namespace LIBC_NAMESPACE_DECL { diff --git a/libc/test/src/string/bcopy_test.cpp b/libc/test/src/strings/bcopy_test.cpp index 04772bb5d8ad..f6bb859b4ae9 100644 --- a/libc/test/src/string/bcopy_test.cpp +++ b/libc/test/src/strings/bcopy_test.cpp @@ -6,13 +6,13 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/macros/config.h" -#include "src/string/bcopy.h" +#include "src/strings/bcopy.h" -#include "memory_utils/memory_check_utils.h" #include "src/__support/CPP/span.h" +#include "src/__support/macros/config.h" #include "test/UnitTest/MemoryMatcher.h" #include "test/UnitTest/Test.h" +#include "test/src/string/memory_utils/memory_check_utils.h" using LIBC_NAMESPACE::cpp::array; using LIBC_NAMESPACE::cpp::span; diff --git a/libc/test/src/string/bzero_test.cpp b/libc/test/src/strings/bzero_test.cpp index a24043613bed..4d4112f4be8e 100644 --- a/libc/test/src/string/bzero_test.cpp +++ b/libc/test/src/strings/bzero_test.cpp @@ -6,10 +6,10 @@ // //===----------------------------------------------------------------------===// -#include "memory_utils/memory_check_utils.h" #include "src/__support/macros/config.h" -#include "src/string/bzero.h" +#include "src/strings/bzero.h" #include "test/UnitTest/Test.h" +#include "test/src/string/memory_utils/memory_check_utils.h" namespace LIBC_NAMESPACE_DECL { diff --git a/libc/test/src/string/index_test.cpp b/libc/test/src/strings/index_test.cpp index 88953205009d..fc4cd2b31c55 100644 --- a/libc/test/src/string/index_test.cpp +++ b/libc/test/src/strings/index_test.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "StrchrTest.h" +#include "test/src/string/StrchrTest.h" -#include "src/string/index.h" +#include "src/strings/index.h" #include "test/UnitTest/Test.h" STRCHR_TEST(Index, LIBC_NAMESPACE::index) diff --git a/libc/test/src/string/rindex_test.cpp b/libc/test/src/strings/rindex_test.cpp index 10513919cffa..d3b756fe5f6e 100644 --- a/libc/test/src/string/rindex_test.cpp +++ b/libc/test/src/strings/rindex_test.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include "StrchrTest.h" +#include "test/src/string/StrchrTest.h" -#include "src/string/rindex.h" +#include "src/strings/rindex.h" #include "test/UnitTest/Test.h" STRRCHR_TEST(Rindex, LIBC_NAMESPACE::rindex) diff --git a/libc/test/src/string/strcasecmp_test.cpp b/libc/test/src/strings/strcasecmp_test.cpp index df7888168c69..cd29c213a732 100644 --- a/libc/test/src/string/strcasecmp_test.cpp +++ b/libc/test/src/strings/strcasecmp_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/string/strcasecmp.h" +#include "src/strings/strcasecmp.h" #include "test/UnitTest/Test.h" TEST(LlvmLibcStrCaseCmpTest, EmptyStringsShouldReturnZero) { diff --git a/libc/test/src/string/strncasecmp_test.cpp b/libc/test/src/strings/strncasecmp_test.cpp index b4173c455de9..870574ed9507 100644 --- a/libc/test/src/string/strncasecmp_test.cpp +++ b/libc/test/src/strings/strncasecmp_test.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "src/string/strncasecmp.h" +#include "src/strings/strncasecmp.h" #include "test/UnitTest/Test.h" TEST(LlvmLibcStrNCaseCmpTest, diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt index 6362b46a6fe0..44ed11aadfe8 100644 --- a/libc/test/src/sys/mman/linux/CMakeLists.txt +++ b/libc/test/src/sys/mman/linux/CMakeLists.txt @@ -181,24 +181,3 @@ add_libc_unittest( libc.hdr.fcntl_macros libc.test.UnitTest.ErrnoSetterMatcher ) - -add_libc_unittest( - process_mrelease_test - SUITE - libc_sys_mman_unittests - SRCS - process_mrelease_test.cpp - DEPENDS - libc.include.sys_mman - libc.include.sys_syscall - libc.src.errno.errno - libc.src.sys.mman.process_mrelease - libc.src.unistd.close - libc.src.signal.kill - libc.include.signal - libc.src.stdlib.exit - libc.src.signal.raise - libc.src.__support.OSUtil.osutil - libc.src.__support.threads.sleep - libc.test.UnitTest.ErrnoSetterMatcher -) diff --git a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp b/libc/test/src/sys/mman/linux/process_mrelease_test.cpp deleted file mode 100644 index 865056c05f8d..000000000000 --- a/libc/test/src/sys/mman/linux/process_mrelease_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//===-- Unittests for process_mrelease ------------------------------------===// -// -// 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 "src/__support/OSUtil/syscall.h" // For internal syscall function. -#include "src/errno/libc_errno.h" -#include "src/signal/kill.h" -#include "src/signal/raise.h" -#include "src/stdlib/exit.h" -#include "src/sys/mman/process_mrelease.h" -#include "src/unistd/close.h" -#include "src/unistd/fork.h" -#include "test/UnitTest/ErrnoSetterMatcher.h" -#include "test/UnitTest/LibcTest.h" - -#include <sys/syscall.h> -#if defined(SYS_process_mrelease) && defined(SYS_pidfd_open) -using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; - -int pidfd_open(pid_t pid, unsigned int flags) { - return LIBC_NAMESPACE::syscall_impl(SYS_pidfd_open, pid, flags); -} - -TEST(LlvmLibcProcessMReleaseTest, NoError) { - pid_t child_pid = fork(); - EXPECT_GE(child_pid, 0); - - if (child_pid == 0) { - // pause the child process - LIBC_NAMESPACE::raise(SIGSTOP); - } else { - // Parent process: wait a bit and then kill the child. - // Give child process some time to start. - int pidfd = pidfd_open(child_pid, 0); - EXPECT_GE(pidfd, 0); - - // Send SIGKILL to child process - LIBC_NAMESPACE::kill(child_pid, SIGKILL); - - EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(pidfd, 0), Succeeds()); - - LIBC_NAMESPACE::close(pidfd); - } -} - -TEST(LlvmLibcProcessMReleaseTest, ErrorNotKilled) { - pid_t child_pid = fork(); - EXPECT_GE(child_pid, 0); - - if (child_pid == 0) { - // pause the child process - LIBC_NAMESPACE::raise(SIGSTOP); - } else { - int pidfd = pidfd_open(child_pid, 0); - EXPECT_GE(pidfd, 0); - - EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(pidfd, 0), Fails(EINVAL)); - - LIBC_NAMESPACE::kill(child_pid, SIGKILL); - - LIBC_NAMESPACE::close(pidfd); - } -} - -TEST(LlvmLibcProcessMReleaseTest, ErrorNonExistingPidfd) { - EXPECT_THAT(LIBC_NAMESPACE::process_mrelease(-1, 0), Fails(EBADF)); -} -#endif diff --git a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp index 267f7598ff70..ebc5c89a1ff5 100644 --- a/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp +++ b/libc/test/src/sys/mman/linux/remap_file_pages_test.cpp @@ -23,7 +23,7 @@ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; TEST(LlvmLibcRemapFilePagesTest, NoError) { - size_t page_size = sysconf(_SC_PAGE_SIZE); + size_t page_size = LIBC_NAMESPACE::sysconf(_SC_PAGE_SIZE); ASSERT_GT(page_size, size_t(0)); // Create a file-backed mapping @@ -53,7 +53,7 @@ TEST(LlvmLibcRemapFilePagesTest, NoError) { } TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidFlags) { - size_t page_size = sysconf(_SC_PAGE_SIZE); + size_t page_size = LIBC_NAMESPACE::sysconf(_SC_PAGE_SIZE); ASSERT_GT(page_size, size_t(0)); // Create a file-backed mapping @@ -81,7 +81,7 @@ TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidFlags) { } TEST(LlvmLibcRemapFilePagesTest, ErrorInvalidAddress) { - size_t page_size = sysconf(_SC_PAGESIZE); + size_t page_size = LIBC_NAMESPACE::sysconf(_SC_PAGESIZE); ASSERT_GT(page_size, size_t(0)); // Use an address that we haven't mapped diff --git a/libc/test/src/time/CMakeLists.txt b/libc/test/src/time/CMakeLists.txt index 7151526b72b2..da3903f3e0e4 100644 --- a/libc/test/src/time/CMakeLists.txt +++ b/libc/test/src/time/CMakeLists.txt @@ -71,11 +71,21 @@ add_libc_test( SUITE libc_time_unittests SRCS - clock_gettime_test.cpp + clock_gettime_test.cpp DEPENDS libc.src.time.clock_gettime ) +add_libc_test( + clock_getres_test + SUITE + libc_time_unittests + SRCS + clock_getres_test.cpp + DEPENDS + libc.src.time.clock_getres +) + add_libc_unittest( difftime_test SUITE @@ -157,8 +167,8 @@ add_libc_unittest( SRCS time_test.cpp DEPENDS - libc.include.time libc.src.time.time + libc.src.__support.time.clock_gettime libc.src.errno.errno ) diff --git a/libc/test/src/time/clock_getres_test.cpp b/libc/test/src/time/clock_getres_test.cpp new file mode 100644 index 000000000000..d8b3f01b37a3 --- /dev/null +++ b/libc/test/src/time/clock_getres_test.cpp @@ -0,0 +1,55 @@ +//===-- Unittests for clock_getres- ---------------------------------------===// +// +// 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/time_macros.h" +#include "src/time/clock_getres.h" +#include "test/UnitTest/ErrnoSetterMatcher.h" +#include "test/UnitTest/Test.h" + +using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails; +using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds; + +TEST(LlvmLibcClockGetRes, Invalid) { + timespec tp; + EXPECT_THAT(LIBC_NAMESPACE::clock_getres(-1, &tp), Fails(EINVAL)); +} + +TEST(LlvmLibcClockGetRes, NullSpec) { + EXPECT_THAT(LIBC_NAMESPACE::clock_getres(CLOCK_REALTIME, nullptr), + Succeeds()); +} + +TEST(LlvmLibcClockGetRes, Realtime) { + timespec tp; + EXPECT_THAT(LIBC_NAMESPACE::clock_getres(CLOCK_REALTIME, &tp), Succeeds()); + EXPECT_GE(tp.tv_sec, static_cast<decltype(tp.tv_sec)>(0)); + EXPECT_GE(tp.tv_nsec, static_cast<decltype(tp.tv_nsec)>(0)); +} + +TEST(LlvmLibcClockGetRes, Monotonic) { + timespec tp; + ASSERT_THAT(LIBC_NAMESPACE::clock_getres(CLOCK_MONOTONIC, &tp), Succeeds()); + EXPECT_GE(tp.tv_sec, static_cast<decltype(tp.tv_sec)>(0)); + EXPECT_GE(tp.tv_nsec, static_cast<decltype(tp.tv_nsec)>(0)); +} + +TEST(LlvmLibcClockGetRes, ProcessCpuTime) { + timespec tp; + ASSERT_THAT(LIBC_NAMESPACE::clock_getres(CLOCK_PROCESS_CPUTIME_ID, &tp), + Succeeds()); + EXPECT_GE(tp.tv_sec, static_cast<decltype(tp.tv_sec)>(0)); + EXPECT_GE(tp.tv_nsec, static_cast<decltype(tp.tv_nsec)>(0)); +} + +TEST(LlvmLibcClockGetRes, ThreadCpuTime) { + timespec tp; + ASSERT_THAT(LIBC_NAMESPACE::clock_getres(CLOCK_THREAD_CPUTIME_ID, &tp), + Succeeds()); + EXPECT_GE(tp.tv_sec, static_cast<decltype(tp.tv_sec)>(0)); + EXPECT_GE(tp.tv_nsec, static_cast<decltype(tp.tv_nsec)>(0)); +} diff --git a/libc/test/src/time/time_test.cpp b/libc/test/src/time/time_test.cpp index d3d4dc9a2851..7cdb4e834633 100644 --- a/libc/test/src/time/time_test.cpp +++ b/libc/test/src/time/time_test.cpp @@ -9,8 +9,6 @@ #include "src/time/time_func.h" #include "test/UnitTest/Test.h" -#include <time.h> - TEST(LlvmLibcTimeTest, SmokeTest) { time_t t1; time_t t2 = LIBC_NAMESPACE::time(&t1); |
