Merge "[RTT][AWARE] Update regulatory configuration of tests" into pi-dev
diff --git a/acts/framework/acts/test_utils/bt/bt_coc_test_utils.py b/acts/framework/acts/test_utils/bt/bt_coc_test_utils.py
index 19e966b..f7d4867 100644
--- a/acts/framework/acts/test_utils/bt/bt_coc_test_utils.py
+++ b/acts/framework/acts/test_utils/bt/bt_coc_test_utils.py
@@ -189,6 +189,8 @@
                 opportunistic=False)
         except GattTestUtilsError as err:
             client_ad.log.error(err)
+            if (adv_callback != None):
+                server_ad.droid.bleStopBleAdvertising(adv_callback)
             return False, None, None
         client_ad.log.info("setup_gatt_connection returns success")
         if (le_connection_interval != 0):
@@ -208,6 +210,8 @@
         if not return_status:
             client_ad.log.error(
                 "gattClientRequestLeConnectionParameters returns failure")
+            if (adv_callback != None):
+                server_ad.droid.bleStopBleAdvertising(adv_callback)
             return False, None, None
         client_ad.log.info(
             "gattClientRequestLeConnectionParameters returns success. Interval={}"
@@ -242,9 +246,13 @@
                 test_result = True
                 break
         time.sleep(1)
+
+    if (adv_callback != None):
+        server_ad.droid.bleStopBleAdvertising(adv_callback)
+
     if not test_result:
         client_ad.log.error("Failed to establish an CoC connection")
-        return False, None
+        return False, None, None
 
     if len(client_ad.droid.bluetoothSocketConnActiveConnections()) > 0:
         server_ad.log.info(
diff --git a/acts/tests/google/ble/conn_oriented_chan/BleCoc2ConnTest.py b/acts/tests/google/ble/conn_oriented_chan/BleCoc2ConnTest.py
index 6a147b7..bff59e7 100644
--- a/acts/tests/google/ble/conn_oriented_chan/BleCoc2ConnTest.py
+++ b/acts/tests/google/ble/conn_oriented_chan/BleCoc2ConnTest.py
@@ -55,8 +55,6 @@
     def teardown_test(self):
         self.client_ad.droid.bluetoothSocketConnStop()
         self.server_ad.droid.bluetoothSocketConnStop()
-        self.server_ad.droid.bleAdvertiseClearAll()
-        self.server2_ad.droid.bleAdvertiseClearAll()
         # Give sufficient time for the physical LE link to be disconnected.
         time.sleep(l2cap_max_inactivity_delay_after_disconnect)
 
diff --git a/acts/tests/google/ble/conn_oriented_chan/BleCocTest.py b/acts/tests/google/ble/conn_oriented_chan/BleCocTest.py
index 6eb7203..e5d093f 100644
--- a/acts/tests/google/ble/conn_oriented_chan/BleCocTest.py
+++ b/acts/tests/google/ble/conn_oriented_chan/BleCocTest.py
@@ -59,7 +59,6 @@
     def teardown_test(self):
         self.client_ad.droid.bluetoothSocketConnStop()
         self.server_ad.droid.bluetoothSocketConnStop()
-        self.server_ad.droid.bleAdvertiseClearAll()
         # Give sufficient time for the physical LE link to be disconnected.
         time.sleep(l2cap_max_inactivity_delay_after_disconnect)
 
diff --git a/acts/tests/google/bt/hid/HidDeviceTest.py b/acts/tests/google/bt/hid/HidDeviceTest.py
index 3df837a..cdd1094 100644
--- a/acts/tests/google/bt/hid/HidDeviceTest.py
+++ b/acts/tests/google/bt/hid/HidDeviceTest.py
@@ -240,12 +240,12 @@
         self.log.info("Host bonded: {}".format(
                 self.host_ad.droid.bluetoothGetBondedDevices()))
 
-        if not self.device_ad.droid.bluetoothGetBondedDevices():
-            self.log.error("HID device unbonded host on virtual_cable_unplug")
+        if self.device_ad.droid.bluetoothGetBondedDevices():
+            self.log.error("HID device didn't unbond on virtual_cable_unplug")
             test_result = False
 
-        if not self.host_ad.droid.bluetoothGetBondedDevices():
-            self.log.error("HID host unbonded device on virtual_cable_unplug")
+        if self.host_ad.droid.bluetoothGetBondedDevices():
+            self.log.error("HID host didn't unbond on virtual_cable_unplug")
             test_result = False
 
         return test_result
diff --git a/acts/tests/google/wifi/WifiRssiTest.py b/acts/tests/google/wifi/WifiRssiTest.py
index aa95b23..4dd053a 100644
--- a/acts/tests/google/wifi/WifiRssiTest.py
+++ b/acts/tests/google/wifi/WifiRssiTest.py
@@ -45,7 +45,7 @@
 
     def setup_class(self):
         self.dut = self.android_devices[0]
-        req_params = ["rssi_test_params", "main_network"]
+        req_params = ["rssi_test_params", "testbed_params", "main_network"]
         opt_params = ["RetailAccessPoints"]
         self.unpack_userparams(req_params, opt_params)
         self.test_params = self.rssi_test_params
@@ -447,7 +447,7 @@
         if self.iperf_traffic:
             self.iperf_server.start(tag=0)
             self.dut.run_iperf_client_nb(
-                self.test_params["iperf_server_address"],
+                self.testbed_params["iperf_server_address"],
                 self.iperf_args,
                 timeout=3600)
         for atten in self.rssi_atten_range:
@@ -465,8 +465,8 @@
                 bssids, scan_measurements)
             rssi_result.append(current_rssi)
             self.log.info("Connected RSSI at {0:.2f} dB is {1:.2f} dB".format(
-                atten, current_rssi["connected_rssi"][
-                    "mean_signal_poll_rssi"]))
+                atten,
+                current_rssi["connected_rssi"]["mean_signal_poll_rssi"]))
         # Stop iperf traffic if needed
         if self.iperf_traffic:
             self.iperf_server.stop()
