[libc] apply formatting to tests

Apply the formatting rules that were applied to the libc/src directory
to the libc/test directory, as well as the files in libc/utils that are
included by the tests. This does not include automated enforcement.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D116127
This commit is contained in:
Michael Jones 2021-12-21 13:12:45 -08:00
parent 8b58344efb
commit 25226f3e4a
75 changed files with 899 additions and 871 deletions

View File

@ -50,9 +50,9 @@ public:
}
protected:
void SetUp() override { Options.Log = BenchmarkLog::Full; }
void set_up() override { Options.Log = BenchmarkLog::Full; }
void TearDown() override {
void tear_down() override {
// We make sure all the expected measurements were performed.
if (MaybeTimepoints)
EXPECT_THAT(*MaybeTimepoints, IsEmpty());

View File

@ -94,7 +94,7 @@ JsonFile parseJsonResultFile(StringRef Filename) {
json::Path::Root Root;
JsonFile JF;
if (!fromJSON(JsonValue, JF, Root))
ExitOnErr(Root.getError());
ExitOnErr(Root.get_error());
return JF;
}

View File

@ -39,6 +39,6 @@ TEST(LlvmLibcX86_64_SyscallTest, APITest) {
return __llvm_libc::syscall(n, a1, a2, a3, a4, a5, a6);
});
Function<long(long, void *)> notLongType(
Function<long(long, void *)> not_long_type(
[](long n, void *a1) { return __llvm_libc::syscall(n, a1); });
}

View File

@ -14,201 +14,209 @@
class LlvmLibcStrToFloatTest : public __llvm_libc::testing::Test {
public:
template <class T>
void ClingerFastPathTest(
void clinger_fast_path_test(
const typename __llvm_libc::fputil::FPBits<T>::UIntType inputMantissa,
const int32_t inputExp10,
const typename __llvm_libc::fputil::FPBits<T>::UIntType
expectedOutputMantissa,
const uint32_t expectedOutputExp2) {
typename __llvm_libc::fputil::FPBits<T>::UIntType actualOutputMantissa = 0;
uint32_t actualOutputExp2 = 0;
typename __llvm_libc::fputil::FPBits<T>::UIntType actual_output_mantissa =
0;
uint32_t actual_output_exp2 = 0;
ASSERT_TRUE(__llvm_libc::internal::clinger_fast_path<T>(
inputMantissa, inputExp10, &actualOutputMantissa, &actualOutputExp2));
EXPECT_EQ(actualOutputMantissa, expectedOutputMantissa);
EXPECT_EQ(actualOutputExp2, expectedOutputExp2);
inputMantissa, inputExp10, &actual_output_mantissa,
&actual_output_exp2));
EXPECT_EQ(actual_output_mantissa, expectedOutputMantissa);
EXPECT_EQ(actual_output_exp2, expectedOutputExp2);
}
template <class T>
void ClingerFastPathFailsTest(
void clinger_fast_path_fails_test(
const typename __llvm_libc::fputil::FPBits<T>::UIntType inputMantissa,
const int32_t inputExp10) {
typename __llvm_libc::fputil::FPBits<T>::UIntType actualOutputMantissa = 0;
uint32_t actualOutputExp2 = 0;
typename __llvm_libc::fputil::FPBits<T>::UIntType actual_output_mantissa =
0;
uint32_t actual_output_exp2 = 0;
ASSERT_FALSE(__llvm_libc::internal::clinger_fast_path<T>(
inputMantissa, inputExp10, &actualOutputMantissa, &actualOutputExp2));
inputMantissa, inputExp10, &actual_output_mantissa,
&actual_output_exp2));
}
template <class T>
void EiselLemireTest(
void eisel_lemire_test(
const typename __llvm_libc::fputil::FPBits<T>::UIntType inputMantissa,
const int32_t inputExp10,
const typename __llvm_libc::fputil::FPBits<T>::UIntType
expectedOutputMantissa,
const uint32_t expectedOutputExp2) {
typename __llvm_libc::fputil::FPBits<T>::UIntType actualOutputMantissa = 0;
uint32_t actualOutputExp2 = 0;
typename __llvm_libc::fputil::FPBits<T>::UIntType actual_output_mantissa =
0;
uint32_t actual_output_exp2 = 0;
ASSERT_TRUE(__llvm_libc::internal::eisel_lemire<T>(
inputMantissa, inputExp10, &actualOutputMantissa, &actualOutputExp2));
EXPECT_EQ(actualOutputMantissa, expectedOutputMantissa);
EXPECT_EQ(actualOutputExp2, expectedOutputExp2);
inputMantissa, inputExp10, &actual_output_mantissa,
&actual_output_exp2));
EXPECT_EQ(actual_output_mantissa, expectedOutputMantissa);
EXPECT_EQ(actual_output_exp2, expectedOutputExp2);
}
template <class T>
void SimpleDecimalConversionTest(
void simple_decimal_conversion_test(
const char *__restrict numStart,
const typename __llvm_libc::fputil::FPBits<T>::UIntType
expectedOutputMantissa,
const uint32_t expectedOutputExp2, const int expectedErrno = 0) {
typename __llvm_libc::fputil::FPBits<T>::UIntType actualOutputMantissa = 0;
uint32_t actualOutputExp2 = 0;
typename __llvm_libc::fputil::FPBits<T>::UIntType actual_output_mantissa =
0;
uint32_t actual_output_exp2 = 0;
errno = 0;
__llvm_libc::internal::simple_decimal_conversion<T>(
numStart, &actualOutputMantissa, &actualOutputExp2);
EXPECT_EQ(actualOutputMantissa, expectedOutputMantissa);
EXPECT_EQ(actualOutputExp2, expectedOutputExp2);
numStart, &actual_output_mantissa, &actual_output_exp2);
EXPECT_EQ(actual_output_mantissa, expectedOutputMantissa);
EXPECT_EQ(actual_output_exp2, expectedOutputExp2);
EXPECT_EQ(errno, expectedErrno);
}
};
TEST(LlvmLibcStrToFloatTest, LeadingZeroes) {
uint64_t testNum64 = 1;
uint32_t numOfZeroes = 63;
uint64_t test_num64 = 1;
uint32_t num_of_zeroes = 63;
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(0), 64u);
for (; numOfZeroes < 64; testNum64 <<= 1, numOfZeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(testNum64),
numOfZeroes);
for (; num_of_zeroes < 64; test_num64 <<= 1, num_of_zeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(test_num64),
num_of_zeroes);
}
testNum64 = 3;
numOfZeroes = 62;
for (; numOfZeroes > 63; testNum64 <<= 1, numOfZeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(testNum64),
numOfZeroes);
test_num64 = 3;
num_of_zeroes = 62;
for (; num_of_zeroes > 63; test_num64 <<= 1, num_of_zeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(test_num64),
num_of_zeroes);
}
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(0xffffffffffffffff),
0u);
testNum64 = 1;
numOfZeroes = 63;
for (; numOfZeroes > 63; testNum64 = (testNum64 << 1) + 1, numOfZeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(testNum64),
numOfZeroes);
test_num64 = 1;
num_of_zeroes = 63;
for (; num_of_zeroes > 63;
test_num64 = (test_num64 << 1) + 1, num_of_zeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint64_t>(test_num64),
num_of_zeroes);
}
uint64_t testNum32 = 1;
numOfZeroes = 31;
uint64_t test_num32 = 1;
num_of_zeroes = 31;
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint32_t>(0), 32u);
for (; numOfZeroes < 32; testNum32 <<= 1, numOfZeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint32_t>(testNum32),
numOfZeroes);
for (; num_of_zeroes < 32; test_num32 <<= 1, num_of_zeroes--) {
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint32_t>(test_num32),
num_of_zeroes);
}
EXPECT_EQ(__llvm_libc::internal::leading_zeroes<uint32_t>(0xffffffff), 0u);
}
TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat64Simple) {
ClingerFastPathTest<double>(123, 0, 0xEC00000000000, 1029);
ClingerFastPathTest<double>(1234567890123456, 1, 0x5ee2a2eb5a5c0, 1076);
ClingerFastPathTest<double>(1234567890, -10, 0xf9add3739635f, 1019);
clinger_fast_path_test<double>(123, 0, 0xEC00000000000, 1029);
clinger_fast_path_test<double>(1234567890123456, 1, 0x5ee2a2eb5a5c0, 1076);
clinger_fast_path_test<double>(1234567890, -10, 0xf9add3739635f, 1019);
}
TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat64ExtendedExp) {
ClingerFastPathTest<double>(1, 30, 0x93e5939a08cea, 1122);
ClingerFastPathTest<double>(1, 37, 0xe17b84357691b, 1145);
ClingerFastPathFailsTest<double>(10, 37);
ClingerFastPathFailsTest<double>(1, 100);
clinger_fast_path_test<double>(1, 30, 0x93e5939a08cea, 1122);
clinger_fast_path_test<double>(1, 37, 0xe17b84357691b, 1145);
clinger_fast_path_fails_test<double>(10, 37);
clinger_fast_path_fails_test<double>(1, 100);
}
TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat64NegativeExp) {
ClingerFastPathTest<double>(1, -10, 0xb7cdfd9d7bdbb, 989);
ClingerFastPathTest<double>(1, -20, 0x79ca10c924223, 956);
ClingerFastPathFailsTest<double>(1, -25);
clinger_fast_path_test<double>(1, -10, 0xb7cdfd9d7bdbb, 989);
clinger_fast_path_test<double>(1, -20, 0x79ca10c924223, 956);
clinger_fast_path_fails_test<double>(1, -25);
}
TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat32Simple) {
ClingerFastPathTest<float>(123, 0, 0x760000, 133);
ClingerFastPathTest<float>(1234567, 1, 0x3c6146, 150);
ClingerFastPathTest<float>(12345, -5, 0x7cd35b, 123);
clinger_fast_path_test<float>(123, 0, 0x760000, 133);
clinger_fast_path_test<float>(1234567, 1, 0x3c6146, 150);
clinger_fast_path_test<float>(12345, -5, 0x7cd35b, 123);
}
TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat32ExtendedExp) {
ClingerFastPathTest<float>(1, 15, 0x635fa9, 176);
ClingerFastPathTest<float>(1, 17, 0x31a2bc, 183);
ClingerFastPathFailsTest<float>(10, 17);
ClingerFastPathFailsTest<float>(1, 50);
clinger_fast_path_test<float>(1, 15, 0x635fa9, 176);
clinger_fast_path_test<float>(1, 17, 0x31a2bc, 183);
clinger_fast_path_fails_test<float>(10, 17);
clinger_fast_path_fails_test<float>(1, 50);
}
TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat32NegativeExp) {
ClingerFastPathTest<float>(1, -5, 0x27c5ac, 110);
ClingerFastPathTest<float>(1, -10, 0x5be6ff, 93);
ClingerFastPathFailsTest<float>(1, -15);
clinger_fast_path_test<float>(1, -5, 0x27c5ac, 110);
clinger_fast_path_test<float>(1, -10, 0x5be6ff, 93);
clinger_fast_path_fails_test<float>(1, -15);
}
TEST_F(LlvmLibcStrToFloatTest, EiselLemireFloat64Simple) {
EiselLemireTest<double>(12345678901234567890u, 1, 0x1AC53A7E04BCDA, 1089);
EiselLemireTest<double>(123, 0, 0x1EC00000000000, 1029);
EiselLemireTest<double>(12345678901234568192u, 0, 0x156A95319D63E2, 1086);
eisel_lemire_test<double>(12345678901234567890u, 1, 0x1AC53A7E04BCDA, 1089);
eisel_lemire_test<double>(123, 0, 0x1EC00000000000, 1029);
eisel_lemire_test<double>(12345678901234568192u, 0, 0x156A95319D63E2, 1086);
}
TEST_F(LlvmLibcStrToFloatTest, EiselLemireFloat64SpecificFailures) {
// These test cases have caused failures in the past.
EiselLemireTest<double>(358416272, -33, 0x1BBB2A68C9D0B9, 941);
EiselLemireTest<double>(2166568064000000238u, -9, 0x10246690000000, 1054);
EiselLemireTest<double>(2794967654709307187u, 1, 0x183e132bc608c8, 1087);
EiselLemireTest<double>(2794967654709307188u, 1, 0x183e132bc608c9, 1087);
eisel_lemire_test<double>(358416272, -33, 0x1BBB2A68C9D0B9, 941);
eisel_lemire_test<double>(2166568064000000238u, -9, 0x10246690000000, 1054);
eisel_lemire_test<double>(2794967654709307187u, 1, 0x183e132bc608c8, 1087);
eisel_lemire_test<double>(2794967654709307188u, 1, 0x183e132bc608c9, 1087);
}
TEST_F(LlvmLibcStrToFloatTest, EiselLemireFallbackStates) {
// Check the fallback states for the algorithm:
uint32_t floatOutputMantissa = 0;
uint64_t doubleOutputMantissa = 0;
__uint128_t tooLongMantissa = 0;
uint32_t outputExp2 = 0;
uint32_t float_output_mantissa = 0;
uint64_t double_output_mantissa = 0;
__uint128_t too_long_mantissa = 0;
uint32_t output_exp2 = 0;
// This Eisel-Lemire implementation doesn't support long doubles yet.
ASSERT_FALSE(__llvm_libc::internal::eisel_lemire<long double>(
tooLongMantissa, 0, &tooLongMantissa, &outputExp2));
too_long_mantissa, 0, &too_long_mantissa, &output_exp2));
// This number can't be evaluated by Eisel-Lemire since it's exactly 1024 away
// from both of its closest floating point approximations
// (12345678901234548736 and 12345678901234550784)
ASSERT_FALSE(__llvm_libc::internal::eisel_lemire<double>(
12345678901234549760u, 0, &doubleOutputMantissa, &outputExp2));
12345678901234549760u, 0, &double_output_mantissa, &output_exp2));
ASSERT_FALSE(__llvm_libc::internal::eisel_lemire<float>(
20040229, 0, &floatOutputMantissa, &outputExp2));
20040229, 0, &float_output_mantissa, &output_exp2));
}
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicWholeNumbers) {
SimpleDecimalConversionTest<double>("123456789012345678900", 0x1AC53A7E04BCDA,
1089);
SimpleDecimalConversionTest<double>("123", 0x1EC00000000000, 1029);
SimpleDecimalConversionTest<double>("12345678901234549760", 0x156A95319D63D8,
1086);
simple_decimal_conversion_test<double>("123456789012345678900",
0x1AC53A7E04BCDA, 1089);
simple_decimal_conversion_test<double>("123", 0x1EC00000000000, 1029);
simple_decimal_conversion_test<double>("12345678901234549760",
0x156A95319D63D8, 1086);
}
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicDecimals) {
SimpleDecimalConversionTest<double>("1.2345", 0x13c083126e978d, 1023);
SimpleDecimalConversionTest<double>(".2345", 0x1e04189374bc6a, 1020);
SimpleDecimalConversionTest<double>(".299792458", 0x132fccb4aca314, 1021);
simple_decimal_conversion_test<double>("1.2345", 0x13c083126e978d, 1023);
simple_decimal_conversion_test<double>(".2345", 0x1e04189374bc6a, 1020);
simple_decimal_conversion_test<double>(".299792458", 0x132fccb4aca314, 1021);
}
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicExponents) {
SimpleDecimalConversionTest<double>("1e10", 0x12a05f20000000, 1056);
SimpleDecimalConversionTest<double>("1e-10", 0x1b7cdfd9d7bdbb, 989);
SimpleDecimalConversionTest<double>("1e300", 0x17e43c8800759c, 2019);
SimpleDecimalConversionTest<double>("1e-300", 0x156e1fc2f8f359, 26);
simple_decimal_conversion_test<double>("1e10", 0x12a05f20000000, 1056);
simple_decimal_conversion_test<double>("1e-10", 0x1b7cdfd9d7bdbb, 989);
simple_decimal_conversion_test<double>("1e300", 0x17e43c8800759c, 2019);
simple_decimal_conversion_test<double>("1e-300", 0x156e1fc2f8f359, 26);
}
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicSubnormals) {
SimpleDecimalConversionTest<double>("1e-320", 0x7e8, 0, ERANGE);
SimpleDecimalConversionTest<double>("1e-308", 0x730d67819e8d2, 0, ERANGE);
SimpleDecimalConversionTest<double>("2.9e-308", 0x14da6df5e4bcc8, 1);
simple_decimal_conversion_test<double>("1e-320", 0x7e8, 0, ERANGE);
simple_decimal_conversion_test<double>("1e-308", 0x730d67819e8d2, 0, ERANGE);
simple_decimal_conversion_test<double>("2.9e-308", 0x14da6df5e4bcc8, 1);
}
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64SubnormalRounding) {
@ -216,40 +224,40 @@ TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64SubnormalRounding) {
// Technically you can keep adding digits until you hit the truncation limit,
// but this is the shortest string that results in the maximum subnormal that
// I found.
SimpleDecimalConversionTest<double>("2.225073858507201e-308", 0xfffffffffffff,
0, ERANGE);
simple_decimal_conversion_test<double>("2.225073858507201e-308",
0xfffffffffffff, 0, ERANGE);
// Same here, if you were to extend the max subnormal out for another 800
// digits, incrementing any one of those digits would create a normal number.
SimpleDecimalConversionTest<double>("2.2250738585072012e-308",
0x10000000000000, 1);
simple_decimal_conversion_test<double>("2.2250738585072012e-308",
0x10000000000000, 1);
}
TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion32SpecificFailures) {
SimpleDecimalConversionTest<float>(
simple_decimal_conversion_test<float>(
"1.4012984643248170709237295832899161312802619418765e-45", 0x1, 0,
ERANGE);
}
TEST(LlvmLibcStrToFloatTest, SimpleDecimalConversionExtraTypes) {
uint32_t floatOutputMantissa = 0;
uint32_t outputExp2 = 0;
uint32_t float_output_mantissa = 0;
uint32_t output_exp2 = 0;
errno = 0;
__llvm_libc::internal::simple_decimal_conversion<float>(
"123456789012345678900", &floatOutputMantissa, &outputExp2);
EXPECT_EQ(floatOutputMantissa, uint32_t(0xd629d4));
EXPECT_EQ(outputExp2, uint32_t(193));
"123456789012345678900", &float_output_mantissa, &output_exp2);
EXPECT_EQ(float_output_mantissa, uint32_t(0xd629d4));
EXPECT_EQ(output_exp2, uint32_t(193));
EXPECT_EQ(errno, 0);
uint64_t doubleOutputMantissa = 0;
outputExp2 = 0;
uint64_t double_output_mantissa = 0;
output_exp2 = 0;
errno = 0;
__llvm_libc::internal::simple_decimal_conversion<double>(
"123456789012345678900", &doubleOutputMantissa, &outputExp2);
EXPECT_EQ(doubleOutputMantissa, uint64_t(0x1AC53A7E04BCDA));
EXPECT_EQ(outputExp2, uint32_t(1089));
"123456789012345678900", &double_output_mantissa, &output_exp2);
EXPECT_EQ(double_output_mantissa, uint64_t(0x1AC53A7E04BCDA));
EXPECT_EQ(output_exp2, uint32_t(1089));
EXPECT_EQ(errno, 0);
// TODO(michaelrj): Get long double support working.

