3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2026-03-01 16:57:56 +01:00
iwd/autotests/testAgent/agent_test.py
James Prestwood cfb782cfff auto-t: remove sleep in testAgent
The test here is verifying that a DBus Connect() call will still
work with 'other' agents registered. In this case it uses iwctl to
set a password, then call Connect() manually.

The problem here is that we have no way of knowing when iwctl fully
starts and registers its agent. There was a sleep in there but that
is unreliable and we occationally were still getting past that without
iwctl having started fully.

To fix this properly we need to wait for iwctl's agent service to appear
on the bus. Since the bus name is unknown we must first find all names,
then cross reference their PID's against the iwctl PID. This is done
using ListNames, and GetConnectionUnixProcessID APIs.
2022-06-24 18:11:49 -05:00

116 lines
2.8 KiB
Python

#!/usr/bin/python3
import unittest
import sys
import dbus
sys.path.append('../util')
import iwd
from iwd import IWD
from iwd import PSKAgent
from iwd import NetworkType
import testutil
import subprocess
from config import ctx
class Test(unittest.TestCase):
def check_connection(self, wd, ssid):
device = wd.list_devices(1)[0]
ordered_network = device.get_ordered_network(ssid)
ordered_network.network_object.connect()
condition = 'obj.state == DeviceState.connected'
wd.wait_for_object_condition(device, condition)
condition = 'obj.connected_network is not None'
wd.wait_for_object_condition(device, condition)
testutil.test_iface_operstate(device.name)
device.disconnect()
condition = 'obj.state == DeviceState.disconnected'
wd.wait_for_object_condition(device, condition)
def test_connection_with_no_agent(self):
wd = IWD()
with self.assertRaises(iwd.NoAgentEx):
self.check_connection(wd, 'ssid1')
IWD.clear_storage()
def test_connection_with_own_agent(self):
wd = IWD()
psk_agent = PSKAgent("secret_ssid1")
wd.register_psk_agent(psk_agent)
self.check_connection(wd, 'ssid1')
wd.unregister_psk_agent(psk_agent)
IWD.clear_storage()
def test_connection_with_other_agent(self):
def wait_for_service_pid(pid):
dbus_object = ctx._bus.get_object('org.freedesktop.DBus',
'/org/freedesktop/DBus')
dbus_iface = dbus.Interface(dbus_object, 'org.freedesktop.DBus')
services = dbus_iface.ListNames()
for service in services:
bus_iface = dbus.Interface(dbus_object, "org.freedesktop.DBus")
if pid == int(bus_iface.GetConnectionUnixProcessID(service)):
return True
return False
wd = IWD()
iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2'])
# Let iwctl to start and register its agent.
ctx.non_block_wait(wait_for_service_pid, 10, iwctl.pid)
self.check_connection(wd, 'ssid2')
iwctl.kill()
IWD.clear_storage()
def test_connection_use_own_agent_from_multiple_registered(self):
wd = IWD()
iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2'])
# Let iwctl to start and register its agent.
wd.wait(2)
psk_agent = PSKAgent("secret_ssid1")
wd.register_psk_agent(psk_agent)
self.check_connection(wd, 'ssid1')
wd.unregister_psk_agent(psk_agent)
iwctl.kill()
IWD.clear_storage()
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
if __name__ == '__main__':
unittest.main(exit=True)