1#!/usr/bin/env python3.4 2# 3# Copyright 2017 - Google 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 import utils 19from acts.base_test import BaseTestClass 20from acts.test_utils.wifi import wifi_test_utils as wutils 21from acts.test_utils.wifi.rtt import rtt_const as rconsts 22from acts.test_utils.wifi.rtt import rtt_test_utils as rutils 23 24 25class RttBaseTest(BaseTestClass): 26 def __init__(self, controllers): 27 if not hasattr(self, 'android_devices'): 28 super(RttBaseTest, self).__init__(controllers) 29 30 def setup_test(self): 31 required_params = ("lci_reference", "lcr_reference", 32 "rtt_reference_distance_mm", 33 "stress_test_min_iteration_count", 34 "stress_test_target_run_time_sec") 35 self.unpack_userparams(required_params) 36 37 # can be moved to JSON config file 38 self.rtt_reference_distance_margin_mm = 2000 39 self.rtt_max_failure_rate_two_sided_rtt_percentage = 20 40 self.rtt_max_failure_rate_one_sided_rtt_percentage = 50 41 self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage = 10 42 self.rtt_max_margin_exceeded_rate_one_sided_rtt_percentage = 50 43 self.rtt_min_expected_rssi_dbm = -100 44 45 for ad in self.android_devices: 46 utils.set_location_service(ad, True) 47 asserts.skip_if( 48 not ad.droid.doesDeviceSupportWifiRttFeature(), 49 "Device under test does not support Wi-Fi RTT - skipping test") 50 wutils.wifi_toggle_state(ad, True) 51 rtt_avail = ad.droid.wifiIsRttAvailable() 52 if not rtt_avail: 53 self.log.info('RTT not available. Waiting ...') 54 rutils.wait_for_event(ad, rconsts.BROADCAST_WIFI_RTT_AVAILABLE) 55 ad.ed.clear_all_events() 56 rutils.config_privilege_override(ad, False) 57 ad.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US) 58 ad.rtt_capabilities = rutils.get_rtt_capabilities(ad) 59 60 def teardown_test(self): 61 for ad in self.android_devices: 62 if not ad.droid.doesDeviceSupportWifiRttFeature(): 63 return 64 65 # clean-up queue from the System Service UID 66 ad.droid.wifiRttCancelRanging([1000]) 67 68 def on_fail(self, test_name, begin_time): 69 for ad in self.android_devices: 70 ad.take_bug_report(test_name, begin_time) 71 ad.cat_adb_log(test_name, begin_time) 72