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