From 0f5029ff41ef286aa7b3e4a3efd3f1a16be925e8 Mon Sep 17 00:00:00 2001
From: "Arnout Vandecappelle (Essensium/Mind)" <arnout@mind.be>
Date: Wed, 9 Jan 2019 18:41:08 +0100
Subject: [PATCH] tests: refactor test_multi_ap

With just one additional argument, the run_multi_ap_association function
can be used for all tests.

While we're at it, also move it to the top of the file.

Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
---
v4: new patch
---
 tests/hwsim/test_multi_ap.py | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

--- a/tests/hwsim/test_multi_ap.py
+++ b/tests/hwsim/test_multi_ap.py
@@ -6,6 +6,15 @@
 
 import hostapd
 
+def run_multi_ap_association(dev, apdev, multi_ap, wait_connect=True):
+    params = hostapd.wpa2_params(ssid="multi-ap", passphrase="12345678")
+    if multi_ap:
+        params["multi_ap"] = str(multi_ap)
+    hapd = hostapd.add_ap(apdev[0], params)
+
+    dev[0].connect("multi-ap", psk="12345678", scan_freq="2412",
+                   multi_ap_backhaul_sta="1", wait_connect=wait_connect)
+
 def test_multi_ap_association(dev, apdev):
     """Multi-AP association in backhaul BSS"""
     run_multi_ap_association(dev, apdev, 1)
@@ -28,21 +37,9 @@ def test_multi_ap_association_shared_bss
     run_multi_ap_association(dev, apdev, 3)
     dev[1].connect("multi-ap", psk="12345678", scan_freq="2412")
 
-def run_multi_ap_association(dev, apdev, multi_ap):
-    params = hostapd.wpa2_params(ssid="multi-ap", passphrase="12345678")
-    params["multi_ap"] = str(multi_ap)
-    hapd = hostapd.add_ap(apdev[0], params)
-
-    dev[0].connect("multi-ap", psk="12345678", multi_ap_backhaul_sta="1",
-                   scan_freq="2412")
-
 def test_multi_ap_disabled_on_ap(dev, apdev):
     """Multi-AP association attempt when disabled on AP"""
-    params = hostapd.wpa2_params(ssid="multi-ap", passphrase="12345678")
-    hapd = hostapd.add_ap(apdev[0], params)
-
-    dev[0].connect("multi-ap", psk="12345678", multi_ap_backhaul_sta="1",
-                   scan_freq="2412", wait_connect=False)
+    run_multi_ap_association(dev, apdev, 0, wait_connect=False)
     ev = dev[0].wait_event([ "CTRL-EVENT-DISCONNECTED",
                              "CTRL-EVENT-CONNECTED" ],
                            timeout=5)
@@ -54,12 +51,7 @@ def test_multi_ap_disabled_on_ap(dev, ap
 
 def test_multi_ap_fronthaul_on_ap(dev, apdev):
     """Multi-AP association attempt when only fronthaul BSS on AP"""
-    params = hostapd.wpa2_params(ssid="multi-ap", passphrase="12345678")
-    params["multi_ap"] = "2"
-    hapd = hostapd.add_ap(apdev[0], params)
-
-    dev[0].connect("multi-ap", psk="12345678", multi_ap_backhaul_sta="1",
-                   scan_freq="2412", wait_connect=False)
+    run_multi_ap_association(dev, apdev, 2, wait_connect=False)
     ev = dev[0].wait_event([ "CTRL-EVENT-DISCONNECTED",
                              "CTRL-EVENT-CONNECTED",
                              "CTRL-EVENT-ASSOC-REJECT" ],
