From 2b6915a13922c16b72d5932babb5ea796ceddc22 Mon Sep 17 00:00:00 2001
From: Jouni Malinen <jouni@codeaurora.org>
Date: Fri, 7 May 2021 13:05:21 +0300
Subject: [PATCH] tests: Extend estimated throughput testing

Cover VHT160 and HE cases.

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
---
 tests/hwsim/test_ap_vht.py |  5 +++++
 tests/hwsim/test_he.py     | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/tests/hwsim/test_ap_vht.py b/tests/hwsim/test_ap_vht.py
index 0123697f4..b47aaa2a4 100644
--- a/tests/hwsim/test_ap_vht.py
+++ b/tests/hwsim/test_ap_vht.py
@@ -369,6 +369,7 @@ def test_ap_vht160(dev, apdev):
                   'ieee80211d': '1',
                   'ieee80211h': '1'}
         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
+        bssid = apdev[0]['bssid']
 
         ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
         if "DFS-CAC-START" not in ev:
@@ -408,6 +409,10 @@ def test_ap_vht160(dev, apdev):
         if "WIDTH=160 MHz" not in sig:
             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
 
+        est = dev[0].get_bss(bssid)['est_throughput']
+        if est != "780001":
+            raise Exception("Unexpected BSS est_throughput: " + est)
+
         sta = hapd.get_sta(dev[0].own_addr())
         if 'supp_op_classes' not in sta or len(sta['supp_op_classes']) < 2:
             raise Exception("No Supported Operating Classes information for STA")
diff --git a/tests/hwsim/test_he.py b/tests/hwsim/test_he.py
index 2593f35f0..43dfa5e65 100644
--- a/tests/hwsim/test_he.py
+++ b/tests/hwsim/test_he.py
@@ -150,7 +150,7 @@ def test_he80(dev, apdev):
         if "WIDTH=80 MHz" not in sig:
             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
         est = dev[0].get_bss(bssid)['est_throughput']
-        if est != "390001":
+        if est != "600502":
             raise Exception("Unexpected BSS est_throughput: " + est)
         status = dev[0].get_status()
         if status["ieee80211ac"] != "1":
@@ -492,6 +492,7 @@ def test_he160(dev, apdev):
                   'ieee80211d': '1',
                   'ieee80211h': '1'}
         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
+        bssid = apdev[0]['bssid']
 
         ev = wait_dfs_event(hapd, "DFS-CAC-START", 5)
         if "DFS-CAC-START" not in ev:
@@ -530,6 +531,9 @@ def test_he160(dev, apdev):
             raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
         if "WIDTH=160 MHz" not in sig:
             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
+        est = dev[0].get_bss(bssid)['est_throughput']
+        if est != "1201002":
+            raise Exception("Unexpected BSS est_throughput: " + est)
     except Exception as e:
         if isinstance(e, Exception) and str(e) == "AP startup failed":
             if not he_supported():
@@ -1186,3 +1190,32 @@ def test_he_6ghz_security(dev, apdev):
     hapd.set("group_cipher", "TKIP")
     if "FAIL" not in hapd.request("ENABLE"):
         raise Exception("Invalid configuration accepted(5)")
+
+def test_he_prefer_he20(dev, apdev):
+    """Preference on HE20 over HT20"""
+    params = {"ssid": "he",
+              "channel": "1",
+              "ieee80211ax": "0",
+              "ieee80211n": "1"}
+    hapd = hostapd.add_ap(apdev[0], params)
+    bssid = apdev[0]['bssid']
+    params = {"ssid": "test",
+              "channel": "1",
+              "ieee80211ax": "1",
+              "ieee80211n": "1"}
+    hapd2 = hostapd.add_ap(apdev[1], params)
+    bssid2 = apdev[1]['bssid']
+
+    dev[0].scan_for_bss(bssid, freq=2412)
+    dev[0].scan_for_bss(bssid2, freq=2412)
+    dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
+    if dev[0].get_status_field('bssid') != bssid2:
+        raise Exception("Unexpected BSS selected")
+
+    est = dev[0].get_bss(bssid)['est_throughput']
+    if est != "65000":
+        raise Exception("Unexpected BSS0 est_throughput: " + est)
+
+    est = dev[0].get_bss(bssid2)['est_throughput']
+    if est != "143402":
+        raise Exception("Unexpected BSS1 est_throughput: " + est)