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

Side by Side Diff: metrics_daemon_test.cc

Issue 3171023: Add weekly crash counters, refactor metrics_daemon, respect opt-in in library. (Closed) Base URL: http://src.chromium.org/git/metrics.git
Patch Set: Respond to review Created 10 years, 3 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 | « metrics_daemon.cc ('k') | metrics_library.h » ('j') | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <utime.h>
6
5 #include <base/file_util.h> 7 #include <base/file_util.h>
6 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
7 9
8 #include "counter_mock.h" 10 #include "counter_mock.h"
9 #include "metrics_daemon.h" 11 #include "metrics_daemon.h"
10 #include "metrics_library_mock.h" 12 #include "metrics_library_mock.h"
11 13
12 using base::Time; 14 using base::Time;
13 using base::TimeTicks; 15 using base::TimeTicks;
16 using chromeos_metrics::FrequencyCounter;
14 using chromeos_metrics::FrequencyCounterMock; 17 using chromeos_metrics::FrequencyCounterMock;
15 using chromeos_metrics::TaggedCounterMock; 18 using chromeos_metrics::TaggedCounterMock;
19 using chromeos_metrics::TaggedCounterReporter;
20 using chromeos_metrics::TaggedCounterReporterMock;
16 using ::testing::_; 21 using ::testing::_;
17 using ::testing::Return; 22 using ::testing::Return;
18 using ::testing::StrictMock; 23 using ::testing::StrictMock;
19 24
20 static const int kSecondsPerDay = 24 * 60 * 60; 25 static const int kSecondsPerDay = 24 * 60 * 60;
21 26
27 static const char kTestDir[] = "test";
28 static const char kLastFile[] = "test/last";
29 static const char kCurrentFile[] = "test/current";
30
22 // This class allows a TimeTicks object to be initialized with seconds 31 // This class allows a TimeTicks object to be initialized with seconds
23 // (rather than microseconds) through the protected TimeTicks(int64) 32 // (rather than microseconds) through the protected TimeTicks(int64)
24 // constructor. 33 // constructor.
25 class TestTicks : public TimeTicks { 34 class TestTicks : public TimeTicks {
26 public: 35 public:
27 TestTicks(int64 seconds) 36 TestTicks(int64 seconds)
28 : TimeTicks(seconds * Time::kMicrosecondsPerSecond) {} 37 : TimeTicks(seconds * Time::kMicrosecondsPerSecond) {}
29 }; 38 };
30 39
31 // Overloaded for test failure printing purposes. 40 // Overloaded for test failure printing purposes.
32 static std::ostream& operator<<(std::ostream& o, const TimeTicks& ticks) { 41 static std::ostream& operator<<(std::ostream& o, const TimeTicks& ticks) {
33 o << ticks.ToInternalValue() << "us"; 42 o << ticks.ToInternalValue() << "us";
34 return o; 43 return o;
35 }; 44 };
36 45
37 // Overloaded for test failure printing purposes. 46 // Overloaded for test failure printing purposes.
38 static std::ostream& operator<<(std::ostream& o, const Time& time) { 47 static std::ostream& operator<<(std::ostream& o, const Time& time) {
39 o << time.ToInternalValue() << "us"; 48 o << time.ToInternalValue() << "us";
40 return o; 49 return o;
41 }; 50 };
42 51
43 class MetricsDaemonTest : public testing::Test { 52 class MetricsDaemonTest : public testing::Test {
44 protected: 53 protected:
45 virtual void SetUp() { 54 virtual void SetUp() {
46 EXPECT_EQ(NULL, daemon_.daily_use_.get()); 55 EXPECT_EQ(NULL, daemon_.daily_use_.get());
47 EXPECT_EQ(NULL, daemon_.kernel_crash_interval_.get()); 56 EXPECT_EQ(NULL, daemon_.kernel_crash_interval_.get());
48 EXPECT_EQ(NULL, daemon_.user_crash_interval_.get()); 57 EXPECT_EQ(NULL, daemon_.user_crash_interval_.get());
49 daemon_.Init(true, &metrics_lib_); 58 daemon_.Init(true, &metrics_lib_);
50 59
60 // Check configuration of a few histograms.
61 FrequencyCounter* frequency_counter =
62 daemon_.frequency_counters_[MetricsDaemon::kMetricAnyCrashesDailyName];
63 const TaggedCounterReporter* reporter = GetReporter(frequency_counter);
64 EXPECT_EQ(MetricsDaemon::kMetricAnyCrashesDailyName,
65 reporter->histogram_name());
66 EXPECT_EQ(chromeos_metrics::kSecondsPerDay,
67 frequency_counter->cycle_duration());
68 EXPECT_EQ(MetricsDaemon::kMetricCrashFrequencyMin, reporter->min());
69 EXPECT_EQ(MetricsDaemon::kMetricCrashFrequencyMax, reporter->max());
70 EXPECT_EQ(MetricsDaemon::kMetricCrashFrequencyBuckets, reporter->buckets());
71
72 frequency_counter =
73 daemon_.frequency_counters_[MetricsDaemon::kMetricAnyCrashesWeeklyName];
74 reporter = GetReporter(frequency_counter);
75 EXPECT_EQ(MetricsDaemon::kMetricAnyCrashesWeeklyName,
76 reporter->histogram_name());
77 EXPECT_EQ(chromeos_metrics::kSecondsPerWeek,
78 frequency_counter->cycle_duration());
79
80 EXPECT_EQ(MetricsDaemon::kMetricKernelCrashIntervalName,
81 daemon_.kernel_crash_interval_->histogram_name());
82 EXPECT_EQ(MetricsDaemon::kMetricCrashIntervalMin,
83 daemon_.kernel_crash_interval_->min());
84 EXPECT_EQ(MetricsDaemon::kMetricCrashIntervalMax,
85 daemon_.kernel_crash_interval_->max());
86 EXPECT_EQ(MetricsDaemon::kMetricCrashIntervalBuckets,
87 daemon_.kernel_crash_interval_->buckets());
88
89 EXPECT_EQ(MetricsDaemon::kMetricUncleanShutdownIntervalName,
90 daemon_.unclean_shutdown_interval_->histogram_name());
91
51 // Tests constructor initialization. Switches to mock counters. 92 // Tests constructor initialization. Switches to mock counters.
52 EXPECT_TRUE(NULL != daemon_.daily_use_.get()); 93 EXPECT_TRUE(NULL != daemon_.daily_use_.get());
53 EXPECT_TRUE(NULL != daemon_.kernel_crash_interval_.get()); 94 EXPECT_TRUE(NULL != daemon_.kernel_crash_interval_.get());
54 EXPECT_TRUE(NULL != daemon_.user_crash_interval_.get()); 95 EXPECT_TRUE(NULL != daemon_.user_crash_interval_.get());
55 96
56 // Allocates mock counter and transfers ownership. 97 // Allocates mock counter and transfers ownership.
57 daily_use_ = new StrictMock<TaggedCounterMock>(); 98 daily_use_ = new StrictMock<TaggedCounterMock>();
58 daemon_.daily_use_.reset(daily_use_); 99 daemon_.daily_use_.reset(daily_use_);
59 kernel_crash_interval_ = new StrictMock<TaggedCounterMock>(); 100 kernel_crash_interval_ = new StrictMock<TaggedCounterReporterMock>();
60 daemon_.kernel_crash_interval_.reset(kernel_crash_interval_); 101 daemon_.kernel_crash_interval_.reset(kernel_crash_interval_);
61 user_crash_interval_ = new StrictMock<TaggedCounterMock>(); 102 user_crash_interval_ = new StrictMock<TaggedCounterReporterMock>();
62 daemon_.user_crash_interval_.reset(user_crash_interval_); 103 daemon_.user_crash_interval_.reset(user_crash_interval_);
63 unclean_shutdown_interval_ = new StrictMock<TaggedCounterMock>(); 104 unclean_shutdown_interval_ = new StrictMock<TaggedCounterReporterMock>();
64 daemon_.unclean_shutdown_interval_.reset(unclean_shutdown_interval_); 105 daemon_.unclean_shutdown_interval_.reset(unclean_shutdown_interval_);
65 kernel_crashes_daily_ = new StrictMock<FrequencyCounterMock>(); 106
66 daemon_.kernel_crashes_daily_.reset(kernel_crashes_daily_); 107 // Reset all frequency counter reporters to mocks for further testing.
67 user_crashes_daily_ = new StrictMock<FrequencyCounterMock>(); 108 MetricsDaemon::FrequencyCounters::iterator i;
68 daemon_.user_crashes_daily_.reset(user_crashes_daily_); 109 for (i = daemon_.frequency_counters_.begin();
69 unclean_shutdowns_daily_ = new StrictMock<FrequencyCounterMock>(); 110 i != daemon_.frequency_counters_.end(); ++i) {
70 daemon_.unclean_shutdowns_daily_.reset(unclean_shutdowns_daily_); 111 delete i->second;
71 any_crashes_daily_ = new StrictMock<FrequencyCounterMock>(); 112 i->second = new StrictMock<FrequencyCounterMock>();
72 daemon_.any_crashes_daily_.reset(any_crashes_daily_); 113 }
73 114
74 EXPECT_FALSE(daemon_.user_active_); 115 EXPECT_FALSE(daemon_.user_active_);
75 EXPECT_TRUE(daemon_.user_active_last_.is_null()); 116 EXPECT_TRUE(daemon_.user_active_last_.is_null());
76 EXPECT_EQ(MetricsDaemon::kUnknownNetworkState, daemon_.network_state_); 117 EXPECT_EQ(MetricsDaemon::kUnknownNetworkState, daemon_.network_state_);
77 EXPECT_TRUE(daemon_.network_state_last_.is_null()); 118 EXPECT_TRUE(daemon_.network_state_last_.is_null());
78 EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_); 119 EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_);
79 EXPECT_EQ(MetricsDaemon::kUnknownSessionState, daemon_.session_state_); 120 EXPECT_EQ(MetricsDaemon::kUnknownSessionState, daemon_.session_state_);
121
122 file_util::Delete(FilePath(kTestDir), true);
123 file_util::CreateDirectory(FilePath(kTestDir));
80 } 124 }
81 125
82 virtual void TearDown() {} 126 virtual void TearDown() {}
83 127
128 const TaggedCounterReporter*
129 GetReporter(FrequencyCounter* frequency_counter) const {
130 return static_cast<const TaggedCounterReporter*>(
131 &frequency_counter->tagged_counter());
132 }
133
134 void ExpectFrequencyFlushCalls() {
135 MetricsDaemon::FrequencyCounters::iterator i;
136 for (i = daemon_.frequency_counters_.begin();
137 i != daemon_.frequency_counters_.end(); ++i) {
138 FrequencyCounterMock* mock =
139 static_cast<FrequencyCounterMock*>(i->second);
140 EXPECT_CALL(*mock, FlushFinishedCycles());
141 }
142 }
143
84 // Adds active use aggregation counters update expectations that the 144 // Adds active use aggregation counters update expectations that the
85 // specified tag/count update will be generated. 145 // specified tag/count update will be generated.
86 void ExpectActiveUseUpdate(int daily_tag, int count) { 146 void ExpectActiveUseUpdate(int daily_tag, int count) {
87 EXPECT_CALL(*daily_use_, Update(daily_tag, count)) 147 EXPECT_CALL(*daily_use_, Update(daily_tag, count))
88 .Times(1) 148 .Times(1)
89 .RetiresOnSaturation(); 149 .RetiresOnSaturation();
90 EXPECT_CALL(*kernel_crash_interval_, Update(0, count)) 150 EXPECT_CALL(*kernel_crash_interval_, Update(0, count))
91 .Times(1) 151 .Times(1)
92 .RetiresOnSaturation(); 152 .RetiresOnSaturation();
93 EXPECT_CALL(*user_crash_interval_, Update(0, count)) 153 EXPECT_CALL(*user_crash_interval_, Update(0, count))
94 .Times(1) 154 .Times(1)
95 .RetiresOnSaturation(); 155 .RetiresOnSaturation();
156 ExpectFrequencyFlushCalls();
96 } 157 }
97 158
98 // Adds active use aggregation counters update expectations that 159 // Adds active use aggregation counters update expectations that
99 // ignore the update arguments. 160 // ignore the update arguments.
100 void IgnoreActiveUseUpdate() { 161 void IgnoreActiveUseUpdate() {
101 EXPECT_CALL(*daily_use_, Update(_, _)) 162 EXPECT_CALL(*daily_use_, Update(_, _))
102 .Times(1) 163 .Times(1)
103 .RetiresOnSaturation(); 164 .RetiresOnSaturation();
104 EXPECT_CALL(*kernel_crash_interval_, Update(_, _)) 165 EXPECT_CALL(*kernel_crash_interval_, Update(_, _))
105 .Times(1) 166 .Times(1)
106 .RetiresOnSaturation(); 167 .RetiresOnSaturation();
107 EXPECT_CALL(*user_crash_interval_, Update(_, _)) 168 EXPECT_CALL(*user_crash_interval_, Update(_, _))
108 .Times(1) 169 .Times(1)
109 .RetiresOnSaturation(); 170 .RetiresOnSaturation();
171 ExpectFrequencyFlushCalls();
110 } 172 }
111 173
112 // Adds a metrics library mock expectation that the specified metric 174 // Adds a metrics library mock expectation that the specified metric
113 // will be generated. 175 // will be generated.
114 void ExpectMetric(const std::string& name, int sample, 176 void ExpectMetric(const std::string& name, int sample,
115 int min, int max, int buckets) { 177 int min, int max, int buckets) {
116 EXPECT_CALL(metrics_lib_, SendToUMA(name, sample, min, max, buckets)) 178 EXPECT_CALL(metrics_lib_, SendToUMA(name, sample, min, max, buckets))
117 .Times(1) 179 .Times(1)
118 .WillOnce(Return(true)) 180 .WillOnce(Return(true))
119 .RetiresOnSaturation(); 181 .RetiresOnSaturation();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &arg_value_c); 225 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &arg_value_c);
164 return msg; 226 return msg;
165 } 227 }
166 228
167 // Deallocates the DBus message |msg| previously allocated through 229 // Deallocates the DBus message |msg| previously allocated through
168 // dbus_message_new*. 230 // dbus_message_new*.
169 void DeleteDBusMessage(DBusMessage* msg) { 231 void DeleteDBusMessage(DBusMessage* msg) {
170 dbus_message_unref(msg); 232 dbus_message_unref(msg);
171 } 233 }
172 234
235 // Get the frequency counter for the given name.
236 FrequencyCounterMock& GetFrequencyMock(const char* histogram_name) {
237 return *static_cast<FrequencyCounterMock*>(
238 daemon_.frequency_counters_[histogram_name]);
239 }
240
173 // The MetricsDaemon under test. 241 // The MetricsDaemon under test.
174 MetricsDaemon daemon_; 242 MetricsDaemon daemon_;
175 243
176 // Metrics library mock. It's a strict mock so that all unexpected 244 // Metrics library mock. It's a strict mock so that all unexpected
177 // metric generation calls are marked as failures. 245 // metric generation calls are marked as failures.
178 StrictMock<MetricsLibraryMock> metrics_lib_; 246 StrictMock<MetricsLibraryMock> metrics_lib_;
179 247
180 // Counter mocks. They are strict mocks so that all unexpected 248 // Counter mocks. They are strict mocks so that all unexpected
181 // update calls are marked as failures. They are pointers so that 249 // update calls are marked as failures. They are pointers so that
182 // they can replace the scoped_ptr's allocated by the daemon. 250 // they can replace the scoped_ptr's allocated by the daemon.
183 StrictMock<TaggedCounterMock>* daily_use_; 251 StrictMock<TaggedCounterMock>* daily_use_;
184 StrictMock<TaggedCounterMock>* kernel_crash_interval_; 252 StrictMock<TaggedCounterReporterMock>* kernel_crash_interval_;
185 StrictMock<TaggedCounterMock>* user_crash_interval_; 253 StrictMock<TaggedCounterReporterMock>* user_crash_interval_;
186 StrictMock<TaggedCounterMock>* unclean_shutdown_interval_; 254 StrictMock<TaggedCounterReporterMock>* unclean_shutdown_interval_;
187
188 StrictMock<FrequencyCounterMock>* kernel_crashes_daily_;
189 StrictMock<FrequencyCounterMock>* user_crashes_daily_;
190 StrictMock<FrequencyCounterMock>* unclean_shutdowns_daily_;
191 StrictMock<FrequencyCounterMock>* any_crashes_daily_;
192 }; 255 };
193 256
194 TEST_F(MetricsDaemonTest, CheckSystemCrash) { 257 TEST_F(MetricsDaemonTest, CheckSystemCrash) {
195 static const char kKernelCrashDetected[] = "test-kernel-crash-detected"; 258 static const char kKernelCrashDetected[] = "test-kernel-crash-detected";
196 EXPECT_FALSE(daemon_.CheckSystemCrash(kKernelCrashDetected)); 259 EXPECT_FALSE(daemon_.CheckSystemCrash(kKernelCrashDetected));
197 260
198 FilePath crash_detected(kKernelCrashDetected); 261 FilePath crash_detected(kKernelCrashDetected);
199 file_util::WriteFile(crash_detected, "", 0); 262 file_util::WriteFile(crash_detected, "", 0);
200 EXPECT_TRUE(file_util::PathExists(crash_detected)); 263 EXPECT_TRUE(file_util::PathExists(crash_detected));
201 EXPECT_TRUE(daemon_.CheckSystemCrash(kKernelCrashDetected)); 264 EXPECT_TRUE(daemon_.CheckSystemCrash(kKernelCrashDetected));
202 EXPECT_FALSE(file_util::PathExists(crash_detected)); 265 EXPECT_FALSE(file_util::PathExists(crash_detected));
203 EXPECT_FALSE(daemon_.CheckSystemCrash(kKernelCrashDetected)); 266 EXPECT_FALSE(daemon_.CheckSystemCrash(kKernelCrashDetected));
204 EXPECT_FALSE(file_util::PathExists(crash_detected)); 267 EXPECT_FALSE(file_util::PathExists(crash_detected));
205 file_util::Delete(crash_detected, false); 268 file_util::Delete(crash_detected, false);
206 } 269 }
207 270
208 TEST_F(MetricsDaemonTest, ReportDailyUse) { 271 TEST_F(MetricsDaemonTest, ReportDailyUse) {
209 ExpectDailyUseTimeMetric(/* sample */ 2); 272 ExpectDailyUseTimeMetric(/* sample */ 2);
210 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 20, /* count */ 90); 273 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 20, /* count */ 90);
211 274
212 ExpectDailyUseTimeMetric(/* sample */ 1); 275 ExpectDailyUseTimeMetric(/* sample */ 1);
213 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 23, /* count */ 89); 276 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 23, /* count */ 89);
214 277
215 // There should be no metrics generated for the calls below. 278 // There should be no metrics generated for the calls below.
216 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 50, /* count */ 0); 279 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 50, /* count */ 0);
217 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 60, /* count */ -5); 280 MetricsDaemon::ReportDailyUse(&daemon_, /* tag */ 60, /* count */ -5);
218 } 281 }
219 282
220 TEST_F(MetricsDaemonTest, ReportKernelCrashInterval) {
221 ExpectMetric(MetricsDaemon::kMetricKernelCrashIntervalName, 50,
222 MetricsDaemon::kMetricCrashIntervalMin,
223 MetricsDaemon::kMetricCrashIntervalMax,
224 MetricsDaemon::kMetricCrashIntervalBuckets);
225 MetricsDaemon::ReportKernelCrashInterval(&daemon_, 0, 50);
226 }
227
228 TEST_F(MetricsDaemonTest, ReportUncleanShutdownInterval) {
229 ExpectMetric(MetricsDaemon::kMetricUncleanShutdownIntervalName, 50,
230 MetricsDaemon::kMetricCrashIntervalMin,
231 MetricsDaemon::kMetricCrashIntervalMax,
232 MetricsDaemon::kMetricCrashIntervalBuckets);
233 MetricsDaemon::ReportUncleanShutdownInterval(&daemon_, 0, 50);
234 }
235
236 TEST_F(MetricsDaemonTest, LookupNetworkState) { 283 TEST_F(MetricsDaemonTest, LookupNetworkState) {
237 EXPECT_EQ(MetricsDaemon::kNetworkStateOnline, 284 EXPECT_EQ(MetricsDaemon::kNetworkStateOnline,
238 daemon_.LookupNetworkState("online")); 285 daemon_.LookupNetworkState("online"));
239 EXPECT_EQ(MetricsDaemon::kNetworkStateOffline, 286 EXPECT_EQ(MetricsDaemon::kNetworkStateOffline,
240 daemon_.LookupNetworkState("offline")); 287 daemon_.LookupNetworkState("offline"));
241 EXPECT_EQ(MetricsDaemon::kUnknownNetworkState, 288 EXPECT_EQ(MetricsDaemon::kUnknownNetworkState,
242 daemon_.LookupNetworkState("somestate")); 289 daemon_.LookupNetworkState("somestate"));
243 } 290 }
244 291
245 TEST_F(MetricsDaemonTest, LookupPowerState) { 292 TEST_F(MetricsDaemonTest, LookupPowerState) {
(...skipping 15 matching lines...) Expand all
261 } 308 }
262 309
263 TEST_F(MetricsDaemonTest, MessageFilter) { 310 TEST_F(MetricsDaemonTest, MessageFilter) {
264 DBusMessage* msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL); 311 DBusMessage* msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL);
265 DBusHandlerResult res = 312 DBusHandlerResult res =
266 MetricsDaemon::MessageFilter(/* connection */ NULL, msg, &daemon_); 313 MetricsDaemon::MessageFilter(/* connection */ NULL, msg, &daemon_);
267 EXPECT_EQ(DBUS_HANDLER_RESULT_NOT_YET_HANDLED, res); 314 EXPECT_EQ(DBUS_HANDLER_RESULT_NOT_YET_HANDLED, res);
268 DeleteDBusMessage(msg); 315 DeleteDBusMessage(msg);
269 316
270 IgnoreActiveUseUpdate(); 317 IgnoreActiveUseUpdate();
318 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesDailyName),
319 Update(1))
320 .Times(1)
321 .RetiresOnSaturation();
322 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesWeeklyName),
323 Update(1))
324 .Times(1)
325 .RetiresOnSaturation();
326 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricUserCrashesDailyName),
327 Update(1))
328 .Times(1)
329 .RetiresOnSaturation();
330 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricUserCrashesWeeklyName),
331 Update(1))
332 .Times(1)
333 .RetiresOnSaturation();
271 EXPECT_CALL(*user_crash_interval_, Flush()) 334 EXPECT_CALL(*user_crash_interval_, Flush())
272 .Times(1) 335 .Times(1)
273 .RetiresOnSaturation(); 336 .RetiresOnSaturation();
274 EXPECT_CALL(*user_crashes_daily_, Update(1))
275 .Times(1)
276 .RetiresOnSaturation();
277 EXPECT_CALL(*any_crashes_daily_, Update(1))
278 .Times(1)
279 .RetiresOnSaturation();
280 msg = NewDBusSignalString("/", 337 msg = NewDBusSignalString("/",
281 "org.chromium.CrashReporter", 338 "org.chromium.CrashReporter",
282 "UserCrash", 339 "UserCrash",
283 ""); 340 "");
284 res = MetricsDaemon::MessageFilter(/* connection */ NULL, msg, &daemon_); 341 res = MetricsDaemon::MessageFilter(/* connection */ NULL, msg, &daemon_);
285 EXPECT_EQ(DBUS_HANDLER_RESULT_HANDLED, res); 342 EXPECT_EQ(DBUS_HANDLER_RESULT_HANDLED, res);
286 DeleteDBusMessage(msg); 343 DeleteDBusMessage(msg);
287 344
288 msg = NewDBusSignalString("/", 345 msg = NewDBusSignalString("/",
289 "org.chromium.flimflam.Manager", 346 "org.chromium.flimflam.Manager",
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_); 460 EXPECT_EQ(MetricsDaemon::kUnknownPowerState, daemon_.power_state_);
404 EXPECT_FALSE(daemon_.user_active_); 461 EXPECT_FALSE(daemon_.user_active_);
405 EXPECT_EQ(TestTime(7 * kSecondsPerDay + 185), daemon_.user_active_last_); 462 EXPECT_EQ(TestTime(7 * kSecondsPerDay + 185), daemon_.user_active_last_);
406 } 463 }
407 464
408 TEST_F(MetricsDaemonTest, ProcessKernelCrash) { 465 TEST_F(MetricsDaemonTest, ProcessKernelCrash) {
409 IgnoreActiveUseUpdate(); 466 IgnoreActiveUseUpdate();
410 EXPECT_CALL(*kernel_crash_interval_, Flush()) 467 EXPECT_CALL(*kernel_crash_interval_, Flush())
411 .Times(1) 468 .Times(1)
412 .RetiresOnSaturation(); 469 .RetiresOnSaturation();
413 EXPECT_CALL(*kernel_crashes_daily_, Update(1)); 470 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesDailyName),
414 EXPECT_CALL(*any_crashes_daily_, Update(1)); 471 Update(1));
472 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesWeeklyName),
473 Update(1));
474 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricKernelCrashesDailyName),
475 Update(1));
476 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricKernelCrashesWeeklyName),
477 Update(1));
415 daemon_.ProcessKernelCrash(); 478 daemon_.ProcessKernelCrash();
416 } 479 }
417 480
418 TEST_F(MetricsDaemonTest, ProcessUncleanShutdown) { 481 TEST_F(MetricsDaemonTest, ProcessUncleanShutdown) {
419 IgnoreActiveUseUpdate(); 482 IgnoreActiveUseUpdate();
420 EXPECT_CALL(*unclean_shutdown_interval_, Flush()) 483 EXPECT_CALL(*unclean_shutdown_interval_, Flush())
421 .Times(1) 484 .Times(1)
422 .RetiresOnSaturation(); 485 .RetiresOnSaturation();
423 EXPECT_CALL(*unclean_shutdowns_daily_, Update(1)); 486 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesDailyName),
424 EXPECT_CALL(*any_crashes_daily_, Update(1)); 487 Update(1));
488 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesWeeklyName),
489 Update(1));
490 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricUncleanShutdownsDailyName),
491 Update(1));
492 EXPECT_CALL(
493 GetFrequencyMock(MetricsDaemon::kMetricUncleanShutdownsWeeklyName),
494 Update(1));
425 daemon_.ProcessUncleanShutdown(); 495 daemon_.ProcessUncleanShutdown();
426 } 496 }
427 497
428 TEST_F(MetricsDaemonTest, ProcessUserCrash) { 498 TEST_F(MetricsDaemonTest, ProcessUserCrash) {
429 IgnoreActiveUseUpdate(); 499 IgnoreActiveUseUpdate();
430 EXPECT_CALL(*user_crash_interval_, Flush()) 500 EXPECT_CALL(*user_crash_interval_, Flush())
431 .Times(1) 501 .Times(1)
432 .RetiresOnSaturation(); 502 .RetiresOnSaturation();
433 EXPECT_CALL(*user_crashes_daily_, Update(1)); 503 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesDailyName),
434 EXPECT_CALL(*any_crashes_daily_, Update(1)); 504 Update(1));
505 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricAnyCrashesWeeklyName),
506 Update(1));
507 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricUserCrashesDailyName),
508 Update(1));
509 EXPECT_CALL(GetFrequencyMock(MetricsDaemon::kMetricUserCrashesWeeklyName),
510 Update(1));
435 daemon_.ProcessUserCrash(); 511 daemon_.ProcessUserCrash();
436 } 512 }
437 513
438 TEST_F(MetricsDaemonTest, SendMetric) { 514 TEST_F(MetricsDaemonTest, SendMetric) {
439 ExpectMetric("Dummy.Metric", 3, 1, 100, 50); 515 ExpectMetric("Dummy.Metric", 3, 1, 100, 50);
440 daemon_.SendMetric("Dummy.Metric", /* sample */ 3, 516 daemon_.SendMetric("Dummy.Metric", /* sample */ 3,
441 /* min */ 1, /* max */ 100, /* buckets */ 50); 517 /* min */ 1, /* max */ 100, /* buckets */ 50);
442 } 518 }
443 519
444 TEST_F(MetricsDaemonTest, SessionStateChanged) { 520 TEST_F(MetricsDaemonTest, SessionStateChanged) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 EXPECT_TRUE(daemon_.user_active_); 583 EXPECT_TRUE(daemon_.user_active_);
508 EXPECT_EQ(TestTime(10 * kSecondsPerDay + 300), daemon_.user_active_last_); 584 EXPECT_EQ(TestTime(10 * kSecondsPerDay + 300), daemon_.user_active_last_);
509 585
510 ExpectActiveUseUpdate(10, 0); 586 ExpectActiveUseUpdate(10, 0);
511 daemon_.SetUserActiveState(/* active */ true, 587 daemon_.SetUserActiveState(/* active */ true,
512 TestTime(10 * kSecondsPerDay + 1000)); 588 TestTime(10 * kSecondsPerDay + 1000));
513 EXPECT_TRUE(daemon_.user_active_); 589 EXPECT_TRUE(daemon_.user_active_);
514 EXPECT_EQ(TestTime(10 * kSecondsPerDay + 1000), daemon_.user_active_last_); 590 EXPECT_EQ(TestTime(10 * kSecondsPerDay + 1000), daemon_.user_active_last_);
515 } 591 }
516 592
517 TEST_F(MetricsDaemonTest, ReportUserCrashInterval) { 593 TEST_F(MetricsDaemonTest, GetHistogramPath) {
518 ExpectMetric(MetricsDaemon::kMetricUserCrashIntervalName, 50, 594 EXPECT_EQ("/var/log/metrics/Logging.AnyCrashesDaily",
519 MetricsDaemon::kMetricCrashIntervalMin, 595 daemon_.GetHistogramPath(
520 MetricsDaemon::kMetricCrashIntervalMax, 596 MetricsDaemon::kMetricAnyCrashesDailyName).value());
521 MetricsDaemon::kMetricCrashIntervalBuckets);
522 MetricsDaemon::ReportUserCrashInterval(&daemon_, 0, 50);
523 }
524
525 TEST_F(MetricsDaemonTest, ReportCrashesDailyFrequency) {
526 ExpectMetric("foobar", 50,
527 MetricsDaemon::kMetricCrashesDailyMin,
528 MetricsDaemon::kMetricCrashesDailyMax,
529 MetricsDaemon::kMetricCrashesDailyBuckets);
530 MetricsDaemon::ReportCrashesDailyFrequency("foobar", &daemon_, 50);
531 } 597 }
532 598
533 int main(int argc, char** argv) { 599 int main(int argc, char** argv) {
534 testing::InitGoogleTest(&argc, argv); 600 testing::InitGoogleTest(&argc, argv);
535 return RUN_ALL_TESTS(); 601 return RUN_ALL_TESTS();
536 } 602 }
OLDNEW
« no previous file with comments | « metrics_daemon.cc ('k') | metrics_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698