Merge "[AWARE] Fix race condition between Responder and Initiator" into pi-dev
diff --git a/acts/framework/acts/asserts.py b/acts/framework/acts/asserts.py
index 939ff9c..5046b3b 100644
--- a/acts/framework/acts/asserts.py
+++ b/acts/framework/acts/asserts.py
@@ -44,6 +44,7 @@
         extras: An optional field for extra information to be included in
                 test result.
     """
+    my_msg = None
     try:
         _pyunit_proxy.assertEqual(first, second)
     except Exception as e:
@@ -55,6 +56,8 @@
         my_msg = str(e)
         if msg:
             my_msg = "%s %s" % (my_msg, msg)
+    # This is a hack to remove the stacktrace produced by the above exception.
+    if my_msg is not None:
         fail(my_msg, extras=extras)
 
 
@@ -75,6 +78,7 @@
     :param extras: Extra object passed to test failure handler
     :return:
     """
+    my_msg = None
     try:
         if delta:
             _pyunit_proxy.assertAlmostEqual(
@@ -86,6 +90,8 @@
         my_msg = str(e)
         if msg:
             my_msg = "%s %s" % (my_msg, msg)
+    # This is a hack to remove the stacktrace produced by the above exception.
+    if my_msg is not None:
         fail(my_msg, extras=extras)
 
 
diff --git a/acts/framework/acts/base_test.py b/acts/framework/acts/base_test.py
index f66058a..3dc8797 100755
--- a/acts/framework/acts/base_test.py
+++ b/acts/framework/acts/base_test.py
@@ -16,14 +16,15 @@
 import logging
 import os
 import traceback
+from concurrent.futures import ThreadPoolExecutor
 
 from acts import asserts
+from acts import keys
 from acts import logger
 from acts import records
 from acts import signals
 from acts import tracelogger
 from acts import utils
-from concurrent.futures import ThreadPoolExecutor
 
 # Macro strings for test result reporting
 TEST_CASE_TOKEN = "[Test Case]"
@@ -400,7 +401,11 @@
                     tr_record.add_error("teardown_test", e)
                     self._exec_procedure_func(self._on_exception, tr_record)
         except (signals.TestFailure, AssertionError) as e:
-            self.log.error(e)
+            if self.user_params.get(
+                    keys.Config.key_test_failure_tracebacks.value, False):
+                self.log.exception(e)
+            else:
+                self.log.error(e)
             tr_record.test_fail(e)
             self._exec_procedure_func(self._on_fail, tr_record)
         except signals.TestSkip as e:
@@ -500,10 +505,10 @@
 
             if format_args:
                 self.exec_one_testcase(test_name, test_func,
-                                       args + (setting, ), **kwargs)
+                                       args + (setting,), **kwargs)
             else:
                 self.exec_one_testcase(test_name, test_func,
-                                       (setting, ) + args, **kwargs)
+                                       (setting,) + args, **kwargs)
 
             if len(self.results.passed) - previous_success_cnt != 1:
                 failed_settings.append(setting)
diff --git a/acts/framework/acts/config_parser.py b/acts/framework/acts/config_parser.py
index ac6380e..498ce38 100755
--- a/acts/framework/acts/config_parser.py
+++ b/acts/framework/acts/config_parser.py
@@ -25,7 +25,8 @@
 
 # An environment variable defining the base location for ACTS logs.
 _ENV_ACTS_LOGPATH = 'ACTS_LOGPATH'
-
+# An environment variable that enables test case failures to log stack traces.
+_ENV_TEST_FAILURE_TRACEBACKS = 'ACTS_TEST_FAILURE_TRACEBACKS'
 # An environment variable defining the test search paths for ACTS.
 _ENV_ACTS_TESTPATHS = 'ACTS_TESTPATHS'
 _PATH_SEPARATOR = ':'
@@ -284,6 +285,10 @@
               (os.environ[_ENV_ACTS_TESTPATHS]))
         configs[keys.Config.key_test_paths.value] = os.environ[
             _ENV_ACTS_TESTPATHS].split(_PATH_SEPARATOR)
+    if (keys.Config.key_test_failure_tracebacks not in configs
+            and _ENV_TEST_FAILURE_TRACEBACKS in os.environ):
+        configs[keys.Config.key_test_failure_tracebacks.value] = os.environ[
+            _ENV_TEST_FAILURE_TRACEBACKS]
 
     # Add the global paths to the global config.
     k_log_path = keys.Config.key_log_path.value
