def sync_device_time(self): self.adb.shell("settings put global auto_time 0") self.adb.shell("settings put global auto_time_zone 0") device_tz = self.adb.shell("date +%z") asserts.assert_true(device_tz, "date +%z must return device timezone, " "but returned {} instead".format(device_tz)) host_tz = time.strftime("%z") if device_tz != host_tz: target_timezone = utils.get_timezone_olson_id() logging.debug("Device timezone %s does not match host timezone %s, " "syncing them by setting timezone to %s" % (device_tz, host_tz, target_timezone)) self.adb.shell("setprop persist.sys.timezone %s" % target_timezone) self.reboot() device_tz = self.adb.shell("date +%z") asserts.assert_equal( host_tz, device_tz, "Device timezone %s still does not match host " "timezone %s after reset" % (device_tz, host_tz)) self.adb.shell("date %s" % time.strftime("%m%d%H%M%Y.%S")) datetime_format = "%Y-%m-%dT%H:%M:%S%z" try: device_time = datetime.strptime(self.adb.shell("date +'%s'" % datetime_format), datetime_format) except ValueError: asserts.fail("Failed to get time after sync") return # Include ADB delay that might be longer in SSH environment max_delta_seconds = 3 host_time = datetime.now(tz=device_time.tzinfo) asserts.assert_almost_equal( (device_time - host_time).total_seconds(), 0, msg="Device time %s and host time %s off by >%dms after sync" % (device_time.isoformat(), host_time.isoformat(), int(max_delta_seconds * 1000)), delta=max_delta_seconds)
def test_run_multiple_bt_audio(self): """Test metrics for multiple Bluetooth audio sessions This test will run Bluetooth A2DP audio for five 30 seconds sessions and collect metrics after that Steps: 1. For the first Android device connected, run A2DP audio for 30 seconds for 5 times 2. Dump and compare metrics Expected Result: There should be a single Bluetooth session with session_duration_sec = 250 +/- 10 audio_duration_millis = 150000 +/- 20000 Note: The discrepancies are mainly due to command delays Returns: Pass if True Fail if False TAGS: Classic, A2DP Priority: 1 """ num_play = 5 play_duration_seconds = 30 bt_duration = 0 a2dp_duration = 0 for i in range(num_play): start_time = time.time() status, bluetooth_off_list, device_not_connected_list = \ self.play_music_for_duration(play_duration_seconds) if not status: return status a2dp_duration += (time.time() - start_time) time.sleep(20) bt_duration += (time.time() - start_time) bluetooth_logs, bluetooth_logs_ascii = \ self.collect_bluetooth_manager_metrics_logs( [self.android_devices[0]]) bluetooth_log = bluetooth_logs[0] bluetooth_log_ascii = bluetooth_logs_ascii[0] self.log.info(bluetooth_log_ascii) asserts.assert_equal(len(bluetooth_log.session), 1) a2dp_session_log = bluetooth_log.session[0] asserts.assert_almost_equal(a2dp_session_log.session_duration_sec, bt_duration, delta=10) asserts.assert_almost_equal( a2dp_session_log.a2dp_session.audio_duration_millis, a2dp_duration * 1000, delta=20000) return True
def test_run_bt_audio(self): """Test run Bluetooth A2DP audio for one iteration This test runs Bluetooth A2DP Audio for 60 seconds and sleep for 20 seconds. Steps: 1. For the first Android device, run audio for 60 seconds 2. Sleep while connected to A2DP sink for 20 seconds 3. Pull Bluetooth metrics 4. Verify metrics values Expected Result: The correct metrics should have one Bluetooth session with audio_duration_millis = 60000 +/- 10000 session_duration_sec = 80 +/- 10 Returns: Pass if True Fail if False TAGS: Classic, A2DP Priority: 1 """ play_duration_seconds = 60 start_time = time.time() status, bluetooth_off_list, device_not_connected_list = \ self.play_music_for_duration(play_duration_seconds) if not status: return status self.stop_playing_music_on_all_devices() time.sleep(20) bt_duration = time.time() - start_time bluetooth_logs, bluetooth_logs_ascii = \ self.collect_bluetooth_manager_metrics_logs( [self.android_devices[0]]) bluetooth_log = bluetooth_logs[0] bluetooth_log_ascii = bluetooth_logs_ascii[0] self.log.info(bluetooth_log_ascii) asserts.assert_equal(len(bluetooth_log.session), 1) a2dp_session_log = bluetooth_log.session[0] asserts.assert_almost_equal(a2dp_session_log.session_duration_sec, bt_duration, delta=10) asserts.assert_almost_equal( a2dp_session_log.a2dp_session.audio_duration_millis, play_duration_seconds * 1000, delta=10000) return True
def test_run_multiple_bt_audio_dump_each(self): """Test run Bluetooth A2DP audio multiple times and dump metrics each time Steps: 1. For the first Android device connected, run A2DP audio for 30 seconds 2. Sleep for 20 seconds 3. Dump metrics and compare 4. Repeate steps 1-3 five times Expected Result: Each time, we should observe the following: session_duration_sec = 50 +/- 10 audio_duration_millis = 30 +/- 5 Returns: Pass if True Fail if False TAGS: Classic, A2DP Priority: 1 """ num_play = 5 play_duration_seconds = 30 for i in range(num_play): start_time = time.time() status, bluetooth_off_list, device_not_connected_list = \ self.play_music_for_duration(play_duration_seconds) if not status: return status time.sleep(20) bt_duration = time.time() - start_time bluetooth_logs, bluetooth_logs_ascii = \ self.collect_bluetooth_manager_metrics_logs( [self.android_devices[0]]) bluetooth_log = bluetooth_logs[0] bluetooth_log_ascii = bluetooth_logs_ascii[0] self.log.info(bluetooth_log_ascii) asserts.assert_equal(len(bluetooth_log.session), 1) a2dp_session_log = bluetooth_log.session[0] asserts.assert_almost_equal(a2dp_session_log.session_duration_sec, bt_duration, delta=10) asserts.assert_almost_equal( a2dp_session_log.a2dp_session.audio_duration_millis, play_duration_seconds * 1000, delta=5000) return True