Merge "Fixing a typo in band channel mapping dictionary" am: b539d870a6 am: 7f1ad160da

Original change: https://android-review.googlesource.com/c/platform/tools/test/connectivity/+/2032274

Change-Id: I75d9d06be4cc0e580a836142b94fbb993018c254
diff --git a/acts_tests/tests/google/wifi/WifiBtStressCoexTest.py b/acts_tests/tests/google/wifi/WifiBtStressCoexTest.py
new file mode 100644
index 0000000..84d026f
--- /dev/null
+++ b/acts_tests/tests/google/wifi/WifiBtStressCoexTest.py
@@ -0,0 +1,247 @@
+#!/usr/bin/env python3.4
+#
+#   Copyright 2018 - The Android Open Source Project
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+import pprint
+import queue
+import threading
+import time
+
+import acts.base_test
+import acts_contrib.test_utils.wifi.wifi_test_utils as wutils
+import acts_contrib.test_utils.tel.tel_test_utils as tutils
+
+from acts import asserts
+from acts import signals
+from acts import utils
+from acts.test_decorators import test_tracker_info
+from acts_contrib.test_utils.bt.bt_test_utils import enable_bluetooth
+from acts_contrib.test_utils.bt.bt_test_utils import pair_pri_to_sec
+from acts_contrib.test_utils.bt.bt_test_utils import factory_reset_bluetooth
+from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
+from acts_contrib.test_utils.tel.tel_test_utils import WIFI_CONFIG_APBAND_5G
+WifiEnums = wutils.WifiEnums
+
+WAIT_FOR_AUTO_CONNECT = 40
+WAIT_BEFORE_CONNECTION = 30
+DEFAULT_TIMEOUT = 10
+PING_ADDR = 'www.google.com'
+BAND_2GHZ = 0
+BAND_5GHZ = 1
+WIFI_NETWORK_AP_CHANNEL_2G = 1
+WIFI_NETWORK_AP_CHANNEL_5G = 36
+
+class WifiBtStressCoexTest(WifiBaseTest):
+    """WiFi BT Coex Stress test class.
+
+    Test Bed Requirement:
+    * Two Android device
+    * One Android device with simulator BT branch code
+    * Several Wi-Fi networks visible to the device, including an open Wi-Fi
+      network.
+    """
+    def __init__(self, configs):
+        super().__init__(configs)
+        self.enable_packet_log = True
+
+    def setup_class(self):
+        super().setup_class()
+
+        self.dut = self.android_devices[0]
+        if len(self.android_devices) > 1:
+            self.dut_client = self.android_devices[1]
+            self.headset = self.android_devices[2]
+        else:
+            self.dut_client = None
+        wutils.wifi_test_device_init(self.dut)
+        req_params = []
+        opt_param = [
+            "open_network", "reference_networks", "iperf_server_address",
+            "stress_count", "stress_hours", "attn_vals", "pno_interval",
+            "iperf_server_port"]
+        self.unpack_userparams(
+            req_param_names=req_params, opt_param_names=opt_param)
+
+        if "AccessPoint" in self.user_params:
+            self.legacy_configure_ap_and_start(ap_count=2)
+        elif "OpenWrtAP" in self.user_params:
+            self.configure_openwrt_ap_and_start(open_network=True,
+                                                wpa_network=True,
+                                                ap_count=2)
+        asserts.assert_true(
+            len(self.reference_networks) > 0,
+            "Need at least one reference network with psk.")
+        self.wpa_2g = self.reference_networks[0]["2g"]
+        self.wpa_5g = self.reference_networks[0]["5g"]
+        self.open_2g = self.open_network[0]["2g"]
+        self.open_5g = self.open_network[0]["5g"]
+        self.networks = [self.wpa_2g, self.wpa_5g, self.open_2g, self.open_5g]
+
+    def setup_test(self):
+        super().setup_test()
+        self.dut.droid.wakeLockAcquireBright()
+        self.dut.droid.wakeUpNow()
+
+    def teardown_test(self):
+        super().teardown_test()
+        if self.dut.droid.wifiIsApEnabled():
+            wutils.stop_wifi_tethering(self.dut)
+        self.dut.droid.wakeLockRelease()
+        self.dut.droid.goToSleepNow()
+        wutils.reset_wifi(self.dut)
+        factory_reset_bluetooth([self.dut, self.headset])
+
+    def teardown_class(self):
+        wutils.reset_wifi(self.dut)
+        if "AccessPoint" in self.user_params:
+            del self.user_params["reference_networks"]
+            del self.user_params["open_network"]
+
+    """Helper Functions"""
+
+    def scan_and_connect_by_ssid(self, ad, network):
+        """Scan for network and connect using network information.
+
+        Args:
+            network: A dictionary representing the network to connect to.
+
+        """
+        ssid = network[WifiEnums.SSID_KEY]
+        wutils.start_wifi_connection_scan_and_ensure_network_found(ad, ssid)
+        wutils.wifi_connect(ad, network, num_of_tries=3)
+
+    def scan_and_connect_by_id(self, network, net_id):
+        """Scan for network and connect using network id.
+
+        Args:
+            net_id: Integer specifying the network id of the network.
+
+        """
+        ssid = network[WifiEnums.SSID_KEY]
+        wutils.start_wifi_connection_scan_and_ensure_network_found(self.dut,
+            ssid)
+        wutils.wifi_connect_by_id(self.dut, net_id)
+
+    def run_ping(self, sec):
+        """Run ping for given number of seconds.
+
+        Args:
+            sec: Time in seconds to run the ping traffic.
+
+        """
+        self.log.info("Running ping for %d seconds" % sec)
+        result = self.dut.adb.shell("ping -w %d %s" %(sec, PING_ADDR),
+            timeout=sec+1)
+        self.log.debug("Ping Result = %s" % result)
+        if "100% packet loss" in result:
+            raise signals.TestFailure("100% packet loss during ping")
+
+    def create_softap_config(self):
+        """Create a softap config with ssid and password."""
+        ap_ssid = "softap_" + utils.rand_ascii_str(8)
+        ap_password = utils.rand_ascii_str(8)
+        self.dut.log.info("softap setup: %s %s", ap_ssid, ap_password)
+        config = {wutils.WifiEnums.SSID_KEY: ap_ssid}
+        config[wutils.WifiEnums.PWD_KEY] = ap_password
+        return config
+
+    def start_softap_and_verify(self, band, check_connectivity=True):
+        """Test startup of softap.
+
+        1. Bring up AP mode.
+        2. Verify SoftAP active using the client device.
+
+        Args:
+            band: wifi band to start soft ap on
+            check_connectivity: If set, verify internet connectivity
+
+        Returns:
+            config
+        """
+        config = self.create_softap_config()
+        wutils.start_wifi_tethering(self.dut,
+                                    config[WifiEnums.SSID_KEY],
+                                    config[WifiEnums.PWD_KEY],
+                                    band)
+        for ad in self.android_devices[1:]:
+            wutils.connect_to_wifi_network(
+                ad, config, check_connectivity=check_connectivity)
+        return config
+
+    def verify_softap_full_on_off(self, network, softap_band):
+        """Bring up AP mode and verify ap mode
+
+        Args:
+            softap_band: wifi band to start soft ap on
+            network: android_device to connect ap with security type
+
+        """
+        self.start_softap_and_verify(softap_band)
+        wutils.stop_wifi_tethering(self.dut)
+
+    def connect_BT_paired(self, dut, headset):
+        """Start to pairing the simulator BT device.
+
+        Args:
+            dut: Android device initiating connection
+            headset: Android device accepting connection
+
+        """
+        enable_bluetooth(dut.droid, dut.ed)
+        enable_bluetooth(headset.droid, headset.ed)
+        time.sleep(DEFAULT_TIMEOUT)
+        pair_pri_to_sec(dut, headset)
+
+    """Tests"""
+
+    @test_tracker_info(uuid="4bacb48d-1e31-4561-b7b3-8e86478a82b3")
+    def test_wifi_on_off_with_2g(self):
+        """Test wifi on/off state by connection to 2G network followed
+           with BT paired.
+        """
+        wutils.wifi_toggle_state(self.dut, True)
+        self.scan_and_connect_by_ssid(self.dut, self.wpa_2g)
+        self.connect_BT_paired(self.dut, self.headset)
+        time.sleep(5)
+        for count in range(self.stress_count):
+            """Test toggling wifi"""
+            try:
+                self.log.debug("Going from on to off.")
+                wutils.wifi_toggle_state(self.dut, False)
+                self.log.debug("Going from off to on.")
+                startTime = time.time()
+                wutils.wifi_toggle_state(self.dut, True)
+                startup_time = time.time() - startTime
+                self.log.debug("WiFi was enabled on the device in %s s." %
+                    startup_time)
+            except:
+                raise signals.TestFailure(details="", extras={"Iterations":"%d" %
+                    self.stress_count, "Pass":"%d" %count})
+        raise signals.TestPass(details="", extras={"Iterations":"%d" %
+            self.stress_count, "Pass":"%d" %(count+1)})
+
+    @test_tracker_info(uuid="cc132d79-d0ea-4f99-ba6f-0f6fbd21eba0")
+    def test_2g_sta_mode_and_hotspot_5g_on_off_stress_bt_paired(self):
+        """Tests connection to 2G network followed by SoftAp on 5G
+           with BT paired.
+        """
+        wutils.wifi_toggle_state(self.dut, True)
+        self.scan_and_connect_by_ssid(self.dut, self.open_2g)
+        self.connect_BT_paired(self.dut, self.headset)
+        time.sleep(5)
+        for count in range(self.stress_count):
+            """Test toggling softap"""
+            self.log.info("Iteration %d", count+1)
+            self.verify_softap_full_on_off(self.open_2g, WIFI_CONFIG_APBAND_5G)
diff --git a/acts_tests/tests/google/wifi/WifiCountrySoftApAcsTest.py b/acts_tests/tests/google/wifi/WifiCountrySoftApAcsTest.py
index 3422167..128bb83 100644
--- a/acts_tests/tests/google/wifi/WifiCountrySoftApAcsTest.py
+++ b/acts_tests/tests/google/wifi/WifiCountrySoftApAcsTest.py
@@ -298,6 +298,7 @@
 
         Returns: List of string; contains failure messages.
          """
+        self.init_softap_band = init_softap_band
         # Set a country code to the DUT.
         self.set_country_code_and_verify(self.dut, country)
         # Get DUT STA frequency.
diff --git a/acts_tests/tests/google/wifi/WifiPnoTest.py b/acts_tests/tests/google/wifi/WifiPnoTest.py
index d93fa45..5378b8f 100644
--- a/acts_tests/tests/google/wifi/WifiPnoTest.py
+++ b/acts_tests/tests/google/wifi/WifiPnoTest.py
@@ -62,6 +62,9 @@
         self.dut.droid.goToSleepNow()
         wutils.reset_wifi(self.dut)
         self.dut.ed.clear_all_events()
+        # DUT to the saved networks so they won't be excluded from PNO scan.
+        wutils.connect_to_wifi_network(self.dut, self.pno_network_a)
+        wutils.connect_to_wifi_network(self.dut, self.pno_network_b)
 
     def teardown_test(self):
         super().teardown_test()
@@ -197,9 +200,6 @@
         self.add_network_and_enable(self.pno_network_b)
         # Force single scan so that both networks become preferred before PNO.
         wutils.start_wifi_connection_scan_and_return_status(self.dut)
-        self.dut.droid.goToSleepNow()
-        wutils.wifi_toggle_state(self.dut, False)
-        wutils.wifi_toggle_state(self.dut, True)
         time.sleep(10)
         self.trigger_pno_and_assert_connect("b_on_a_off", self.pno_network_b)
 
diff --git a/acts_tests/tests/google/wifi/WifiTeleCoexTest.py b/acts_tests/tests/google/wifi/WifiTeleCoexTest.py
index 02e9541..f509dea 100644
--- a/acts_tests/tests/google/wifi/WifiTeleCoexTest.py
+++ b/acts_tests/tests/google/wifi/WifiTeleCoexTest.py
@@ -4,6 +4,7 @@
 import time
 
 import acts.base_test
+import acts_contrib.test_utils.tel.tel_wifi_utils
 import acts_contrib.test_utils.wifi.wifi_test_utils as wifi_utils
 import acts_contrib.test_utils.tel.tel_test_utils as tele_utils
 import acts_contrib.test_utils.tel.tel_mms_utils as mms_utils
@@ -224,7 +225,7 @@
             return False
         tele_utils.toggle_airplane_mode(self.log, self.android_devices[0],
                              is_airplane_mode)
-        if not tele_utils.ensure_wifi_connected(self.log, self.android_devices[0],
+        if not tel_wifi_utils.ensure_wifi_connected(self.log, self.android_devices[0],
                                      self.wifi_network_ssid,
                                      self.wifi_network_pass):
             self.log.error("{} connect WiFI failed".format(
diff --git a/acts_tests/tests/google/wifi/WifiWpa3AutoUpdateTest.py b/acts_tests/tests/google/wifi/WifiWpa3AutoUpdateTest.py
index 60d8ebb..6ce5e35 100644
--- a/acts_tests/tests/google/wifi/WifiWpa3AutoUpdateTest.py
+++ b/acts_tests/tests/google/wifi/WifiWpa3AutoUpdateTest.py
@@ -115,7 +115,8 @@
     @WifiBaseTest.wifi_test_wrap
     def test_check_wpa3_wifi_state_after_au(self):
         """Check if the state of WiFi is enabled after Auto-update."""
-        super().test_check_wifi_state_after_au()
+        if not self.dut.droid.wifiCheckState():
+            raise signals.TestFailure("WiFi is disabled after Auto-update!!!")
 
     @test_tracker_info(uuid="4dd106b0-6390-47d2-9b6d-00f21a0535f1")
     @WifiBaseTest.wifi_test_wrap
@@ -126,7 +127,7 @@
                Number of networs should be the same and match each network.
 
         """