diff --git a/acts/framework/acts/controllers/access_point.py b/acts/framework/acts/controllers/access_point.py
index d293ec6..f537bc8 100755
--- a/acts/framework/acts/controllers/access_point.py
+++ b/acts/framework/acts/controllers/access_point.py
@@ -145,8 +145,11 @@
         Bring down hostapd if instance is running, bring down all bridge
         interfaces.
         """
-        # Stop hostapd instance if running
         try:
+            # This is necessary for Gale/Whirlwind flashed with dev channel image
+            # Unused interfaces such as existing hostapd daemon, guest, mesh
+            # interfaces need to be brought down as part of the AP initialization
+            # process, otherwise test would fail.
             try:
                 self.ssh.run('stop hostapd')
             except job.Error:
diff --git a/acts/framework/acts/keys.py b/acts/framework/acts/keys.py
index 083d44c..526ef71 100644
--- a/acts/framework/acts/keys.py
+++ b/acts/framework/acts/keys.py
@@ -35,6 +35,7 @@
     key_address = "Address"
     key_random = "random"
     key_test_case_iterations = "test_case_iterations"
+    key_test_failure_tracebacks = "test_failure_tracebacks"
     # Config names for controllers packaged in ACTS.
     key_android_device = "AndroidDevice"
     key_chameleon_device = "ChameleonDevice"
diff --git a/acts/framework/acts/test_utils/bt/bt_contacts_utils.py b/acts/framework/acts/test_utils/bt/bt_contacts_utils.py
index ccebdbf..91d37cc 100644
--- a/acts/framework/acts/test_utils/bt/bt_contacts_utils.py
+++ b/acts/framework/acts/test_utils/bt/bt_contacts_utils.py
@@ -1,4 +1,4 @@
-#/usr/bin/env python3.4
+# /usr/bin/env python3.4
 #
 # Copyright (C) 2016 The Android Open Source Project
 #
@@ -24,7 +24,7 @@
 import re
 import random
 import string
-
+from time import sleep
 from acts.utils import exe_cmd
 import queue
 
@@ -283,6 +283,10 @@
     phone_phonebook_path = "{}{}".format(STORAGE_PATH, vcf_file)
     device.adb.push("{} {}".format(local_phonebook_path, phone_phonebook_path))
     device.droid.importVcf("file://{}{}".format(STORAGE_PATH, vcf_file))
+    # keyevent to allow contacts import from vcf file
+    sleep(1)
+    for key in ["ENTER", "DPAD_RIGHT", "ENTER"]:
+        device.adb.shell("input keyevent KEYCODE_{}".format(key))
     if wait_for_phone_number_update_complete(device, number_count):
         return number_count
     else:
@@ -299,6 +303,15 @@
     return True
 
 
+def delete_vcf_files(device):
+    """Deletes all files with .vcf extension
+    """
+    files = device.adb.shell("ls {}".format(STORAGE_PATH))
+    for file_name in files.split():
+        if ".vcf" in file_name:
+            device.adb.shell("rm -f {}{}".format(STORAGE_PATH, file_name))
+
+
 def erase_contacts(device):
     """Erase all contacts out of devices contact database.
     """
@@ -379,8 +392,8 @@
         for i in range(len(pse_call_log)):
             # Compare the phone number
             if normalize_phonenumber(pse_call_log[i][
-                    "number"]) != normalize_phonenumber(pce_call_log[i][
-                        "number"]):
+                                         "number"]) != normalize_phonenumber(pce_call_log[i][
+                                                                                 "number"]):
                 log.warning("Call Log numbers differ")
                 call_logs_match = False
 
@@ -391,7 +404,7 @@
 
             # Compare time to truncated second.
             if int(pse_call_log[i]["date"]) // 1000 != int(pce_call_log[i][
-                    "date"]) // 1000:
+                                                               "date"]) // 1000:
                 log.warning("Call log times don't match, check timezone.")
                 call_logs_match = False
 
diff --git a/acts/framework/acts/test_utils/wifi/WifiBaseTest.py b/acts/framework/acts/test_utils/wifi/WifiBaseTest.py
index 95c7b95..edf1bfa 100755
--- a/acts/framework/acts/test_utils/wifi/WifiBaseTest.py
+++ b/acts/framework/acts/test_utils/wifi/WifiBaseTest.py
@@ -13,21 +13,14 @@
 #   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.
-"""
-    Base Class for Defining Common WiFi Test Functionality
-"""
+"""Base Class for Defining Common WiFi Test Functionality"""
 
 import copy
 import itertools
-import time
-
-import acts.controllers.access_point as ap
 
 from acts import asserts
 from acts import utils
 from acts.base_test import BaseTestClass
-from acts.signals import TestSignal
-from acts.controllers import android_device
 from acts.controllers.ap_lib import hostapd_ap_preset
 from acts.controllers.ap_lib import hostapd_bss_settings
 from acts.controllers.ap_lib import hostapd_constants
@@ -76,19 +69,19 @@
         ref_5g_passphrase = utils.rand_ascii_str(passphrase_length_5g)
 
         if hidden:
-           network_dict_2g = {
-              "SSID": ref_2g_ssid,
-              "security": ref_2g_security,
-              "password": ref_2g_passphrase,
-              "hiddenSSID": true
-           }
+            network_dict_2g = {
+                "SSID": ref_2g_ssid,
+                "security": ref_2g_security,
+                "password": ref_2g_passphrase,
+                "hiddenSSID": True
+            }
 
-           network_dict_5g = {
-              "SSID": ref_5g_ssid,
-              "security": ref_5g_security,
-              "password": ref_5g_passphrase,
-              "hiddenSSID": true
-           }
+            network_dict_5g = {
+                "SSID": ref_5g_ssid,
+                "security": ref_5g_security,
+                "password": ref_5g_passphrase,
+                "hiddenSSID": True
+            }
         else:
             network_dict_2g = {
                 "SSID": ref_2g_ssid,
@@ -105,10 +98,8 @@
         ap = 0
         for ap in range(ap_count):
             self.user_params["reference_networks"].append({
-                "2g":
-                copy.copy(network_dict_2g),
-                "5g":
-                copy.copy(network_dict_5g)
+                "2g": copy.copy(network_dict_2g),
+                "5g": copy.copy(network_dict_5g)
             })
         self.reference_networks = self.user_params["reference_networks"]
         return {"2g": network_dict_2g, "5g": network_dict_5g}
@@ -136,15 +127,15 @@
         open_5g_ssid = '5g_%s' % utils.rand_ascii_str(ssid_length_5g)
         if hidden:
             network_dict_2g = {
-            "SSID": open_2g_ssid,
-            "security": 'none',
-            "hiddenSSID": true
+                "SSID": open_2g_ssid,
+                "security": 'none',
+                "hiddenSSID": True
             }
 
             network_dict_5g = {
-            "SSID": open_5g_ssid,
-            "security": 'none',
-            "hiddenSSID": true
+                "SSID": open_5g_ssid,
+                "security": 'none',
+                "hiddenSSID": True
             }
         else:
             network_dict_2g = {
@@ -166,21 +157,21 @@
         self.open_network = self.user_params["open_network"]
         return {"2g": network_dict_2g, "5g": network_dict_5g}
 
-    def populate_bssid(self, ap_instance, ap, networks_5g, networks_2g):
+    def populate_bssid(self, ap_instance, ap, networks_2g, networks_5g):
         """Get bssid for a given SSID and add it to the network dictionary.
 
         Args:
             ap_instance: Accesspoint index that was configured.
             ap: Accesspoint object corresponding to ap_instance.
