3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-21 22:09:23 +01:00

auto-t: add test for known frequency sorting/maximum

Modify the existing frequency test to check that the ordering
lines up with the ranking of the BSS.

Add a test to check that quick scans limit the number of known
frequencies.
This commit is contained in:
James Prestwood 2024-01-26 12:22:43 -08:00 committed by Denis Kenzior
parent f52180d41c
commit 1a79092383
2 changed files with 102 additions and 9 deletions

View File

@ -4,17 +4,15 @@ import unittest
import sys import sys
sys.path.append('../util') sys.path.append('../util')
import iwd
from iwd import IWD from iwd import IWD
from iwd import PSKAgent from iwd import PSKAgent
from iwd import NetworkType from hwsim import Hwsim
import testutil
import os import os
from configparser import ConfigParser from configparser import ConfigParser
class Test(unittest.TestCase): class Test(unittest.TestCase):
def connect_network(self, wd, device, network): def connect_network(self, wd, device, network):
ordered_network = device.get_ordered_network(network) ordered_network = device.get_ordered_network(network, full_scan=True)
condition = 'not obj.connected' condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition) wd.wait_for_object_condition(ordered_network.network_object, condition)
@ -30,7 +28,7 @@ class Test(unittest.TestCase):
wd.wait_for_object_condition(ordered_network.network_object, condition) wd.wait_for_object_condition(ordered_network.network_object, condition)
def test_connection_success(self): def test_connection_success(self):
wd = IWD(True, '/tmp') wd = self.wd
psk_agent = PSKAgent("secret123") psk_agent = PSKAgent("secret123")
wd.register_psk_agent(psk_agent) wd.register_psk_agent(psk_agent)
@ -38,6 +36,11 @@ class Test(unittest.TestCase):
devices = wd.list_devices(1) devices = wd.list_devices(1)
device = devices[0] device = devices[0]
# Set the signals so that the 2.4GHz ranking will be higher
self.ssidccmp_2g_rule.signal = -2000
self.ssidccmp_5g_rule.signal = -8000
# #
# Connect to the PSK network, then Hotspot so IWD creates 2 entries in # Connect to the PSK network, then Hotspot so IWD creates 2 entries in
# the known frequency file. # the known frequency file.
@ -75,8 +78,10 @@ class Test(unittest.TestCase):
# #
self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_freqs)
self.assertIsNotNone(psk_uuid) self.assertIsNotNone(psk_uuid)
self.assertIn('5180', psk_freqs)
self.assertIn('2412', psk_freqs) # The 2.4GHz frequency should come first, as it was ranked higher
self.assertEqual('2412', psk_freqs[0])
self.assertEqual('5180', psk_freqs[1])
self.assertIsNotNone(hs20_freqs) self.assertIsNotNone(hs20_freqs)
self.assertIsNotNone(hs20_uuid) self.assertIsNotNone(hs20_uuid)
@ -92,6 +97,10 @@ class Test(unittest.TestCase):
psk_agent = PSKAgent("secret123") psk_agent = PSKAgent("secret123")
wd.register_psk_agent(psk_agent) wd.register_psk_agent(psk_agent)
# Now set the signals so that the 5GHz ranking will be higher
self.ssidccmp_2g_rule.signal = -8000
self.ssidccmp_5g_rule.signal = -2000
# #
# Reconnect, this should generate a completely new UUID since we # Reconnect, this should generate a completely new UUID since we
# previously forgot the network. # previously forgot the network.
@ -120,8 +129,78 @@ class Test(unittest.TestCase):
self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_freqs)
self.assertIsNotNone(psk_uuid2) self.assertIsNotNone(psk_uuid2)
self.assertNotEqual(psk_uuid, psk_uuid2) self.assertNotEqual(psk_uuid, psk_uuid2)
self.assertIn('5180', psk_freqs) # Now the 5GHz frequency should be first
self.assertIn('2412', psk_freqs) self.assertEqual('5180', psk_freqs[0])
self.assertEqual('2412', psk_freqs[1])
def test_maximum_frequencies(self):
psk_agent = PSKAgent("secret123")
self.wd.register_psk_agent(psk_agent)
devices = self.wd.list_devices(1)
device = devices[0]
# Connect and generate a known frequencies file
self.connect_network(self.wd, device, 'ssidCCMP')
self.wd.unregister_psk_agent(psk_agent)
#
# Rewrite the known frequencies file to move the valid network
# frequencies to the end, past the maximum for a quick scan
#
config = ConfigParser()
config.read('/tmp/iwd/.known_network.freq')
for s in config.sections():
if os.path.basename(config[s]['name']) == 'ssidCCMP.psk':
config.set(s, 'list', "2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484 2412 5180")
break
self.wd.stop()
with open('/tmp/iwd/.known_network.freq', 'w') as f:
config.write(f)
self.wd = IWD(True)
devices = self.wd.list_devices(1)
device = devices[0]
device.autoconnect = True
device.wait_for_event("autoconnect_quick")
condition = "obj.scanning == True"
self.wd.wait_for_object_condition(device, condition)
condition = "obj.scanning == False"
self.wd.wait_for_object_condition(device, condition)
#
# Check that the quick scan didn't return any results
#
with self.assertRaises(Exception):
device.get_ordered_network("ssidCCMP", scan_if_needed=False)
device.wait_for_event("autoconnect_full")
condition = "obj.scanning == True"
self.wd.wait_for_object_condition(device, condition)
condition = "obj.scanning == False"
self.wd.wait_for_object_condition(device, condition)
#
# The full scan should now see the network
#
device.get_ordered_network("ssidCCMP", scan_if_needed=False)
def setUp(self):
self.wd = IWD(True)
def tearDown(self):
self.wd.stop()
self.wd = None
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
@ -129,10 +208,23 @@ class Test(unittest.TestCase):
conf = '[General]\nDisableANQP=0\n' conf = '[General]\nDisableANQP=0\n'
os.system('echo "%s" > /tmp/main.conf' % conf) os.system('echo "%s" > /tmp/main.conf' % conf)
hwsim = Hwsim()
cls.ssidccmp_2g_rule = hwsim.rules.create()
cls.ssidccmp_2g_rule.source = hwsim.get_radio('rad1').addresses[0]
cls.ssidccmp_2g_rule.enabled = True
cls.ssidccmp_5g_rule = hwsim.rules.create()
cls.ssidccmp_5g_rule.source = hwsim.get_radio('rad2').addresses[0]
cls.ssidccmp_5g_rule.enabled = True
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
IWD.clear_storage() IWD.clear_storage()
os.remove('/tmp/main.conf') os.remove('/tmp/main.conf')
cls.ssidccmp_2g_rule.remove()
cls.ssidccmp_5g_rule.remove()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(exit=True) unittest.main(exit=True)

View File

@ -2,6 +2,7 @@
num_radios=5 num_radios=5
start_iwd=0 start_iwd=0
reg_domain=US reg_domain=US
hwsim_medium=yes
[HOSTAPD] [HOSTAPD]
rad0=ssidNew.conf rad0=ssidNew.conf