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.base_test import BaseTestClass
19from acts.test_utils.wifi.rtt import rtt_test_utils as rutils
20from acts.test_utils.wifi.rtt.RttBaseTest import RttBaseTest
21
22
23class StressRangeApTest(RttBaseTest):
24  """Test class for stress testing of RTT ranging to Access Points"""
25
26  def __init__(self, controllers):
27    BaseTestClass.__init__(self, controllers)
28
29  #############################################################################
30
31  def test_rtt_supporting_ap_only(self):
32    """Scan for APs and perform RTT only to those which support 802.11mc.
33
34    Stress test: repeat ranging to the same AP. Verify rate of success and
35    stability of results.
36    """
37    dut = self.android_devices[0]
38    rtt_supporting_aps = rutils.scan_with_rtt_support_constraint(dut, True,
39                                                                 repeat=10)
40    dut.log.debug("RTT Supporting APs=%s", rtt_supporting_aps)
41
42    num_iter = self.stress_test_min_iteration_count
43
44    max_peers = dut.droid.wifiRttMaxPeersInRequest()
45    asserts.assert_true(
46        len(rtt_supporting_aps) > 0,
47        "Need at least one AP which supports 802.11mc!")
48    if len(rtt_supporting_aps) > max_peers:
49      rtt_supporting_aps = rtt_supporting_aps[0:max_peers]
50
51    events = rutils.run_ranging(dut, rtt_supporting_aps, num_iter, 0,
52                                self.stress_test_target_run_time_sec)
53    stats = rutils.analyze_results(events, self.rtt_reference_distance_mm,
54                                   self.rtt_reference_distance_margin_mm,
55                                   self.rtt_min_expected_rssi_dbm,
56                                   self.lci_reference, self.lcr_reference,
57                                   summary_only=True)
58    dut.log.debug("Stats=%s", stats)
59
60    for bssid, stat in stats.items():
61      asserts.assert_true(stat['num_no_results'] == 0,
62                          "Missing (timed-out) results", extras=stats)
63      asserts.assert_false(stat['any_lci_mismatch'],
64                           "LCI mismatch", extras=stats)
65      asserts.assert_false(stat['any_lcr_mismatch'],
66                           "LCR mismatch", extras=stats)
67      asserts.assert_equal(stat['num_invalid_rssi'], 0, "Invalid RSSI",
68                          extras=stats)
69      asserts.assert_true(stat['num_failures'] <=
70                          self.rtt_max_failure_rate_two_sided_rtt_percentage
71                          * stat['num_results'] / 100,
72                          "Failure rate is too high", extras=stats)
73      asserts.assert_true(stat['num_range_out_of_margin'] <=
74                    self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage
75                    * stat['num_success_results'] / 100,
76                    "Results exceeding error margin rate is too high",
77                    extras=stats)
78    asserts.explicit_pass("RTT test done", extras=stats)
79
80