Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 1 | // 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 Chen | bd12527 | 2018-04-04 19:02:50 -0700 | [diff] [blame] | 21 | #include <iostream> |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace os { |
| 26 | namespace statsd { |
| 27 | |
| 28 | #ifdef __ANDROID__ |
| 29 | |
| 30 | namespace { |
| 31 | |
Yangster-mac | e06cfd7 | 2018-03-10 23:22:59 -0800 | [diff] [blame] | 32 | StatsdConfig CreateStatsdConfig(const Position position) { |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 33 | StatsdConfig config; |
David Chen | 8faaa01 | 2018-02-28 15:54:36 -0800 | [diff] [blame] | 34 | config.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root. |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 35 | 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-mac | 468ff04 | 2018-01-17 12:26:34 -0800 | [diff] [blame] | 49 | *countMetric->mutable_dimensions_in_what() = |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 50 | CreateAttributionUidAndTagDimensions( |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 51 | util::WAKELOCK_STATE_CHANGED, {position}); |
yro | 59cc24d | 2018-02-13 20:17:32 -0800 | [diff] [blame] | 52 | countMetric->set_bucket(FIVE_MINUTES); |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 53 | return config; |
| 54 | } |
| 55 | |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 56 | // GMS core node is in the middle. |
| 57 | std::vector<int> attributionUids1 = {111, 222, 333}; |
| 58 | std::vector<string> attributionTags1 = {"App1", "GMSCoreModule1", "App3"}; |
| 59 | |
| 60 | // GMS core node is the last one. |
| 61 | std::vector<int> attributionUids2 = {111, 333, 222}; |
| 62 | std::vector<string> attributionTags2 = {"App1", "App3", "GMSCoreModule1"}; |
| 63 | |
| 64 | // GMS core node is the first one. |
| 65 | std::vector<int> attributionUids3 = {222, 333}; |
| 66 | std::vector<string> attributionTags3 = {"GMSCoreModule1", "App3"}; |
| 67 | |
| 68 | // Single GMS core node. |
| 69 | std::vector<int> attributionUids4 = {222}; |
| 70 | std::vector<string> attributionTags4 = {"GMSCoreModule1"}; |
| 71 | |
| 72 | // GMS core has another uid. |
| 73 | std::vector<int> attributionUids5 = {111, 444, 333}; |
| 74 | std::vector<string> attributionTags5 = {"App1", "GMSCoreModule2", "App3"}; |
| 75 | |
| 76 | // Multiple GMS core nodes. |
| 77 | std::vector<int> attributionUids6 = {444, 222}; |
| 78 | std::vector<string> attributionTags6 = {"GMSCoreModule2", "GMSCoreModule1"}; |
| 79 | |
| 80 | // No GMS core nodes |
| 81 | std::vector<int> attributionUids7 = {111, 333}; |
| 82 | std::vector<string> attributionTags7 = {"App1", "App3"}; |
| 83 | |
| 84 | std::vector<int> attributionUids8 = {111}; |
| 85 | std::vector<string> attributionTags8 = {"App1"}; |
| 86 | |
| 87 | // GMS core node with isolated uid. |
| 88 | const int isolatedUid = 666; |
| 89 | std::vector<int> attributionUids9 = {isolatedUid}; |
| 90 | std::vector<string> attributionTags9 = {"GMSCoreModule3"}; |
| 91 | |
| 92 | std::vector<int> attributionUids10 = {isolatedUid}; |
| 93 | std::vector<string> attributionTags10 = {"GMSCoreModule1"}; |
| 94 | |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 95 | } // namespace |
| 96 | |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 97 | TEST(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 Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 104 | ASSERT_EQ(processor->mMetricsManagers.size(), 1u); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 105 | 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 Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 158 | ASSERT_EQ(reports.reports_size(), 1); |
| 159 | ASSERT_EQ(reports.reports(0).metrics_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 160 | |
| 161 | StatsLogReport::CountMetricDataWrapper countMetrics; |
| 162 | sortMetricDataByDimensionsValue(reports.reports(0).metrics(0).count_metrics(), &countMetrics); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 163 | ASSERT_EQ(countMetrics.data_size(), 4); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 164 | |
| 165 | auto data = countMetrics.data(0); |
| 166 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 167 | util::WAKELOCK_STATE_CHANGED, 111, "App1"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 168 | ASSERT_EQ(data.bucket_info_size(), 2); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 169 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 179 | util::WAKELOCK_STATE_CHANGED, 222, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 180 | "GMSCoreModule1"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 181 | ASSERT_EQ(data.bucket_info_size(), 2); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 182 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 191 | util::WAKELOCK_STATE_CHANGED, 222, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 192 | "GMSCoreModule3"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 193 | ASSERT_EQ(data.bucket_info_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 194 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 201 | util::WAKELOCK_STATE_CHANGED, 444, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 202 | "GMSCoreModule2"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 203 | ASSERT_EQ(data.bucket_info_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 204 | 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 | |
| 210 | TEST(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 Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 217 | ASSERT_EQ(processor->mMetricsManagers.size(), 1u); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 218 | 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 Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 271 | ASSERT_EQ(reports.reports_size(), 1); |
| 272 | ASSERT_EQ(reports.reports(0).metrics_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 273 | |
| 274 | StatsLogReport::CountMetricDataWrapper countMetrics; |
| 275 | sortMetricDataByDimensionsValue(reports.reports(0).metrics(0).count_metrics(), &countMetrics); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 276 | ASSERT_EQ(countMetrics.data_size(), 6); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 277 | |
| 278 | auto data = countMetrics.data(0); |
| 279 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 280 | util::WAKELOCK_STATE_CHANGED, 222, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 281 | "GMSCoreModule1"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 282 | ASSERT_EQ(2, data.bucket_info_size()); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 283 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 292 | ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 222); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 293 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 294 | util::WAKELOCK_STATE_CHANGED, 222, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 295 | "GMSCoreModule1"); |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 296 | ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 333); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 297 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 298 | util::WAKELOCK_STATE_CHANGED, 333, "App3"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 299 | ASSERT_EQ(data.bucket_info_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 300 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 305 | ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 444); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 306 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 307 | util::WAKELOCK_STATE_CHANGED, 444, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 308 | "GMSCoreModule2"); |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 309 | ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 222); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 310 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 311 | util::WAKELOCK_STATE_CHANGED, 222, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 312 | "GMSCoreModule1"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 313 | ASSERT_EQ(data.bucket_info_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 314 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 320 | ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 111); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 321 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 322 | util::WAKELOCK_STATE_CHANGED, 111, "App1"); |
| 323 | ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 222); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 324 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 325 | util::WAKELOCK_STATE_CHANGED, 222, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 326 | "GMSCoreModule1"); |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 327 | ValidateUidDimension(data.dimensions_in_what(), 2, util::WAKELOCK_STATE_CHANGED, 333); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 328 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 2, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 329 | util::WAKELOCK_STATE_CHANGED, 333, "App3"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 330 | ASSERT_EQ(data.bucket_info_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 331 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 336 | ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 111); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 337 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 338 | util::WAKELOCK_STATE_CHANGED, 111, "App1"); |
| 339 | ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 333); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 340 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 341 | util::WAKELOCK_STATE_CHANGED, 333, "App3"); |
| 342 | ValidateUidDimension(data.dimensions_in_what(), 2, util::WAKELOCK_STATE_CHANGED, 222); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 343 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 2, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 344 | util::WAKELOCK_STATE_CHANGED, 222, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 345 | "GMSCoreModule1"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 346 | ASSERT_EQ(data.bucket_info_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 347 | 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 Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 352 | ValidateUidDimension(data.dimensions_in_what(), 0, util::WAKELOCK_STATE_CHANGED, 111); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 353 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 0, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 354 | util::WAKELOCK_STATE_CHANGED, 111, "App1"); |
| 355 | ValidateUidDimension(data.dimensions_in_what(), 1, util::WAKELOCK_STATE_CHANGED, 444); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 356 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 1, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 357 | util::WAKELOCK_STATE_CHANGED, 444, |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 358 | "GMSCoreModule2"); |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 359 | ValidateUidDimension(data.dimensions_in_what(), 2, util::WAKELOCK_STATE_CHANGED, 333); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 360 | ValidateAttributionUidAndTagDimension(data.dimensions_in_what(), 2, |
Jeffrey Huang | 3eb84d4 | 2020-03-17 10:31:22 -0700 | [diff] [blame] | 361 | util::WAKELOCK_STATE_CHANGED, 333, "App3"); |
Muhammad Qureshi | dff78d6 | 2020-05-11 13:37:43 -0700 | [diff] [blame] | 362 | ASSERT_EQ(data.bucket_info_size(), 1); |
tsaichristine | 7747d37 | 2020-02-28 17:36:59 -0800 | [diff] [blame] | 363 | 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-mac | e06cfd7 | 2018-03-10 23:22:59 -0800 | [diff] [blame] | 368 | |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 369 | #else |
| 370 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 371 | #endif |
| 372 | |
| 373 | } // namespace statsd |
| 374 | } // namespace os |
yro | 59cc24d | 2018-02-13 20:17:32 -0800 | [diff] [blame] | 375 | } // namespace android |