blob: 4c2caa904f6ab8b39ccaf614060cdeadc8bbec13 [file] [log] [blame]
Yangster-macb5bc7412018-01-06 23:17:45 -08001// Copyright (C) 2017 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include <gtest/gtest.h>
16
17#include "src/StatsLogProcessor.h"
18#include "src/stats_log_util.h"
19#include "tests/statsd_test_util.h"
20
David Chenbd125272018-04-04 19:02:50 -070021#include <iostream>
Yangster-macb5bc7412018-01-06 23:17:45 -080022#include <vector>
23
24namespace android {
25namespace os {
26namespace statsd {
27
28#ifdef __ANDROID__
29
30namespace {
31
Yangster-mace06cfd72018-03-10 23:22:59 -080032StatsdConfig CreateStatsdConfig(const Position position) {
Yangster-macb5bc7412018-01-06 23:17:45 -080033 StatsdConfig config;
David Chen8faaa012018-02-28 15:54:36 -080034 config.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root.
Yangster-macb5bc7412018-01-06 23:17:45 -080035 auto wakelockAcquireMatcher = CreateAcquireWakelockAtomMatcher();
36 auto attributionNodeMatcher =
37 wakelockAcquireMatcher.mutable_simple_atom_matcher()->add_field_value_matcher();
38 attributionNodeMatcher->set_field(1);
39 attributionNodeMatcher->set_position(Position::ANY);
40 auto uidMatcher = attributionNodeMatcher->mutable_matches_tuple()->add_field_value_matcher();
41 uidMatcher->set_field(1); // uid field.
42 uidMatcher->set_eq_string("com.android.gmscore");
43
44 *config.add_atom_matcher() = wakelockAcquireMatcher;
45
46 auto countMetric = config.add_count_metric();
47 countMetric->set_id(123456);
48 countMetric->set_what(wakelockAcquireMatcher.id());
Yangster-mac468ff042018-01-17 12:26:34 -080049 *countMetric->mutable_dimensions_in_what() =
Yangster-macb5bc7412018-01-06 23:17:45 -080050 CreateAttributionUidAndTagDimensions(
Jeffrey Huang3eb84d42020-03-17 10:31:22 -070051 util::WAKELOCK_STATE_CHANGED, {position});
yro59cc24d2018-02-13 20:17:32 -080052 countMetric->set_bucket(FIVE_MINUTES);
Yangster-macb5bc7412018-01-06 23:17:45 -080053 return config;
54}
55
tsaichristine7747d372020-02-28 17:36:59 -080056// GMS core node is in the middle.
57std::vector<int> attributionUids1 = {111, 222, 333};
58std::vector<string> attributionTags1 = {"App1", "GMSCoreModule1", "App3"};
59
60// GMS core node is the last one.
61std::vector<int> attributionUids2 = {111, 333, 222};
62std::vector<string> attributionTags2 = {"App1", "App3", "GMSCoreModule1"};
63
64// GMS core node is the first one.
65std::vector<int> attributionUids3 = {222, 333};
66std::vector<string> attributionTags3 = {"GMSCoreModule1", "App3"};
67
68// Single GMS core node.
69std::vector<int> attributionUids4 = {222};
70std::vector<string> attributionTags4 = {"GMSCoreModule1"};
71
72// GMS core has another uid.
73std::vector<int> attributionUids5 = {111, 444, 333};
74std::vector<string> attributionTags5 = {"App1", "GMSCoreModule2", "App3"};
75
76// Multiple GMS core nodes.
77std::vector<int> attributionUids6 = {444, 222};
78std::vector<string> attributionTags6 = {"GMSCoreModule2", "GMSCoreModule1"};
79
80// No GMS core nodes
81std::vector<int> attributionUids7 = {111, 333};
82std::vector<string> attributionTags7 = {"App1", "App3"};
83
84std::vector<int> attributionUids8 = {111};
85std::vector<string> attributionTags8 = {"App1"};
86
87// GMS core node with isolated uid.
88const int isolatedUid = 666;
89std::vector<int> attributionUids9 = {isolatedUid};
90std::vector<string> attributionTags9 = {"GMSCoreModule3"};
91
92std::vector<int> attributionUids10 = {isolatedUid};
93std::vector<string> attributionTags10 = {"GMSCoreModule1"};
94
Yangster-macb5bc7412018-01-06 23:17:45 -080095} // namespace
96
tsaichristine7747d372020-02-28 17:36:59 -080097TEST(AttributionE2eTest, TestAttributionMatchAndSliceByFirstUid) {
98 auto config = CreateStatsdConfig(Position::FIRST);
99 int64_t bucketStartTimeNs = 10000000000;
100 int64_t bucketSizeNs = TimeUnitToBucketSizeInMillis(config.count_metric(0).bucket()) * 1000000;
101
102 ConfigKey cfgKey;
103 auto processor = CreateStatsLogProcessor(bucketStartTimeNs, bucketStartTimeNs, config, cfgKey);
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700104 ASSERT_EQ(processor->mMetricsManagers.size(), 1u);
tsaichristine7747d372020-02-28 17:36:59 -0800105 EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid());
106
107 // Here it assumes that GMS core has two uids.
108 processor->getUidMap()->updateMap(
109 1, {222, 444, 111, 333}, {1, 1, 2, 2},
110 {String16("v1"), String16("v1"), String16("v2"), String16("v2")},
111 {String16("com.android.gmscore"), String16("com.android.gmscore"), String16("app1"),
112 String16("APP3")},
113 {String16(""), String16(""), String16(""), String16("")});
114
115 std::vector<std::unique_ptr<LogEvent>> events;
116 // Events 1~4 are in the 1st bucket.
117 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 2, attributionUids1,
118 attributionTags1, "wl1"));
119 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 200, attributionUids2,
120 attributionTags2, "wl1"));
121 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + bucketSizeNs - 1,
122 attributionUids3, attributionTags3, "wl1"));
123 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + bucketSizeNs, attributionUids4,
124 attributionTags4, "wl1"));
125
126 // Events 5~8 are in the 3rd bucket.
127 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 2 * bucketSizeNs + 1,
128 attributionUids5, attributionTags5, "wl2"));
129 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 2 * bucketSizeNs + 100,
130 attributionUids6, attributionTags6, "wl2"));
131 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs - 2,
132 attributionUids7, attributionTags7, "wl2"));
133 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs,
134 attributionUids8, attributionTags8, "wl2"));
135 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs + 1,
136 attributionUids9, attributionTags9, "wl2"));
137 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs + 100,
138 attributionUids9, attributionTags9, "wl2"));
139 events.push_back(CreateIsolatedUidChangedEvent(bucketStartTimeNs + 3 * bucketSizeNs - 1, 222,
140 isolatedUid, true /*is_create*/));
141 events.push_back(CreateIsolatedUidChangedEvent(bucketStartTimeNs + 3 * bucketSizeNs + 10, 222,
142 isolatedUid, false /*is_create*/));
143
144 sortLogEventsByTimestamp(&events);
145
146 for (const auto& event : events) {
147 processor->OnLogEvent(event.get());
148 }
149 ConfigMetricsReportList reports;
150 vector<uint8_t> buffer;
151 processor->onDumpReport(cfgKey, bucketStartTimeNs + 4 * bucketSizeNs + 1, false, true, ADB_DUMP,
152 FAST, &buffer);
153 EXPECT_TRUE(buffer.size() > 0);
154 EXPECT_TRUE(reports.ParseFromArray(&buffer[0], buffer.size()));
155 backfillDimensionPath(&reports);
156 backfillStringInReport(&reports);
157 backfillStartEndTimestamp(&reports);
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700158 ASSERT_EQ(reports.reports_size(), 1);
159 ASSERT_EQ(reports.reports(0).metrics_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800160
161 StatsLogReport::CountMetricDataWrapper countMetrics;
162 sortMetricDataByDimensionsValue(reports.reports(0).metrics(0).count_metrics(), &countMetrics);
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700163 ASSERT_EQ(countMetrics.data_size(), 4);
tsaichristine7747d372020-02-28 17:36:59 -0800164
165 auto data = countMetrics.data(0);
166 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(),
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700167 util::WAKELOCK_STATE_CHANGED, 111, "App1");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700168 ASSERT_EQ(data.bucket_info_size(), 2);
tsaichristine7747d372020-02-28 17:36:59 -0800169 EXPECT_EQ(data.bucket_info(0).count(), 2);
170 EXPECT_EQ(data.bucket_info(0).start_bucket_elapsed_nanos(), bucketStartTimeNs);
171 EXPECT_EQ(data.bucket_info(0).end_bucket_elapsed_nanos(), bucketStartTimeNs + bucketSizeNs);
172 EXPECT_EQ(data.bucket_info(1).count(), 1);
173 EXPECT_EQ(data.bucket_info(1).start_bucket_elapsed_nanos(),
174 bucketStartTimeNs + 2 * bucketSizeNs);
175 EXPECT_EQ(data.bucket_info(1).end_bucket_elapsed_nanos(), bucketStartTimeNs + 3 * bucketSizeNs);
176
177 data = countMetrics.data(1);
178 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(),
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700179 util::WAKELOCK_STATE_CHANGED, 222,
tsaichristine7747d372020-02-28 17:36:59 -0800180 "GMSCoreModule1");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700181 ASSERT_EQ(data.bucket_info_size(), 2);
tsaichristine7747d372020-02-28 17:36:59 -0800182 EXPECT_EQ(data.bucket_info(0).count(), 1);
183 EXPECT_EQ(data.bucket_info(0).start_bucket_elapsed_nanos(), bucketStartTimeNs);
184 EXPECT_EQ(data.bucket_info(0).end_bucket_elapsed_nanos(), bucketStartTimeNs + bucketSizeNs);
185 EXPECT_EQ(data.bucket_info(1).count(), 1);
186 EXPECT_EQ(data.bucket_info(1).start_bucket_elapsed_nanos(), bucketStartTimeNs + bucketSizeNs);
187 EXPECT_EQ(data.bucket_info(1).end_bucket_elapsed_nanos(), bucketStartTimeNs + 2 * bucketSizeNs);
188
189 data = countMetrics.data(2);
190 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(),
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700191 util::WAKELOCK_STATE_CHANGED, 222,
tsaichristine7747d372020-02-28 17:36:59 -0800192 "GMSCoreModule3");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700193 ASSERT_EQ(data.bucket_info_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800194 EXPECT_EQ(data.bucket_info(0).count(), 1);
195 EXPECT_EQ(data.bucket_info(0).start_bucket_elapsed_nanos(),
196 bucketStartTimeNs + 3 * bucketSizeNs);
197 EXPECT_EQ(data.bucket_info(0).end_bucket_elapsed_nanos(), bucketStartTimeNs + 4 * bucketSizeNs);
198
199 data = countMetrics.data(3);
200 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(),
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700201 util::WAKELOCK_STATE_CHANGED, 444,
tsaichristine7747d372020-02-28 17:36:59 -0800202 "GMSCoreModule2");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700203 ASSERT_EQ(data.bucket_info_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800204 EXPECT_EQ(data.bucket_info(0).count(), 1);
205 EXPECT_EQ(data.bucket_info(0).start_bucket_elapsed_nanos(),
206 bucketStartTimeNs + 2 * bucketSizeNs);
207 EXPECT_EQ(data.bucket_info(0).end_bucket_elapsed_nanos(), bucketStartTimeNs + 3 * bucketSizeNs);
208}
209
210TEST(AttributionE2eTest, TestAttributionMatchAndSliceByChain) {
211 auto config = CreateStatsdConfig(Position::ALL);
212 int64_t bucketStartTimeNs = 10000000000;
213 int64_t bucketSizeNs = TimeUnitToBucketSizeInMillis(config.count_metric(0).bucket()) * 1000000;
214
215 ConfigKey cfgKey;
216 auto processor = CreateStatsLogProcessor(bucketStartTimeNs, bucketStartTimeNs, config, cfgKey);
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700217 ASSERT_EQ(processor->mMetricsManagers.size(), 1u);
tsaichristine7747d372020-02-28 17:36:59 -0800218 EXPECT_TRUE(processor->mMetricsManagers.begin()->second->isConfigValid());
219
220 // Here it assumes that GMS core has two uids.
221 processor->getUidMap()->updateMap(
222 1, {222, 444, 111, 333}, {1, 1, 2, 2},
223 {String16("v1"), String16("v1"), String16("v2"), String16("v2")},
224 {String16("com.android.gmscore"), String16("com.android.gmscore"), String16("app1"),
225 String16("APP3")},
226 {String16(""), String16(""), String16(""), String16("")});
227
228 std::vector<std::unique_ptr<LogEvent>> events;
229 // Events 1~4 are in the 1st bucket.
230 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 2, attributionUids1,
231 attributionTags1, "wl1"));
232 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 200, attributionUids2,
233 attributionTags2, "wl1"));
234 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + bucketSizeNs - 1,
235 attributionUids3, attributionTags3, "wl1"));
236 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + bucketSizeNs, attributionUids4,
237 attributionTags4, "wl1"));
238
239 // Events 5~8 are in the 3rd bucket.
240 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 2 * bucketSizeNs + 1,
241 attributionUids5, attributionTags5, "wl2"));
242 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 2 * bucketSizeNs + 100,
243 attributionUids6, attributionTags6, "wl2"));
244 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs - 2,
245 attributionUids7, attributionTags7, "wl2"));
246 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs,
247 attributionUids8, attributionTags8, "wl2"));
248 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs + 1,
249 attributionUids10, attributionTags10, "wl2"));
250 events.push_back(CreateAcquireWakelockEvent(bucketStartTimeNs + 3 * bucketSizeNs + 100,
251 attributionUids10, attributionTags10, "wl2"));
252 events.push_back(CreateIsolatedUidChangedEvent(bucketStartTimeNs + 3 * bucketSizeNs - 1, 222,
253 isolatedUid, true /*is_create*/));
254 events.push_back(CreateIsolatedUidChangedEvent(bucketStartTimeNs + 3 * bucketSizeNs + 10, 222,
255 isolatedUid, false /*is_create*/));
256
257 sortLogEventsByTimestamp(&events);
258
259 for (const auto& event : events) {
260 processor->OnLogEvent(event.get());
261 }
262 ConfigMetricsReportList reports;
263 vector<uint8_t> buffer;
264 processor->onDumpReport(cfgKey, bucketStartTimeNs + 4 * bucketSizeNs + 1, false, true, ADB_DUMP,
265 FAST, &buffer);
266 EXPECT_TRUE(buffer.size() > 0);
267 EXPECT_TRUE(reports.ParseFromArray(&buffer[0], buffer.size()));
268 backfillDimensionPath(&reports);
269 backfillStringInReport(&reports);
270 backfillStartEndTimestamp(&reports);
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700271 ASSERT_EQ(reports.reports_size(), 1);
272 ASSERT_EQ(reports.reports(0).metrics_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800273
274 StatsLogReport::CountMetricDataWrapper countMetrics;
275 sortMetricDataByDimensionsValue(reports.reports(0).metrics(0).count_metrics(), &countMetrics);
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700276 ASSERT_EQ(countMetrics.data_size(), 6);
tsaichristine7747d372020-02-28 17:36:59 -0800277
278 auto data = countMetrics.data(0);
279 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(),
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700280 util::WAKELOCK_STATE_CHANGED, 222,
tsaichristine7747d372020-02-28 17:36:59 -0800281 "GMSCoreModule1");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700282 ASSERT_EQ(2, data.bucket_info_size());
tsaichristine7747d372020-02-28 17:36:59 -0800283 EXPECT_EQ(1, data.bucket_info(0).count());
284 EXPECT_EQ(bucketStartTimeNs + bucketSizeNs, data.bucket_info(0).start_bucket_elapsed_nanos());
285 EXPECT_EQ(bucketStartTimeNs + 2 * bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
286 EXPECT_EQ(1, data.bucket_info(1).count());
287 EXPECT_EQ(bucketStartTimeNs + 3 * bucketSizeNs,
288 data.bucket_info(1).start_bucket_elapsed_nanos());
289 EXPECT_EQ(bucketStartTimeNs + 4 * bucketSizeNs, data.bucket_info(1).end_bucket_elapsed_nanos());
290
291 data = countMetrics.data(1);
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700292 ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 222);
tsaichristine7747d372020-02-28 17:36:59 -0800293 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700294 util::WAKELOCK_STATE_CHANGED, 222,
tsaichristine7747d372020-02-28 17:36:59 -0800295 "GMSCoreModule1");
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700296 ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 333);
tsaichristine7747d372020-02-28 17:36:59 -0800297 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700298 util::WAKELOCK_STATE_CHANGED, 333, "App3");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700299 ASSERT_EQ(data.bucket_info_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800300 EXPECT_EQ(data.bucket_info(0).count(), 1);
301 EXPECT_EQ(data.bucket_info(0).start_bucket_elapsed_nanos(), bucketStartTimeNs);
302 EXPECT_EQ(data.bucket_info(0).end_bucket_elapsed_nanos(), bucketStartTimeNs + bucketSizeNs);
303
304 data = countMetrics.data(2);
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700305 ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 444);
tsaichristine7747d372020-02-28 17:36:59 -0800306 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700307 util::WAKELOCK_STATE_CHANGED, 444,
tsaichristine7747d372020-02-28 17:36:59 -0800308 "GMSCoreModule2");
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700309 ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 222);
tsaichristine7747d372020-02-28 17:36:59 -0800310 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700311 util::WAKELOCK_STATE_CHANGED, 222,
tsaichristine7747d372020-02-28 17:36:59 -0800312 "GMSCoreModule1");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700313 ASSERT_EQ(data.bucket_info_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800314 EXPECT_EQ(data.bucket_info(0).count(), 1);
315 EXPECT_EQ(bucketStartTimeNs + 2 * bucketSizeNs,
316 data.bucket_info(0).start_bucket_elapsed_nanos());
317 EXPECT_EQ(bucketStartTimeNs + 3 * bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
318
319 data = countMetrics.data(3);
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700320 ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 111);
tsaichristine7747d372020-02-28 17:36:59 -0800321 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700322 util::WAKELOCK_STATE_CHANGED, 111, "App1");
323 ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 222);
tsaichristine7747d372020-02-28 17:36:59 -0800324 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700325 util::WAKELOCK_STATE_CHANGED, 222,
tsaichristine7747d372020-02-28 17:36:59 -0800326 "GMSCoreModule1");
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700327 ValidateUidDimension(data.dimensions_in_what(), 2, util::WAKELOCK_STATE_CHANGED, 333);
tsaichristine7747d372020-02-28 17:36:59 -0800328 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 2,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700329 util::WAKELOCK_STATE_CHANGED, 333, "App3");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700330 ASSERT_EQ(data.bucket_info_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800331 EXPECT_EQ(data.bucket_info(0).count(), 1);
332 EXPECT_EQ(bucketStartTimeNs, data.bucket_info(0).start_bucket_elapsed_nanos());
333 EXPECT_EQ(bucketStartTimeNs + bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
334
335 data = countMetrics.data(4);
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700336 ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 111);
tsaichristine7747d372020-02-28 17:36:59 -0800337 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700338 util::WAKELOCK_STATE_CHANGED, 111, "App1");
339 ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 333);
tsaichristine7747d372020-02-28 17:36:59 -0800340 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700341 util::WAKELOCK_STATE_CHANGED, 333, "App3");
342 ValidateUidDimension(data.dimensions_in_what(), 2, util::WAKELOCK_STATE_CHANGED, 222);
tsaichristine7747d372020-02-28 17:36:59 -0800343 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 2,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700344 util::WAKELOCK_STATE_CHANGED, 222,
tsaichristine7747d372020-02-28 17:36:59 -0800345 "GMSCoreModule1");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700346 ASSERT_EQ(data.bucket_info_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800347 EXPECT_EQ(data.bucket_info(0).count(), 1);
348 EXPECT_EQ(bucketStartTimeNs, data.bucket_info(0).start_bucket_elapsed_nanos());
349 EXPECT_EQ(bucketStartTimeNs + bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
350
351 data = countMetrics.data(5);
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700352 ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 111);
tsaichristine7747d372020-02-28 17:36:59 -0800353 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700354 util::WAKELOCK_STATE_CHANGED, 111, "App1");
355 ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 444);
tsaichristine7747d372020-02-28 17:36:59 -0800356 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700357 util::WAKELOCK_STATE_CHANGED, 444,
tsaichristine7747d372020-02-28 17:36:59 -0800358 "GMSCoreModule2");
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700359 ValidateUidDimension(data.dimensions_in_what(), 2, util::WAKELOCK_STATE_CHANGED, 333);
tsaichristine7747d372020-02-28 17:36:59 -0800360 ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 2,
Jeffrey Huang3eb84d42020-03-17 10:31:22 -0700361 util::WAKELOCK_STATE_CHANGED, 333, "App3");
Muhammad Qureshidff78d62020-05-11 13:37:43 -0700362 ASSERT_EQ(data.bucket_info_size(), 1);
tsaichristine7747d372020-02-28 17:36:59 -0800363 EXPECT_EQ(data.bucket_info(0).count(), 1);
364 EXPECT_EQ(bucketStartTimeNs + 2 * bucketSizeNs,
365 data.bucket_info(0).start_bucket_elapsed_nanos());
366 EXPECT_EQ(bucketStartTimeNs + 3 * bucketSizeNs, data.bucket_info(0).end_bucket_elapsed_nanos());
367}
Yangster-mace06cfd72018-03-10 23:22:59 -0800368
Yangster-macb5bc7412018-01-06 23:17:45 -0800369#else
370GTEST_LOG_(INFO) << "This test does nothing.\n";
371#endif
372
373} // namespace statsd
374} // namespace os
yro59cc24d2018-02-13 20:17:32 -0800375} // namespace android