Home | History | Annotate | Download | only in audio_lab
      1 # Copyright (C) 2017 The Android Open Source Project
      2 #
      3 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
      4 # use this file except in compliance with the License. You may obtain a copy of
      5 # 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, WITHOUT
     11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     12 # License for the specific language governing permissions and limitations under
     13 # the License.
     14 import time
     15 
     16 from acts import asserts
     17 from acts.test_utils.bt.BtFunhausBaseTest import BtFunhausBaseTest
     18 
     19 
     20 class BtFunhausMetricsTest(BtFunhausBaseTest):
     21     def __init__(self, controllers):
     22         BtFunhausBaseTest.__init__(self, controllers)
     23         self.bluetooth_proto_path = None
     24         self.metrics_path = None
     25         self.bluetooth_proto_module = None
     26 
     27     def setup_class(self):
     28         return super(BtFunhausMetricsTest, self).setup_class()
     29 
     30     def setup_test(self):
     31         return super(BtFunhausMetricsTest, self).setup_test()
     32 
     33     def test_run_bt_audio(self):
     34         """Test run Bluetooth A2DP audio for one iteration
     35 
     36         This test runs Bluetooth A2DP Audio for 60 seconds and sleep for 20
     37         seconds.
     38 
     39         Steps:
     40         1. For the first Android device, run audio for 60 seconds
     41         2. Sleep while connected to A2DP sink for 20 seconds
     42         3. Pull Bluetooth metrics
     43         4. Verify metrics values
     44 
     45         Expected Result:
     46         The correct metrics should have one Bluetooth session with
     47             audio_duration_millis = 60000 +/- 10000
     48             session_duration_sec = 80 +/- 10
     49 
     50         Returns:
     51           Pass if True
     52           Fail if False
     53 
     54         TAGS: Classic, A2DP
     55         Priority: 1
     56         """
     57         play_duration_seconds = 60
     58         start_time = time.time()
     59         status, bluetooth_off_list, device_not_connected_list = \
     60             self.play_music_for_duration(play_duration_seconds)
     61         if not status:
     62             return status
     63         self.stop_playing_music_on_all_devices()
     64         time.sleep(20)
     65         bt_duration = time.time() - start_time
     66         bluetooth_logs, bluetooth_logs_ascii = \
     67             self.collect_bluetooth_manager_metrics_logs(
     68                 [self.android_devices[0]])
     69         bluetooth_log = bluetooth_logs[0]
     70         bluetooth_log_ascii = bluetooth_logs_ascii[0]
     71         self.log.info(bluetooth_log_ascii)
     72         asserts.assert_equal(len(bluetooth_log.session), 1)
     73         a2dp_session_log = bluetooth_log.session[0]
     74         asserts.assert_almost_equal(
     75             a2dp_session_log.session_duration_sec, bt_duration, delta=10)
     76         asserts.assert_almost_equal(
     77             a2dp_session_log.a2dp_session.audio_duration_millis,
     78             play_duration_seconds * 1000,
     79             delta=10000)
     80         return True
     81 
     82     def test_run_multiple_bt_audio(self):
     83         """Test metrics for multiple Bluetooth audio sessions
     84 
     85         This test will run Bluetooth A2DP audio for five 30 seconds sessions
     86         and collect metrics after that
     87 
     88         Steps:
     89         1. For the first Android device connected, run A2DP audio for 30
     90         seconds for 5 times
     91         2. Dump and compare metrics
     92 
     93         Expected Result:
     94         There should be a single Bluetooth session with
     95             session_duration_sec = 250 +/- 10
     96             audio_duration_millis = 150000 +/- 20000
     97 
     98         Note: The discrepancies are mainly due to command delays
     99 
    100         Returns:
    101           Pass if True
    102           Fail if False
    103 
    104         TAGS: Classic, A2DP
    105         Priority: 1
    106         """
    107         num_play = 5
    108         play_duration_seconds = 30
    109         bt_duration = 0
    110         a2dp_duration = 0
    111         for i in range(num_play):
    112             start_time = time.time()
    113             status, bluetooth_off_list, device_not_connected_list = \
    114                 self.play_music_for_duration(play_duration_seconds)
    115             if not status:
    116                 return status
    117             a2dp_duration += (time.time() - start_time)
    118             time.sleep(20)
    119             bt_duration += (time.time() - start_time)
    120         bluetooth_logs, bluetooth_logs_ascii = \
    121             self.collect_bluetooth_manager_metrics_logs(
    122                 [self.android_devices[0]])
    123         bluetooth_log = bluetooth_logs[0]
    124         bluetooth_log_ascii = bluetooth_logs_ascii[0]
    125         self.log.info(bluetooth_log_ascii)
    126         asserts.assert_equal(len(bluetooth_log.session), 1)
    127         a2dp_session_log = bluetooth_log.session[0]
    128         asserts.assert_almost_equal(
    129             a2dp_session_log.session_duration_sec, bt_duration, delta=10)
    130         asserts.assert_almost_equal(
    131             a2dp_session_log.a2dp_session.audio_duration_millis,
    132             a2dp_duration * 1000,
    133             delta=20000)
    134         return True
    135 
    136     def test_run_multiple_bt_audio_dump_each(self):
    137         """Test run Bluetooth A2DP audio multiple times and dump metrics each time
    138 
    139         Steps:
    140         1. For the first Android device connected, run A2DP audio for 30 seconds
    141         2. Sleep for 20 seconds
    142         3. Dump metrics and compare
    143         4. Repeate steps 1-3 five times
    144 
    145         Expected Result:
    146         Each time, we should observe the following:
    147             session_duration_sec = 50 +/- 10
    148             audio_duration_millis = 30 +/- 5
    149 
    150         Returns:
    151           Pass if True
    152           Fail if False
    153 
    154         TAGS: Classic, A2DP
    155         Priority: 1
    156         """
    157         num_play = 5
    158         play_duration_seconds = 30
    159         for i in range(num_play):
    160             start_time = time.time()
    161             status, bluetooth_off_list, device_not_connected_list = \
    162                 self.play_music_for_duration(play_duration_seconds)
    163             if not status:
    164                 return status
    165             time.sleep(20)
    166             bt_duration = time.time() - start_time
    167             bluetooth_logs, bluetooth_logs_ascii = \
    168                 self.collect_bluetooth_manager_metrics_logs(
    169                     [self.android_devices[0]])
    170             bluetooth_log = bluetooth_logs[0]
    171             bluetooth_log_ascii = bluetooth_logs_ascii[0]
    172             self.log.info(bluetooth_log_ascii)
    173             asserts.assert_equal(len(bluetooth_log.session), 1)
    174             a2dp_session_log = bluetooth_log.session[0]
    175             asserts.assert_almost_equal(
    176                 a2dp_session_log.session_duration_sec, bt_duration, delta=10)
    177             asserts.assert_almost_equal(
    178                 a2dp_session_log.a2dp_session.audio_duration_millis,
    179                 play_duration_seconds * 1000,
    180                 delta=5000)
    181         return True
    182