diff --git a/betocq/base_test.py b/betocq/base_test.py index 5ea92f5..7bceaf6 100644 --- a/betocq/base_test.py +++ b/betocq/base_test.py @@ -91,7 +91,7 @@ def setup_class(self) -> None: except (errors.Error, adb.Error, signals.ControllerError) as e: setup_utils.report_error_on_setup_class( self, - 'Failed to get Android devices with error: %s,' + 'Failed to get Android devices with error:' f' {traceback.format_exception(e)}', abort_all=not self.test_parameters.run_all_tests_in_suite, error_class=constants.DeviceRegistrationError, diff --git a/betocq/constants.py b/betocq/constants.py index 09193b7..bf26e7a 100644 --- a/betocq/constants.py +++ b/betocq/constants.py @@ -165,6 +165,9 @@ class TestParameters: wifi_chipset_model: str = '' # check if the test is running in debug mode. debug_mode: bool = False + # Ignore the indoor 5g test for china ap, as China AP has no 5g channel + # for Japan country code. + ignore_indoor_5g_test_for_china_ap: bool = False @classmethod def from_user_params(cls, user_params: dict[str, Any]) -> 'TestParameters': diff --git a/betocq/gms_auto_updates_util.py b/betocq/gms_auto_updates_util.py index 42b7873..8a9f5c5 100644 --- a/betocq/gms_auto_updates_util.py +++ b/betocq/gms_auto_updates_util.py @@ -191,7 +191,14 @@ def _create_or_update_play_store_config( except adb.AdbError as e: self._device.log.warning('failed to pull %s: %s', device_path, e) - config_doc = ElementTree.parse(path) if os.path.isfile(path) else None + config_doc = None + if os.path.isfile(path): + try: + config_doc = ElementTree.parse(path) + except ElementTree.ParseError as e: + self._device.log.warning( + 'failed to parse %s due to %s, assume it as blank config.', path, e + ) changing_element = None root = ( diff --git a/betocq/nearby_connection/betocq_aqt_test_suite.py b/betocq/nearby_connection/betocq_aqt_test_suite.py index 72aff7d..c6c0b7f 100644 --- a/betocq/nearby_connection/betocq_aqt_test_suite.py +++ b/betocq/nearby_connection/betocq_aqt_test_suite.py @@ -35,14 +35,15 @@ from betocq.nearby_connection.directed_tests import xcc_hotspot_dfs_5g_sta_test from betocq.nearby_connection.directed_tests import xcc_wfd_dbs_2g_sta_test from betocq.nearby_connection.directed_tests import xcc_wfd_dfs_5g_sta_test -from betocq.nearby_connection.directed_tests import xcc_wfd_indoor_5g_sta_test +from betocq.nearby_connection.directed_tests import xcc_wfd_ww_5g_sta_test from betocq.nearby_connection.function_tests import beto_cq_function_group_test + _SUITE_NAME = 'AQT' # increment this version number when adding new tests or changing the config # parameters of existing tests. # LINT.IfChange(suite_version) -_SUITE_VERSION = '7' +_SUITE_VERSION = '8' # LINT.ThenChange() @@ -95,7 +96,7 @@ def setup_suite(self, config): # 5G STA self.add_test_class(scc_5g_wfd_sta_test.Scc5gWfdStaTest) self.add_test_class(scc_5g_wlan_sta_test.Scc5gWifiLanStaTest) - self.add_test_class(xcc_wfd_indoor_5g_sta_test.XccWfdIndoor5gStaTest) + self.add_test_class(xcc_wfd_ww_5g_sta_test.XccWfdWw5gStaTest) # 5G DFS STA self.add_test_class(xcc_hotspot_dfs_5g_sta_test.XccHotspotDfs5gStaTest) self.add_test_class(xcc_wfd_dfs_5g_sta_test.XccWfdDfs5gStaTest) diff --git a/betocq/nearby_connection/betocq_test_suite.py b/betocq/nearby_connection/betocq_test_suite.py index 8b6e096..90154b7 100644 --- a/betocq/nearby_connection/betocq_test_suite.py +++ b/betocq/nearby_connection/betocq_test_suite.py @@ -32,7 +32,7 @@ from betocq.nearby_connection.compound_tests import scc_5g_all_wifi_sta_test from betocq.nearby_connection.directed_tests import ble_performance_test from betocq.nearby_connection.directed_tests import bt_performance_test -from betocq.nearby_connection.directed_tests import mcc_2g_wfd_indoor_5g_sta_test +from betocq.nearby_connection.directed_tests import mcc_2g_wfd_ww_5g_sta_test from betocq.nearby_connection.directed_tests import mcc_5g_hotspot_dfs_5g_sta_test from betocq.nearby_connection.directed_tests import mcc_5g_wfd_dfs_5g_sta_test from betocq.nearby_connection.directed_tests import mcc_5g_wfd_non_dbs_2g_sta_test @@ -53,7 +53,7 @@ # increment this version number when adding new tests or changing the config # parameters of existing tests. # LINT.IfChange(suite_version) -_SUITE_VERSION = '1' +_SUITE_VERSION = '2' # LINT.ThenChange() @@ -75,13 +75,13 @@ def setup_suite(self, config): # Directed test cases: self.add_test_class(bt_performance_test.BtPerformanceTest) - self.add_test_class(mcc_2g_wfd_indoor_5g_sta_test.Mcc2gWfdIndoor5gStaTest) self.add_test_class(mcc_5g_hotspot_dfs_5g_sta_test.Mcc5gHotspotDfs5gStaTest) self.add_test_class(mcc_5g_wfd_dfs_5g_sta_test.Mcc5gWfdDfs5gStaTest) self.add_test_class(mcc_5g_wfd_non_dbs_2g_sta_test.Mcc5gWfdNonDbs2gStaTest) self.add_test_class(scc_2g_wfd_sta_test.Scc2gWfdStaTest) self.add_test_class(scc_2g_wlan_sta_test.Scc2gWlanStaTest) self.add_test_class(scc_5g_wfd_dbs_2g_sta_test.Scc5gWfdDbs2gStaTest) + self.add_test_class(mcc_2g_wfd_ww_5g_sta_test.Mcc2gWfdWw5gStaTest) self.add_test_class(scc_5g_wfd_sta_test.Scc5gWfdStaTest) self.add_test_class(scc_5g_wlan_sta_test.Scc5gWifiLanStaTest) self.add_test_class(scc_dfs_5g_hotspot_sta_test.SccDfs5gHotspotStaTest) diff --git a/betocq/nearby_connection/directed_tests/mcc_2g_wfd_indoor_5g_sta_test.py b/betocq/nearby_connection/directed_tests/mcc_2g_wfd_ww_5g_sta_test.py similarity index 80% rename from betocq/nearby_connection/directed_tests/mcc_2g_wfd_indoor_5g_sta_test.py rename to betocq/nearby_connection/directed_tests/mcc_2g_wfd_ww_5g_sta_test.py index 2a23408..8f3cc96 100644 --- a/betocq/nearby_connection/directed_tests/mcc_2g_wfd_indoor_5g_sta_test.py +++ b/betocq/nearby_connection/directed_tests/mcc_2g_wfd_ww_5g_sta_test.py @@ -12,26 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""This test is to test the Wifi MCC with 2G WFD and indoor 5G STA. +"""This test is to test the Wifi MCC with 2G WFD and 5G STA. -This is about the feature - using indoor channels for WFD, for details, refer to -https://drive.google.com/file/d/1Aj77Euao8XkvE6uWF15WMK1XCwmYhdxW/view?resourcekey=0-a69XQup8McOcUnzYN9eh0Q -(confidential) and config_wifiEnableStaIndoorChannelForPeerNetwork - -https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml;l=1147 -In this case, the feature is disabled for the device; The WFD will be started in -a 2G channel, but the STA is using the 5G channel. +This test case is to test the WFD performance when the STA is using the 5G +channel and the WFD is using the 2G channel, which is a scenario that may +occur in real-world usages. Test requirements: The device requirements: support 5G band support Wi-Fi Direct - (target device only) enable_sta_indoor_channel_for_peer_network=False in - config file The AP requirements: - Wi-Fi channel: 36 (5180) or other 5G indoor channels in JP. + Wi-Fi channel: 36 (5180) or any other 5G channels. Test preparations: - Set country code to JP on Android devices. + Set country code to '00' on Android devices. Test steps: 1. Disconnect discoverer from the current connected Wi-Fi network. @@ -45,8 +40,8 @@ Expected results: 1. The file transfer completes and throughput meets the target. The target is calculated according to the device capabilities. - 2. The Wi-Fi STA frequency is an indoor 5G frequency. - 3. The Wi-Fi P2P frequency is different from the STA frequency. + 2. The Wi-Fi STA frequency is a 5G frequency. + 3. The Wi-Fi P2P frequency is a 2G frequency. 4. This test will be repeated for `TEST_ITERATION_NUM` times, requiring a success rate of no less than `SUCCESS_RATE_TARGET`. """ @@ -73,12 +68,12 @@ _FILE_TRANSFER_SIZE_KB = constants.TRANSFER_FILE_SIZE_20MB _FILE_TRANSFER_TIMEOUT = constants.WIFI_2G_20M_PAYLOAD_TRANSFER_TIMEOUT _PAYLOAD_TYPE = constants.PayloadType.FILE -_COUNTRY_CODE = 'JP' +_COUNTRY_CODE = '00' _THROUGHPUT_LOW_TIP = ( 'This is a MCC test case where WFD uses a 2G channel and the STA uses a 5G' - ' indoor channel. Check with the wifi chip vendor about the possible' + ' channel. Check with the wifi chip vendor about the possible' ' firmware Tx/Rx issues in MCC mode.' ) @@ -88,8 +83,8 @@ ) -class Mcc2gWfdIndoor5gStaTest(performance_test_base.PerformanceTestBase): - """Test class for wifi MCC with 2G WFD and indoor 5G STA.""" +class Mcc2gWfdWw5gStaTest(performance_test_base.PerformanceTestBase): + """Test class for wifi MCC with 2G WFD and 5G STA.""" test_runtime: constants.NcTestRuntime wifi_info: constants.WifiInfo @@ -98,14 +93,14 @@ def setup_class(self): super().setup_class() self.setup_wifi_env( - d2d_type=constants.WifiD2DType.MCC_2G_WFD_5G_INDOOR_STA, + d2d_type=constants.WifiD2DType.MCC_2G_WFD_5G_STA, country_code=_COUNTRY_CODE, ) nc_utils.check_wifi_ap_status_in_setup_class( self, self.advertiser, self.test_parameters ) self.wifi_info = constants.WifiInfo.from_test_parameters( - d2d_type=constants.WifiD2DType.MCC_2G_WFD_5G_INDOOR_STA, + d2d_type=constants.WifiD2DType.MCC_2G_WFD_5G_STA, params=self.test_parameters, ) self.test_runtime = constants.NcTestRuntime( @@ -158,19 +153,13 @@ def _assert_test_conditions(self): ) # Check WiFi AP. setup_utils.abort_if_5g_ap_not_ready(self.test_parameters) - # Check device capabilities. - setup_utils.abort_if_device_cap_not_match( - [self.advertiser], - 'enable_sta_indoor_channel_for_peer_network', - expected_value=False, - ) @base_test.repeat( count=TEST_ITERATION_NUM, max_consecutive_error=_MAX_CONSECUTIVE_ERROR, ) - def test_mcc_2g_wfd_indoor_5g_sta(self): - """Test the performance for wifi MCC with 2G WFD and indoor 5G STA.""" + def test_mcc_2g_ww_wfd_5g_sta(self): + """Test the performance for wifi MCC with 2G WFD and 5G STA.""" # Test Step: Connect discoverer to wifi sta. discoverer_sta_op = setup_utils.remove_current_connected_wifi_network( self.discoverer @@ -220,10 +209,8 @@ def test_mcc_2g_wfd_indoor_5g_sta(self): self.test_runtime.is_dbs_mode, sta_frequency=self.current_test_result.sta_frequency, additional_error_message=( - 'Check if enable_sta_indoor_channel_for_peer_network is really' - ' false for the target device. If yes, the device violate the' - ' regulation of Wi-Fi 5G indoor channel. You may work with your' - ' chipset vendor.' + 'You may work with your wifi chipset vendor, in the world wide' + ' mode, WFD should use the 2G channel.' ), ) diff --git a/betocq/nearby_connection/directed_tests/scc_2g_wfd_sta_test.py b/betocq/nearby_connection/directed_tests/scc_2g_wfd_sta_test.py index 0a28371..8dd9522 100644 --- a/betocq/nearby_connection/directed_tests/scc_2g_wfd_sta_test.py +++ b/betocq/nearby_connection/directed_tests/scc_2g_wfd_sta_test.py @@ -18,10 +18,6 @@ Note that the country code is set to JP so that 5G is not available for any D2D mediums. -Note: This test case is not related to the capability of -'enable_sta_indoor_channel_for_peer_network', which is only for 5G when the -device is connected to a sta 5G network. - Test requirements: The device requirements support Wi-Fi Direct @@ -29,7 +25,7 @@ Wi-Fi channel: 6 (2437) or other 2G channels. Test preparations: - Set country code to JP on Android devices. + Set country code to '00' on Android devices. Test steps: 1. Disconnect discoverer from the current connected Wi-Fi network. @@ -71,7 +67,7 @@ _FILE_TRANSFER_SIZE_KB = constants.TRANSFER_FILE_SIZE_20MB _FILE_TRANSFER_TIMEOUT = constants.WIFI_2G_20M_PAYLOAD_TRANSFER_TIMEOUT _PAYLOAD_TYPE = constants.PayloadType.FILE -_COUNTRY_CODE = 'JP' +_COUNTRY_CODE = '00' _THROUGHPUT_LOW_TIP = ( diff --git a/betocq/nearby_connection/directed_tests/scc_indoor_5g_wfd_sta_test.py b/betocq/nearby_connection/directed_tests/scc_indoor_5g_wfd_sta_test.py index 0fc9f5b..5aa3b7b 100644 --- a/betocq/nearby_connection/directed_tests/scc_indoor_5g_wfd_sta_test.py +++ b/betocq/nearby_connection/directed_tests/scc_indoor_5g_wfd_sta_test.py @@ -53,6 +53,7 @@ import time +from mobly import asserts from mobly import base_test from mobly import test_runner from mobly import utils @@ -99,6 +100,10 @@ class SccIndoor5gWfdStaTest(performance_test_base.PerformanceTestBase): def setup_class(self): super().setup_class() + asserts.skip_if( + self.test_parameters.ignore_indoor_5g_test_for_china_ap, + 'Skip indoor 5g test for China AP', + ) self.setup_wifi_env( d2d_type=constants.WifiD2DType.SCC_5G, country_code=_COUNTRY_CODE diff --git a/betocq/nearby_connection/directed_tests/xcc_2g_wfd_sta_test.py b/betocq/nearby_connection/directed_tests/xcc_2g_wfd_sta_test.py index 435f918..103fb7a 100644 --- a/betocq/nearby_connection/directed_tests/xcc_2g_wfd_sta_test.py +++ b/betocq/nearby_connection/directed_tests/xcc_2g_wfd_sta_test.py @@ -12,15 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""This test is to test the WFD medium with 2G channel and Country code JP. +"""This test is to test the WFD medium with 2G channel and Country code 00. In this case, the STA is using the 2G channel; and the WFD is expected to use -the 2G channel as well if the device cannot tell if they are indoor or not; -otherwise, the WFD may use 5G channel. - -Note: This test case is not related to the capability of -'enable_sta_indoor_channel_for_peer_network', which is only for 5G when the -device is connected to a sta 5G network. +the 2G channel as well in the world wide country code '00'. but allow 5G channel +in case the device does not follow the world wide country code wifi channel. Test requirements: The device requirements @@ -29,7 +25,7 @@ Wi-Fi channel: 6 (2437) or other 2G channels. Test preparations: - Set country code to JP on Android devices. + Set country code to '00' on Android devices. Test steps: 1. Disconnect discoverer from the current connected Wi-Fi network. @@ -64,13 +60,14 @@ # use the SCC test count as most devices should be in SCC mode, except the -# device has indoor channel detection capability, which will be MCC mode. +# device does not follow the world wide country code wifi channel, which will be +# MCC mode. TEST_ITERATION_NUM = constants.SCC_PERFORMANCE_TEST_COUNT SUCCESS_RATE_TARGET = constants.SUCCESS_RATE_TARGET _MAX_CONSECUTIVE_ERROR = constants.SCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR _FILE_TRANSFER_NUM = 1 _PAYLOAD_TYPE = constants.PayloadType.FILE -_COUNTRY_CODE = 'JP' +_COUNTRY_CODE = '00' _THROUGHPUT_LOW_TIP = ( @@ -219,9 +216,11 @@ def test_xcc_2g_wfd_sta(self): ], test_result=self.current_test_result, additional_error_message=( - 'If the device can detected as indoor, the concurrency mode should' - ' be SCC_2G. If the device can not detect the indoor environment,' - ' the concurrency mode will be MCC_5G_P2P_2G_STA.' + 'In world wide country code, WFD should use the 2G channel, but the' + ' device may use the 5G channel as well if the device does not' + ' follow the world wide country code wifi channel. You may work' + ' with your wifi chipset vendor to fix this frequency selection' + ' issue.' ), ) self.advertiser.log.info( diff --git a/betocq/nearby_connection/directed_tests/xcc_wfd_indoor_5g_sta_test.py b/betocq/nearby_connection/directed_tests/xcc_wfd_ww_5g_sta_test.py similarity index 82% rename from betocq/nearby_connection/directed_tests/xcc_wfd_indoor_5g_sta_test.py rename to betocq/nearby_connection/directed_tests/xcc_wfd_ww_5g_sta_test.py index 04a0237..9fff76d 100644 --- a/betocq/nearby_connection/directed_tests/xcc_wfd_indoor_5g_sta_test.py +++ b/betocq/nearby_connection/directed_tests/xcc_wfd_ww_5g_sta_test.py @@ -12,33 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""This test is to test the Wifi throughput with indoor 5G STA. +"""This test is to test the Wifi throughput with 5G STA. -This is about the feature - using indoor channels for WFD, for details, refer to -https://drive.google.com/file/d/1Aj77Euao8XkvE6uWF15WMK1XCwmYhdxW/view?resourcekey=0-a69XQup8McOcUnzYN9eh0Q -(confidential) and config_wifiEnableStaIndoorChannelForPeerNetwork - -https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml;l=1147 -If the feature is disabled for the device, the WFD will be started in -a 2G channel, but the STA is using the 5G channel. -If the feature is enabled for the device, the WFD will be started in -a 5G channel same as the STA. +This test case is to test the WFD performance when the STA is using the 5G +channel and the WFD is using the 2G channel, but the WFD may use the 5G +channel as well if the device does not follow the world wide country code wifi +channel, which is a scenario that may occur in real-world usages. Test requirements: The device requirements: support 5G band support Wi-Fi Direct The AP requirements: - Wi-Fi channel: 36 (5180) or other 5G indoor channels in JP. + Wi-Fi channel: 36 (5180) or other 5G channels. Test preparations: - Set country code to JP on Android devices. + Set country code to '00' on Android devices. Test steps: 1. Disconnect discoverer from the current connected Wi-Fi network. 2. Set up a prior Nearby Connection through Bluetooth medium. 3. Connect advertiser to the 5G Wi-Fi network. 4. Set up a connection with Wi-Fi Direct as upgrade medium. - * Wi-Fi Direct will be set up by Nearby Connection in a 2G channel. + * Wi-Fi Direct will be set up by Nearby Connection in a 2G channel or 5G + channel in case the device does not follow the world wide country code + wifi channel. 5. Transfer file on the connection established in step 4. 6. Disconnect all Nearby Connections. @@ -64,24 +62,22 @@ # Use MCC strategy for iteration number and max consecutive error, -# as most devices do not support SCC_5G mode in this case. +# as most devices should not support SCC_5G mode in this case. TEST_ITERATION_NUM = nc_constants.MCC_PERFORMANCE_TEST_COUNT SUCCESS_RATE_TARGET = constants.SUCCESS_RATE_TARGET _MAX_CONSECUTIVE_ERROR = nc_constants.MCC_PERFORMANCE_TEST_MAX_CONSECUTIVE_ERROR _FILE_TRANSFER_NUM = 1 _PAYLOAD_TYPE = constants.PayloadType.FILE -_COUNTRY_CODE = 'JP' +_COUNTRY_CODE = '00' _FILE_TRANSFER_FAILURE_TIP = ( 'The Wifi Direct connection might be broken, check related logs.' ) -class XccWfdIndoor5gStaTest(performance_test_base.PerformanceTestBase): - """Test class for wifi XCC with 2G WFD and indoor 5G STA. +class XccWfdWw5gStaTest(performance_test_base.PerformanceTestBase): + """Test class for wifi XCC with 2G WFD and 5G STA. - This test covers both SCC (if enable_sta_indoor_channel_for_peer_network is - supported) and MCC (otherwise) scenarios. """ test_runtime: constants.NcTestRuntime @@ -155,11 +151,8 @@ def _assert_test_conditions(self): count=TEST_ITERATION_NUM, max_consecutive_error=_MAX_CONSECUTIVE_ERROR, ) - def test_xcc_wfd_indoor_5g_sta(self): - """Test the performance for wifi XCC with 2G WFD and indoor 5G STA. - - This test covers both SCC (if enable_sta_indoor_channel_for_peer_network is - supported) and MCC (otherwise) scenarios. + def test_xcc_wfd_ww_5g_sta(self): + """Test the performance for wifi XCC with a 5G STA in the world wide country code '00'. """ # Test Step: Connect discoverer to wifi sta. discoverer_sta_op = setup_utils.remove_current_connected_wifi_network( @@ -218,14 +211,10 @@ def test_xcc_wfd_indoor_5g_sta(self): ], test_result=self.current_test_result, additional_error_message=( - 'If the enable_sta_indoor_channel_for_peer_network feature is not' - ' supported by the device, the p2p frequency should be 2G' - ' concurrency mode will be' - ' {WifiConcurrencyMode.MCC_2G_P2P_5G_STA.name}; otherwise, the' - ' p2p frequency should be 5G and be the same as the STA, the' - ' concurrency mode will be {WifiConcurrencyMode.SCC_5G.name}.' - ' Your device might vialate the Japan regulatory about the indoor' - ' 5G channels.' + 'In world wide country code, WFD should use the 2G channel, but' + ' the device may use the same channel as the STA, which is the 5G' + ' channel as well. You may work with your wifi chipset vendor to' + ' fix this frequency selection issue.' ), ) self.advertiser.log.info( diff --git a/betocq/setup_utils.py b/betocq/setup_utils.py index 841277f..f9a6fca 100644 --- a/betocq/setup_utils.py +++ b/betocq/setup_utils.py @@ -16,6 +16,7 @@ from collections.abc import Callable, Iterable, Sequence import datetime +import logging import pprint import re import time @@ -53,7 +54,7 @@ WIFI_SCAN_WAIT_TIME_SEC = 5 _WIFI_CONNECT_INTERVAL_SEC = 5 -_WIFI_CONNECT_RETRY_TIMES = 3 +_WIFI_CONNECT_RETRY_TIMES = 2 _CLEAN_WIFI_ENV_CHECK_BSSID_THRESHOLD = 5 @@ -1303,12 +1304,12 @@ def report_error_on_setup_class( ) else: termination_signal = error_class(error_message) - test_result_record.test_fail(termination_signal) test.results.add_class_error(test_result_record) test.summary_writer.dump( test_result_record.to_dict(), records.TestSummaryEntryType.RECORD ) + logging.error('%s', termination_signal) raise termination_signal @@ -1712,9 +1713,56 @@ def _extract_bt_firmware_version( version = match.group('version').strip() ad.log.info('version: %s', version) # Basic check to ensure it looks like a version string - if ('FW' in version or 'Firmware' in version or - re.search(r'[0-9a-fA-F]{6,}', version)): + if ( + 'FW' in version + or 'Firmware' in version + or re.search(r'[0-9a-fA-F]{6,}', version) + ): return version break # Stop searching after checking the line(s) below the header break # Move to the next line in the dumpsys output return _UNKNOWN_BT_FIRMWARE_VERSION + + +def disable_package_verifiers(ad: android_device.AndroidDevice): + """Disables package verifier and Play Protect for ADB installs.""" + try: + if not ad.is_adb_root: + ad.log.info( + 'Device is not rooted. Skipping disabling package verifiers.' + ) + return + ad.log.info( + 'Device is in Root. Disabling package verifier and Play Protect for ADB' + ' installs.' + ) + ad.adb.shell(['settings', 'put', 'global', 'package_verifier_enable', '0']) + ad.adb.shell( + ['settings', 'put', 'global', 'verifier_verify_adb_installs', '0'] + ) + ad.adb.shell(['settings', 'put', 'global', 'verifier_engprod', '1']) + except adb.AdbError as e: + ad.log.error(f'Failed to disable package verifiers: {e} on ' + f'device {ad.serial}.') + + +def enable_package_verifiers(ad: android_device.AndroidDevice): + """Reverts package verifier and Play Protect settings.""" + try: + if not ad.is_adb_root: + ad.log.info( + 'Device is not rooted. Skipping reverting package verifiers.' + ) + return + ad.log.info( + 'Device is in Root. Reverting package verifier and Play Protect' + ' settings for ADB installs.' + ) + ad.adb.shell(['settings', 'put', 'global', 'package_verifier_enable', '1']) + ad.adb.shell( + ['settings', 'put', 'global', 'verifier_verify_adb_installs', '1'] + ) + ad.adb.shell(['settings', 'put', 'global', 'verifier_engprod', '0']) + except adb.AdbError as e: + ad.log.error(f'Failed to enable package verifiers: {e} on ' + f'device {ad.serial}.') diff --git a/betocq/test_result_utils.py b/betocq/test_result_utils.py index b168aa9..8c429db 100644 --- a/betocq/test_result_utils.py +++ b/betocq/test_result_utils.py @@ -33,7 +33,6 @@ from betocq import setup_utils from betocq import version - _BITS_PER_BYTE = 8 @@ -211,9 +210,7 @@ def set_and_assert_sta_frequency( test_result.test_failure_reason = ( constants.SingleTestFailureReason.SOURCE_WIFI_CONNECTION ) - asserts.fail( - constants.COMMON_TRIAGE_TIP[test_result.test_failure_reason] - ) + asserts.fail(constants.COMMON_TRIAGE_TIP[test_result.test_failure_reason]) ad.log.warning( 'The STA frequency is not available, but the STA is' ' connected, the test result may not be expected.' @@ -304,9 +301,7 @@ def _get_2g_wifi_throughput_benchmark( discoverer = nc_test_runtime.discoverer advertiser = nc_test_runtime.advertiser if nc_test_runtime.wifi_info is None: - return constants.SpeedTarget( - constants.INVALID_INT, constants.INVALID_INT - ) + return constants.SpeedTarget(constants.INVALID_INT, constants.INVALID_INT) max_num_streams = min(discoverer.max_num_streams, advertiser.max_num_streams) @@ -393,9 +388,7 @@ def _get_5g_wifi_throughput_benchmark( discoverer = nc_test_runtime.discoverer advertiser = nc_test_runtime.advertiser if nc_test_runtime.wifi_info is None: - return constants.SpeedTarget( - constants.INVALID_INT, constants.INVALID_INT - ) + return constants.SpeedTarget(constants.INVALID_INT, constants.INVALID_INT) is_mcc = nc_test_runtime.wifi_info.is_mcc is_dbs_mode = nc_test_runtime.is_dbs_mode is_wlan_medium = ( @@ -612,9 +605,7 @@ def _run_iperf_test( ), medium=test_result.quality_info.upgrade_medium, ) - logging.info( - 'iperf throughput: %d (KB/s)', test_result.iperf_throughput_kbps - ) + logging.info('iperf throughput: %d (KB/s)', test_result.iperf_throughput_kbps) return round(test_result.iperf_throughput_kbps / 1024, 1) @@ -626,7 +617,7 @@ def assert_nc_throughput_meets_target( """Checks the Nearby connection throughput meets the target.""" test_result.speed_target = constants.SpeedTarget( nc_speed_mbtye_per_sec=nc_speed_min_mbps, - iperf_speed_mbtye_per_sec=constants.INVALID_INT + iperf_speed_mbtye_per_sec=constants.INVALID_INT, ) nc_speed_mbps = round(test_result.file_transfer_throughput_kbps / 1024, 3) if nc_speed_mbps >= nc_speed_min_mbps: @@ -655,8 +646,10 @@ def _get_device_attributes(ad: android_device.AndroidDevice) -> str: return '\n'.join([ f'serial: {getattr(ad, "serial", "NA")}', f'model: {getattr(ad, "model", "NA")}', - f'android_version: {getattr(ad, "android_version", "NA")}\n' - f'build_info: {getattr(ad, "build_info", "NA")}', + ( + f'android_version: {getattr(ad, "android_version", "NA")}\n' + f'build_info: {getattr(ad, "build_info", "NA")}' + ), f'gms_version: {setup_utils.dump_gms_version(ad)}', f'wifi_chipset: {getattr(ad, "wifi_chipset", "NA")}', f'wifi_fw: {wifi_fw}', @@ -801,7 +794,8 @@ class SingleTestResult: end_time: datetime.datetime | None = None debug_reference_info: dict[str, Any] = dataclasses.field(default_factory=dict) speed_target: constants.SpeedTarget = constants.SpeedTarget( - constants.INVALID_INT, constants.INVALID_INT) + constants.INVALID_INT, constants.INVALID_INT + ) wifi_concurrency_mode: constants.WifiConcurrencyMode = ( constants.WifiConcurrencyMode.UNKNOWN ) @@ -821,9 +815,7 @@ def failure_reason(self) -> constants.SingleTestFailureReason: return self.prior_nc_fail_reason return self.active_nc_fail_reason - def add_debug_reference_info( - self, key: str, value: Any - ) -> None: + def add_debug_reference_info(self, key: str, value: Any) -> None: """Adds debug reference info for the current test iteration.""" self.debug_reference_info[key] = value @@ -878,6 +870,58 @@ def gen_basic_test_summary( return basic_test_summary +def gen_uiautomation_test_summary( + ad: android_device.AndroidDevice, + ios_model: str, + ios_build_info: str, + test_passed: bool, + error_code: str | None, + upgrade_medium: str, + medium_frequency: str, + sta_frequency: str, + speed: str, + total_transfer_size: str | None = None, + transfer_time: str | None = None, + completed_types: Sequence[str] | None = None, + incomplete_types: Sequence[str] | None = None, +) -> dict[str, Any]: + """Generates a test summary for UI Automation tests.""" + transfer_quality_info = { + 'upgrade_medium': upgrade_medium, + 'speed': speed, + } + if medium_frequency != 'Unknown': + transfer_quality_info['medium_frequency'] = medium_frequency + if sta_frequency != 'Unknown': + transfer_quality_info['sta_frequency'] = sta_frequency + if total_transfer_size: + transfer_quality_info['total_transfer_size'] = total_transfer_size + if transfer_time: + transfer_quality_info['transfer_time'] = transfer_time + + result_message = 'PASS' if test_passed else 'FAIL' + if not test_passed and error_code: + result_message += f' - {error_code}' + + res = { + 'result': result_message, + 'transfer_info': '\n'.join( + [f'{k}: {v}' for k, v in transfer_quality_info.items()] + ), + 'device_android': _get_device_attributes(ad), + 'device_ios': f'model: {ios_model}\nbuild: {ios_build_info}', + } + + if completed_types or incomplete_types: + completed_str = ', '.join(completed_types) if completed_types else '' + incomplete_str = ', '.join(incomplete_types) if incomplete_types else '' + res['data_types'] = ( + f'completed: {completed_str}\nincomplete: {incomplete_str}' + ) + + return res + + def check_gms_pids_changed( ads: Sequence[android_device.AndroidDevice], ) -> str | None: @@ -989,14 +1033,9 @@ def is_test_class_passed(self) -> bool: def get_wifi_concurrency_mode(self) -> constants.WifiConcurrencyMode: """Returns the wifi concurrency mode of the test class.""" - if ( - self.nc_test_runtime is None - or self.nc_test_runtime.wifi_info is None - ): + if self.nc_test_runtime is None or self.nc_test_runtime.wifi_info is None: return constants.WifiConcurrencyMode.UNKNOWN - nc_test_runtime = typing.cast( - constants.NcTestRuntime, self.nc_test_runtime - ) + nc_test_runtime = typing.cast(constants.NcTestRuntime, self.nc_test_runtime) if constants.is_xcc_test(nc_test_runtime.wifi_info.d2d_type): for result in self._results: if ( @@ -1070,8 +1109,7 @@ def gen_test_summary(self) -> dict[str, Any]: def _get_success_iteration_count(self) -> int: return sum( - test_result.failure_reason - is constants.SingleTestFailureReason.SUCCESS + test_result.failure_reason is constants.SingleTestFailureReason.SUCCESS for test_result in self._results ) @@ -1086,10 +1124,7 @@ def _get_failed_iteration_messages(self) -> str: """Summarizes failed iterations with detailed reasons and signatures.""" messages = [] for result in self._results: - if ( - result.failure_reason - is not constants.SingleTestFailureReason.SUCCESS - ): + if result.failure_reason is not constants.SingleTestFailureReason.SUCCESS: messages.append( f'- Iter: {result.test_iteration}: {result.start_time}' f' {result.result_message}\n' @@ -1188,8 +1223,9 @@ def _get_test_runtime_info( if (wifi_info := nc_test_runtime.wifi_info) is not None: # If the test could upgrade to either 2G or 5G WiFi mediums, do not show # below info in test summary. - if (constants.is_upgrading_to_wifi_of_any_freq(wifi_info.d2d_type) - or constants.is_xcc_test(wifi_info.d2d_type)): + if constants.is_upgrading_to_wifi_of_any_freq( + wifi_info.d2d_type + ) or constants.is_xcc_test(wifi_info.d2d_type): info.update( {'is_2g_only': 'NA', 'is_dbs_mode': 'NA', 'is_mcc_mode': 'NA'} ) @@ -1224,8 +1260,7 @@ def _get_prior_bt_connection_stats(self) -> str: filtered_results = [ r for r in self._results - if r.prior_nc_quality_info.discovery_latency - != constants.UNSET_LATENCY + if r.prior_nc_quality_info.discovery_latency != constants.UNSET_LATENCY ] if not filtered_results: return 'NA' @@ -1272,9 +1307,7 @@ def _get_latency_stats( filtered_int.count(0), round(filtered[0], constants.LATENCY_PRECISION_DIGITS), percentile_50, - round( - filtered[len(filtered) - 1], constants.LATENCY_PRECISION_DIGITS - ), + round(filtered[len(filtered) - 1], constants.LATENCY_PRECISION_DIGITS), ) def _get_transfer_stats( @@ -1293,9 +1326,7 @@ def _get_transfer_stats( An instance of TestResultStats. """ filtered = [ - x - for x in throughput_indicators - if x != constants.UNSET_THROUGHPUT_KBPS + x for x in throughput_indicators if x != constants.UNSET_THROUGHPUT_KBPS ] if not filtered: # all test cases are failed diff --git a/betocq/version.py b/betocq/version.py index 523c40a..3daa9e6 100644 --- a/betocq/version.py +++ b/betocq/version.py @@ -37,3 +37,4 @@ # '2.6.2': ('Optimize tests for AQT and fix some bugs.') # '2.6.3': ('Fix some bugs.') # '2.6.4': 'Replace the SCC 2G WFD STA test with XCC 2G WFD STA test.' +# '2.6.5': ('Making the test compatible with the China version of the AP.')