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

Unified Diff: base/metrics/histogram_unittest.cc

Issue 1779503002: Fix StatisticsRecorder to handle re-entry during tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: always do global UninitializeForTesting when uninitializing Created 4 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
« no previous file with comments | « no previous file | base/metrics/sparse_histogram_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_unittest.cc
diff --git a/base/metrics/histogram_unittest.cc b/base/metrics/histogram_unittest.cc
index da11513346a833b0a7525d4e209bf1f76eb01add..58b72480018591f72679a6e1ff036727f25ada2c 100644
--- a/base/metrics/histogram_unittest.cc
+++ b/base/metrics/histogram_unittest.cc
@@ -55,13 +55,12 @@ class HistogramTest : public testing::TestWithParam<bool> {
}
void InitializeStatisticsRecorder() {
- StatisticsRecorder::ResetForTesting();
- statistics_recorder_ = new StatisticsRecorder();
+ DCHECK(!statistics_recorder_);
+ statistics_recorder_.reset(new StatisticsRecorder());
}
void UninitializeStatisticsRecorder() {
- delete statistics_recorder_;
- statistics_recorder_ = NULL;
+ statistics_recorder_.reset();
}
void CreatePersistentHistogramAllocator() {
@@ -82,7 +81,7 @@ class HistogramTest : public testing::TestWithParam<bool> {
const bool use_persistent_histogram_allocator_;
- StatisticsRecorder* statistics_recorder_ = nullptr;
+ std::unique_ptr<StatisticsRecorder> statistics_recorder_;
std::unique_ptr<char[]> allocator_memory_;
PersistentMemoryAllocator* allocator_ = nullptr;
@@ -112,6 +111,14 @@ TEST_P(HistogramTest, BasicTest) {
"TestCustomHistogram", custom_ranges, HistogramBase::kNoFlags);
EXPECT_TRUE(custom_histogram);
+ // Macros that create hitograms have an internal static variable which will
+ // continue to point to those from the very first run of this method even
+ // during subsequent runs.
+ static bool already_run = false;
+ if (already_run)
+ return;
+ already_run = true;
+
// Use standard macros (but with fixed samples)
LOCAL_HISTOGRAM_TIMES("Test2Histogram", TimeDelta::FromDays(1));
LOCAL_HISTOGRAM_COUNTS("Test3Histogram", 30);
@@ -436,6 +443,13 @@ TEST_P(HistogramTest, BucketPlacementTest) {
}
TEST_P(HistogramTest, CorruptSampleCounts) {
+ // The internal code creates histograms via macros and thus keeps static
+ // pointers to them. If those pointers are to persistent memory which will
+ // be free'd then any following calls to that code will crash with a
+ // segmentation violation.
+ if (use_persistent_histogram_allocator_)
+ return;
+
Histogram* histogram = static_cast<Histogram*>(
Histogram::FactoryGet("Histogram", 1, 64, 8, HistogramBase::kNoFlags));
« no previous file with comments | « no previous file | base/metrics/sparse_histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698