1#!/usr/bin/env python3.4 2# 3# Copyright 2018 - 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 17import acts.test_utils.power.PowerBaseTest as PBT 18from acts.test_utils.wifi import wifi_power_test_utils as wputils 19 20IPERF_DURATION = 'iperf_duration' 21 22 23class PowerWiFiBaseTest(PBT.PowerBaseTest): 24 """Base class for WiFi power related tests. 25 26 Inherited from the PowerBaseTest class 27 """ 28 29 def setup_class(self): 30 31 super().setup_class() 32 if hasattr(self, 'access_points'): 33 self.access_point = self.access_points[0] 34 self.access_point_main = self.access_points[0] 35 if len(self.access_points) > 1: 36 self.access_point_aux = self.access_points[1] 37 self.networks = self.unpack_custom_file(self.network_file, False) 38 self.main_network = self.networks['main_network'] 39 self.aux_network = self.networks['aux_network'] 40 if hasattr(self, 'packet_senders'): 41 self.pkt_sender = self.packet_senders[0] 42 if hasattr(self, 'iperf_servers'): 43 self.iperf_server = self.iperf_servers[0] 44 if hasattr(self, 'iperf_duration'): 45 self.mon_duration = self.iperf_duration - 10 46 self.create_monsoon_info() 47 48 def teardown_test(self): 49 """Tear down necessary objects after test case is finished. 50 51 Bring down the AP interface, delete the bridge interface, stop the 52 packet sender, and reset the ethernet interface for the packet sender 53 """ 54 super().teardown_test() 55 if hasattr(self, 'pkt_sender'): 56 self.pkt_sender.stop_sending(ignore_status=True) 57 if hasattr(self, 'brconfigs'): 58 self.access_point.bridge.teardown(self.brconfigs) 59 delattr(self, 'brconfigs') 60 if hasattr(self, 'brconfigs_main'): 61 self.access_point_main.bridge.teardown(self.brconfigs_main) 62 delattr(self, 'brconfigs_main') 63 if hasattr(self, 'brconfigs_aux'): 64 self.access_point_aux.bridge.teardown(self.brconfigs_aux) 65 delattr(self, 'brconfigs_aux') 66 if hasattr(self, 'access_points'): 67 for ap in self.access_points: 68 ap.close() 69 if hasattr(self, 'pkt_sender'): 70 wputils.reset_host_interface(self.pkt_sender.interface) 71 if hasattr(self, 'iperf_server'): 72 self.iperf_server.stop() 73 74 def teardown_class(self): 75 """Clean up the test class after tests finish running 76 77 """ 78 super().teardown_class() 79 if hasattr(self, 'access_points'): 80 for ap in self.access_points: 81 ap.close() 82 83 def collect_power_data(self): 84 """Measure power, plot and check pass/fail. 85 86 If IPERF is run, need to pull iperf results and attach it to the plot. 87 """ 88 super().collect_power_data() 89 tag = '' 90 if hasattr(self, IPERF_DURATION): 91 throughput = self.process_iperf_results() 92 tag = '_RSSI_{0:d}dBm_Throughput_{1:.2f}Mbps'.format( 93 self.RSSI, throughput) 94 wputils.monsoon_data_plot(self.mon_info, self.file_path, tag=tag) 95