예제 #1
0
 def _take_bug_report(self, test_name, begin_time):
     test_log_path = os.path.join(self.log_path, test_name)
     utils.create_dir(test_log_path)
     # Extract test_run_info.txt, test_run_detail.txt
     for file_name in ("test_run_info.txt", "test_run_details.txt"):
         extract_test_log(
             self.log, os.path.join(self.log_path, file_name),
             os.path.join(test_log_path, "%s_%s" % (test_name, file_name)),
             "\[Test Case\] %s " % test_name)
     if self._skip_bug_report():
         return
     dev_num = getattr(self, "number_of_devices", None) or len(
         self.android_devices)
     tasks = [(self._ad_take_bugreport, (ad, test_name, begin_time))
              for ad in self.android_devices[:dev_num]]
     tasks.extend([(self._ad_take_extra_logs, (ad, test_name, begin_time))
                   for ad in self.android_devices[:dev_num]])
     run_multithread_func(self.log, tasks)
     for ad in self.android_devices[:dev_num]:
         if getattr(ad, "reboot_to_recover", False):
             reboot_device(ad)
             ad.reboot_to_recover = False
     # Zip log folder
     if not self.user_params.get("zip_log", False): return
     src_dir = os.path.join(self.log_path, test_name)
     file_name = "%s_%s" % (src_dir, begin_time)
     self.log.info("Zip folder %s to %s.zip", src_dir, file_name)
     shutil.make_archive(file_name, "zip", src_dir)
     shutil.rmtree(src_dir)
예제 #2
0
 def _account_registration(self, ad):
     toggle_airplane_mode_by_adb(self.log, ad, new_state=False)
     for cmd in _TYCHO_VERBOSE_LOGGING_CMDS:
         ad.adb.shell(cmd)
     if hasattr(ad, "user_account"):
         if self.check_project_fi_activated(ad, retries=2):
             ad.log.info("Project Fi is activated already")
             return True
         ad.exit_setup_wizard()
         if not ad.is_apk_installed("com.google.android.tradefed.account"
                                    ) and self.user_params.get(
                                        "account_util"):
             for _ in range(2):
                 if self._install_account_util(ad):
                     break
             else:
                 ad.log.error(
                     "Fail to install com.google.android.tradefed.account")
                 return False
         ad.force_stop_apk(_TYCHO_PKG)
         if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                      self.wifi_network_pass):
             ad.log.error("Failed to connect to wifi")
             return False
         ad.log.info("Add google account")
         if not self._add_google_account(ad):
             ad.log.error("Failed to add google account")
             return False
         ad.adb.shell(
             'am instrument -w -e account "*****@*****.**" -e password '
             '"%s" -e sync true -e wait-for-checkin false '
             'com.google.android.tradefed.account/.AddAccount' %
             (ad.user_account, ad.user_password))
         ad.log.info("Enable and activate tycho apk")
         if not ad.is_apk_installed(_TYCHO_PKG):
             ad.log.info("%s is not installed", _TYCHO_PKG)
             return False
         ad.adb.shell('pm enable %s' % _TYCHO_PKG)
         #ad.adb.shell(_TYCHO_SERVER_LAB_OVERRIDE_CMD)
         for i in range(1, self.activation_attemps + 1):
             if i == self.activation_attemps:
                 ad.log.info("Reboot and try Fi activation again")
                 reboot_device(ad)
             self.activate_fi_account(ad)
             if not self.check_project_fi_activated(ad):
                 ad.log.error("Fail to activate Fi account on attempt-%s",
                              i)
                 if i == self.activation_attemps:
                     return False
             else:
                 ad.log.info("Fi account is activated successfully")
                 break
     elif "Fi Network" in ad.adb.getprop("gsm.sim.operator.alpha"):
         ad.log.error("Google account is not provided for Fi Network")
         return False
     if not ensure_phone_subscription(self.log, ad):
         ad.log.error("Unable to find a valid subscription!")
         return False
     refresh_droid_config(self.log, ad)
     return True