@@ -509,9 +509,14 @@
         rssi_result["ap_settings"] = self.access_point.ap_settings.copy()
         rssi_result["attenuation"] = list(self.rssi_atten_range)
         rssi_result["connected_bssid"] = self.main_network[band]["BSSID"]
-        rssi_result["ap_tx_power"] = self.test_params["ap_tx_power"][str(
-            self.channel)]
-        rssi_result["fixed_attenuation"] = self.test_params[
+        if "{}_{}".format(str(self.channel),
+                          self.mode) in self.testbed_params["ap_tx_power"]:
+            rssi_result["ap_tx_power"] = self.testbed_params["ap_tx_power"][
+                "{}_{}".format(str(self.channel), self.mode)]
+        else:
+            rssi_result["ap_tx_power"] = self.testbed_params["ap_tx_power"][
+                str(self.channel)]
+        rssi_result["fixed_attenuation"] = self.testbed_params[
             "fixed_attenuation"][str(self.channel)]
         rssi_result["rssi_result"] = self.rssi_test(
             iperf_traffic, connected_measurements, scan_measurements, bssids,
@@ -541,9 +546,9 @@
         ]
         rssi_result = self.rssi_test_func(
             self.iperf_traffic, self.test_params["connected_measurements"],
-            self.test_params["scan_measurements"], [
-                self.main_network[band]["BSSID"]
-            ], self.test_params["polling_frequency"])
+            self.test_params["scan_measurements"],
+            [self.main_network[band]["BSSID"]],
+            self.test_params["polling_frequency"])
         postprocessed_results = self.post_process_rssi_vs_attenuation(
             rssi_result)
         self.pass_fail_check_rssi_vs_attenuation(postprocessed_results)
@@ -565,9 +570,9 @@
             self.test_params["stability_test_duration"] /
             self.test_params["polling_frequency"])
         rssi_result = self.rssi_test_func(
-            self.iperf_traffic, connected_measurements, 0, [
-                self.main_network[band]["BSSID"]
-            ], self.test_params["polling_frequency"])
+            self.iperf_traffic, connected_measurements, 0,
+            [self.main_network[band]["BSSID"]],
+            self.test_params["polling_frequency"])
         self.pass_fail_check_rssi_stability(rssi_result)
 
     @test_tracker_info(uuid='519689b8-0a3c-4fd9-9227-fd7962d0f1a0')
@@ -668,7 +673,7 @@
 
     @test_tracker_info(uuid='4b74dd46-4190-4556-8ad8-c55808e9e847')
     def test_rssi_stability_ch161_VHT20_ActiveTraffic(self):
-        self._test_rssi_vs_atten()
+        self._test_rssi_stability()
 
     @test_tracker_info(uuid='ae54b7cc-d76d-4460-8dcc-2c439265c7c9')
     def test_rssi_vs_atten_ch1_VHT20_ActiveTraffic(self):
diff --git a/acts/tests/google/wifi/WifiRvrTest.py b/acts/tests/google/wifi/WifiRvrTest.py
index f40cc50..b0b2298 100644
--- a/acts/tests/google/wifi/WifiRvrTest.py
+++ b/acts/tests/google/wifi/WifiRvrTest.py
@@ -39,7 +39,7 @@
 
     def setup_class(self):
         self.client_dut = self.android_devices[-1]
