bug 1438335 - Test edge-of-representation accumulations to Histograms. r?Dexter
MozReview-Commit-ID: 4FflK2q7Gea
--- a/toolkit/components/telemetry/tests/gtest/TestHistograms.cpp
+++ b/toolkit/components/telemetry/tests/gtest/TestHistograms.cpp
@@ -303,17 +303,17 @@ TEST_F(TelemetryTestFixture, AccumulateL
// Check that this count matches with nSamples
uint32_t uCount = 0;
JS::ToUint32(cx.GetJSContext(), count, &uCount);
ASSERT_EQ(uCount, kExpectedCount) << "The histogram did not accumulate the correct number of values";
}
TEST_F(TelemetryTestFixture, AccumulateLinearHistogram_DifferentSamples)
{
- nsTArray<uint32_t> samples({4, 8, 2147483646});
+ nsTArray<uint32_t> samples({4, 8, 2147483646, uint32_t(INT_MAX) + 1, UINT32_MAX});
AutoJSContextWithGlobal cx(mCleanGlobal);
GetAndClearHistogram(cx.GetJSContext(), mTelemetry, NS_LITERAL_CSTRING("TELEMETRY_TEST_LINEAR"),
false);
// Accumulate in histogram
Telemetry::Accumulate(Telemetry::TELEMETRY_TEST_LINEAR, samples);
@@ -340,17 +340,19 @@ TEST_F(TelemetryTestFixture, AccumulateL
// Check that the counts match
uint32_t uCountFirst = 0;
uint32_t uCountLast = 0;
JS::ToUint32(cx.GetJSContext(), countFirst, &uCountFirst);
JS::ToUint32(cx.GetJSContext(), countLast, &uCountLast);
const uint32_t kExpectedCountFirst = 2;
- const uint32_t kExpectedCountLast = 1;
+ // We expect 2147483646 to be in the last bucket, as well the two samples above 2^31
+ // (prior to bug 1438335, values between INT_MAX and UINT32_MAX would end up as 0s)
+ const uint32_t kExpectedCountLast = 3;
ASSERT_EQ(uCountFirst, kExpectedCountFirst) << "The first bucket did not accumulate the correct number of values";
ASSERT_EQ(uCountLast, kExpectedCountLast) << "The last bucket did not accumulate the correct number of values";
}
TEST_F(TelemetryTestFixture, AccumulateKeyedCountHistogram_MultipleSamples)
{
const nsTArray<uint32_t> samples({5, 10, 15});
const uint32_t kExpectedSum = 5 + 10 + 15;