diff --git a/libc/benchmarks/LibcBenchmarkTest.cpp b/libc/benchmarks/LibcBenchmarkTest.cpp --- a/libc/benchmarks/LibcBenchmarkTest.cpp +++ b/libc/benchmarks/LibcBenchmarkTest.cpp @@ -50,9 +50,9 @@ } 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()); diff --git a/libc/benchmarks/automemcpy/lib/ResultAnalyzerMain.cpp b/libc/benchmarks/automemcpy/lib/ResultAnalyzerMain.cpp --- a/libc/benchmarks/automemcpy/lib/ResultAnalyzerMain.cpp +++ b/libc/benchmarks/automemcpy/lib/ResultAnalyzerMain.cpp @@ -94,7 +94,7 @@ json::Path::Root Root; JsonFile JF; if (!fromJSON(JsonValue, JF, Root)) - ExitOnErr(Root.getError()); + ExitOnErr(Root.get_error()); return JF; } diff --git a/libc/test/config/linux/x86_64/syscall_test.cpp b/libc/test/config/linux/x86_64/syscall_test.cpp --- a/libc/test/config/linux/x86_64/syscall_test.cpp +++ b/libc/test/config/linux/x86_64/syscall_test.cpp @@ -39,6 +39,6 @@ return __llvm_libc::syscall(n, a1, a2, a3, a4, a5, a6); }); - Function notLongType( + Function not_long_type( [](long n, void *a1) { return __llvm_libc::syscall(n, a1); }); } diff --git a/libc/test/src/__support/str_to_float_test.cpp b/libc/test/src/__support/str_to_float_test.cpp --- a/libc/test/src/__support/str_to_float_test.cpp +++ b/libc/test/src/__support/str_to_float_test.cpp @@ -14,201 +14,209 @@ class LlvmLibcStrToFloatTest : public __llvm_libc::testing::Test { public: template - void ClingerFastPathTest( + void clinger_fast_path_test( const typename __llvm_libc::fputil::FPBits::UIntType inputMantissa, const int32_t inputExp10, const typename __llvm_libc::fputil::FPBits::UIntType expectedOutputMantissa, const uint32_t expectedOutputExp2) { - typename __llvm_libc::fputil::FPBits::UIntType actualOutputMantissa = 0; - uint32_t actualOutputExp2 = 0; + typename __llvm_libc::fputil::FPBits::UIntType actual_output_mantissa = + 0; + uint32_t actual_output_exp2 = 0; ASSERT_TRUE(__llvm_libc::internal::clinger_fast_path( - 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 - void ClingerFastPathFailsTest( + void clinger_fast_path_fails_test( const typename __llvm_libc::fputil::FPBits::UIntType inputMantissa, const int32_t inputExp10) { - typename __llvm_libc::fputil::FPBits::UIntType actualOutputMantissa = 0; - uint32_t actualOutputExp2 = 0; + typename __llvm_libc::fputil::FPBits::UIntType actual_output_mantissa = + 0; + uint32_t actual_output_exp2 = 0; ASSERT_FALSE(__llvm_libc::internal::clinger_fast_path( - inputMantissa, inputExp10, &actualOutputMantissa, &actualOutputExp2)); + inputMantissa, inputExp10, &actual_output_mantissa, + &actual_output_exp2)); } template - void EiselLemireTest( + void eisel_lemire_test( const typename __llvm_libc::fputil::FPBits::UIntType inputMantissa, const int32_t inputExp10, const typename __llvm_libc::fputil::FPBits::UIntType expectedOutputMantissa, const uint32_t expectedOutputExp2) { - typename __llvm_libc::fputil::FPBits::UIntType actualOutputMantissa = 0; - uint32_t actualOutputExp2 = 0; + typename __llvm_libc::fputil::FPBits::UIntType actual_output_mantissa = + 0; + uint32_t actual_output_exp2 = 0; ASSERT_TRUE(__llvm_libc::internal::eisel_lemire( - 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 - void SimpleDecimalConversionTest( + void simple_decimal_conversion_test( const char *__restrict numStart, const typename __llvm_libc::fputil::FPBits::UIntType expectedOutputMantissa, const uint32_t expectedOutputExp2, const int expectedErrno = 0) { - typename __llvm_libc::fputil::FPBits::UIntType actualOutputMantissa = 0; - uint32_t actualOutputExp2 = 0; + typename __llvm_libc::fputil::FPBits::UIntType actual_output_mantissa = + 0; + uint32_t actual_output_exp2 = 0; errno = 0; __llvm_libc::internal::simple_decimal_conversion( - 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(0), 64u); - for (; numOfZeroes < 64; testNum64 <<= 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leading_zeroes(testNum64), - numOfZeroes); + for (; num_of_zeroes < 64; test_num64 <<= 1, num_of_zeroes--) { + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(test_num64), + num_of_zeroes); } - testNum64 = 3; - numOfZeroes = 62; - for (; numOfZeroes > 63; testNum64 <<= 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leading_zeroes(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(test_num64), + num_of_zeroes); } EXPECT_EQ(__llvm_libc::internal::leading_zeroes(0xffffffffffffffff), 0u); - testNum64 = 1; - numOfZeroes = 63; - for (; numOfZeroes > 63; testNum64 = (testNum64 << 1) + 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leading_zeroes(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(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(0), 32u); - for (; numOfZeroes < 32; testNum32 <<= 1, numOfZeroes--) { - EXPECT_EQ(__llvm_libc::internal::leading_zeroes(testNum32), - numOfZeroes); + for (; num_of_zeroes < 32; test_num32 <<= 1, num_of_zeroes--) { + EXPECT_EQ(__llvm_libc::internal::leading_zeroes(test_num32), + num_of_zeroes); } EXPECT_EQ(__llvm_libc::internal::leading_zeroes(0xffffffff), 0u); } TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat64Simple) { - ClingerFastPathTest(123, 0, 0xEC00000000000, 1029); - ClingerFastPathTest(1234567890123456, 1, 0x5ee2a2eb5a5c0, 1076); - ClingerFastPathTest(1234567890, -10, 0xf9add3739635f, 1019); + clinger_fast_path_test(123, 0, 0xEC00000000000, 1029); + clinger_fast_path_test(1234567890123456, 1, 0x5ee2a2eb5a5c0, 1076); + clinger_fast_path_test(1234567890, -10, 0xf9add3739635f, 1019); } TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat64ExtendedExp) { - ClingerFastPathTest(1, 30, 0x93e5939a08cea, 1122); - ClingerFastPathTest(1, 37, 0xe17b84357691b, 1145); - ClingerFastPathFailsTest(10, 37); - ClingerFastPathFailsTest(1, 100); + clinger_fast_path_test(1, 30, 0x93e5939a08cea, 1122); + clinger_fast_path_test(1, 37, 0xe17b84357691b, 1145); + clinger_fast_path_fails_test(10, 37); + clinger_fast_path_fails_test(1, 100); } TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat64NegativeExp) { - ClingerFastPathTest(1, -10, 0xb7cdfd9d7bdbb, 989); - ClingerFastPathTest(1, -20, 0x79ca10c924223, 956); - ClingerFastPathFailsTest(1, -25); + clinger_fast_path_test(1, -10, 0xb7cdfd9d7bdbb, 989); + clinger_fast_path_test(1, -20, 0x79ca10c924223, 956); + clinger_fast_path_fails_test(1, -25); } TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat32Simple) { - ClingerFastPathTest(123, 0, 0x760000, 133); - ClingerFastPathTest(1234567, 1, 0x3c6146, 150); - ClingerFastPathTest(12345, -5, 0x7cd35b, 123); + clinger_fast_path_test(123, 0, 0x760000, 133); + clinger_fast_path_test(1234567, 1, 0x3c6146, 150); + clinger_fast_path_test(12345, -5, 0x7cd35b, 123); } TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat32ExtendedExp) { - ClingerFastPathTest(1, 15, 0x635fa9, 176); - ClingerFastPathTest(1, 17, 0x31a2bc, 183); - ClingerFastPathFailsTest(10, 17); - ClingerFastPathFailsTest(1, 50); + clinger_fast_path_test(1, 15, 0x635fa9, 176); + clinger_fast_path_test(1, 17, 0x31a2bc, 183); + clinger_fast_path_fails_test(10, 17); + clinger_fast_path_fails_test(1, 50); } TEST_F(LlvmLibcStrToFloatTest, ClingerFastPathFloat32NegativeExp) { - ClingerFastPathTest(1, -5, 0x27c5ac, 110); - ClingerFastPathTest(1, -10, 0x5be6ff, 93); - ClingerFastPathFailsTest(1, -15); + clinger_fast_path_test(1, -5, 0x27c5ac, 110); + clinger_fast_path_test(1, -10, 0x5be6ff, 93); + clinger_fast_path_fails_test(1, -15); } TEST_F(LlvmLibcStrToFloatTest, EiselLemireFloat64Simple) { - EiselLemireTest(12345678901234567890u, 1, 0x1AC53A7E04BCDA, 1089); - EiselLemireTest(123, 0, 0x1EC00000000000, 1029); - EiselLemireTest(12345678901234568192u, 0, 0x156A95319D63E2, 1086); + eisel_lemire_test(12345678901234567890u, 1, 0x1AC53A7E04BCDA, 1089); + eisel_lemire_test(123, 0, 0x1EC00000000000, 1029); + eisel_lemire_test(12345678901234568192u, 0, 0x156A95319D63E2, 1086); } TEST_F(LlvmLibcStrToFloatTest, EiselLemireFloat64SpecificFailures) { // These test cases have caused failures in the past. - EiselLemireTest(358416272, -33, 0x1BBB2A68C9D0B9, 941); - EiselLemireTest(2166568064000000238u, -9, 0x10246690000000, 1054); - EiselLemireTest(2794967654709307187u, 1, 0x183e132bc608c8, 1087); - EiselLemireTest(2794967654709307188u, 1, 0x183e132bc608c9, 1087); + eisel_lemire_test(358416272, -33, 0x1BBB2A68C9D0B9, 941); + eisel_lemire_test(2166568064000000238u, -9, 0x10246690000000, 1054); + eisel_lemire_test(2794967654709307187u, 1, 0x183e132bc608c8, 1087); + eisel_lemire_test(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( - 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( - 12345678901234549760u, 0, &doubleOutputMantissa, &outputExp2)); + 12345678901234549760u, 0, &double_output_mantissa, &output_exp2)); ASSERT_FALSE(__llvm_libc::internal::eisel_lemire( - 20040229, 0, &floatOutputMantissa, &outputExp2)); + 20040229, 0, &float_output_mantissa, &output_exp2)); } TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicWholeNumbers) { - SimpleDecimalConversionTest("123456789012345678900", 0x1AC53A7E04BCDA, - 1089); - SimpleDecimalConversionTest("123", 0x1EC00000000000, 1029); - SimpleDecimalConversionTest("12345678901234549760", 0x156A95319D63D8, - 1086); + simple_decimal_conversion_test("123456789012345678900", + 0x1AC53A7E04BCDA, 1089); + simple_decimal_conversion_test("123", 0x1EC00000000000, 1029); + simple_decimal_conversion_test("12345678901234549760", + 0x156A95319D63D8, 1086); } TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicDecimals) { - SimpleDecimalConversionTest("1.2345", 0x13c083126e978d, 1023); - SimpleDecimalConversionTest(".2345", 0x1e04189374bc6a, 1020); - SimpleDecimalConversionTest(".299792458", 0x132fccb4aca314, 1021); + simple_decimal_conversion_test("1.2345", 0x13c083126e978d, 1023); + simple_decimal_conversion_test(".2345", 0x1e04189374bc6a, 1020); + simple_decimal_conversion_test(".299792458", 0x132fccb4aca314, 1021); } TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicExponents) { - SimpleDecimalConversionTest("1e10", 0x12a05f20000000, 1056); - SimpleDecimalConversionTest("1e-10", 0x1b7cdfd9d7bdbb, 989); - SimpleDecimalConversionTest("1e300", 0x17e43c8800759c, 2019); - SimpleDecimalConversionTest("1e-300", 0x156e1fc2f8f359, 26); + simple_decimal_conversion_test("1e10", 0x12a05f20000000, 1056); + simple_decimal_conversion_test("1e-10", 0x1b7cdfd9d7bdbb, 989); + simple_decimal_conversion_test("1e300", 0x17e43c8800759c, 2019); + simple_decimal_conversion_test("1e-300", 0x156e1fc2f8f359, 26); } TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64BasicSubnormals) { - SimpleDecimalConversionTest("1e-320", 0x7e8, 0, ERANGE); - SimpleDecimalConversionTest("1e-308", 0x730d67819e8d2, 0, ERANGE); - SimpleDecimalConversionTest("2.9e-308", 0x14da6df5e4bcc8, 1); + simple_decimal_conversion_test("1e-320", 0x7e8, 0, ERANGE); + simple_decimal_conversion_test("1e-308", 0x730d67819e8d2, 0, ERANGE); + simple_decimal_conversion_test("2.9e-308", 0x14da6df5e4bcc8, 1); } TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion64SubnormalRounding) { @@ -216,40 +224,40 @@ // 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("2.225073858507201e-308", 0xfffffffffffff, - 0, ERANGE); + simple_decimal_conversion_test("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("2.2250738585072012e-308", - 0x10000000000000, 1); + simple_decimal_conversion_test("2.2250738585072012e-308", + 0x10000000000000, 1); } TEST_F(LlvmLibcStrToFloatTest, SimpleDecimalConversion32SpecificFailures) { - SimpleDecimalConversionTest( + simple_decimal_conversion_test( "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( - "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( - "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. diff --git a/libc/test/src/fenv/enabled_exceptions_test.cpp b/libc/test/src/fenv/enabled_exceptions_test.cpp --- a/libc/test/src/fenv/enabled_exceptions_test.cpp +++ b/libc/test/src/fenv/enabled_exceptions_test.cpp @@ -46,7 +46,7 @@ // 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 @@ // 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); } diff --git a/libc/test/src/fenv/exception_status_test.cpp b/libc/test/src/fenv/exception_status_test.cpp --- a/libc/test/src/fenv/exception_status_test.cpp +++ b/libc/test/src/fenv/exception_status_test.cpp @@ -25,7 +25,7 @@ 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 @@ } } - 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); } diff --git a/libc/test/src/math/CeilTest.h b/libc/test/src/math/CeilTest.h --- a/libc/test/src/math/CeilTest.h +++ b/libc/test/src/math/CeilTest.h @@ -64,9 +64,9 @@ } 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; diff --git a/libc/test/src/math/CopySignTest.h b/libc/test/src/math/CopySignTest.h --- a/libc/test/src/math/CopySignTest.h +++ b/libc/test/src/math/CopySignTest.h @@ -33,9 +33,9 @@ } 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; diff --git a/libc/test/src/math/FAbsTest.h b/libc/test/src/math/FAbsTest.h --- a/libc/test/src/math/FAbsTest.h +++ b/libc/test/src/math/FAbsTest.h @@ -32,9 +32,9 @@ } 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; diff --git a/libc/test/src/math/FDimTest.h b/libc/test/src/math/FDimTest.h --- a/libc/test/src/math/FDimTest.h +++ b/libc/test/src/math/FDimTest.h @@ -19,7 +19,7 @@ using FPBits = __llvm_libc::fputil::FPBits; 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 @@ 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 @@ 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 @@ 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; diff --git a/libc/test/src/math/FMaxTest.h b/libc/test/src/math/FMaxTest.h --- a/libc/test/src/math/FMaxTest.h +++ b/libc/test/src/math/FMaxTest.h @@ -55,10 +55,10 @@ } 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; diff --git a/libc/test/src/math/FMinTest.h b/libc/test/src/math/FMinTest.h --- a/libc/test/src/math/FMinTest.h +++ b/libc/test/src/math/FMinTest.h @@ -55,10 +55,10 @@ } 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; diff --git a/libc/test/src/math/FloorTest.h b/libc/test/src/math/FloorTest.h --- a/libc/test/src/math/FloorTest.h +++ b/libc/test/src/math/FloorTest.h @@ -64,9 +64,9 @@ } 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; diff --git a/libc/test/src/math/FmaTest.h b/libc/test/src/math/FmaTest.h --- a/libc/test/src/math/FmaTest.h +++ b/libc/test/src/math/FmaTest.h @@ -29,7 +29,7 @@ const T zero = T(__llvm_libc::fputil::FPBits::zero()); const T neg_zero = T(__llvm_libc::fputil::FPBits::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 @@ } 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 @@ 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 input{x, y, z}; @@ -78,14 +78,14 @@ } } - 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 input{x, y, z}; ASSERT_MPFR_MATCH(mpfr::Operation::Fma, input, result, 0.5); diff --git a/libc/test/src/math/FrexpTest.h b/libc/test/src/math/FrexpTest.h --- a/libc/test/src/math/FrexpTest.h +++ b/libc/test/src/math/FrexpTest.h @@ -19,7 +19,7 @@ DECLARE_SPECIAL_CONSTANTS(T) - static constexpr UIntType HiddenBit = + static constexpr UIntType HIDDEN_BIT = UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; public: @@ -93,9 +93,9 @@ 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(FPBits(v)); if (isnan(x) || isinf(x) || x == 0.0l) continue; diff --git a/libc/test/src/math/HypotTest.h b/libc/test/src/math/HypotTest.h --- a/libc/test/src/math/HypotTest.h +++ b/libc/test/src/math/HypotTest.h @@ -32,7 +32,7 @@ const T neg_zero = T(__llvm_libc::fputil::FPBits::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 @@ 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 @@ } } - 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; diff --git a/libc/test/src/math/ILogbTest.h b/libc/test/src/math/ILogbTest.h --- a/libc/test/src/math/ILogbTest.h +++ b/libc/test/src/math/ILogbTest.h @@ -21,7 +21,7 @@ template struct ILogbFunc { typedef int (*Func)(T); }; template - void testSpecialNumbers(typename ILogbFunc::Func func) { + void test_special_numbers(typename ILogbFunc::Func func) { EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits::zero()))); EXPECT_EQ(FP_ILOGB0, func(T(__llvm_libc::fputil::FPBits::neg_zero()))); @@ -32,7 +32,8 @@ EXPECT_EQ(INT_MAX, func(T(__llvm_libc::fputil::FPBits::neg_inf()))); } - template void testPowersOfTwo(typename ILogbFunc::Func func) { + template + void test_powers_of_two(typename ILogbFunc::Func func) { EXPECT_EQ(0, func(T(1.0))); EXPECT_EQ(0, func(T(-1.0))); @@ -53,7 +54,7 @@ } template - void testSomeIntegers(typename ILogbFunc::Func func) { + void test_some_integers(typename ILogbFunc::Func func) { EXPECT_EQ(1, func(T(3.0))); EXPECT_EQ(1, func(T(-3.0))); @@ -71,14 +72,14 @@ } template - void testSubnormalRange(typename ILogbFunc::Func func) { + void test_subnormal_range(typename ILogbFunc::Func func) { using FPBits = __llvm_libc::fputil::FPBits; 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 @@ } } - template void testNormalRange(typename ILogbFunc::Func func) { + template + void test_normal_range(typename ILogbFunc::Func func) { using FPBits = __llvm_libc::fputil::FPBits; 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; diff --git a/libc/test/src/math/LdExpTest.h b/libc/test/src/math/LdExpTest.h --- a/libc/test/src/math/LdExpTest.h +++ b/libc/test/src/math/LdExpTest.h @@ -23,10 +23,10 @@ using FPBits = __llvm_libc::fputil::FPBits; using NormalFloat = __llvm_libc::fputil::NormalFloat; using UIntType = typename FPBits::UIntType; - static constexpr UIntType mantissaWidth = + static constexpr UIntType MANTISSA_WIDTH = __llvm_libc::fputil::MantissaWidth::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::zero()); const T neg_zero = T(__llvm_libc::fputil::FPBits::neg_zero()); @@ -38,8 +38,8 @@ 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 @@ } 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 @@ 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 @@ 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(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(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 @@ 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. diff --git a/libc/test/src/math/LogbTest.h b/libc/test/src/math/LogbTest.h --- a/libc/test/src/math/LogbTest.h +++ b/libc/test/src/math/LogbTest.h @@ -19,7 +19,7 @@ DECLARE_SPECIAL_CONSTANTS(T) - static constexpr UIntType HiddenBit = + static constexpr UIntType HIDDEN_BIT = UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; public: @@ -72,9 +72,9 @@ 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(FPBits(v)); if (isnan(x) || isinf(x) || x == 0.0l) continue; diff --git a/libc/test/src/math/ModfTest.h b/libc/test/src/math/ModfTest.h --- a/libc/test/src/math/ModfTest.h +++ b/libc/test/src/math/ModfTest.h @@ -84,9 +84,9 @@ } 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; diff --git a/libc/test/src/math/NextAfterTest.h b/libc/test/src/math/NextAfterTest.h --- a/libc/test/src/math/NextAfterTest.h +++ b/libc/test/src/math/NextAfterTest.h @@ -22,7 +22,7 @@ using MantissaWidth = __llvm_libc::fputil::MantissaWidth; using UIntType = typename FPBits::UIntType; - static constexpr int bitWidthOfType = + static constexpr int BIT_WIDTH_OF_TYPE = __llvm_libc::fputil::FloatProperties::BIT_WIDTH; const T zero = T(FPBits::zero()); @@ -30,10 +30,10 @@ 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 @@ // 'from' is zero|neg_zero. T x = zero; T result = func(x, T(1)); - UIntType expectedBits = 1; - T expected = *reinterpret_cast(&expectedBits); + UIntType expected_bits = 1; + T expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); result = func(x, T(-1)); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); x = neg_zero; result = func(x, 1); - expectedBits = 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); result = func(x, -1); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); // 'from' is max subnormal value. - x = *reinterpret_cast(&MAX_SUBNORMAL); + x = *reinterpret_cast(&max_subnormal); result = func(x, 1); - expected = *reinterpret_cast(&MIN_NORMAL); + expected = *reinterpret_cast(&min_normal); ASSERT_FP_EQ(result, expected); result = func(x, 0); - expectedBits = MAX_SUBNORMAL - 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = max_subnormal - 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); x = -x; result = func(x, -1); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_NORMAL; - expected = *reinterpret_cast(&expectedBits); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); result = func(x, 0); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_SUBNORMAL - 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = + (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal - 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); // 'from' is min subnormal value. - x = *reinterpret_cast(&MIN_SUBNORMAL); + x = *reinterpret_cast(&min_subnormal); result = func(x, 1); - expectedBits = MIN_SUBNORMAL + 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = min_subnormal + 1; + expected = *reinterpret_cast(&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(&expectedBits); + expected_bits = + (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_subnormal + 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); ASSERT_FP_EQ(func(x, 0), T(-0.0)); // 'from' is min normal. - x = *reinterpret_cast(&MIN_NORMAL); + x = *reinterpret_cast(&min_normal); result = func(x, 0); - expectedBits = MAX_SUBNORMAL; - expected = *reinterpret_cast(&expectedBits); + expected_bits = max_subnormal; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); result = func(x, inf); - expectedBits = MIN_NORMAL + 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = min_normal + 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); x = -x; result = func(x, 0); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MAX_SUBNORMAL; - expected = *reinterpret_cast(&expectedBits); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_subnormal; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); result = func(x, -inf); - expectedBits = (UIntType(1) << (bitWidthOfType - 1)) + MIN_NORMAL + 1; - expected = *reinterpret_cast(&expectedBits); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + min_normal + 1; + expected = *reinterpret_cast(&expected_bits); ASSERT_FP_EQ(result, expected); // 'from' is max normal and 'to' is infinity. - x = *reinterpret_cast(&MAX_NORMAL); + x = *reinterpret_cast(&max_normal); result = func(x, inf); ASSERT_FP_EQ(result, inf); @@ -142,48 +144,48 @@ // 'from' is infinity. x = inf; result = func(x, 0); - expectedBits = MAX_NORMAL; - expected = *reinterpret_cast(&expectedBits); + expected_bits = max_normal; + expected = *reinterpret_cast(&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(&expectedBits); + expected_bits = (UIntType(1) << (BIT_WIDTH_OF_TYPE - 1)) + max_normal; + expected = *reinterpret_cast(&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)); } }; diff --git a/libc/test/src/math/RIntTest.h b/libc/test/src/math/RIntTest.h --- a/libc/test/src/math/RIntTest.h +++ b/libc/test/src/math/RIntTest.h @@ -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 class RIntTestTemplate : public __llvm_libc::testing::Test { @@ -39,7 +39,7 @@ 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 @@ 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 @@ } 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 @@ 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)); } } } diff --git a/libc/test/src/math/RemQuoTest.h b/libc/test/src/math/RemQuoTest.h --- a/libc/test/src/math/RemQuoTest.h +++ b/libc/test/src/math/RemQuoTest.h @@ -95,12 +95,12 @@ } 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 result; mpfr::BinaryInput input{x, y}; @@ -110,11 +110,11 @@ } 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 result; mpfr::BinaryInput input{x, y}; diff --git a/libc/test/src/math/RoundTest.h b/libc/test/src/math/RoundTest.h --- a/libc/test/src/math/RoundTest.h +++ b/libc/test/src/math/RoundTest.h @@ -64,9 +64,9 @@ } 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; diff --git a/libc/test/src/math/RoundToIntegerTest.h b/libc/test/src/math/RoundToIntegerTest.h --- a/libc/test/src/math/RoundToIntegerTest.h +++ b/libc/test/src/math/RoundToIntegerTest.h @@ -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 class RoundToIntegerTestTemplate : public __llvm_libc::testing::Test { @@ -40,11 +40,11 @@ const F inf = F(__llvm_libc::fputil::FPBits::inf()); const F neg_inf = F(__llvm_libc::fputil::FPBits::neg_inf()); const F nan = F(__llvm_libc::fputil::FPBits::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 @@ } } - 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 @@ #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 @@ 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 @@ 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::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 @@ 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 @@ 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 @@ } 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); } } } diff --git a/libc/test/src/math/SqrtTest.h b/libc/test/src/math/SqrtTest.h --- a/libc/test/src/math/SqrtTest.h +++ b/libc/test/src/math/SqrtTest.h @@ -18,7 +18,7 @@ DECLARE_SPECIAL_CONSTANTS(T) - static constexpr UIntType HiddenBit = + static constexpr UIntType HIDDEN_BIT = UIntType(1) << __llvm_libc::fputil::MantissaWidth::VALUE; public: @@ -37,7 +37,7 @@ } 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 @@ 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(&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(&v); if (isnan(x) || (x < 0)) { continue; diff --git a/libc/test/src/math/TruncTest.h b/libc/test/src/math/TruncTest.h --- a/libc/test/src/math/TruncTest.h +++ b/libc/test/src/math/TruncTest.h @@ -64,9 +64,9 @@ } 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; diff --git a/libc/test/src/math/cos_test.cpp b/libc/test/src/math/cos_test.cpp --- a/libc/test/src/math/cos_test.cpp +++ b/libc/test/src/math/cos_test.cpp @@ -19,9 +19,9 @@ 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) diff --git a/libc/test/src/math/cosf_test.cpp b/libc/test/src/math/cosf_test.cpp --- a/libc/test/src/math/cosf_test.cpp +++ b/libc/test/src/math/cosf_test.cpp @@ -18,7 +18,7 @@ #include #include -using __llvm_libc::testing::sdcomp26094Values; +using __llvm_libc::testing::SDCOMP26094_VALUES; using FPBits = __llvm_libc::fputil::FPBits; namespace mpfr = __llvm_libc::testing::mpfr; @@ -47,9 +47,9 @@ } 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 @@ // 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); } diff --git a/libc/test/src/math/exp2f_test.cpp b/libc/test/src/math/exp2f_test.cpp --- a/libc/test/src/math/exp2f_test.cpp +++ b/libc/test/src/math/exp2f_test.cpp @@ -101,9 +101,9 @@ } 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; diff --git a/libc/test/src/math/expf_test.cpp b/libc/test/src/math/expf_test.cpp --- a/libc/test/src/math/expf_test.cpp +++ b/libc/test/src/math/expf_test.cpp @@ -93,9 +93,9 @@ } 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; diff --git a/libc/test/src/math/expm1f_test.cpp b/libc/test/src/math/expm1f_test.cpp --- a/libc/test/src/math/expm1f_test.cpp +++ b/libc/test/src/math/expm1f_test.cpp @@ -93,9 +93,9 @@ } 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; diff --git a/libc/test/src/math/fdim_test.cpp b/libc/test/src/math/fdim_test.cpp --- a/libc/test/src/math/fdim_test.cpp +++ b/libc/test/src/math/fdim_test.cpp @@ -16,14 +16,16 @@ using LlvmLibcFDimTest = FDimTestTemplate; -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); } diff --git a/libc/test/src/math/fdimf_test.cpp b/libc/test/src/math/fdimf_test.cpp --- a/libc/test/src/math/fdimf_test.cpp +++ b/libc/test/src/math/fdimf_test.cpp @@ -16,16 +16,18 @@ using LlvmLibcFDimTest = FDimTestTemplate; -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); } diff --git a/libc/test/src/math/fdiml_test.cpp b/libc/test/src/math/fdiml_test.cpp --- a/libc/test/src/math/fdiml_test.cpp +++ b/libc/test/src/math/fdiml_test.cpp @@ -16,16 +16,18 @@ using LlvmLibcFDimTest = FDimTestTemplate; -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); } diff --git a/libc/test/src/math/fma_test.cpp b/libc/test/src/math/fma_test.cpp --- a/libc/test/src/math/fma_test.cpp +++ b/libc/test/src/math/fma_test.cpp @@ -13,11 +13,11 @@ using LlvmLibcFmaTest = FmaTestTemplate; 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); } diff --git a/libc/test/src/math/fmaf_test.cpp b/libc/test/src/math/fmaf_test.cpp --- a/libc/test/src/math/fmaf_test.cpp +++ b/libc/test/src/math/fmaf_test.cpp @@ -13,11 +13,11 @@ using LlvmLibcFmaTest = FmaTestTemplate; 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); } diff --git a/libc/test/src/math/hypot_test.cpp b/libc/test/src/math/hypot_test.cpp --- a/libc/test/src/math/hypot_test.cpp +++ b/libc/test/src/math/hypot_test.cpp @@ -13,11 +13,13 @@ using LlvmLibcHypotTest = HypotTestTemplate; 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); +} diff --git a/libc/test/src/math/hypotf_test.cpp b/libc/test/src/math/hypotf_test.cpp --- a/libc/test/src/math/hypotf_test.cpp +++ b/libc/test/src/math/hypotf_test.cpp @@ -13,13 +13,13 @@ using LlvmLibcHypotfTest = HypotTestTemplate; 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); } diff --git a/libc/test/src/math/ilogb_test.cpp b/libc/test/src/math/ilogb_test.cpp --- a/libc/test/src/math/ilogb_test.cpp +++ b/libc/test/src/math/ilogb_test.cpp @@ -16,21 +16,21 @@ #include TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogb) { - testSpecialNumbers(&__llvm_libc::ilogb); + test_special_numbers(&__llvm_libc::ilogb); } TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogb) { - testPowersOfTwo(&__llvm_libc::ilogb); + test_powers_of_two(&__llvm_libc::ilogb); } TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogb) { - testSomeIntegers(&__llvm_libc::ilogb); + test_some_integers(&__llvm_libc::ilogb); } TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogb) { - testSubnormalRange(&__llvm_libc::ilogb); + test_subnormal_range(&__llvm_libc::ilogb); } TEST_F(LlvmLibcILogbTest, NormalRange_ilogb) { - testNormalRange(&__llvm_libc::ilogb); + test_normal_range(&__llvm_libc::ilogb); } diff --git a/libc/test/src/math/ilogbf_test.cpp b/libc/test/src/math/ilogbf_test.cpp --- a/libc/test/src/math/ilogbf_test.cpp +++ b/libc/test/src/math/ilogbf_test.cpp @@ -16,21 +16,21 @@ #include TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogbf) { - testSpecialNumbers(&__llvm_libc::ilogbf); + test_special_numbers(&__llvm_libc::ilogbf); } TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogbf) { - testPowersOfTwo(&__llvm_libc::ilogbf); + test_powers_of_two(&__llvm_libc::ilogbf); } TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogbf) { - testSomeIntegers(&__llvm_libc::ilogbf); + test_some_integers(&__llvm_libc::ilogbf); } TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogbf) { - testSubnormalRange(&__llvm_libc::ilogbf); + test_subnormal_range(&__llvm_libc::ilogbf); } TEST_F(LlvmLibcILogbTest, NormalRange_ilogbf) { - testNormalRange(&__llvm_libc::ilogbf); + test_normal_range(&__llvm_libc::ilogbf); } diff --git a/libc/test/src/math/ilogbl_test.cpp b/libc/test/src/math/ilogbl_test.cpp --- a/libc/test/src/math/ilogbl_test.cpp +++ b/libc/test/src/math/ilogbl_test.cpp @@ -18,21 +18,21 @@ using RunContext = __llvm_libc::testing::RunContext; TEST_F(LlvmLibcILogbTest, SpecialNumbers_ilogbl) { - testSpecialNumbers(&__llvm_libc::ilogbl); + test_special_numbers(&__llvm_libc::ilogbl); } TEST_F(LlvmLibcILogbTest, PowersOfTwo_ilogbl) { - testPowersOfTwo(&__llvm_libc::ilogbl); + test_powers_of_two(&__llvm_libc::ilogbl); } TEST_F(LlvmLibcILogbTest, SomeIntegers_ilogbl) { - testSomeIntegers(&__llvm_libc::ilogbl); + test_some_integers(&__llvm_libc::ilogbl); } TEST_F(LlvmLibcILogbTest, SubnormalRange_ilogbl) { - testSubnormalRange(&__llvm_libc::ilogbl); + test_subnormal_range(&__llvm_libc::ilogbl); } TEST_F(LlvmLibcILogbTest, NormalRange_ilogbl) { - testNormalRange(&__llvm_libc::ilogbl); + test_normal_range(&__llvm_libc::ilogbl); } diff --git a/libc/test/src/math/logf_test.cpp b/libc/test/src/math/logf_test.cpp --- a/libc/test/src/math/logf_test.cpp +++ b/libc/test/src/math/logf_test.cpp @@ -45,9 +45,9 @@ } 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; diff --git a/libc/test/src/math/sdcomp26094.h b/libc/test/src/math/sdcomp26094.h --- a/libc/test/src/math/sdcomp26094.h +++ b/libc/test/src/math/sdcomp26094.h @@ -16,7 +16,7 @@ namespace __llvm_libc { namespace testing { -static constexpr __llvm_libc::cpp::Array sdcomp26094Values{ +static constexpr __llvm_libc::cpp::Array SDCOMP26094_VALUES{ 0x46427f1b, 0x4647e568, 0x46428bac, 0x4647f1f9, 0x4647fe8a, 0x45d8d7f1, 0x45d371a4, 0x45ce0b57, 0x45d35882, 0x45cdf235, }; diff --git a/libc/test/src/math/sin_test.cpp b/libc/test/src/math/sin_test.cpp --- a/libc/test/src/math/sin_test.cpp +++ b/libc/test/src/math/sin_test.cpp @@ -20,9 +20,9 @@ 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) diff --git a/libc/test/src/math/sincosf_test.cpp b/libc/test/src/math/sincosf_test.cpp --- a/libc/test/src/math/sincosf_test.cpp +++ b/libc/test/src/math/sincosf_test.cpp @@ -18,7 +18,7 @@ #include #include -using __llvm_libc::testing::sdcomp26094Values; +using __llvm_libc::testing::SDCOMP26094_VALUES; using FPBits = __llvm_libc::fputil::FPBits; namespace mpfr = __llvm_libc::testing::mpfr; @@ -58,9 +58,9 @@ } 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 @@ // 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); diff --git a/libc/test/src/math/sinf_test.cpp b/libc/test/src/math/sinf_test.cpp --- a/libc/test/src/math/sinf_test.cpp +++ b/libc/test/src/math/sinf_test.cpp @@ -18,7 +18,7 @@ #include #include -using __llvm_libc::testing::sdcomp26094Values; +using __llvm_libc::testing::SDCOMP26094_VALUES; using FPBits = __llvm_libc::fputil::FPBits; namespace mpfr = __llvm_libc::testing::mpfr; @@ -47,9 +47,9 @@ } 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 @@ // 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); } diff --git a/libc/test/src/math/tan_test.cpp b/libc/test/src/math/tan_test.cpp --- a/libc/test/src/math/tan_test.cpp +++ b/libc/test/src/math/tan_test.cpp @@ -19,9 +19,9 @@ 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) diff --git a/libc/test/src/signal/sigprocmask_test.cpp b/libc/test/src/signal/sigprocmask_test.cpp --- a/libc/test/src/signal/sigprocmask_test.cpp +++ b/libc/test/src/signal/sigprocmask_test.cpp @@ -21,9 +21,9 @@ 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); } }; diff --git a/libc/test/src/stdlib/atof_test.cpp b/libc/test/src/stdlib/atof_test.cpp --- a/libc/test/src/stdlib/atof_test.cpp +++ b/libc/test/src/stdlib/atof_test.cpp @@ -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 expectedFP = + __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(uint64_t(0x405ec00000000000)); errno = 0; double result = __llvm_libc::atof("123"); - __llvm_libc::fputil::FPBits actualFP = + __llvm_libc::fputil::FPBits actual_fp = __llvm_libc::fputil::FPBits(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 expectedFP = + __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(uint64_t(0)); errno = 0; double result = __llvm_libc::atof("???"); - __llvm_libc::fputil::FPBits actualFP = + __llvm_libc::fputil::FPBits actual_fp = __llvm_libc::fputil::FPBits(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); } diff --git a/libc/test/src/stdlib/bsearch_test.cpp b/libc/test/src/stdlib/bsearch_test.cpp --- a/libc/test/src/stdlib/bsearch_test.cpp +++ b/libc/test/src/stdlib/bsearch_test.cpp @@ -35,44 +35,44 @@ } 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(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(elem), array[0]); + __llvm_libc::bsearch(ARRAY, ARRAY, ARRAY_SIZE, sizeof(int), int_compare); + EXPECT_EQ(*reinterpret_cast(elem), ARRAY[0]); } diff --git a/libc/test/src/stdlib/qsort_test.cpp b/libc/test/src/stdlib/qsort_test.cpp --- a/libc/test/src/stdlib/qsort_test.cpp +++ b/libc/test/src/stdlib/qsort_test.cpp @@ -27,9 +27,9 @@ 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, 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 @@ 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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); } diff --git a/libc/test/src/stdlib/strtod_test.cpp b/libc/test/src/stdlib/strtod_test.cpp --- a/libc/test/src/stdlib/strtod_test.cpp +++ b/libc/test/src/stdlib/strtod_test.cpp @@ -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 @@ // +-- 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 expectedFP = + __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(expectedRawData); errno = 0; - double result = __llvm_libc::strtod(inputString, &strEnd); + double result = __llvm_libc::strtod(inputString, &str_end); - __llvm_libc::fputil::FPBits actualFP = + __llvm_libc::fputil::FPBits actual_fp = __llvm_libc::fputil::FPBits(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)); } diff --git a/libc/test/src/stdlib/strtof_test.cpp b/libc/test/src/stdlib/strtof_test.cpp --- a/libc/test/src/stdlib/strtof_test.cpp +++ b/libc/test/src/stdlib/strtof_test.cpp @@ -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 @@ // +-- 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 expectedFP = + __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(expectedRawData); errno = 0; - float result = __llvm_libc::strtof(inputString, &strEnd); + float result = __llvm_libc::strtof(inputString, &str_end); - __llvm_libc::fputil::FPBits actualFP = + __llvm_libc::fputil::FPBits actual_fp = __llvm_libc::fputil::FPBits(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 @@ // 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 @@ // 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); } diff --git a/libc/test/src/stdlib/strtold_test.cpp b/libc/test/src/stdlib/strtold_test.cpp --- a/libc/test/src/stdlib/strtold_test.cpp +++ b/libc/test/src/stdlib/strtold_test.cpp @@ -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 @@ // +------+------+ // | // +-- 15 Exponent Bits - char *strEnd = nullptr; + char *str_end = nullptr; #if defined(LONG_DOUBLE_IS_DOUBLE) __llvm_libc::fputil::FPBits expectedFP = __llvm_libc::fputil::FPBits(expectedRawData64); const int expectedErrno = expectedErrno64; #elif defined(SPECIAL_X86_LONG_DOUBLE) - __llvm_libc::fputil::FPBits expectedFP = + __llvm_libc::fputil::FPBits expected_fp = __llvm_libc::fputil::FPBits(expectedRawData80); - const int expectedErrno = expectedErrno80; + const int expected_errno = expectedErrno80; #else __llvm_libc::fputil::FPBits expectedFP = __llvm_libc::fputil::FPBits(expectedRawData128); @@ -78,144 +78,146 @@ #endif errno = 0; - long double result = __llvm_libc::strtold(inputString, &strEnd); + long double result = __llvm_libc::strtold(inputString, &str_end); - __llvm_libc::fputil::FPBits actualFP = + __llvm_libc::fputil::FPBits actual_fp = __llvm_libc::fputil::FPBits(); - actualFP = __llvm_libc::fputil::FPBits(result); + actual_fp = __llvm_libc::fputil::FPBits(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)); - - runTest("0x123", 5, uint64_t(0x4072300000000000), - (__uint128_t(0x4007918000) << 40), - (__uint128_t(0x4007230000000000) << 64)); + run_test("1090544144181609348835077142190", 31, uint64_t(0x462b8779f2474dfb), + (__uint128_t(0x4062dc3bcf) << 40) + __uint128_t(0x923a6fd402), + (__uint128_t(0x4062b8779f2474df) << 64) + + __uint128_t(0xa804bfd8c6d5c000)); + + 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)); } diff --git a/libc/test/src/string/bcmp_test.cpp b/libc/test/src/string/bcmp_test.cpp --- a/libc/test/src/string/bcmp_test.cpp +++ b/libc/test/src/string/bcmp_test.cpp @@ -34,25 +34,25 @@ } 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'; } } diff --git a/libc/test/src/string/bzero_test.cpp b/libc/test/src/string/bzero_test.cpp --- a/libc/test/src/string/bzero_test.cpp +++ b/libc/test/src/string/bzero_test.cpp @@ -14,10 +14,10 @@ using __llvm_libc::cpp::ArrayRef; using Data = Array; -static const ArrayRef kDeadcode("DEADC0DE", 8); +static const ArrayRef k_deadcode("DEADC0DE", 8); // Returns a Data object filled with a repetition of `filler`. -Data getData(ArrayRef filler) { +Data get_data(ArrayRef filler) { Data out; for (size_t i = 0; i < out.size(); ++i) out[i] = filler[i % filler.size()]; @@ -25,7 +25,7 @@ } 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; diff --git a/libc/test/src/string/memcmp_test.cpp b/libc/test/src/string/memcmp_test.cpp --- a/libc/test/src/string/memcmp_test.cpp +++ b/libc/test/src/string/memcmp_test.cpp @@ -34,25 +34,25 @@ } 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'; } } diff --git a/libc/test/src/string/memcpy_test.cpp b/libc/test/src/string/memcpy_test.cpp --- a/libc/test/src/string/memcpy_test.cpp +++ b/libc/test/src/string/memcpy_test.cpp @@ -14,11 +14,11 @@ using __llvm_libc::cpp::ArrayRef; using Data = Array; -static const ArrayRef kNumbers("0123456789", 10); -static const ArrayRef kDeadcode("DEADC0DE", 8); +static const ArrayRef k_numbers("0123456789", 10); +static const ArrayRef k_deadcode("DEADC0DE", 8); // Returns a Data object filled with a repetition of `filler`. -Data getData(ArrayRef filler) { +Data get_data(ArrayRef filler) { Data out; for (size_t i = 0; i < out.size(); ++i) out[i] = filler[i % filler.size()]; @@ -26,8 +26,8 @@ } 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; diff --git a/libc/test/src/string/memset_test.cpp b/libc/test/src/string/memset_test.cpp --- a/libc/test/src/string/memset_test.cpp +++ b/libc/test/src/string/memset_test.cpp @@ -14,10 +14,10 @@ using __llvm_libc::cpp::ArrayRef; using Data = Array; -static const ArrayRef kDeadcode("DEADC0DE", 8); +static const ArrayRef k_deadcode("DEADC0DE", 8); // Returns a Data object filled with a repetition of `filler`. -Data getData(ArrayRef filler) { +Data get_data(ArrayRef filler) { Data out; for (size_t i = 0; i < out.size(); ++i) out[i] = filler[i % filler.size()]; @@ -25,7 +25,7 @@ } 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) { diff --git a/libc/test/src/string/stpcpy_test.cpp b/libc/test/src/string/stpcpy_test.cpp --- a/libc/test/src/string/stpcpy_test.cpp +++ b/libc/test/src/string/stpcpy_test.cpp @@ -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"); } diff --git a/libc/test/src/threads/call_once_test.cpp b/libc/test/src/threads/call_once_test.cpp --- a/libc/test/src/threads/call_once_test.cpp +++ b/libc/test/src/threads/call_once_test.cpp @@ -18,7 +18,7 @@ #include -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 @@ 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(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(thrd_success)); diff --git a/libc/test/src/threads/mtx_test.cpp b/libc/test/src/threads/mtx_test.cpp --- a/libc/test/src/threads/mtx_test.cpp +++ b/libc/test/src/threads/mtx_test.cpp @@ -69,11 +69,11 @@ } 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 @@ // 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(thrd_success)); thrd_t thread; @@ -102,7 +102,7 @@ // Make sure the thread actually started. ASSERT_EQ(__llvm_libc::mtx_lock(&start_lock), static_cast(thrd_success)); - bool s = start; + bool s = started; ASSERT_EQ(__llvm_libc::mtx_unlock(&start_lock), static_cast(thrd_success)); if (s) diff --git a/libc/test/src/time/TmHelper.h b/libc/test/src/time/TmHelper.h --- a/libc/test/src/time/TmHelper.h +++ b/libc/test/src/time/TmHelper.h @@ -20,9 +20,9 @@ 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, diff --git a/libc/test/src/time/asctime_r_test.cpp b/libc/test/src/time/asctime_r_test.cpp --- a/libc/test/src/time/asctime_r_test.cpp +++ b/libc/test/src/time/asctime_r_test.cpp @@ -17,8 +17,8 @@ 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); } diff --git a/libc/test/src/time/asctime_test.cpp b/libc/test/src/time/asctime_test.cpp --- a/libc/test/src/time/asctime_test.cpp +++ b/libc/test/src/time/asctime_test.cpp @@ -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); } diff --git a/libc/test/src/time/mktime_test.cpp b/libc/test/src/time/mktime_test.cpp --- a/libc/test/src/time/mktime_test.cpp +++ b/libc/test/src/time/mktime_test.cpp @@ -24,14 +24,14 @@ 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)); } diff --git a/libc/test/src/unistd/write_test.cpp b/libc/test/src/unistd/write_test.cpp --- a/libc/test/src/unistd/write_test.cpp +++ b/libc/test/src/unistd/write_test.cpp @@ -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) { diff --git a/libc/utils/UnitTest/LibcTest.cpp b/libc/utils/UnitTest/LibcTest.cpp --- a/libc/utils/UnitTest/LibcTest.cpp +++ b/libc/utils/UnitTest/LibcTest.cpp @@ -291,22 +291,22 @@ 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 @@ 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 @@ return false; } - int ActualExit = Result.getExitCode(); + int ActualExit = Result.get_exit_code(); if (ActualExit == ExitCode) return true; diff --git a/libc/utils/testutils/ExecuteFunction.h b/libc/utils/testutils/ExecuteFunction.h --- a/libc/utils/testutils/ExecuteFunction.h +++ b/libc/utils/testutils/ExecuteFunction.h @@ -21,28 +21,29 @@ }; 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(timeout)}; + static ProcessStatus error(const char *error) { return {0, error}; } + static ProcessStatus timed_out_ps() { + return {0, reinterpret_cast(TIMEOUT)}; } - bool timedOut() const { - return failure == reinterpret_cast(timeout); + bool timed_out() const { + return failure == reinterpret_cast(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 diff --git a/libc/utils/testutils/ExecuteFunctionUnix.cpp b/libc/utils/testutils/ExecuteFunctionUnix.cpp --- a/libc/utils/testutils/ExecuteFunctionUnix.cpp +++ b/libc/utils/testutils/ExecuteFunctionUnix.cpp @@ -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 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 @@ // 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 @@ // 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 diff --git a/libc/utils/testutils/FDReader.h b/libc/utils/testutils/FDReader.h --- a/libc/utils/testutils/FDReader.h +++ b/libc/utils/testutils/FDReader.h @@ -19,8 +19,8 @@ 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 diff --git a/libc/utils/testutils/FDReaderUnix.cpp b/libc/utils/testutils/FDReaderUnix.cpp --- a/libc/utils/testutils/FDReaderUnix.cpp +++ b/libc/utils/testutils/FDReaderUnix.cpp @@ -27,7 +27,7 @@ ::close(pipefd[1]); } -bool FDReader::matchWritten(const char *str) { +bool FDReader::match_written(const char *str) { ::close(pipefd[1]); diff --git a/libc/utils/testutils/StreamWrapper.h b/libc/utils/testutils/StreamWrapper.h --- a/libc/utils/testutils/StreamWrapper.h +++ b/libc/utils/testutils/StreamWrapper.h @@ -17,10 +17,10 @@ // expose the system libc headers. class StreamWrapper { protected: - void *OS; + void *os; public: - StreamWrapper(void *OS) : OS(OS) {} + StreamWrapper(void *OS) : os(OS) {} template StreamWrapper &operator<<(T t); }; diff --git a/libc/utils/testutils/StreamWrapper.cpp b/libc/utils/testutils/StreamWrapper.cpp --- a/libc/utils/testutils/StreamWrapper.cpp +++ b/libc/utils/testutils/StreamWrapper.cpp @@ -19,8 +19,8 @@ StreamWrapper outs() { return {std::addressof(std::cout)}; } template StreamWrapper &StreamWrapper::operator<<(T t) { - assert(OS); - std::ostream &Stream = *reinterpret_cast(OS); + assert(os); + std::ostream &Stream = *reinterpret_cast(os); Stream << t; Stream.flush(); return *this; @@ -52,7 +52,7 @@ : StreamWrapper(new std::ofstream(FN)) {} OutputFileStream::~OutputFileStream() { - delete reinterpret_cast(OS); + delete reinterpret_cast(os); } } // namespace testutils