-            networks_5g: List of 5g networks configured on the APs.
             networks_2g: List of 2g networks configured on the APs.
+            networks_5g: List of 5g networks configured on the APs.
 
         """
 
-        if not (networks_5g or networks_2g):
+        if not (networks_2g or networks_5g):
             return
 
-        for network in itertools.chain(networks_5g, networks_2g):
+        for network in itertools.chain(networks_2g, networks_5g):
             if 'channel' in network:
                 continue
             bssid = ap.get_bssid_from_ssid(network["SSID"])
@@ -189,7 +180,7 @@
             else:
                 band = hostapd_constants.BAND_5G
             if network["security"] == hostapd_constants.WPA2_STRING:
-                # TODO:(bamahadev) Change all occurances of reference_networks
+                # TODO:(bamahadev) Change all occurrences of reference_networks
                 # to wpa_networks.
                 self.reference_networks[ap_instance][band]["bssid"] = bssid
             else:
@@ -197,21 +188,14 @@
 
     def legacy_configure_ap_and_start(
             self,
-            channel_5g=hostapd_constants.AP_DEFAULT_CHANNEL_5G,
             channel_2g=hostapd_constants.AP_DEFAULT_CHANNEL_2G,
-            max_2g_networks=hostapd_constants.AP_DEFAULT_MAX_SSIDS_2G,
-            max_5g_networks=hostapd_constants.AP_DEFAULT_MAX_SSIDS_5G,
-            ap_ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G,
-            ap_passphrase_length_2g=hostapd_constants.AP_PASSPHRASE_LENGTH_2G,
-            ap_ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G,
-            ap_passphrase_length_5g=hostapd_constants.AP_PASSPHRASE_LENGTH_5G,
-            hidden=False,
+            channel_5g=hostapd_constants.AP_DEFAULT_CHANNEL_5G,
             ap_count=1):
         asserts.assert_true(
             len(self.user_params["AccessPoint"]) == 2,
-            "Exactly two access points must be specified. \
-             Each access point has 2 radios, one each for 2.4GHZ \
-             and 5GHz. A test can choose to use one or both APs.")
+            "Exactly two access points must be specified. "
+            "Each access point has 2 radios, one each for 2.4GHZ "
+            "and 5GHz. A test can choose to use one or both APs.")
         network_list_2g = []
         network_list_5g = []
         network_list_2g.append({"channel": channel_2g})
@@ -234,16 +218,17 @@
         orig_network_list_5g = copy.copy(network_list_5g)
         orig_network_list_2g = copy.copy(network_list_2g)
 
-        if len(network_list_5g) > 1:
-            self.config_5g = self._generate_legacy_ap_config(network_list_5g)
         if len(network_list_2g) > 1:
             self.config_2g = self._generate_legacy_ap_config(network_list_2g)
+        if len(network_list_5g) > 1:
+            self.config_5g = self._generate_legacy_ap_config(network_list_5g)
         ap = 0
         for ap in range(ap_count):
             self.access_points[ap].start_ap(self.config_2g)
             self.access_points[ap].start_ap(self.config_5g)
-            self.populate_bssid(ap, self.access_points[ap], orig_network_list_5g,
-                                orig_network_list_2g)
+            self.populate_bssid(ap, self.access_points[ap],
+                                orig_network_list_2g,
+                                orig_network_list_5g)
 
     def _generate_legacy_ap_config(self, network_list):
         bss_settings = []
diff --git a/acts/framework/acts/test_utils/wifi/aware/AwareBaseTest.py b/acts/framework/acts/test_utils/wifi/aware/AwareBaseTest.py
index 1e8f9d0..c928acf 100644
--- a/acts/framework/acts/test_utils/wifi/aware/AwareBaseTest.py
+++ b/acts/framework/acts/test_utils/wifi/aware/AwareBaseTest.py
@@ -56,6 +56,9 @@
       self.set_power_mode_parameters(ad)
       utils.set_regulatory_domain(ad, "US")
       autils.configure_ndp_allow_any_override(ad, True)
+      # set randomization interval to 0 (disable) to reduce likelihood of
+      # interference in tests
+      autils.configure_mac_random_interval(ad, 0)
 
   def teardown_test(self):
     for ad in self.android_devices:
diff --git a/acts/framework/acts/test_utils/wifi/aware/aware_test_utils.py b/acts/framework/acts/test_utils/wifi/aware/aware_test_utils.py
index 4be392e..05ba784 100644
--- a/acts/framework/acts/test_utils/wifi/aware/aware_test_utils.py
+++ b/acts/framework/acts/test_utils/wifi/aware/aware_test_utils.py
@@ -404,6 +404,18 @@
   device.adb.shell(
     "cmd wifiaware native_api set-power %s %s %d" % (mode, name, value))
 
+def configure_mac_random_interval(device, interval_sec):
+  """Use the command-line API to configure the MAC address randomization
+  interval.
+
+  Args:
+    device: Device on which to perform configuration
+    interval_sec: The MAC randomization interval in seconds. A value of 0
+                  disables all randomization.
+  """
+  device.adb.shell(
+    "cmd wifiaware native_api set mac_random_interval_sec %d" % interval_sec)
+
 def configure_ndp_allow_any_override(device, override_api_check):
   """Use the command-line API to configure whether an NDP Responder may be
   configured to accept an NDP request from ANY peer.
