def setup_test(self): if getattr(self, "qxdm_log", True): start_qxdm_loggers(self.log, self.android_devices) ensure_phones_idle(self.log, self.android_devices) toggle_airplane_mode(self.log, self.ad, True) self.ad.adb.shell("logcat -c -b all", ignore_status=True) return True
def test_bt_on_toggle_airplane_mode_on_then_off(self): """Test that toggles airplane mode both on and off Turning airplane mode on should toggle Bluetooth off successfully. Turning airplane mode off should toggle Bluetooth back on. Steps: 1. Verify that Bluetooth state is on 2. Turn airplane mode on 3. Verify that Bluetooth state is off 4. Turn airplane mode off 5. Verify that Bluetooth state is on Expected Result: Bluetooth should toggle off successfully. Returns: Pass if True Fail if False TAGS: Bluetooth, Airplane Priority: 3 """ if not bluetooth_enabled_check(self.dut): self.log.error("Failed to set Bluetooth state to enabled") return False if not toggle_airplane_mode(self.log, self.dut, True): self.log.error("Failed to toggle airplane mode on") return False if not toggle_airplane_mode(self.log, self.dut, False): self.log.error("Failed to toggle airplane mode off") return False time.sleep(self.WAIT_TIME_ANDROID_STATE_SETTLING) return self.dut.droid.bluetoothCheckState()
def phone_setup_video_for_subscription(log, ad, sub_id, wfc_mode=WFC_MODE_DISABLED): """Setup phone sub_id to make video call Args: log: log object. ad: android device object sub_id: ad's sub id. wfc_mode: WFC mode to set to. Valid mode includes: WFC_MODE_WIFI_ONLY, WFC_MODE_CELLULAR_PREFERRED, WFC_MODE_WIFI_PREFERRED, WFC_MODE_DISABLED. Returns: True if ad (sub_id) is setup correctly and idle for video call. """ toggle_airplane_mode(log, ad, False) if not set_wfc_mode(log, ad, wfc_mode): log.error("{} WFC mode failed to be set to {}.".format( ad.serial, wfc_mode)) return False toggle_volte(log, ad, True) if not ensure_network_generation( log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): log.error("{} voice not in LTE mode.".format(ad.serial)) return False return phone_idle_video_for_subscription(log, ad, sub_id)
def phone_setup_data_for_subscription(log, ad, sub_id, network_generation): """Setup Phone <sub_id> Data to <network_generation> Args: log: log object ad: android device object sub_id: subscription id network_generation: network generation, e.g. GEN_2G, GEN_3G, GEN_4G Returns: True if success, False if fail. """ toggle_airplane_mode(log, ad, False, strict_checking=False) set_wifi_to_default(log, ad) if not set_wfc_mode(log, ad, WFC_MODE_DISABLED): ad.log.error("Disable WFC failed.") return False if not ensure_network_generation_for_subscription( log, ad, sub_id, network_generation, voice_or_data=NETWORK_SERVICE_DATA): get_telephony_signal_strength(ad) return False return True
def _bring_up_callbox(self, set_simulation_func, rat): try: [self.bts1] = set_simulation_func(self.anritsu, self.user_params, self.ad.sim_card) set_usim_parameters(self.anritsu, self.ad.sim_card) if rat == RAT_LTE: set_post_sim_params(self.anritsu, self.user_params, self.ad.sim_card) self.anritsu.start_simulation() if rat == RAT_LTE: preferred_network_setting = NETWORK_MODE_LTE_GSM_WCDMA rat_family = RAT_FAMILY_LTE else: self.log.error("No valid RAT provided to bring up callbox.") return False if not ensure_preferred_network_type_for_subscription( self.ad, preferred_network_setting): self.log.error( "Failed to set rat family {}, preferred network:{}".format( rat_family, preferred_network_setting)) return False if self.ad.droid.connectivityCheckAirplaneMode(): toggle_airplane_mode(self.log, self.ad, False) except AnritsuError as e: self.log.error("Error in connection with Anritsu Simulator: " + str(e)) return False return True
def teardown_class(self): try: ensure_phones_default_state(self.log, self.android_devices) for ad in self.android_devices: ad.droid.telephonyAdjustPreciseCallStateListenLevel( PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND, False) ad.droid.telephonyAdjustPreciseCallStateListenLevel( PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING, False) ad.droid.telephonyAdjustPreciseCallStateListenLevel( PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND, False) if "enable_wifi_verbose_logging" in self.user_params: ad.droid.wifiEnableVerboseLogging( WIFI_VERBOSE_LOGGING_DISABLED) finally: for ad in self.android_devices: try: toggle_airplane_mode(self.log, ad, True, strict_checking=False) except BrokenPipeError: # Broken Pipe, can not call SL4A API to turn on Airplane Mode. # Use adb command to turn on Airplane Mode. if not force_airplane_mode(ad, True): self.log.error( "Can not turn on airplane mode on:{}".format( ad.serial)) return True
def setup_test(self): if getattr(self, "qxdm_log", True): start_qxdm_loggers(self.log, self.android_devices) ensure_phones_idle(self.log, self.android_devices) toggle_airplane_mode(self.log, self.ad, True) self.ad.adb.shell("setprop net.lte.ims.volte.provisioned 1", ignore_status=True) return True
def set_apm_on(self): """ Wrapper method to turn airplane mode on. This is passed to the Contest object so it can be executed when the automation system requires the DUT to be set to 'off' state. """ tel_test_utils.toggle_airplane_mode(self.log, self.dut, True)
def phone_setup_rat_for_subscription(log, ad, sub_id, network_preference, rat_family): toggle_airplane_mode(log, ad, False) if not set_wfc_mode(log, ad, WFC_MODE_DISABLED): log.error("{} Disable WFC failed.".format(ad.serial)) return False return ensure_network_rat_for_subscription(log, ad, sub_id, network_preference, rat_family)
def phone_setup_rat_for_subscription(log, ad, sub_id, network_preference, rat_family): toggle_airplane_mode(log, ad, False, strict_checking=False) if not set_wfc_mode(log, ad, WFC_MODE_DISABLED): ad.log.error("Disable WFC failed.") return False return ensure_network_rat_for_subscription(log, ad, sub_id, network_preference, rat_family)
def airplane_mode_test(log, ad): """ Test airplane mode basic on Phone and Live SIM. Ensure phone attach, data on, WiFi off and verify Internet. Turn on airplane mode to make sure detach. Turn off airplane mode to make sure attach. Verify Internet connection. Args: log: log object. ad: android object. Returns: True if pass; False if fail. """ if not ensure_phones_idle(log, [ad]): log.error("Failed to return phones to idle.") return False try: ad.droid.telephonyToggleDataConnection(True) WifiUtils.wifi_toggle_state(log, ad, False) log.info("Step1: ensure attach") if not toggle_airplane_mode(log, ad, False): log.error("Failed initial attach") return False if not verify_http_connection(log, ad): log.error("Data not available on cell.") return False log.info("Step2: enable airplane mode and ensure detach") if not toggle_airplane_mode(log, ad, True): log.error("Failed to enable Airplane Mode") return False if not wait_for_cell_data_connection(log, ad, False): log.error("Failed to disable cell data connection") return False if verify_http_connection(log, ad): log.error("Data available in airplane mode.") return False log.info("Step3: disable airplane mode and ensure attach") if not toggle_airplane_mode(log, ad, False): log.error("Failed to disable Airplane Mode") return False if not wait_for_cell_data_connection(log, ad, True): log.error("Failed to enable cell data connection") return False time.sleep(WAIT_TIME_ANDROID_STATE_SETTLING) log.info("Step4 verify internet") return verify_http_connection(log, ad) finally: toggle_airplane_mode(log, ad, False)
def _test_stress_cbrsdataswitch_timing(self, ad, method, validation=False): setattr(self, "number_of_devices", 1) ad.adb.shell("pm disable com.google.android.apps.scone") wifi_toggle_state(self.log, ad, True) self.cbrs_subid, self.default_subid = get_cbrs_and_default_sub_id(ad) toggle_airplane_mode(ad.log, ad, new_state=False, strict_checking=False) if self._is_current_data_on_cbrs(): ad.log.info("Current Data is on CBRS, proceeding with test") else: ad.log.error("Current Data not on CBRS, forcing it now..") ad.droid.telephonySetPreferredOpportunisticDataSubscription( self.cbrs_subid, False) ad.droid.telephonyUpdateAvailableNetworks(self.cbrs_subid) total_iteration = self.stress_test_number fail_count = collections.defaultdict(int) self.switch_time_dict = { 'cbrs_default_switch': [], 'default_cbrs_switch': [] } current_iteration = 1 for i in range(1, total_iteration + 1): msg = "Stress CBRS Test Iteration: <%s> / <%s>" % (i, total_iteration) begin_time = get_current_epoch_time() self.log.info(msg) start_qxdm_logger(ad, begin_time) iteration_result = self._cbrs_default_data_switch_timing( ad, method, validation) self.log.info("Result: %s", iteration_result) if iteration_result: self.log.info(">----Iteration : %d/%d succeed.----<", i, total_iteration) else: fail_count["cbrsdataswitch_fail"] += 1 self.log.error(">----Iteration : %d/%d failed.----<", i, total_iteration) self._take_bug_report("%s_IterNo_%s" % (self.test_name, i), begin_time) current_iteration += 1 time.sleep(WAIT_TIME_BETWEEN_ITERATION) test_result = True for time_task, time_list in self.switch_time_dict.items(): ad.log.info("%s %s", time_task, time_list) avg_time = self._get_list_average(time_list) ad.log.info("Average %s for %d iterations = %.2f seconds", time_task, self.stress_test_number, avg_time) for failure, count in fail_count.items(): if count: self.log.error("%s: %s %s failures in %s iterations", self.test_name, count, failure, total_iteration) test_result = False ad.adb.shell("pm enable com.google.android.apps.scone") return test_result
def set_apm_off(self): """ Wrapper method to turn airplane mode off. This is passed to the Contest object so it can be executed when the automation system requires the DUT to be set to 'on' state. """ # Wait for the Contest system to initialize the base stations before # actually setting APM off. time.sleep(5) tel_test_utils.toggle_airplane_mode(self.log, self.dut, False)
def phone_setup_iwlan_for_subscription(log, ad, sub_id, is_airplane_mode, wfc_mode, wifi_ssid=None, wifi_pwd=None): """Phone setup function for epdg call test for subscription id. Set WFC mode according to wfc_mode. Set airplane mode according to is_airplane_mode. Make sure phone connect to WiFi. (If wifi_ssid is not None.) Wait for phone to be in iwlan data network type. Wait for phone to report wfc enabled flag to be true. Args: log: Log object. ad: Android device object. sub_id: subscription id. is_airplane_mode: True to turn on airplane mode. False to turn off airplane mode. wfc_mode: WFC mode to set to. wifi_ssid: WiFi network SSID. This is optional. If wifi_ssid is None, then phone_setup_iwlan will not attempt to connect to wifi. wifi_pwd: WiFi network password. This is optional. Returns: True if success. False if fail. """ # VoLTE settings are unavailable in airplane mode toggle_airplane_mode(log, ad, False) # Now that we are out of APM, toggle VoLTE if necessary if ad.droid.imsIsEnhanced4gLteModeSettingEnabledByPlatform(): toggle_volte(log, ad, True) if not is_airplane_mode and not ensure_network_generation_for_subscription( log, ad, sub_id, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): return False if not set_wfc_mode(log, ad, wfc_mode): log.error("{} set WFC mode failed.".format(ad.serial)) return False if not toggle_airplane_mode(log, ad, is_airplane_mode): log.error("Failed to enable airplane mode on {}".format(ad.serial)) return False if wifi_ssid is not None: if not ensure_wifi_connected(log, ad, wifi_ssid, wifi_pwd): log.error("{} connect to WiFi failed.".format(ad.serial)) return False return phone_idle_iwlan_for_subscription(log, ad, sub_id)
def setup_class(self): if not "sim_conf_file" in self.user_params.keys(): self.log.error("Missing mandatory user config \"sim_conf_file\"!") return False sim_conf_file = self.user_params["sim_conf_file"] # If the sim_conf_file is not a full path, attempt to find it # relative to the config file. if not os.path.isfile(sim_conf_file): sim_conf_file = os.path.join( self.user_params[Config.key_config_path], sim_conf_file) if not os.path.isfile(sim_conf_file): self.log.error("Unable to load user config " + sim_conf_file + " from test config file.") return False setattr( self, "diag_logger", self.register_controller(acts.controllers.diag_logger, required=False)) for ad in self.android_devices: setup_droid_properties(self.log, ad, sim_conf_file) # Ensure that a test class starts from a consistent state that # improves chances of valid network selection and facilitates # logging. toggle_airplane_mode(self.log, ad, True) if not set_phone_screen_on(self.log, ad): self.log.error("Failed to set phone screen-on time.") return False if not set_phone_silent_mode(self.log, ad): self.log.error("Failed to set phone silent mode.") return False ad.droid.telephonyAdjustPreciseCallStateListenLevel( PRECISE_CALL_STATE_LISTEN_LEVEL_FOREGROUND, True) ad.droid.telephonyAdjustPreciseCallStateListenLevel( PRECISE_CALL_STATE_LISTEN_LEVEL_RINGING, True) ad.droid.telephonyAdjustPreciseCallStateListenLevel( PRECISE_CALL_STATE_LISTEN_LEVEL_BACKGROUND, True) if "enable_wifi_verbose_logging" in self.user_params: ad.droid.wifiEnableVerboseLogging(WIFI_VERBOSE_LOGGING_ENABLED) # Reset preferred network type. reset_preferred_network_type_to_allowable_range(self.log, ad) # Sub ID setup for ad in self.android_devices: initial_set_up_for_subid_infomation(self.log, ad) return True
def droid_has_phone(log, ad): #check for sim and service subInfo = ad.droid.subscriptionGetAllSubInfoList() if not subInfo or len(subInfo) < 1: return False toggle_airplane_mode(log, ad, False) sub_id = ad.droid.subscriptionGetDefaultVoiceSubId() if not wait_for_voice_attach_for_subscription( log, ad, sub_id, MAX_WAIT_TIME_NW_SELECTION): log.error("{} didn't find a cell network".format(ad.serial)) return False return True
def set_to_rockbottom_and_attach(self): self.bts1.input_power = -10 self.bts1.output_power = -30 # Set device to rockbottom self.ad.droid.goToSleepNow() # Turn of airplane mode and wait until the phone attaches toggle_airplane_mode(self.log, self.ad, False) time.sleep(2) self.anritsu.wait_for_registration_state() time.sleep(self.SETTLING_TIME) self.log.info("UE attached to the callbox.")
def stop(self): """ Detach phone from the basestation by stopping the simulation. Stop the simulation and turn airplane mode on. """ # Set the DUT to airplane mode so it doesn't see the # cellular network going off toggle_airplane_mode(self.log, self.dut, True) # Wait for APM to propagate time.sleep(2) # Stop the simulation self.simulator.stop()
def setup_class(self): """ Executed before any test case is started. Sets the device to rockbottom and connects to the cellular instrument. Returns: False if connecting to the callbox fails. """ super().setup_class() # Unpack test parameters used in this class self.unpack_userparams(md8475_version=None, md8475a_ip_address=None, cmw500_ip=None, cmw500_port=None, cmx500_ip=None, cmx500_port=None, qxdm_logs=None) # Load calibration tables filename_calibration_table = ( self.FILENAME_CALIBRATION_TABLE_UNFORMATTED.format( self.testbed_name)) for file in self.custom_files: if filename_calibration_table in file: self.calibration_table = self.unpack_custom_file(file, False) self.log.info('Loading calibration table from ' + file) self.log.debug(self.calibration_table) break # Ensure the calibration table only contains non-negative values self.ensure_valid_calibration_table(self.calibration_table) # Turn on airplane mode for all devices, as some might # be unused during the test for ad in self.android_devices: telutils.toggle_airplane_mode(self.log, ad, True) # Establish a connection with the cellular simulator equipment try: self.cellular_simulator = self.initialize_simulator() except ValueError: self.log.error('No cellular simulator could be selected with the ' 'current configuration.') raise except simulator.CellularSimulatorError: self.log.error('Could not initialize the cellular simulator.') raise
def phone_setup_iwlan_cellular_preferred(log, ad, wifi_ssid=None, wifi_pwd=None): """Phone setup function for iwlan Non-APM CELLULAR_PREFERRED test. Set WFC mode according to CELLULAR_PREFERRED. Set airplane mode according to False. Make sure phone connect to WiFi. (If wifi_ssid is not None.) Make sure phone don't report iwlan data network type. Make sure phone don't report wfc enabled flag to be true. Args: log: Log object. ad: Android device object. wifi_ssid: WiFi network SSID. This is optional. If wifi_ssid is None, then phone_setup_iwlan will not attempt to connect to wifi. wifi_pwd: WiFi network password. This is optional. Returns: True if success. False if fail. """ toggle_airplane_mode(log, ad, False, strict_checking=False) try: toggle_volte(log, ad, True) if not wait_for_network_generation( log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): if not ensure_network_generation( log, ad, GEN_4G, voice_or_data=NETWORK_SERVICE_DATA): ad.log.error("Fail to ensure data in 4G") return False except Exception as e: ad.log.error(e) ad.droid.telephonyToggleDataConnection(True) if wifi_ssid is not None: if not ensure_wifi_connected(log, ad, wifi_ssid, wifi_pwd): ad.log.error("Connect to WiFi failed.") return False if not set_wfc_mode(log, ad, WFC_MODE_CELLULAR_PREFERRED): ad.log.error("Set WFC mode failed.") return False if not wait_for_not_network_rat( log, ad, RAT_FAMILY_WLAN, voice_or_data=NETWORK_SERVICE_DATA): ad.log.error("Data rat in iwlan mode.") return False elif not wait_for_wfc_disabled(log, ad, MAX_WAIT_TIME_WFC_ENABLED): ad.log.error("Should report wifi calling disabled within %s.", MAX_WAIT_TIME_WFC_ENABLED) return False return True
def detach(self): """ Detach the phone from the basestation. Turns airplane mode and resets basestation. """ # Set the DUT to airplane mode so it doesn't see the # cellular network going off toggle_airplane_mode(self.log, self.dut, True) # Wait for APM to propagate time.sleep(2) # Power off basestation self.simulator.detach()
def orchestrate_and_verify_pan_connection(pan_dut, panu_dut): """Setups up a PAN conenction between two android devices. Args: pan_dut: the Android device providing tethering services panu_dut: the Android device using the internet connection from the pan_dut Returns: True if PAN connection and verification is successful, false if unsuccessful. """ if not toggle_airplane_mode(log, panu_dut, True): log.error("Failed to toggle airplane mode on") return False if not bluetooth_enabled_check(panu_dut): return False pan_dut.droid.bluetoothPanSetBluetoothTethering(True) if not (pair_pri_to_sec(pan_dut.droid, panu_dut.droid)): return False if not pan_dut.droid.bluetoothPanIsTetheringOn(): log.error("Failed to enable Bluetooth tethering.") return False # Magic sleep needed to give the stack time in between bonding and # connecting the PAN profile. time.sleep(MAGIC_PAN_CONNECT_TIMEOUT) panu_dut.droid.bluetoothConnectBonded( pan_dut.droid.bluetoothGetLocalAddress()) if not verify_http_connection(log, panu_dut): log.error("Can't verify http connection on PANU device.") if not verify_http_connection(log, pan_dut): log.info("Can't verify http connection on PAN service device") return False return True
def setup_class(self): super().setup_class() self.ad = self.android_devices[0] self.wifi_network_ssid = self.user_params.get( "wifi_network_ssid") or self.user_params.get( "wifi_network_ssid_2g") or self.user_params.get( "wifi_network_ssid_5g") self.wifi_network_pass = self.user_params.get( "wifi_network_pass") or self.user_params.get( "wifi_network_pass_2g") or self.user_params.get( "wifi_network_ssid_5g") if self.ad.droid.connectivityCheckAirplaneMode(): toggle_airplane_mode(self.log, self.ad, False) time.sleep(WAIT_FOR_CELLULAR_CONNECTION) return True
def test_bt_on_toggle_airplane_mode_on_bt_remains_off(self): """Test that verifies BT remains off after airplane mode toggles Turning airplane mode on should toggle Bluetooth off successfully and Bluetooth state should remain off. For this test we will use 60 seconds as a baseline. Steps: 1. Verify that Bluetooth state is on 2. Turn airplane mode on 3. Verify that Bluetooth state is off 3. Verify tat Bluetooth state remains off for 60 seconds Expected Result: Bluetooth should remain toggled off. Returns: Pass if True Fail if False TAGS: Bluetooth, Airplane Priority: 3 """ if not bluetooth_enabled_check(self.dut): self.log.error("Failed to set Bluetooth state to enabled") return False if not toggle_airplane_mode(self.log, self.dut, True): self.log.error("Failed to toggle airplane mode on") return False toggle_timeout = 60 self.log.info( "Waiting {} seconds until verifying Bluetooth state.".format( toggle_timeout)) time.sleep(toggle_timeout) return not self.dut.droid.bluetoothCheckState()
def test_bt_on_toggle_airplane_mode_on(self): """Test that toggles airplane mode on while BT on Turning airplane mode on should toggle Bluetooth off successfully. Steps: 1. Verify that Bluetooth state is on 2. Turn airplane mode on 3. Verify that Bluetooth state is off Expected Result: Bluetooth should toggle off successfully. Returns: Pass if True Fail if False TAGS: Bluetooth, Airplane Priority: 3 """ if not bluetooth_enabled_check(self.dut): self.log.error("Failed to set Bluetooth state to enabled") return False if not toggle_airplane_mode(self.log, self.dut, True): self.log.error("Failed to toggle airplane mode on") return False return not self.dut.droid.bluetoothCheckState()
def setup_test(self): super(BluetoothBaseTest, self).setup_test() # Ensure testcase starts with Airplane mode off if not toggle_airplane_mode(self.log, self.dut, False): return False time.sleep(self.WAIT_TIME_ANDROID_STATE_SETTLING) return True
def _setup_apm(self): if not toggle_airplane_mode(self.log, self.ad, True): self.log.error("Phone failed to turn on airplane mode.") return False else: self.log.info("Airplane mode is enabled successfully.") return True
def _basic_connectivity_check(self): """ Set Attenuator Value for WiFi and Cell to 0 Make sure DUT get Cell Data coverage (LTE) Make sure DUT WiFi is connected """ toggle_airplane_mode(self.log, self.android_devices[0], False) if not ensure_network_generation(self.log, self.android_devices[0], GEN_4G, NETWORK_SERVICE_DATA): return False if not ensure_wifi_connected(self.log, self.android_devices[0], self.live_network_ssid, self.live_network_pwd): ad.log.error("%s connect WiFI failed") return False return True
def test_check_environment(self): ad = self.android_devices[0] # Check WiFi environment. # 1. Connect to WiFi. # 2. Check WiFi have Internet access. toggle_airplane_mode(self.log, ad, False, strict_checking=False) try: if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid, self.wifi_network_pass): abort_all_tests(ad.log, "WiFi connect fail") if (not wait_for_wifi_data_connection(self.log, ad, True) or not verify_http_connection(self.log, ad)): abort_all_tests(ad.log, "Data not available on WiFi") finally: wifi_toggle_state(self.log, ad, False) # TODO: add more environment check here. return True
def _basic_connectivity_check(self): """ Set Attenuator Value for WiFi and Cell to 0 Make sure DUT get Cell Data coverage (LTE) Make sure DUT WiFi is connected """ ad = self.android_devices[0] toggle_airplane_mode(self.log, ad, False) if not ensure_network_generation(self.log, ad, GEN_4G, MAX_WAIT_TIME_NW_SELECTION, NETWORK_SERVICE_DATA): return False if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid, self.wifi_network_pass): ad.log.error("connect WiFi failed") return False return True