Skip to content

Commit b79507a

Browse files
committed
[libc] Add exhaustive test for sqrtf.
Differential Revision: https://reviews.llvm.org/D96985
1 parent a05aa0d commit b79507a

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ function(add_libc_testsuite suite_name)
164164
add_dependencies(check-libc ${suite_name})
165165
endfunction(add_libc_testsuite)
166166

167+
function(add_libc_exhaustive_testsuite suite_name)
168+
add_custom_target(${suite_name})
169+
add_dependencies(exhaustive-check-libc ${suite_name})
170+
endfunction(add_libc_exhaustive_testsuite)
171+
167172
# Rule to add a fuzzer test.
168173
# Usage
169174
# add_libc_fuzzer(

libc/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_header_library(
55
)
66

77
add_custom_target(check-libc)
8+
add_custom_target(exhaustive-check-libc)
89

910
add_subdirectory(config)
1011
add_subdirectory(loader)

libc/test/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,3 +1072,4 @@ add_fp_unittest(
10721072
)
10731073

10741074
add_subdirectory(generic)
1075+
add_subdirectory(exhaustive)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_libc_exhaustive_testsuite(libc_math_exhaustive_tests)
2+
3+
add_fp_unittest(
4+
sqrtf_test
5+
NEED_MPFR
6+
SUITE
7+
libc_math_exhaustive_tests
8+
SRCS
9+
sqrtf_test.cpp
10+
DEPENDS
11+
libc.include.math
12+
libc.src.math.sqrtf
13+
libc.utils.FPUtil.fputil
14+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Exhaustive test for sqrtf -----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===---------------------------------------------------------------------===//
8+
9+
#include "src/math/sqrtf.h"
10+
#include "utils/FPUtil/FPBits.h"
11+
#include "utils/FPUtil/TestHelpers.h"
12+
#include "utils/MPFRWrapper/MPFRUtils.h"
13+
#include <math.h>
14+
15+
using FPBits = __llvm_libc::fputil::FPBits<float>;
16+
17+
namespace mpfr = __llvm_libc::testing::mpfr;
18+
19+
TEST(LlvmLibcSqrtfExhaustiveTest, AllValues) {
20+
uint32_t bits = 0;
21+
do {
22+
FPBits x(bits);
23+
ASSERT_MPFR_MATCH(mpfr::Operation::Sqrt, float(x), __llvm_libc::sqrtf(x),
24+
0.5);
25+
} while (bits++ < 0xffff'ffffU);
26+
}

0 commit comments

Comments
 (0)