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 LAN 2G SCC in a general case. 16 17In this case, both the Wifi LAN and STA(internet AP) are using the 2G channel, 18the Wifi LAN and STA should use the same channel. 19Wifi LAN - The target device starts WFD GO as the role of AP, the source device 20is connected to the AP. 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 Scc2gWlanStaTest(d2d_performance_test_base.D2dPerformanceTestBase): 47 """Test class for Wifi SCC with 2G WifiLAN and STA.""" 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_wifilan_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_wifilan_sta(self): 67 """Test the performance for Wifi SCC with 2G WifiLAN and STA.""" 68 self._test_connection_medium_performance( 69 nc_constants.NearbyMedium.WIFILAN_ONLY, 70 wifi_ssid=self.test_parameters.wifi_2g_ssid, 71 wifi_password=self.test_parameters.wifi_2g_password, 72 ) 73 74 def _get_transfer_file_size(self) -> int: 75 # For 2G wifi medium 76 return nc_constants.TRANSFER_FILE_SIZE_20MB 77 78 def _get_file_transfer_timeout(self) -> datetime.timedelta: 79 return nc_constants.WIFI_2G_20M_PAYLOAD_TRANSFER_TIMEOUT 80 81 def _get_file_transfer_failure_tip(self) -> str: 82 return ( 83 'The WLAN connection might be broken, check related logs, ' 84 f'{self._get_throughput_low_tip()}' 85 ) 86 87 def _get_throughput_low_tip(self) -> str: 88 return ( 89 f'{self._throughput_low_string}.' 90 ' This is a SCC 2G test case with WLAN medium. Check with the wifi chip' 91 ' vendor if TDLS is supported correctly. Also check if' 92 ' the AP has the firewall which could block the mDNS traffic.' 93 ) 94 95 def _is_wifi_ap_ready(self) -> bool: 96 return True if self.test_parameters.wifi_2g_ssid else False 97 98 @property 99 def _devices_capabilities_definition(self) -> dict[str, dict[str, bool]]: 100 return { 101 'discoverer': { 102 'supports_5g': False, 103 }, 104 'advertiser': { 105 'supports_5g': False, 106 }, 107 } 108 109 110if __name__ == '__main__': 111 test_runner.main() 112