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 17import os 18 19from acts import asserts 20from acts import utils 21from acts.base_test import BaseTestClass 22from acts.keys import Config 23from acts_contrib.test_utils.net import net_test_utils as nutils 24from acts_contrib.test_utils.wifi import wifi_test_utils as wutils 25from acts_contrib.test_utils.wifi.rtt import rtt_const as rconsts 26from acts_contrib.test_utils.wifi.rtt import rtt_test_utils as rutils 27 28 29class RttBaseTest(BaseTestClass): 30 31 def setup_class(self): 32 opt_param = ["pixel_models", "cnss_diag_file"] 33 self.unpack_userparams(opt_param_names=opt_param) 34 if hasattr(self, "cnss_diag_file"): 35 if isinstance(self.cnss_diag_file, list): 36 self.cnss_diag_file = self.cnss_diag_file[0] 37 if not os.path.isfile(self.cnss_diag_file): 38 self.cnss_diag_file = os.path.join( 39 self.user_params[Config.key_config_path.value], 40 self.cnss_diag_file) 41 42 def setup_test(self): 43 required_params = ("lci_reference", "lcr_reference", 44 "rtt_reference_distance_mm", 45 "stress_test_min_iteration_count", 46 "stress_test_target_run_time_sec") 47 self.unpack_userparams(required_params) 48 49 # can be moved to JSON config file 50 self.rtt_reference_distance_margin_mm = 2000 51 self.rtt_max_failure_rate_two_sided_rtt_percentage = 20 52 self.rtt_max_failure_rate_one_sided_rtt_percentage = 50 53 self.rtt_max_margin_exceeded_rate_two_sided_rtt_percentage = 10 54 self.rtt_max_margin_exceeded_rate_one_sided_rtt_percentage = 50 55 self.rtt_min_expected_rssi_dbm = -100 56 57 if hasattr(self, "cnss_diag_file") and hasattr(self, "pixel_models"): 58 wutils.start_cnss_diags( 59 self.android_devices, self.cnss_diag_file, self.pixel_models) 60 self.tcpdump_proc = [] 61 if hasattr(self, "android_devices"): 62 for ad in self.android_devices: 63 proc = nutils.start_tcpdump(ad, self.test_name) 64 self.tcpdump_proc.append((ad, proc)) 65 66 for ad in self.android_devices: 67 utils.set_location_service(ad, True) 68 ad.droid.wifiEnableVerboseLogging(1) 69 asserts.skip_if( 70 not ad.droid.doesDeviceSupportWifiRttFeature(), 71 "Device under test does not support Wi-Fi RTT - skipping test") 72 wutils.wifi_toggle_state(ad, True) 73 rtt_avail = ad.droid.wifiIsRttAvailable() 74 if not rtt_avail: 75 self.log.info('RTT not available. Waiting ...') 76 rutils.wait_for_event(ad, rconsts.BROADCAST_WIFI_RTT_AVAILABLE) 77 ad.ed.clear_all_events() 78 rutils.config_privilege_override(ad, False) 79 wutils.set_wifi_country_code(ad, wutils.WifiEnums.CountryCode.US) 80 ad.rtt_capabilities = rutils.get_rtt_capabilities(ad) 81 82 def teardown_test(self): 83 if hasattr(self, "cnss_diag_file") and hasattr(self, "pixel_models"): 84 wutils.stop_cnss_diags(self.android_devices, self.pixel_models) 85 for proc in self.tcpdump_proc: 86 nutils.stop_tcpdump( 87 proc[0], proc[1], self.test_name, pull_dump=False) 88 self.tcpdump_proc = [] 89 for ad in self.android_devices: 90 if not ad.droid.doesDeviceSupportWifiRttFeature(): 91 return 92 93 # clean-up queue from the System Service UID 94 ad.droid.wifiRttCancelRanging([1000]) 95 96 def on_fail(self, test_name, begin_time): 97 for ad in self.android_devices: 98 ad.take_bug_report(test_name, begin_time) 99 ad.cat_adb_log(test_name, begin_time) 100 wutils.get_ssrdumps(ad) 101 if hasattr(self, "cnss_diag_file") and hasattr(self, "pixel_models"): 102 wutils.stop_cnss_diags(self.android_devices, self.pixel_models) 103 for ad in self.android_devices: 104 wutils.get_cnss_diag_log(ad) 105 for proc in self.tcpdump_proc: 106 nutils.stop_tcpdump(proc[0], proc[1], self.test_name) 107 self.tcpdump_proc = [] 108