-        super().test_verify_networks_after_au()
+        self.check_networks_after_autoupdate(self.wifi_config_list)
 
     @test_tracker_info(uuid="4e5107d1-17cc-4c4d-aee5-38052dec5ddd")
     @WifiBaseTest.wifi_test_wrap
@@ -175,8 +176,10 @@
                1. Connect to a wpa3 network.
                2. Forget ntworks added in 1.
         """
-        super().test_connection_to_new_networks()
-
+        for network in self.new_networks:
+            wutils.connect_to_wifi_network(self.dut, network)
+        for network in self.new_networks:
+            wutils.wifi_forget_network(self.dut, network[SSID])
 
     @test_tracker_info(uuid="542a39c3-eea0-445c-89ae-8c74c6afb0bf")
     @WifiBaseTest.wifi_test_wrap
@@ -186,16 +189,25 @@
            Steps:
                1. Connect to previously added wpa3 network using network id.
         """
-        super().test_all_networks_connectable_after_au()
+        network = self.wifi_config_list[0]
+        if not wutils.connect_to_wifi_network_with_id(self.dut,
+                                                      network[NETID],
+                                                      network[SSID]):
+            raise signals.TestFailure("Failed to connect to %s after OTA" %
+                                      network[SSID])
+        wutils.wifi_forget_network(self.dut, network[SSID])
 
     @test_tracker_info(uuid="68a34667-aca2-4630-b2fa-c25f1d234a92")
     @WifiBaseTest.wifi_test_wrap
     def test_check_wpa3_wifi_toggling_after_au(self):
         """Check if WiFi can be toggled ON/OFF after auto-update."""
