Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3.4 |
| 2 | # |
| 3 | # Copyright 2017 - The Android Open Source Project |
| 4 | # |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 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 |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 12 | # distributed under the License is distributed on an 'AS IS' BASIS, |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 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 | |
| 17 | import collections |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 18 | import csv |
| 19 | import itertools |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 20 | import logging |
Omar El Ayach | e972596 | 2019-09-18 17:30:17 -0700 | [diff] [blame] | 21 | import numpy |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 22 | import os |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 23 | from acts import asserts |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 24 | from acts import context |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 25 | from acts import base_test |
| 26 | from acts import utils |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 27 | from acts.controllers import iperf_client |
Omar El Ayach | 14416ac | 2019-01-30 14:58:19 -0800 | [diff] [blame] | 28 | from acts.controllers.utils_lib import ssh |
Xianyuan Jia | 976d404 | 2019-09-30 17:19:47 -0700 | [diff] [blame] | 29 | from acts.metrics.loggers.blackbox import BlackboxMappedMetricLogger |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 30 | from acts.test_utils.wifi import ota_chamber |
Omar El Ayach | 6e518a2 | 2019-06-13 13:55:42 -0700 | [diff] [blame] | 31 | from acts.test_utils.wifi import wifi_performance_test_utils as wputils |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 32 | from acts.test_utils.wifi import wifi_test_utils as wutils |
| 33 | from acts.test_utils.wifi import wifi_retail_ap as retail_ap |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 34 | from functools import partial |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 35 | from WifiRvrTest import WifiRvrTest |
| 36 | from WifiPingTest import WifiPingTest |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 37 | |
| 38 | |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 39 | class WifiSensitivityTest(WifiRvrTest, WifiPingTest): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 40 | """Class to test WiFi sensitivity tests. |
| 41 | |
| 42 | This class implements measures WiFi sensitivity per rate. It heavily |
| 43 | leverages the WifiRvrTest class and introduced minor differences to set |
| 44 | specific rates and the access point, and implements a different pass/fail |
| 45 | check. For an example config file to run this test class see |
| 46 | example_connectivity_performance_ap_sta.json. |
| 47 | """ |
| 48 | |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 49 | RSSI_POLL_INTERVAL = 0.2 |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 50 | VALID_TEST_CONFIGS = { |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 51 | 1: ['legacy', 'VHT20'], |
| 52 | 2: ['legacy', 'VHT20'], |
| 53 | 6: ['legacy', 'VHT20'], |
| 54 | 10: ['legacy', 'VHT20'], |
| 55 | 11: ['legacy', 'VHT20'], |
| 56 | 36: ['legacy', 'VHT20', 'VHT40', 'VHT80'], |
| 57 | 40: ['legacy', 'VHT20'], |
| 58 | 44: ['legacy', 'VHT20'], |
| 59 | 48: ['legacy', 'VHT20'], |
| 60 | 149: ['legacy', 'VHT20', 'VHT40', 'VHT80'], |
| 61 | 153: ['legacy', 'VHT20'], |
| 62 | 157: ['legacy', 'VHT20'], |
| 63 | 161: ['legacy', 'VHT20'] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 64 | } |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 65 | RateTuple = collections.namedtuple(('RateTuple'), |
| 66 | ['mcs', 'streams', 'data_rate']) |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 67 | #yapf:disable |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 68 | VALID_RATES = { |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 69 | 'legacy_2GHz': [ |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 70 | RateTuple(54, 1, 54), RateTuple(48, 1, 48), |
| 71 | RateTuple(36, 1, 36), RateTuple(24, 1, 24), |
| 72 | RateTuple(18, 1, 18), RateTuple(12, 1, 12), |
| 73 | RateTuple(11, 1, 11), RateTuple(9, 1, 9), |
| 74 | RateTuple(6, 1, 6), RateTuple(5.5, 1, 5.5), |
| 75 | RateTuple(2, 1, 2), RateTuple(1, 1, 1)], |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 76 | 'legacy_5GHz': [ |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 77 | RateTuple(54, 1, 54), RateTuple(48, 1, 48), |
| 78 | RateTuple(36, 1, 36), RateTuple(24, 1, 24), |
| 79 | RateTuple(18, 1, 18), RateTuple(12, 1, 12), |
| 80 | RateTuple(9, 1, 9), RateTuple(6, 1, 6)], |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 81 | 'HT20': [ |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 82 | RateTuple(7, 1, 72.2), RateTuple(6, 1, 65), |
| 83 | RateTuple(5, 1, 57.8), RateTuple(4, 1, 43.3), |
| 84 | RateTuple(3, 1, 26), RateTuple(2, 1, 21.7), |
| 85 | RateTuple(1, 1, 14.4), RateTuple(0, 1, 7.2), |
| 86 | RateTuple(15, 2, 144.4), RateTuple(14, 2, 130), |
| 87 | RateTuple(13, 2, 115.6), RateTuple(12, 2, 86.7), |
| 88 | RateTuple(11, 2, 57.8), RateTuple(10, 2, 43.4), |
| 89 | RateTuple(9, 2, 28.9), RateTuple(8, 2, 14.4)], |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 90 | 'VHT20': [ |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 91 | RateTuple(9, 1, 96), RateTuple(8, 1, 86.7), |
| 92 | RateTuple(7, 1, 72.2), RateTuple(6, 1, 65), |
| 93 | RateTuple(5, 1, 57.8), RateTuple(4, 1, 43.3), |
| 94 | RateTuple(3, 1, 28.9), RateTuple(2, 1, 21.7), |
| 95 | RateTuple(1, 1, 14.4), RateTuple(0, 1, 7.2), |
| 96 | RateTuple(9, 2, 192), RateTuple(8, 2, 173.3), |
| 97 | RateTuple(7, 2, 144.4), RateTuple(6, 2, 130.3), |
| 98 | RateTuple(5, 2, 115.6), RateTuple(4, 2, 86.7), |
| 99 | RateTuple(3, 2, 57.8), RateTuple(2, 2, 43.3), |
| 100 | RateTuple(1, 2, 28.9), RateTuple(0, 2, 14.4)], |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 101 | 'VHT40': [ |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 102 | RateTuple(9, 1, 96), RateTuple(8, 1, 86.7), |
| 103 | RateTuple(7, 1, 72.2), RateTuple(6, 1, 65), |
| 104 | RateTuple(5, 1, 57.8), RateTuple(4, 1, 43.3), |
| 105 | RateTuple(3, 1, 28.9), RateTuple(2, 1, 21.7), |
| 106 | RateTuple(1, 1, 14.4), RateTuple(0, 1, 7.2), |
| 107 | RateTuple(9, 2, 192), RateTuple(8, 2, 173.3), |
| 108 | RateTuple(7, 2, 144.4), RateTuple(6, 2, 130.3), |
| 109 | RateTuple(5, 2, 115.6), RateTuple(4, 2, 86.7), |
| 110 | RateTuple(3, 2, 57.8), RateTuple(2, 2, 43.3), |
| 111 | RateTuple(1, 2, 28.9), RateTuple(0, 2, 14.4)], |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 112 | 'VHT80': [ |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 113 | RateTuple(9, 1, 96), RateTuple(8, 1, 86.7), |
| 114 | RateTuple(7, 1, 72.2), RateTuple(6, 1, 65), |
| 115 | RateTuple(5, 1, 57.8), RateTuple(4, 1, 43.3), |
| 116 | RateTuple(3, 1, 28.9), RateTuple(2, 1, 21.7), |
| 117 | RateTuple(1, 1, 14.4), RateTuple(0, 1, 7.2), |
| 118 | RateTuple(9, 2, 192), RateTuple(8, 2, 173.3), |
| 119 | RateTuple(7, 2, 144.4), RateTuple(6, 2, 130.3), |
| 120 | RateTuple(5, 2, 115.6), RateTuple(4, 2, 86.7), |
| 121 | RateTuple(3, 2, 57.8), RateTuple(2, 2, 43.3), |
| 122 | RateTuple(1, 2, 28.9), RateTuple(0, 2, 14.4)], |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 123 | } |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 124 | #yapf:enable |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 125 | |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 126 | def __init__(self, controllers): |
| 127 | base_test.BaseTestClass.__init__(self, controllers) |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 128 | self.testcase_metric_logger = ( |
Xianyuan Jia | 976d404 | 2019-09-30 17:19:47 -0700 | [diff] [blame] | 129 | BlackboxMappedMetricLogger.for_test_case()) |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 130 | self.testclass_metric_logger = ( |
Xianyuan Jia | 976d404 | 2019-09-30 17:19:47 -0700 | [diff] [blame] | 131 | BlackboxMappedMetricLogger.for_test_class()) |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 132 | self.publish_testcase_metrics = True |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 133 | |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 134 | def setup_class(self): |
| 135 | """Initializes common test hardware and parameters. |
| 136 | |
| 137 | This function initializes hardwares and compiles parameters that are |
| 138 | common to all tests in this class. |
| 139 | """ |
Omar El Ayach | 656bf3d | 2019-07-31 15:04:53 -0700 | [diff] [blame] | 140 | self.dut = self.android_devices[-1] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 141 | req_params = [ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 142 | 'RetailAccessPoints', 'sensitivity_test_params', 'testbed_params', |
| 143 | 'RemoteServer' |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 144 | ] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 145 | opt_params = ['main_network', 'golden_files_list'] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 146 | self.unpack_userparams(req_params, opt_params) |
| 147 | self.testclass_params = self.sensitivity_test_params |
| 148 | self.num_atten = self.attenuators[0].instrument.num_atten |
Omar El Ayach | 14416ac | 2019-01-30 14:58:19 -0800 | [diff] [blame] | 149 | self.ping_server = ssh.connection.SshConnection( |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 150 | ssh.settings.from_config(self.RemoteServer[0]['ssh_config'])) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 151 | self.iperf_server = self.iperf_servers[0] |
Omar El Ayach | 14416ac | 2019-01-30 14:58:19 -0800 | [diff] [blame] | 152 | self.iperf_client = self.iperf_clients[0] |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 153 | self.access_point = retail_ap.create(self.RetailAccessPoints)[0] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 154 | self.log.info('Access Point Configuration: {}'.format( |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 155 | self.access_point.ap_settings)) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 156 | self.log_path = os.path.join(logging.log_path, 'results') |
Mark De Ruyter | 72f8df9 | 2020-02-12 13:44:49 -0800 | [diff] [blame] | 157 | os.makedirs(self.log_path, exist_ok=True) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 158 | if not hasattr(self, 'golden_files_list'): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 159 | self.golden_files_list = [ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 160 | os.path.join(self.testbed_params['golden_results_path'], file) |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 161 | for file in os.listdir( |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 162 | self.testbed_params['golden_results_path']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 163 | ] |
Omar El Ayach | 9c56cf3 | 2019-09-19 13:07:51 -0700 | [diff] [blame] | 164 | if hasattr(self, 'bdf'): |
| 165 | self.log.info('Pushing WiFi BDF to DUT.') |
| 166 | wputils.push_bdf(self.dut, self.bdf) |
| 167 | if hasattr(self, 'firmware'): |
| 168 | self.log.info('Pushing WiFi firmware to DUT.') |
| 169 | wlanmdsp = [ |
| 170 | file for file in self.firmware if "wlanmdsp.mbn" in file |
| 171 | ][0] |
| 172 | data_msc = [file for file in self.firmware |
| 173 | if "Data.msc" in file][0] |
| 174 | wputils.push_firmware(self.dut, wlanmdsp, data_msc) |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 175 | self.atten_dut_chain_map = {} |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 176 | self.testclass_results = [] |
| 177 | |
| 178 | # Turn WiFi ON |
Omar El Ayach | d710909 | 2019-09-29 18:31:33 -0700 | [diff] [blame] | 179 | if self.testclass_params.get('airplane_mode', 1): |
| 180 | self.log.info('Turning on airplane mode.') |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 181 | asserts.assert_true(utils.force_airplane_mode(self.dut, True), |
| 182 | "Can not turn on airplane mode.") |
Omar El Ayach | 9c56cf3 | 2019-09-19 13:07:51 -0700 | [diff] [blame] | 183 | wutils.wifi_toggle_state(self.dut, True) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 184 | |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 185 | # Configure test retries |
| 186 | self.user_params['retry_tests'] = [self.__class__.__name__] |
| 187 | |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 188 | def teardown_class(self): |
| 189 | # Turn WiFi OFF |
| 190 | for dev in self.android_devices: |
| 191 | wutils.wifi_toggle_state(dev, False) |
| 192 | self.process_testclass_results() |
| 193 | |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 194 | def setup_test(self): |
| 195 | self.retry_flag = False |
| 196 | |
| 197 | def teardown_test(self): |
| 198 | self.retry_flag = False |
| 199 | |
| 200 | def on_retry(self): |
| 201 | """Function to control test logic on retried tests. |
| 202 | |
| 203 | This function is automatically executed on tests that are being |
| 204 | retried. In this case the function resets wifi, toggles it off and on |
| 205 | and sets a retry_flag to enable further tweaking the test logic on |
| 206 | second attempts. |
| 207 | """ |
| 208 | self.retry_flag = True |
| 209 | for dev in self.android_devices: |
| 210 | wutils.reset_wifi(dev) |
| 211 | wutils.toggle_wifi_off_and_on(dev) |
| 212 | |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 213 | def pass_fail_check(self, result): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 214 | """Checks sensitivity against golden results and decides on pass/fail. |
| 215 | |
| 216 | Args: |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 217 | result: dict containing attenuation, throughput and other meta |
Mark De Ruyter | e54396c | 2019-08-20 12:54:37 -0700 | [diff] [blame] | 218 | data |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 219 | """ |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 220 | result_string = ('Throughput = {}%, Sensitivity = {}.'.format( |
| 221 | result['peak_throughput_pct'], result['sensitivity'])) |
Omar El Ayach | e972596 | 2019-09-18 17:30:17 -0700 | [diff] [blame] | 222 | if result['peak_throughput_pct'] < 95: |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 223 | asserts.fail('Result unreliable. {}'.format(result_string)) |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 224 | else: |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 225 | asserts.explicit_pass('Test Passed. {}'.format(result_string)) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 226 | |
| 227 | def process_testclass_results(self): |
| 228 | """Saves and plots test results from all executed test cases.""" |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 229 | # write json output |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 230 | testclass_results_dict = collections.OrderedDict() |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 231 | id_fields = ['mode', 'rate', 'num_streams', 'chain_mask'] |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 232 | channels_tested = [] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 233 | for result in self.testclass_results: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 234 | testcase_params = result['testcase_params'] |
Omar El Ayach | 55f51b5 | 2019-12-06 17:56:23 -0800 | [diff] [blame] | 235 | test_id = self.extract_test_id(testcase_params, id_fields) |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 236 | test_id = tuple(test_id.items()) |
Omar El Ayach | 6e518a2 | 2019-06-13 13:55:42 -0700 | [diff] [blame] | 237 | if test_id not in testclass_results_dict: |
| 238 | testclass_results_dict[test_id] = collections.OrderedDict() |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 239 | channel = testcase_params['channel'] |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 240 | if channel not in channels_tested: |
| 241 | channels_tested.append(channel) |
Omar El Ayach | e972596 | 2019-09-18 17:30:17 -0700 | [diff] [blame] | 242 | if result['peak_throughput_pct'] >= 95: |
Omar El Ayach | 6e518a2 | 2019-06-13 13:55:42 -0700 | [diff] [blame] | 243 | testclass_results_dict[test_id][channel] = result[ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 244 | 'sensitivity'] |
Omar El Ayach | 6e518a2 | 2019-06-13 13:55:42 -0700 | [diff] [blame] | 245 | else: |
| 246 | testclass_results_dict[test_id][channel] = '' |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 247 | |
Omar El Ayach | 55f51b5 | 2019-12-06 17:56:23 -0800 | [diff] [blame] | 248 | # calculate average metrics |
| 249 | metrics_dict = collections.OrderedDict() |
| 250 | id_fields = ['channel', 'mode', 'num_streams', 'chain_mask'] |
Omar El Ayach | cbf6ba9 | 2019-12-07 11:54:06 -0800 | [diff] [blame] | 251 | for test_id in testclass_results_dict.keys(): |
| 252 | for channel in testclass_results_dict[test_id].keys(): |
| 253 | metric_tag = collections.OrderedDict(test_id, channel=channel) |
| 254 | metric_tag = self.extract_test_id(metric_tag, id_fields) |
| 255 | metric_tag = tuple(metric_tag.items()) |
| 256 | metrics_dict.setdefault(metric_tag, []) |
| 257 | sensitivity_result = testclass_results_dict[test_id][channel] |
| 258 | if sensitivity_result != '': |
| 259 | metrics_dict[metric_tag].append(sensitivity_result) |
Omar El Ayach | 55f51b5 | 2019-12-06 17:56:23 -0800 | [diff] [blame] | 260 | for metric_tag_tuple, metric_data in metrics_dict.items(): |
| 261 | metric_tag_dict = collections.OrderedDict(metric_tag_tuple) |
| 262 | metric_tag = 'ch{}_{}_nss{}_chain{}'.format( |
| 263 | metric_tag_dict['channel'], metric_tag_dict['mode'], |
| 264 | metric_tag_dict['num_streams'], metric_tag_dict['chain_mask']) |
| 265 | metric_key = "{}.avg_sensitivity".format(metric_tag) |
| 266 | metric_value = numpy.nanmean(metric_data) |
| 267 | self.testclass_metric_logger.add_metric(metric_key, metric_value) |
| 268 | |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 269 | # write csv |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 270 | csv_header = ['Mode', 'MCS', 'Streams', 'Chain', 'Rate (Mbps)'] |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 271 | for channel in channels_tested: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 272 | csv_header.append('Ch. ' + str(channel)) |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 273 | results_file_path = os.path.join(self.log_path, 'results.csv') |
| 274 | with open(results_file_path, mode='w') as csv_file: |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 275 | writer = csv.DictWriter(csv_file, fieldnames=csv_header) |
| 276 | writer.writeheader() |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 277 | for test_id, test_results in testclass_results_dict.items(): |
| 278 | test_id_dict = dict(test_id) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 279 | if 'legacy' in test_id_dict['mode']: |
| 280 | rate_list = self.VALID_RATES['legacy_2GHz'] |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 281 | else: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 282 | rate_list = self.VALID_RATES[test_id_dict['mode']] |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 283 | data_rate = next(rate.data_rate for rate in rate_list |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 284 | if rate[:-1] == (test_id_dict['rate'], |
| 285 | test_id_dict['num_streams'])) |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 286 | row_value = { |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 287 | 'Mode': test_id_dict['mode'], |
| 288 | 'MCS': test_id_dict['rate'], |
| 289 | 'Streams': test_id_dict['num_streams'], |
| 290 | 'Chain': test_id_dict['chain_mask'], |
| 291 | 'Rate (Mbps)': data_rate, |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 292 | } |
| 293 | for channel in channels_tested: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 294 | row_value['Ch. ' + str(channel)] = test_results.pop( |
| 295 | channel, ' ') |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 296 | writer.writerow(row_value) |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 297 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 298 | if not self.testclass_params['traffic_type'].lower() == 'ping': |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 299 | WifiRvrTest.process_testclass_results(self) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 300 | |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 301 | def process_rvr_test_results(self, testcase_params, rvr_result): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 302 | """Post processes RvR results to compute sensitivity. |
| 303 | |
| 304 | Takes in the results of the RvR tests and computes the sensitivity of |
| 305 | the current rate by looking at the point at which throughput drops |
| 306 | below the percentage specified in the config file. The function then |
| 307 | calls on its parent class process_test_results to plot the result. |
| 308 | |
| 309 | Args: |
| 310 | rvr_result: dict containing attenuation, throughput and other meta |
| 311 | data |
| 312 | """ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 313 | rvr_result['peak_throughput'] = max(rvr_result['throughput_receive']) |
| 314 | rvr_result['peak_throughput_pct'] = 100 |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 315 | throughput_check = [ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 316 | throughput < rvr_result['peak_throughput'] * |
| 317 | (self.testclass_params['throughput_pct_at_sensitivity'] / 100) |
| 318 | for throughput in rvr_result['throughput_receive'] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 319 | ] |
| 320 | consistency_check = [ |
| 321 | idx for idx in range(len(throughput_check)) |
| 322 | if all(throughput_check[idx:]) |
| 323 | ] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 324 | rvr_result['atten_at_range'] = rvr_result['attenuation'][ |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 325 | consistency_check[0] - 1] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 326 | rvr_result['range'] = rvr_result['fixed_attenuation'] + ( |
| 327 | rvr_result['atten_at_range']) |
| 328 | rvr_result['sensitivity'] = self.testclass_params['ap_tx_power'] + ( |
| 329 | self.testbed_params['ap_tx_power_offset'][str( |
| 330 | testcase_params['channel'])] - rvr_result['range']) |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 331 | WifiRvrTest.process_test_results(self, rvr_result) |
| 332 | |
| 333 | def process_ping_test_results(self, testcase_params, ping_result): |
| 334 | """Post processes RvR results to compute sensitivity. |
| 335 | |
| 336 | Takes in the results of the RvR tests and computes the sensitivity of |
| 337 | the current rate by looking at the point at which throughput drops |
| 338 | below the percentage specified in the config file. The function then |
| 339 | calls on its parent class process_test_results to plot the result. |
| 340 | |
| 341 | Args: |
| 342 | rvr_result: dict containing attenuation, throughput and other meta |
| 343 | data |
| 344 | """ |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 345 | WifiPingTest.process_ping_results(self, testcase_params, ping_result) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 346 | ping_result['sensitivity'] = self.testclass_params['ap_tx_power'] + ( |
| 347 | self.testbed_params['ap_tx_power_offset'][str( |
| 348 | testcase_params['channel'])] - ping_result['range']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 349 | |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 350 | def setup_sensitivity_test(self, testcase_params): |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 351 | if testcase_params['traffic_type'].lower() == 'ping': |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 352 | self.setup_ping_test(testcase_params) |
| 353 | self.run_sensitivity_test = self.run_ping_test |
| 354 | self.process_sensitivity_test_results = ( |
| 355 | self.process_ping_test_results) |
| 356 | else: |
| 357 | self.setup_rvr_test(testcase_params) |
| 358 | self.run_sensitivity_test = self.run_rvr_test |
| 359 | self.process_sensitivity_test_results = ( |
| 360 | self.process_rvr_test_results) |
| 361 | |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 362 | def setup_ap(self, testcase_params): |
Omar El Ayach | 5a1496bf | 2019-01-09 11:43:02 -0800 | [diff] [blame] | 363 | """Sets up the AP and attenuator to compensate for AP chain imbalance. |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 364 | |
| 365 | Args: |
| 366 | testcase_params: dict containing AP and other test params |
| 367 | """ |
| 368 | band = self.access_point.band_lookup_by_channel( |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 369 | testcase_params['channel']) |
| 370 | if '2G' in band: |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 371 | frequency = wutils.WifiEnums.channel_2G_to_freq[ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 372 | testcase_params['channel']] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 373 | else: |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 374 | frequency = wutils.WifiEnums.channel_5G_to_freq[ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 375 | testcase_params['channel']] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 376 | if frequency in wutils.WifiEnums.DFS_5G_FREQUENCIES: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 377 | self.access_point.set_region(self.testbed_params['DFS_region']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 378 | else: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 379 | self.access_point.set_region(self.testbed_params['default_region']) |
| 380 | self.access_point.set_channel(band, testcase_params['channel']) |
| 381 | self.access_point.set_bandwidth(band, testcase_params['mode']) |
| 382 | self.access_point.set_power(band, testcase_params['ap_tx_power']) |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 383 | self.access_point.set_rate(band, testcase_params['mode'], |
| 384 | testcase_params['num_streams'], |
| 385 | testcase_params['rate'], |
| 386 | testcase_params['short_gi']) |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 387 | # Set attenuator offsets and set attenuators to initial condition |
| 388 | atten_offsets = self.testbed_params['chain_offset'][str( |
| 389 | testcase_params['channel'])] |
Omar El Ayach | 5a1496bf | 2019-01-09 11:43:02 -0800 | [diff] [blame] | 390 | for atten in self.attenuators: |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 391 | if 'AP-Chain-0' in atten.path: |
| 392 | atten.offset = atten_offsets[0] |
| 393 | elif 'AP-Chain-1' in atten.path: |
| 394 | atten.offset = atten_offsets[1] |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 395 | else: |
| 396 | atten.offset = 0 |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 397 | self.log.info('Access Point Configuration: {}'.format( |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 398 | self.access_point.ap_settings)) |
| 399 | |
Omar El Ayach | 6e518a2 | 2019-06-13 13:55:42 -0700 | [diff] [blame] | 400 | def setup_dut(self, testcase_params): |
| 401 | """Sets up the DUT in the configuration required by the test. |
| 402 | |
| 403 | Args: |
| 404 | testcase_params: dict containing AP and other test params |
| 405 | """ |
Omar El Ayach | 656bf3d | 2019-07-31 15:04:53 -0700 | [diff] [blame] | 406 | # Check battery level before test |
| 407 | if not wputils.health_check(self.dut, 10): |
| 408 | asserts.skip('Battery level too low. Skipping test.') |
| 409 | # Turn screen off to preserve battery |
| 410 | self.dut.go_to_sleep() |
Omar El Ayach | 35bf3b8 | 2019-12-06 19:29:19 -0800 | [diff] [blame] | 411 | if wputils.validate_network(self.dut, |
| 412 | testcase_params['test_network']['SSID']): |
Omar El Ayach | 39acf80 | 2019-08-02 17:52:39 -0700 | [diff] [blame] | 413 | self.log.info('Already connected to desired network') |
| 414 | else: |
| 415 | wutils.reset_wifi(self.dut) |
Roshan Pius | 5b19a12 | 2019-09-13 08:07:30 -0700 | [diff] [blame] | 416 | wutils.set_wifi_country_code(self.dut, |
Omar El Ayach | e5b8be1 | 2019-10-01 16:27:12 -0700 | [diff] [blame] | 417 | self.testclass_params['country_code']) |
Omar El Ayach | c27b7f9 | 2019-12-04 15:46:43 -0800 | [diff] [blame] | 418 | testcase_params['test_network']['channel'] = testcase_params[ |
| 419 | 'channel'] |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 420 | wutils.wifi_connect(self.dut, |
Omar El Ayach | c27b7f9 | 2019-12-04 15:46:43 -0800 | [diff] [blame] | 421 | testcase_params['test_network'], |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 422 | num_of_tries=5, |
| 423 | check_connectivity=False) |
Omar El Ayach | 39acf80 | 2019-08-02 17:52:39 -0700 | [diff] [blame] | 424 | self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0] |
Omar El Ayach | e5b8be1 | 2019-10-01 16:27:12 -0700 | [diff] [blame] | 425 | # Activate/attenuate the correct chains |
Omar El Ayach | 16f5f34 | 2019-11-23 12:27:56 -0800 | [diff] [blame] | 426 | if testcase_params['channel'] not in self.atten_dut_chain_map.keys(): |
| 427 | self.atten_dut_chain_map[testcase_params[ |
| 428 | 'channel']] = wputils.get_current_atten_dut_chain_map( |
| 429 | self.attenuators, self.dut, self.ping_server) |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 430 | self.log.info("Current Attenuator-DUT Chain Map: {}".format( |
| 431 | self.atten_dut_chain_map[testcase_params['channel']])) |
Omar El Ayach | 6e518a2 | 2019-06-13 13:55:42 -0700 | [diff] [blame] | 432 | for idx, atten in enumerate(self.attenuators): |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 433 | if self.atten_dut_chain_map[testcase_params['channel']][ |
| 434 | idx] == testcase_params['attenuated_chain']: |
Omar El Ayach | 6e518a2 | 2019-06-13 13:55:42 -0700 | [diff] [blame] | 435 | atten.offset = atten.instrument.max_atten |
| 436 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 437 | def extract_test_id(self, testcase_params, id_fields): |
| 438 | test_id = collections.OrderedDict( |
| 439 | (param, testcase_params[param]) for param in id_fields) |
| 440 | return test_id |
| 441 | |
| 442 | def get_start_atten(self, testcase_params): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 443 | """Gets the starting attenuation for this sensitivity test. |
| 444 | |
| 445 | The function gets the starting attenuation by checking whether a test |
| 446 | as the next higher MCS has been executed. If so it sets the starting |
| 447 | point a configurable number of dBs below the next MCS's sensitivity. |
| 448 | |
| 449 | Returns: |
| 450 | start_atten: starting attenuation for current test |
| 451 | """ |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 452 | # If the test is being retried, start from the beginning |
| 453 | if self.retry_flag: |
| 454 | self.log.info('Retry flag set. Setting attenuation to minimum.') |
| 455 | return self.testclass_params['atten_start'] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 456 | # Get the current and reference test config. The reference test is the |
| 457 | # one performed at the current MCS+1 |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 458 | current_rate = testcase_params['rate'] |
| 459 | ref_test_params = self.extract_test_id( |
| 460 | testcase_params, |
| 461 | ['channel', 'mode', 'rate', 'num_streams', 'chain_mask']) |
| 462 | if 'legacy' in testcase_params['mode']: |
| 463 | if testcase_params['channel'] <= 13: |
| 464 | rate_list = self.VALID_RATES['legacy_2GHz'] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 465 | else: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 466 | rate_list = self.VALID_RATES['legacy_5GHz'] |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 467 | ref_index = max( |
| 468 | 0, |
| 469 | rate_list.index(self.RateTuple(current_rate, 1, current_rate)) |
| 470 | - 1) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 471 | ref_test_params['rate'] = rate_list[ref_index].mcs |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 472 | else: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 473 | ref_test_params['rate'] = current_rate + 1 |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 474 | |
| 475 | # Check if reference test has been run and set attenuation accordingly |
| 476 | previous_params = [ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 477 | self.extract_test_id( |
| 478 | result['testcase_params'], |
| 479 | ['channel', 'mode', 'rate', 'num_streams', 'chain_mask']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 480 | for result in self.testclass_results |
| 481 | ] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 482 | |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 483 | try: |
| 484 | ref_index = previous_params.index(ref_test_params) |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 485 | start_atten = self.testclass_results[ref_index][ |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 486 | 'atten_at_range'] - ( |
| 487 | self.testclass_params['adjacent_mcs_range_gap']) |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 488 | except ValueError: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 489 | self.log.warning( |
| 490 | 'Reference test not found. Starting from {} dB'.format( |
| 491 | self.testclass_params['atten_start'])) |
| 492 | start_atten = self.testclass_params['atten_start'] |
Omar El Ayach | 49141c0 | 2019-09-16 16:43:51 -0700 | [diff] [blame] | 493 | start_atten = max(start_atten, 0) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 494 | return start_atten |
| 495 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 496 | def compile_test_params(self, testcase_params): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 497 | """Function that generates test params based on the test name.""" |
Omar El Ayach | c27b7f9 | 2019-12-04 15:46:43 -0800 | [diff] [blame] | 498 | band = self.access_point.band_lookup_by_channel( |
| 499 | testcase_params['channel']) |
| 500 | testcase_params['test_network'] = self.main_network[band] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 501 | if testcase_params['chain_mask'] in ['0', '1']: |
| 502 | testcase_params['attenuated_chain'] = 'DUT-Chain-{}'.format( |
| 503 | 1 if testcase_params['chain_mask'] == '0' else 0) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 504 | else: |
Omar El Ayach | df470fb | 2019-09-16 12:22:28 -0700 | [diff] [blame] | 505 | # Set attenuated chain to -1. Do not set to None as this will be |
| 506 | # compared to RF chain map which may include None |
| 507 | testcase_params['attenuated_chain'] = -1 |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 508 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 509 | self.testclass_params[ |
| 510 | 'range_ping_loss_threshold'] = 100 - self.testclass_params[ |
| 511 | 'throughput_pct_at_sensitivity'] |
| 512 | if self.testclass_params['traffic_type'] == 'UDP': |
| 513 | testcase_params['iperf_args'] = '-i 1 -t {} -J -u -b {}'.format( |
| 514 | self.testclass_params['iperf_duration'], |
| 515 | self.testclass_params['UDP_rates'][testcase_params['mode']]) |
| 516 | elif self.testclass_params['traffic_type'] == 'TCP': |
| 517 | testcase_params['iperf_args'] = '-i 1 -t {} -J'.format( |
| 518 | self.testclass_params['iperf_duration']) |
Omar El Ayach | 14416ac | 2019-01-30 14:58:19 -0800 | [diff] [blame] | 519 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 520 | if self.testclass_params['traffic_type'] != 'ping' and isinstance( |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 521 | self.iperf_client, iperf_client.IPerfClientOverAdb): |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 522 | testcase_params['iperf_args'] += ' -R' |
| 523 | testcase_params['use_client_output'] = True |
Omar El Ayach | 14416ac | 2019-01-30 14:58:19 -0800 | [diff] [blame] | 524 | else: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 525 | testcase_params['use_client_output'] = False |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 526 | |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 527 | return testcase_params |
| 528 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 529 | def _test_sensitivity(self, testcase_params): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 530 | """ Function that gets called for each test case |
| 531 | |
| 532 | The function gets called in each rvr test case. The function customizes |
| 533 | the rvr test based on the test name of the test that called it |
| 534 | """ |
| 535 | # Compile test parameters from config and test name |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 536 | testcase_params = self.compile_test_params(testcase_params) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 537 | testcase_params.update(self.testclass_params) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 538 | testcase_params['atten_start'] = self.get_start_atten(testcase_params) |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 539 | num_atten_steps = int( |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 540 | (testcase_params['atten_stop'] - testcase_params['atten_start']) / |
| 541 | testcase_params['atten_step']) |
| 542 | testcase_params['atten_range'] = [ |
| 543 | testcase_params['atten_start'] + x * testcase_params['atten_step'] |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 544 | for x in range(0, num_atten_steps) |
| 545 | ] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 546 | |
| 547 | # Prepare devices and run test |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 548 | self.setup_sensitivity_test(testcase_params) |
| 549 | result = self.run_sensitivity_test(testcase_params) |
| 550 | self.process_sensitivity_test_results(testcase_params, result) |
| 551 | |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 552 | # Post-process results |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 553 | self.testclass_results.append(result) |
| 554 | self.pass_fail_check(result) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 555 | |
Omar El Ayach | ffb5a46 | 2019-09-16 21:05:44 -0700 | [diff] [blame] | 556 | def generate_test_cases(self, channels, modes, chain_mask): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 557 | """Function that auto-generates test cases for a test class.""" |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 558 | test_cases = [] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 559 | for channel in channels: |
Omar El Ayach | cbf6ba9 | 2019-12-07 11:54:06 -0800 | [diff] [blame] | 560 | requested_modes = [ |
| 561 | mode for mode in modes |
| 562 | if mode in self.VALID_TEST_CONFIGS[channel] |
| 563 | ] |
Omar El Ayach | ffb5a46 | 2019-09-16 21:05:44 -0700 | [diff] [blame] | 564 | for mode in requested_modes: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 565 | if 'VHT' in mode: |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 566 | rates = self.VALID_RATES[mode] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 567 | elif 'HT' in mode: |
Omar El Ayach | a210d57 | 2019-03-14 17:31:38 -0700 | [diff] [blame] | 568 | rates = self.VALID_RATES[mode] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 569 | elif 'legacy' in mode and channel < 14: |
| 570 | rates = self.VALID_RATES['legacy_2GHz'] |
| 571 | elif 'legacy' in mode and channel > 14: |
| 572 | rates = self.VALID_RATES['legacy_5GHz'] |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 573 | else: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 574 | raise ValueError('Invalid test mode.') |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 575 | for chain, rate in itertools.product(chain_mask, rates): |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 576 | testcase_params = collections.OrderedDict( |
| 577 | channel=channel, |
| 578 | mode=mode, |
| 579 | rate=rate.mcs, |
| 580 | num_streams=rate.streams, |
| 581 | short_gi=1, |
| 582 | chain_mask=chain) |
| 583 | if chain in ['0', '1'] and rate[1] == 2: |
Omar El Ayach | 96714c8 | 2019-01-28 18:51:46 -0800 | [diff] [blame] | 584 | # Do not test 2-stream rates in single chain mode |
| 585 | continue |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 586 | if 'legacy' in mode: |
| 587 | testcase_name = ('test_sensitivity_ch{}_{}_{}_nss{}' |
| 588 | '_ch{}'.format( |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 589 | channel, mode, |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 590 | str(rate.mcs).replace('.', 'p'), |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 591 | rate.streams, chain)) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 592 | else: |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 593 | testcase_name = ('test_sensitivity_ch{}_{}_mcs{}_nss{}' |
| 594 | '_ch{}'.format( |
Omar El Ayach | 03e4061 | 2019-05-01 16:25:39 -0700 | [diff] [blame] | 595 | channel, mode, rate.mcs, |
| 596 | rate.streams, chain)) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 597 | setattr(self, testcase_name, |
| 598 | partial(self._test_sensitivity, testcase_params)) |
| 599 | test_cases.append(testcase_name) |
Omar El Ayach | ab047c0 | 2019-09-03 11:38:30 -0700 | [diff] [blame] | 600 | return test_cases |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 601 | |
| 602 | |
| 603 | class WifiSensitivity_AllChannels_Test(WifiSensitivityTest): |
| 604 | def __init__(self, controllers): |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 605 | super().__init__(controllers) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 606 | self.tests = self.generate_test_cases( |
Omar El Ayach | ffb5a46 | 2019-09-16 21:05:44 -0700 | [diff] [blame] | 607 | [6, 36, 40, 44, 48, 149, 153, 157, 161], |
| 608 | ['VHT20', 'VHT40', 'VHT80'], ['0', '1', '2x2']) |
Omar El Ayach | 9873c08 | 2019-09-04 12:14:50 -0700 | [diff] [blame] | 609 | |
| 610 | |
| 611 | class WifiSensitivity_SampleChannels_Test(WifiSensitivityTest): |
| 612 | def __init__(self, controllers): |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 613 | super().__init__(controllers) |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 614 | self.tests = self.generate_test_cases([6, 36, 149], |
| 615 | ['VHT20', 'VHT40', 'VHT80'], |
| 616 | ['0', '1', '2x2']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 617 | |
| 618 | |
| 619 | class WifiSensitivity_2GHz_Test(WifiSensitivityTest): |
| 620 | def __init__(self, controllers): |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 621 | super().__init__(controllers) |
Omar El Ayach | e972596 | 2019-09-18 17:30:17 -0700 | [diff] [blame] | 622 | self.tests = self.generate_test_cases([1, 2, 6, 10, 11], ['VHT20'], |
| 623 | ['0', '1', '2x2']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 624 | |
| 625 | |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 626 | class WifiSensitivity_5GHz_Test(WifiSensitivityTest): |
| 627 | def __init__(self, controllers): |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 628 | super().__init__(controllers) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 629 | self.tests = self.generate_test_cases( |
Omar El Ayach | ffb5a46 | 2019-09-16 21:05:44 -0700 | [diff] [blame] | 630 | [36, 40, 44, 48, 149, 153, 157, 161], ['VHT20', 'VHT40', 'VHT80'], |
| 631 | ['0', '1', '2x2']) |
Omar El Ayach | 5fbc122 | 2018-12-07 18:10:05 -0800 | [diff] [blame] | 632 | |
| 633 | |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 634 | class WifiSensitivity_UNII1_Test(WifiSensitivityTest): |
| 635 | def __init__(self, controllers): |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 636 | super().__init__(controllers) |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 637 | self.tests = self.generate_test_cases([36, 40, 44, 48], |
| 638 | ['VHT20', 'VHT40', 'VHT80'], |
| 639 | ['0', '1', '2x2']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 640 | |
| 641 | |
| 642 | class WifiSensitivity_UNII3_Test(WifiSensitivityTest): |
| 643 | def __init__(self, controllers): |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 644 | super().__init__(controllers) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 645 | self.tests = self.generate_test_cases([149, 153, 157, 161], |
Omar El Ayach | ffb5a46 | 2019-09-16 21:05:44 -0700 | [diff] [blame] | 646 | ['VHT20', 'VHT40', 'VHT80'], |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 647 | ['0', '1', '2x2']) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 648 | |
| 649 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 650 | # Over-the air version of senstivity tests |
| 651 | class WifiOtaSensitivityTest(WifiSensitivityTest): |
| 652 | """Class to test over-the-air senstivity. |
| 653 | |
| 654 | This class implements measures WiFi sensitivity tests in an OTA chamber. |
| 655 | It allows setting orientation and other chamber parameters to study |
| 656 | performance in varying channel conditions |
| 657 | """ |
Omar El Ayach | 40099d0 | 2019-09-12 15:17:33 -0700 | [diff] [blame] | 658 | def __init__(self, controllers): |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 659 | base_test.BaseTestClass.__init__(self, controllers) |
| 660 | self.testcase_metric_logger = ( |
Xianyuan Jia | 976d404 | 2019-09-30 17:19:47 -0700 | [diff] [blame] | 661 | BlackboxMappedMetricLogger.for_test_case()) |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 662 | self.testclass_metric_logger = ( |
Xianyuan Jia | 976d404 | 2019-09-30 17:19:47 -0700 | [diff] [blame] | 663 | BlackboxMappedMetricLogger.for_test_class()) |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 664 | self.publish_testcase_metrics = False |
Omar El Ayach | 40099d0 | 2019-09-12 15:17:33 -0700 | [diff] [blame] | 665 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 666 | def setup_class(self): |
| 667 | WifiSensitivityTest.setup_class(self) |
Omar El Ayach | e5b8be1 | 2019-10-01 16:27:12 -0700 | [diff] [blame] | 668 | self.current_chain_mask = '2x2' |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 669 | self.ota_chamber = ota_chamber.create( |
| 670 | self.user_params['OTAChamber'])[0] |
| 671 | |
| 672 | def teardown_class(self): |
| 673 | WifiSensitivityTest.teardown_class(self) |
| 674 | self.ota_chamber.reset_chamber() |
| 675 | |
| 676 | def setup_sensitivity_test(self, testcase_params): |
| 677 | # Setup turntable |
| 678 | self.ota_chamber.set_orientation(testcase_params['orientation']) |
| 679 | # Continue test setup |
| 680 | WifiSensitivityTest.setup_sensitivity_test(self, testcase_params) |
| 681 | |
Omar El Ayach | e5b8be1 | 2019-10-01 16:27:12 -0700 | [diff] [blame] | 682 | def setup_dut(self, testcase_params): |
| 683 | """Sets up the DUT in the configuration required by the test. |
| 684 | |
| 685 | Args: |
| 686 | testcase_params: dict containing AP and other test params |
| 687 | """ |
| 688 | # Configure the right INI settings |
| 689 | if testcase_params['chain_mask'] != self.current_chain_mask: |
| 690 | self.log.info('Updating WiFi chain mask to: {}'.format( |
| 691 | testcase_params['chain_mask'])) |
Omar El Ayach | f7143fc | 2020-02-03 10:15:55 -0800 | [diff] [blame] | 692 | self.current_chain_mask = testcase_params['chain_mask'] |
Omar El Ayach | e5b8be1 | 2019-10-01 16:27:12 -0700 | [diff] [blame] | 693 | if testcase_params['chain_mask'] in ['0', '1']: |
| 694 | wputils.set_ini_single_chain_mode( |
| 695 | self.dut, int(testcase_params['chain_mask'])) |
| 696 | else: |
| 697 | wputils.set_ini_two_chain_mode(self.dut) |
| 698 | # Check battery level before test |
| 699 | if not wputils.health_check(self.dut, 10): |
| 700 | asserts.skip('Battery level too low. Skipping test.') |
| 701 | # Turn screen off to preserve battery |
| 702 | self.dut.go_to_sleep() |
| 703 | if wputils.validate_network(self.dut, |
| 704 | testcase_params['test_network']['SSID']): |
| 705 | self.log.info('Already connected to desired network') |
| 706 | else: |
| 707 | wutils.reset_wifi(self.dut) |
| 708 | wutils.set_wifi_country_code(self.dut, |
| 709 | self.testclass_params['country_code']) |
| 710 | testcase_params['test_network']['channel'] = testcase_params[ |
| 711 | 'channel'] |
| 712 | wutils.wifi_connect(self.dut, |
| 713 | testcase_params['test_network'], |
| 714 | num_of_tries=5, |
| 715 | check_connectivity=False) |
| 716 | self.dut_ip = self.dut.droid.connectivityGetIPv4Addresses('wlan0')[0] |
| 717 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 718 | def process_testclass_results(self): |
| 719 | """Saves and plots test results from all executed test cases.""" |
| 720 | testclass_results_dict = collections.OrderedDict() |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 721 | id_fields = ['channel', 'mode', 'rate'] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 722 | plots = [] |
| 723 | for result in self.testclass_results: |
| 724 | test_id = self.extract_test_id(result['testcase_params'], |
| 725 | id_fields) |
| 726 | test_id = tuple(test_id.items()) |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 727 | chain_mask = result['testcase_params']['chain_mask'] |
| 728 | num_streams = result['testcase_params']['num_streams'] |
| 729 | line_id = (chain_mask, num_streams) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 730 | if test_id not in testclass_results_dict: |
| 731 | testclass_results_dict[test_id] = collections.OrderedDict() |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 732 | if line_id not in testclass_results_dict[test_id]: |
| 733 | testclass_results_dict[test_id][line_id] = { |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 734 | 'orientation': [], |
| 735 | 'sensitivity': [] |
| 736 | } |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 737 | orientation = result['testcase_params']['orientation'] |
Omar El Ayach | e972596 | 2019-09-18 17:30:17 -0700 | [diff] [blame] | 738 | if result['peak_throughput_pct'] >= 95: |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 739 | sensitivity = result['sensitivity'] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 740 | else: |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 741 | sensitivity = float('nan') |
| 742 | if orientation not in testclass_results_dict[test_id][line_id][ |
| 743 | 'orientation']: |
| 744 | testclass_results_dict[test_id][line_id]['orientation'].append( |
| 745 | orientation) |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 746 | testclass_results_dict[test_id][line_id]['sensitivity'].append( |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 747 | sensitivity) |
| 748 | else: |
| 749 | testclass_results_dict[test_id][line_id]['sensitivity'][ |
| 750 | -1] = sensitivity |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 751 | |
| 752 | for test_id, test_data in testclass_results_dict.items(): |
| 753 | test_id_dict = dict(test_id) |
| 754 | if 'legacy' in test_id_dict['mode']: |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 755 | test_id_str = 'Channel {} - {} {}Mbps'.format( |
| 756 | test_id_dict['channel'], test_id_dict['mode'], |
| 757 | test_id_dict['rate']) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 758 | else: |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 759 | test_id_str = 'Channel {} - {} MCS{}'.format( |
| 760 | test_id_dict['channel'], test_id_dict['mode'], |
| 761 | test_id_dict['rate']) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 762 | curr_plot = wputils.BokehFigure( |
| 763 | title=str(test_id_str), |
| 764 | x_label='Orientation (deg)', |
Omar El Ayach | 954eb28 | 2019-09-30 15:33:32 -0700 | [diff] [blame] | 765 | primary_y_label='Sensitivity (dBm)') |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 766 | for line_id, line_results in test_data.items(): |
| 767 | curr_plot.add_line(line_results['orientation'], |
| 768 | line_results['sensitivity'], |
| 769 | legend='Nss{} - Chain Mask {}'.format( |
| 770 | line_id[1], line_id[0]), |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 771 | marker='circle') |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 772 | if 'legacy' in test_id_dict['mode']: |
| 773 | metric_tag = 'ota_summary_ch{}_{}_{}_ch{}'.format( |
| 774 | test_id_dict['channel'], test_id_dict['mode'], |
| 775 | test_id_dict['rate'], line_id[0]) |
| 776 | else: |
| 777 | metric_tag = 'ota_summary_ch{}_{}_mcs{}_nss{}_ch{}'.format( |
| 778 | test_id_dict['channel'], test_id_dict['mode'], |
| 779 | test_id_dict['rate'], line_id[1], line_id[0]) |
| 780 | |
Omar El Ayach | 40099d0 | 2019-09-12 15:17:33 -0700 | [diff] [blame] | 781 | metric_name = metric_tag + '.avg_sensitivity' |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 782 | metric_value = numpy.nanmean(line_results['sensitivity']) |
Omar El Ayach | 02a1cce | 2019-09-19 17:51:39 -0700 | [diff] [blame] | 783 | self.testclass_metric_logger.add_metric( |
| 784 | metric_name, metric_value) |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 785 | self.log.info(("Average Sensitivity for {}: {:.1f}").format( |
Omar El Ayach | e972596 | 2019-09-18 17:30:17 -0700 | [diff] [blame] | 786 | metric_tag, metric_value)) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 787 | current_context = ( |
| 788 | context.get_current_context().get_full_output_path()) |
| 789 | output_file_path = os.path.join(current_context, |
| 790 | str(test_id_str) + '.html') |
| 791 | curr_plot.generate_figure(output_file_path) |
| 792 | plots.append(curr_plot) |
| 793 | output_file_path = os.path.join(current_context, 'results.html') |
| 794 | wputils.BokehFigure.save_figures(plots, output_file_path) |
| 795 | |
| 796 | def get_start_atten(self, testcase_params): |
| 797 | """Gets the starting attenuation for this sensitivity test. |
| 798 | |
| 799 | The function gets the starting attenuation by checking whether a test |
| 800 | at the same rate configuration has executed. If so it sets the starting |
| 801 | point a configurable number of dBs below the reference test. |
| 802 | |
| 803 | Returns: |
| 804 | start_atten: starting attenuation for current test |
| 805 | """ |
Omar El Ayach | 8722206 | 2020-03-25 19:34:12 -0700 | [diff] [blame^] | 806 | # If the test is being retried, start from the beginning |
| 807 | if self.retry_flag: |
| 808 | self.log.info('Retry flag set. Setting attenuation to minimum.') |
| 809 | return self.testclass_params['atten_start'] |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 810 | # Get the current and reference test config. The reference test is the |
| 811 | # one performed at the current MCS+1 |
| 812 | ref_test_params = self.extract_test_id( |
| 813 | testcase_params, |
| 814 | ['channel', 'mode', 'rate', 'num_streams', 'chain_mask']) |
| 815 | # Check if reference test has been run and set attenuation accordingly |
| 816 | previous_params = [ |
| 817 | self.extract_test_id( |
| 818 | result['testcase_params'], |
| 819 | ['channel', 'mode', 'rate', 'num_streams', 'chain_mask']) |
| 820 | for result in self.testclass_results |
| 821 | ] |
| 822 | try: |
| 823 | ref_index = previous_params[::-1].index(ref_test_params) |
| 824 | ref_index = len(previous_params) - 1 - ref_index |
| 825 | start_atten = self.testclass_results[ref_index][ |
| 826 | 'atten_at_range'] - ( |
| 827 | self.testclass_params['adjacent_mcs_range_gap']) |
| 828 | except ValueError: |
| 829 | print('Reference test not found. Starting from {} dB'.format( |
| 830 | self.testclass_params['atten_start'])) |
| 831 | start_atten = self.testclass_params['atten_start'] |
Omar El Ayach | e972596 | 2019-09-18 17:30:17 -0700 | [diff] [blame] | 832 | start_atten = max(start_atten, 0) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 833 | return start_atten |
| 834 | |
Omar El Ayach | ffb5a46 | 2019-09-16 21:05:44 -0700 | [diff] [blame] | 835 | def generate_test_cases(self, channels, modes, requested_rates, chain_mask, |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 836 | angles): |
| 837 | """Function that auto-generates test cases for a test class.""" |
| 838 | test_cases = [] |
| 839 | for channel in channels: |
Omar El Ayach | cbf6ba9 | 2019-12-07 11:54:06 -0800 | [diff] [blame] | 840 | requested_modes = [ |
| 841 | mode for mode in modes |
| 842 | if mode in self.VALID_TEST_CONFIGS[channel] |
| 843 | ] |
Omar El Ayach | eacef87 | 2020-01-31 16:22:28 -0800 | [diff] [blame] | 844 | for chain, mode in itertools.product(chain_mask, requested_modes): |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 845 | if 'VHT' in mode: |
| 846 | valid_rates = self.VALID_RATES[mode] |
| 847 | elif 'HT' in mode: |
| 848 | valid_rates = self.VALID_RATES[mode] |
| 849 | elif 'legacy' in mode and channel < 14: |
| 850 | valid_rates = self.VALID_RATES['legacy_2GHz'] |
| 851 | elif 'legacy' in mode and channel > 14: |
| 852 | valid_rates = self.VALID_RATES['legacy_5GHz'] |
| 853 | else: |
| 854 | raise ValueError('Invalid test mode.') |
Omar El Ayach | eacef87 | 2020-01-31 16:22:28 -0800 | [diff] [blame] | 855 | for rate, angle in itertools.product(valid_rates, angles): |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 856 | testcase_params = collections.OrderedDict( |
| 857 | channel=channel, |
| 858 | mode=mode, |
| 859 | rate=rate.mcs, |
| 860 | num_streams=rate.streams, |
| 861 | short_gi=1, |
| 862 | chain_mask=chain, |
| 863 | orientation=angle) |
| 864 | if rate not in requested_rates: |
| 865 | continue |
| 866 | if str(chain) in ['0', '1'] and rate[1] == 2: |
| 867 | # Do not test 2-stream rates in single chain mode |
| 868 | continue |
| 869 | if 'legacy' in mode: |
| 870 | testcase_name = ('test_sensitivity_ch{}_{}_{}_nss{}' |
| 871 | '_ch{}_{}deg'.format( |
| 872 | channel, mode, |
| 873 | str(rate.mcs).replace('.', 'p'), |
| 874 | rate.streams, chain, angle)) |
| 875 | else: |
| 876 | testcase_name = ('test_sensitivity_ch{}_{}_mcs{}_nss{}' |
| 877 | '_ch{}_{}deg'.format( |
| 878 | channel, mode, rate.mcs, |
| 879 | rate.streams, chain, angle)) |
| 880 | setattr(self, testcase_name, |
| 881 | partial(self._test_sensitivity, testcase_params)) |
| 882 | test_cases.append(testcase_name) |
Omar El Ayach | f2f99c3 | 2019-09-16 17:18:45 -0700 | [diff] [blame] | 883 | return test_cases |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 884 | |
| 885 | |
Omar El Ayach | a8ed99f | 2019-09-18 13:41:58 -0700 | [diff] [blame] | 886 | class WifiOtaSensitivity_TenDegree_Test(WifiOtaSensitivityTest): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 887 | def __init__(self, controllers): |
Omar El Ayach | 40099d0 | 2019-09-12 15:17:33 -0700 | [diff] [blame] | 888 | WifiOtaSensitivityTest.__init__(self, controllers) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 889 | requested_channels = [6, 36, 149] |
| 890 | requested_rates = [ |
| 891 | self.RateTuple(8, 1, 86.7), |
Omar El Ayach | d9024eb | 2019-09-16 18:22:46 -0700 | [diff] [blame] | 892 | self.RateTuple(2, 1, 21.7), |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 893 | self.RateTuple(8, 2, 173.3), |
Omar El Ayach | d9024eb | 2019-09-16 18:22:46 -0700 | [diff] [blame] | 894 | self.RateTuple(2, 2, 43.3) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 895 | ] |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 896 | self.tests = self.generate_test_cases(requested_channels, |
| 897 | ['VHT20', 'VHT80'], |
| 898 | requested_rates, ['2x2'], |
| 899 | list(range(0, 360, 10))) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 900 | |
| 901 | |
Omar El Ayach | e5b8be1 | 2019-10-01 16:27:12 -0700 | [diff] [blame] | 902 | class WifiOtaSensitivity_PerChain_TenDegree_Test(WifiOtaSensitivityTest): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 903 | def __init__(self, controllers): |
Omar El Ayach | 40099d0 | 2019-09-12 15:17:33 -0700 | [diff] [blame] | 904 | WifiOtaSensitivityTest.__init__(self, controllers) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 905 | requested_channels = [6, 36, 149] |
Omar El Ayach | 2711426 | 2020-02-06 15:30:08 -0800 | [diff] [blame] | 906 | requested_rates = [ |
| 907 | self.RateTuple(2, 1, 21.7), |
| 908 | self.RateTuple(2, 2, 43.3) |
| 909 | ] |
Omar El Ayach | e5b8be1 | 2019-10-01 16:27:12 -0700 | [diff] [blame] | 910 | self.tests = self.generate_test_cases(requested_channels, ['VHT20'], |
| 911 | requested_rates, |
| 912 | ['0', '1', '2x2'], |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 913 | list(range(0, 360, 10))) |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 914 | |
| 915 | |
Omar El Ayach | d3850d0 | 2019-09-23 16:35:49 -0700 | [diff] [blame] | 916 | class WifiOtaSensitivity_ThirtyDegree_Test(WifiOtaSensitivityTest): |
| 917 | def __init__(self, controllers): |
| 918 | WifiOtaSensitivityTest.__init__(self, controllers) |
| 919 | requested_channels = [6, 36, 149] |
| 920 | requested_rates = [ |
| 921 | self.RateTuple(9, 1, 96), |
| 922 | self.RateTuple(8, 1, 86.7), |
| 923 | self.RateTuple(7, 1, 72.2), |
| 924 | self.RateTuple(4, 1, 43.3), |
| 925 | self.RateTuple(2, 1, 21.7), |
| 926 | self.RateTuple(0, 1, 7.2), |
| 927 | self.RateTuple(9, 2, 192), |
| 928 | self.RateTuple(8, 2, 173.3), |
| 929 | self.RateTuple(7, 2, 144.4), |
| 930 | self.RateTuple(4, 2, 86.7), |
| 931 | self.RateTuple(2, 2, 43.3), |
| 932 | self.RateTuple(0, 2, 14.4) |
| 933 | ] |
Omar El Ayach | a218f6b | 2019-11-22 18:24:48 -0800 | [diff] [blame] | 934 | self.tests = self.generate_test_cases(requested_channels, |
| 935 | ['VHT20', 'VHT80'], |
| 936 | requested_rates, ['2x2'], |
| 937 | list(range(0, 360, 30))) |
Omar El Ayach | d3850d0 | 2019-09-23 16:35:49 -0700 | [diff] [blame] | 938 | |
| 939 | |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 940 | class WifiOtaSensitivity_45Degree_Test(WifiOtaSensitivityTest): |
Omar El Ayach | 33f80c0 | 2018-09-27 15:02:03 -0700 | [diff] [blame] | 941 | def __init__(self, controllers): |
Omar El Ayach | 40099d0 | 2019-09-12 15:17:33 -0700 | [diff] [blame] | 942 | WifiOtaSensitivityTest.__init__(self, controllers) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 943 | requested_rates = [ |
| 944 | self.RateTuple(8, 1, 86.7), |
Omar El Ayach | d9024eb | 2019-09-16 18:22:46 -0700 | [diff] [blame] | 945 | self.RateTuple(2, 1, 21.7), |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 946 | self.RateTuple(8, 2, 173.3), |
Omar El Ayach | d9024eb | 2019-09-16 18:22:46 -0700 | [diff] [blame] | 947 | self.RateTuple(2, 2, 43.3) |
Omar El Ayach | bbc6a0a | 2019-07-22 10:26:11 -0700 | [diff] [blame] | 948 | ] |
| 949 | self.tests = self.generate_test_cases( |
Omar El Ayach | ffb5a46 | 2019-09-16 21:05:44 -0700 | [diff] [blame] | 950 | [1, 6, 11, 36, 40, 44, 48, 149, 153, 157, 161], ['VHT20', 'VHT80'], |
| 951 | requested_rates, ['2x2'], list(range(0, 360, 45))) |