Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1144)

Unified Diff: base/metrics/sparse_histogram_unittest.cc

Issue 2853853002: Fix overflow when logging MaxInt32 to a sparse histogram. (Closed)
Patch Set: Address comments. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/metrics/sparse_histogram_unittest.cc
diff --git a/base/metrics/sparse_histogram_unittest.cc b/base/metrics/sparse_histogram_unittest.cc
index f4a7c9495ed89a496ea9edafa657c00063035247..40e6fbf644bdf4ac8024259534fed9b01126c70d 100644
--- a/base/metrics/sparse_histogram_unittest.cc
+++ b/base/metrics/sparse_histogram_unittest.cc
@@ -327,4 +327,41 @@ TEST_P(SparseHistogramTest, FactoryTime) {
<< "ns each.";
}
+TEST_P(SparseHistogramTest, ExtremeValues) {
+ static const struct {
+ Histogram::Sample sample;
+ int64_t expected_max;
+ } cases[] = {
+ // Note: We use -2147483647 - 1 rather than -2147483648 because the later
+ // is interpreted as - operator applied to 2147483648 and the latter can't
+ // be represented as an int32 and causes a warning.
+ {-2147483647 - 1, -2147483647LL},
+ {0, 1},
+ {2147483647, 2147483648LL},
+ };
+
+ for (size_t i = 0; i < arraysize(cases); ++i) {
+ HistogramBase* histogram =
+ SparseHistogram::FactoryGet(StringPrintf("ExtremeValues_%zu", i),
+ HistogramBase::kUmaTargetedHistogramFlag);
+ histogram->Add(cases[i].sample);
+
+ std::unique_ptr<HistogramSamples> snapshot = histogram->SnapshotSamples();
+ std::unique_ptr<SampleCountIterator> it = snapshot->Iterator();
+ ASSERT_FALSE(it->Done());
+
+ base::Histogram::Sample min;
+ int64_t max;
+ base::Histogram::Count count;
+ it->Get(&min, &max, &count);
+
+ EXPECT_EQ(1, count);
+ EXPECT_EQ(cases[i].sample, min);
+ EXPECT_EQ(cases[i].expected_max, max);
+
+ it->Next();
+ EXPECT_TRUE(it->Done());
+ }
+}
+
} // namespace base
« no previous file with comments | « base/metrics/sparse_histogram.cc ('k') | chrome/browser/ui/webui/task_scheduler_internals/task_scheduler_internals_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698