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

Side by Side Diff: base/metrics/statistics_recorder_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: rebased 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 unified diff | Download patch
« no previous file with comments | « base/metrics/statistics_recorder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/statistics_recorder.h" 5 #include "base/metrics/statistics_recorder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 18 matching lines...) Expand all
29 // registered). 29 // registered).
30 InitializeStatisticsRecorder(); 30 InitializeStatisticsRecorder();
31 } 31 }
32 32
33 void TearDown() override { 33 void TearDown() override {
34 UninitializeStatisticsRecorder(); 34 UninitializeStatisticsRecorder();
35 GlobalHistogramAllocator::ReleaseForTesting(); 35 GlobalHistogramAllocator::ReleaseForTesting();
36 } 36 }
37 37
38 void InitializeStatisticsRecorder() { 38 void InitializeStatisticsRecorder() {
39 statistics_recorder_ = new StatisticsRecorder(); 39 DCHECK(!statistics_recorder_);
40 StatisticsRecorder::UninitializeForTesting();
41 statistics_recorder_.reset(new StatisticsRecorder());
40 } 42 }
41 43
42 void UninitializeStatisticsRecorder() { 44 void UninitializeStatisticsRecorder() {
43 delete statistics_recorder_; 45 statistics_recorder_.reset();
44 statistics_recorder_ = NULL;
45 } 46 }
46 47
47 Histogram* CreateHistogram(const std::string& name, 48 Histogram* CreateHistogram(const std::string& name,
48 HistogramBase::Sample min, 49 HistogramBase::Sample min,
49 HistogramBase::Sample max, 50 HistogramBase::Sample max,
50 size_t bucket_count) { 51 size_t bucket_count) {
51 BucketRanges* ranges = new BucketRanges(bucket_count + 1); 52 BucketRanges* ranges = new BucketRanges(bucket_count + 1);
52 Histogram::InitializeBucketRanges(min, max, ranges); 53 Histogram::InitializeBucketRanges(min, max, ranges);
53 const BucketRanges* registered_ranges = 54 const BucketRanges* registered_ranges =
54 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges); 55 StatisticsRecorder::RegisterOrDeleteDuplicateRanges(ranges);
55 return new Histogram(name, min, max, registered_ranges); 56 return new Histogram(name, min, max, registered_ranges);
56 } 57 }
57 58
58 void DeleteHistogram(HistogramBase* histogram) { 59 void DeleteHistogram(HistogramBase* histogram) {
59 delete histogram; 60 delete histogram;
60 } 61 }
61 62
62 StatisticsRecorder* statistics_recorder_; 63 std::unique_ptr<StatisticsRecorder> statistics_recorder_;
63 }; 64 };
64 65
65 TEST_F(StatisticsRecorderTest, NotInitialized) { 66 TEST_F(StatisticsRecorderTest, NotInitialized) {
66 UninitializeStatisticsRecorder(); 67 UninitializeStatisticsRecorder();
68 StatisticsRecorder::UninitializeForTesting();
Alexei Svitkine (slow) 2016/04/08 15:04:19 Shouldn't this be part of UninitializeStatisticsRe
bcwhite 2016/04/08 16:06:33 It's not generally important since it's just a sta
67 69
68 ASSERT_FALSE(StatisticsRecorder::IsActive()); 70 ASSERT_FALSE(StatisticsRecorder::IsActive());
69 71
70 StatisticsRecorder::Histograms registered_histograms; 72 StatisticsRecorder::Histograms registered_histograms;
71 std::vector<const BucketRanges*> registered_ranges; 73 std::vector<const BucketRanges*> registered_ranges;
72 74
73 StatisticsRecorder::GetHistograms(&registered_histograms); 75 StatisticsRecorder::GetHistograms(&registered_histograms);
74 EXPECT_EQ(0u, registered_histograms.size()); 76 EXPECT_EQ(0u, registered_histograms.size());
75 77
76 Histogram* histogram = CreateHistogram("TestHistogram", 1, 1000, 10); 78 Histogram* histogram = CreateHistogram("TestHistogram", 1, 1000, 10);
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10, 509 HistogramBase* histogram = Histogram::FactoryGet("TestHistogram", 1, 1000, 10,
508 HistogramBase::kNoFlags); 510 HistogramBase::kNoFlags);
509 EXPECT_TRUE(histogram); 511 EXPECT_TRUE(histogram);
510 histogram->Add(1); 512 histogram->Add(1);
511 513
512 EXPECT_TRUE(callback_wrapper.called); 514 EXPECT_TRUE(callback_wrapper.called);
513 EXPECT_EQ(callback_wrapper.last_histogram_value, 1); 515 EXPECT_EQ(callback_wrapper.last_histogram_value, 1);
514 } 516 }
515 517
516 } // namespace base 518 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/statistics_recorder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698