3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

autotests: Add the AP mode test

This commit is contained in:
Andrew Zaborowski 2017-10-21 01:27:22 +02:00 committed by Denis Kenzior
parent 4dba9e37dd
commit 828b8b7708
4 changed files with 145 additions and 0 deletions

5
autotests/testAP/hw.conf Normal file
View File

@ -0,0 +1,5 @@
[SETUP]
num_radios=3
[HOSTAPD]
rad0=psk-ccmp.conf

View File

@ -0,0 +1,8 @@
hw_mode=g
channel=2
ssid=TestAP1
utf8_ssid=1
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
wpa_passphrase=Password1

119
autotests/testAP/test.py Normal file
View File

@ -0,0 +1,119 @@
#! /usr/bin/python3
import unittest
import sys, os
sys.path.append('../util')
import iwd
from iwd import IWD
from iwd import PSKAgent
from iwd import NetworkType
import hostapd
import testutil
class Test(unittest.TestCase):
def client_connect(self, wd, dev):
condition = 'not obj.scanning'
wd.wait_for_object_condition(dev, condition)
if not dev.get_ordered_networks():
dev.scan()
condition = 'obj.scanning'
wd.wait_for_object_condition(dev, condition)
condition = 'not obj.scanning'
wd.wait_for_object_condition(dev, condition)
ordered_networks = dev.get_ordered_networks()
self.assertEqual(len(ordered_networks), 1)
ordered_network = ordered_networks[0]
self.assertEqual(ordered_network.name, 'TestAP1')
self.assertEqual(ordered_network.type, NetworkType.psk)
psk_agent = PSKAgent('Password1')
wd.register_psk_agent(psk_agent)
ordered_network.network_object.connect()
condition = 'obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
wd.unregister_psk_agent(psk_agent)
testutil.test_iface_operstate(dev.name)
testutil.test_ifaces_connected(list(hostapd.hostapd_map.keys())[0],
dev.name)
self.assertRaises(iwd.dbus.DBusException, dev.start_ap,
'TestAP2', 'Password2')
dev.disconnect()
condition = 'not obj.connected'
wd.wait_for_object_condition(ordered_network.network_object, condition)
def test_connection_success(self):
wd = IWD()
dev1, dev2 = wd.list_devices()
self.client_connect(wd, dev1)
dev1.start_ap('TestAP2', 'Password2')
condition = 'not obj.scanning'
wd.wait_for_object_condition(dev2, condition)
dev2.scan()
condition = 'obj.scanning'
wd.wait_for_object_condition(dev2, condition)
condition = 'not obj.scanning'
wd.wait_for_object_condition(dev2, condition)
ordered_networks = dev2.get_ordered_networks()
self.assertEqual(len(ordered_networks), 2)
networks = { n.name: n for n in ordered_networks }
self.assertEqual(networks['TestAP1'].type, NetworkType.psk)
self.assertEqual(networks['TestAP2'].type, NetworkType.psk)
psk_agent = PSKAgent('Password2')
wd.register_psk_agent(psk_agent)
try:
dev2.disconnect()
condition = 'not obj.connected'
wd.wait_for_object_condition(dev2, condition)
except:
pass
networks['TestAP2'].network_object.connect()
condition = 'obj.connected'
wd.wait_for_object_condition(networks['TestAP2'].network_object,
condition)
testutil.test_iface_operstate(dev2.name)
testutil.test_ifaces_connected(dev1.name, dev2.name)
wd.unregister_psk_agent(psk_agent)
dev2.disconnect()
condition = 'not obj.connected'
wd.wait_for_object_condition(networks['TestAP2'].network_object,
condition)
dev1.stop_ap()
# Finally test dev1 can go to client mode and connect again
self.client_connect(wd, dev1)
@classmethod
def setUpClass(cls):
pass
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
if __name__ == '__main__':
unittest.main(exit=True)

View File

@ -350,6 +350,19 @@ class Device(IWDDBusAbstract):
error_handler=self._failure)
self._wait_for_async_op()
def start_ap(self, ssid, psk):
self._iface.StartAccessPoint(ssid, psk,
dbus_interface=self._iface_name,
reply_handler=self._success,
error_handler=self._failure)
self._wait_for_async_op()
def stop_ap(self):
self._iface.StopAccessPoint(dbus_interface=self._iface_name,
reply_handler=self._success,
error_handler=self._failure)
self._wait_for_async_op()
def __str__(self, prefix = ''):
return prefix + 'Device: ' + self.device_path + '\n'\
+ prefix + '\tName:\t\t' + self.name + '\n'\