View File

@ -46,7 +46,7 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndCrash) {
// We '|' the individual exception flags instead of using FE_ALL_EXCEPT
// as it can include non-standard extensions. Note that we should be able
// to compile this file with headers from other libcs as well.
constexpr int allExcepts =
constexpr int ALL_EXCEPTS =
FE_DIVBYZERO | FE_INVALID | FE_INEXACT | FE_OVERFLOW | FE_UNDERFLOW;
for (int e : excepts) {
@ -59,7 +59,7 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndCrash) {
// can raise FE_INEXACT as well, we don't verify the other
// exception flags when FE_INEXACT is enabled.
if (e != FE_INEXACT) {
int others = allExcepts & ~e;
int others = ALL_EXCEPTS & ~e;
ASSERT_EQ(__llvm_libc::feraiseexcept(others), 0);
ASSERT_EQ(__llvm_libc::fetestexcept(others), others);
}

View File

@ -25,7 +25,7 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
FE_UNDERFLOW};
constexpr int allExcepts =
constexpr int ALL_EXCEPTS =
FE_DIVBYZERO | FE_INVALID | FE_INEXACT | FE_OVERFLOW | FE_UNDERFLOW;
for (int e : excepts) {
@ -112,8 +112,8 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndTest) {
}
}
int r = __llvm_libc::feraiseexcept(allExcepts);
int r = __llvm_libc::feraiseexcept(ALL_EXCEPTS);
ASSERT_EQ(r, 0);
int s = __llvm_libc::fetestexcept(allExcepts);
ASSERT_EQ(s, allExcepts);
int s = __llvm_libc::fetestexcept(ALL_EXCEPTS);
ASSERT_EQ(s, ALL_EXCEPTS);
}

View File

