blob: 167e73f61a49a64da58014139ac52173b7e467f4 [file] [log] [blame]
Tom Turney35d297e2018-05-11 13:37:41 -07001#!/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 if hasattr(self, 'brconfigs_main'):
60 self.access_point_main.bridge.teardown(self.brconfigs_main)
61 if hasattr(self, 'brconfigs_aux'):
62 self.access_point_aux.bridge.teardown(self.brconfigs_aux)
63 if hasattr(self, 'access_points'):
64 for ap in self.access_points:
65 ap.close()
66 if hasattr(self, 'pkt_sender'):
67 wputils.reset_host_interface(self.pkt_sender.interface)
68 if hasattr(self, 'iperf_server'):
69 self.iperf_server.stop()
70
71 def teardown_class(self):
72 """Clean up the test class after tests finish running
73
74 """
75 super().teardown_class()
76 if hasattr(self, 'access_points'):
77 for ap in self.access_points:
78 ap.close()
79
80 def collect_power_data(self):
81 """Measure power, plot and check pass/fail.
82
83 If IPERF is run, need to pull iperf results and attach it to the plot.
84 """
85 super().collect_power_data()
86 tag = ''
87 if hasattr(self, IPERF_DURATION):
88 throughput = self.process_iperf_results()
89 tag = '_RSSI_{0:d}dBm_Throughput_{1:.2f}Mbps'.format(
90 self.RSSI, throughput)
91 wputils.monsoon_data_plot(self.mon_info, self.file_path, tag=tag)