def test_rtt_non_80211mc_supporting_ap_faked_as_supporting(self):
        """Scan for APs which do not support IEEE 802.11mc, maliciously modify the
        Responder config to indicate support and pass-through to service. Verify
        that get an error result.
        """
        dut = self.android_devices[0]
        non_rtt_aps = rutils.select_best_scan_results(
            rutils.scan_with_rtt_support_constraint(dut, False),
            select_count=1)
        dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps)
        asserts.assert_true(len(non_rtt_aps) > 0, "Need at least one AP!")
        non_rtt_aps = non_rtt_aps[0:1]  # pick first
        non_rtt_aps[0][rconsts.SCAN_RESULT_KEY_RTT_RESPONDER] = True  # falsify
        dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps)
        events = rutils.run_ranging(dut, non_rtt_aps, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference, self.lcr_reference)
        dut.log.debug("Stats=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(stat['num_no_results'] == 0,
                                "Missing (timed-out) results",
                                extras=stats)
            asserts.assert_true(
                stat['num_failures'] == self.NUM_ITER,
                "Failures expected for falsified responder config",
                extras=stats)
        asserts.explicit_pass("RTT test done", extras=stats)
    def test_rtt_non_80211mc_supporting_aps_wo_privilege(self):
        """Scan for APs and perform RTT on non-IEEE 802.11mc supporting APs with the
        device not having privilege access (expect failures).
        """
        dut = self.android_devices[0]
        rutils.config_privilege_override(dut, True)
        non_rtt_aps = rutils.select_best_scan_results(
            rutils.scan_with_rtt_support_constraint(dut, False),
            select_count=1)
        dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps)
        asserts.assert_true(len(non_rtt_aps) > 0, "Need at least one AP!")
        events = rutils.run_ranging(dut, non_rtt_aps, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference, self.lcr_reference)
        dut.log.debug("Stats=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(stat['num_no_results'] == 0,
                                "Missing (timed-out) results",
                                extras=stats)
            asserts.assert_true(
                stat['num_failures'] == self.NUM_ITER,
                "All one-sided RTT requests must fail when executed without privilege",
                extras=stats)
            for code in stat['status_codes']:
                asserts.assert_true(
                    code == rconsts.
                    EVENT_CB_RANGING_STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC,
                    "Expected non-support error code",
                    extras=stats)
        asserts.explicit_pass("RTT test done", extras=stats)
    def test_rtt_supporting_ap_only(self):
        """Scan for APs and perform RTT only to those which support 802.11mc.

    Stress test: repeat ranging to the same AP. Verify rate of success and
    stability of results.
    """
        dut = self.android_devices[0]
        rtt_supporting_aps = rutils.scan_with_rtt_support_constraint(dut,
                                                                     True,
                                                                     repeat=10)
        dut.log.debug("RTT Supporting APs=%s", rtt_supporting_aps)

        num_iter = self.stress_test_min_iteration_count

        max_peers = dut.droid.wifiRttMaxPeersInRequest()
        asserts.assert_true(
            len(rtt_supporting_aps) > 0,
            "Need at least one AP which supports 802.11mc!")
        if len(rtt_supporting_aps) > max_peers:
            rtt_supporting_aps = rtt_supporting_aps[0:max_peers]

        events = rutils.run_ranging(dut, rtt_supporting_aps, num_iter, 0,
                                    self.stress_test_target_run_time_sec)
        stats = rutils.analyze_results(events,
                                       self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference,
                                       self.lcr_reference,
                                       summary_only=True)
        dut.log.debug("Stats=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(stat['num_no_results'] == 0,
                                "Missing (timed-out) results",
                                extras=stats)
            asserts.assert_false(stat['any_lci_mismatch'],
                                 "LCI mismatch",
                                 extras=stats)
            asserts.assert_false(stat['any_lcr_mismatch'],
                                 "LCR mismatch",
                                 extras=stats)
            asserts.assert_equal(stat['num_invalid_rssi'],
                                 0,
                                 "Invalid RSSI",
                                 extras=stats)
            asserts.assert_true(
                stat['num_failures'] <=
                self.rtt_max_failure_rate_two_sided_rtt_percentage *
                stat['num_results'] / 100,
                "Failure rate is too high",
                extras=stats)
            asserts.assert_true(
                stat['num_range_out_of_margin'] <=
                self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage *
                stat['num_success_results'] / 100,
                "Results exceeding error margin rate is too high",
                extras=stats)
        asserts.explicit_pass("RTT test done", extras=stats)
    def test_rtt_mixed_80211mc_supporting_aps_wo_privilege(self):
        """Scan for APs and perform RTT on one supporting and one non-supporting
    IEEE 802.11mc APs with the device not having privilege access (expect
    failures)."""
        dut = self.android_devices[0]
        rutils.config_privilege_override(dut, True)
        rtt_aps = rutils.scan_with_rtt_support_constraint(dut, True)
        non_rtt_aps = rutils.scan_with_rtt_support_constraint(dut, False)
        mix_list = [rtt_aps[0], non_rtt_aps[0]]
        dut.log.debug("Visible non-IEEE 802.11mc APs=%s", mix_list)
        events = rutils.run_ranging(dut, mix_list, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference, self.lcr_reference)
        dut.log.debug("Stats=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(stat['num_no_results'] == 0,
                                "Missing (timed-out) results",
                                extras=stats)
            if bssid == rtt_aps[0][wutils.WifiEnums.BSSID_KEY]:
                asserts.assert_false(stat['any_lci_mismatch'],
                                     "LCI mismatch",
                                     extras=stats)
                asserts.assert_false(stat['any_lcr_mismatch'],
                                     "LCR mismatch",
                                     extras=stats)
                asserts.assert_equal(stat['num_invalid_rssi'],
                                     0,
                                     "Invalid RSSI",
                                     extras=stats)
                asserts.assert_true(
                    stat['num_failures'] <=
                    self.rtt_max_failure_rate_two_sided_rtt_percentage *
                    stat['num_results'] / 100,
                    "Failure rate is too high",
                    extras=stats)
                asserts.assert_true(
                    stat['num_range_out_of_margin'] <=
                    self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage
                    * stat['num_success_results'] / 100,
                    "Results exceeding error margin rate is too high",
                    extras=stats)
            else:
                asserts.assert_true(
                    stat['num_failures'] == self.NUM_ITER,
                    "All one-sided RTT requests must fail when executed without privilege",
                    extras=stats)
                for code in stat['status_codes']:
                    asserts.assert_true(
                        code == rconsts.
                        EVENT_CB_RANGING_STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC,
                        "Expected non-support error code",
                        extras=stats)
        asserts.explicit_pass("RTT test done", extras=stats)
