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_utils.wifi import wifi_test_utils as wutils 19from acts.test_utils.wifi.rtt import rtt_const as rconsts 20from acts.test_utils.wifi.rtt import rtt_test_utils as rutils 21from acts.test_utils.wifi.rtt.RttBaseTest import RttBaseTest 22 23 24class RangeApMiscTest(RttBaseTest): 25 """Test class for RTT ranging to Access Points - miscellaneous tests which 26 do not fit into the strict IEEE 802.11mc supporting or non-supporting test 27 beds - e.g. a mixed test.""" 28 29 # Number of RTT iterations 30 NUM_ITER = 10 31 32 # Time gap (in seconds) between iterations 33 TIME_BETWEEN_ITERATIONS = 0 34 35 def __init__(self, controllers): 36 RttBaseTest.__init__(self, controllers) 37 38 ############################################################################# 39 40 def test_rtt_mixed_80211mc_supporting_aps_wo_privilege(self): 41 """Scan for APs and perform RTT on one supporting and one non-supporting 42 IEEE 802.11mc APs with the device not having privilege access (expect 43 failures).""" 44 dut = self.android_devices[0] 45 rutils.config_privilege_override(dut, True) 46 rtt_aps = rutils.scan_with_rtt_support_constraint(dut, True) 47 non_rtt_aps = rutils.scan_with_rtt_support_constraint(dut, False) 48 mix_list = [rtt_aps[0], non_rtt_aps[0]] 49 dut.log.debug("Visible non-IEEE 802.11mc APs=%s", mix_list) 50 events = rutils.run_ranging(dut, mix_list, self.NUM_ITER, 51 self.TIME_BETWEEN_ITERATIONS) 52 stats = rutils.analyze_results(events, self.rtt_reference_distance_mm, 53 self.rtt_reference_distance_margin_mm, 54 self.rtt_min_expected_rssi_dbm, 55 self.lci_reference, self.lcr_reference) 56 dut.log.debug("Stats=%s", stats) 57 58 for bssid, stat in stats.items(): 59 asserts.assert_true( 60 stat['num_no_results'] == 0, 61 "Missing (timed-out) results", 62 extras=stats) 63 if bssid == rtt_aps[0][wutils.WifiEnums.BSSID_KEY]: 64 asserts.assert_false( 65 stat['any_lci_mismatch'], "LCI mismatch", extras=stats) 66 asserts.assert_false( 67 stat['any_lcr_mismatch'], "LCR mismatch", extras=stats) 68 asserts.assert_equal( 69 stat['num_invalid_rssi'], 0, "Invalid RSSI", extras=stats) 70 asserts.assert_true( 71 stat['num_failures'] <= 72 self.rtt_max_failure_rate_two_sided_rtt_percentage * 73 stat['num_results'] / 100, 74 "Failure rate is too high", 75 extras=stats) 76 asserts.assert_true( 77 stat['num_range_out_of_margin'] <= 78 self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage 79 * stat['num_success_results'] / 100, 80 "Results exceeding error margin rate is too high", 81 extras=stats) 82 else: 83 asserts.assert_true( 84 stat['num_failures'] == self.NUM_ITER, 85 "All one-sided RTT requests must fail when executed without privilege", 86 extras=stats) 87 for code in stat['status_codes']: 88 asserts.assert_true( 89 code == rconsts. 90 EVENT_CB_RANGING_STATUS_RESPONDER_DOES_NOT_SUPPORT_IEEE80211MC, 91 "Expected non-support error code", 92 extras=stats) 93 asserts.explicit_pass("RTT test done", extras=stats) 94