diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-09-16 18:47:07 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-09-16 18:47:07 +0000 |
commit | dd4e3468549c53d9fbe7ddce9ba18962d6b63032 (patch) | |
tree | 1e1310a0c6654e36204638c308c39008fbf06b9a | |
parent | a56bdf9ff117651759680d6c579b7d4dc50f46c0 (diff) | |
parent | 30e655a8709e29e2484a780614392e3a7b97bc67 (diff) | |
download | platform_tools_test_connectivity-dd4e3468549c53d9fbe7ddce9ba18962d6b63032.tar.gz platform_tools_test_connectivity-dd4e3468549c53d9fbe7ddce9ba18962d6b63032.tar.bz2 platform_tools_test_connectivity-dd4e3468549c53d9fbe7ddce9ba18962d6b63032.zip |
Merge "Encapsulating DUT dependencies in BaseCellularDut"
8 files changed, 211 insertions, 51 deletions
diff --git a/acts/framework/acts/controllers/cellular_lib/AndroidCellularDut.py b/acts/framework/acts/controllers/cellular_lib/AndroidCellularDut.py new file mode 100644 index 0000000000..aaef6f5a0a --- /dev/null +++ b/acts/framework/acts/controllers/cellular_lib/AndroidCellularDut.py @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 +# +# Copyright 2020 - The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from acts.controllers.cellular_lib import BaseCellularDut +from acts.test_utils.tel import tel_test_utils as tel_utils +from acts.test_utils.tel import tel_defines + + +class AndroidCellularDut(BaseCellularDut.BaseCellularDut): + """ Android implementation of the cellular DUT class.""" + def __init__(self, ad, logger): + """ Keeps a handler to the android device. + + Args: + ad: Android device handler + logger: a handler to the logger object + """ + self.ad = ad + self.log = logger + + def toggle_airplane_mode(self, new_state=True): + """ Turns airplane mode on / off. + + Args: + new_state: True if airplane mode needs to be enabled. + """ + tel_utils.toggle_airplane_mode(self.log, self.ad, new_state) + + def toggle_data_roaming(self, new_state=True): + """ Enables or disables cellular data roaming. + + Args: + new_state: True if data roaming needs to be enabled. + """ + tel_utils.toggle_cell_data_roaming(self.ad, new_state) + + def get_rx_tx_power_levels(self): + """ Obtains Rx and Tx power levels measured from the DUT. + + Returns: + A tuple where the first element is an array with the RSRP value + in each Rx chain, and the second element is the Tx power in dBm. + Values for invalid or disabled Rx / Tx chains are set to None. + """ + return tel_utils.get_rx_tx_power_levels(self.log, self.ad) + + def set_apn(self, name, apn, type='default'): + """ Sets the Access Point Name. + + Args: + name: the APN name + apn: the APN + type: the APN type + """ + self.ad.droid.telephonySetAPN(name, apn, type) + + def set_preferred_network_type(self, type): + """ Sets the preferred RAT. + + Args: + type: an instance of class PreferredNetworkType + """ + if type == BaseCellularDut.PreferredNetworkType.LTE_ONLY: + formatted_type = tel_defines.NETWORK_MODE_LTE_ONLY + elif type == BaseCellularDut.PreferredNetworkType.WCDMA_ONLY: + formatted_type = tel_defines.NETWORK_MODE_WCDMA_ONLY + elif type == BaseCellularDut.PreferredNetworkType.GSM_ONLY: + formatted_type = tel_defines.NETWORK_MODE_GSM_ONLY + else: + raise ValueError('Invalid RAT type.') + + if not self.ad.droid.telephonySetPreferredNetworkTypesForSubscription( + formatted_type, self.ad.droid.subscriptionGetDefaultSubId()): + self.log.error("Could not set preferred network type.") + else: + self.log.info("Preferred network type set.") + + def get_telephony_signal_strength(self): + """ Wrapper for the method with the same name in tel_utils. + + Will be deprecated and replaced by get_rx_tx_power_levels. """ + tel_utils.get_telephony_signal_strength(self.ad) diff --git a/acts/framework/acts/controllers/cellular_lib/BaseCellularDut.py b/acts/framework/acts/controllers/cellular_lib/BaseCellularDut.py new file mode 100644 index 0000000000..31c19fa9c5 --- /dev/null +++ b/acts/framework/acts/controllers/cellular_lib/BaseCellularDut.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# +# Copyright 2020 - The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from enum import Enum + + +class PreferredNetworkType(Enum): + """ Available preferred network types that can be passed to + set_preferred_network_type""" + LTE_ONLY = 'lte-only' + GSM_ONLY = 'gsm-only' + WCDMA_ONLY = 'wcdma-only' + + +class BaseCellularDut(): + """ Base class for DUTs used with cellular simulators. """ + def toggle_airplane_mode(self, new_state=True): + """ Turns airplane mode on / off. + + Args: + new_state: True if airplane mode needs to be enabled. + """ + raise NotImplementedError() + + def toggle_data_roaming(self, new_state=True): + """ Enables or disables cellular data roaming. + + Args: + new_state: True if data roaming needs to be enabled. + """ + raise NotImplementedError() + + def get_rx_tx_power_levels(self): + """ Obtains Rx and Tx power levels measured from the DUT. + + Returns: + A tuple where the first element is an array with the RSRP value + in each Rx chain, and the second element is the Tx power in dBm. + Values for invalid or disabled Rx / Tx chains are set to None. + """ + raise NotImplementedError() + + def set_apn(self, name, apn, type='default'): + """ Sets the Access Point Name. + + Args: + name: the APN name + apn: the APN + type: the APN type + """ + raise NotImplementedError() + + def set_preferred_network_type(self, type): + """ Sets the preferred RAT. + + Args: + type: an instance of class PreferredNetworkType + """ + raise NotImplementedError() + + def get_telephony_signal_strength(self): + """ Wrapper for the method with the same name in tel_utils. + + Will be deprecated and replaced by get_rx_tx_power_levels. """ + raise NotImplementedError() diff --git a/acts/framework/acts/controllers/cellular_lib/BaseSimulation.py b/acts/framework/acts/controllers/cellular_lib/BaseSimulation.py index 924277cd93..9cc091f2a0 100644 --- a/acts/framework/acts/controllers/cellular_lib/BaseSimulation.py +++ b/acts/framework/acts/controllers/cellular_lib/BaseSimulation.py @@ -19,10 +19,6 @@ from enum import Enum import numpy as np from acts.controllers import cellular_simulator -from acts.test_utils.tel.tel_test_utils import get_telephony_signal_strength -from acts.test_utils.tel.tel_test_utils import toggle_airplane_mode -from acts.test_utils.tel.tel_test_utils import toggle_cell_data_roaming -from acts.test_utils.tel.tel_test_utils import get_rx_tx_power_levels class BaseSimulation(): @@ -106,7 +102,7 @@ class BaseSimulation(): Args: simulator: a cellular simulator controller log: a logger handle - dut: the android device handler + dut: a device handler implementing BaseCellularDut test_config: test configuration obtained from the config file calibration_table: a dictionary containing path losses for different bands. @@ -168,13 +164,13 @@ class BaseSimulation(): # Set to default APN log.info("Configuring APN.") - dut.droid.telephonySetAPN("test", "test", "default") + self.dut.set_apn('test', 'test') # Enable roaming on the phone - toggle_cell_data_roaming(self.dut, True) + self.dut.toggle_data_roaming(True) # Make sure airplane mode is on so the phone won't attach right away - toggle_airplane_mode(self.log, self.dut, True) + self.dut.toggle_airplane_mode(True) # Wait for airplane mode setting to propagate time.sleep(2) @@ -197,7 +193,7 @@ class BaseSimulation(): """ # Turn on airplane mode - toggle_airplane_mode(self.log, self.dut, True) + self.dut.toggle_airplane_mode(True) # Wait for airplane mode setting to propagate time.sleep(2) @@ -215,7 +211,7 @@ class BaseSimulation(): try: # Turn off airplane mode - toggle_airplane_mode(self.log, self.dut, False) + self.dut.toggle_airplane_mode(False) # Wait for the phone to attach. self.simulator.wait_until_attached(timeout=self.attach_timeout) @@ -227,7 +223,7 @@ class BaseSimulation(): "UE failed to attach on attempt number {}.".format(i + 1)) # Turn airplane mode on to prepare the phone for a retry. - toggle_airplane_mode(self.log, self.dut, True) + self.dut.toggle_airplane_mode(True) # Wait for APM to propagate time.sleep(3) @@ -256,7 +252,7 @@ class BaseSimulation(): # Set the DUT to airplane mode so it doesn't see the # cellular network going off - toggle_airplane_mode(self.log, self.dut, True) + self.dut.toggle_airplane_mode(True) # Wait for APM to propagate time.sleep(2) @@ -271,7 +267,7 @@ class BaseSimulation(): # Set the DUT to airplane mode so it doesn't see the # cellular network going off - toggle_airplane_mode(self.log, self.dut, True) + self.dut.toggle_airplane_mode(True) # Wait for APM to propagate time.sleep(2) @@ -312,7 +308,7 @@ class BaseSimulation(): # Verify signal level try: - rx_power, tx_power = get_rx_tx_power_levels(self.log, self.dut) + rx_power, tx_power = self.dut.get_rx_tx_power_levels() if not tx_power or not rx_power[0]: raise RuntimeError('The method return invalid Tx/Rx values.') @@ -627,7 +623,7 @@ class BaseSimulation(): down_power_measured = [] for i in range(0, self.NUM_DL_CAL_READS): # For some reason, the RSRP gets updated on Screen ON event - signal_strength = get_telephony_signal_strength(self.dut) + signal_strength = self.dut.get_telephony_signal_strength() down_power_measured.append(signal_strength[rat]) time.sleep(5) diff --git a/acts/framework/acts/controllers/cellular_lib/GsmSimulation.py b/acts/framework/acts/controllers/cellular_lib/GsmSimulation.py index d275cae208..20c731b8fa 100644 --- a/acts/framework/acts/controllers/cellular_lib/GsmSimulation.py +++ b/acts/framework/acts/controllers/cellular_lib/GsmSimulation.py @@ -20,12 +20,12 @@ import time from acts.controllers.anritsu_lib.md8475a import BtsGprsMode from acts.controllers.anritsu_lib.md8475a import BtsNumber from acts.controllers.anritsu_lib import md8475_cellular_simulator as anritsusim +from acts.controllers.cellular_lib import BaseCellularDut from acts.controllers.cellular_lib.BaseSimulation import BaseSimulation from acts.test_utils.tel.anritsu_utils import GSM_BAND_DCS1800 from acts.test_utils.tel.anritsu_utils import GSM_BAND_EGSM900 from acts.test_utils.tel.anritsu_utils import GSM_BAND_GSM850 from acts.test_utils.tel.anritsu_utils import GSM_BAND_RGSM900 -from acts.test_utils.tel.tel_defines import NETWORK_MODE_GSM_ONLY class GsmSimulation(BaseSimulation): @@ -63,7 +63,7 @@ class GsmSimulation(BaseSimulation): Args: simulator: a cellular simulator controller log: a logger handle - dut: the android device handler + dut: a device handler implementing BaseCellularDut test_config: test configuration obtained from the config file calibration_table: a dictionary containing path losses for different bands. @@ -82,12 +82,8 @@ class GsmSimulation(BaseSimulation): super().__init__(simulator, log, dut, test_config, calibration_table) - if not dut.droid.telephonySetPreferredNetworkTypesForSubscription( - NETWORK_MODE_GSM_ONLY, - dut.droid.subscriptionGetDefaultSubId()): - log.error("Coold not set preferred network type.") - else: - log.info("Preferred network type set.") + self.dut.set_preferred_network_type( + BaseCellularDut.PreferredNetworkType.GSM_ONLY) def setup_simulator(self): """ Do initial configuration in the simulator. """ diff --git a/acts/framework/acts/controllers/cellular_lib/LteCaSimulation.py b/acts/framework/acts/controllers/cellular_lib/LteCaSimulation.py index 26f6e43d07..3f98a34e60 100644 --- a/acts/framework/acts/controllers/cellular_lib/LteCaSimulation.py +++ b/acts/framework/acts/controllers/cellular_lib/LteCaSimulation.py @@ -80,7 +80,7 @@ class LteCaSimulation(LteSimulation.LteSimulation): Args: simulator: the cellular instrument controller log: a logger handle - dut: the android device handler + dut: a device handler implementing BaseCellularDut test_config: test configuration obtained from the config file calibration_table: a dictionary containing path losses for different bands. diff --git a/acts/framework/acts/controllers/cellular_lib/LteSimulation.py b/acts/framework/acts/controllers/cellular_lib/LteSimulation.py index b4c84bb703..9627e9fa26 100644 --- a/acts/framework/acts/controllers/cellular_lib/LteSimulation.py +++ b/acts/framework/acts/controllers/cellular_lib/LteSimulation.py @@ -18,7 +18,7 @@ import math from enum import Enum from acts.controllers.cellular_lib.BaseSimulation import BaseSimulation -from acts.test_utils.tel.tel_defines import NETWORK_MODE_LTE_ONLY +from acts.controllers.cellular_lib import BaseCellularDut class TransmissionMode(Enum): @@ -459,7 +459,7 @@ class LteSimulation(BaseSimulation): Args: simulator: a cellular simulator controller log: a logger handle - dut: the android device handler + dut: a device handler implementing BaseCellularDut test_config: test configuration obtained from the config file calibration_table: a dictionary containing path losses for different bands. @@ -468,12 +468,8 @@ class LteSimulation(BaseSimulation): super().__init__(simulator, log, dut, test_config, calibration_table) - if not dut.droid.telephonySetPreferredNetworkTypesForSubscription( - NETWORK_MODE_LTE_ONLY, - dut.droid.subscriptionGetDefaultSubId()): - log.error("Couldn't set preferred network type.") - else: - log.info("Preferred network type set.") + self.dut.set_preferred_network_type( + BaseCellularDut.PreferredNetworkType.LTE_ONLY) # Get TBS pattern setting from the test configuration if self.KEY_TBS_PATTERN not in test_config: diff --git a/acts/framework/acts/controllers/cellular_lib/UmtsSimulation.py b/acts/framework/acts/controllers/cellular_lib/UmtsSimulation.py index 4a2619cf58..b301a6b6f5 100644 --- a/acts/framework/acts/controllers/cellular_lib/UmtsSimulation.py +++ b/acts/framework/acts/controllers/cellular_lib/UmtsSimulation.py @@ -21,7 +21,7 @@ from acts.controllers.anritsu_lib import md8475_cellular_simulator as anritsusim from acts.controllers.anritsu_lib.md8475a import BtsNumber from acts.controllers.anritsu_lib.md8475a import BtsPacketRate from acts.controllers.cellular_lib.BaseSimulation import BaseSimulation -from acts.test_utils.tel.tel_defines import NETWORK_MODE_WCDMA_ONLY +from acts.controllers.cellular_lib import BaseCellularDut class UmtsSimulation(BaseSimulation): @@ -98,7 +98,7 @@ class UmtsSimulation(BaseSimulation): Args: simulator: a cellular simulator controller log: a logger handle - dut: the android device handler + dut: a device handler implementing BaseCellularDut test_config: test configuration obtained from the config file calibration_table: a dictionary containing path losses for different bands. @@ -117,12 +117,8 @@ class UmtsSimulation(BaseSimulation): super().__init__(simulator, log, dut, test_config, calibration_table) - if not dut.droid.telephonySetPreferredNetworkTypesForSubscription( - NETWORK_MODE_WCDMA_ONLY, - dut.droid.subscriptionGetDefaultSubId()): - log.error("Coold not set preferred network type.") - else: - log.info("Preferred network type set.") + self.dut.set_preferred_network_type( + BaseCellularDut.PreferredNetworkType.WCDMA_ONLY) self.release_version = None self.packet_rate = None diff --git a/acts/framework/acts/test_utils/power/cellular/cellular_power_base_test.py b/acts/framework/acts/test_utils/power/cellular/cellular_power_base_test.py index 9fe7fd1301..1e422f535e 100644 --- a/acts/framework/acts/test_utils/power/cellular/cellular_power_base_test.py +++ b/acts/framework/acts/test_utils/power/cellular/cellular_power_base_test.py @@ -21,11 +21,12 @@ import acts.controllers.cellular_simulator as simulator from acts.controllers.anritsu_lib import md8475_cellular_simulator as anritsu from acts.controllers.rohdeschwarz_lib import cmw500_cellular_simulator as cmw from acts.controllers.rohdeschwarz_lib import cmx500_cellular_simulator as cmx -from acts.controllers.cellular_lib.GsmSimulation import GsmSimulation -from acts.controllers.cellular_lib.LteSimulation import LteSimulation -from acts.controllers.cellular_lib.UmtsSimulation import UmtsSimulation -from acts.controllers.cellular_lib.LteCaSimulation import LteCaSimulation -from acts.controllers.cellular_lib.LteImsSimulation import LteImsSimulation +from acts.controllers.cellular_lib import AndroidCellularDut +from acts.controllers.cellular_lib import GsmSimulation +from acts.controllers.cellular_lib import LteSimulation +from acts.controllers.cellular_lib import UmtsSimulation +from acts.controllers.cellular_lib import LteCaSimulation +from acts.controllers.cellular_lib import LteImsSimulation from acts.test_utils.tel import tel_test_utils as telutils @@ -366,11 +367,11 @@ class PowerCellularLabBaseTest(PBT.PowerBaseTest): """ simulation_dictionary = { - self.PARAM_SIM_TYPE_LTE: LteSimulation, - self.PARAM_SIM_TYPE_UMTS: UmtsSimulation, - self.PARAM_SIM_TYPE_GSM: GsmSimulation, - self.PARAM_SIM_TYPE_LTE_CA: LteCaSimulation, - self.PARAM_SIM_TYPE_LTE_IMS: LteImsSimulation + self.PARAM_SIM_TYPE_LTE: LteSimulation.LteSimulation, + self.PARAM_SIM_TYPE_UMTS: UmtsSimulation.UmtsSimulation, + self.PARAM_SIM_TYPE_GSM: GsmSimulation.GsmSimulation, + self.PARAM_SIM_TYPE_LTE_CA: LteCaSimulation.LteCaSimulation, + self.PARAM_SIM_TYPE_LTE_IMS: LteImsSimulation.LteImsSimulation } if not sim_type in simulation_dictionary: @@ -391,9 +392,11 @@ class PowerCellularLabBaseTest(PBT.PowerBaseTest): if sim_type not in self.calibration_table: self.calibration_table[sim_type] = {} + cellular_dut = AndroidCellularDut.AndroidCellularDut( + self.dut, self.log) # Instantiate a new simulation self.simulation = simulation_class(self.cellular_simulator, self.log, - self.dut, self.test_params, + cellular_dut, self.test_params, self.calibration_table[sim_type]) def ensure_valid_calibration_table(self, calibration_table): |