diff --git a/acts/tests/google/bt/car_bt/BtCarPbapTest.py b/acts/tests/google/bt/car_bt/BtCarPbapTest.py
index bc1b930..a3ae194 100644
--- a/acts/tests/google/bt/car_bt/BtCarPbapTest.py
+++ b/acts/tests/google/bt/car_bt/BtCarPbapTest.py
@@ -1,4 +1,4 @@
-#/usr/bin/env python3.4
+# /usr/bin/env python3.4
 #
 # Copyright (C) 2016 The Android Open Source Project
 #
@@ -55,12 +55,10 @@
             "android.permission.WRITE_CONTACTS",
             "android.permission.READ_EXTERNAL_STORAGE"
         ]
-        for permission in permissions_list:
-            self.pse.adb.shell(
-                "pm grant com.google.android.contacts {}".format(permission))
-        for permission in permissions_list:
-            self.pce.adb.shell("pm grant com.android.contacts {}".format(
-                permission))
+        for device in [self.pce, self.pse, self.pse2]:
+            for permission in permissions_list:
+                device.adb.shell(
+                    "pm grant com.google.android.contacts {}".format(permission))
 
         # Pair the devices.
         # This call may block until some specified timeout in bt_test_utils.py.
@@ -115,6 +113,9 @@
     def teardown_test(self):
         if not super(BtCarPbapTest, self).teardown_test():
             return False
