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 Wifi MCC in a general case. 16 17In this case, even though the expected wifi medium is the WFD, but the wifi D2D 18could be any wifi mediums, such as WFD, HOTSPOT, WifiLan; Once the WFD is 19failed, other meidums will be tried. As DBS is not supported by both devices, 20and the STA is coonected with 2G channel, D2D medium is using a 5G channel, 21this cause the MCC case. 22 23The device requirements: 24 support 5G: true 25 support DBS (target device): false 26The AP requirements: 27 wifi channel: 6 (2437) 28""" 29 30import logging 31import os 32import sys 33 34# Allows local imports to be resolved via relative path, so the test can be run 35# without building. 36_betocq_dir = os.path.dirname(os.path.dirname(__file__)) 37if _betocq_dir not in sys.path: 38 sys.path.append(_betocq_dir) 39 40from mobly import base_test 41from mobly import test_runner 42 43from betocq import d2d_performance_test_base 44from betocq import nc_constants 45 46 47class Mcc5gAllWifiNonDbs2gStaTest( 48 d2d_performance_test_base.D2dPerformanceTestBase): 49 """Test class for CUJ MCC with 5G D2D medium and 2G WLAN test.""" 50 51 def _get_country_code(self) -> str: 52 return 'US' 53 54 def setup_class(self): 55 super().setup_class() 56 self._is_mcc = True 57 self.performance_test_iterations = getattr( 58 self.test_mcc_5g_all_wifi_non_dbs_2g_sta, base_test.ATTR_REPEAT_CNT 59 ) 60 logging.info( 61 'performance test iterations: %s', self.performance_test_iterations 62 ) 63 64 @base_test.repeat( 65 count=nc_constants.MCC_PERFORMANCE_TEST_COUNT, 66 max_consecutive_error=nc_constants.MCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR, 67 ) 68 def test_mcc_5g_all_wifi_non_dbs_2g_sta(self): 69 self._test_connection_medium_performance( 70 upgrade_medium_under_test=nc_constants.NearbyMedium.UPGRADE_TO_ALL_WIFI, 71 wifi_ssid=self.test_parameters.wifi_2g_ssid, 72 wifi_password=self.test_parameters.wifi_2g_password, 73 ) 74 75 def _get_file_transfer_failure_tip(self) -> str: 76 upgraded_medium_name = None 77 if (self._current_test_result.quality_info.upgrade_medium 78 is not None): 79 upgraded_medium_name = ( 80 self._current_test_result.quality_info.upgrade_medium.name 81 ) 82 83 return ( 84 f'The upgraded wifi medium {upgraded_medium_name} might be broken, ' 85 f'check the related log, Or {self._get_throughput_low_tip()}' 86 ) 87 88 def _get_throughput_low_tip(self) -> str: 89 upgraded_medium_name = None 90 if (self._current_test_result.quality_info.upgrade_medium 91 is not None): 92 upgraded_medium_name = ( 93 self._current_test_result.quality_info.upgrade_medium.name 94 ) 95 return ( 96 f'{self._throughput_low_string}. The upgraded medium is' 97 f' {upgraded_medium_name} Check with the wifi chip vendor for any FW' 98 ' issue in MCC mode' 99 ) 100 101 def _is_wifi_ap_ready(self) -> bool: 102 return True if self.test_parameters.wifi_2g_ssid else False 103 104 @property 105 def _devices_capabilities_definition(self) -> dict[str, dict[str, bool]]: 106 return { 107 'discoverer': { 108 'supports_5g': True, 109 }, 110 'advertiser': { 111 'supports_5g': True, 112 'supports_dbs_sta_wfd': False, 113 }, 114 } 115 116 117if __name__ == '__main__': 118 test_runner.main() 119