diff mbox series

[2/3] tests: Refactor MSCS

Message ID 20231226094525.502618-2-andrei.otcheretianski@intel.com
State Accepted
Headers show
Series [1/3] MSCS: Extend MSCS response handling | expand

Commit Message

Andrei Otcheretianski Dec. 26, 2023, 9:45 a.m. UTC
From: Daniel Gabay <daniel.gabay@intel.com>

Add helper functions for common logic.

Signed-off-by: Daniel Gabay <daniel.gabay@intel.com>
---
 tests/hwsim/test_mscs.py | 76 ++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 41 deletions(-)
diff mbox series

Patch

diff --git a/tests/hwsim/test_mscs.py b/tests/hwsim/test_mscs.py
index b200550b3a..1a884074c8 100644
--- a/tests/hwsim/test_mscs.py
+++ b/tests/hwsim/test_mscs.py
@@ -43,6 +43,24 @@  def wait_mscs_result(dev, expect_status=0):
     if "status_code=%d" % expect_status not in ev:
         raise Exception("Unexpected MSCS result: " + ev)
 
+def add_mscs_ap(apdev, reg_mscs_req=True, mscs_supported=True, assocresp_elements=None):
+    params = {"ssid": "mscs"}
+
+    if mscs_supported:
+        params["ext_capa"] = 10*"00" + "20"
+    else:
+        params["ext_capa_mask"] = 10*"00" + "20"
+
+    if assocresp_elements is not None:
+        params['assocresp_elements'] = assocresp_elements
+
+    hapd = hostapd.add_ap(apdev, params)
+
+    if reg_mscs_req:
+        register_mcsc_req(hapd)
+
+    return hapd
+
 def test_mscs_invalid_params(dev, apdev):
     """MSCS command invalid parameters"""
     tests = ["",
@@ -58,17 +76,18 @@  def test_mscs_invalid_params(dev, apdev):
         if "FAIL" not in dev[0].request("MSCS " + t):
             raise Exception("Invalid MSCS parameters accepted: " + t)
 
-def test_mscs_without_ap_support(dev, apdev):
-    """MSCS without AP support"""
+def run(dev, apdev, func):
     try:
-        run_mscs_without_ap_support(dev, apdev)
+        func(dev, apdev)
     finally:
         dev[0].request("MSCS remove")
 
+def test_mscs_without_ap_support(dev, apdev):
+    """MSCS without AP support"""
+    run(dev, apdev, run_mscs_without_ap_support)
+
 def run_mscs_without_ap_support(dev, apdev):
-    params = {"ssid": "mscs",
-              "ext_capa_mask": 10*"00" + "20"}
-    hapd = hostapd.add_ap(apdev[0], params)
+    add_mscs_ap(apdev[0], reg_mscs_req=False, mscs_supported=False)
 
     cmd = "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=12345 frame_classifier=045F"
     if "OK" not in dev[0].request(cmd):
@@ -86,16 +105,10 @@  def run_mscs_without_ap_support(dev, apdev):
 
 def test_mscs_post_assoc(dev, apdev):
     """MSCS configuration post-association"""
-    try:
-        run_mscs_post_assoc(dev, apdev)
-    finally:
-        dev[0].request("MSCS remove")
+    run(dev, apdev, run_mscs_post_assoc)
 
 def run_mscs_post_assoc(dev, apdev):
-    params = {"ssid": "mscs",
-              "ext_capa": 10*"00" + "20"}
-    hapd = hostapd.add_ap(apdev[0], params)
-    register_mcsc_req(hapd)
+    hapd = add_mscs_ap(apdev[0])
 
     dev[0].connect("mscs", key_mgmt="NONE", scan_freq="2412")
 
@@ -129,17 +142,11 @@  def run_mscs_post_assoc(dev, apdev):
 
 def test_mscs_pre_assoc(dev, apdev):
     """MSCS configuration pre-association"""
-    try:
-        run_mscs_pre_assoc(dev, apdev)
-    finally:
-        dev[0].request("MSCS remove")
+    run(dev, apdev, run_mscs_pre_assoc)
 
 def run_mscs_pre_assoc(dev, apdev):
-    params = {"ssid": "mscs",
-              "ext_capa": 10*"00" + "20",
-              "assocresp_elements": "ff0c5800000000000000" + "01020000"}
-    hapd = hostapd.add_ap(apdev[0], params)
-    register_mcsc_req(hapd)
+    ies = "ff0c5800000000000000" + "01020000"
+    hapd = add_mscs_ap(apdev[0], assocresp_elements=ies)
 
     cmd = "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=12345 frame_classifier=045F"
     if "OK" not in dev[0].request(cmd):
@@ -171,17 +178,11 @@  def run_mscs_pre_assoc(dev, apdev):
 
 def test_mscs_assoc_failure(dev, apdev):
     """MSCS configuration failure during association exchange"""
-    try:
-        run_mscs_assoc_failure(dev, apdev)
-    finally:
-        dev[0].request("MSCS remove")
+    run(dev, apdev, run_mscs_assoc_failure)
 
 def run_mscs_assoc_failure(dev, apdev):
-    params = {"ssid": "mscs",
-              "ext_capa": 10*"00" + "20",
-              "assocresp_elements": "ff0c5800000000000000" + "01020001"}
-    hapd = hostapd.add_ap(apdev[0], params)
-    register_mcsc_req(hapd)
+    ies = "ff0c5800000000000000" + "01020001"
+    hapd = add_mscs_ap(apdev[0], assocresp_elements=ies)
 
     cmd = "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=12345 frame_classifier=045F"
     if "OK" not in dev[0].request(cmd):
@@ -208,17 +209,10 @@  def run_mscs_assoc_failure(dev, apdev):
 
 def test_mscs_local_errors(dev, apdev):
     """MSCS configuration local errors"""
-    try:
-        run_mscs_local_errors(dev, apdev)
-    finally:
-        dev[0].request("MSCS remove")
+    run(dev, apdev, run_mscs_local_errors)
 
 def run_mscs_local_errors(dev, apdev):
-    params = {"ssid": "mscs",
-              "ext_capa": 10*"00" + "20"}
-    hapd = hostapd.add_ap(apdev[0], params)
-    register_mcsc_req(hapd)
-
+    hapd = add_mscs_ap(apdev[0])
     dev[0].connect("mscs", key_mgmt="NONE", scan_freq="2412")
 
     hapd.dump_monitor()