+        for device in [self.pce, self.pse, self.pse2]:
+            bt_contacts_utils.delete_vcf_files(device)
+
         self.pce.droid.bluetoothPbapClientDisconnect(
             self.pse.droid.bluetoothGetLocalAddress())
         bt_contacts_utils.erase_contacts(self.pse)
@@ -214,6 +215,8 @@
                                                 PSE_CONTACTS_FILE, 100)
         phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
             self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
+
+        bt_test_utils.reset_bluetooth([self.pce])
         bt_test_utils.connect_pri_to_sec(
             self.pce, self.pse,
             set([BtEnum.BluetoothProfile.PBAP_CLIENT.value]))
@@ -249,6 +252,7 @@
                                                 PSE_CONTACTS_FILE, 100)
         phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
             self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
+        bt_test_utils.reset_bluetooth([self.pce])
         if not self.connect_and_verify(phone_numbers_added):
             return False
 
@@ -257,6 +261,7 @@
                                                 PSE_CONTACTS_FILE, 110, 2)
         phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
             self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
+        bt_test_utils.reset_bluetooth([self.pce])
         return self.connect_and_verify(phone_numbers_added)
 
     @test_tracker_info(uuid='bbe31bf5-51e8-4175-b266-1c7750e44f5b')
@@ -330,7 +335,7 @@
 
         phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
             self.pse, self.contacts_destination_path, PSE_CONTACTS_FILE)
-
+        bt_test_utils.reset_bluetooth([self.pce])
         return self.connect_and_verify(phone_numbers_added)
 
     @test_tracker_info(uuid='2aa2bd00-86cc-4f39-a06a-90b17ea5b320')
@@ -432,13 +437,16 @@
 
         bt_contacts_utils.generate_contact_list(self.contacts_destination_path,
                                                 PSE1_CONTACTS_FILE, 100)
-        phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
-            self.pse, self.contacts_destination_path, PSE1_CONTACTS_FILE)
+        phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(self.pse,
+                                                                                self.contacts_destination_path,
+                                                                                PSE1_CONTACTS_FILE)
         bt_contacts_utils.generate_contact_list(self.contacts_destination_path,
                                                 PSE2_CONTACTS_FILE, 100)
-        phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(
-            self.pse2, self.contacts_destination_path, PSE2_CONTACTS_FILE)
+        phone_numbers_added = bt_contacts_utils.import_device_contacts_from_vcf(self.pse2,
+                                                                                self.contacts_destination_path,
+                                                                                PSE2_CONTACTS_FILE)
 
