blob: 1a31894d7661aa2762d4ca5d9826e26b515ec238 [file] [log] [blame]
Alfie Chen0e932be2020-02-19 00:36:00 +08001#!/usr/bin/env python3
2#
3# Copyright 2020 - 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
18import random
19import re
20import acts.test_utils.wifi.wifi_test_utils as wutils
21import acts.test_utils.tel.tel_test_utils as tel_utils
22import acts.utils as utils
23from acts import asserts
24from acts.test_decorators import test_tracker_info
25from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest
26from acts import signals
27
28
29WifiEnums = wutils.WifiEnums
30
31
32class WifiChannelSwitchStressTest(WifiBaseTest):
33
34 def setup_class(self):
35 super().setup_class()
36 self.dut = self.android_devices[0]
37 self.dut_client = self.android_devices[1]
38 utils.require_sl4a((self.dut, self.dut_client))
39
40 req_params = ["dbs_supported_models"]
41 opt_param = ["stress_count"]
42 self.unpack_userparams(
43 req_param_names=req_params, opt_param_names=opt_param)
44
45 self.AP_IFACE = 'wlan0'
46 if self.dut.model in self.dbs_supported_models:
47 self.AP_IFACE = 'wlan1'
48
49 for ad in self.android_devices:
50 wutils.wifi_test_device_init(ad)
51 utils.sync_device_time(ad)
52 ad.droid.wifiSetCountryCode(wutils.WifiEnums.CountryCode.US)
53
54 def setup_test(self):
55 for ad in self.android_devices:
56 ad.droid.wakeLockAcquireBright()
57 ad.droid.wakeUpNow()
58
59 def teardown_test(self):
60 for ad in self.android_devices:
61 ad.droid.wakeLockRelease()
62 ad.droid.goToSleepNow()
63 wutils.reset_wifi(ad)
64 try:
65 wutils.stop_wifi_tethering(self.dut)
66 except signals.TestFailure:
67 pass
68
69 def on_fail(self, test_name, begin_time):
70 for ad in self.android_devices:
71 ad.take_bug_report(test_name, begin_time)
72 ad.cat_adb_log(test_name, begin_time)
73
74 def check_cell_data_and_enable(self):
75 """Make sure that cell data is enabled if there is a sim present.
76
77 If a sim is active, cell data needs to be enabled to allow provisioning
78 checks through (when applicable). This is done to relax hardware
79 requirements on DUTs - without this check, running this set of tests
80 after other wifi tests may cause failures.
81 """
82
83 if not self.dut.droid.telephonyIsDataEnabled():
84 self.dut.log.info("need to enable data")
85 self.dut.droid.telephonyToggleDataConnection(True)
86 asserts.assert_true(self.dut.droid.telephonyIsDataEnabled(),
87 "Failed to enable cell data for dut.")
88
89 def get_wlan0_link(self, dut):
90 get_wlan0 = 'wpa_cli -iwlan0 -g@android:wpa_wlan0 IFNAME=wlan0 status'
91 out = dut.adb.shell(get_wlan0)
92 out = dict(re.findall(r'(\S+)=(".*?"|\S+)', out))
93 asserts.assert_true("ssid" in out,
94 "Client doesn't connect to any network")
95 return out
96
97 def generate_random_list(self, lst):
98 """Generate a list where
99 the previous and subsequent items
100 do not repeat"""
101
102 channel_list = []
103 num = random.choice(lst)
104 channel_list.append(num)
105 for i in range(1, self.stress_count):
106 num = random.choice(lst)
107 while num == channel_list[-1]:
108 num = random.choice(lst)
109 channel_list.append(num)
110 return channel_list
111
112 @test_tracker_info(uuid="3411cb7c-2609-433a-97b6-202a096dc71b")
113 def test_softap_channel_switch_stress_5g(self):
114 """
115 1. Disable DUT's Wi-Fi
116 2. Enable CLIENT's Wi-Fi
117 3. Check DUT's sim is ready or not
118 4. Enable DUT's mobile data
119 5. Bring up DUT's softap in 5g
120 6. CLIENT connect to DUT
121 7. DUT switch to different 5g channel
122 8. Verify CLIENT follow the change
123 9, Repeat step 7 and 8
124 """
125
126 config = wutils.create_softap_config()
127 wutils.wifi_toggle_state(self.dut_client, True)
128 init_wifi_state = self.dut.droid.wifiCheckState()
129 init_sim_state = tel_utils.is_sim_ready(self.log, self.dut)
130 self.dut.log.info("initial wifi state = {}".format(init_wifi_state))
131 self.dut.log.info("initial sim state = {}".format(init_sim_state))
132 if init_sim_state:
133 self.check_cell_data_and_enable()
134 wutils.start_wifi_tethering(self.dut,
135 config[wutils.WifiEnums.SSID_KEY],
136 config[wutils.WifiEnums.PWD_KEY],
137 WifiEnums.WIFI_CONFIG_APBAND_5G)
138 wutils.connect_to_wifi_network(self.dut_client, config)
139 channel_list = self.generate_random_list(
140 WifiEnums.NONE_DFS_5G_FREQUENCIES)
141 self.log.info("channel_list = {}".format(channel_list))
142 for count in range(len(channel_list)):
143 self.log.info("iteration : {}".format(count))
144 self.dut.log.info('hotspot 5g channel switch START')
145 channel_5g = channel_list[count]
146 hotspot_5g_channel_switch_cmd = (
147 'hostapd_cli -i {} chan_switch 10 {}'.format(self.AP_IFACE,
148 channel_5g))
149 self.dut.adb.shell(hotspot_5g_channel_switch_cmd)
150 self.dut.log.info('softap frequency : {}'.format(channel_5g))
151 time.sleep(30)
152 client_frequency = int(self.get_wlan0_link(self.dut_client)["freq"])
153 self.dut_client.log.info(
154 "client frequency : {}".format(client_frequency))
155 asserts.assert_true(
156 channel_5g == client_frequency,
157 "hotspot frequency != client frequency")