예제 #3
0
    def _reboot_stress_test(self, *args):
        """Reboot Reliability Test

        Arguments:
            function_name: function to be checked

        Expected Results:
            No crash happens in stress test.

        Returns:
            True is pass, False if fail.
        """
        self.number_of_devices = 2
        fail_count = collections.defaultdict(int)
        test_result = True

        for i in range(1, self.stress_test_number + 1):
            begin_time = get_current_epoch_time()
            test_name = "%s_iteration_%s" % (self.test_name, i)
            log_msg = "[Test Case] %s" % test_name
            self.log.info("%s begin", log_msg)
            self.dut.droid.logI("%s begin" % log_msg)
            test_msg = "Reboot Stress Test %s Iteration <%s> / <%s>" % (
                self.test_name, i, self.stress_test_number)
            self.log.info(test_msg)
            reboot_device(self.dut)
            self.log.info("{} wait {}s for radio up.".format(
                self.dut.serial, WAIT_TIME_AFTER_REBOOT))
            time.sleep(WAIT_TIME_AFTER_REBOOT)
            failed_tests = self.feature_validator(*args)
            for test in failed_tests:
                fail_count[test] += 1

            crash_report = self.dut.check_crash_report("%s_%s" %
                                                       (self.test_name, i),
                                                       begin_time,
                                                       log_crash_report=True)
            if crash_report:
                fail_count["crashes"] += 1
            if failed_tests or crash_report:
                self.log.error("%s FAIL with %s and crashes %s", test_msg,
                               failed_tests, crash_report)
                self._take_bug_report(test_name, begin_time)
            else:
                self.log.info("%s PASS", test_msg)
            self.log.info("Total failure count: %s", dict(fail_count))
            self.log.info("%s end", log_msg)
            self.dut.droid.logI("%s end" % log_msg)

        for failure, count in fail_count.items():
            if count:
                self.log.error("%s failure count = %s in total %s iterations",
                               failure, count, self.stress_test_number)
                test_result = False
        return test_result
 def _take_bug_report(self, test_name, begin_time):
     if self._skip_bug_report(test_name):
         return
     dev_num = getattr(self, "number_of_devices", None) or len(
         self.android_devices)
     tasks = [(self._ad_take_bugreport, (ad, test_name, begin_time))
              for ad in self.android_devices[:dev_num]]
     tasks.extend([(self._ad_take_extra_logs, (ad, test_name, begin_time))
                   for ad in self.android_devices[:dev_num]])
     run_multithread_func(self.log, tasks)
     for ad in self.android_devices[:dev_num]:
         if getattr(ad, "reboot_to_recover", False):
             reboot_device(ad)
             ad.reboot_to_recover = False
     # Zip log folder
     if not self.user_params.get("zip_log", False): return
     src_dir = os.path.join(self.log_path, test_name)
     os.makedirs(src_dir, exist_ok=True)
     file_name = "%s_%s" % (src_dir, begin_time)
     self.log.info("Zip folder %s to %s.zip", src_dir, file_name)
     shutil.make_archive(file_name, "zip", src_dir)
     shutil.rmtree(src_dir)
