Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 1 addition & 31 deletions libc/test/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,6 @@ add_libc_test(
libc.include.llvm-libc-macros.math_function_macros
)

add_libc_test(
isnan_test
SUITE
libc_include_tests
SRCS
isnan_test.cpp
DEPENDS
libc.include.llvm-libc-macros.math_function_macros
)

add_libc_test(
isnanf_test
SUITE
libc_include_tests
SRCS
isnanf_test.cpp
DEPENDS
libc.include.llvm-libc-macros.math_function_macros
)

add_libc_test(
isnanl_test
SUITE
libc_include_tests
SRCS
isnanl_test.cpp
DEPENDS
libc.include.llvm-libc-macros.math_function_macros
)

add_libc_test(
isinf_test
SUITE
Expand Down Expand Up @@ -217,7 +187,7 @@ add_libc_test(
)

add_libc_test(
isnan_c_test
isnan_test
C_TEST
UNIT_TEST_ONLY
SUITE
Expand Down
39 changes: 39 additions & 0 deletions libc/test/src/math/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,45 @@ add_fp_unittest(
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
isnan_test
SUITE
libc-math-unittests
SRCS
isnan_test.cpp
HDRS
IsNanTest.h
DEPENDS
libc.src.math.isnan
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
isnanf_test
SUITE
libc-math-unittests
SRCS
isnanf_test.cpp
HDRS
IsNanTest.h
DEPENDS
libc.src.math.isnanf
libc.src.__support.FPUtil.fp_bits
)

add_fp_unittest(
isnanl_test
SUITE
libc-math-unittests
SRCS
isnanl_test.cpp
HDRS
IsNanTest.h
DEPENDS
libc.src.math.isnanl
libc.src.__support.FPUtil.fp_bits
)

add_subdirectory(generic)
add_subdirectory(smoke)

Expand Down
21 changes: 7 additions & 14 deletions libc/test/include/IsNanTest.h → libc/test/src/math/IsNanTest.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
//===-- Utility class to test the isnan macro [f|l] -------------*- C++ -*-===//
//===-- Utility class to test isnan[f|l] ------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license nanormation.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H
#define LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H

#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include "include/llvm-libc-macros/math-function-macros.h"

template <typename T> class IsNanTest : public LIBC_NAMESPACE::testing::Test {
template <typename T>
class IsNanTest : public LIBC_NAMESPACE::testing::FPTest<T> {

DECLARE_SPECIAL_CONSTANTS(T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with FPTest<T> you don't need to add DECLARE_SPECIAL_CONSTANTS(T): https://github.com/llvm/llvm-project/blob/main/libc/test/UnitTest/FPMatcher.h#L70

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I do that I get the following error:

In file included from /usr/local/google/home/phosek/llvm/llvm-project/libc/test/src/math/isnan_test.cpp:9:
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/src/math/IsNanTest.h:18:20: error: use of undeclared identifier 'zero'; did you mean 'erf'?
   18 |     EXPECT_EQ(func(zero), 0);
      |                    ^~~~
      |                    erf
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/UnitTest/LibcTest.h:420:50: note: expanded from macro 'EXPECT_EQ'
  420 | #define EXPECT_EQ(LHS, RHS) LIBC_TEST_BINOP_(EQ, LHS, RHS, )
      |                                                  ^
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/UnitTest/LibcTest.h:413:72: note: expanded from macro 'LIBC_TEST_BINOP_'
  413 |   LIBC_TEST_SCAFFOLDING_(test(LIBC_NAMESPACE::testing::TestCond::COND, LHS,    \
      |                                                                        ^
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/UnitTest/LibcTest.h:406:7: note: expanded from macro 'LIBC_TEST_SCAFFOLDING_'
  406 |   if (TEST)                                                                    \
      |       ^
/usr/local/google/home/phosek/fuchsia/prebuilt/third_party/clang/linux-x64/bin/../include/c++/v1/math.h:456:20: note: 'erf' declared here
  456 | using std::__math::erf;
      |                    ^
In file included from /usr/local/google/home/phosek/llvm/llvm-project/libc/test/src/math/isnan_test.cpp:9:
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/src/math/IsNanTest.h:19:20: error: use of undeclared identifier 'neg_zero'
   19 |     EXPECT_EQ(func(neg_zero), 0);
      |                    ^
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/src/math/IsNanTest.h:20:20: error: use of undeclared identifier 'inf'
   20 |     EXPECT_EQ(func(inf), 0);
      |                    ^
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/src/math/IsNanTest.h:21:20: error: use of undeclared identifier 'neg_inf'
   21 |     EXPECT_EQ(func(neg_inf), 0);
      |                    ^
/usr/local/google/home/phosek/llvm/llvm-project/libc/test/src/math/IsNanTest.h:22:20: error: use of undeclared identifier 'aNaN'; did you mean 'atan'?
   22 |     EXPECT_NE(func(aNaN), 0);
      |                    ^~~~
      |                    atan


Expand All @@ -24,16 +20,13 @@ template <typename T> class IsNanTest : public LIBC_NAMESPACE::testing::Test {
void testSpecialNumbers(IsNanFunc func) {
EXPECT_EQ(func(zero), 0);
EXPECT_EQ(func(neg_zero), 0);
EXPECT_EQ(func(inf), 0);
EXPECT_EQ(func(neg_inf), 0);
EXPECT_EQ(func(aNaN), 1);
EXPECT_EQ(func(sNaN), 1);
Comment on lines 25 to 26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change these to EXPECT_NE(func(aNaN), 0); because C standard only requires isnan macro to be non-zero instead of 1 for non-NaN cases.

}
};

#define LIST_ISNAN_TESTS(T, func) \
using LlvmLibcIsNanTest = IsNanTest<T>; \
TEST_F(LlvmLibcIsNanTest, SpecialNumbers) { \
auto isnan_func = [](T x) { return func(x); }; \
testSpecialNumbers(isnan_func); \
}

#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H
TEST_F(LlvmLibcIsNanTest, SpecialNumbers) { testSpecialNumbers(&func); }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- Unittest for isnan[l] macro ---------------------------------------===//
//===-- Unittests for isnan -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,6 +7,10 @@
//===----------------------------------------------------------------------===//

#include "IsNanTest.h"
#include "include/llvm-libc-macros/math-function-macros.h"

LIST_ISNAN_TESTS(long double, isnan)
// We need to avoid expanding isnan to __builtin_isnan.
#undef isnan

#include "src/math/isnan.h"

LIST_ISNAN_TESTS(double, LIBC_NAMESPACE::isnan)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- Unittest for isnan[f] macro ---------------------------------------===//
//===-- Unittests for isnanf ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "IsNanTest.h"
#include "include/llvm-libc-macros/math-function-macros.h"

LIST_ISNAN_TESTS(float, isnan)
#include "src/math/isnanf.h"

LIST_ISNAN_TESTS(float, LIBC_NAMESPACE::isnanf)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- Unittest for isnan[l] macro ---------------------------------------===//
//===-- Unittests for isnanl ----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand All @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include "IsNanTest.h"
#include "include/llvm-libc-macros/math-function-macros.h"

LIST_ISNAN_TESTS(double, isnan)
#include "src/math/isnanl.h"

LIST_ISNAN_TESTS(long double, LIBC_NAMESPACE::isnanl)