[libc-commits] [PATCH] D96985: [libc] Add exhaustive test for sqrtf.
Tue Ly via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Feb 18 12:08:47 PST 2021
lntue created this revision.
lntue added a reviewer: sivachandra.
Herald added subscribers: libc-commits, ecnelises, tschuett, mgorny.
Herald added a project: libc-project.
lntue requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96985
Files:
libc/cmake/modules/LLVMLibCTestRules.cmake
libc/test/CMakeLists.txt
libc/test/src/math/exhaustive/CMakeList.txt
libc/test/src/math/exhaustive/sqrtf_test.cpp
Index: libc/test/src/math/exhaustive/sqrtf_test.cpp
===================================================================
--- /dev/null
+++ 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);
+}
Index: libc/test/src/math/exhaustive/CMakeList.txt
===================================================================
--- /dev/null
+++ libc/test/src/math/exhaustive/CMakeList.txt
@@ -0,0 +1,12 @@
+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
+)
Index: libc/test/CMakeLists.txt
===================================================================
--- libc/test/CMakeLists.txt
+++ libc/test/CMakeLists.txt
@@ -5,6 +5,7 @@
)
add_custom_target(check-libc)
+add_custom_target(exhaustive-check-libc)
add_subdirectory(config)
add_subdirectory(loader)
Index: libc/cmake/modules/LLVMLibCTestRules.cmake
===================================================================
--- libc/cmake/modules/LLVMLibCTestRules.cmake
+++ libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -164,6 +164,11 @@
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(
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96985.324729.patch
Type: text/x-patch
Size: 2367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20210218/8b4736e9/attachment.bin>
More information about the libc-commits
mailing list