aboutsummaryrefslogtreecommitdiff
path: root/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2022-04-13 02:27:30 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-04-13 02:27:30 +0000
commit7563023510bf04108a954596ea9393a4c11ac279 (patch)
tree2ce94d7f0804ccb77d1fa9b2a1bca00eecdff1e2 /third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
parentf60eaea2240ba9e1c508e8e0c91d39ee9fc47be5 (diff)
parenta9167328fc721c9637f0bcd87525cd23ff5ddac1 (diff)
downloadwebrtc-android13-dev.tar.gz
Merge changes I0ab600cd,I1e74c64a am: 798f3afdf6 am: 2f9c4b2c3b am: a9167328fct_frc_odp_330442040t_frc_odp_330442000t_frc_ase_330444010android13-frc-odp-releaseandroid13-dev
Original change: https://android-review.googlesource.com/c/platform/external/webrtc/+/2062410 Change-Id: I9a35945cfb943544bbb0f4632fef787ea38c1ad1 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'third_party/abseil-cpp/absl/random/exponential_distribution_test.cc')
-rw-r--r--third_party/abseil-cpp/absl/random/exponential_distribution_test.cc48
1 files changed, 25 insertions, 23 deletions
diff --git a/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc b/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
index f3cfd76442..81a5d17bac 100644
--- a/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
+++ b/third_party/abseil-cpp/absl/random/exponential_distribution_test.cc
@@ -15,6 +15,7 @@
#include "absl/random/exponential_distribution.h"
#include <algorithm>
+#include <cfloat>
#include <cmath>
#include <cstddef>
#include <cstdint>
@@ -30,8 +31,10 @@
#include "gtest/gtest.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/macros.h"
+#include "absl/numeric/internal/representation.h"
#include "absl/random/internal/chi_square.h"
#include "absl/random/internal/distribution_test_util.h"
+#include "absl/random/internal/pcg_engine.h"
#include "absl/random/internal/sequence_urbg.h"
#include "absl/random/random.h"
#include "absl/strings/str_cat.h"
@@ -46,11 +49,15 @@ using absl::random_internal::kChiSquared;
template <typename RealType>
class ExponentialDistributionTypedTest : public ::testing::Test {};
-#if defined(__EMSCRIPTEN__)
-using RealTypes = ::testing::Types<float, double>;
-#else
-using RealTypes = ::testing::Types<float, double, long double>;
-#endif // defined(__EMSCRIPTEN__)
+// double-double arithmetic is not supported well by either GCC or Clang; see
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99048,
+// https://bugs.llvm.org/show_bug.cgi?id=49131, and
+// https://bugs.llvm.org/show_bug.cgi?id=49132. Don't bother running these tests
+// with double doubles until compiler support is better.
+using RealTypes =
+ std::conditional<absl::numeric_internal::IsDoubleDouble(),
+ ::testing::Types<float, double>,
+ ::testing::Types<float, double, long double>>::type;
TYPED_TEST_CASE(ExponentialDistributionTypedTest, RealTypes);
TYPED_TEST(ExponentialDistributionTypedTest, SerializeTest) {
@@ -129,23 +136,6 @@ TYPED_TEST(ExponentialDistributionTypedTest, SerializeTest) {
ss >> after;
-#if defined(__powerpc64__) || defined(__PPC64__) || defined(__powerpc__) || \
- defined(__ppc__) || defined(__PPC__)
- if (std::is_same<TypeParam, long double>::value) {
- // Roundtripping floating point values requires sufficient precision to
- // reconstruct the exact value. It turns out that long double has some
- // errors doing this on ppc, particularly for values
- // near {1.0 +/- epsilon}.
- if (lambda <= std::numeric_limits<double>::max() &&
- lambda >= std::numeric_limits<double>::lowest()) {
- EXPECT_EQ(static_cast<double>(before.lambda()),
- static_cast<double>(after.lambda()))
- << ss.str();
- }
- continue;
- }
-#endif
-
EXPECT_EQ(before.lambda(), after.lambda()) //
<< ss.str() << " " //
<< (ss.good() ? "good " : "") //
@@ -205,7 +195,10 @@ class ExponentialDistributionTests : public testing::TestWithParam<Param>,
template <typename D>
double SingleChiSquaredTest();
- absl::InsecureBitGen rng_;
+ // We use a fixed bit generator for distribution accuracy tests. This allows
+ // these tests to be deterministic, while still testing the qualify of the
+ // implementation.
+ absl::random_internal::pcg64_2018_engine rng_{0x2B7E151628AED2A6};
};
template <typename D>
@@ -392,6 +385,15 @@ TEST(ExponentialDistributionTest, StabilityTest) {
TEST(ExponentialDistributionTest, AlgorithmBounds) {
// Relies on absl::uniform_real_distribution, so some of these comments
// reference that.
+
+#if (defined(__i386__) || defined(_M_IX86)) && FLT_EVAL_METHOD != 0
+ // We're using an x87-compatible FPU, and intermediate operations can be
+ // performed with 80-bit floats. This produces slightly different results from
+ // what we expect below.
+ GTEST_SKIP()
+ << "Skipping the test because we detected x87 floating-point semantics";
+#endif
+
absl::exponential_distribution<double> dist;
{