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 BLE 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 BlePerformanceTest(d2d_performance_test_base.D2dPerformanceTestBase): 36 """Test class for the BLE 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_ble_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_ble_performance(self): 55 """Test the performance of the BLE.""" 56 self._test_connection_medium_performance( 57 upgrade_medium_under_test=nc_constants.NearbyMedium.BLE_ONLY, 58 force_disable_bt_multiplex=True, 59 connection_medium=nc_constants.NearbyMedium.BLE_ONLY, 60 ) 61 62 def _get_transfer_file_size(self) -> int: 63 return nc_constants.TRANSFER_FILE_SIZE_500KB 64 65 def _get_file_transfer_timeout(self) -> datetime.timedelta: 66 return nc_constants.BLE_500K_PAYLOAD_TRANSFER_TIMEOUT 67 68 # @typing.override 69 def _get_throughput_benchmark( 70 self, sta_frequency: int, sta_max_link_speed_mbps: int 71 ) -> tuple[float, float]: 72 return ( 73 nc_constants.BLE_MEDIUM_THROUGHPUT_BENCHMARK_MBPS, 74 nc_constants.BLE_MEDIUM_THROUGHPUT_BENCHMARK_MBPS, 75 ) 76 77 def _get_medium_upgrade_failure_tip(self) -> str: 78 return 'Not Applied' # No medium upgrade required for BLE. 79 80 def _get_file_transfer_failure_tip(self) -> str: 81 return ( 82 'The BLE connection might be broken, check the related logs, ' 83 f'{self._get_throughput_low_tip()}' 84 ) 85 86 def _get_throughput_low_tip(self) -> str: 87 return ( 88 f'{self._throughput_low_string}. Check with the chip vendor if there is' 89 ' any BT firmware issue.' 90 ) 91 92 def _is_wifi_ap_ready(self) -> bool: 93 # don't require wifi STA. 94 return True 95 96 97if __name__ == '__main__': 98 test_runner.main() 99