+        bt_test_utils.reset_bluetooth([self.pce])
         self.pce.droid.bluetoothPbapClientDisconnect(
             self.pse.droid.bluetoothGetLocalAddress())
         self.pce.droid.bluetoothPbapClientDisconnect(
diff --git a/acts/tests/google/power/bt/PowerBTbaselineTest.py b/acts/tests/google/power/bt/PowerBTbaselineTest.py
index 89eceaa..c8305d6 100644
--- a/acts/tests/google/power/bt/PowerBTbaselineTest.py
+++ b/acts/tests/google/power/bt/PowerBTbaselineTest.py
@@ -44,7 +44,7 @@
         self.mon.attach_device(self.dut)
         self.mon_info = wputils.create_monsoon_info(self)
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
         self.threshold = wputils.unpack_custom_file(self.threshold_file,
                                                     self.TAG)
diff --git a/acts/tests/google/power/bt/PowerBTscanTest.py b/acts/tests/google/power/bt/PowerBTscanTest.py
index 59818e1..49d0641 100644
--- a/acts/tests/google/power/bt/PowerBTscanTest.py
+++ b/acts/tests/google/power/bt/PowerBTscanTest.py
@@ -45,7 +45,7 @@
         self.mon.attach_device(self.dut)
         self.mon_info = wputils.create_monsoon_info(self)
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
         self.threshold = wputils.unpack_custom_file(self.threshold_file,
                                                     self.TAG)
diff --git a/acts/tests/google/power/coex/PowerCoexBaseTest.py b/acts/tests/google/power/coex/PowerCoexBaseTest.py
index d4cae36..f89b81f 100644
--- a/acts/tests/google/power/coex/PowerCoexBaseTest.py
+++ b/acts/tests/google/power/coex/PowerCoexBaseTest.py
@@ -45,7 +45,7 @@
         self.mon_info = wputils.create_monsoon_info(self)
         self.num_atten = self.attenuators[0].instrument.num_atten
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
             elif 'attenuator_setting' in file:
                 self.attenuation_file = file
diff --git a/acts/tests/google/power/coex/PowerCoexScanTest.py b/acts/tests/google/power/coex/PowerCoexScanTest.py
index 210b5a9..4bb80d7 100644
--- a/acts/tests/google/power/coex/PowerCoexScanTest.py
+++ b/acts/tests/google/power/coex/PowerCoexScanTest.py
@@ -49,7 +49,7 @@
         self.mon_info = wputils.create_monsoon_info(self)
         self.num_atten = self.attenuators[0].instrument.num_atten
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
             elif 'attenuator_setting' in file:
                 self.attenuation_file = file
diff --git a/acts/tests/google/power/wifi/PowerbaselineTest.py b/acts/tests/google/power/wifi/PowerbaselineTest.py
index f74f639..eaa852a 100644
--- a/acts/tests/google/power/wifi/PowerbaselineTest.py
+++ b/acts/tests/google/power/wifi/PowerbaselineTest.py
@@ -47,7 +47,7 @@
         self.mon.attach_device(self.dut)
         self.mon_info = wputils.create_monsoon_info(self)
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
         self.threshold = wputils.unpack_custom_file(self.threshold_file,
                                                     self.TAG)
diff --git a/acts/tests/google/power/wifi/PowerdtimTest.py b/acts/tests/google/power/wifi/PowerdtimTest.py
index 1a91e95..14efa44 100644
--- a/acts/tests/google/power/wifi/PowerdtimTest.py
+++ b/acts/tests/google/power/wifi/PowerdtimTest.py
@@ -46,7 +46,7 @@
         self.mon_info = wputils.create_monsoon_info(self)
         self.num_atten = self.attenuators[0].instrument.num_atten
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
             elif 'attenuator_setting' in file:
                 self.attenuation_file = file
diff --git a/acts/tests/google/power/wifi/PowermulticastTest.py b/acts/tests/google/power/wifi/PowermulticastTest.py
index 52dea86..c0b0d4c 100644
--- a/acts/tests/google/power/wifi/PowermulticastTest.py
+++ b/acts/tests/google/power/wifi/PowermulticastTest.py
@@ -54,7 +54,7 @@
         self.mon_info = wputils.create_monsoon_info(self)
         self.pkt_sender = self.packet_senders[0]
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
             elif 'attenuator_setting' in file:
                 self.attenuation_file = file
diff --git a/acts/tests/google/power/wifi/PowerroamingTest.py b/acts/tests/google/power/wifi/PowerroamingTest.py
index 1b71583..811e372 100644
--- a/acts/tests/google/power/wifi/PowerroamingTest.py
+++ b/acts/tests/google/power/wifi/PowerroamingTest.py
@@ -49,7 +49,7 @@
         self.mon_info = wputils.create_monsoon_info(self)
         self.num_atten = self.attenuators[0].instrument.num_atten
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
             elif 'attenuator_setting' in file:
                 self.attenuation_file = file
diff --git a/acts/tests/google/power/wifi/PowerscanTest.py b/acts/tests/google/power/wifi/PowerscanTest.py
index 1c26a90..25e2c59 100644
--- a/acts/tests/google/power/wifi/PowerscanTest.py
+++ b/acts/tests/google/power/wifi/PowerscanTest.py
@@ -48,7 +48,7 @@
         self.mon_info = wputils.create_monsoon_info(self)
         self.num_atten = self.attenuators[0].instrument.num_atten
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
             elif 'attenuator_setting' in file:
                 self.attenuation_file = file
diff --git a/acts/tests/google/power/wifi/PowertrafficTest.py b/acts/tests/google/power/wifi/PowertrafficTest.py
index 83f99dd..36b7e86 100644
--- a/acts/tests/google/power/wifi/PowertrafficTest.py
+++ b/acts/tests/google/power/wifi/PowertrafficTest.py
@@ -53,7 +53,7 @@
         self.access_point = self.access_points[0]
         self.pkt_sender = self.packet_senders[0]
         for file in self.custom_files:
-            if 'pass_fail_threshold' in file:
+            if 'pass_fail_threshold_' + self.dut.model in file:
                 self.threshold_file = file
             elif 'attenuator_setting' in file:
                 self.attenuation_file = file
diff --git a/acts/tests/google/wifi/WifiIOTTest.py b/acts/tests/google/wifi/WifiIOTTest.py
index 1f3da05..36f7302 100755
--- a/acts/tests/google/wifi/WifiIOTTest.py
+++ b/acts/tests/google/wifi/WifiIOTTest.py
@@ -43,17 +43,22 @@
         self.dut = self.android_devices[0]
         wutils.wifi_test_device_init(self.dut)
 
-        req_params = [ "iot_networks", "open_network", "iperf_server_address" ]
-        self.unpack_userparams(req_param_names=req_params)
+        req_params = [ "iot_networks", ]
+        opt_params = [ "open_network", "iperf_server_address" ]
+        self.unpack_userparams(req_param_names=req_params,
+                               opt_param_names=opt_params)
 
         asserts.assert_true(
             len(self.iot_networks) > 0,
             "Need at least one iot network with psk.")
-        self.iot_networks.append(self.open_network)
+
+        if self.open_network:
+            self.iot_networks.append(self.open_network)
 
         wutils.wifi_toggle_state(self.dut, True)
         if "iperf_server_address" in self.user_params:
             self.iperf_server = self.iperf_servers[0]
+            self.iperf_server.start()
 
         # create hashmap for testcase name and SSIDs
         self.iot_test_prefix = "test_iot_connection_to_"
@@ -61,7 +66,6 @@
         for network in self.iot_networks:
             SSID = network['SSID'].replace('-','_')
             self.ssid_map[SSID] = network
-        self.iperf_server.start()
 
     def setup_test(self):
         self.dut.droid.wakeLockAcquireBright()
@@ -73,7 +77,8 @@
         wutils.reset_wifi(self.dut)
 
     def teardown_class(self):
-        self.iperf_server.stop()
+        if "iperf_server_address" in self.user_params:
+            self.iperf_server.stop()
 
     def on_fail(self, test_name, begin_time):
         self.dut.take_bug_report(test_name, begin_time)
diff --git a/acts/tests/google/wifi/aware/functional/DataPathTest.py b/acts/tests/google/wifi/aware/functional/DataPathTest.py
index c3598bf..bd7f500 100644
--- a/acts/tests/google/wifi/aware/functional/DataPathTest.py
+++ b/acts/tests/google/wifi/aware/functional/DataPathTest.py
@@ -958,7 +958,8 @@
     """
     num_events = 0
     while num_events != len(req_keys):
-      event = autils.wait_for_event(dut, cconsts.EVENT_NETWORK_CALLBACK)
+      event = autils.wait_for_event(dut, cconsts.EVENT_NETWORK_CALLBACK,
+                                    timeout=autils.EVENT_NDP_TIMEOUT)
       if (event["data"][cconsts.NETWORK_CB_KEY_EVENT] ==
           cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED):
         if event["data"][cconsts.NETWORK_CB_KEY_ID] in req_keys:
@@ -1234,6 +1235,8 @@
     dut1_req_keys = []
     dut2_aware_ifs = []
     dut1_aware_ifs = []
+    dut2_aware_ipv6 = []
+    dut1_aware_ipv6 = []
 
     dut2_type = aconsts.DATA_PATH_RESPONDER
     dut1_type = aconsts.DATA_PATH_INITIATOR
@@ -1274,20 +1277,24 @@
 
       # Wait for network
       dut1_net_event = autils.wait_for_event_with_keys(
-          dut1, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT,
+          dut1, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
           (cconsts.NETWORK_CB_KEY_EVENT,
            cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
           (cconsts.NETWORK_CB_KEY_ID, dut1_req_key))
       dut2_net_event = autils.wait_for_event_with_keys(
-          dut2, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT,
+          dut2, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
           (cconsts.NETWORK_CB_KEY_EVENT,
            cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
           (cconsts.NETWORK_CB_KEY_ID, dut2_req_key))
 
-      dut2_aware_ifs.append(
-          dut2_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME])
-      dut1_aware_ifs.append(
-          dut1_net_event["data"][cconsts.NETWORK_CB_KEY_INTERFACE_NAME])
+      dut2_aware_if = dut2_net_event["data"][
+        cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
+      dut1_aware_if = dut1_net_event["data"][
+        cconsts.NETWORK_CB_KEY_INTERFACE_NAME]
+      dut2_aware_ifs.append(dut2_aware_if)
+      dut1_aware_ifs.append(dut1_aware_if)
+      dut2_aware_ipv6.append(autils.get_ipv6_addr(dut2, dut2_aware_if))
+      dut1_aware_ipv6.append(autils.get_ipv6_addr(dut1, dut1_aware_if))
 
       if flip_init_resp:
         if dut2_is_responder:
@@ -1298,12 +1305,16 @@
           dut1_type = aconsts.DATA_PATH_INITIATOR
         dut2_is_responder = not dut2_is_responder
 
-    # check that we are using 2 NDIs
+    # check that we are using 2 NDIs & that they have unique IPv6 addresses
     dut1_aware_ifs = list(set(dut1_aware_ifs))
     dut2_aware_ifs = list(set(dut2_aware_ifs))
+    dut1_aware_ipv6 = list(set(dut1_aware_ipv6))
+    dut2_aware_ipv6 = list(set(dut2_aware_ipv6))
 
     self.log.info("Interface names: DUT1=%s, DUT2=%s", dut1_aware_ifs,
                   dut2_aware_ifs)
+    self.log.info("IPv6 addresses: DUT1=%s, DUT2=%s", dut1_aware_ipv6,
+                  dut2_aware_ipv6)
     self.log.info("DUT1 requests: %s", dut1_req_keys)
     self.log.info("DUT2 requests: %s", dut2_req_keys)
 
@@ -1311,6 +1322,10 @@
         len(dut1_aware_ifs), len(sec_configs), "Multiple DUT1 interfaces")
     asserts.assert_equal(
         len(dut2_aware_ifs), len(sec_configs), "Multiple DUT2 interfaces")
+    asserts.assert_equal(
+        len(dut1_aware_ipv6), len(sec_configs), "Multiple DUT1 IPv6 addresses")
+    asserts.assert_equal(
+        len(dut2_aware_ipv6), len(sec_configs), "Multiple DUT2 IPv6 addresses")
 
     for i in range(len(sec_configs)):
       if_name = "%s%d" % (aconsts.AWARE_NDI_PREFIX, i)
diff --git a/acts/tests/google/wifi/aware/functional/MacRandomTest.py b/acts/tests/google/wifi/aware/functional/MacRandomTest.py
index 329ead4..af1503b 100644
--- a/acts/tests/google/wifi/aware/functional/MacRandomTest.py
+++ b/acts/tests/google/wifi/aware/functional/MacRandomTest.py
@@ -57,6 +57,10 @@
     (NAN data-interface) on each enable/disable cycle"""
     dut = self.android_devices[0]
 
+    # re-enable randomization interval (since if disabled it may also disable
+    # the 'randomize on enable' feature).
+    autils.configure_mac_random_interval(dut, 1800)
+
     # DUT: attach and wait for confirmation & identity 10 times
     mac_addresses = {}
     for i in range(self.NUM_ITERATIONS):
@@ -108,9 +112,8 @@
 
     dut = self.android_devices[0]
 
-    # set randomization interval to 5 seconds
-    dut.adb.shell("cmd wifiaware native_api set mac_random_interval_sec %d" %
-                  RANDOM_INTERVAL)
+    # set randomization interval to 120 seconds
+    autils.configure_mac_random_interval(dut, RANDOM_INTERVAL)
 
     # attach and wait for first identity
     id = dut.droid.wifiAwareAttach(True)
diff --git a/acts/tests/google/wifi/aware/performance/ThroughputTest.py b/acts/tests/google/wifi/aware/performance/ThroughputTest.py
index 7ee6e08..ddb6d15 100644
--- a/acts/tests/google/wifi/aware/performance/ThroughputTest.py
+++ b/acts/tests/google/wifi/aware/performance/ThroughputTest.py
@@ -302,12 +302,12 @@
 
       # Wait for network
       init_net_event = autils.wait_for_event_with_keys(
-          init_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT,
+          init_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
           (cconsts.NETWORK_CB_KEY_EVENT,
            cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
           (cconsts.NETWORK_CB_KEY_ID, init_req_key))
       resp_net_event = autils.wait_for_event_with_keys(
-          resp_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_TIMEOUT,
+          resp_dut, cconsts.EVENT_NETWORK_CALLBACK, autils.EVENT_NDP_TIMEOUT,
           (cconsts.NETWORK_CB_KEY_EVENT,
            cconsts.NETWORK_CB_LINK_PROPERTIES_CHANGED),
           (cconsts.NETWORK_CB_KEY_ID, resp_req_key))