-        req_params = ["rvr_test_params"]
+        req_params = ["rvr_test_params", "testbed_params"]
         opt_params = [
             "main_network", "RetailAccessPoints", "golden_files_list"
         ]
@@ -56,8 +56,9 @@
         utils.create_dir(self.log_path)
         if not hasattr(self, "golden_files_list"):
             self.golden_files_list = [
-                os.path.join(self.test_params["golden_results_path"], file)
-                for file in os.listdir(self.test_params["golden_results_path"])
+                os.path.join(self.testbed_params["golden_results_path"],
+                             file) for file in os.listdir(
+                                 self.testbed_params["golden_results_path"])
             ]
         self.testclass_results = []
 
@@ -284,7 +285,7 @@
             try:
                 client_output = ""
                 client_status, client_output = self.client_dut.run_iperf_client(
-                    self.test_params["iperf_server_address"],
+                    self.testbed_params["iperf_server_address"],
                     self.iperf_args,
                     timeout=self.test_params["iperf_duration"] +
                     self.TEST_TIMEOUT)
@@ -358,7 +359,7 @@
         rvr_result["test_name"] = self.current_test_name
         rvr_result["ap_settings"] = self.access_point.ap_settings.copy()
         rvr_result["attenuation"] = list(self.rvr_atten_range)
-        rvr_result["fixed_attenuation"] = self.test_params[
+        rvr_result["fixed_attenuation"] = self.testbed_params[
             "fixed_attenuation"][str(channel)]
         rvr_result["throughput_receive"] = self.rvr_test()
         self.testclass_results.append(rvr_result)
diff --git a/acts/tests/google/wifi/WifiThroughputStabilityTest.py b/acts/tests/google/wifi/WifiThroughputStabilityTest.py
index 93a1b16..c28bd63 100644
--- a/acts/tests/google/wifi/WifiThroughputStabilityTest.py
+++ b/acts/tests/google/wifi/WifiThroughputStabilityTest.py
@@ -93,7 +93,10 @@
 
     def setup_class(self):
         self.dut = self.android_devices[0]
-        req_params = ["throughput_stability_test_params", "main_network"]
+        req_params = [
+            "throughput_stability_test_params", "testbed_params",
+            "main_network"
+        ]
         opt_params = ["RetailAccessPoints"]
         self.unpack_userparams(req_params, opt_params)
         self.test_params = self.throughput_stability_test_params
@@ -107,8 +110,9 @@
             self.access_point.ap_settings))
         if not hasattr(self, "golden_files_list"):
             self.golden_files_list = [
-                os.path.join(self.test_params["golden_results_path"], file)
-                for file in os.listdir(self.test_params["golden_results_path"])
+                os.path.join(self.testbed_params["golden_results_path"],
+                             file) for file in os.listdir(
+                                 self.testbed_params["golden_results_path"])
             ]
 
     def teardown_test(self):
@@ -170,9 +174,8 @@
         test_result_dict["ap_settings"] = test_result["ap_settings"].copy()
         test_result_dict["attenuation"] = self.atten_level
         instantaneous_rates_Mbps = [
-            rate * 8
-            for rate in test_result["iperf_result"].instantaneous_rates[
-                self.test_params["iperf_ignored_interval"]:-1]
+            rate * 8 * (1.024**2) for rate in test_result["iperf_result"]
+            .instantaneous_rates[self.test_params["iperf_ignored_interval"]:-1]
         ]
         test_result_dict["iperf_results"] = {
             "instantaneous_rates":
@@ -238,7 +241,7 @@
         ]
         # Connect DUT to Network
         self.main_network[band]["channel"] = channel
-        wutils.toggle_wifi_off_and_on(self.dut)
+        wutils.reset_wifi(self.dut)
         wutils.wifi_connect(self.dut, self.main_network[band], num_of_tries=5)
         time.sleep(5)
         # Run test and log result
@@ -248,14 +251,14 @@
         try:
             client_output = ""
             client_status, client_output = self.dut.run_iperf_client(
-                self.test_params["iperf_server_address"],
+                self.testbed_params["iperf_server_address"],
                 self.iperf_args,
                 timeout=self.test_params["iperf_duration"] + TEST_TIMEOUT)
         except:
             self.log.warning("TimeoutError: Iperf measurement timed out.")
-        client_output_path = os.path.join(
-            self.iperf_server.log_path,
-            "iperf_client_output_{}".format(self.current_test_name))
+        client_output_path = os.path.join(self.iperf_server.log_path,
+                                          "iperf_client_output_{}".format(
+                                              self.current_test_name))
         with open(client_output_path, 'w') as out_file:
             out_file.write("\n".join(client_output))
         self.iperf_server.stop()