Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 2016 Google, Inc. |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | #include <chrono> |
| 19 | #include <cstdint> |
| 20 | #include <string> |
| 21 | #include <thread> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <gmock/gmock.h> |
| 25 | #include <gtest/gtest.h> |
| 26 | |
| 27 | #include <base/logging.h> |
| 28 | |
Jack He | ad18de0 | 2018-03-03 00:03:25 -0800 | [diff] [blame^] | 29 | #include "bluetooth/metrics/bluetooth.pb.h" |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 30 | #include "osi/include/metrics.h" |
| 31 | #include "osi/include/time.h" |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 32 | |
| 33 | #define BTM_COD_MAJOR_AUDIO_TEST 0x04 |
| 34 | |
| 35 | namespace testing { |
| 36 | |
Jack He | ad18de0 | 2018-03-03 00:03:25 -0800 | [diff] [blame^] | 37 | using bluetooth::metrics::BluetoothMetricsProto::A2DPSession; |
| 38 | using bluetooth::metrics::BluetoothMetricsProto::BluetoothLog; |
| 39 | using bluetooth::metrics::BluetoothMetricsProto::BluetoothSession; |
| 40 | using bluetooth::metrics::BluetoothMetricsProto:: |
| 41 | BluetoothSession_ConnectionTechnologyType; |
| 42 | using bluetooth::metrics::BluetoothMetricsProto:: |
| 43 | BluetoothSession_DisconnectReasonType; |
| 44 | using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo; |
| 45 | using bluetooth::metrics::BluetoothMetricsProto::DeviceInfo_DeviceType; |
| 46 | using bluetooth::metrics::BluetoothMetricsProto::PairEvent; |
| 47 | using bluetooth::metrics::BluetoothMetricsProto::RFCommSession; |
| 48 | using bluetooth::metrics::BluetoothMetricsProto::ScanEvent; |
| 49 | using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanTechnologyType; |
| 50 | using bluetooth::metrics::BluetoothMetricsProto::ScanEvent_ScanEventType; |
| 51 | using bluetooth::metrics::BluetoothMetricsProto::WakeEvent; |
| 52 | using bluetooth::metrics::BluetoothMetricsProto::WakeEvent_WakeEventType; |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 53 | using system_bt_osi::BluetoothMetricsLogger; |
| 54 | using system_bt_osi::A2dpSessionMetrics; |
| 55 | |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 56 | namespace { |
| 57 | const size_t kMaxEventGenerationLimit = 5000; |
| 58 | } |
| 59 | |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 60 | /* |
| 61 | * Get current OS boot time in ms |
| 62 | */ |
| 63 | static int64_t time_get_os_boottime_ms(void) { |
| 64 | return time_get_os_boottime_us() / 1000; |
| 65 | } |
| 66 | |
| 67 | static void sleep_ms(int64_t t) { |
| 68 | std::this_thread::sleep_for(std::chrono::milliseconds(t)); |
| 69 | } |
| 70 | |
| 71 | DeviceInfo* MakeDeviceInfo(int32_t device_class, |
| 72 | DeviceInfo_DeviceType device_type) { |
| 73 | DeviceInfo* info = new DeviceInfo(); |
| 74 | info->set_device_class(device_class); |
| 75 | info->set_device_type(device_type); |
| 76 | return info; |
| 77 | } |
| 78 | |
| 79 | PairEvent* MakePairEvent(int32_t disconnect_reason, int64_t timestamp_ms, |
| 80 | DeviceInfo* device_info) { |
| 81 | PairEvent* event = new PairEvent(); |
| 82 | event->set_disconnect_reason(disconnect_reason); |
| 83 | event->set_event_time_millis(timestamp_ms); |
| 84 | if (device_info) event->set_allocated_device_paired_with(device_info); |
| 85 | return event; |
| 86 | } |
| 87 | |
| 88 | WakeEvent* MakeWakeEvent(WakeEvent_WakeEventType event_type, |
| 89 | const std::string& requestor, const std::string& name, |
| 90 | int64_t timestamp_ms) { |
| 91 | WakeEvent* event = new WakeEvent(); |
| 92 | event->set_wake_event_type(event_type); |
| 93 | event->set_requestor(requestor); |
| 94 | event->set_name(name); |
| 95 | event->set_event_time_millis(timestamp_ms); |
| 96 | return event; |
| 97 | } |
| 98 | |
| 99 | ScanEvent* MakeScanEvent(ScanEvent_ScanEventType event_type, |
| 100 | const std::string& initiator, |
| 101 | ScanEvent_ScanTechnologyType tech_type, |
| 102 | int32_t num_results, int64_t timestamp_ms) { |
| 103 | ScanEvent* event = new ScanEvent(); |
| 104 | event->set_scan_event_type(event_type); |
| 105 | event->set_initiator(initiator); |
| 106 | event->set_scan_technology_type(tech_type); |
| 107 | event->set_number_results(num_results); |
| 108 | event->set_event_time_millis(timestamp_ms); |
| 109 | return event; |
| 110 | } |
| 111 | |
| 112 | A2DPSession* MakeA2DPSession(const A2dpSessionMetrics& metrics) { |
| 113 | A2DPSession* session = new A2DPSession(); |
| 114 | session->set_media_timer_min_millis(metrics.media_timer_min_ms); |
| 115 | session->set_media_timer_max_millis(metrics.media_timer_max_ms); |
| 116 | session->set_media_timer_avg_millis(metrics.media_timer_avg_ms); |
| 117 | session->set_buffer_overruns_max_count(metrics.buffer_overruns_max_count); |
| 118 | session->set_buffer_overruns_total(metrics.buffer_overruns_total); |
| 119 | session->set_buffer_underruns_average(metrics.buffer_underruns_average); |
| 120 | session->set_buffer_underruns_count(metrics.buffer_underruns_count); |
| 121 | session->set_audio_duration_millis(metrics.audio_duration_ms); |
| 122 | return session; |
| 123 | } |
| 124 | |
| 125 | BluetoothSession* MakeBluetoothSession( |
| 126 | int64_t session_duration_sec, |
| 127 | BluetoothSession_ConnectionTechnologyType conn_type, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 128 | BluetoothSession_DisconnectReasonType disconnect_reason, |
| 129 | DeviceInfo* device_info, RFCommSession* rfcomm_session, |
| 130 | A2DPSession* a2dp_session) { |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 131 | BluetoothSession* session = new BluetoothSession(); |
| 132 | if (a2dp_session) session->set_allocated_a2dp_session(a2dp_session); |
| 133 | if (rfcomm_session) session->set_allocated_rfcomm_session(rfcomm_session); |
| 134 | if (device_info) session->set_allocated_device_connected_to(device_info); |
| 135 | session->set_session_duration_sec(session_duration_sec); |
| 136 | session->set_connection_technology_type(conn_type); |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 137 | session->set_disconnect_reason_type(disconnect_reason); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 138 | return session; |
| 139 | } |
| 140 | |
| 141 | BluetoothLog* MakeBluetoothLog(std::vector<BluetoothSession*> bt_sessions, |
| 142 | std::vector<PairEvent*> pair_events, |
| 143 | std::vector<WakeEvent*> wake_events, |
| 144 | std::vector<ScanEvent*> scan_events) { |
| 145 | BluetoothLog* bt_log = new BluetoothLog(); |
| 146 | for (BluetoothSession* session : bt_sessions) { |
| 147 | bt_log->mutable_session()->AddAllocated(session); |
| 148 | } |
| 149 | bt_sessions.clear(); |
| 150 | for (PairEvent* event : pair_events) { |
| 151 | bt_log->mutable_pair_event()->AddAllocated(event); |
| 152 | } |
| 153 | pair_events.clear(); |
| 154 | for (WakeEvent* event : wake_events) { |
| 155 | bt_log->mutable_wake_event()->AddAllocated(event); |
| 156 | } |
| 157 | wake_events.clear(); |
| 158 | for (ScanEvent* event : scan_events) { |
| 159 | bt_log->mutable_scan_event()->AddAllocated(event); |
| 160 | } |
| 161 | scan_events.clear(); |
| 162 | return bt_log; |
| 163 | } |
| 164 | |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 165 | void GenerateWakeEvents(size_t start, size_t end, |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 166 | std::vector<WakeEvent*>* wake_events) { |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 167 | for (size_t i = start; i < end; ++i) { |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 168 | wake_events->push_back(MakeWakeEvent( |
| 169 | i % 2 == 0 ? WakeEvent_WakeEventType::WakeEvent_WakeEventType_ACQUIRED |
| 170 | : WakeEvent_WakeEventType::WakeEvent_WakeEventType_RELEASED, |
| 171 | "TEST_REQ", "TEST_NAME", i)); |
| 172 | } |
| 173 | } |
| 174 | |
Chih-Hung Hsieh | fc25b19 | 2017-08-01 15:04:23 -0700 | [diff] [blame] | 175 | #define COMPARE_A2DP_METRICS(a, b) \ |
| 176 | do { \ |
| 177 | EXPECT_EQ((a).audio_duration_ms, (b).audio_duration_ms); \ |
| 178 | EXPECT_EQ((a).media_timer_min_ms, (b).media_timer_min_ms); \ |
| 179 | EXPECT_EQ((a).media_timer_max_ms, (b).media_timer_max_ms); \ |
| 180 | EXPECT_EQ((a).media_timer_avg_ms, (b).media_timer_avg_ms); \ |
| 181 | EXPECT_EQ((a).total_scheduling_count, (b).total_scheduling_count); \ |
| 182 | EXPECT_EQ((a).buffer_overruns_max_count, (b).buffer_overruns_max_count); \ |
| 183 | EXPECT_EQ((a).buffer_overruns_total, (b).buffer_overruns_total); \ |
| 184 | EXPECT_THAT((a).buffer_underruns_average, \ |
| 185 | FloatNear((b).buffer_underruns_average, 0.01)); \ |
| 186 | (a).buffer_underruns_average = (b).buffer_underruns_average; \ |
| 187 | EXPECT_EQ((a).buffer_underruns_count, (b).buffer_underruns_count); \ |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 188 | } while (0) |
| 189 | |
| 190 | /* |
| 191 | * metrics_sum = metrics1 + metrics2 |
| 192 | */ |
| 193 | TEST(BluetoothA2DPSessionMetricsTest, TestUpdateNormal) { |
| 194 | A2dpSessionMetrics metrics1; |
| 195 | A2dpSessionMetrics metrics2; |
| 196 | A2dpSessionMetrics metrics_sum; |
| 197 | metrics1.audio_duration_ms = 10; |
| 198 | metrics2.audio_duration_ms = 25; |
| 199 | metrics_sum.audio_duration_ms = 35; |
| 200 | metrics1.media_timer_min_ms = 10; |
| 201 | metrics2.media_timer_min_ms = 25; |
| 202 | metrics_sum.media_timer_min_ms = 10; |
| 203 | metrics1.media_timer_max_ms = 100; |
| 204 | metrics2.media_timer_max_ms = 200; |
| 205 | metrics_sum.media_timer_max_ms = 200; |
| 206 | metrics1.media_timer_avg_ms = 50; |
| 207 | metrics1.total_scheduling_count = 50; |
| 208 | metrics2.media_timer_avg_ms = 100; |
| 209 | metrics2.total_scheduling_count = 50; |
| 210 | metrics_sum.media_timer_avg_ms = 75; |
| 211 | metrics_sum.total_scheduling_count = 100; |
| 212 | metrics1.buffer_overruns_max_count = 70; |
| 213 | metrics2.buffer_overruns_max_count = 80; |
| 214 | metrics_sum.buffer_overruns_max_count = 80; |
| 215 | metrics1.buffer_underruns_average = 80; |
| 216 | metrics1.buffer_underruns_count = 1200; |
| 217 | metrics2.buffer_underruns_average = 130; |
| 218 | metrics2.buffer_underruns_count = 2400; |
| 219 | metrics_sum.buffer_underruns_average = 113.33333333; |
| 220 | metrics_sum.buffer_underruns_count = 3600; |
| 221 | metrics1.Update(metrics2); |
| 222 | COMPARE_A2DP_METRICS(metrics1, metrics_sum); |
| 223 | EXPECT_TRUE(metrics1 == metrics_sum); |
| 224 | EXPECT_EQ(metrics1, metrics_sum); |
| 225 | } |
| 226 | |
| 227 | TEST(BluetoothA2DPSessionMetricsTest, TestUpdateNew) { |
| 228 | A2dpSessionMetrics metrics1; |
| 229 | A2dpSessionMetrics metrics2; |
| 230 | A2dpSessionMetrics metrics_sum; |
| 231 | metrics2.audio_duration_ms = 25; |
| 232 | metrics_sum.audio_duration_ms = 25; |
| 233 | metrics2.media_timer_min_ms = 25; |
| 234 | metrics_sum.media_timer_min_ms = 25; |
| 235 | metrics2.media_timer_max_ms = 200; |
| 236 | metrics_sum.media_timer_max_ms = 200; |
| 237 | metrics2.media_timer_avg_ms = 100; |
| 238 | metrics2.total_scheduling_count = 50; |
| 239 | metrics_sum.media_timer_avg_ms = 100; |
| 240 | metrics_sum.total_scheduling_count = 50; |
| 241 | metrics2.buffer_overruns_max_count = 80; |
| 242 | metrics_sum.buffer_overruns_max_count = 80; |
| 243 | metrics2.buffer_underruns_average = 130; |
| 244 | metrics2.buffer_underruns_count = 2400; |
| 245 | metrics_sum.buffer_underruns_average = 130; |
| 246 | metrics_sum.buffer_underruns_count = 2400; |
| 247 | metrics1.Update(metrics2); |
| 248 | COMPARE_A2DP_METRICS(metrics1, metrics_sum); |
| 249 | EXPECT_TRUE(metrics1 == metrics_sum); |
| 250 | EXPECT_EQ(metrics1, metrics_sum); |
| 251 | } |
| 252 | |
| 253 | TEST(BluetoothA2DPSessionMetricsTest, TestNullUpdate) { |
| 254 | A2dpSessionMetrics metrics1; |
| 255 | A2dpSessionMetrics metrics2; |
| 256 | A2dpSessionMetrics metrics_sum; |
| 257 | metrics2.audio_duration_ms = 25; |
| 258 | metrics_sum.audio_duration_ms = 25; |
| 259 | metrics2.media_timer_min_ms = 25; |
| 260 | metrics_sum.media_timer_min_ms = 25; |
| 261 | metrics2.media_timer_max_ms = 200; |
| 262 | metrics_sum.media_timer_max_ms = 200; |
| 263 | metrics2.media_timer_avg_ms = 100; |
| 264 | metrics2.total_scheduling_count = 50; |
| 265 | metrics_sum.media_timer_avg_ms = 100; |
| 266 | metrics_sum.total_scheduling_count = 50; |
| 267 | metrics2.buffer_overruns_max_count = 80; |
| 268 | metrics_sum.buffer_overruns_max_count = 80; |
| 269 | metrics2.buffer_underruns_average = 130; |
| 270 | metrics2.buffer_underruns_count = 2400; |
| 271 | metrics_sum.buffer_underruns_average = 130; |
| 272 | metrics_sum.buffer_underruns_count = 2400; |
| 273 | metrics2.Update(metrics1); |
| 274 | COMPARE_A2DP_METRICS(metrics2, metrics_sum); |
| 275 | EXPECT_TRUE(metrics2 == metrics_sum); |
| 276 | EXPECT_EQ(metrics2, metrics_sum); |
| 277 | } |
| 278 | |
| 279 | TEST(BluetoothA2DPSessionMetricsTest, TestPartialUpdate) { |
| 280 | A2dpSessionMetrics metrics1; |
| 281 | A2dpSessionMetrics metrics2; |
| 282 | A2dpSessionMetrics metrics_sum; |
| 283 | metrics1.audio_duration_ms = 10; |
| 284 | metrics2.audio_duration_ms = 25; |
| 285 | metrics_sum.audio_duration_ms = 35; |
| 286 | metrics1.media_timer_min_ms = 10; |
| 287 | metrics_sum.media_timer_min_ms = 10; |
| 288 | metrics1.media_timer_max_ms = 100; |
| 289 | metrics_sum.media_timer_max_ms = 100; |
| 290 | metrics1.media_timer_avg_ms = 50; |
| 291 | metrics1.total_scheduling_count = 50; |
| 292 | metrics2.media_timer_avg_ms = 100; |
| 293 | metrics_sum.media_timer_avg_ms = 50; |
| 294 | metrics_sum.total_scheduling_count = 50; |
| 295 | metrics1.buffer_overruns_max_count = 70; |
| 296 | metrics_sum.buffer_overruns_max_count = 70; |
| 297 | metrics1.buffer_underruns_average = 80; |
| 298 | metrics1.buffer_underruns_count = 1200; |
| 299 | metrics2.buffer_underruns_count = 2400; |
| 300 | metrics_sum.buffer_underruns_average = 80; |
| 301 | metrics_sum.buffer_underruns_count = 1200; |
| 302 | metrics1.Update(metrics2); |
| 303 | COMPARE_A2DP_METRICS(metrics1, metrics_sum); |
| 304 | EXPECT_TRUE(metrics1 == metrics_sum); |
| 305 | EXPECT_EQ(metrics1, metrics_sum); |
| 306 | } |
| 307 | |
| 308 | class BluetoothMetricsLoggerTest : public Test { |
| 309 | protected: |
| 310 | // Use to hold test protos |
| 311 | std::vector<PairEvent*> pair_events_; |
| 312 | std::vector<WakeEvent*> wake_events_; |
| 313 | std::vector<ScanEvent*> scan_events_; |
| 314 | std::vector<BluetoothSession*> bt_sessions_; |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 315 | int64_t num_pair_event_ = 0; |
| 316 | int64_t num_wake_event_ = 0; |
| 317 | int64_t num_scan_event_ = 0; |
| 318 | int64_t num_bt_session_ = 0; |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 319 | BluetoothLog* bt_log_; |
| 320 | std::string bt_log_str_; |
| 321 | std::string bt_log_ascii_str_; |
| 322 | |
| 323 | void UpdateLog() { |
| 324 | for (BluetoothSession* session : bt_sessions_) { |
| 325 | bt_log_->mutable_session()->AddAllocated(session); |
| 326 | } |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 327 | if (num_bt_session_ > 0) { |
| 328 | bt_log_->set_num_bluetooth_session(num_bt_session_); |
| 329 | } else if (bt_sessions_.size() > 0) { |
| 330 | bt_log_->set_num_bluetooth_session(bt_sessions_.size()); |
| 331 | } |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 332 | bt_sessions_.clear(); |
| 333 | for (PairEvent* event : pair_events_) { |
| 334 | bt_log_->mutable_pair_event()->AddAllocated(event); |
| 335 | } |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 336 | if (num_pair_event_ > 0) { |
| 337 | bt_log_->set_num_pair_event(num_pair_event_); |
| 338 | } else if (pair_events_.size() > 0) { |
| 339 | bt_log_->set_num_pair_event(pair_events_.size()); |
| 340 | } |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 341 | pair_events_.clear(); |
| 342 | for (WakeEvent* event : wake_events_) { |
| 343 | bt_log_->mutable_wake_event()->AddAllocated(event); |
| 344 | } |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 345 | if (num_wake_event_ > 0) { |
| 346 | bt_log_->set_num_wake_event(num_wake_event_); |
| 347 | } else if (wake_events_.size() > 0) { |
| 348 | bt_log_->set_num_wake_event(wake_events_.size()); |
| 349 | } |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 350 | wake_events_.clear(); |
| 351 | for (ScanEvent* event : scan_events_) { |
| 352 | bt_log_->mutable_scan_event()->AddAllocated(event); |
| 353 | } |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 354 | if (num_scan_event_ > 0) { |
| 355 | bt_log_->set_num_scan_event(num_scan_event_); |
| 356 | } else if (scan_events_.size() > 0) { |
| 357 | bt_log_->set_num_scan_event(scan_events_.size()); |
| 358 | } |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 359 | scan_events_.clear(); |
| 360 | bt_log_->SerializeToString(&bt_log_str_); |
| 361 | } |
| 362 | |
| 363 | void ClearLog() { |
| 364 | for (BluetoothSession* session : bt_sessions_) { |
| 365 | session->Clear(); |
| 366 | delete session; |
| 367 | } |
| 368 | bt_sessions_.clear(); |
| 369 | for (PairEvent* event : pair_events_) { |
| 370 | event->Clear(); |
| 371 | delete event; |
| 372 | } |
| 373 | pair_events_.clear(); |
| 374 | for (WakeEvent* event : wake_events_) { |
| 375 | event->Clear(); |
| 376 | delete event; |
| 377 | } |
| 378 | wake_events_.clear(); |
| 379 | for (ScanEvent* event : scan_events_) { |
| 380 | event->Clear(); |
| 381 | delete event; |
| 382 | } |
| 383 | scan_events_.clear(); |
| 384 | bt_log_->Clear(); |
| 385 | } |
| 386 | |
| 387 | void SetUp() { |
| 388 | bt_log_ = new BluetoothLog(); |
| 389 | // Clear existing metrics entries, if any |
| 390 | BluetoothMetricsLogger::GetInstance()->Reset(); |
| 391 | } |
| 392 | void TearDown() { |
| 393 | // Clear remaining metrics entries, if any |
| 394 | BluetoothMetricsLogger::GetInstance()->Reset(); |
| 395 | ClearLog(); |
| 396 | delete bt_log_; |
| 397 | } |
| 398 | |
| 399 | public: |
| 400 | }; |
| 401 | |
| 402 | TEST_F(BluetoothMetricsLoggerTest, PairEventTest) { |
| 403 | pair_events_.push_back(MakePairEvent( |
| 404 | 35, 12345, |
| 405 | MakeDeviceInfo( |
| 406 | 42, DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR))); |
| 407 | UpdateLog(); |
| 408 | BluetoothMetricsLogger::GetInstance()->LogPairEvent( |
| 409 | 35, 12345, 42, system_bt_osi::DEVICE_TYPE_BREDR); |
| 410 | std::string msg_str; |
| 411 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 412 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 413 | } |
| 414 | |
| 415 | TEST_F(BluetoothMetricsLoggerTest, WakeEventTest) { |
| 416 | wake_events_.push_back( |
| 417 | MakeWakeEvent(WakeEvent_WakeEventType::WakeEvent_WakeEventType_ACQUIRED, |
| 418 | "TEST_REQ", "TEST_NAME", 12345)); |
| 419 | UpdateLog(); |
| 420 | BluetoothMetricsLogger::GetInstance()->LogWakeEvent( |
| 421 | system_bt_osi::WAKE_EVENT_ACQUIRED, "TEST_REQ", "TEST_NAME", 12345); |
| 422 | std::string msg_str; |
| 423 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 424 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 425 | } |
| 426 | |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 427 | TEST_F(BluetoothMetricsLoggerTest, WakeEventOverrunTest) { |
| 428 | GenerateWakeEvents( |
| 429 | kMaxEventGenerationLimit - BluetoothMetricsLogger::kMaxNumWakeEvent, |
| 430 | kMaxEventGenerationLimit, &wake_events_); |
| 431 | num_wake_event_ = kMaxEventGenerationLimit; |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 432 | UpdateLog(); |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 433 | for (size_t i = 0; i < kMaxEventGenerationLimit; ++i) { |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 434 | BluetoothMetricsLogger::GetInstance()->LogWakeEvent( |
| 435 | i % 2 == 0 ? system_bt_osi::WAKE_EVENT_ACQUIRED |
| 436 | : system_bt_osi::WAKE_EVENT_RELEASED, |
| 437 | "TEST_REQ", "TEST_NAME", i); |
| 438 | } |
| 439 | std::string msg_str; |
| 440 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 441 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 442 | } |
| 443 | |
| 444 | TEST_F(BluetoothMetricsLoggerTest, ScanEventTest) { |
| 445 | scan_events_.push_back(MakeScanEvent( |
| 446 | ScanEvent_ScanEventType::ScanEvent_ScanEventType_SCAN_EVENT_STOP, |
| 447 | "TEST_INITIATOR", ScanEvent_ScanTechnologyType:: |
| 448 | ScanEvent_ScanTechnologyType_SCAN_TECH_TYPE_BREDR, |
| 449 | 42, 123456)); |
| 450 | UpdateLog(); |
| 451 | BluetoothMetricsLogger::GetInstance()->LogScanEvent( |
| 452 | false, "TEST_INITIATOR", system_bt_osi::SCAN_TECH_TYPE_BREDR, 42, 123456); |
| 453 | std::string msg_str; |
| 454 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 455 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 456 | } |
| 457 | |
| 458 | TEST_F(BluetoothMetricsLoggerTest, BluetoothSessionTest) { |
| 459 | bt_sessions_.push_back(MakeBluetoothSession( |
| 460 | 10, |
| 461 | BluetoothSession_ConnectionTechnologyType:: |
| 462 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_LE, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 463 | BluetoothSession_DisconnectReasonType:: |
| 464 | BluetoothSession_DisconnectReasonType_UNKNOWN, |
| 465 | nullptr, nullptr, nullptr)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 466 | UpdateLog(); |
| 467 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( |
| 468 | system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, 123456); |
| 469 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd( |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 470 | system_bt_osi::DISCONNECT_REASON_UNKNOWN, 133456); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 471 | std::string msg_str; |
| 472 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 473 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 474 | } |
| 475 | |
| 476 | TEST_F(BluetoothMetricsLoggerTest, BluetoothSessionDumpBeforeEndTest) { |
| 477 | bt_sessions_.push_back(MakeBluetoothSession( |
| 478 | 1, |
| 479 | BluetoothSession_ConnectionTechnologyType:: |
| 480 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_LE, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 481 | BluetoothSession_DisconnectReasonType:: |
| 482 | BluetoothSession_DisconnectReasonType_METRICS_DUMP, |
| 483 | nullptr, nullptr, nullptr)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 484 | UpdateLog(); |
| 485 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( |
| 486 | system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, time_get_os_boottime_ms()); |
| 487 | sleep_ms(1000); |
| 488 | std::string msg_str; |
| 489 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 490 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 491 | } |
| 492 | |
| 493 | TEST_F(BluetoothMetricsLoggerTest, BluetoothSessionStartBeforeEndTest) { |
| 494 | bt_sessions_.push_back(MakeBluetoothSession( |
| 495 | 1, |
| 496 | BluetoothSession_ConnectionTechnologyType:: |
| 497 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_UNKNOWN, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 498 | BluetoothSession_DisconnectReasonType:: |
| 499 | BluetoothSession_DisconnectReasonType_NEXT_START_WITHOUT_END_PREVIOUS, |
| 500 | nullptr, nullptr, nullptr)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 501 | bt_sessions_.push_back(MakeBluetoothSession( |
| 502 | 2, |
| 503 | BluetoothSession_ConnectionTechnologyType:: |
| 504 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_LE, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 505 | BluetoothSession_DisconnectReasonType:: |
| 506 | BluetoothSession_DisconnectReasonType_METRICS_DUMP, |
| 507 | nullptr, nullptr, nullptr)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 508 | UpdateLog(); |
| 509 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( |
| 510 | system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_UNKNOWN, 0); |
| 511 | sleep_ms(1000); |
| 512 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( |
| 513 | system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_LE, 0); |
| 514 | sleep_ms(2000); |
| 515 | std::string msg_str; |
| 516 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 517 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 518 | } |
| 519 | |
| 520 | /* |
| 521 | * Test Case: A2DPSessionTwoUpdatesTest |
| 522 | * |
| 523 | * 1. Create Instance |
| 524 | * 2. LogBluetoothSessionStart |
| 525 | * 3. LogBluetoothSessionDeviceInfo |
| 526 | * 4. LogA2dpSession |
| 527 | * 5. LogA2dpSession |
| 528 | * 6. LogBluetoothSessionEnd |
| 529 | * 7. WriteString |
| 530 | * |
| 531 | */ |
| 532 | TEST_F(BluetoothMetricsLoggerTest, A2DPSessionTwoUpdatesTest) { |
| 533 | /* Same metrics from BluetoothA2DPSessionMetricsTest.TestUpdateNormal */ |
| 534 | A2dpSessionMetrics metrics1; |
| 535 | A2dpSessionMetrics metrics2; |
| 536 | A2dpSessionMetrics metrics_sum; |
| 537 | metrics1.audio_duration_ms = 10; |
| 538 | metrics2.audio_duration_ms = 25; |
| 539 | metrics_sum.audio_duration_ms = 35; |
| 540 | metrics1.media_timer_min_ms = 10; |
| 541 | metrics2.media_timer_min_ms = 25; |
| 542 | metrics_sum.media_timer_min_ms = 10; |
| 543 | metrics1.media_timer_max_ms = 100; |
| 544 | metrics2.media_timer_max_ms = 200; |
| 545 | metrics_sum.media_timer_max_ms = 200; |
| 546 | metrics1.media_timer_avg_ms = 50; |
| 547 | metrics1.total_scheduling_count = 50; |
| 548 | metrics2.media_timer_avg_ms = 100; |
| 549 | metrics2.total_scheduling_count = 50; |
| 550 | metrics_sum.media_timer_avg_ms = 75; |
| 551 | metrics_sum.total_scheduling_count = 100; |
| 552 | metrics1.buffer_overruns_max_count = 70; |
| 553 | metrics2.buffer_overruns_max_count = 80; |
| 554 | metrics_sum.buffer_overruns_max_count = 80; |
| 555 | metrics1.buffer_underruns_average = 80; |
| 556 | metrics1.buffer_underruns_count = 1200; |
| 557 | metrics2.buffer_underruns_average = 130; |
| 558 | metrics2.buffer_underruns_count = 2400; |
| 559 | metrics_sum.buffer_underruns_average = 113.33333333; |
| 560 | metrics_sum.buffer_underruns_count = 3600; |
| 561 | DeviceInfo* info = MakeDeviceInfo( |
| 562 | BTM_COD_MAJOR_AUDIO_TEST, |
| 563 | DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR); |
| 564 | A2DPSession* session = MakeA2DPSession(metrics_sum); |
| 565 | bt_sessions_.push_back(MakeBluetoothSession( |
| 566 | 10, |
| 567 | BluetoothSession_ConnectionTechnologyType:: |
| 568 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_BREDR, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 569 | BluetoothSession_DisconnectReasonType:: |
| 570 | BluetoothSession_DisconnectReasonType_UNKNOWN, |
| 571 | info, nullptr, session)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 572 | UpdateLog(); |
| 573 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( |
| 574 | system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 123456); |
| 575 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo( |
| 576 | BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR); |
| 577 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1); |
| 578 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2); |
| 579 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd( |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 580 | system_bt_osi::DISCONNECT_REASON_UNKNOWN, 133456); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 581 | std::string msg_str; |
| 582 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 583 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Test Case: A2DPSessionTwoUpdatesSeparatedbyDumpTest |
| 588 | * |
| 589 | * 1. Create Instance |
| 590 | * 2. LogBluetoothSessionStart |
| 591 | * 3. LogBluetoothSessionDeviceInfo |
| 592 | * 4. LogA2dpSession |
| 593 | * 5. WriteString |
| 594 | * 6. LogA2dpSession |
| 595 | * 7. LogBluetoothSessionEnd |
| 596 | * 8. WriteString |
| 597 | * |
| 598 | */ |
| 599 | TEST_F(BluetoothMetricsLoggerTest, A2DPSessionTwoUpdatesSeparatedbyDumpTest) { |
| 600 | /* Same metrics from BluetoothA2DPSessionMetricsTest.TestUpdateNormal */ |
| 601 | A2dpSessionMetrics metrics1; |
| 602 | A2dpSessionMetrics metrics2; |
| 603 | metrics1.audio_duration_ms = 10; |
| 604 | metrics2.audio_duration_ms = 25; |
| 605 | metrics1.media_timer_min_ms = 10; |
| 606 | metrics2.media_timer_min_ms = 25; |
| 607 | metrics1.media_timer_max_ms = 100; |
| 608 | metrics2.media_timer_max_ms = 200; |
| 609 | metrics1.media_timer_avg_ms = 50; |
| 610 | metrics1.total_scheduling_count = 50; |
| 611 | metrics2.media_timer_avg_ms = 100; |
| 612 | metrics2.total_scheduling_count = 50; |
| 613 | metrics1.buffer_overruns_max_count = 70; |
| 614 | metrics2.buffer_overruns_max_count = 80; |
| 615 | metrics1.buffer_underruns_average = 80; |
| 616 | metrics1.buffer_underruns_count = 1200; |
| 617 | metrics2.buffer_underruns_average = 130; |
| 618 | metrics2.buffer_underruns_count = 2400; |
| 619 | DeviceInfo* info = MakeDeviceInfo( |
| 620 | BTM_COD_MAJOR_AUDIO_TEST, |
| 621 | DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR); |
| 622 | A2DPSession* session = MakeA2DPSession(metrics1); |
| 623 | bt_sessions_.push_back(MakeBluetoothSession( |
| 624 | 1, |
| 625 | BluetoothSession_ConnectionTechnologyType:: |
| 626 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_BREDR, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 627 | BluetoothSession_DisconnectReasonType:: |
| 628 | BluetoothSession_DisconnectReasonType_METRICS_DUMP, |
| 629 | info, nullptr, session)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 630 | UpdateLog(); |
| 631 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( |
| 632 | system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0); |
| 633 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo( |
| 634 | BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR); |
| 635 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1); |
| 636 | sleep_ms(1000); |
| 637 | std::string msg_str; |
| 638 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 639 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 640 | ClearLog(); |
| 641 | info = MakeDeviceInfo( |
| 642 | BTM_COD_MAJOR_AUDIO_TEST, |
| 643 | DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR); |
| 644 | session = MakeA2DPSession(metrics2); |
| 645 | bt_sessions_.push_back(MakeBluetoothSession( |
| 646 | 1, |
| 647 | BluetoothSession_ConnectionTechnologyType:: |
| 648 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_BREDR, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 649 | BluetoothSession_DisconnectReasonType:: |
| 650 | BluetoothSession_DisconnectReasonType_UNKNOWN, |
| 651 | info, nullptr, session)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 652 | UpdateLog(); |
| 653 | sleep_ms(1000); |
| 654 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2); |
| 655 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd( |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 656 | system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 657 | msg_str.clear(); |
| 658 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 659 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 660 | } |
| 661 | |
| 662 | /* |
| 663 | * Test Case 1: A2DPSessionOnlyTest |
| 664 | * |
| 665 | * 1. Create Instance |
| 666 | * 4. LogA2dpSession |
| 667 | * 5. WriteString |
| 668 | * 6. LogA2dpSession |
| 669 | * 8. WriteString |
| 670 | * |
| 671 | */ |
| 672 | TEST_F(BluetoothMetricsLoggerTest, A2DPSessionOnlyTest) { |
| 673 | /* Same metrics from BluetoothA2DPSessionMetricsTest.TestUpdateNormal */ |
| 674 | A2dpSessionMetrics metrics1; |
| 675 | A2dpSessionMetrics metrics2; |
| 676 | A2dpSessionMetrics metrics_sum; |
| 677 | metrics1.audio_duration_ms = 10; |
| 678 | metrics2.audio_duration_ms = 25; |
| 679 | metrics_sum.audio_duration_ms = 35; |
| 680 | metrics1.media_timer_min_ms = 10; |
| 681 | metrics2.media_timer_min_ms = 25; |
| 682 | metrics_sum.media_timer_min_ms = 10; |
| 683 | metrics1.media_timer_max_ms = 100; |
| 684 | metrics2.media_timer_max_ms = 200; |
| 685 | metrics_sum.media_timer_max_ms = 200; |
| 686 | metrics1.media_timer_avg_ms = 50; |
| 687 | metrics1.total_scheduling_count = 50; |
| 688 | metrics2.media_timer_avg_ms = 100; |
| 689 | metrics2.total_scheduling_count = 50; |
| 690 | metrics_sum.media_timer_avg_ms = 75; |
| 691 | metrics_sum.total_scheduling_count = 100; |
| 692 | metrics1.buffer_overruns_max_count = 70; |
| 693 | metrics2.buffer_overruns_max_count = 80; |
| 694 | metrics_sum.buffer_overruns_max_count = 80; |
| 695 | metrics1.buffer_underruns_average = 80; |
| 696 | metrics1.buffer_underruns_count = 1200; |
| 697 | metrics2.buffer_underruns_average = 130; |
| 698 | metrics2.buffer_underruns_count = 2400; |
| 699 | metrics_sum.buffer_underruns_average = 113.33333333; |
| 700 | metrics_sum.buffer_underruns_count = 3600; |
| 701 | DeviceInfo* info = MakeDeviceInfo( |
| 702 | BTM_COD_MAJOR_AUDIO_TEST, |
| 703 | DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR); |
| 704 | A2DPSession* session = MakeA2DPSession(metrics_sum); |
| 705 | bt_sessions_.push_back(MakeBluetoothSession( |
| 706 | 1, |
| 707 | BluetoothSession_ConnectionTechnologyType:: |
| 708 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_BREDR, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 709 | BluetoothSession_DisconnectReasonType:: |
| 710 | BluetoothSession_DisconnectReasonType_METRICS_DUMP, |
| 711 | info, nullptr, session)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 712 | UpdateLog(); |
| 713 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1); |
| 714 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2); |
| 715 | sleep_ms(1000); |
| 716 | std::string msg_str; |
| 717 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 718 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Test Case: A2DPSessionDumpBeforeTwoUpdatesTest |
| 723 | * |
| 724 | * 1. Create Instance |
| 725 | * 2. LogBluetoothSessionStart |
| 726 | * 3. LogBluetoothSessionDeviceInfo |
| 727 | * 5. WriteString |
| 728 | * 6. LogA2dpSession |
| 729 | * 7. LogA2dpSession |
| 730 | * 8. LogBluetoothSessionEnd |
| 731 | * 9. WriteString |
| 732 | * |
| 733 | */ |
| 734 | TEST_F(BluetoothMetricsLoggerTest, A2DPSessionDumpBeforeTwoUpdatesTest) { |
| 735 | /* Same metrics from BluetoothA2DPSessionMetricsTest.TestUpdateNormal */ |
| 736 | A2dpSessionMetrics metrics1; |
| 737 | A2dpSessionMetrics metrics2; |
| 738 | A2dpSessionMetrics metrics_sum; |
| 739 | metrics1.audio_duration_ms = 10; |
| 740 | metrics2.audio_duration_ms = 25; |
| 741 | metrics_sum.audio_duration_ms = 35; |
| 742 | metrics1.media_timer_min_ms = 10; |
| 743 | metrics2.media_timer_min_ms = 25; |
| 744 | metrics_sum.media_timer_min_ms = 10; |
| 745 | metrics1.media_timer_max_ms = 100; |
| 746 | metrics2.media_timer_max_ms = 200; |
| 747 | metrics_sum.media_timer_max_ms = 200; |
| 748 | metrics1.media_timer_avg_ms = 50; |
| 749 | metrics1.total_scheduling_count = 50; |
| 750 | metrics2.media_timer_avg_ms = 100; |
| 751 | metrics2.total_scheduling_count = 50; |
| 752 | metrics_sum.media_timer_avg_ms = 75; |
| 753 | metrics_sum.total_scheduling_count = 100; |
| 754 | metrics1.buffer_overruns_max_count = 70; |
| 755 | metrics2.buffer_overruns_max_count = 80; |
| 756 | metrics_sum.buffer_overruns_max_count = 80; |
| 757 | metrics1.buffer_underruns_average = 80; |
| 758 | metrics1.buffer_underruns_count = 1200; |
| 759 | metrics2.buffer_underruns_average = 130; |
| 760 | metrics2.buffer_underruns_count = 2400; |
| 761 | metrics_sum.buffer_underruns_average = 113.33333333; |
| 762 | metrics_sum.buffer_underruns_count = 3600; |
| 763 | DeviceInfo* info = MakeDeviceInfo( |
| 764 | BTM_COD_MAJOR_AUDIO_TEST, |
| 765 | DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR); |
| 766 | bt_sessions_.push_back(MakeBluetoothSession( |
| 767 | 1, |
| 768 | BluetoothSession_ConnectionTechnologyType:: |
| 769 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_BREDR, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 770 | BluetoothSession_DisconnectReasonType:: |
| 771 | BluetoothSession_DisconnectReasonType_METRICS_DUMP, |
| 772 | info, nullptr, nullptr)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 773 | UpdateLog(); |
| 774 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionStart( |
| 775 | system_bt_osi::CONNECTION_TECHNOLOGY_TYPE_BREDR, 0); |
| 776 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionDeviceInfo( |
| 777 | BTM_COD_MAJOR_AUDIO_TEST, system_bt_osi::DEVICE_TYPE_BREDR); |
| 778 | sleep_ms(1000); |
| 779 | std::string msg_str; |
| 780 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 781 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 782 | ClearLog(); |
| 783 | info = MakeDeviceInfo( |
| 784 | BTM_COD_MAJOR_AUDIO_TEST, |
| 785 | DeviceInfo_DeviceType::DeviceInfo_DeviceType_DEVICE_TYPE_BREDR); |
| 786 | A2DPSession* session = MakeA2DPSession(metrics_sum); |
| 787 | bt_sessions_.push_back(MakeBluetoothSession( |
| 788 | 1, |
| 789 | BluetoothSession_ConnectionTechnologyType:: |
| 790 | BluetoothSession_ConnectionTechnologyType_CONNECTION_TECHNOLOGY_TYPE_BREDR, |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 791 | BluetoothSession_DisconnectReasonType:: |
| 792 | BluetoothSession_DisconnectReasonType_UNKNOWN, |
| 793 | info, nullptr, session)); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 794 | UpdateLog(); |
| 795 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics1); |
| 796 | BluetoothMetricsLogger::GetInstance()->LogA2dpSession(metrics2); |
| 797 | sleep_ms(1000); |
| 798 | BluetoothMetricsLogger::GetInstance()->LogBluetoothSessionEnd( |
Jack He | a3f831c | 2017-01-17 15:41:30 -0800 | [diff] [blame] | 799 | system_bt_osi::DISCONNECT_REASON_UNKNOWN, 0); |
Jack He | f317562 | 2016-12-08 19:29:00 -0800 | [diff] [blame] | 800 | msg_str.clear(); |
| 801 | BluetoothMetricsLogger::GetInstance()->WriteString(&msg_str, true); |
| 802 | EXPECT_THAT(msg_str, StrEq(bt_log_str_)); |
| 803 | } |
| 804 | } |