1# Copyright (C) 2024 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"""This Test is to test the classic Bluetooth performance.""" 16 17import datetime 18import logging 19import os 20import sys 21 22# Allows local imports to be resolved via relative path, so the test can be run 23# without building. 24_betocq_dir = os.path.dirname(os.path.dirname(__file__)) 25if _betocq_dir not in sys.path: 26 sys.path.append(_betocq_dir) 27 28from mobly import base_test 29from mobly import test_runner 30 31from betocq import d2d_performance_test_base 32from betocq import nc_constants 33 34 35class BtPerformanceTest(d2d_performance_test_base.D2dPerformanceTestBase): 36 """Test class for the classic Bluetooth connection performance.""" 37 38 def _get_country_code(self) -> str: 39 return 'US' 40 41 def setup_class(self): 42 super().setup_class() 43 self.performance_test_iterations = getattr( 44 self.test_classic_bt_performance, base_test.ATTR_REPEAT_CNT 45 ) 46 logging.info( 47 'performance test iterations: %s', self.performance_test_iterations 48 ) 49 50 @base_test.repeat( 51 count=nc_constants.BT_PERFORMANCE_TEST_COUNT, 52 max_consecutive_error=nc_constants.BT_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR, 53 ) 54 def test_classic_bt_performance(self): 55 """Test the performance of the classic BT connetion.""" 56 self._test_connection_medium_performance( 57 upgrade_medium_under_test=nc_constants.NearbyMedium.BT_ONLY, 58 force_disable_bt_multiplex=True 59 ) 60 61 def _get_transfer_file_size(self) -> int: 62 return nc_constants.TRANSFER_FILE_SIZE_500KB 63 64 def _get_file_transfer_timeout(self) -> datetime.timedelta: 65 return nc_constants.BT_500K_PAYLOAD_TRANSFER_TIMEOUT 66 67 # @typing.override 68 def _get_throughput_benchmark( 69 self, sta_frequency: int, sta_max_link_speed_mbps: int 70 ) -> tuple[float, float]: 71 return ( 72 nc_constants.CLASSIC_BT_MEDIUM_THROUGHPUT_BENCHMARK_MBPS, 73 nc_constants.CLASSIC_BT_MEDIUM_THROUGHPUT_BENCHMARK_MBPS, 74 ) 75 76 def _get_medium_upgrade_failure_tip(self) -> str: 77 return 'Not Applied' # No medium upgrade required for BT. 78 79 def _get_file_transfer_failure_tip(self) -> str: 80 return ( 81 'The classic Bluetooth connection might be broken, check related log, ' 82 f'{self._get_throughput_low_tip()}' 83 ) 84 85 def _get_throughput_low_tip(self) -> str: 86 return ( 87 f'{self._throughput_low_string}. Check with the chip vendor if there is' 88 ' any BT firmware issue.' 89 ) 90 91 def _is_wifi_ap_ready(self) -> bool: 92 # don't require wifi STA. 93 return True 94 95 96if __name__ == '__main__': 97 test_runner.main() 98