--- autotests/testAgent/agent_test.py | 100 ++++++++++++++++++++++++++++++++++++++ autotests/testAgent/hw.conf | 7 +++ autotests/testAgent/ssid1.conf | 7 +++ autotests/testAgent/ssid2.conf | 7 +++ 4 files changed, 121 insertions(+) create mode 100644 autotests/testAgent/agent_test.py create mode 100644 autotests/testAgent/hw.conf create mode 100644 autotests/testAgent/ssid1.conf create mode 100644 autotests/testAgent/ssid2.conf diff --git a/autotests/testAgent/agent_test.py b/autotests/testAgent/agent_test.py new file mode 100644 index 00000000..80d2ce83 --- /dev/null +++ b/autotests/testAgent/agent_test.py @@ -0,0 +1,100 @@ +#!/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 +import testutil +import subprocess + +class Test(unittest.TestCase): + + def check_connection(self, wd, ssid): + + device = wd.list_devices(1)[0] + ordered_network = device.get_ordered_network(ssid, scan_if_needed=True) + + 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): + wd = IWD() + + iwctl = subprocess.Popen(['iwctl', '-P', 'secret_ssid2']) + # Let iwctl to start and register its agent. + wd.wait(2) + + self.check_connection(wd, 'ssid2') + + iwctl.terminate() + iwctl.communicate() + + IWD.clear_storage() + + def test_connection_use_own_agent_from_multiple_registered(self): + + wd = IWD() + + iwctl = subprocess.Popen(['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.terminate() + iwctl.communicate() + + IWD.clear_storage() + + @classmethod + def setUpClass(cls): + pass + + @classmethod + def tearDownClass(cls): + IWD.clear_storage() + +if __name__ == '__main__': + unittest.main(exit=True) diff --git a/autotests/testAgent/hw.conf b/autotests/testAgent/hw.conf new file mode 100644 index 00000000..53249c9c --- /dev/null +++ b/autotests/testAgent/hw.conf @@ -0,0 +1,7 @@ +[SETUP] +num_radios=3 +max_test_exec_interval_sec=40 + +[HOSTAPD] +rad0=ssid1.conf +rad1=ssid2.conf diff --git a/autotests/testAgent/ssid1.conf b/autotests/testAgent/ssid1.conf new file mode 100644 index 00000000..2416d53a --- /dev/null +++ b/autotests/testAgent/ssid1.conf @@ -0,0 +1,7 @@ +hw_mode=g +channel=1 +ssid=ssid1 + +wpa=1 +wpa_pairwise=TKIP +wpa_passphrase=secret_ssid1 diff --git a/autotests/testAgent/ssid2.conf b/autotests/testAgent/ssid2.conf new file mode 100644 index 00000000..69b4f000 --- /dev/null +++ b/autotests/testAgent/ssid2.conf @@ -0,0 +1,7 @@ +hw_mode=g +channel=1 +ssid=ssid2 + +wpa=1 +wpa_pairwise=TKIP +wpa_passphrase=secret_ssid2 -- 2.13.6