-        super().test_check_wifi_toggling_after_au()
+        self.log.debug("Going from on to off.")
+        wutils.wifi_toggle_state(self.dut, False)
+        self.log.debug("Going from off to on.")
+        wutils.wifi_toggle_state(self.dut, True)
 
     @test_tracker_info(uuid="39ba98de-cb49-4475-a218-7470122af885")
     @WifiBaseTest.wifi_test_wrap
     def test_reset_wpa3_wifi_after_au(self):
         """"Check if WiFi can be reset after auto-update."""
-        super().test_reset_wifi_after_au()
+        wutils.reset_wifi(self.dut)
diff --git a/acts_tests/tests/google/wifi/aware/functional/NonConcurrencyTest.py b/acts_tests/tests/google/wifi/aware/functional/NonConcurrencyTest.py
index 1c27ab8..b012cc2 100644
--- a/acts_tests/tests/google/wifi/aware/functional/NonConcurrencyTest.py
+++ b/acts_tests/tests/google/wifi/aware/functional/NonConcurrencyTest.py
@@ -226,6 +226,10 @@
     def test_run_aware_then_softap(self):
         """Validate that a running Aware session terminates when softAp is
     started"""
+        #Adding dbs support verifying before test start
+        asserts.skip_if(
+            self.android_devices[0].model not in self.dbs_supported_models,
+            "Device %s doesn't support STA+AP." % self.android_devices[0].model)
         self.run_aware_then_incompat_service(is_p2p=False)
 
     @test_tracker_info(uuid="2ac27ac6-8010-4d05-b892-00242420b075")