@ -64,9 +64,9 @@ public:
}
void testRange(CeilFunc func) {
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -33,9 +33,9 @@ public:
}
void testRange(CopySignFunc func) {
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -32,9 +32,9 @@ public:
}
void testRange(FabsFunc func) {
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -19,7 +19,7 @@ public:
using FPBits = __llvm_libc::fputil::FPBits<T>;
using UIntType = typename FPBits::UIntType;
void testNaNArg(FuncPtr func) {
void test_na_n_arg(FuncPtr func) {
EXPECT_FP_EQ(nan, func(nan, inf));
EXPECT_FP_EQ(nan, func(neg_inf, nan));
EXPECT_FP_EQ(nan, func(nan, zero));
@ -29,7 +29,7 @@ public:
EXPECT_FP_EQ(func(nan, nan), nan);
}
void testInfArg(FuncPtr func) {
void test_inf_arg(FuncPtr func) {
EXPECT_FP_EQ(zero, func(neg_inf, inf));
EXPECT_FP_EQ(inf, func(inf, zero));
EXPECT_FP_EQ(zero, func(neg_zero, inf));
@ -37,7 +37,7 @@ public:
EXPECT_FP_EQ(zero, func(T(-1.2345), inf));
}
void testNegInfArg(FuncPtr func) {
void test_neg_inf_arg(FuncPtr func) {
EXPECT_FP_EQ(inf, func(inf, neg_inf));
EXPECT_FP_EQ(zero, func(neg_inf, zero));
EXPECT_FP_EQ(inf, func(neg_zero, neg_inf));
@ -45,18 +45,18 @@ public:
EXPECT_FP_EQ(inf, func(T(1.2345), neg_inf));
}
void testBothZero(FuncPtr func) {
void test_both_zero(FuncPtr func) {
EXPECT_FP_EQ(zero, func(zero, zero));
EXPECT_FP_EQ(zero, func(zero, neg_zero));
EXPECT_FP_EQ(zero, func(neg_zero, zero));
EXPECT_FP_EQ(zero, func(neg_zero, neg_zero));
}
void testInRange(FuncPtr func) {
constexpr UIntType count = 10000001;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count;
++i, v += step, w -= step) {
void test_in_range(FuncPtr func) {
constexpr UIntType COUNT = 10000001;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0, w = UIntType(-1); i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
if (isnan(x) || isinf(x))
continue;

View File

@ -55,10 +55,10 @@ public:
}
void testRange(FMaxFunc func) {
constexpr UIntType count = 10000001;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count;
++i, v += step, w -= step) {
constexpr UIntType COUNT = 10000001;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0, w = UIntType(-1); i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
if (isnan(x) || isinf(x))
continue;

View File

@ -55,10 +55,10 @@ public:
}
void testRange(FMinFunc func) {
constexpr UIntType count = 10000001;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0, w = UIntType(-1); i <= count;
++i, v += step, w -= step) {
constexpr UIntType COUNT = 10000001;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0, w = UIntType(-1); i <= COUNT;
++i, v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
if (isnan(x) || isinf(x))
continue;

View File

@ -64,9 +64,9 @@ public:
}
void testRange(FloorFunc func) {
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -29,7 +29,7 @@ private:
const T zero = T(__llvm_libc::fputil::FPBits<T>::zero());
const T neg_zero = T(__llvm_libc::fputil::FPBits<T>::neg_zero());
UIntType getRandomBitPattern() {
UIntType get_random_bit_pattern() {
UIntType bits{0};
for (UIntType i = 0; i < sizeof(UIntType) / 2; ++i) {
bits =
@ -39,7 +39,7 @@ private:
}
public:
void testSpecialNumbers(Func func) {
void test_special_numbers(Func func) {
EXPECT_FP_EQ(func(zero, zero, zero), zero);
EXPECT_FP_EQ(func(zero, neg_zero, neg_zero), neg_zero);
EXPECT_FP_EQ(func(inf, inf, zero), inf);
@ -63,14 +63,14 @@ public:
EXPECT_FP_EQ(func(T(1.75), z, -z), T(0.75) * z);
}
void testSubnormalRange(Func func) {
constexpr UIntType count = 1000001;
constexpr UIntType step =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count;
void test_subnormal_range(Func func) {
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / COUNT;
for (UIntType v = FPBits::MIN_SUBNORMAL, w = FPBits::MAX_SUBNORMAL;
v <= FPBits::MAX_SUBNORMAL && w >= FPBits::MIN_SUBNORMAL;
v += step, w -= step) {
T x = T(FPBits(getRandomBitPattern())), y = T(FPBits(v)),
v += STEP, w -= STEP) {
T x = T(FPBits(get_random_bit_pattern())), y = T(FPBits(v)),
z = T(FPBits(w));
T result = func(x, y, z);
mpfr::TernaryInput<T> input{x, y, z};
@ -78,14 +78,14 @@ public:
}
}
void testNormalRange(Func func) {
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count;
void test_normal_range(Func func) {
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / COUNT;
for (UIntType v = FPBits::MIN_NORMAL, w = FPBits::MAX_NORMAL;
v <= FPBits::MAX_NORMAL && w >= FPBits::MIN_NORMAL;
v += step, w -= step) {
v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w)),
z = T(FPBits(getRandomBitPattern()));
z = T(FPBits(get_random_bit_pattern()));
T result = func(x, y, z);
mpfr::TernaryInput<T> input{x, y, z};
ASSERT_MPFR_MATCH(mpfr::Operation::Fma, input, result, 0.5);

View File

@ -19,7 +19,7 @@ template <typename T> class FrexpTest : public __llvm_libc::testing::Test {
DECLARE_SPECIAL_CONSTANTS(T)
static constexpr UIntType HiddenBit =
static constexpr UIntType HIDDEN_BIT =
UIntType(1) << __llvm_libc::fputil::MantissaWidth<T>::VALUE;
public:
@ -93,9 +93,9 @@ public:
void testRange(FrexpFunc func) {
using UIntType = typename FPBits::UIntType;
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = static_cast<T>(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0l)
continue;

View File

@ -32,7 +32,7 @@ private:
const T neg_zero = T(__llvm_libc::fputil::FPBits<T>::neg_zero());
public:
void testSpecialNumbers(Func func) {
void test_special_numbers(Func func) {
EXPECT_FP_EQ(func(inf, nan), inf);
EXPECT_FP_EQ(func(nan, neg_inf), inf);
EXPECT_FP_EQ(func(zero, inf), inf);
@ -45,14 +45,14 @@ public:
EXPECT_FP_EQ(func(neg_zero, zero), zero);
}
void testSubnormalRange(Func func) {
constexpr UIntType count = 1000001;
void test_subnormal_range(Func func) {
constexpr UIntType COUNT = 1000001;
for (unsigned scale = 0; scale < 4; ++scale) {
UIntType maxValue = FPBits::MAX_SUBNORMAL << scale;
UIntType step = (maxValue - FPBits::MIN_SUBNORMAL) / count;
UIntType max_value = FPBits::MAX_SUBNORMAL << scale;
UIntType step = (max_value - FPBits::MIN_SUBNORMAL) / COUNT;
for (int signs = 0; signs < 4; ++signs) {
for (UIntType v = FPBits::MIN_SUBNORMAL, w = maxValue;
v <= maxValue && w >= FPBits::MIN_SUBNORMAL;
for (UIntType v = FPBits::MIN_SUBNORMAL, w = max_value;
v <= max_value && w >= FPBits::MIN_SUBNORMAL;
v += step, w -= step) {
T x = T(FPBits(v)), y = T(FPBits(w));
if (signs % 2 == 1) {
@ -70,13 +70,13 @@ public:
}
}
void testNormalRange(Func func) {
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count;
void test_normal_range(Func func) {
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / COUNT;
for (int signs = 0; signs < 4; ++signs) {
for (UIntType v = FPBits::MIN_NORMAL, w = FPBits::MAX_NORMAL;
v <= FPBits::MAX_NORMAL && w >= FPBits::MIN_NORMAL;
v += step, w -= step) {
v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
if (signs % 2 == 1) {
x = -x;

View File

@ -21,7 +21,7 @@ public:
template <typename T> struct ILogbFunc { typedef int (*Func)(T); };
template <typename T>
void testSpecialNumbers(typename ILogbFunc<T>::Func func) {
void test_special_numbers(typename ILogbFunc<T>::Func func) {
EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits<T>::zero())));
EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits<T>::neg_zero())));
@ -32,7 +32,8 @@ public:
EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits<T>::neg_inf())));
}
template <typename T> void testPowersOfTwo(typename ILogbFunc<T>::Func func) {
template <typename T>
void test_powers_of_two(typename ILogbFunc<T>::Func func) {
EXPECT_EQ(0, func(T(1.0)));
EXPECT_EQ(0, func(T(-1.0)));
@ -53,7 +54,7 @@ public:
}
template <typename T>
void testSomeIntegers(typename ILogbFunc<T>::Func func) {
void test_some_integers(typename ILogbFunc<T>::Func func) {
EXPECT_EQ(1, func(T(3.0)));
EXPECT_EQ(1, func(T(-3.0)));
@ -71,14 +72,14 @@ public:
}
template <typename T>
void testSubnormalRange(typename ILogbFunc<T>::Func func) {
void test_subnormal_range(typename ILogbFunc<T>::Func func) {
using FPBits = __llvm_libc::fputil::FPBits<T>;
using UIntType = typename FPBits::UIntType;
constexpr UIntType count = 1000001;
constexpr UIntType step =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count;
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / COUNT;
for (UIntType v = FPBits::MIN_SUBNORMAL; v <= FPBits::MAX_SUBNORMAL;
v += step) {
v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0)
continue;
@ -89,12 +90,13 @@ public:
}
}
template <typename T> void testNormalRange(typename ILogbFunc<T>::Func func) {
template <typename T>
void test_normal_range(typename ILogbFunc<T>::Func func) {
using FPBits = __llvm_libc::fputil::FPBits<T>;
using UIntType = typename FPBits::UIntType;
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count;
for (UIntType v = FPBits::MIN_NORMAL; v <= FPBits::MAX_NORMAL; v += step) {
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / COUNT;
for (UIntType v = FPBits::MIN_NORMAL; v <= FPBits::MAX_NORMAL; v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0)
continue;

View File

@ -23,10 +23,10 @@ class LdExpTestTemplate : public __llvm_libc::testing::Test {
using FPBits = __llvm_libc::fputil::FPBits<T>;
using NormalFloat = __llvm_libc::fputil::NormalFloat<T>;
using UIntType = typename FPBits::UIntType;
static constexpr UIntType mantissaWidth =
static constexpr UIntType MANTISSA_WIDTH =
__llvm_libc::fputil::MantissaWidth<T>::VALUE;
// A normalized mantissa to be used with tests.
static constexpr UIntType mantissa = NormalFloat::ONE + 0x1234;
static constexpr UIntType MANTISSA = NormalFloat::ONE + 0x1234;
const T zero = T(__llvm_libc::fputil::FPBits<T>::zero());
const T neg_zero = T(__llvm_libc::fputil::FPBits<T>::neg_zero());
@ -38,8 +38,8 @@ public:
typedef T (*LdExpFunc)(T, int);
void testSpecialNumbers(LdExpFunc func) {
int expArray[5] = {-INT_MAX - 1, -10, 0, 10, INT_MAX};
for (int exp : expArray) {
int exp_array[5] = {-INT_MAX - 1, -10, 0, 10, INT_MAX};
for (int exp : exp_array) {
ASSERT_FP_EQ(zero, func(zero, exp));
ASSERT_FP_EQ(neg_zero, func(neg_zero, exp));
ASSERT_FP_EQ(inf, func(inf, exp));
@ -49,10 +49,10 @@ public:
}
void testPowersOfTwo(LdExpFunc func) {
int32_t expArray[5] = {1, 2, 3, 4, 5};
int32_t valArray[6] = {1, 2, 4, 8, 16, 32};
for (int32_t exp : expArray) {
for (int32_t val : valArray) {
int32_t exp_array[5] = {1, 2, 3, 4, 5};
int32_t val_array[6] = {1, 2, 4, 8, 16, 32};
for (int32_t exp : exp_array) {
for (int32_t val : val_array) {
ASSERT_FP_EQ(T(val << exp), func(T(val), exp));
ASSERT_FP_EQ(T(-1 * (val << exp)), func(T(-val), exp));
}
@ -70,11 +70,12 @@ public:
void testUnderflowToZeroOnNormal(LdExpFunc func) {
// In this test, we pass a normal nubmer to func and expect zero
// to be returned due to underflow.
int32_t baseExponent = FPBits::EXPONENT_BIAS + mantissaWidth;
int32_t expArray[] = {baseExponent + 5, baseExponent + 4, baseExponent + 3,
baseExponent + 2, baseExponent + 1};
T x = NormalFloat(0, mantissa, 0);
for (int32_t exp : expArray) {
int32_t base_exponent = FPBits::EXPONENT_BIAS + MANTISSA_WIDTH;
int32_t exp_array[] = {base_exponent + 5, base_exponent + 4,
base_exponent + 3, base_exponent + 2,
base_exponent + 1};
T x = NormalFloat(0, MANTISSA, 0);
for (int32_t exp : exp_array) {
ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : neg_zero);
}
}
@ -82,25 +83,26 @@ public:
void testUnderflowToZeroOnSubnormal(LdExpFunc func) {
// In this test, we pass a normal nubmer to func and expect zero
// to be returned due to underflow.
int32_t baseExponent = FPBits::EXPONENT_BIAS + mantissaWidth;
int32_t expArray[] = {baseExponent + 5, baseExponent + 4, baseExponent + 3,
baseExponent + 2, baseExponent + 1};
T x = NormalFloat(-FPBits::EXPONENT_BIAS, mantissa, 0);
for (int32_t exp : expArray) {
int32_t base_exponent = FPBits::EXPONENT_BIAS + MANTISSA_WIDTH;
int32_t exp_array[] = {base_exponent + 5, base_exponent + 4,
base_exponent + 3, base_exponent + 2,
base_exponent + 1};
T x = NormalFloat(-FPBits::EXPONENT_BIAS, MANTISSA, 0);
for (int32_t exp : exp_array) {
ASSERT_FP_EQ(func(x, -exp), x > 0 ? zero : neg_zero);
}
}
void testNormalOperation(LdExpFunc func) {
T valArray[] = {
T val_array[] = {
// Normal numbers
NormalFloat(100, mantissa, 0), NormalFloat(-100, mantissa, 0),
NormalFloat(100, mantissa, 1), NormalFloat(-100, mantissa, 1),
NormalFloat(100, MANTISSA, 0), NormalFloat(-100, MANTISSA, 0),
NormalFloat(100, MANTISSA, 1), NormalFloat(-100, MANTISSA, 1),
// Subnormal numbers
NormalFloat(-FPBits::EXPONENT_BIAS, mantissa, 0),
NormalFloat(-FPBits::EXPONENT_BIAS, mantissa, 1)};
for (int32_t exp = 0; exp <= static_cast<int32_t>(mantissaWidth); ++exp) {
for (T x : valArray) {
NormalFloat(-FPBits::EXPONENT_BIAS, MANTISSA, 0),
NormalFloat(-FPBits::EXPONENT_BIAS, MANTISSA, 1)};
for (int32_t exp = 0; exp <= static_cast<int32_t>(MANTISSA_WIDTH); ++exp) {
for (T x : val_array) {
// We compare the result of ldexp with the result
// of the native multiplication/division instruction.
ASSERT_FP_EQ(func(x, exp), x * (UIntType(1) << exp));
@ -118,13 +120,13 @@ public:
x = NormalFloat(FPBits::EXPONENT_BIAS, NormalFloat::ONE, 0);
int exp = -FPBits::MAX_EXPONENT - 5;
T result = func(x, exp);
FPBits resultBits(result);
ASSERT_FALSE(resultBits.is_zero());
FPBits result_bits(result);
ASSERT_FALSE(result_bits.is_zero());
// Verify that the result is indeed subnormal.
ASSERT_EQ(resultBits.get_unbiased_exponent(), uint16_t(0));
ASSERT_EQ(result_bits.get_unbiased_exponent(), uint16_t(0));
// But if the exp is so less that normalization leads to zero, then
// the result should be zero.
result = func(x, -FPBits::MAX_EXPONENT - int(mantissaWidth) - 5);
result = func(x, -FPBits::MAX_EXPONENT - int(MANTISSA_WIDTH) - 5);
ASSERT_TRUE(FPBits(result).is_zero());
// Start with a subnormal number but pass a very high number for exponent.

View File

@ -19,7 +19,7 @@ template <typename T> class LogbTest : public __llvm_libc::testing::Test {
DECLARE_SPECIAL_CONSTANTS(T)
static constexpr UIntType HiddenBit =
static constexpr UIntType HIDDEN_BIT =
UIntType(1) << __llvm_libc::fputil::MantissaWidth<T>::VALUE;
public:
@ -72,9 +72,9 @@ public:
void testRange(LogbFunc func) {
using UIntType = typename FPBits::UIntType;
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = static_cast<T>(FPBits(v));
if (isnan(x) || isinf(x) || x == 0.0l)
continue;

View File

@ -84,9 +84,9 @@ public:
}
void testRange(ModfFunc func) {
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x) || x == T(0.0))
continue;

View File

@ -22,7 +22,7 @@ class NextAfterTestTemplate : public __llvm_libc::testing::Test {
using MantissaWidth = __llvm_libc::fputil::MantissaWidth<T>;
using UIntType = typename FPBits::UIntType;
static constexpr int bitWidthOfType =
static constexpr int BIT_WIDTH_OF_TYPE =
__llvm_libc::fputil::FloatProperties<T>::BIT_WIDTH;
const T zero = T(FPBits::zero());
@ -30,10 +30,10 @@ class NextAfterTestTemplate : public __llvm_libc::testing::Test {
const T inf = T(FPBits::inf());
const T neg_inf = T(FPBits::neg_inf());
const T nan = T(FPBits::build_nan(1));
const UIntType MIN_SUBNORMAL = FPBits::MIN_SUBNORMAL;
const UIntType MAX_SUBNORMAL = FPBits::MAX_SUBNORMAL;
const UIntType MIN_NORMAL = FPBits::MIN_NORMAL;
const UIntType MAX_NORMAL = FPBits::MAX_NORMAL;
const UIntType min_subnormal = FPBits::MIN_SUBNORMAL;
const UIntType max_subnormal = FPBits::MAX_SUBNORMAL;
const UIntType min_normal = FPBits::MIN_NORMAL;
const UIntType max_normal = FPBits::MAX_NORMAL;
public:
typedef T (*NextAfterFunc)(T, T);
@ -50,89 +50,91 @@ public:
// 'from' is zero|neg_zero.
T x = zero;
T result = func(x, T(1));
UIntType expectedBits = 1;
T expected = *reinterpret_cast<T *>(&expectedBits);
UIntType expected_bits = 1;
T expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
result = func(x, T(-1));
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
x = neg_zero;
result = func(x, 1);
expectedBits = 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
result = func(x, -1);
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
// 'from' is max subnormal value.
x = *reinterpret_cast<const T *>(&MAX_SUBNORMAL);
x = *reinterpret_cast<const T *>(&max_subnormal);
result = func(x, 1);
expected = *reinterpret_cast<const T *>(&MIN_NORMAL);
expected = *reinterpret_cast<const T *>(&min_normal);
ASSERT_FP_EQ(result, expected);
result = func(x, 0);
expectedBits = MAX_SUBNORMAL - 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = max_subnormal - 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
x = -x;
result = func(x, -1);
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_NORMAL;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
result = func(x, 0);
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_SUBNORMAL - 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits =
(UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal - 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
// 'from' is min subnormal value.
x = *reinterpret_cast<const T *>(&MIN_SUBNORMAL);
x = *reinterpret_cast<const T *>(&min_subnormal);
result = func(x, 1);
expectedBits = MIN_SUBNORMAL + 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = min_subnormal + 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
ASSERT_FP_EQ(func(x, 0), 0);
x = -x;
result = func(x, -1);
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_SUBNORMAL + 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits =
(UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_subnormal + 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
ASSERT_FP_EQ(func(x, 0), T(-0.0));
// 'from' is min normal.
x = *reinterpret_cast<const T *>(&MIN_NORMAL);
x = *reinterpret_cast<const T *>(&min_normal);
result = func(x, 0);
expectedBits = MAX_SUBNORMAL;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = max_subnormal;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
result = func(x, inf);
expectedBits = MIN_NORMAL + 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = min_normal + 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
x = -x;
result = func(x, 0);
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_SUBNORMAL;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
result = func(x, -inf);
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_NORMAL + 1;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal + 1;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
// 'from' is max normal and 'to' is infinity.
x = *reinterpret_cast<const T *>(&MAX_NORMAL);
x = *reinterpret_cast<const T *>(&max_normal);
result = func(x, inf);
ASSERT_FP_EQ(result, inf);
@ -142,48 +144,48 @@ public:
// 'from' is infinity.
x = inf;
result = func(x, 0);
expectedBits = MAX_NORMAL;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = max_normal;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
ASSERT_FP_EQ(func(x, inf), inf);
x = neg_inf;
result = func(x, 0);
expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_NORMAL;
expected = *reinterpret_cast<T *>(&expectedBits);
expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_normal;
expected = *reinterpret_cast<T *>(&expected_bits);
ASSERT_FP_EQ(result, expected);
ASSERT_FP_EQ(func(x, neg_inf), neg_inf);
// 'from' is a power of 2.
x = T(32.0);
result = func(x, 0);
FPBits xBits = FPBits(x);
FPBits resultBits = FPBits(result);
ASSERT_EQ(resultBits.get_unbiased_exponent(),
uint16_t(xBits.get_unbiased_exponent() - 1));
ASSERT_EQ(resultBits.get_mantissa(),
FPBits x_bits = FPBits(x);
FPBits result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);
result = func(x, T(33.0));
resultBits = FPBits(result);
ASSERT_EQ(resultBits.get_unbiased_exponent(),
xBits.get_unbiased_exponent());
ASSERT_EQ(resultBits.get_mantissa(), xBits.get_mantissa() + UIntType(1));
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));
x = -x;
result = func(x, 0);
resultBits = FPBits(result);
ASSERT_EQ(resultBits.get_unbiased_exponent(),
uint16_t(xBits.get_unbiased_exponent() - 1));
ASSERT_EQ(resultBits.get_mantissa(),
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
uint16_t(x_bits.get_unbiased_exponent() - 1));
ASSERT_EQ(result_bits.get_mantissa(),
(UIntType(1) << MantissaWidth::VALUE) - 1);
result = func(x, T(-33.0));
resultBits = FPBits(result);
ASSERT_EQ(resultBits.get_unbiased_exponent(),
xBits.get_unbiased_exponent());
ASSERT_EQ(resultBits.get_mantissa(), xBits.get_mantissa() + UIntType(1));
result_bits = FPBits(result);
ASSERT_EQ(result_bits.get_unbiased_exponent(),
x_bits.get_unbiased_exponent());
ASSERT_EQ(result_bits.get_mantissa(), x_bits.get_mantissa() + UIntType(1));
}
};

View File

@ -21,8 +21,8 @@
namespace mpfr = __llvm_libc::testing::mpfr;
static constexpr int roundingModes[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};
static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};
template <typename T>
class RIntTestTemplate : public __llvm_libc::testing::Test {
@ -39,7 +39,7 @@ private:
const T neg_inf = T(FPBits::neg_inf());
const T nan = T(FPBits::build_nan(1));
static inline mpfr::RoundingMode toMPFRRoundingMode(int mode) {
static inline mpfr::RoundingMode to_mpfr_rounding_mode(int mode) {
switch (mode) {
case FE_UPWARD:
return mpfr::RoundingMode::Upward;
@ -56,7 +56,7 @@ private:
public:
void testSpecialNumbers(RIntFunc func) {
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
ASSERT_FP_EQ(inf, func(inf));
ASSERT_FP_EQ(neg_inf, func(neg_inf));
@ -67,50 +67,50 @@ public:
}
void testRoundNumbers(RIntFunc func) {
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode);
ASSERT_FP_EQ(func(T(1.0)), mpfr::Round(T(1.0), mpfrMode));
ASSERT_FP_EQ(func(T(-1.0)), mpfr::Round(T(-1.0), mpfrMode));
ASSERT_FP_EQ(func(T(10.0)), mpfr::Round(T(10.0), mpfrMode));
ASSERT_FP_EQ(func(T(-10.0)), mpfr::Round(T(-10.0), mpfrMode));
ASSERT_FP_EQ(func(T(1234.0)), mpfr::Round(T(1234.0), mpfrMode));
ASSERT_FP_EQ(func(T(-1234.0)), mpfr::Round(T(-1234.0), mpfrMode));
mpfr::RoundingMode mpfr_mode = to_mpfr_rounding_mode(mode);
ASSERT_FP_EQ(func(T(1.0)), mpfr::Round(T(1.0), mpfr_mode));
ASSERT_FP_EQ(func(T(-1.0)), mpfr::Round(T(-1.0), mpfr_mode));
ASSERT_FP_EQ(func(T(10.0)), mpfr::Round(T(10.0), mpfr_mode));
ASSERT_FP_EQ(func(T(-10.0)), mpfr::Round(T(-10.0), mpfr_mode));
ASSERT_FP_EQ(func(T(1234.0)), mpfr::Round(T(1234.0), mpfr_mode));
ASSERT_FP_EQ(func(T(-1234.0)), mpfr::Round(T(-1234.0), mpfr_mode));
}
}
void testFractions(RIntFunc func) {
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode);
ASSERT_FP_EQ(func(T(0.5)), mpfr::Round(T(0.5), mpfrMode));
ASSERT_FP_EQ(func(T(-0.5)), mpfr::Round(T(-0.5), mpfrMode));
ASSERT_FP_EQ(func(T(0.115)), mpfr::Round(T(0.115), mpfrMode));
ASSERT_FP_EQ(func(T(-0.115)), mpfr::Round(T(-0.115), mpfrMode));
ASSERT_FP_EQ(func(T(0.715)), mpfr::Round(T(0.715), mpfrMode));
ASSERT_FP_EQ(func(T(-0.715)), mpfr::Round(T(-0.715), mpfrMode));
mpfr::RoundingMode mpfr_mode = to_mpfr_rounding_mode(mode);
ASSERT_FP_EQ(func(T(0.5)), mpfr::Round(T(0.5), mpfr_mode));
ASSERT_FP_EQ(func(T(-0.5)), mpfr::Round(T(-0.5), mpfr_mode));
ASSERT_FP_EQ(func(T(0.115)), mpfr::Round(T(0.115), mpfr_mode));
ASSERT_FP_EQ(func(T(-0.115)), mpfr::Round(T(-0.115), mpfr_mode));
ASSERT_FP_EQ(func(T(0.715)), mpfr::Round(T(0.715), mpfr_mode));
ASSERT_FP_EQ(func(T(-0.715)), mpfr::Round(T(-0.715), mpfr_mode));
}
}
void testSubnormalRange(RIntFunc func) {
constexpr UIntType count = 1000001;
constexpr UIntType step =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count;
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / COUNT;
for (UIntType i = FPBits::MIN_SUBNORMAL; i <= FPBits::MAX_SUBNORMAL;
i += step) {
i += STEP) {
T x = T(FPBits(i));
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode);
ASSERT_FP_EQ(func(x), mpfr::Round(x, mpfrMode));
mpfr::RoundingMode mpfr_mode = to_mpfr_rounding_mode(mode);
ASSERT_FP_EQ(func(x), mpfr::Round(x, mpfr_mode));
}
}
}
void testNormalRange(RIntFunc func) {
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count;
for (UIntType i = FPBits::MIN_NORMAL; i <= FPBits::MAX_NORMAL; i += step) {
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / COUNT;
for (UIntType i = FPBits::MIN_NORMAL; i <= FPBits::MAX_NORMAL; i += STEP) {
T x = T(FPBits(i));
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
@ -118,10 +118,10 @@ public:
continue;
}
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
mpfr::RoundingMode mpfrMode = toMPFRRoundingMode(mode);
ASSERT_FP_EQ(func(x), mpfr::Round(x, mpfrMode));
mpfr::RoundingMode mpfr_mode = to_mpfr_rounding_mode(mode);
ASSERT_FP_EQ(func(x), mpfr::Round(x, mpfr_mode));
}
}
}

View File

@ -95,12 +95,12 @@ public:
}
void testSubnormalRange(RemQuoFunc func) {
constexpr UIntType count = 1000001;
constexpr UIntType step =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count;
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / COUNT;
for (UIntType v = FPBits::MIN_SUBNORMAL, w = FPBits::MAX_SUBNORMAL;
v <= FPBits::MAX_SUBNORMAL && w >= FPBits::MIN_SUBNORMAL;
v += step, w -= step) {
v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
mpfr::BinaryOutput<T> result;
mpfr::BinaryInput<T> input{x, y};
@ -110,11 +110,11 @@ public:
}
void testNormalRange(RemQuoFunc func) {
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count;
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / COUNT;
for (UIntType v = FPBits::MIN_NORMAL, w = FPBits::MAX_NORMAL;
v <= FPBits::MAX_NORMAL && w >= FPBits::MIN_NORMAL;
v += step, w -= step) {
v += STEP, w -= STEP) {
T x = T(FPBits(v)), y = T(FPBits(w));
mpfr::BinaryOutput<T> result;
mpfr::BinaryInput<T> input{x, y};

View File

@ -64,9 +64,9 @@ public:
}
void testRange(RoundFunc func) {
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -23,8 +23,8 @@
namespace mpfr = __llvm_libc::testing::mpfr;
static constexpr int roundingModes[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};
static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};
template <typename F, typename I, bool TestModes = false>
class RoundToIntegerTestTemplate : public __llvm_libc::testing::Test {
@ -40,11 +40,11 @@ private:
const F inf = F(__llvm_libc::fputil::FPBits<F>::inf());
const F neg_inf = F(__llvm_libc::fputil::FPBits<F>::neg_inf());
const F nan = F(__llvm_libc::fputil::FPBits<F>::build_nan(1));
static constexpr I IntegerMin = I(1) << (sizeof(I) * 8 - 1);
static constexpr I IntegerMax = -(IntegerMin + 1);
static constexpr I INTEGER_MIN = I(1) << (sizeof(I) * 8 - 1);
static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1);
void testOneInput(RoundToIntegerFunc func, F input, I expected,
bool expectError) {
void test_one_input(RoundToIntegerFunc func, F input, I expected,
bool expectError) {
#if math_errhandling & MATH_ERRNO
errno = 0;
#endif
@ -71,7 +71,7 @@ private:
}
}
static inline mpfr::RoundingMode toMPFRRoundingMode(int mode) {
static inline mpfr::RoundingMode to_mpfr_rounding_mode(int mode) {
switch (mode) {
case FE_UPWARD:
return mpfr::RoundingMode::Upward;
@ -96,32 +96,32 @@ public:
#endif
}
void doInfinityAndNaNTest(RoundToIntegerFunc func) {
testOneInput(func, inf, IntegerMax, true);
testOneInput(func, neg_inf, IntegerMin, true);
testOneInput(func, nan, IntegerMax, true);
void do_infinity_and_na_n_test(RoundToIntegerFunc func) {
test_one_input(func, inf, INTEGER_MAX, true);
test_one_input(func, neg_inf, INTEGER_MIN, true);
test_one_input(func, nan, INTEGER_MAX, true);
}
void testInfinityAndNaN(RoundToIntegerFunc func) {
if (TestModes) {
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
doInfinityAndNaNTest(func);
do_infinity_and_na_n_test(func);
}
} else {
doInfinityAndNaNTest(func);
do_infinity_and_na_n_test(func);
}
}
void doRoundNumbersTest(RoundToIntegerFunc func) {
testOneInput(func, zero, I(0), false);
testOneInput(func, neg_zero, I(0), false);
testOneInput(func, F(1.0), I(1), false);
testOneInput(func, F(-1.0), I(-1), false);
testOneInput(func, F(10.0), I(10), false);
testOneInput(func, F(-10.0), I(-10), false);
testOneInput(func, F(1234.0), I(1234), false);
testOneInput(func, F(-1234.0), I(-1234), false);
void do_round_numbers_test(RoundToIntegerFunc func) {
test_one_input(func, zero, I(0), false);
test_one_input(func, neg_zero, I(0), false);
test_one_input(func, F(1.0), I(1), false);
test_one_input(func, F(-1.0), I(-1), false);
test_one_input(func, F(10.0), I(10), false);
test_one_input(func, F(-10.0), I(-10), false);
test_one_input(func, F(1234.0), I(1234), false);
test_one_input(func, F(-1234.0), I(-1234), false);
// The rest of this this function compares with an equivalent MPFR function
// which rounds floating point numbers to long values. There is no MPFR
@ -131,58 +131,58 @@ public:
if (sizeof(I) > sizeof(long))
return;
constexpr int exponentLimit = sizeof(I) * 8 - 1;
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
bits.set_unbiased_exponent(exponentLimit + FPBits::EXPONENT_BIAS);
bits.set_unbiased_exponent(EXPONENT_LIMIT + FPBits::EXPONENT_BIAS);
bits.set_sign(1);
bits.set_mantissa(0);
F x = F(bits);
long mpfrResult;
bool erangeflag = mpfr::RoundToLong(x, mpfrResult);
long mpfr_result;
bool erangeflag = mpfr::RoundToLong(x, mpfr_result);
ASSERT_FALSE(erangeflag);
testOneInput(func, x, mpfrResult, false);
test_one_input(func, x, mpfr_result, false);
}
void testRoundNumbers(RoundToIntegerFunc func) {
if (TestModes) {
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
doRoundNumbersTest(func);
do_round_numbers_test(func);
}
} else {
doRoundNumbersTest(func);
do_round_numbers_test(func);
}
}
void doFractionsTest(RoundToIntegerFunc func, int mode) {
constexpr F fractions[] = {0.5, -0.5, 0.115, -0.115, 0.715, -0.715};
for (F x : fractions) {
long mpfrLongResult;
void do_fractions_test(RoundToIntegerFunc func, int mode) {
constexpr F FRACTIONS[] = {0.5, -0.5, 0.115, -0.115, 0.715, -0.715};
for (F x : FRACTIONS) {
long mpfr_long_result;
bool erangeflag;
if (TestModes)
erangeflag =
mpfr::RoundToLong(x, toMPFRRoundingMode(mode), mpfrLongResult);
mpfr::RoundToLong(x, to_mpfr_rounding_mode(mode), mpfr_long_result);
else
erangeflag = mpfr::RoundToLong(x, mpfrLongResult);
erangeflag = mpfr::RoundToLong(x, mpfr_long_result);
ASSERT_FALSE(erangeflag);
I mpfrResult = mpfrLongResult;
testOneInput(func, x, mpfrResult, false);
I mpfr_result = mpfr_long_result;
test_one_input(func, x, mpfr_result, false);
}
}
void testFractions(RoundToIntegerFunc func) {
if (TestModes) {
for (int mode : roundingModes) {
for (int mode : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(mode);
doFractionsTest(func, mode);
do_fractions_test(func, mode);
}
} else {
// Passing 0 for mode has no effect as it is not used in doFractionsTest
// when `TestModes` is false;
doFractionsTest(func, 0);
do_fractions_test(func, 0);
}
}
@ -195,39 +195,39 @@ public:
if (sizeof(I) > sizeof(long))
return;
constexpr int exponentLimit = sizeof(I) * 8 - 1;
constexpr int EXPONENT_LIMIT = sizeof(I) * 8 - 1;
// We start with 1.0 so that the implicit bit for x86 long doubles
// is set.
FPBits bits(F(1.0));
bits.set_unbiased_exponent(exponentLimit + FPBits::EXPONENT_BIAS);
bits.set_unbiased_exponent(EXPONENT_LIMIT + FPBits::EXPONENT_BIAS);
bits.set_sign(1);
bits.set_mantissa(UIntType(0x1)
<< (__llvm_libc::fputil::MantissaWidth<F>::VALUE - 1));
F x = F(bits);
if (TestModes) {
for (int m : roundingModes) {
for (int m : ROUNDING_MODES) {
__llvm_libc::fputil::set_round(m);
long mpfrLongResult;
long mpfr_long_result;
bool erangeflag =
mpfr::RoundToLong(x, toMPFRRoundingMode(m), mpfrLongResult);
mpfr::RoundToLong(x, to_mpfr_rounding_mode(m), mpfr_long_result);
ASSERT_TRUE(erangeflag);
testOneInput(func, x, IntegerMin, true);
test_one_input(func, x, INTEGER_MIN, true);
}
} else {
long mpfrLongResult;
bool erangeflag = mpfr::RoundToLong(x, mpfrLongResult);
long mpfr_long_result;
bool erangeflag = mpfr::RoundToLong(x, mpfr_long_result);
ASSERT_TRUE(erangeflag);
testOneInput(func, x, IntegerMin, true);
test_one_input(func, x, INTEGER_MIN, true);
}
}
void testSubnormalRange(RoundToIntegerFunc func) {
constexpr UIntType count = 1000001;
constexpr UIntType step =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / count;
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP =
(FPBits::MAX_SUBNORMAL - FPBits::MIN_SUBNORMAL) / COUNT;
for (UIntType i = FPBits::MIN_SUBNORMAL; i <= FPBits::MAX_SUBNORMAL;
i += step) {
i += STEP) {
F x = F(FPBits(i));
if (x == F(0.0))
continue;
@ -235,25 +235,25 @@ public:
if (TestModes) {
if (x > 0) {
__llvm_libc::fputil::set_round(FE_UPWARD);
testOneInput(func, x, I(1), false);
test_one_input(func, x, I(1), false);
__llvm_libc::fputil::set_round(FE_DOWNWARD);
testOneInput(func, x, I(0), false);
test_one_input(func, x, I(0), false);
__llvm_libc::fputil::set_round(FE_TOWARDZERO);
testOneInput(func, x, I(0), false);
test_one_input(func, x, I(0), false);
__llvm_libc::fputil::set_round(FE_TONEAREST);
testOneInput(func, x, I(0), false);
test_one_input(func, x, I(0), false);
} else {
__llvm_libc::fputil::set_round(FE_UPWARD);
testOneInput(func, x, I(0), false);
test_one_input(func, x, I(0), false);
__llvm_libc::fputil::set_round(FE_DOWNWARD);
testOneInput(func, x, I(-1), false);
test_one_input(func, x, I(-1), false);
__llvm_libc::fputil::set_round(FE_TOWARDZERO);
testOneInput(func, x, I(0), false);
test_one_input(func, x, I(0), false);
__llvm_libc::fputil::set_round(FE_TONEAREST);
testOneInput(func, x, I(0), false);
test_one_input(func, x, I(0), false);
}
} else {
testOneInput(func, x, 0L, false);
test_one_input(func, x, 0L, false);
}
}
}
@ -267,9 +267,9 @@ public:
if (sizeof(I) > sizeof(long))
return;
constexpr UIntType count = 1000001;
constexpr UIntType step = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / count;
for (UIntType i = FPBits::MIN_NORMAL; i <= FPBits::MAX_NORMAL; i += step) {
constexpr UIntType COUNT = 1000001;
constexpr UIntType STEP = (FPBits::MAX_NORMAL - FPBits::MIN_NORMAL) / COUNT;
for (UIntType i = FPBits::MIN_NORMAL; i <= FPBits::MAX_NORMAL; i += STEP) {
F x = F(FPBits(i));
// In normal range on x86 platforms, the long double implicit 1 bit can be
// zero making the numbers NaN. We will skip them.
@ -278,25 +278,25 @@ public:
}
if (TestModes) {
for (int m : roundingModes) {
long mpfrLongResult;
for (int m : ROUNDING_MODES) {
long mpfr_long_result;
bool erangeflag =
mpfr::RoundToLong(x, toMPFRRoundingMode(m), mpfrLongResult);
I mpfrResult = mpfrLongResult;
mpfr::RoundToLong(x, to_mpfr_rounding_mode(m), mpfr_long_result);
I mpfr_result = mpfr_long_result;
__llvm_libc::fputil::set_round(m);
if (erangeflag)
testOneInput(func, x, x > 0 ? IntegerMax : IntegerMin, true);
test_one_input(func, x, x > 0 ? INTEGER_MAX : INTEGER_MIN, true);
else
testOneInput(func, x, mpfrResult, false);
test_one_input(func, x, mpfr_result, false);
}
} else {
long mpfrLongResult;
bool erangeflag = mpfr::RoundToLong(x, mpfrLongResult);
I mpfrResult = mpfrLongResult;
long mpfr_long_result;
bool erangeflag = mpfr::RoundToLong(x, mpfr_long_result);
I mpfr_result = mpfr_long_result;
if (erangeflag)
testOneInput(func, x, x > 0 ? IntegerMax : IntegerMin, true);
test_one_input(func, x, x > 0 ? INTEGER_MAX : INTEGER_MIN, true);
else
testOneInput(func, x, mpfrResult, false);
test_one_input(func, x, mpfr_result, false);
}
}
}

View File

@ -18,7 +18,7 @@ template <typename T> class SqrtTest : public __llvm_libc::testing::Test {
DECLARE_SPECIAL_CONSTANTS(T)
static constexpr UIntType HiddenBit =
static constexpr UIntType HIDDEN_BIT =
UIntType(1) << __llvm_libc::fputil::MantissaWidth<T>::VALUE;
public:
@ -37,7 +37,7 @@ public:
}
void testDenormalValues(SqrtFunc func) {
for (UIntType mant = 1; mant < HiddenBit; mant <<= 1) {
for (UIntType mant = 1; mant < HIDDEN_BIT; mant <<= 1) {
FPBits denormal(T(0.0));
denormal.set_mantissa(mant);
@ -45,18 +45,18 @@ public:
T(0.5));
}
constexpr UIntType count = 1'000'001;
constexpr UIntType step = HiddenBit / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 1'000'001;
constexpr UIntType STEP = HIDDEN_BIT / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = *reinterpret_cast<T *>(&v);
ASSERT_MPFR_MATCH(mpfr::Operation::Sqrt, x, func(x), 0.5);
}
}
void testNormalRange(SqrtFunc func) {
constexpr UIntType count = 10'000'001;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10'000'001;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = *reinterpret_cast<T *>(&v);
if (isnan(x) || (x < 0)) {
continue;

View File

@ -64,9 +64,9 @@ public:
}
void testRange(TruncFunc func) {
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
T x = T(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -19,9 +19,9 @@ DECLARE_SPECIAL_CONSTANTS(double)
TEST(LlvmLibccosTest, Range) {
static constexpr double _2pi = 6.283185307179586;
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
double x = double(FPBits(v));
// TODO: Expand the range of testing after range reduction is implemented.
if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)

View File

@ -18,7 +18,7 @@
#include <errno.h>
#include <stdint.h>
using __llvm_libc::testing::sdcomp26094Values;
using __llvm_libc::testing::SDCOMP26094_VALUES;
using FPBits = __llvm_libc::fputil::FPBits<float>;
namespace mpfr = __llvm_libc::testing::mpfr;
@ -47,9 +47,9 @@ TEST(LlvmLibcCosfTest, SpecialNumbers) {
}
TEST(LlvmLibcCosfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
constexpr uint32_t COUNT = 1000000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;
@ -73,7 +73,7 @@ TEST(LlvmLibcCosfTest, SmallValues) {
// SDCOMP-26094: check cosf in the cases for which the range reducer
// returns values furthest beyond its nominal upper bound of pi/4.
TEST(LlvmLibcCosfTest, SDCOMP_26094) {
for (uint32_t v : sdcomp26094Values) {
for (uint32_t v : SDCOMP26094_VALUES) {
float x = float(FPBits(v));
ASSERT_MPFR_MATCH(mpfr::Operation::Cos, x, __llvm_libc::cosf(x), 1.0);
}

View File

@ -101,9 +101,9 @@ TEST(LlvmLibcExpfTest, Underflow) {
}
TEST(LlvmLibcexp2fTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
constexpr uint32_t COUNT = 1000000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -93,9 +93,9 @@ TEST(LlvmLibcExpfTest, Borderline) {
}
TEST(LlvmLibcExpfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
constexpr uint32_t COUNT = 1000000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -93,9 +93,9 @@ TEST(LlvmLibcExpm1fTest, Borderline) {
}
TEST(LlvmLibcExpm1fTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
constexpr uint32_t COUNT = 1000000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -16,14 +16,16 @@
using LlvmLibcFDimTest = FDimTestTemplate<double>;
TEST_F(LlvmLibcFDimTest, NaNArg_fdim) { testNaNArg(&__llvm_libc::fdim); }
TEST_F(LlvmLibcFDimTest, NaNArg_fdim) { test_na_n_arg(&__llvm_libc::fdim); }
TEST_F(LlvmLibcFDimTest, InfArg_fdim) { testInfArg(&__llvm_libc::fdim); }
TEST_F(LlvmLibcFDimTest, InfArg_fdim) { test_inf_arg(&__llvm_libc::fdim); }
TEST_F(LlvmLibcFDimTest, NegInfArg_fdim) { testNegInfArg(&__llvm_libc::fdim); }
TEST_F(LlvmLibcFDimTest, NegInfArg_fdim) {
test_neg_inf_arg(&__llvm_libc::fdim);
}
TEST_F(LlvmLibcFDimTest, BothZero_fdim) { testBothZero(&__llvm_libc::fdim); }
TEST_F(LlvmLibcFDimTest, BothZero_fdim) { test_both_zero(&__llvm_libc::fdim); }
TEST_F(LlvmLibcFDimTest, InDoubleRange_fdim) {
testInRange(&__llvm_libc::fdim);
test_in_range(&__llvm_libc::fdim);
}

View File

@ -16,16 +16,18 @@
using LlvmLibcFDimTest = FDimTestTemplate<float>;
TEST_F(LlvmLibcFDimTest, NaNArg_fdimf) { testNaNArg(&__llvm_libc::fdimf); }
TEST_F(LlvmLibcFDimTest, NaNArg_fdimf) { test_na_n_arg(&__llvm_libc::fdimf); }
TEST_F(LlvmLibcFDimTest, InfArg_fdimf) { testInfArg(&__llvm_libc::fdimf); }
TEST_F(LlvmLibcFDimTest, InfArg_fdimf) { test_inf_arg(&__llvm_libc::fdimf); }
TEST_F(LlvmLibcFDimTest, NegInfArg_fdimf) {
testNegInfArg(&__llvm_libc::fdimf);
test_neg_inf_arg(&__llvm_libc::fdimf);
}
TEST_F(LlvmLibcFDimTest, BothZero_fdimf) { testBothZero(&__llvm_libc::fdimf); }
TEST_F(LlvmLibcFDimTest, BothZero_fdimf) {
test_both_zero(&__llvm_libc::fdimf);
}
TEST_F(LlvmLibcFDimTest, InFloatRange_fdimf) {
testInRange(&__llvm_libc::fdimf);
test_in_range(&__llvm_libc::fdimf);
}

View File

@ -16,16 +16,18 @@
using LlvmLibcFDimTest = FDimTestTemplate<long double>;
TEST_F(LlvmLibcFDimTest, NaNArg_fdiml) { testNaNArg(&__llvm_libc::fdiml); }
TEST_F(LlvmLibcFDimTest, NaNArg_fdiml) { test_na_n_arg(&__llvm_libc::fdiml); }
TEST_F(LlvmLibcFDimTest, InfArg_fdiml) { testInfArg(&__llvm_libc::fdiml); }
TEST_F(LlvmLibcFDimTest, InfArg_fdiml) { test_inf_arg(&__llvm_libc::fdiml); }
TEST_F(LlvmLibcFDimTest, NegInfArg_fdiml) {
testNegInfArg(&__llvm_libc::fdiml);
test_neg_inf_arg(&__llvm_libc::fdiml);
}
TEST_F(LlvmLibcFDimTest, BothZero_fdiml) { testBothZero(&__llvm_libc::fdiml); }
TEST_F(LlvmLibcFDimTest, BothZero_fdiml) {
test_both_zero(&__llvm_libc::fdiml);
}
TEST_F(LlvmLibcFDimTest, InLongDoubleRange_fdiml) {
testInRange(&__llvm_libc::fdiml);
test_in_range(&__llvm_libc::fdiml);
}

View File

@ -13,11 +13,11 @@
using LlvmLibcFmaTest = FmaTestTemplate<double>;
TEST_F(LlvmLibcFmaTest, SpecialNumbers) {
testSpecialNumbers(&__llvm_libc::fma);
test_special_numbers(&__llvm_libc::fma);
}
TEST_F(LlvmLibcFmaTest, SubnormalRange) {
testSubnormalRange(&__llvm_libc::fma);
test_subnormal_range(&__llvm_libc::fma);
}
TEST_F(LlvmLibcFmaTest, NormalRange) { testNormalRange(&__llvm_libc::fma); }
TEST_F(LlvmLibcFmaTest, NormalRange) { test_normal_range(&__llvm_libc::fma); }

View File

@ -13,11 +13,11 @@
using LlvmLibcFmaTest = FmaTestTemplate<float>;
TEST_F(LlvmLibcFmaTest, SpecialNumbers) {
testSpecialNumbers(&__llvm_libc::fmaf);
test_special_numbers(&__llvm_libc::fmaf);
}
TEST_F(LlvmLibcFmaTest, SubnormalRange) {
testSubnormalRange(&__llvm_libc::fmaf);
test_subnormal_range(&__llvm_libc::fmaf);
}
TEST_F(LlvmLibcFmaTest, NormalRange) { testNormalRange(&__llvm_libc::fmaf); }
TEST_F(LlvmLibcFmaTest, NormalRange) { test_normal_range(&__llvm_libc::fmaf); }

View File

@ -13,11 +13,13 @@
using LlvmLibcHypotTest = HypotTestTemplate<double>;
TEST_F(LlvmLibcHypotTest, SpecialNumbers) {
testSpecialNumbers(&__llvm_libc::hypot);
test_special_numbers(&__llvm_libc::hypot);
}
TEST_F(LlvmLibcHypotTest, SubnormalRange) {
testSubnormalRange(&__llvm_libc::hypot);
test_subnormal_range(&__llvm_libc::hypot);
}
TEST_F(LlvmLibcHypotTest, NormalRange) { testNormalRange(&__llvm_libc::hypot); }
TEST_F(LlvmLibcHypotTest, NormalRange) {
test_normal_range(&__llvm_libc::hypot);
}

View File

@ -13,13 +13,13 @@
using LlvmLibcHypotfTest = HypotTestTemplate<float>;
TEST_F(LlvmLibcHypotfTest, SpecialNumbers) {
testSpecialNumbers(&__llvm_libc::hypotf);
test_special_numbers(&__llvm_libc::hypotf);
}
TEST_F(LlvmLibcHypotfTest, SubnormalRange) {
testSubnormalRange(&__llvm_libc::hypotf);
test_subnormal_range(&__llvm_libc::hypotf);
}
TEST_F(LlvmLibcHypotfTest, NormalRange) {
testNormalRange(&__llvm_libc::hypotf);
test_normal_range(&__llvm_libc::hypotf);
}

View File

@ -16,21 +16,21 @@
#include <math.h>
TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogb) {
testSpecialNumbers<double>(&__llvm_libc::ilogb);
test_special_numbers<double>(&__llvm_libc::ilogb);
}
TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogb) {
testPowersOfTwo<double>(&__llvm_libc::ilogb);
test_powers_of_two<double>(&__llvm_libc::ilogb);
}
TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogb) {
testSomeIntegers<double>(&__llvm_libc::ilogb);
test_some_integers<double>(&__llvm_libc::ilogb);
}
TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogb) {
testSubnormalRange<double>(&__llvm_libc::ilogb);
test_subnormal_range<double>(&__llvm_libc::ilogb);
}
TEST_F(LlvmLibcILogbTest, NormalRange_ilogb) {
testNormalRange<double>(&__llvm_libc::ilogb);
test_normal_range<double>(&__llvm_libc::ilogb);
}

View File

@ -16,21 +16,21 @@
#include <math.h>
TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogbf) {
testSpecialNumbers<float>(&__llvm_libc::ilogbf);
test_special_numbers<float>(&__llvm_libc::ilogbf);
}
TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogbf) {
testPowersOfTwo<float>(&__llvm_libc::ilogbf);
test_powers_of_two<float>(&__llvm_libc::ilogbf);
}
TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogbf) {
testSomeIntegers<float>(&__llvm_libc::ilogbf);
test_some_integers<float>(&__llvm_libc::ilogbf);
}
TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogbf) {
testSubnormalRange<float>(&__llvm_libc::ilogbf);
test_subnormal_range<float>(&__llvm_libc::ilogbf);
}
TEST_F(LlvmLibcILogbTest, NormalRange_ilogbf) {
testNormalRange<float>(&__llvm_libc::ilogbf);
test_normal_range<float>(&__llvm_libc::ilogbf);
}

View File

@ -18,21 +18,21 @@
using RunContext = __llvm_libc::testing::RunContext;
TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogbl) {
testSpecialNumbers<long double>(&__llvm_libc::ilogbl);
test_special_numbers<long double>(&__llvm_libc::ilogbl);
}
TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogbl) {
testPowersOfTwo<long double>(&__llvm_libc::ilogbl);
test_powers_of_two<long double>(&__llvm_libc::ilogbl);
}
TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogbl) {
testSomeIntegers<long double>(&__llvm_libc::ilogbl);
test_some_integers<long double>(&__llvm_libc::ilogbl);
}
TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogbl) {
testSubnormalRange<long double>(&__llvm_libc::ilogbl);
test_subnormal_range<long double>(&__llvm_libc::ilogbl);
}
TEST_F(LlvmLibcILogbTest, NormalRange_ilogbl) {
testNormalRange<long double>(&__llvm_libc::ilogbl);
test_normal_range<long double>(&__llvm_libc::ilogbl);
}

View File

@ -45,9 +45,9 @@ TEST(LlvmLibcLogfTest, TrickyInputs) {
}
TEST(LlvmLibcLogfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
constexpr uint32_t COUNT = 1000000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;

View File

@ -16,7 +16,7 @@
namespace __llvm_libc {
namespace testing {
static constexpr __llvm_libc::cpp::Array<uint32_t, 10> sdcomp26094Values{
static constexpr __llvm_libc::cpp::Array<uint32_t, 10> SDCOMP26094_VALUES{
0x46427f1b, 0x4647e568, 0x46428bac, 0x4647f1f9, 0x4647fe8a,
0x45d8d7f1, 0x45d371a4, 0x45ce0b57, 0x45d35882, 0x45cdf235,
};

View File

@ -20,9 +20,9 @@ DECLARE_SPECIAL_CONSTANTS(double)
TEST(LlvmLibcSinTest, Range) {
static constexpr double _2pi = 6.283185307179586;
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
double x = double(FPBits(v));
// TODO: Expand the range of testing after range reduction is implemented.
if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)

View File

@ -18,7 +18,7 @@
#include <errno.h>
#include <stdint.h>
using __llvm_libc::testing::sdcomp26094Values;
using __llvm_libc::testing::SDCOMP26094_VALUES;
using FPBits = __llvm_libc::fputil::FPBits<float>;
namespace mpfr = __llvm_libc::testing::mpfr;
@ -58,9 +58,9 @@ TEST(LlvmLibcSinCosfTest, SpecialNumbers) {
}
TEST(LlvmLibcSinCosfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
constexpr uint32_t COUNT = 1000000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits((v)));
if (isnan(x) || isinf(x))
continue;
@ -95,7 +95,7 @@ TEST(LlvmLibcSinCosfTest, SmallValues) {
// SDCOMP-26094: check sinf in the cases for which the range reducer
// returns values furthest beyond its nominal upper bound of pi/4.
TEST(LlvmLibcSinCosfTest, SDCOMP_26094) {
for (uint32_t v : sdcomp26094Values) {
for (uint32_t v : SDCOMP26094_VALUES) {
float x = float(FPBits((v)));
float sin, cos;
__llvm_libc::sincosf(x, &sin, &cos);

View File

@ -18,7 +18,7 @@
#include <errno.h>
#include <stdint.h>
using __llvm_libc::testing::sdcomp26094Values;
using __llvm_libc::testing::SDCOMP26094_VALUES;
using FPBits = __llvm_libc::fputil::FPBits<float>;
namespace mpfr = __llvm_libc::testing::mpfr;
@ -47,9 +47,9 @@ TEST(LlvmLibcSinfTest, SpecialNumbers) {
}
TEST(LlvmLibcSinfTest, InFloatRange) {
constexpr uint32_t count = 1000000;
constexpr uint32_t step = UINT32_MAX / count;
for (uint32_t i = 0, v = 0; i <= count; ++i, v += step) {
constexpr uint32_t COUNT = 1000000;
constexpr uint32_t STEP = UINT32_MAX / COUNT;
for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
float x = float(FPBits(v));
if (isnan(x) || isinf(x))
continue;
@ -78,7 +78,7 @@ TEST(LlvmLibcSinfTest, SmallValues) {
// SDCOMP-26094: check sinf in the cases for which the range reducer
// returns values furthest beyond its nominal upper bound of pi/4.
TEST(LlvmLibcSinfTest, SDCOMP_26094) {
for (uint32_t v : sdcomp26094Values) {
for (uint32_t v : SDCOMP26094_VALUES) {
float x = float(FPBits((v)));
EXPECT_MPFR_MATCH(mpfr::Operation::Sin, x, __llvm_libc::sinf(x), 1.0);
}

View File

@ -19,9 +19,9 @@ DECLARE_SPECIAL_CONSTANTS(double)
TEST(LlvmLibctanTest, Range) {
static constexpr double _2pi = 6.283185307179586;
constexpr UIntType count = 10000000;
constexpr UIntType step = UIntType(-1) / count;
for (UIntType i = 0, v = 0; i <= count; ++i, v += step) {
constexpr UIntType COUNT = 10000000;
constexpr UIntType STEP = UIntType(-1) / COUNT;
for (UIntType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
double x = double(FPBits(v));
// TODO: Expand the range of testing after range reduction is implemented.
if (isnan(x) || isinf(x) || x > _2pi || x < -_2pi)

View File

@ -21,9 +21,9 @@ class LlvmLibcSignalTest : public __llvm_libc::testing::Test {
sigset_t oldSet;
public:
void SetUp() override { __llvm_libc::sigprocmask(0, nullptr, &oldSet); }
void set_up() override { __llvm_libc::sigprocmask(0, nullptr, &oldSet); }
void TearDown() override {
void tear_down() override {
__llvm_libc::sigprocmask(SIG_SETMASK, &oldSet, nullptr);
}
};

View File

@ -18,35 +18,35 @@
// This is just a simple test to make sure that this function works at all. It's
// functionally identical to strtod so the bulk of the testing is there.
TEST(LlvmLibcAToFTest, SimpleTest) {
__llvm_libc::fputil::FPBits<double> expectedFP =
__llvm_libc::fputil::FPBits<double> expected_fp =
__llvm_libc::fputil::FPBits<double>(uint64_t(0x405ec00000000000));
errno = 0;
double result = __llvm_libc::atof("123");
__llvm_libc::fputil::FPBits<double> actualFP =
__llvm_libc::fputil::FPBits<double> actual_fp =
__llvm_libc::fputil::FPBits<double>(result);
EXPECT_EQ(actualFP.bits, expectedFP.bits);
EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign());
EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent());
EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa());
EXPECT_EQ(actual_fp.bits, expected_fp.bits);
EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
EXPECT_EQ(errno, 0);
}
TEST(LlvmLibcAToFTest, FailedParsingTest) {
__llvm_libc::fputil::FPBits<double> expectedFP =
__llvm_libc::fputil::FPBits<double> expected_fp =
__llvm_libc::fputil::FPBits<double>(uint64_t(0));
errno = 0;
double result = __llvm_libc::atof("???");
__llvm_libc::fputil::FPBits<double> actualFP =
__llvm_libc::fputil::FPBits<double> actual_fp =
__llvm_libc::fputil::FPBits<double>(result);
EXPECT_EQ(actualFP.bits, expectedFP.bits);
EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign());
EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent());
EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa());
EXPECT_EQ(actual_fp.bits, expected_fp.bits);
EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
EXPECT_EQ(errno, 0);
}

View File

@ -35,44 +35,44 @@ TEST(LlvmLibcBsearchTest, ErrorInputs) {
}
TEST(LlvmLibcBsearchTest, IntegerArray) {
constexpr int array[25] = {10, 23, 33, 35, 55, 70, 71,
constexpr int ARRAY[25] = {10, 23, 33, 35, 55, 70, 71,
100, 110, 123, 133, 135, 155, 170,
171, 1100, 1110, 1123, 1133, 1135, 1155,
1170, 1171, 11100, 12310};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(ARRAY) / sizeof(int);
for (size_t s = 1; s <= array_size; ++s) {
for (size_t s = 1; s <= ARRAY_SIZE; ++s) {
for (size_t i = 0; i < s; ++i) {
int key = array[i];
int key = ARRAY[i];
void *elem =
__llvm_libc::bsearch(&key, array, s, sizeof(int), int_compare);
__llvm_libc::bsearch(&key, ARRAY, s, sizeof(int), int_compare);
ASSERT_EQ(*reinterpret_cast<int *>(elem), key);
}
}
// Non existent keys
for (size_t s = 1; s <= array_size; ++s) {
for (size_t s = 1; s <= ARRAY_SIZE; ++s) {
int key = 5;
ASSERT_TRUE(__llvm_libc::bsearch(&key, &array, s, sizeof(int),
ASSERT_TRUE(__llvm_libc::bsearch(&key, &ARRAY, s, sizeof(int),
int_compare) == nullptr);
key = 125;
ASSERT_TRUE(__llvm_libc::bsearch(&key, &array, s, sizeof(int),
ASSERT_TRUE(__llvm_libc::bsearch(&key, &ARRAY, s, sizeof(int),
int_compare) == nullptr);
key = 136;
ASSERT_TRUE(__llvm_libc::bsearch(&key, &array, s, sizeof(int),
ASSERT_TRUE(__llvm_libc::bsearch(&key, &ARRAY, s, sizeof(int),
int_compare) == nullptr);
key = 12345;
ASSERT_TRUE(__llvm_libc::bsearch(&key, &array, s, sizeof(int),
ASSERT_TRUE(__llvm_libc::bsearch(&key, &ARRAY, s, sizeof(int),
int_compare) == nullptr);
}
}
TEST(LlvmLibcBsearchTest, SameKeyAndArray) {
constexpr int array[5] = {1, 2, 3, 4, 5};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr int ARRAY[5] = {1, 2, 3, 4, 5};
constexpr size_t ARRAY_SIZE = sizeof(ARRAY) / sizeof(int);
void *elem =
__llvm_libc::bsearch(array, array, array_size, sizeof(int), int_compare);
EXPECT_EQ(*reinterpret_cast<int *>(elem), array[0]);
__llvm_libc::bsearch(ARRAY, ARRAY, ARRAY_SIZE, sizeof(int), int_compare);
EXPECT_EQ(*reinterpret_cast<int *>(elem), ARRAY[0]);
}

View File

@ -27,9 +27,9 @@ TEST(LlvmLibcQsortTest, SortedArray) {
int array[25] = {10, 23, 33, 35, 55, 70, 71, 100, 110,
123, 133, 135, 155, 170, 171, 1100, 1110, 1123,
1133, 1135, 1155, 1170, 1171, 11100, 12310};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 10);
ASSERT_LE(array[1], 23);
@ -61,11 +61,11 @@ TEST(LlvmLibcQsortTest, SortedArray) {
TEST(LlvmLibcQsortTest, ReverseSortedArray) {
int array[25] = {25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
for (int i = 0; i < int(array_size - 1); ++i)
for (int i = 0; i < int(ARRAY_SIZE - 1); ++i)
ASSERT_LE(array[i], i + 1);
}
@ -73,20 +73,20 @@ TEST(LlvmLibcQsortTest, AllEqualElements) {
int array[25] = {100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
for (size_t i = 0; i < array_size - 1; ++i)
for (size_t i = 0; i < ARRAY_SIZE - 1; ++i)
ASSERT_LE(array[i], 100);
}
TEST(LlvmLibcQsortTest, UnsortedArray1) {
int array[25] = {10, 23, 8, 35, 55, 45, 40, 100, 110, 123, 90, 80, 70,
60, 171, 11, 1, -1, -5, -10, 1155, 1170, 1171, 12, -100};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], -100);
ASSERT_LE(array[1], -10);
@ -117,9 +117,9 @@ TEST(LlvmLibcQsortTest, UnsortedArray1) {
TEST(LlvmLibcQsortTest, UnsortedArray2) {
int array[7] = {10, 40, 45, 55, 35, 23, 60};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 10);
ASSERT_LE(array[1], 23);
@ -132,9 +132,9 @@ TEST(LlvmLibcQsortTest, UnsortedArray2) {
TEST(LlvmLibcQsortTest, UnsortedArrayDuplicateElements1) {
int array[6] = {10, 10, 20, 20, 5, 5};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 5);
ASSERT_LE(array[1], 5);
@ -146,9 +146,9 @@ TEST(LlvmLibcQsortTest, UnsortedArrayDuplicateElements1) {
TEST(LlvmLibcQsortTest, UnsortedArrayDuplicateElements2) {
int array[10] = {20, 10, 10, 10, 10, 20, 21, 21, 21, 21};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 10);
ASSERT_LE(array[1], 10);
@ -164,9 +164,9 @@ TEST(LlvmLibcQsortTest, UnsortedArrayDuplicateElements2) {
TEST(LlvmLibcQsortTest, UnsortedArrayDuplicateElements3) {
int array[10] = {20, 30, 30, 30, 30, 20, 21, 21, 21, 21};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 20);
ASSERT_LE(array[1], 20);
@ -182,9 +182,9 @@ TEST(LlvmLibcQsortTest, UnsortedArrayDuplicateElements3) {
TEST(LlvmLibcQsortTest, UnsortedThreeElementArray1) {
int array[3] = {14999024, 0, 3};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 0);
ASSERT_LE(array[1], 3);
@ -193,9 +193,9 @@ TEST(LlvmLibcQsortTest, UnsortedThreeElementArray1) {
TEST(LlvmLibcQsortTest, UnsortedThreeElementArray2) {
int array[3] = {3, 14999024, 0};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 0);
ASSERT_LE(array[1], 3);
@ -204,9 +204,9 @@ TEST(LlvmLibcQsortTest, UnsortedThreeElementArray2) {
TEST(LlvmLibcQsortTest, UnsortedThreeElementArray3) {
int array[3] = {3, 0, 14999024};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 0);
ASSERT_LE(array[1], 3);
@ -215,9 +215,9 @@ TEST(LlvmLibcQsortTest, UnsortedThreeElementArray3) {
TEST(LlvmLibcQsortTest, SameElementThreeElementArray) {
int array[3] = {12345, 12345, 12345};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 12345);
ASSERT_LE(array[1], 12345);
@ -226,9 +226,9 @@ TEST(LlvmLibcQsortTest, SameElementThreeElementArray) {
TEST(LlvmLibcQsortTest, UnsortedTwoElementArray1) {
int array[2] = {14999024, 0};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 0);
ASSERT_LE(array[1], 14999024);
@ -236,9 +236,9 @@ TEST(LlvmLibcQsortTest, UnsortedTwoElementArray1) {
TEST(LlvmLibcQsortTest, UnsortedTwoElementArray2) {
int array[2] = {0, 14999024};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 0);
ASSERT_LE(array[1], 14999024);
@ -246,20 +246,20 @@ TEST(LlvmLibcQsortTest, UnsortedTwoElementArray2) {
TEST(LlvmLibcQsortTest, SameElementTwoElementArray) {
int array[2] = {12345, 12345};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], 12345);
ASSERT_LE(array[1], 12345);
}
TEST(LlvmLibcQSortTest, SingleElementArray) {
constexpr int elem = 12345;
int array[1] = {elem};
constexpr size_t array_size = sizeof(array) / sizeof(int);
constexpr int ELEM = 12345;
int array[1] = {ELEM};
constexpr size_t ARRAY_SIZE = sizeof(array) / sizeof(int);
__llvm_libc::qsort(array, array_size, sizeof(int), int_compare);
__llvm_libc::qsort(array, ARRAY_SIZE, sizeof(int), int_compare);
ASSERT_LE(array[0], elem);
ASSERT_LE(array[0], ELEM);
}

View File

@ -17,8 +17,8 @@
class LlvmLibcStrToDTest : public __llvm_libc::testing::Test {
public:
void runTest(const char *inputString, const ptrdiff_t expectedStrLen,
const uint64_t expectedRawData, const int expectedErrno = 0) {
void run_test(const char *inputString, const ptrdiff_t expectedStrLen,
const uint64_t expectedRawData, const int expectedErrno = 0) {
// expectedRawData is the expected double result as a uint64_t, organized
// according to IEEE754:
//
@ -33,58 +33,59 @@ public:
// +-- 11 Exponent Bits
//
// This is so that the result can be compared in parts.
char *strEnd = nullptr;
char *str_end = nullptr;
__llvm_libc::fputil::FPBits<double> expectedFP =
__llvm_libc::fputil::FPBits<double> expected_fp =
__llvm_libc::fputil::FPBits<double>(expectedRawData);
errno = 0;
double result = __llvm_libc::strtod(inputString, &strEnd);
double result = __llvm_libc::strtod(inputString, &str_end);
__llvm_libc::fputil::FPBits<double> actualFP =
__llvm_libc::fputil::FPBits<double> actual_fp =
__llvm_libc::fputil::FPBits<double>(result);
EXPECT_EQ(strEnd - inputString, expectedStrLen);
EXPECT_EQ(str_end - inputString, expectedStrLen);
EXPECT_EQ(actualFP.bits, expectedFP.bits);
EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign());
EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent());
EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa());
EXPECT_EQ(actual_fp.bits, expected_fp.bits);
EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
EXPECT_EQ(errno, expectedErrno);
}
};
TEST_F(LlvmLibcStrToDTest, SimpleTest) {
runTest("123", 3, uint64_t(0x405ec00000000000));
run_test("123", 3, uint64_t(0x405ec00000000000));
// This should fail on Eisel-Lemire, forcing a fallback to simple decimal
// conversion.
runTest("12345678901234549760", 20, uint64_t(0x43e56a95319d63d8));
run_test("12345678901234549760", 20, uint64_t(0x43e56a95319d63d8));
// Found while looking for difficult test cases here:
// https://github.com/nigeltao/parse-number-fxx-test-data/blob/main/more-test-cases/golang-org-issue-36657.txt
runTest("1090544144181609348835077142190", 31, uint64_t(0x462b8779f2474dfb));
run_test("1090544144181609348835077142190", 31, uint64_t(0x462b8779f2474dfb));
runTest("0x123", 5, uint64_t(0x4072300000000000));
run_test("0x123", 5, uint64_t(0x4072300000000000));
}
// These are tests that have caused problems in the past.
TEST_F(LlvmLibcStrToDTest, SpecificFailures) {
runTest("3E70000000000000", 16, uint64_t(0x7FF0000000000000), ERANGE);
runTest("358416272e-33", 13, uint64_t(0x3adbbb2a68c9d0b9));
runTest("2.16656806400000023841857910156251e9", 36,
uint64_t(0x41e0246690000001));
runTest("27949676547093071875", 20, uint64_t(0x43f83e132bc608c9));
run_test("3E70000000000000", 16, uint64_t(0x7FF0000000000000), ERANGE);
run_test("358416272e-33", 13, uint64_t(0x3adbbb2a68c9d0b9));
run_test("2.16656806400000023841857910156251e9", 36,
uint64_t(0x41e0246690000001));
run_test("27949676547093071875", 20, uint64_t(0x43f83e132bc608c9));
}
TEST_F(LlvmLibcStrToDTest, FuzzFailures) {
runTest("-\xff\xff\xff\xff\xff\xff\xff\x01", 0, uint64_t(0));
runTest("-.????", 0, uint64_t(0));
runTest("44444444444444444444444444444444444444444444444444A44444444444444444"
"44444444444*\x99\xff\xff\xff\xff",
50, uint64_t(0x4a3e68fdd0e0b2d8));
runTest("-NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNKNNNNNNNNNNNNNNNNNN?"
"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN?",
0, uint64_t(0));
runTest("0x.666E40", 9, uint64_t(0x3fd99b9000000000));
run_test("-\xff\xff\xff\xff\xff\xff\xff\x01", 0, uint64_t(0));
run_test("-.????", 0, uint64_t(0));
run_test(
"44444444444444444444444444444444444444444444444444A44444444444444444"
"44444444444*\x99\xff\xff\xff\xff",
50, uint64_t(0x4a3e68fdd0e0b2d8));
run_test("-NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNKNNNNNNNNNNNNNNNNNN?"
"NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN?",
0, uint64_t(0));
run_test("0x.666E40", 9, uint64_t(0x3fd99b9000000000));
}

View File

@ -17,8 +17,8 @@
class LlvmLibcStrToFTest : public __llvm_libc::testing::Test {
public:
void runTest(const char *inputString, const ptrdiff_t expectedStrLen,
const uint32_t expectedRawData, const int expectedErrno = 0) {
void run_test(const char *inputString, const ptrdiff_t expectedStrLen,
const uint32_t expectedRawData, const int expectedErrno = 0) {
// expectedRawData is the expected float result as a uint32_t, organized
// according to IEEE754:
//
@ -33,23 +33,23 @@ public:
// +-- 8 Exponent Bits
//
// This is so that the result can be compared in parts.
char *strEnd = nullptr;
char *str_end = nullptr;
__llvm_libc::fputil::FPBits<float> expectedFP =
__llvm_libc::fputil::FPBits<float> expected_fp =
__llvm_libc::fputil::FPBits<float>(expectedRawData);
errno = 0;
float result = __llvm_libc::strtof(inputString, &strEnd);
float result = __llvm_libc::strtof(inputString, &str_end);
__llvm_libc::fputil::FPBits<float> actualFP =
__llvm_libc::fputil::FPBits<float> actual_fp =
__llvm_libc::fputil::FPBits<float>(result);
EXPECT_EQ(strEnd - inputString, expectedStrLen);
EXPECT_EQ(str_end - inputString, expectedStrLen);
EXPECT_EQ(actualFP.bits, expectedFP.bits);
EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign());
EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent());
EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa());
EXPECT_EQ(actual_fp.bits, expected_fp.bits);
EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
EXPECT_EQ(errno, expectedErrno);
}
};
@ -59,115 +59,117 @@ public:
// them.
TEST_F(LlvmLibcStrToFTest, BasicDecimalTests) {
runTest("1", 1, 0x3f800000);
runTest("123", 3, 0x42f60000);
runTest("1234567890", 10, 0x4e932c06u);
runTest("123456789012345678901", 21, 0x60d629d4);
runTest("0.1", 3, 0x3dcccccdu);
runTest(".1", 2, 0x3dcccccdu);
runTest("-0.123456789", 12, 0xbdfcd6eau);
runTest("0.11111111111111111111", 22, 0x3de38e39u);
runTest("0.0000000000000000000000001", 27, 0x15f79688u);
run_test("1", 1, 0x3f800000);
run_test("123", 3, 0x42f60000);
run_test("1234567890", 10, 0x4e932c06u);
run_test("123456789012345678901", 21, 0x60d629d4);
run_test("0.1", 3, 0x3dcccccdu);
run_test(".1", 2, 0x3dcccccdu);
run_test("-0.123456789", 12, 0xbdfcd6eau);
run_test("0.11111111111111111111", 22, 0x3de38e39u);
run_test("0.0000000000000000000000001", 27, 0x15f79688u);
}
TEST_F(LlvmLibcStrToFTest, DecimalOutOfRangeTests) {
runTest("555E36", 6, 0x7f800000, ERANGE);
runTest("1e-10000", 8, 0x0, ERANGE);
run_test("555E36", 6, 0x7f800000, ERANGE);
run_test("1e-10000", 8, 0x0, ERANGE);
}
TEST_F(LlvmLibcStrToFTest, DecimalsWithRoundingProblems) {
runTest("20040229", 8, 0x4b98e512);
runTest("20040401", 8, 0x4b98e568);
runTest("9E9", 3, 0x50061c46);
run_test("20040229", 8, 0x4b98e512);
run_test("20040401", 8, 0x4b98e568);
run_test("9E9", 3, 0x50061c46);
}
TEST_F(LlvmLibcStrToFTest, DecimalSubnormals) {
runTest("1.4012984643248170709237295832899161312802619418765e-45", 55, 0x1,
ERANGE);
run_test("1.4012984643248170709237295832899161312802619418765e-45", 55, 0x1,
ERANGE);
}
TEST_F(LlvmLibcStrToFTest, DecimalWithLongExponent) {
runTest("1e2147483648", 12, 0x7f800000, ERANGE);
runTest("1e2147483646", 12, 0x7f800000, ERANGE);
runTest("100e2147483646", 14, 0x7f800000, ERANGE);
runTest("1e-2147483647", 13, 0x0, ERANGE);
runTest("1e-2147483649", 13, 0x0, ERANGE);
run_test("1e2147483648", 12, 0x7f800000, ERANGE);
run_test("1e2147483646", 12, 0x7f800000, ERANGE);
run_test("100e2147483646", 14, 0x7f800000, ERANGE);
run_test("1e-2147483647", 13, 0x0, ERANGE);
run_test("1e-2147483649", 13, 0x0, ERANGE);
}
TEST_F(LlvmLibcStrToFTest, BasicHexadecimalTests) {
runTest("0x1", 3, 0x3f800000);
runTest("0x10", 4, 0x41800000);
runTest("0x11", 4, 0x41880000);
runTest("0x0.1234", 8, 0x3d91a000);
run_test("0x1", 3, 0x3f800000);
run_test("0x10", 4, 0x41800000);
run_test("0x11", 4, 0x41880000);
run_test("0x0.1234", 8, 0x3d91a000);
}
TEST_F(LlvmLibcStrToFTest, HexadecimalSubnormalTests) {
runTest("0x0.0000000000000000000000000000000002", 38, 0x4000, ERANGE);
run_test("0x0.0000000000000000000000000000000002", 38, 0x4000, ERANGE);
// This is the largest subnormal number as represented in hex
runTest("0x0.00000000000000000000000000000003fffff8", 42, 0x7fffff, ERANGE);
run_test("0x0.00000000000000000000000000000003fffff8", 42, 0x7fffff, ERANGE);
}
TEST_F(LlvmLibcStrToFTest, HexadecimalSubnormalRoundingTests) {
// This is the largest subnormal number that gets rounded down to 0 (as a
// float)
runTest("0x0.00000000000000000000000000000000000004", 42, 0x0, ERANGE);
run_test("0x0.00000000000000000000000000000000000004", 42, 0x0, ERANGE);
// This is slightly larger, and thus rounded up
runTest("0x0.000000000000000000000000000000000000041", 43, 0x00000001,
ERANGE);
run_test("0x0.000000000000000000000000000000000000041", 43, 0x00000001,
ERANGE);
// These check that we're rounding to even properly
runTest("0x0.0000000000000000000000000000000000000b", 42, 0x00000001, ERANGE);
runTest("0x0.0000000000000000000000000000000000000c", 42, 0x00000002, ERANGE);
run_test("0x0.0000000000000000000000000000000000000b", 42, 0x00000001,
ERANGE);
run_test("0x0.0000000000000000000000000000000000000c", 42, 0x00000002,
ERANGE);
// These check that we're rounding to even properly even when the input bits
// are longer than the bit fields can contain.
runTest("0x1.000000000000000000000p-150", 30, 0x00000000, ERANGE);
runTest("0x1.000010000000000001000p-150", 30, 0x00000001, ERANGE);
runTest("0x1.000100000000000001000p-134", 30, 0x00008001, ERANGE);
runTest("0x1.FFFFFC000000000001000p-127", 30, 0x007FFFFF, ERANGE);
runTest("0x1.FFFFFE000000000000000p-127", 30, 0x00800000);
run_test("0x1.000000000000000000000p-150", 30, 0x00000000, ERANGE);
run_test("0x1.000010000000000001000p-150", 30, 0x00000001, ERANGE);
run_test("0x1.000100000000000001000p-134", 30, 0x00008001, ERANGE);
run_test("0x1.FFFFFC000000000001000p-127", 30, 0x007FFFFF, ERANGE);
run_test("0x1.FFFFFE000000000000000p-127", 30, 0x00800000);
}
TEST_F(LlvmLibcStrToFTest, HexadecimalNormalRoundingTests) {
// This also checks the round to even behavior by checking three adjacent
// numbers.
// This gets rounded down to even
runTest("0x123456500", 11, 0x4f91a2b2);
run_test("0x123456500", 11, 0x4f91a2b2);
// This doesn't get rounded at all
runTest("0x123456600", 11, 0x4f91a2b3);
run_test("0x123456600", 11, 0x4f91a2b3);
// This gets rounded up to even
runTest("0x123456700", 11, 0x4f91a2b4);
run_test("0x123456700", 11, 0x4f91a2b4);
// Correct rounding for long input
runTest("0x1.000001000000000000000", 25, 0x3f800000);
runTest("0x1.000001000000000000100", 25, 0x3f800001);
run_test("0x1.000001000000000000000", 25, 0x3f800000);
run_test("0x1.000001000000000000100", 25, 0x3f800001);
}
TEST_F(LlvmLibcStrToFTest, HexadecimalsWithRoundingProblems) {
runTest("0xFFFFFFFF", 10, 0x4f800000);
run_test("0xFFFFFFFF", 10, 0x4f800000);
}
TEST_F(LlvmLibcStrToFTest, HexadecimalOutOfRangeTests) {
runTest("0x123456789123456789123456789123456789", 38, 0x7f800000, ERANGE);
runTest("-0x123456789123456789123456789123456789", 39, 0xff800000, ERANGE);
runTest("0x0.00000000000000000000000000000000000001", 42, 0x0, ERANGE);
run_test("0x123456789123456789123456789123456789", 38, 0x7f800000, ERANGE);
run_test("-0x123456789123456789123456789123456789", 39, 0xff800000, ERANGE);
run_test("0x0.00000000000000000000000000000000000001", 42, 0x0, ERANGE);
}
TEST_F(LlvmLibcStrToFTest, InfTests) {
runTest("INF", 3, 0x7f800000);
runTest("INFinity", 8, 0x7f800000);
runTest("infnity", 3, 0x7f800000);
runTest("infinit", 3, 0x7f800000);
runTest("infinfinit", 3, 0x7f800000);
runTest("innf", 0, 0x0);
runTest("-inf", 4, 0xff800000);
runTest("-iNfInItY", 9, 0xff800000);
run_test("INF", 3, 0x7f800000);
run_test("INFinity", 8, 0x7f800000);
run_test("infnity", 3, 0x7f800000);
run_test("infinit", 3, 0x7f800000);
run_test("infinfinit", 3, 0x7f800000);
run_test("innf", 0, 0x0);
run_test("-inf", 4, 0xff800000);
run_test("-iNfInItY", 9, 0xff800000);
}
TEST_F(LlvmLibcStrToFTest, SimpleNaNTests) {
runTest("NaN", 3, 0x7fc00000);
runTest("-nAn", 4, 0xffc00000);
run_test("NaN", 3, 0x7fc00000);
run_test("-nAn", 4, 0xffc00000);
}
// These NaNs are of the form `NaN(n-character-sequence)` where the
@ -178,26 +180,26 @@ TEST_F(LlvmLibcStrToFTest, SimpleNaNTests) {
// the result is put into the mantissa if it takes up the whole width of the
// parentheses.
TEST_F(LlvmLibcStrToFTest, NaNWithParenthesesEmptyTest) {
runTest("NaN()", 5, 0x7fc00000);
run_test("NaN()", 5, 0x7fc00000);
}
TEST_F(LlvmLibcStrToFTest, NaNWithParenthesesValidNumberTests) {
runTest("NaN(1234)", 9, 0x7fc004d2);
runTest("NaN(0x1234)", 11, 0x7fc01234);
runTest("NaN(01234)", 10, 0x7fc0029c);
run_test("NaN(1234)", 9, 0x7fc004d2);
run_test("NaN(0x1234)", 11, 0x7fc01234);
run_test("NaN(01234)", 10, 0x7fc0029c);
}
TEST_F(LlvmLibcStrToFTest, NaNWithParenthesesInvalidSequenceTests) {
runTest("NaN( 1234)", 3, 0x7fc00000);
runTest("NaN(-1234)", 3, 0x7fc00000);
runTest("NaN(asd&f)", 3, 0x7fc00000);
runTest("NaN(123 )", 3, 0x7fc00000);
runTest("NaN(123+asdf)", 3, 0x7fc00000);
runTest("NaN(123", 3, 0x7fc00000);
run_test("NaN( 1234)", 3, 0x7fc00000);
run_test("NaN(-1234)", 3, 0x7fc00000);
run_test("NaN(asd&f)", 3, 0x7fc00000);
run_test("NaN(123 )", 3, 0x7fc00000);
run_test("NaN(123+asdf)", 3, 0x7fc00000);
run_test("NaN(123", 3, 0x7fc00000);
}
TEST_F(LlvmLibcStrToFTest, NaNWithParenthesesValidSequenceInvalidNumberTests) {
runTest("NaN(1a)", 7, 0x7fc00000);
runTest("NaN(asdf)", 9, 0x7fc00000);
runTest("NaN(1A1)", 8, 0x7fc00000);
run_test("NaN(1a)", 7, 0x7fc00000);
run_test("NaN(asdf)", 9, 0x7fc00000);
run_test("NaN(1A1)", 8, 0x7fc00000);
}

View File

@ -17,12 +17,12 @@
class LlvmLibcStrToLDTest : public __llvm_libc::testing::Test {
public:
void runTest(const char *inputString, const ptrdiff_t expectedStrLen,
const uint64_t expectedRawData64,
const __uint128_t expectedRawData80,
const __uint128_t expectedRawData128,
const int expectedErrno64 = 0, const int expectedErrno80 = 0,
const int expectedErrno128 = 0) {
void run_test(const char *inputString, const ptrdiff_t expectedStrLen,
const uint64_t expectedRawData64,
const __uint128_t expectedRawData80,
const __uint128_t expectedRawData128,
const int expectedErrno64 = 0, const int expectedErrno80 = 0,
const int expectedErrno128 = 0) {
// expectedRawData64 is the expected long double result as a uint64_t,
// organized according to the IEEE754 double precision format:
//
@ -61,16 +61,16 @@ public:
// +------+------+
// |
// +-- 15 Exponent Bits
char *strEnd = nullptr;
char *str_end = nullptr;
#if defined(LONG_DOUBLE_IS_DOUBLE)
__llvm_libc::fputil::FPBits<long double> expectedFP =
__llvm_libc::fputil::FPBits<long double>(expectedRawData64);
const int expectedErrno = expectedErrno64;
#elif defined(SPECIAL_X86_LONG_DOUBLE)
__llvm_libc::fputil::FPBits<long double> expectedFP =
__llvm_libc::fputil::FPBits<long double> expected_fp =
__llvm_libc::fputil::FPBits<long double>(expectedRawData80);
const int expectedErrno = expectedErrno80;
const int expected_errno = expectedErrno80;
#else
__llvm_libc::fputil::FPBits<long double> expectedFP =
__llvm_libc::fputil::FPBits<long double>(expectedRawData128);
@ -78,144 +78,146 @@ public:
#endif
errno = 0;
long double result = __llvm_libc::strtold(inputString, &strEnd);
long double result = __llvm_libc::strtold(inputString, &str_end);
__llvm_libc::fputil::FPBits<long double> actualFP =
__llvm_libc::fputil::FPBits<long double> actual_fp =
__llvm_libc::fputil::FPBits<long double>();
actualFP = __llvm_libc::fputil::FPBits<long double>(result);
actual_fp = __llvm_libc::fputil::FPBits<long double>(result);
EXPECT_EQ(strEnd - inputString, expectedStrLen);
EXPECT_EQ(str_end - inputString, expectedStrLen);
EXPECT_EQ(actualFP.bits, expectedFP.bits);
EXPECT_EQ(actualFP.get_sign(), expectedFP.get_sign());
EXPECT_EQ(actualFP.get_exponent(), expectedFP.get_exponent());
EXPECT_EQ(actualFP.get_mantissa(), expectedFP.get_mantissa());
EXPECT_EQ(errno, expectedErrno);
EXPECT_EQ(actual_fp.bits, expected_fp.bits);
EXPECT_EQ(actual_fp.get_sign(), expected_fp.get_sign());
EXPECT_EQ(actual_fp.get_exponent(), expected_fp.get_exponent());
EXPECT_EQ(actual_fp.get_mantissa(), expected_fp.get_mantissa());
EXPECT_EQ(errno, expected_errno);
}
};
TEST_F(LlvmLibcStrToLDTest, SimpleTest) {
runTest("123", 3, uint64_t(0x405ec00000000000),
__uint128_t(0x4005f60000) << 40,
__uint128_t(0x4005ec0000000000) << 64);
run_test("123", 3, uint64_t(0x405ec00000000000),
__uint128_t(0x4005f60000) << 40,
__uint128_t(0x4005ec0000000000) << 64);
// This should fail on Eisel-Lemire, forcing a fallback to simple decimal
// conversion.
runTest("12345678901234549760", 20, uint64_t(0x43e56a95319d63d8),
(__uint128_t(0x403eab54a9) << 40) + __uint128_t(0x8ceb1ec400),
(__uint128_t(0x403e56a95319d63d) << 64) +
__uint128_t(0x8800000000000000));
run_test("12345678901234549760", 20, uint64_t(0x43e56a95319d63d8),
(__uint128_t(0x403eab54a9) << 40) + __uint128_t(0x8ceb1ec400),
(__uint128_t(0x403e56a95319d63d) << 64) +
__uint128_t(0x8800000000000000));
// Found while looking for difficult test cases here:
// https://github.com/nigeltao/parse-number-fxx-test-data/blob/main/more-test-cases/golang-org-issue-36657.txt
runTest("1090544144181609348835077142190", 31, uint64_t(0x462b8779f2474dfb),
(__uint128_t(0x4062dc3bcf) << 40) + __uint128_t(0x923a6fd402),
(__uint128_t(0x4062b8779f2474df) << 64) +
__uint128_t(0xa804bfd8c6d5c000));
run_test("1090544144181609348835077142190", 31, uint64_t(0x462b8779f2474dfb),
(__uint128_t(0x4062dc3bcf) << 40) + __uint128_t(0x923a6fd402),
(__uint128_t(0x4062b8779f2474df) << 64) +
__uint128_t(0xa804bfd8c6d5c000));
runTest("0x123", 5, uint64_t(0x4072300000000000),
(__uint128_t(0x4007918000) << 40),
(__uint128_t(0x4007230000000000) << 64));
run_test("0x123", 5, uint64_t(0x4072300000000000),
(__uint128_t(0x4007918000) << 40),
(__uint128_t(0x4007230000000000) << 64));
}
// These are tests that have caused problems for doubles in the past.
TEST_F(LlvmLibcStrToLDTest, Float64SpecificFailures) {
runTest("3E70000000000000", 16, uint64_t(0x7FF0000000000000),
(__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7fff000000000000) << 64), ERANGE, ERANGE, ERANGE);
runTest("358416272e-33", 13, uint64_t(0x3adbbb2a68c9d0b9),
(__uint128_t(0x3fadddd953) << 40) + __uint128_t(0x464e85c400),
(__uint128_t(0x3fadbbb2a68c9d0b) << 64) +
__uint128_t(0x8800e7969e1c5fc8));
runTest(
run_test("3E70000000000000", 16, uint64_t(0x7FF0000000000000),
(__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7fff000000000000) << 64), ERANGE, ERANGE, ERANGE);
run_test("358416272e-33", 13, uint64_t(0x3adbbb2a68c9d0b9),
(__uint128_t(0x3fadddd953) << 40) + __uint128_t(0x464e85c400),
(__uint128_t(0x3fadbbb2a68c9d0b) << 64) +
__uint128_t(0x8800e7969e1c5fc8));
run_test(
"2.16656806400000023841857910156251e9", 36, uint64_t(0x41e0246690000001),
(__uint128_t(0x401e812334) << 40) + __uint128_t(0x8000000400),
(__uint128_t(0x401e024669000000) << 64) + __uint128_t(0x800000000000018));
runTest("27949676547093071875", 20, uint64_t(0x43f83e132bc608c9),
(__uint128_t(0x403fc1f099) << 40) + __uint128_t(0x5e30464402),
(__uint128_t(0x403f83e132bc608c) << 64) +
__uint128_t(0x8803000000000000));
run_test("27949676547093071875", 20, uint64_t(0x43f83e132bc608c9),
(__uint128_t(0x403fc1f099) << 40) + __uint128_t(0x5e30464402),
(__uint128_t(0x403f83e132bc608c) << 64) +
__uint128_t(0x8803000000000000));
}
TEST_F(LlvmLibcStrToLDTest, MaxSizeNumbers) {
runTest("1.1897314953572317650e4932", 26, uint64_t(0x7FF0000000000000),
(__uint128_t(0x7ffeffffff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7ffeffffffffffff) << 64) +
__uint128_t(0xfffd57322e3f8675),
ERANGE, 0, 0);
runTest("1.18973149535723176508e4932", 27, uint64_t(0x7FF0000000000000),
(__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7ffeffffffffffff) << 64) +
__uint128_t(0xffffd2478338036c),
ERANGE, ERANGE, 0);
run_test("1.1897314953572317650e4932", 26, uint64_t(0x7FF0000000000000),
(__uint128_t(0x7ffeffffff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7ffeffffffffffff) << 64) +
__uint128_t(0xfffd57322e3f8675),
ERANGE, 0, 0);
run_test("1.18973149535723176508e4932", 27, uint64_t(0x7FF0000000000000),
(__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7ffeffffffffffff) << 64) +
__uint128_t(0xffffd2478338036c),
ERANGE, ERANGE, 0);
}
// These tests check subnormal behavior for 80 bit and 128 bit floats. They will
// be too small for 64 bit floats.
TEST_F(LlvmLibcStrToLDTest, SubnormalTests) {
runTest("1e-4950", 7, uint64_t(0), (__uint128_t(0x00000000000000000003)),
(__uint128_t(0x000000000000000000057c9647e1a018)), ERANGE, ERANGE,
ERANGE);
runTest("1.89e-4951", 10, uint64_t(0), (__uint128_t(0x00000000000000000001)),
(__uint128_t(0x0000000000000000000109778a006738)), ERANGE, ERANGE,
ERANGE);
runTest("4e-4966", 7, uint64_t(0), (__uint128_t(0)),
(__uint128_t(0x00000000000000000000000000000001)), ERANGE, ERANGE,
ERANGE);
run_test("1e-4950", 7, uint64_t(0), (__uint128_t(0x00000000000000000003)),
(__uint128_t(0x000000000000000000057c9647e1a018)), ERANGE, ERANGE,
ERANGE);
run_test("1.89e-4951", 10, uint64_t(0), (__uint128_t(0x00000000000000000001)),
(__uint128_t(0x0000000000000000000109778a006738)), ERANGE, ERANGE,
ERANGE);
run_test("4e-4966", 7, uint64_t(0), (__uint128_t(0)),
(__uint128_t(0x00000000000000000000000000000001)), ERANGE, ERANGE,
ERANGE);
}
TEST_F(LlvmLibcStrToLDTest, SmallNormalTests) {
runTest("3.37e-4932", 10, uint64_t(0),
(__uint128_t(0x1804cf7) << 40) + __uint128_t(0x908850712),
(__uint128_t(0x10099ee12110a) << 64) + __uint128_t(0xe24b75c0f50dc0c),
ERANGE, 0, 0);
run_test("3.37e-4932", 10, uint64_t(0),
(__uint128_t(0x1804cf7) << 40) + __uint128_t(0x908850712),
(__uint128_t(0x10099ee12110a) << 64) +
__uint128_t(0xe24b75c0f50dc0c),
ERANGE, 0, 0);
}
TEST_F(LlvmLibcStrToLDTest, ComplexHexadecimalTests) {
runTest("0x1p16383", 9, 0x7ff0000000000000, (__uint128_t(0x7ffe800000) << 40),
(__uint128_t(0x7ffe000000000000) << 64));
runTest("0x123456789abcdef", 17, 0x43723456789abcdf,
(__uint128_t(0x403791a2b3) << 40) + __uint128_t(0xc4d5e6f780),
(__uint128_t(0x403723456789abcd) << 64) +
__uint128_t(0xef00000000000000));
runTest("0x123456789abcdef0123456789ABCDEF", 33, 0x7ff0000000000000,
(__uint128_t(0x407791a2b3) << 40) + __uint128_t(0xc4d5e6f781),
(__uint128_t(0x407723456789abcd) << 64) +
__uint128_t(0xef0123456789abce));
run_test("0x1p16383", 9, 0x7ff0000000000000,
(__uint128_t(0x7ffe800000) << 40),
(__uint128_t(0x7ffe000000000000) << 64));
run_test("0x123456789abcdef", 17, 0x43723456789abcdf,
(__uint128_t(0x403791a2b3) << 40) + __uint128_t(0xc4d5e6f780),
(__uint128_t(0x403723456789abcd) << 64) +
__uint128_t(0xef00000000000000));
run_test("0x123456789abcdef0123456789ABCDEF", 33, 0x7ff0000000000000,
(__uint128_t(0x407791a2b3) << 40) + __uint128_t(0xc4d5e6f781),
(__uint128_t(0x407723456789abcd) << 64) +
__uint128_t(0xef0123456789abce));
}
TEST_F(LlvmLibcStrToLDTest, InfTests) {
runTest("INF", 3, 0x7ff0000000000000, (__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7fff000000000000) << 64));
runTest("INFinity", 8, 0x7ff0000000000000, (__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7fff000000000000) << 64));
runTest("-inf", 4, 0xfff0000000000000, (__uint128_t(0xffff800000) << 40),
(__uint128_t(0xffff000000000000) << 64));
run_test("INF", 3, 0x7ff0000000000000, (__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7fff000000000000) << 64));
run_test("INFinity", 8, 0x7ff0000000000000, (__uint128_t(0x7fff800000) << 40),
(__uint128_t(0x7fff000000000000) << 64));
run_test("-inf", 4, 0xfff0000000000000, (__uint128_t(0xffff800000) << 40),
(__uint128_t(0xffff000000000000) << 64));
}
TEST_F(LlvmLibcStrToLDTest, NaNTests) {
runTest("NaN", 3, 0x7ff8000000000000, (__uint128_t(0x7fffc00000) << 40),
(__uint128_t(0x7fff800000000000) << 64));
runTest("-nAn", 4, 0xfff8000000000000, (__uint128_t(0xffffc00000) << 40),
(__uint128_t(0xffff800000000000) << 64));
runTest("NaN()", 5, 0x7ff8000000000000, (__uint128_t(0x7fffc00000) << 40),
(__uint128_t(0x7fff800000000000) << 64));
runTest("NaN(1234)", 9, 0x7ff80000000004d2,
(__uint128_t(0x7fffc00000) << 40) + __uint128_t(0x4d2),
(__uint128_t(0x7fff800000000000) << 64) + __uint128_t(0x4d2));
runTest("NaN(0xffffffffffff)", 19, 0x7ff8ffffffffffff,
(__uint128_t(0x7fffc000ff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7fff800000000000) << 64) +
__uint128_t(0xffffffffffff));
runTest("NaN(0xfffffffffffff)", 20, 0x7fffffffffffffff,
(__uint128_t(0x7fffc00fff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7fff800000000000) << 64) +
__uint128_t(0xfffffffffffff));
runTest("NaN(0xffffffffffffffff)", 23, 0x7fffffffffffffff,
(__uint128_t(0x7fffffffff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7fff800000000000) << 64) +
__uint128_t(0xffffffffffffffff));
runTest("NaN( 1234)", 3, 0x7ff8000000000000,
(__uint128_t(0x7fffc00000) << 40),
(__uint128_t(0x7fff800000000000) << 64));
run_test("NaN", 3, 0x7ff8000000000000, (__uint128_t(0x7fffc00000) << 40),
(__uint128_t(0x7fff800000000000) << 64));
run_test("-nAn", 4, 0xfff8000000000000, (__uint128_t(0xffffc00000) << 40),
(__uint128_t(0xffff800000000000) << 64));
run_test("NaN()", 5, 0x7ff8000000000000, (__uint128_t(0x7fffc00000) << 40),
(__uint128_t(0x7fff800000000000) << 64));
run_test("NaN(1234)", 9, 0x7ff80000000004d2,
(__uint128_t(0x7fffc00000) << 40) + __uint128_t(0x4d2),
(__uint128_t(0x7fff800000000000) << 64) + __uint128_t(0x4d2));
run_test("NaN(0xffffffffffff)", 19, 0x7ff8ffffffffffff,
(__uint128_t(0x7fffc000ff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7fff800000000000) << 64) +
__uint128_t(0xffffffffffff));
run_test("NaN(0xfffffffffffff)", 20, 0x7fffffffffffffff,
(__uint128_t(0x7fffc00fff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7fff800000000000) << 64) +
__uint128_t(0xfffffffffffff));
run_test("NaN(0xffffffffffffffff)", 23, 0x7fffffffffffffff,
(__uint128_t(0x7fffffffff) << 40) + __uint128_t(0xffffffffff),
(__uint128_t(0x7fff800000000000) << 64) +
__uint128_t(0xffffffffffffffff));
run_test("NaN( 1234)", 3, 0x7ff8000000000000,
(__uint128_t(0x7fffc00000) << 40),
(__uint128_t(0x7fff800000000000) << 64));
}

View File

@ -34,25 +34,25 @@ TEST(LlvmLibcBcmpTest, LhsAfterRhsLexically) {
}
TEST(LlvmLibcBcmpTest, Sweep) {
static constexpr size_t kMaxSize = 1024;
char lhs[kMaxSize];
char rhs[kMaxSize];
static constexpr size_t K_MAX_SIZE = 1024;
char lhs[K_MAX_SIZE];
char rhs[K_MAX_SIZE];
const auto reset = [](char *const ptr) {
for (size_t i = 0; i < kMaxSize; ++i)
for (size_t i = 0; i < K_MAX_SIZE; ++i)
ptr[i] = 'a';
};
reset(lhs);
reset(rhs);
for (size_t i = 0; i < kMaxSize; ++i)
for (size_t i = 0; i < K_MAX_SIZE; ++i)
EXPECT_EQ(__llvm_libc::bcmp(lhs, rhs, i), 0);
reset(lhs);
reset(rhs);
for (size_t i = 0; i < kMaxSize; ++i) {
for (size_t i = 0; i < K_MAX_SIZE; ++i) {
rhs[i] = 'b';
EXPECT_NE(__llvm_libc::bcmp(lhs, rhs, kMaxSize), 0);
EXPECT_NE(__llvm_libc::bcmp(lhs, rhs, K_MAX_SIZE), 0);
rhs[i] = 'a';
}
}

View File

@ -14,10 +14,10 @@ using __llvm_libc::cpp::Array;
using __llvm_libc::cpp::ArrayRef;
using Data = Array<char, 2048>;
static const ArrayRef<char> kDeadcode("DEADC0DE", 8);
static const ArrayRef<char> k_deadcode("DEADC0DE", 8);
// Returns a Data object filled with a repetition of `filler`.
Data getData(ArrayRef<char> filler) {
Data get_data(ArrayRef<char> filler) {
Data out;
for (size_t i = 0; i < out.size(); ++i)
out[i] = filler[i % filler.size()];
@ -25,7 +25,7 @@ Data getData(ArrayRef<char> filler) {
}
TEST(LlvmLibcBzeroTest, Thorough) {
const Data dirty = getData(kDeadcode);
const Data dirty = get_data(k_deadcode);
for (size_t count = 0; count < 1024; ++count) {
for (size_t align = 0; align < 64; ++align) {
auto buffer = dirty;

View File

@ -34,25 +34,25 @@ TEST(LlvmLibcMemcmpTest, LhsAfterRhsLexically) {
}
TEST(LlvmLibcMemcmpTest, Sweep) {
static constexpr size_t kMaxSize = 1024;
char lhs[kMaxSize];
char rhs[kMaxSize];
static constexpr size_t K_MAX_SIZE = 1024;
char lhs[K_MAX_SIZE];
char rhs[K_MAX_SIZE];
const auto reset = [](char *const ptr) {
for (size_t i = 0; i < kMaxSize; ++i)
for (size_t i = 0; i < K_MAX_SIZE; ++i)
ptr[i] = 'a';
};
reset(lhs);
reset(rhs);
for (size_t i = 0; i < kMaxSize; ++i)
for (size_t i = 0; i < K_MAX_SIZE; ++i)
EXPECT_EQ(__llvm_libc::memcmp(lhs, rhs, i), 0);
reset(lhs);
reset(rhs);
for (size_t i = 0; i < kMaxSize; ++i) {
for (size_t i = 0; i < K_MAX_SIZE; ++i) {
rhs[i] = 'z';
EXPECT_LT(__llvm_libc::memcmp(lhs, rhs, kMaxSize), 0);
EXPECT_LT(__llvm_libc::memcmp(lhs, rhs, K_MAX_SIZE), 0);
rhs[i] = 'a';
}
}

View File

@ -14,11 +14,11 @@ using __llvm_libc::cpp::Array;
using __llvm_libc::cpp::ArrayRef;
using Data = Array<char, 2048>;
static const ArrayRef<char> kNumbers("0123456789", 10);
static const ArrayRef<char> kDeadcode("DEADC0DE", 8);
static const ArrayRef<char> k_numbers("0123456789", 10);
static const ArrayRef<char> k_deadcode("DEADC0DE", 8);
// Returns a Data object filled with a repetition of `filler`.
Data getData(ArrayRef<char> filler) {
Data get_data(ArrayRef<char> filler) {
Data out;
for (size_t i = 0; i < out.size(); ++i)
out[i] = filler[i % filler.size()];
@ -26,8 +26,8 @@ Data getData(ArrayRef<char> filler) {
}
TEST(LlvmLibcMemcpyTest, Thorough) {
const Data groundtruth = getData(kNumbers);
const Data dirty = getData(kDeadcode);
const Data groundtruth = get_data(k_numbers);
const Data dirty = get_data(k_deadcode);
for (size_t count = 0; count < 1024; ++count) {
for (size_t align = 0; align < 64; ++align) {
auto buffer = dirty;

View File

@ -14,10 +14,10 @@ using __llvm_libc::cpp::Array;
using __llvm_libc::cpp::ArrayRef;
using Data = Array<char, 2048>;
static const ArrayRef<char> kDeadcode("DEADC0DE", 8);
static const ArrayRef<char> k_deadcode("DEADC0DE", 8);
// Returns a Data object filled with a repetition of `filler`.
Data getData(ArrayRef<char> filler) {
Data get_data(ArrayRef<char> filler) {
Data out;
for (size_t i = 0; i < out.size(); ++i)
out[i] = filler[i % filler.size()];
@ -25,7 +25,7 @@ Data getData(ArrayRef<char> filler) {
}
TEST(LlvmLibcMemsetTest, Thorough) {
const Data dirty = getData(kDeadcode);
const Data dirty = get_data(k_deadcode);
for (int value = -1; value <= 1; ++value) {
for (size_t count = 0; count < 1024; ++count) {
for (size_t align = 0; align < 64; ++align) {

View File

@ -13,33 +13,33 @@
TEST(LlvmLibcStpCpyTest, EmptySrc) {
const char *empty = "";
size_t srcSize = __llvm_libc::internal::string_length(empty);
size_t src_size = __llvm_libc::internal::string_length(empty);
char dest[4] = {'a', 'b', 'c', '\0'};
char *result = __llvm_libc::stpcpy(dest, empty);
ASSERT_EQ(dest + srcSize, result);
ASSERT_EQ(dest + src_size, result);
ASSERT_EQ(result[0], '\0');
ASSERT_STREQ(dest, empty);
}
TEST(LlvmLibcStpCpyTest, EmptyDest) {
const char *abc = "abc";
size_t srcSize = __llvm_libc::internal::string_length(abc);
size_t src_size = __llvm_libc::internal::string_length(abc);
char dest[4];
char *result = __llvm_libc::stpcpy(dest, abc);
ASSERT_EQ(dest + srcSize, result);
ASSERT_EQ(dest + src_size, result);
ASSERT_EQ(result[0], '\0');
ASSERT_STREQ(dest, abc);
}
TEST(LlvmLibcStpCpyTest, OffsetDest) {
const char *abc = "abc";
size_t srcSize = __llvm_libc::internal::string_length(abc);
size_t src_size = __llvm_libc::internal::string_length(abc);
char dest[7] = {'x', 'y', 'z'};
char *result = __llvm_libc::stpcpy(dest + 3, abc);
ASSERT_EQ(dest + 3 + srcSize, result);
ASSERT_EQ(dest + 3 + src_size, result);
ASSERT_EQ(result[0], '\0');
ASSERT_STREQ(dest, "xyzabc");
}

View File

@ -18,7 +18,7 @@
#include <stdatomic.h>
static constexpr unsigned int num_threads = 5;
static constexpr unsigned int NUM_THREADS = 5;
static atomic_uint thread_count;
static unsigned int call_count;
@ -38,13 +38,13 @@ TEST(LlvmLibcCallOnceTest, CallFrom5Threads) {
call_count = 0;
thread_count = 0;
thrd_t threads[num_threads];
for (unsigned int i = 0; i < num_threads; ++i) {
thrd_t threads[NUM_THREADS];
for (unsigned int i = 0; i < NUM_THREADS; ++i) {
ASSERT_EQ(__llvm_libc::thrd_create(threads + i, func, nullptr),
static_cast<int>(thrd_success));
}
for (unsigned int i = 0; i < num_threads; ++i) {
for (unsigned int i = 0; i < NUM_THREADS; ++i) {
int retval;
ASSERT_EQ(__llvm_libc::thrd_join(threads + i, &retval),
static_cast<int>(thrd_success));

View File

@ -69,11 +69,11 @@ TEST(LlvmLibcMutexTest, RelayCounter) {
}
mtx_t start_lock, step_lock;
bool start, step;
bool started, step;
int stepper(void *arg) {
__llvm_libc::mtx_lock(&start_lock);
start = true;
started = true;
__llvm_libc::mtx_unlock(&start_lock);
__llvm_libc::mtx_lock(&step_lock);
@ -92,7 +92,7 @@ TEST(LlvmLibcMutexTest, WaitAndStep) {
// step. Once we ensure that the thread is blocked, we unblock it.
// After unblocking, we then verify that the thread was indeed unblocked.
step = false;
start = false;
started = false;
ASSERT_EQ(__llvm_libc::mtx_lock(&step_lock), static_cast<int>(thrd_success));
thrd_t thread;
@ -102,7 +102,7 @@ TEST(LlvmLibcMutexTest, WaitAndStep) {
// Make sure the thread actually started.
ASSERT_EQ(__llvm_libc::mtx_lock(&start_lock),
static_cast<int>(thrd_success));
bool s = start;
bool s = started;
ASSERT_EQ(__llvm_libc::mtx_unlock(&start_lock),
static_cast<int>(thrd_success));
if (s)

View File

@ -20,9 +20,9 @@ namespace tmhelper {
namespace testing {
// A helper function to initialize tm data structure.
static inline void InitializeTmData(struct tm *tm_data, int year, int month,
int mday, int hour, int min, int sec,
int wday, int yday) {
static inline void initialize_tm_data(struct tm *tm_data, int year, int month,
int mday, int hour, int min, int sec,
int wday, int yday) {
struct tm temp = {.tm_sec = sec,
.tm_min = min,
.tm_hour = hour,

View File

@ -17,8 +17,8 @@ using __llvm_libc::time_utils::TimeConstants;
static inline char *call_asctime_r(struct tm *tm_data, int year, int month,
int mday, int hour, int min, int sec,
int wday, int yday, char *buffer) {
__llvm_libc::tmhelper::testing::InitializeTmData(tm_data, year, month, mday,
hour, min, sec, wday, yday);
__llvm_libc::tmhelper::testing::initialize_tm_data(
tm_data, year, month, mday, hour, min, sec, wday, yday);
return __llvm_libc::asctime_r(tm_data, buffer);
}

View File

@ -13,8 +13,8 @@
static inline char *call_asctime(struct tm *tm_data, int year, int month,
int mday, int hour, int min, int sec, int wday,
int yday) {
__llvm_libc::tmhelper::testing::InitializeTmData(tm_data, year, month, mday,
hour, min, sec, wday, yday);
__llvm_libc::tmhelper::testing::initialize_tm_data(
tm_data, year, month, mday, hour, min, sec, wday, yday);
return __llvm_libc::asctime(tm_data);
}

View File

@ -24,14 +24,14 @@ using __llvm_libc::time_utils::TimeConstants;
static inline time_t call_mktime(struct tm *tm_data, int year, int month,
int mday, int hour, int min, int sec, int wday,
int yday) {
__llvm_libc::tmhelper::testing::InitializeTmData(tm_data, year, month, mday,
hour, min, sec, wday, yday);
__llvm_libc::tmhelper::testing::initialize_tm_data(
tm_data, year, month, mday, hour, min, sec, wday, yday);
return __llvm_libc::mktime(tm_data);
}
TEST(LlvmLibcMkTime, FailureSetsErrno) {
struct tm tm_data;
__llvm_libc::tmhelper::testing::InitializeTmData(
__llvm_libc::tmhelper::testing::initialize_tm_data(
&tm_data, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, -1, 0, 0);
EXPECT_THAT(__llvm_libc::mktime(&tm_data), Fails(EOVERFLOW));
}

View File

@ -14,10 +14,10 @@
TEST(LlvmLibcUniStd, WriteBasic) {
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *hello = "hello";
constexpr const char *HELLO = "hello";
__llvm_libc::testutils::FDReader reader;
EXPECT_THAT(__llvm_libc::write(reader.getWriteFD(), hello, 5), Succeeds(5));
EXPECT_TRUE(reader.matchWritten(hello));
EXPECT_THAT(__llvm_libc::write(reader.get_write_fd(), HELLO, 5), Succeeds(5));
EXPECT_TRUE(reader.match_written(HELLO));
}
TEST(LlvmLibcUniStd, WriteFails) {

View File

@ -291,22 +291,22 @@ bool Test::testMatch(bool MatchResult, MatcherBase &Matcher, const char *LHSStr,
bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal,
const char *LHSStr, const char *RHSStr,
const char *File, unsigned long Line) {
testutils::ProcessStatus Result = testutils::invokeInSubprocess(Func, 500);
testutils::ProcessStatus Result = testutils::invoke_in_subprocess(Func, 500);
if (const char *error = Result.getError()) {
if (const char *error = Result.get_error()) {
Ctx->markFail();
std::cout << File << ":" << Line << ": FAILURE\n" << error << '\n';
return false;
}
if (Result.timedOut()) {
if (Result.timed_out()) {
Ctx->markFail();
std::cout << File << ":" << Line << ": FAILURE\n"
<< "Process timed out after " << 500 << " milliseconds.\n";
return false;
}
if (Result.exitedNormally()) {
if (Result.exited_normally()) {
Ctx->markFail();
std::cout << File << ":" << Line << ": FAILURE\n"
<< "Expected " << LHSStr
@ -314,41 +314,41 @@ bool Test::testProcessKilled(testutils::FunctionCaller *Func, int Signal,
return false;
}
int KilledBy = Result.getFatalSignal();
int KilledBy = Result.get_fatal_signal();
assert(KilledBy != 0 && "Not killed by any signal");
if (Signal == -1 || KilledBy == Signal)
return true;
using testutils::signalAsString;
using testutils::signal_as_string;
Ctx->markFail();
std::cout << File << ":" << Line << ": FAILURE\n"
<< " Expected: " << LHSStr << '\n'
<< "To be killed by signal: " << Signal << '\n'
<< " Which is: " << signalAsString(Signal) << '\n'
<< " Which is: " << signal_as_string(Signal) << '\n'
<< " But it was killed by: " << KilledBy << '\n'
<< " Which is: " << signalAsString(KilledBy) << '\n';
<< " Which is: " << signal_as_string(KilledBy) << '\n';
return false;
}
bool Test::testProcessExits(testutils::FunctionCaller *Func, int ExitCode,
const char *LHSStr, const char *RHSStr,
const char *File, unsigned long Line) {
testutils::ProcessStatus Result = testutils::invokeInSubprocess(Func, 500);
testutils::ProcessStatus Result = testutils::invoke_in_subprocess(Func, 500);
if (const char *error = Result.getError()) {
if (const char *error = Result.get_error()) {
Ctx->markFail();
std::cout << File << ":" << Line << ": FAILURE\n" << error << '\n';
return false;
}
if (Result.timedOut()) {
if (Result.timed_out()) {
Ctx->markFail();
std::cout << File << ":" << Line << ": FAILURE\n"
<< "Process timed out after " << 500 << " milliseconds.\n";
return false;
}
if (!Result.exitedNormally()) {
if (!Result.exited_normally()) {
Ctx->markFail();
std::cout << File << ":" << Line << ": FAILURE\n"
<< "Expected " << LHSStr << '\n'
@ -357,7 +357,7 @@ bool Test::testProcessExits(testutils::FunctionCaller *Func, int ExitCode,
return false;
}
int ActualExit = Result.getExitCode();
int ActualExit = Result.get_exit_code();
if (ActualExit == ExitCode)
return true;

View File

@ -21,28 +21,29 @@ public:
};
struct ProcessStatus {
int PlatformDefined;
int platform_defined;
const char *failure = nullptr;
static constexpr uintptr_t timeout = -1L;
static constexpr uintptr_t TIMEOUT = -1L;
static ProcessStatus Error(const char *error) { return {0, error}; }
static ProcessStatus TimedOut() {
return {0, reinterpret_cast<const char *>(timeout)};
static ProcessStatus error(const char *error) { return {0, error}; }
static ProcessStatus timed_out_ps() {
return {0, reinterpret_cast<const char *>(TIMEOUT)};
}
bool timedOut() const {
return failure == reinterpret_cast<const char *>(timeout);
bool timed_out() const {
return failure == reinterpret_cast<const char *>(TIMEOUT);
}
const char *getError() const { return timedOut() ? nullptr : failure; }
bool exitedNormally() const;
int getExitCode() const;
int getFatalSignal() const;
const char *get_error() const { return timed_out() ? nullptr : failure; }
bool exited_normally() const;
int get_exit_code() const;
int get_fatal_signal() const;
};
ProcessStatus invokeInSubprocess(FunctionCaller *Func, unsigned TimeoutMS = -1);
ProcessStatus invoke_in_subprocess(FunctionCaller *Func,
unsigned TimeoutMS = -1);
const char *signalAsString(int Signum);
const char *signal_as_string(int Signum);
} // namespace testutils
} // namespace __llvm_libc

View File

@ -20,33 +20,33 @@
namespace __llvm_libc {
namespace testutils {
bool ProcessStatus::exitedNormally() const {
return WIFEXITED(PlatformDefined);
bool ProcessStatus::exited_normally() const {
return WIFEXITED(platform_defined);
}
int ProcessStatus::getExitCode() const {
assert(exitedNormally() && "Abnormal termination, no exit code");
return WEXITSTATUS(PlatformDefined);
int ProcessStatus::get_exit_code() const {
assert(exited_normally() && "Abnormal termination, no exit code");
return WEXITSTATUS(platform_defined);
}
int ProcessStatus::getFatalSignal() const {
if (exitedNormally())
int ProcessStatus::get_fatal_signal() const {
if (exited_normally())
return 0;
return WTERMSIG(PlatformDefined);
return WTERMSIG(platform_defined);
}
ProcessStatus invokeInSubprocess(FunctionCaller *Func, unsigned timeoutMS) {
ProcessStatus invoke_in_subprocess(FunctionCaller *Func, unsigned timeoutMS) {
std::unique_ptr<FunctionCaller> X(Func);
int pipeFDs[2];
if (::pipe(pipeFDs) == -1)
return ProcessStatus::Error("pipe(2) failed");
return ProcessStatus::error("pipe(2) failed");
// Don't copy the buffers into the child process and print twice.
std::cout.flush();
std::cerr.flush();
pid_t Pid = ::fork();
if (Pid == -1)
return ProcessStatus::Error("fork(2) failed");
return ProcessStatus::error("fork(2) failed");
if (!Pid) {
(*Func)();
@ -60,11 +60,11 @@ ProcessStatus invokeInSubprocess(FunctionCaller *Func, unsigned timeoutMS) {
// No events requested so this call will only return after the timeout or if
// the pipes peer was closed, signaling the process exited.
if (::poll(&pollFD, 1, timeoutMS) == -1)
return ProcessStatus::Error("poll(2) failed");
return ProcessStatus::error("poll(2) failed");
// If the pipe wasn't closed by the child yet then timeout has expired.
if (!(pollFD.revents & POLLHUP)) {
::kill(Pid, SIGKILL);
return ProcessStatus::TimedOut();
return ProcessStatus::timed_out_ps();
}
int WStatus = 0;
@ -72,13 +72,13 @@ ProcessStatus invokeInSubprocess(FunctionCaller *Func, unsigned timeoutMS) {
// and doesn't turn into a zombie.
pid_t status = ::waitpid(Pid, &WStatus, 0);
if (status == -1)
return ProcessStatus::Error("waitpid(2) failed");
return ProcessStatus::error("waitpid(2) failed");
assert(status == Pid);
(void)status;
return {WStatus};
}
const char *signalAsString(int Signum) { return ::strsignal(Signum); }
const char *signal_as_string(int Signum) { return ::strsignal(Signum); }
} // namespace testutils
} // namespace __llvm_libc

View File

@ -19,8 +19,8 @@ public:
FDReader();
~FDReader();
int getWriteFD() { return pipefd[1]; }
bool matchWritten(const char *);
int get_write_fd() { return pipefd[1]; }
bool match_written(const char *);
};
} // namespace testutils

View File

@ -27,7 +27,7 @@ FDReader::~FDReader() {
::close(pipefd[1]);
}
bool FDReader::matchWritten(const char *str) {
bool FDReader::match_written(const char *str) {
::close(pipefd[1]);

View File

@ -19,8 +19,8 @@ namespace testutils {
StreamWrapper outs() { return {std::addressof(std::cout)}; }
template <typename T> StreamWrapper &StreamWrapper::operator<<(T t) {
assert(OS);
std::ostream &Stream = *reinterpret_cast<std::ostream *>(OS);
assert(os);
std::ostream &Stream = *reinterpret_cast<std::ostream *>(os);
Stream << t;
Stream.flush();
return *this;
@ -52,7 +52,7 @@ OutputFileStream::OutputFileStream(const char *FN)
: StreamWrapper(new std::ofstream(FN)) {}
OutputFileStream::~OutputFileStream() {
delete reinterpret_cast<std::ofstream *>(OS);
delete reinterpret_cast<std::ofstream *>(os);
}
} // namespace testutils

View File

@ -17,10 +17,10 @@ namespace testutils {
// expose the system libc headers.
class StreamWrapper {
protected:
void *OS;
void *os;
public:
StreamWrapper(void *OS) : OS(OS) {}
StreamWrapper(void *OS) : os(OS) {}
template <typename T> StreamWrapper &operator<<(T t);
};