예제 #5
0
    def _setup_device(self, ad, sim_conf_file, qxdm_log_mask_cfg=None):
        if self.user_params.get("enable_connectivity_metrics", True):
            enable_connectivity_metrics(ad)
        if self.user_params.get("build_id_override", False):
            build_postfix = self.user_params.get("build_id_postfix", "TEST")
            build_id_override(ad,
                              new_build_id=self.user_params.get(
                                  "build_id_override_with", None),
                              postfix=build_postfix)
        if self.enable_radio_log_on:
            enable_radio_log_on(ad)
        if "sdm" in ad.model:
            if ad.adb.getprop("persist.radio.multisim.config") != "ssss":
                ad.adb.shell("setprop persist.radio.multisim.config ssss")
                reboot_device(ad)

        stop_qxdm_logger(ad)
        ad.qxdm_log = getattr(ad, "qxdm_log", self.qxdm_log)
        if ad.qxdm_log:
            qxdm_log_mask = getattr(ad, "qxdm_log_mask", None)
            if qxdm_log_mask_cfg:
                qxdm_mask_path = self.user_params.get("qxdm_log_path",
                                                      DEFAULT_QXDM_LOG_PATH)
                ad.adb.shell("mkdir %s" % qxdm_mask_path)
                ad.log.info("Push %s to %s", qxdm_log_mask_cfg, qxdm_mask_path)
                ad.adb.push("%s %s" % (qxdm_log_mask_cfg, qxdm_mask_path))
                mask_file_name = os.path.split(qxdm_log_mask_cfg)[-1]
                qxdm_log_mask = os.path.join(qxdm_mask_path, mask_file_name)
            set_qxdm_logger_command(ad, mask=qxdm_log_mask)
            start_qxdm_logger(ad, utils.get_current_epoch_time())
        else:
            disable_qxdm_logger(ad)
        if not unlock_sim(ad):
            raise signals.TestAbortClass("unable to unlock the SIM")

        if get_sim_state(ad) in (SIM_STATE_ABSENT, SIM_STATE_UNKNOWN):
            ad.log.info("Device has no or unknown SIM in it")
            ensure_phone_idle(self.log, ad)
        elif self.user_params.get("Attenuator"):
            ad.log.info("Device in chamber room")
            ensure_phone_idle(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)
        else:
            if not wait_for_sim_ready_by_adb(self.log, ad):
                raise signals.TestAbortClass("unable to load the SIM")
            ensure_phone_default_state(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)

        # Setup VoWiFi MDN for Verizon. b/33187374
        if get_operator_name(self.log, ad) == "vzw" and ad.is_apk_installed(
                "com.google.android.wfcactivation"):
            ad.log.info("setup VoWiFi MDN per b/33187374")
        ad.adb.shell("setprop dbg.vzw.force_wfc_nv_enabled true")
        ad.adb.shell("am start --ei EXTRA_LAUNCH_CARRIER_APP 0 -n "
                     "\"com.google.android.wfcactivation/"
                     ".VzwEmergencyAddressActivity\"")
        # Sub ID setup
        initial_set_up_for_subid_infomation(self.log, ad)

        # If device is setup already, skip the following setup procedures
        if getattr(ad, "telephony_test_setup", None):
            return True

        if "enable_wifi_verbose_logging" in self.user_params:
            ad.droid.wifiEnableVerboseLogging(WIFI_VERBOSE_LOGGING_ENABLED)

        # Disable Emergency alerts
        # Set chrome browser start with no-first-run verification and
        # disable-fre. Give permission to read from and write to storage.
        for cmd in ("pm disable com.android.cellbroadcastreceiver",
                    "pm grant com.android.chrome "
                    "android.permission.READ_EXTERNAL_STORAGE",
                    "pm grant com.android.chrome "
                    "android.permission.WRITE_EXTERNAL_STORAGE",
                    "rm /data/local/chrome-command-line",
                    "am set-debug-app --persistent com.android.chrome",
                    'echo "chrome --no-default-browser-check --no-first-run '
                    '--disable-fre" > /data/local/tmp/chrome-command-line'):
            ad.adb.shell(cmd)

        # Curl for 2016/7 devices
        if not getattr(ad, "curl_capable", False):
            try:
                out = ad.adb.shell("/data/curl --version")
                if not out or "not found" in out:
                    if int(ad.adb.getprop("ro.product.first_api_level")) >= 25:
                        tel_data = self.user_params.get("tel_data", "tel_data")
                        if isinstance(tel_data, list):
                            tel_data = tel_data[0]
                        curl_file_path = os.path.join(tel_data, "curl")
                        if not os.path.isfile(curl_file_path):
                            curl_file_path = os.path.join(
                                self.user_params[Config.key_config_path],
                                curl_file_path)
                        if os.path.isfile(curl_file_path):
                            ad.log.info("Pushing Curl to /data dir")
                            ad.adb.push("%s /data" % (curl_file_path))
                            ad.adb.shell("chmod 777 /data/curl",
                                         ignore_status=True)
                else:
                    setattr(ad, "curl_capable", True)
            except Exception:
                ad.log.info("Failed to push curl on this device")

        # Ensure that a test class starts from a consistent state that
        # improves chances of valid network selection and facilitates
        # logging.
        try:
            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)
        except Exception as e:
            self.log.error("Failure with %s", e)
        setattr(ad, "telephony_test_setup", True)
        return True
 def call_drop_test_after_reboot(self, setup=None):
     self.forced_call_drop_test(setup=setup)
     self.healthy_call_test(setup=setup, count=1)
     reboot_device(self.dut)
     return self.forced_call_drop_test(setup=setup)
