• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
14import time
15
16from acts.test_decorators import test_tracker_info
17from acts import asserts
18from acts_contrib.test_utils.bt.BtFunhausBaseTest import BtFunhausBaseTest
19
20
21class BtFunhausMetricsTest(BtFunhausBaseTest):
22    def __init__(self, controllers):
23        BtFunhausBaseTest.__init__(self, controllers)
24        self.metrics_path = None
25
26    def setup_class(self):
27        return super(BtFunhausMetricsTest, self).setup_class()
28
29    def setup_test(self):
30        return super(BtFunhausMetricsTest, self).setup_test()
31
32    @test_tracker_info(uuid='b712ed0e-c1fb-4bc8-9dee-83891aa22205')
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        if not self.play_music_for_duration(play_duration_seconds):
60            return False
61        self.ad.droid.mediaPlayStopAll()
62        time.sleep(20)
63        bt_duration = time.time() - start_time
64        bluetooth_logs, bluetooth_logs_ascii = \
65            self.collect_bluetooth_manager_metrics_logs(
66                [self.ad])
67        bluetooth_log = bluetooth_logs[0]
68        bluetooth_log_ascii = bluetooth_logs_ascii[0]
69        self.log.info(bluetooth_log_ascii)
70        asserts.assert_equal(len(bluetooth_log.session), 1)
71        a2dp_session_log = bluetooth_log.session[0]
72        asserts.assert_almost_equal(
73            a2dp_session_log.session_duration_sec, bt_duration, delta=10)
74        asserts.assert_almost_equal(
75            a2dp_session_log.a2dp_session.audio_duration_millis,
76            play_duration_seconds * 1000,
77            delta=10000)
78        return True
79
80    @test_tracker_info(uuid='ab6b8c61-057b-4bf6-b0cf-8bec3ae3a7eb')
81    def test_run_multiple_bt_audio(self):
82        """Test metrics for multiple Bluetooth audio sessions
83
84        This test will run Bluetooth A2DP audio for five 30 seconds sessions
85        and collect metrics after that
86
87        Steps:
88        1. For the first Android device connected, run A2DP audio for 30
89        seconds for 5 times
90        2. Dump and compare metrics
91
92        Expected Result:
93        There should be a single Bluetooth session with
94            session_duration_sec = 250 +/- 10
95            audio_duration_millis = 150000 +/- 20000
96
97        Note: The discrepancies are mainly due to command delays
98
99        Returns:
100          Pass if True
101          Fail if False
102
103        TAGS: Classic, A2DP
104        Priority: 1
105        """
106        num_play = 5
107        play_duration_seconds = 30
108        bt_duration = 0
109        a2dp_duration = 0
110        for i in range(num_play):
111            start_time = time.time()
112            if not self.play_music_for_duration(play_duration_seconds):
113                return False
114            a2dp_duration += (time.time() - start_time)
115            time.sleep(20)
116            bt_duration += (time.time() - start_time)
117        bluetooth_logs, bluetooth_logs_ascii = \
118            self.collect_bluetooth_manager_metrics_logs(
119                [self.android_devices[0]])
120        bluetooth_log = bluetooth_logs[0]
121        bluetooth_log_ascii = bluetooth_logs_ascii[0]
122        self.log.info(bluetooth_log_ascii)
123        asserts.assert_equal(len(bluetooth_log.session), 1)
124        a2dp_session_log = bluetooth_log.session[0]
125        asserts.assert_almost_equal(
126            a2dp_session_log.session_duration_sec, bt_duration, delta=10)
127        asserts.assert_almost_equal(
128            a2dp_session_log.a2dp_session.audio_duration_millis,
129            a2dp_duration * 1000,
130            delta=20000)
131        return True
132
133    def test_run_multiple_bt_audio_dump_each(self):
134        """Test run Bluetooth A2DP audio multiple times and dump metrics each time
135
136        Steps:
137        1. For the first Android device connected, run A2DP audio for 30 seconds
138        2. Sleep for 20 seconds
139        3. Dump metrics and compare
140        4. Repeate steps 1-3 five times
141
142        Expected Result:
143        Each time, we should observe the following:
144            session_duration_sec = 50 +/- 10
145            audio_duration_millis = 30 +/- 5
146
147        Returns:
148          Pass if True
149          Fail if False
150
151        TAGS: Classic, A2DP
152        Priority: 1
153        """
154        num_play = 5
155        play_duration_seconds = 30
156        for i in range(num_play):
157            start_time = time.time()
158            if not self.play_music_for_duration(play_duration_seconds):
159                return False
160            time.sleep(20)
161            bt_duration = time.time() - start_time
162            bluetooth_logs, bluetooth_logs_ascii = \
163                self.collect_bluetooth_manager_metrics_logs(
164                    [self.android_devices[0]])
165            bluetooth_log = bluetooth_logs[0]
166            bluetooth_log_ascii = bluetooth_logs_ascii[0]
167            self.log.info(bluetooth_log_ascii)
168            asserts.assert_equal(len(bluetooth_log.session), 1)
169            a2dp_session_log = bluetooth_log.session[0]
170            asserts.assert_almost_equal(
171                a2dp_session_log.session_duration_sec, bt_duration, delta=10)
172            asserts.assert_almost_equal(
173                a2dp_session_log.a2dp_session.audio_duration_millis,
174                play_duration_seconds * 1000,
175                delta=5000)
176        return True
177