Example #5
0
    def run_test_rtt_80211mc_supporting_aps(self,
                                            dut,
                                            accuracy_evaluation=False):
        """Scan for APs and perform RTT only to those which support 802.11mc
        Args:
            dut: test device
            accuracy_evaluation: False - only evaluate success rate.
                                 True - evaluate both success rate and accuracy
                                 default is False.
        """
        rtt_supporting_aps = rutils.select_best_scan_results(
            rutils.scan_with_rtt_support_constraint(dut, True, repeat=10),
            select_count=2)
        dut.log.debug("RTT Supporting APs=%s", rtt_supporting_aps)
        events = rutils.run_ranging(dut, rtt_supporting_aps, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference, self.lcr_reference)
        dut.log.debug("Stats=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(stat['num_no_results'] == 0,
                                "Missing (timed-out) results",
                                extras=stats)
            asserts.assert_false(stat['any_lci_mismatch'],
                                 "LCI mismatch",
                                 extras=stats)
            asserts.assert_false(stat['any_lcr_mismatch'],
                                 "LCR mismatch",
                                 extras=stats)
            asserts.assert_false(stat['invalid_num_attempted'],
                                 "Invalid (0) number of attempts",
                                 extras=stats)
            asserts.assert_false(stat['invalid_num_successful'],
                                 "Invalid (0) number of successes",
                                 extras=stats)
            asserts.assert_equal(stat['num_invalid_rssi'],
                                 0,
                                 "Invalid RSSI",
                                 extras=stats)
            asserts.assert_true(
                stat['num_failures'] <=
                self.rtt_max_failure_rate_two_sided_rtt_percentage *
                stat['num_results'] / 100,
                "Failure rate is too high",
                extras=stats)
            if accuracy_evaluation:
                asserts.assert_true(
                    stat['num_range_out_of_margin'] <=
                    self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage
                    * stat['num_success_results'] / 100,
                    "Results exceeding error margin rate is too high",
                    extras=stats)
        asserts.explicit_pass("RTT test done", extras=stats)
    def run_test_rtt_non_80211mc_supporting_aps(self,
                                                dut,
                                                accuracy_evaluation=False):
        """Scan for APs and perform RTT on non-IEEE 802.11mc supporting APs
        Args:
            dut: test device
            accuracy_evaluation: False - only evaluate success rate.
                                 True - evaluate both success rate and accuracy
                                 default is False.
        """
        asserts.skip_if(
            not dut.rtt_capabilities[rconsts.CAP_RTT_ONE_SIDED_SUPPORTED],
            "Device does not support one-sided RTT")

        non_rtt_aps = rutils.select_best_scan_results(
            rutils.scan_with_rtt_support_constraint(dut, False),
            select_count=1)
        dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps)
        asserts.assert_true(len(non_rtt_aps) > 0, "Need at least one AP!")
        events = rutils.run_ranging(dut, non_rtt_aps, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm, [], [])
        dut.log.debug("Stats=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(stat['num_no_results'] == 0,
                                "Missing (timed-out) results",
                                extras=stats)
            asserts.assert_false(stat['any_lci_mismatch'],
                                 "LCI mismatch",
                                 extras=stats)
            asserts.assert_false(stat['any_lcr_mismatch'],
                                 "LCR mismatch",
                                 extras=stats)
            asserts.assert_equal(stat['num_invalid_rssi'],
                                 0,
                                 "Invalid RSSI",
                                 extras=stats)
            asserts.assert_true(
                stat['num_failures'] <=
                self.rtt_max_failure_rate_one_sided_rtt_percentage *
                stat['num_results'] / 100,
                "Failure rate is too high",
                extras=stats)
            if accuracy_evaluation:
                asserts.assert_true(
                    stat['num_range_out_of_margin'] <=
                    self.rtt_max_margin_exceeded_rate_one_sided_rtt_percentage
                    * stat['num_success_results'] / 100,
                    "Results exceeding error margin rate is too high",
                    extras=stats)
        asserts.explicit_pass("RTT test done", extras=stats)
    def test_rtt_to_soft_ap(self):
        """Set up a Soft AP on one device and try performing an RTT ranging to it
    from another device. The attempt must fail - RTT on Soft AP must be
    disabled."""
        sap = self.android_devices[0]
        sap.pretty_name = "SoftAP"
        client = self.android_devices[1]
        client.pretty_name = "Client"

        # start Soft AP
        wutils.start_wifi_tethering(sap,
                                    self.SOFT_AP_SSID,
                                    self.SOFT_AP_PASSWORD,
                                    band=WIFI_CONFIG_APBAND_5G,
                                    hidden=False)

        try:
            # start scanning on the client
            wutils.start_wifi_connection_scan_and_ensure_network_found(
                client, self.SOFT_AP_SSID)
            scans = client.droid.wifiGetScanResults()
            scanned_softap = None
            for scanned_ap in scans:
                if scanned_ap[wutils.WifiEnums.SSID_KEY] == self.SOFT_AP_SSID:
                    scanned_softap = scanned_ap
                    break

            asserts.assert_false(scanned_softap == None,
                                 "Soft AP not found in scan!",
                                 extras=scans)

            # validate that Soft AP does not advertise 802.11mc support
            asserts.assert_false(
                rconsts.SCAN_RESULT_KEY_RTT_RESPONDER in scanned_softap
                and scanned_softap[rconsts.SCAN_RESULT_KEY_RTT_RESPONDER],
                "Soft AP advertises itself as supporting 802.11mc!",
                extras=scanned_softap)

            # falsify the SoftAP's support for IEEE 802.11 so we try a 2-sided RTT
            scanned_softap[
                rconsts.SCAN_RESULT_KEY_RTT_RESPONDER] = True  # falsify

            # actually try ranging to the Soft AP
            events = rutils.run_ranging(client, [scanned_softap],
                                        self.NUM_ITER, 0)
            stats = rutils.analyze_results(
                events, self.rtt_reference_distance_mm,
                self.rtt_reference_distance_margin_mm,
                self.rtt_min_expected_rssi_dbm, self.lci_reference,
                self.lcr_reference)

            asserts.assert_equal(
                stats[scanned_ap[wutils.WifiEnums.BSSID_KEY]]['num_failures'],
                self.NUM_ITER,
                "Some RTT operations to Soft AP succeed!?",
                extras=stats)

            asserts.explicit_pass("SoftAP + RTT validation done",
                                  extras=events)
        finally:
            wutils.stop_wifi_tethering(sap)