예제 #7
0
    def test_modem_power_poor_coverage(self):
        """Connectivity Monitor reports Poor Coverage to User

        Steps:
        1. Set WiFi, Cellular atten to MAX
        2. Wait for X amount of time
        3. Verify if the user gets a notification on UI

        Expected Results:
        1. User gets notification "Cellular battery issue: Poor coverage"

        Returns:
        True if Pass. False if fail.
        """
        ad = self.android_devices[0]
        # Ensure apk is installed
        monitor_apk = None
        for apk in ("com.google.telephonymonitor",
                    "com.google.android.connectivitymonitor"):
            if ad.is_apk_installed(apk):
                ad.log.info("apk %s is installed", apk)
                monitor_apk = apk
                break
        if not monitor_apk:
            ad.log.info(
                "ConnectivityMonitor|TelephonyMonitor is not installed")
            return False

        # Ensure apk is running
        ad.adb.shell("am start -n com.android.settings/.DevelopmentSettings",
                     ignore_status=True)
        for cmd in ("setprop persist.radio.enable_tel_mon user_enabled",
                    "setprop persist.radio.con_mon_hbeat 15000"):
            ad.log.info(cmd)
            ad.adb.shell(cmd)
        ad.log.info("reboot to bring up %s", monitor_apk)
        reboot_device(ad)
        for i in range(30):
            if ad.is_apk_running(monitor_apk):
                ad.log.info("%s is running after reboot", monitor_apk)
                break
            elif i == 19:
                ad.log.error("%s is not running after reboot", monitor_apk)
                return False
            else:
                ad.log.info(
                    "%s is not running after reboot. Wait and check again",
                    monitor_apk)
                time.sleep(30)

        # Setup all Notify Poor Coverage params
        for cmd in (
                "am broadcast -a "
                "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
                "-e \"ce.cm.bi.c.notify_poor_coverage\" \"true\"",
                "am broadcast -a "
                "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
                "-e \"ce.cm.bi.c.max_time_lowest_signal_strength_level_ms\" \"1\"",
                "am broadcast -a "
                "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
                "-e \"ce.cm.bi.c.max_temperature_c\" \"1\"",
                "dumpsys battery set usb 0"):
            time.sleep(1)
            ad.log.info(cmd)
            ad.adb.shell(cmd)

        # Make Chamber ready for test
        self._atten_setup_no_service()
        ad.log.info("Waiting 1 min for attens to settle")
        time.sleep(60)
        if (wait_for_cell_data_connection(self.log, ad, True)
                or wait_for_wifi_data_connection(self.log, ad, True)):
            ad.log.error(
                "Data is available, Expecting no Cellular/WiFi Signal")
            get_telephony_signal_strength(ad)
            get_wifi_signal_strength(ad)
            return False
        ad.log.info("Wait time for 2 CM Heart Beats")
        time.sleep(60)
        ad.log.info("dumpsys battery set usb 1")
        ad.adb.shell("dumpsys battery set usb 1")
        if ad.search_logcat(
                "Bugreport notification title Cellular battery drain"):
            ad.log.info("User got Poor coverage notification")
        else:
            ad.log.error("User didn't get Poor coverage notification")
            result = False
        return True
    def _cbrs_bootup_time_test(self):
        """CBRS Bootup Perf Test

        Expected Results:
            Time

        Returns:
            True is pass, False if fail.
        """
        self.number_of_devices = 1
        ad = self.dut
        cbrs_subid, default_subid = get_cbrs_and_default_sub_id(ad)
        toggle_airplane_mode(self.log, ad, False)

        fail_count = collections.defaultdict(int)
        test_result = True
        keyword_time_dict = {}

        text_search_mapping = {
            'boot_complete':
            "ModemService: Received: android.intent.action.BOOT_COMPLETED",
            'cbrs_active':
            "notifyPreferredDataSubIdChanged to %s" % cbrs_subid,
        }

        text_obj_mapping = {
            "boot_complete": None,
            "cbrs_active": None,
        }
        blocked_for_calculate = ["boot_complete"]
        for i in range(1, self.stress_test_number + 1):
            ad.log.info("CBRS Bootup Time Test %s Iteration: %d / %d",
                        self.test_name, i, self.stress_test_number)
            begin_time = get_current_epoch_time()
            ad.log.debug("Begin Time is %s", begin_time)
            ad.log.info("reboot!")
            reboot_device(ad)
            iteration_result = "pass"

            time.sleep(WAIT_TIME_FOR_BOOT_COMPLETE)

            dict_match = ad.search_logcat(text_search_mapping['boot_complete'],
                                          begin_time=begin_time)
            if len(dict_match) != 0:
                text_obj_mapping['boot_complete'] = dict_match[0][
                    'datetime_obj']
                ad.log.debug("Datetime for boot_complete is %s",
                             text_obj_mapping['boot_complete'])
                bootup_time = dict_match[0]['datetime_obj'].strftime('%s')
                bootup_time = int(bootup_time) * 1000
                ad.log.info("Bootup Time is %d", bootup_time)
            else:
                ad.log.error("TERMINATE- boot_complete not seen in logcat")
                return False

            for tel_state in text_search_mapping:
                if tel_state == "boot_complete":
                    continue
                dict_match = ad.search_logcat(text_search_mapping[tel_state],
                                              begin_time=bootup_time)
                if len(dict_match) != 0:
                    text_obj_mapping[tel_state] = dict_match[0]['datetime_obj']
                    ad.log.debug("Datetime for %s is %s", tel_state,
                                 text_obj_mapping[tel_state])
                else:
                    ad.log.error("Cannot Find Text %s in logcat",
                                 text_search_mapping[tel_state])
                    blocked_for_calculate.append(tel_state)
                    ad.log.debug("New Blocked %s", blocked_for_calculate)

            ad.log.info("List Blocked %s", blocked_for_calculate)
            for tel_state in text_search_mapping:
                if tel_state not in blocked_for_calculate:
                    time_diff = text_obj_mapping[tel_state] - \
                                text_obj_mapping['boot_complete']
                    ad.log.info("Time Diff is %d for %s", time_diff.seconds,
                                tel_state)
                    if tel_state in keyword_time_dict:
                        keyword_time_dict[tel_state].append(time_diff.seconds)
                    else:
                        keyword_time_dict[tel_state] = [
                            time_diff.seconds,
                        ]
                    ad.log.debug("Keyword Time Dict %s", keyword_time_dict)

            ad.log.info("CBRS Bootup Time Test %s Iteration: %d / %d %s",
                        self.test_name, i, self.stress_test_number,
                        iteration_result)
        ad.log.info("Final Keyword Time Dict %s", keyword_time_dict)
        for tel_state in text_search_mapping:
            if tel_state not in blocked_for_calculate:
                avg_time = self._get_list_average(keyword_time_dict[tel_state])
                if avg_time < 12.0:
                    ad.log.info("Average %s for %d iterations = %.2f seconds",
                                tel_state, self.stress_test_number, avg_time)
                else:
                    ad.log.error("Average %s for %d iterations = %.2f seconds",
                                 tel_state, self.stress_test_number, avg_time)
                    fail_count[tel_state] += 1

        ad.log.info("Bootup Time Dict: %s", keyword_time_dict)
        ad.log.info("fail_count: %s", dict(fail_count))
        for failure, count in fail_count.items():
            if count:
                ad.log.error("%s %s failures in %s iterations", count, failure,
                             self.stress_test_number)
                test_result = False
        return test_result
    def _telephony_bootup_time_test(self):
        """Telephony Bootup Perf Test

        Arguments:
            check_lte_data: whether to check the LTE data.
            check_volte: whether to check Voice over LTE.
            check_wfc: whether to check Wifi Calling.

        Expected Results:
            Time

        Returns:
            True is pass, False if fail.
        """
        self.number_of_devices = 1
        ad = self.dut
        toggle_airplane_mode(self.log, ad, False)
        if not phone_setup_volte(self.log, ad):
            ad.log.error("Failed to setup VoLTE.")
            return False
        fail_count = collections.defaultdict(int)
        test_result = True
        keyword_time_dict = {}

        text_search_mapping = {
            'boot_complete':
            "ModemService: Received: android.intent.action.BOOT_COMPLETED",
            'Voice_Reg': "< VOICE_REGISTRATION_STATE {.regState = REG_HOME",
            'Data_Reg': "< DATA_REGISTRATION_STATE {.regState = REG_HOME",
            'Data_Call_Up': "onSetupConnectionCompleted result=SUCCESS",
            'VoLTE_Enabled': "isVolteEnabled=true",
        }

        text_obj_mapping = {
            "boot_complete": None,
            "Voice_Reg": None,
            "Data_Reg": None,
            "Data_Call_Up": None,
            "VoLTE_Enabled": None,
        }
        blocked_for_calculate = ["boot_complete"]
        for i in range(1, self.stress_test_number + 1):
            ad.log.info("Telephony Bootup Time Test %s Iteration: %d / %d",
                        self.test_name, i, self.stress_test_number)
            begin_time = get_current_epoch_time()
            ad.log.debug("Begin Time is %s", begin_time)
            ad.log.info("reboot!")
            reboot_device(ad)
            iteration_result = "pass"

            time.sleep(WAIT_TIME_FOR_BOOT_COMPLETE)

            dict_match = ad.search_logcat(text_search_mapping['boot_complete'],
                                          begin_time=begin_time)
            if len(dict_match) != 0:
                text_obj_mapping['boot_complete'] = dict_match[0][
                    'datetime_obj']
                ad.log.debug("Datetime for boot_complete is %s",
                             text_obj_mapping['boot_complete'])
                bootup_time = dict_match[0]['datetime_obj'].strftime('%s')
                bootup_time = int(bootup_time) * 1000
                ad.log.info("Bootup Time is %d", bootup_time)
            else:
                ad.log.error("TERMINATE- boot_complete not seen in logcat")
                return False

            for tel_state in text_search_mapping:
                if tel_state == "boot_complete":
                    continue
                dict_match = ad.search_logcat(text_search_mapping[tel_state],
                                              begin_time=bootup_time)
                if len(dict_match) != 0:
                    text_obj_mapping[tel_state] = dict_match[0]['datetime_obj']
                    ad.log.debug("Datetime for %s is %s", tel_state,
                                 text_obj_mapping[tel_state])
                else:
                    ad.log.error("Cannot Find Text %s in logcat",
                                 text_search_mapping[tel_state])
                    blocked_for_calculate.append(tel_state)
                    ad.log.debug("New Blocked %s", blocked_for_calculate)

            ad.log.info("List Blocked %s", blocked_for_calculate)
            for tel_state in text_search_mapping:
                if tel_state not in blocked_for_calculate:
                    time_diff = text_obj_mapping[tel_state] - \
                                text_obj_mapping['boot_complete']
                    ad.log.info("Time Diff is %d for %s", time_diff.seconds,
                                tel_state)
                    if tel_state in keyword_time_dict:
                        keyword_time_dict[tel_state].append(time_diff.seconds)
                    else:
                        keyword_time_dict[tel_state] = [
                            time_diff.seconds,
                        ]
                    ad.log.debug("Keyword Time Dict %s", keyword_time_dict)

            ad.log.info("Telephony Bootup Time Test %s Iteration: %d / %d %s",
                        self.test_name, i, self.stress_test_number,
                        iteration_result)
        ad.log.info("Final Keyword Time Dict %s", keyword_time_dict)
        for tel_state in text_search_mapping:
            if tel_state not in blocked_for_calculate:
                avg_time = self._get_list_average(keyword_time_dict[tel_state])
                if avg_time < 12.0:
                    ad.log.info("Average %s for %d iterations = %.2f seconds",
                                tel_state, self.stress_test_number, avg_time)
                else:
                    ad.log.error("Average %s for %d iterations = %.2f seconds",
                                 tel_state, self.stress_test_number, avg_time)
                    fail_count[tel_state] += 1

        ad.log.info("Bootup Time Dict: %s", keyword_time_dict)
        ad.log.info("fail_count: %s", dict(fail_count))
        for failure, count in fail_count.items():
            if count:
                ad.log.error("%s %s failures in %s iterations", count, failure,
                             self.stress_test_number)
                test_result = False
        return test_result
    def _setup_device(self, ad, sim_conf_file, qxdm_log_mask_cfg=None):
        ad.qxdm_log = getattr(ad, "qxdm_log", self.qxdm_log)
        ad.sdm_log = getattr(ad, "sdm_log", self.sdm_log)
        if self.user_params.get("enable_connectivity_metrics", False):
            enable_connectivity_metrics(ad)
        if self.user_params.get("build_id_override", False):
            build_postfix = self.user_params.get("build_id_postfix",
                                                 "LAB_TEST")
            build_id_override(
                ad,
                new_build_id=self.user_params.get("build_id_override_with",
                                                  None),
                postfix=build_postfix)
        if self.enable_radio_log_on:
            enable_radio_log_on(ad)
        list_of_models = ["sdm", "msm", "kon", "lit"]
        if any(model in ad.model for model in list_of_models):
            phone_mode = "ssss"
            if hasattr(ad, "mtp_dsds"):
                phone_mode = "dsds"
            if ad.adb.getprop("persist.radio.multisim.config") != phone_mode:
                ad.adb.shell("setprop persist.radio.multisim.config %s" \
                             % phone_mode)
                reboot_device(ad)

        stop_qxdm_logger(ad)
        if ad.qxdm_log:
            qxdm_log_mask = getattr(ad, "qxdm_log_mask", None)
            if qxdm_log_mask_cfg:
                qxdm_mask_path = self.user_params.get("qxdm_log_path",
                                                      DEFAULT_QXDM_LOG_PATH)
                ad.adb.shell("mkdir %s" % qxdm_mask_path)
                ad.log.info("Push %s to %s", qxdm_log_mask_cfg, qxdm_mask_path)
                ad.adb.push("%s %s" % (qxdm_log_mask_cfg, qxdm_mask_path))
                mask_file_name = os.path.split(qxdm_log_mask_cfg)[-1]
                qxdm_log_mask = os.path.join(qxdm_mask_path, mask_file_name)
            set_qxdm_logger_command(ad, mask=qxdm_log_mask)
            start_qxdm_logger(ad, utils.get_current_epoch_time())
        elif ad.sdm_log:
            start_sdm_logger(ad)
        else:
            disable_qxdm_logger(ad)
        if not unlock_sim(ad):
            raise signals.TestAbortClass("unable to unlock the SIM")

        # eSIM enablement
        if hasattr(ad, "fi_esim"):
            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
                                         self.wifi_network_pass):
                ad.log.error("Failed to connect to wifi")
            if check_google_fi_activated(ad):
                ad.log.info("Google Fi is already Activated")
            else:
                install_googleaccountutil_apk(ad, self.account_util)
                add_google_account(ad)
                install_googlefi_apk(ad, self.fi_util)
                if not activate_google_fi_account(ad):
                    ad.log.error("Failed to activate Fi")
                check_google_fi_activated(ad)
        if hasattr(ad, "dsds"):
            sim_mode = ad.droid.telephonyGetPhoneCount()
            if sim_mode == 1:
                ad.log.info("Phone in Single SIM Mode")
                if not phone_switch_to_msim_mode(ad):
                    ad.log.error("Failed to switch to Dual SIM Mode")
                    return False
            elif sim_mode == 2:
                ad.log.info("Phone already in Dual SIM Mode")
        if get_sim_state(ad) in (SIM_STATE_ABSENT, SIM_STATE_UNKNOWN):
            ad.log.info("Device has no or unknown SIM in it")
            # eSIM needs activation
            activate_esim_using_suw(ad)
            ensure_phone_idle(self.log, ad)
        elif self.user_params.get("Attenuator"):
            ad.log.info("Device in chamber room")
            ensure_phone_idle(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)
        else:
            self.wait_for_sim_ready(ad)
            ensure_phone_default_state(self.log, ad)
            setup_droid_properties(self.log, ad, sim_conf_file)

        default_slot = getattr(ad, "default_slot", 0)
        if get_subid_from_slot_index(ad.log, ad, default_slot) != INVALID_SUB_ID:
            ad.log.info("Slot %s is the default slot.", default_slot)
            set_default_sub_for_all_services(ad, default_slot)
        else:
            ad.log.warning("Slot %s is NOT a valid slot. Slot %s will be used by default.",
                default_slot, 1-default_slot)
            set_default_sub_for_all_services(ad, 1-default_slot)

        # Activate WFC on Verizon, AT&T and Canada operators as per # b/33187374 &
        # b/122327716
        activate_wfc_on_device(self.log, ad)

        # Sub ID setup
        initial_set_up_for_subid_infomation(self.log, ad)

        # If device is setup already, skip the following setup procedures
        if getattr(ad, "telephony_test_setup", None):
            return True

        try:
            ad.droid.wifiEnableVerboseLogging(WIFI_VERBOSE_LOGGING_ENABLED)
        except Exception:
            pass

        # Disable Emergency alerts
        # Set chrome browser start with no-first-run verification and
        # disable-fre. Give permission to read from and write to storage.
        for cmd in ("pm disable com.android.cellbroadcastreceiver",
                    "pm grant com.android.chrome "
                    "android.permission.READ_EXTERNAL_STORAGE",
                    "pm grant com.android.chrome "
                    "android.permission.WRITE_EXTERNAL_STORAGE",
                    "rm /data/local/chrome-command-line",
                    "am set-debug-app --persistent com.android.chrome",
                    'echo "chrome --no-default-browser-check --no-first-run '
                    '--disable-fre" > /data/local/tmp/chrome-command-line'):
            ad.adb.shell(cmd, ignore_status=True)

        # Curl for 2016/7 devices
        if not getattr(ad, "curl_capable", False):
            try:
                out = ad.adb.shell("/data/curl --version")
                if not out or "not found" in out:
                    if int(ad.adb.getprop("ro.product.first_api_level")) >= 25:
                        tel_data = self.user_params.get("tel_data", "tel_data")
                        if isinstance(tel_data, list):
                            tel_data = tel_data[0]
                        curl_file_path = os.path.join(tel_data, "curl")
                        if not os.path.isfile(curl_file_path):
                            curl_file_path = os.path.join(
                                self.user_params[Config.key_config_path.value],
                                curl_file_path)
                        if os.path.isfile(curl_file_path):
                            ad.log.info("Pushing Curl to /data dir")
                            ad.adb.push("%s /data" % (curl_file_path))
                            ad.adb.shell(
                                "chmod 777 /data/curl", ignore_status=True)
                else:
                    setattr(ad, "curl_capable", True)
            except Exception:
                ad.log.info("Failed to push curl on this device")

        # Ensure that a test class starts from a consistent state that
        # improves chances of valid network selection and facilitates
        # logging.
        try:
            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)
        except Exception as e:
            self.log.error("Failure with %s", e)
        setattr(ad, "telephony_test_setup", True)
        return True