[libc-commits] [libc] b79507a - [libc] Add exhaustive test for sqrtf.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Tue Feb 23 15:40:02 PST 2021


Author: Tue Ly
Date: 2021-02-23T18:39:33-05:00
New Revision: b79507a4acad4114ab0fde3babd81551b214e65b

URL: https://github.com/llvm/llvm-project/commit/b79507a4acad4114ab0fde3babd81551b214e65b
DIFF: https://github.com/llvm/llvm-project/commit/b79507a4acad4114ab0fde3babd81551b214e65b.diff

LOG: [libc] Add exhaustive test for sqrtf.

Differential Revision: https://reviews.llvm.org/D96985

Added: 
    libc/test/src/math/exhaustive/CMakeLists.txt
    libc/test/src/math/exhaustive/sqrtf_test.cpp

Modified: 
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/test/CMakeLists.txt
    libc/test/src/math/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 421e1a16b700..6816e0e19038 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -164,6 +164,11 @@ function(add_libc_testsuite suite_name)
   add_dependencies(check-libc ${suite_name})
 endfunction(add_libc_testsuite)
 
+function(add_libc_exhaustive_testsuite suite_name)
+  add_custom_target(${suite_name})
+  add_dependencies(exhaustive-check-libc ${suite_name})
+endfunction(add_libc_exhaustive_testsuite)
+
 # Rule to add a fuzzer test.
 # Usage
 #    add_libc_fuzzer(

diff  --git a/libc/test/CMakeLists.txt b/libc/test/CMakeLists.txt
index edce4bbf78cc..100c8ffd4b69 100644
--- a/libc/test/CMakeLists.txt
+++ b/libc/test/CMakeLists.txt
@@ -5,6 +5,7 @@ add_header_library(
 )
 
 add_custom_target(check-libc)
+add_custom_target(exhaustive-check-libc)
 
 add_subdirectory(config)
 add_subdirectory(loader)

diff  --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt
index 841e4db5a22b..07d57b06a87e 100644
--- a/libc/test/src/math/CMakeLists.txt
+++ b/libc/test/src/math/CMakeLists.txt
@@ -1072,3 +1072,4 @@ add_fp_unittest(
 )
 
 add_subdirectory(generic)
+add_subdirectory(exhaustive)

diff  --git a/libc/test/src/math/exhaustive/CMakeLists.txt b/libc/test/src/math/exhaustive/CMakeLists.txt
new file mode 100644
index 000000000000..4e6505658190
--- /dev/null
+++ b/libc/test/src/math/exhaustive/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_libc_exhaustive_testsuite(libc_math_exhaustive_tests)
+
+add_fp_unittest(
+  sqrtf_test
+  NEED_MPFR
+  SUITE
+    libc_math_exhaustive_tests
+  SRCS
+    sqrtf_test.cpp
+  DEPENDS
+    libc.include.math
+    libc.src.math.sqrtf
+    libc.utils.FPUtil.fputil
+)

diff  --git a/libc/test/src/math/exhaustive/sqrtf_test.cpp b/libc/test/src/math/exhaustive/sqrtf_test.cpp
new file mode 100644
index 000000000000..4e2b566625ef
--- /dev/null
+++ b/libc/test/src/math/exhaustive/sqrtf_test.cpp
@@ -0,0 +1,26 @@
+//===-- Exhaustive test for sqrtf -----------------------------------------===//
+//
+// 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/sqrtf.h"
+#include "utils/FPUtil/FPBits.h"
+#include "utils/FPUtil/TestHelpers.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+#include <math.h>
+
+using FPBits = __llvm_libc::fputil::FPBits<float>;
+
+namespace mpfr = __llvm_libc::testing::mpfr;
+
+TEST(LlvmLibcSqrtfExhaustiveTest, AllValues) {
+  uint32_t bits = 0;
+  do {
+    FPBits x(bits);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Sqrt, float(x), __llvm_libc::sqrtf(x),
+                      0.5);
+  } while (bits++ < 0xffff'ffffU);
+}


        


More information about the libc-commits mailing list