From 5f6f4a956cd630f873fe41058e96262f897f4bc9 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Wed, 19 Feb 2014 15:42:58 +0000 Subject: [PATCH] Fix signbit / infinite / isinf / isnan unit tests. Turns out stlport isn't broken. (included transitively via gtest in our case) is not required to make C99 math macros (like signbit) available, nor is it required to preserve them if they're already defined. It is only required to make the equivalent functions in namespace std available. I couldn't find any documentation of required behaviour for programs that include both and . I've verified experimentally that llvm's libc++ and gnu stl behave the same as stlport. bug: 12935307 Change-Id: I9dc5cc0fd9f4f259abc8eefb280177cdd092a94b --- tests/math_test.cpp | 74 ++++++++++++++++++++++++++++++--------------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/tests/math_test.cpp b/tests/math_test.cpp index c8974d3b0..fc561bc8c 100644 --- a/tests/math_test.cpp +++ b/tests/math_test.cpp @@ -16,11 +16,42 @@ #define _DECLARE_C99_LDBL_MATH 1 +// This include (and the associated definition of __test_capture_signbit) +// must be placed before any files that include (gtest.h in this case). +// +// is required to define generic macros signbit, isfinite and +// several other such functions. +// +// is required to undef declarations of these macros in the global +// namespace and make equivalent functions available in namespace std. Our +// stlport implementation does this only for signbit, isfinite, isinf and +// isnan. +// +// NOTE: We don't write our test using std::signbit because we want to be +// sure that we're testing the bionic version of signbit. The C++ libraries +// are free to reimplement signbit or delegate to compiler builtins if they +// please. +#include + +namespace { +template inline int test_capture_signbit(const T in) { + return signbit(in); +} +template inline int test_capture_isfinite(const T in) { + return isfinite(in); +} +template inline int test_capture_isnan(const T in) { + return isnan(in); +} +template inline int test_capture_isinf(const T in) { + return isinf(in); +} +} + #include #include #include -#include #include float float_subnormal() { @@ -59,27 +90,25 @@ TEST(math, fpclassify) { ASSERT_EQ(FP_ZERO, fpclassify(0.0)); } -/* TODO: stlport breaks the isfinite macro TEST(math, isfinite) { - ASSERT_TRUE(isfinite(123.0f)); - ASSERT_TRUE(isfinite(123.0)); - ASSERT_FALSE(isfinite(HUGE_VALF)); - ASSERT_FALSE(isfinite(HUGE_VAL)); + ASSERT_TRUE(test_capture_isfinite(123.0f)); + ASSERT_TRUE(test_capture_isfinite(123.0)); + ASSERT_FALSE(test_capture_isfinite(HUGE_VALF)); + ASSERT_FALSE(test_capture_isfinite(HUGE_VAL)); } -*/ TEST(math, isinf) { - ASSERT_FALSE(isinf(123.0f)); - ASSERT_FALSE(isinf(123.0)); - ASSERT_TRUE(isinf(HUGE_VALF)); - ASSERT_TRUE(isinf(HUGE_VAL)); + ASSERT_FALSE(test_capture_isinf(123.0f)); + ASSERT_FALSE(test_capture_isinf(123.0)); + ASSERT_TRUE(test_capture_isinf(HUGE_VALF)); + ASSERT_TRUE(test_capture_isinf(HUGE_VAL)); } TEST(math, isnan) { - ASSERT_FALSE(isnan(123.0f)); - ASSERT_FALSE(isnan(123.0)); - ASSERT_TRUE(isnan(nanf(""))); - ASSERT_TRUE(isnan(nan(""))); + ASSERT_FALSE(test_capture_isnan(123.0f)); + ASSERT_FALSE(test_capture_isnan(123.0)); + ASSERT_TRUE(test_capture_isnan(nanf(""))); + ASSERT_TRUE(test_capture_isnan(nan(""))); } TEST(math, isnormal) { @@ -90,19 +119,16 @@ TEST(math, isnormal) { } // TODO: isgreater, isgreaterequals, isless, islessequal, islessgreater, isunordered - -/* TODO: stlport breaks the signbit macro TEST(math, signbit) { - ASSERT_EQ(0, signbit(0.0f)); - ASSERT_EQ(0, signbit(0.0)); + ASSERT_EQ(0, test_capture_signbit(0.0f)); + ASSERT_EQ(0, test_capture_signbit(0.0)); - ASSERT_EQ(0, signbit(1.0f)); - ASSERT_EQ(0, signbit(1.0)); + ASSERT_EQ(0, test_capture_signbit(1.0f)); + ASSERT_EQ(0, test_capture_signbit(1.0)); - ASSERT_NE(0, signbit(-1.0f)); - ASSERT_NE(0, signbit(-1.0)); + ASSERT_NE(0, test_capture_signbit(-1.0f)); + ASSERT_NE(0, test_capture_signbit(-1.0)); } -*/ TEST(math, __fpclassifyd) { #if defined(__BIONIC__)