1#!/usr/bin/python3.4 2# 3# Copyright 2017 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from acts import asserts 18from acts.test_decorators import test_tracker_info 19from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest 20from acts_contrib.test_utils.wifi.rtt import rtt_const as rconsts 21from acts_contrib.test_utils.wifi.rtt import rtt_test_utils as rutils 22from acts_contrib.test_utils.wifi.rtt.RttBaseTest import RttBaseTest 23 24 25class RangeApNonSupporting11McTest(RttBaseTest, WifiBaseTest): 26 """Test class for RTT ranging to Access Points which do not support IEEE 27 802.11mc 28 """ 29 30 # Number of RTT iterations 31 NUM_ITER = 10 32 33 # Time gap (in seconds) between iterations 34 TIME_BETWEEN_ITERATIONS = 0 35 36 def setup_class(self): 37 super().setup_class() 38 if "AccessPoint" in self.user_params: 39 self.legacy_configure_ap_and_start() 40 41 def run_test_rtt_non_80211mc_supporting_aps(self, dut, accuracy_evaluation=False): 42 """Scan for APs and perform RTT on non-IEEE 802.11mc supporting APs 43 Args: 44 dut: test device 45 accuracy_evaluation: False - only evaluate success rate. 46 True - evaluate both success rate and accuracy 47 default is False. 48 """ 49 asserts.skip_if( 50 not dut.rtt_capabilities[rconsts.CAP_RTT_ONE_SIDED_SUPPORTED], 51 "Device does not support one-sided RTT") 52 53 non_rtt_aps = rutils.select_best_scan_results( 54 rutils.scan_with_rtt_support_constraint(dut, False), 55 select_count=1) 56 dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps) 57 asserts.assert_true(len(non_rtt_aps) > 0, "Need at least one AP!") 58 events = rutils.run_ranging(dut, non_rtt_aps, self.NUM_ITER, 59 self.TIME_BETWEEN_ITERATIONS) 60 stats = rutils.analyze_results(events, self.rtt_reference_distance_mm, 61 self.rtt_reference_distance_margin_mm, 62 self.rtt_min_expected_rssi_dbm, 63 [], []) 64 dut.log.debug("Stats=%s", stats) 65 66 for bssid, stat in stats.items(): 67 asserts.assert_true( 68 stat['num_no_results'] == 0, 69 "Missing (timed-out) results", 70 extras=stats) 71 asserts.assert_false( 72 stat['any_lci_mismatch'], "LCI mismatch", extras=stats) 73 asserts.assert_false( 74 stat['any_lcr_mismatch'], "LCR mismatch", extras=stats) 75 asserts.assert_equal( 76 stat['num_invalid_rssi'], 0, "Invalid RSSI", extras=stats) 77 asserts.assert_true( 78 stat['num_failures'] <= 79 self.rtt_max_failure_rate_one_sided_rtt_percentage * 80 stat['num_results'] / 100, 81 "Failure rate is too high", 82 extras=stats) 83 if accuracy_evaluation: 84 asserts.assert_true( 85 stat['num_range_out_of_margin'] <= 86 self.rtt_max_margin_exceeded_rate_one_sided_rtt_percentage * 87 stat['num_success_results'] / 100, 88 "Results exceeding error margin rate is too high", 89 extras=stats) 90 asserts.explicit_pass("RTT test done", extras=stats) 91 92 @test_tracker_info(uuid="cde756e9-11f3-43da-b9ae-9edf85764f82") 93 def test_rtt_non_80211mc_supporting_aps(self): 94 """Scan for APs and perform RTT on non-IEEE 802.11mc supporting APs, 95 Functionality test: Only evaluate success rate. 96 """ 97 dut = self.android_devices[0] 98 self.run_test_rtt_non_80211mc_supporting_aps(dut) 99 100 @test_tracker_info(uuid="8fea37f7-0499-4b02-bd33-5ae4d697a4b7") 101 def test_rtt_non_80211mc_supporting_aps_with_accuracy_evaluation(self): 102 """Scan for APs and perform RTT on non-IEEE 802.11mc supporting APs, 103 Performance test: evaluate success rate and accuracy. 104 """ 105 dut = self.android_devices[0] 106 self.run_test_rtt_non_80211mc_supporting_aps(dut, accuracy_evaluation=True) 107 108 @test_tracker_info(uuid="c9e22185-16d4-4fe6-894f-5823587b3288") 109 def test_rtt_non_80211mc_supporting_aps_wo_privilege(self): 110 """Scan for APs and perform RTT on non-IEEE 802.11mc supporting APs with the 111 device not having privilege access (expect failures). 112 """ 113 dut = self.android_devices[0] 114 asserts.skip_if(dut.droid.isSdkAtLeastS(), 115 "Build at least S doesn't need privilege access to use one-sided RTT.") 116 rutils.config_privilege_override(dut, True) 117 non_rtt_aps = rutils.select_best_scan_results( 118 rutils.scan_with_rtt_support_constraint(dut, False), 119 select_count=1) 120 dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps) 121 asserts.assert_true(len(non_rtt_aps) > 0, "Need at least one AP!") 122 events = rutils.run_ranging(dut, non_rtt_aps, self.NUM_ITER, 123 self.TIME_BETWEEN_ITERATIONS) 124 stats = rutils.analyze_results(events, self.rtt_reference_distance_mm, 125 self.rtt_reference_distance_margin_mm, 126 self.rtt_min_expected_rssi_dbm, 127 self.lci_reference, self.lcr_reference) 128 dut.log.debug("Stats=%s", stats) 129 130 for bssid, stat in stats.items(): 131 asserts.assert_true( 132 stat['num_no_results'] == 0, 133 "Missing (timed-out) results", 134 extras=stats) 135 asserts.assert_true( 136 stat['num_failures'] == self.NUM_ITER, 137 "All one-sided RTT requests must fail when executed without privilege", 138 extras=stats) 139 for code in stat['status_codes']: 140 asserts.assert_true( 141 code == rconsts. 142 EVENT_CB_RANGING_STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC, 143 "Expected non-support error code", 144 extras=stats) 145 asserts.explicit_pass("RTT test done", extras=stats) 146 147 @test_tracker_info(uuid="e117af56-bd3f-40ae-a2fd-4175f0daa7fa") 148 def test_rtt_non_80211mc_supporting_ap_faked_as_supporting(self): 149 """Scan for APs which do not support IEEE 802.11mc, maliciously modify the 150 Responder config to indicate support and pass-through to service. Verify 151 that get an error result. 152 """ 153 dut = self.android_devices[0] 154 non_rtt_aps = rutils.select_best_scan_results( 155 rutils.scan_with_rtt_support_constraint(dut, False), 156 select_count=1) 157 dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps) 158 asserts.assert_true(len(non_rtt_aps) > 0, "Need at least one AP!") 159 non_rtt_aps = non_rtt_aps[0:1] # pick first 160 non_rtt_aps[0][rconsts.SCAN_RESULT_KEY_RTT_RESPONDER] = True # falsify 161 dut.log.debug("Visible non-IEEE 802.11mc APs=%s", non_rtt_aps) 162 events = rutils.run_ranging(dut, non_rtt_aps, self.NUM_ITER, 163 self.TIME_BETWEEN_ITERATIONS) 164 stats = rutils.analyze_results(events, self.rtt_reference_distance_mm, 165 self.rtt_reference_distance_margin_mm, 166 self.rtt_min_expected_rssi_dbm, 167 self.lci_reference, self.lcr_reference) 168 dut.log.debug("Stats=%s", stats) 169 170 for bssid, stat in stats.items(): 171 asserts.assert_true( 172 stat['num_no_results'] == 0, 173 "Missing (timed-out) results", 174 extras=stats) 175 asserts.assert_true( 176 stat['num_failures'] == self.NUM_ITER, 177 "Failures expected for falsified responder config", 178 extras=stats) 179 asserts.explicit_pass("RTT test done", extras=stats) 180