3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 21:22:37 +01:00
iwd/autotests/testHiddenNetworks/validation.py
James Prestwood 2bd2462968 auto-t: fix hidden network test
This test was never 100% reliable, and after the test-runner re-write
it became extremely unreliable. The issue came down to the very common
block of code thats present in many tests where we wait for obj.scanning
then not obj.scanning. This is fine when a dbus scan() is explicitly
done before, otherwise it could lead to problems. Without a dbus scan
explicitly called we are assuming a periodic scan will happen. If it
already happen the initial wait for obj.scanning will never return and
time out.

This probably needs to be changed in several tests, but for this specific
case we can remove the waits completely. Since
check_autoconnect_hidden_network has a 30 second wait on
DeviceState.connected this will ultimately time out if anything goes
wrong. There isn't any great reason to wait for scanning (for this test
specifically).

A minor style change was also made when initializing IWD. The values
passed in this test are now the default, so no arguments need to be
passed.
2020-09-10 17:59:49 -05:00

72 lines
2.4 KiB
Python

#!/usr/bin/python3
import unittest
import sys
sys.path.append('../util')
import iwd
from iwd import IWD
from iwd import PSKAgent
from iwd import NetworkType
class TestConnectAutoConnect(unittest.TestCase):
def check_connect_hidden_network(self, wd, device, ssid, throws):
if not throws is None:
with self.assertRaises(throws):
device.connect_hidden_network(ssid)
return
else:
device.connect_hidden_network(ssid)
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition, 30)
def check_autoconnect_hidden_network(self, wd, device, ssid, throws):
if throws is None:
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition, 30)
condition = 'obj.connected_network is not None'
wd.wait_for_object_condition(device, condition)
ordered_network = device.get_ordered_network(ssid)
self.assertTrue(ordered_network.network_object.connected)
device.disconnect()
condition = 'obj.state == DeviceState.disconnected'
wd.wait_for_object_condition(device, condition, 30)
def validate_connection(self, wd, ssid, autoconnect, throws, use_agent,
wait_periodic_scan):
if use_agent:
psk_agent = PSKAgent(["secret123"], ('domain\\User', 'Password'))
wd.register_psk_agent(psk_agent)
devices = wd.list_devices(1)
self.assertIsNotNone(devices)
device = devices[0]
if autoconnect:
self.check_autoconnect_hidden_network(wd, device, ssid, throws)
else:
if wait_periodic_scan:
condition = 'obj.scanning'
wd.wait_for_object_condition(device, condition)
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
self.check_connect_hidden_network(wd, device, ssid, throws)
if use_agent:
wd.unregister_psk_agent(psk_agent)
def validate(self, ssid, autoconnect, throws = None, use_agent = False,
wait_periodic_scan = False):
wd = IWD(True)
self.validate_connection(wd, ssid, autoconnect, throws, use_agent,
wait_periodic_scan)