Example #8
0
    def test_rtt_in_and_after_softap_mode(self):
        """Verify behavior when a SoftAP is enabled and then disabled on the
        device:

        - SAP Enabled: depending on device characteristics RTT may succeed or
                       fail.
        - SAP Disabled: RTT must now succeed.
        """
        supp_required_params = ("dbs_supported_models", )
        self.unpack_userparams(supp_required_params)

        dut = self.android_devices[0]

        rtt_supporting_aps = rutils.select_best_scan_results(
            rutils.scan_with_rtt_support_constraint(dut, True, repeat=10),
            select_count=1)
        dut.log.debug("RTT Supporting APs=%s", rtt_supporting_aps)

        # phase 1 (pre-SAP)
        events = rutils.run_ranging(dut, rtt_supporting_aps, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference, self.lcr_reference)
        dut.log.debug("Stats Phase 1 (pre-SAP)=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(
                stat['num_no_results'] == 0,
                "Phase 1 (pre-SAP) missing (timed-out) results",
                extras=stats)

        # phase 2 (SAP)
        wutils.start_wifi_tethering(dut,
                                    self.SOFT_AP_SSID,
                                    self.SOFT_AP_PASSWORD,
                                    band=WIFI_CONFIG_APBAND_5G,
                                    hidden=False)
        time.sleep(self.WAIT_FOR_CONFIG_CHANGES_SEC)

        if dut.model not in self.dbs_supported_models:
            rutils.wait_for_event(dut,
                                  rconsts.BROADCAST_WIFI_RTT_NOT_AVAILABLE)
            asserts.assert_false(dut.droid.wifiIsRttAvailable(),
                                 "RTT is available")

        events = rutils.run_ranging(dut, rtt_supporting_aps, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference, self.lcr_reference)
        dut.log.debug("Stats Phase 2 (SAP)=%s", stats)

        for bssid, stat in stats.items():
            if dut.model in self.dbs_supported_models:
                asserts.assert_true(
                    stat['num_no_results'] == 0,
                    "Phase 2 (SAP) missing (timed-out) results",
                    extras=stats)
            else:
                asserts.assert_true(
                    stat['num_success_results'] == 0,
                    "Phase 2 (SAP) valid results - but unexpected in SAP!?",
                    extras=stats)

        # phase 3 (post-SAP)

        # enabling Wi-Fi first: on some devices this will also disable SAP
        # (that's the scenario we're primarily testing). Additionally,
        # explicitly disable SAP (which may be a NOP on some devices).
        wutils.wifi_toggle_state(dut, True)
        time.sleep(self.WAIT_FOR_CONFIG_CHANGES_SEC)
        wutils.stop_wifi_tethering(dut)

        if dut.model not in self.dbs_supported_models:
            rutils.wait_for_event(dut, rconsts.BROADCAST_WIFI_RTT_AVAILABLE)
            asserts.assert_true(dut.droid.wifiIsRttAvailable(),
                                "RTT is not available")

        events = rutils.run_ranging(dut, rtt_supporting_aps, self.NUM_ITER,
                                    self.TIME_BETWEEN_ITERATIONS)
        stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
                                       self.rtt_reference_distance_margin_mm,
                                       self.rtt_min_expected_rssi_dbm,
                                       self.lci_reference, self.lcr_reference)
        dut.log.debug("Stats Phase 3 (post-SAP)=%s", stats)

        for bssid, stat in stats.items():
            asserts.assert_true(
                stat['num_no_results'] == 0,
                "Phase 3 (post-SAP) missing (timed-out) results",
                extras=stats)