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

Side by Side Diff: webrtc/system_wrappers/source/metrics_unittest.cc

Issue 1567013004: Add helper macros for calling a histogram with different names. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #include "webrtc/system_wrappers/include/metrics.h" 13 #include "webrtc/system_wrappers/include/metrics.h"
14 #include "webrtc/test/histogram.h" 14 #include "webrtc/test/histogram.h"
15 15
16 namespace webrtc { 16 namespace webrtc {
17 namespace { 17 namespace {
18 const int kSample = 22; 18 const int kSample = 22;
19 const std::string kName = "Name"; 19 const std::string kName = "Name";
20 20
21 void AddSparseSample(const std::string& name, int sample) { 21 void AddSparseSample(const std::string& name, int sample) {
22 RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample); 22 RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample);
23 } 23 }
24 void AddSampleWithVaryingName(int index, const std::string& name, int sample) {
25 RTC_HISTOGRAMS_COUNTS_100(index, name, sample);
26 }
24 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 27 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
25 void AddSample(const std::string& name, int sample) { 28 void AddSample(const std::string& name, int sample) {
26 RTC_HISTOGRAM_COUNTS_100(name, sample); 29 RTC_HISTOGRAM_COUNTS_100(name, sample);
27 } 30 }
28 #endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 31 #endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
29 } // namespace 32 } // namespace
30 33
31 TEST(MetricsTest, InitiallyNoSamples) { 34 TEST(MetricsTest, InitiallyNoSamples) {
32 test::ClearHistograms(); 35 test::ClearHistograms();
33 EXPECT_EQ(0, test::NumHistogramSamples(kName)); 36 EXPECT_EQ(0, test::NumHistogramSamples(kName));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 TEST(MetricsTest, RtcHistogramCounts_AddMultipleSamples) { 68 TEST(MetricsTest, RtcHistogramCounts_AddMultipleSamples) {
66 test::ClearHistograms(); 69 test::ClearHistograms();
67 const int kNumSamples = 10; 70 const int kNumSamples = 10;
68 for (int i = 0; i < kNumSamples; ++i) { 71 for (int i = 0; i < kNumSamples; ++i) {
69 RTC_HISTOGRAM_COUNTS_100(kName, i); 72 RTC_HISTOGRAM_COUNTS_100(kName, i);
70 } 73 }
71 EXPECT_EQ(kNumSamples, test::NumHistogramSamples(kName)); 74 EXPECT_EQ(kNumSamples, test::NumHistogramSamples(kName));
72 EXPECT_EQ(kNumSamples - 1, test::LastHistogramSample(kName)); 75 EXPECT_EQ(kNumSamples - 1, test::LastHistogramSample(kName));
73 } 76 }
74 77
78 TEST(MetricsTest, RtcHistogramsCounts_AddSample) {
79 test::ClearHistograms();
80 AddSampleWithVaryingName(0, "Name1", kSample);
81 AddSampleWithVaryingName(1, "Name2", kSample + 1);
82 AddSampleWithVaryingName(2, "Name3", kSample + 2);
83 EXPECT_EQ(1, test::NumHistogramSamples("Name1"));
84 EXPECT_EQ(1, test::NumHistogramSamples("Name2"));
85 EXPECT_EQ(1, test::NumHistogramSamples("Name3"));
86 EXPECT_EQ(kSample + 0, test::LastHistogramSample("Name1"));
87 EXPECT_EQ(kSample + 1, test::LastHistogramSample("Name2"));
88 EXPECT_EQ(kSample + 2, test::LastHistogramSample("Name3"));
89 }
90
75 TEST(MetricsTest, RtcHistogramSparse_NonConstantNameWorks) { 91 TEST(MetricsTest, RtcHistogramSparse_NonConstantNameWorks) {
76 test::ClearHistograms(); 92 test::ClearHistograms();
77 AddSparseSample("Name1", kSample); 93 AddSparseSample("Name1", kSample);
78 AddSparseSample("Name2", kSample); 94 AddSparseSample("Name2", kSample);
79 EXPECT_EQ(1, test::NumHistogramSamples("Name1")); 95 EXPECT_EQ(1, test::NumHistogramSamples("Name1"));
80 EXPECT_EQ(1, test::NumHistogramSamples("Name2")); 96 EXPECT_EQ(1, test::NumHistogramSamples("Name2"));
81 } 97 }
82 98
83 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 99 #if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
84 TEST(MetricsTest, RtcHistogram_FailsForNonConstantName) { 100 TEST(MetricsTest, RtcHistogram_FailsForNonConstantName) {
85 test::ClearHistograms(); 101 test::ClearHistograms();
86 AddSample("Name1", kSample); 102 AddSample("Name1", kSample);
87 EXPECT_DEATH(AddSample("Name2", kSample), ""); 103 EXPECT_DEATH(AddSample("Name2", kSample), "");
88 } 104 }
89 #endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 105 #endif // GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
90 106
91 } // namespace webrtc 107 } // namespace webrtc
OLDNEW
« webrtc/system_wrappers/include/metrics.h ('K') | « webrtc/system_wrappers/include/metrics.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698