• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 time
18from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_2G
19from acts.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
20from acts.test_utils.wifi import wifi_test_utils as wutils
21from PowerTelTrafficTest import PowerTelTrafficTest
22
23
24class PowerTelHotspotTest(PowerTelTrafficTest):
25    """ Cellular traffic over WiFi tethering power test.
26
27    Treated as a different case of data traffic. Inherits from
28    PowerTelTrafficTest and only needs to make a change in the measurement step.
29    """
30
31    # Class config parameters
32    CONFIG_KEY_WIFI = 'hotspot_network'
33
34    # Test name configuration keywords
35    PARAM_WIFI_BAND = "wifiband"
36    PARAM_2G_BAND = "2g"
37    PARAM_5G_BAND = "5g"
38
39    def __init__(self, controllers):
40        """ Class initialization
41
42        Set attributes to default values.
43        """
44
45        super().__init__(controllers)
46
47        # Initialize values
48        self.wifi_band = None
49        self.iperf_results = None
50
51    def setup_class(self):
52        """ Executed before any test case is started.
53
54        Set country code for client and host devices.
55
56        """
57
58        if not super().setup_class():
59            return False
60
61        # If an SSID and password are indicated in the configuration parameters,
62        # use those. If not, use default parameters and warn the user.
63
64        if hasattr(self, self.CONFIG_KEY_WIFI):
65
66            self.network = getattr(self, self.CONFIG_KEY_WIFI)
67
68            if not (wutils.WifiEnums.SSID_KEY in self.network
69                    and wutils.WifiEnums.PWD_KEY in self.network):
70                raise RuntimeError(
71                    "The '{}' key in the configuration file needs"
72                    " to contain the '{}' and '{}' fields.".format(
73                        self.CONFIG_KEY_WIFI, wutils.WifiEnums.SSID_KEY,
74                        wutils.WifiEnums.PWD_KEY))
75        else:
76
77            self.log.warning(
78                "The configuration file doesn't indicate an SSID "
79                "password for the hotspot. Using default values. "
80                "To configured the SSID and pwd include a the key"
81                " {} containing the '{}' and '{}' fields.".format(
82                    self.CONFIG_KEY_WIFI,
83                    wutils.WifiEnums.SSID_KEY,
84                    wutils.WifiEnums.PWD_KEY))
85
86            self.network = {
87                wutils.WifiEnums.SSID_KEY: "Pixel_1030",
88                wutils.WifiEnums.PWD_KEY: "1234567890"
89            }
90
91        # Both devices need to have a country code in order
92        # to use the 5 GHz band.
93        self.android_devices[0].droid.wifiSetCountryCode('US')
94        self.android_devices[1].droid.wifiSetCountryCode('US')
95
96    def power_tel_tethering_test(self):
97        """ Measure power and throughput during data transmission.
98
99        Starts WiFi tethering in the DUT and connects a second device. Then
100        the iPerf client is hosted in the second android device.
101
102        """
103
104        # Setup tethering
105        wutils.start_wifi_tethering(
106            self.dut, self.network[wutils.WifiEnums.SSID_KEY],
107            self.network[wutils.WifiEnums.PWD_KEY], self.wifi_band)
108
109        wutils.wifi_connect(
110            self.android_devices[1], self.network, check_connectivity=False)
111
112        # Start data traffic
113        iperf_helpers = self.start_tel_traffic(self.android_devices[1])
114
115        # Measure power
116        self.collect_power_data()
117
118        # Wait for iPerf to finish
119        time.sleep(self.IPERF_MARGIN + 2)
120
121        # Collect throughput measurement
122        self.iperf_results = self.get_iperf_results(self.android_devices[1],
123                                                    iperf_helpers)
124
125        # Checks if power is below the required threshold.
126        self.pass_fail_check()
127
128    def setup_test(self):
129        """ Executed before every test case.
130
131        Parses test configuration from the test name and prepares
132        the simulation for measurement.
133        """
134
135        # Call parent method first to setup simulation
136        if not super().setup_test():
137            return False
138
139        try:
140            values = self.consume_parameter(self.PARAM_WIFI_BAND, 1)
141
142            if values[1] == self.PARAM_2G_BAND:
143                self.wifi_band = WIFI_CONFIG_APBAND_2G
144            elif values[1] == self.PARAM_5G_BAND:
145                self.wifi_band = WIFI_CONFIG_APBAND_5G
146            else:
147                raise ValueError()
148        except:
149            self.log.error(
150                "The test name has to include parameter {} followed by "
151                "either {} or {}.".
152                format(self.PARAM_WIFI_BAND, self.PARAM_2G_BAND,
153                       self.PARAM_5G_BAND))
154            return False
155
156        return True
157