2018-07-17 23:16:06 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
from iwd import IWD
|
2022-06-30 20:03:28 +02:00
|
|
|
from iwd import AdHocDevice
|
|
|
|
from config import ctx
|
2018-07-17 23:16:06 +02:00
|
|
|
import testutil
|
|
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
|
2022-06-30 20:03:28 +02:00
|
|
|
def validate_connection(self, wd, client=False):
|
2018-07-17 23:16:06 +02:00
|
|
|
dev1, dev2 = wd.list_devices(2)
|
|
|
|
|
|
|
|
self.assertIsNotNone(dev1)
|
|
|
|
self.assertIsNotNone(dev2)
|
|
|
|
|
2020-09-14 23:04:06 +02:00
|
|
|
adhoc1 = dev1.start_adhoc("AdHocNetwork", "secret123")
|
2018-07-17 23:16:06 +02:00
|
|
|
|
2020-09-14 23:04:06 +02:00
|
|
|
condition = 'obj.started == True'
|
|
|
|
wd.wait_for_object_condition(adhoc1, condition)
|
|
|
|
|
2022-06-30 20:03:28 +02:00
|
|
|
if not client:
|
|
|
|
adhoc2 = dev2.start_adhoc("AdHocNetwork", "secret123")
|
|
|
|
else:
|
|
|
|
ctx.start_process(['iwctl', 'device', dev2.name, 'set-property',
|
|
|
|
'Mode', 'ad-hoc'], check=True)
|
|
|
|
ctx.start_process(['iwctl', 'ad-hoc', dev2.name, 'start',
|
|
|
|
'AdHocNetwork', 'secret123'], check=True)
|
|
|
|
adhoc2 = AdHocDevice(dev2.device_path)
|
2020-09-14 23:04:06 +02:00
|
|
|
|
|
|
|
condition = 'obj.started == True'
|
|
|
|
wd.wait_for_object_condition(adhoc1, condition)
|
|
|
|
|
|
|
|
condition = '"%s" in obj.connected_peers' % dev2.address
|
|
|
|
wd.wait_for_object_condition(adhoc1, condition)
|
|
|
|
|
|
|
|
condition = '"%s" in obj.connected_peers' % dev1.address
|
|
|
|
wd.wait_for_object_condition(adhoc2, condition)
|
2018-07-17 23:16:06 +02:00
|
|
|
|
|
|
|
testutil.test_iface_operstate(dev1.name)
|
|
|
|
testutil.test_iface_operstate(dev2.name)
|
|
|
|
testutil.test_ifaces_connected(dev1.name, dev2.name)
|
|
|
|
|
2019-03-15 22:48:56 +01:00
|
|
|
def test_connection_success(self):
|
|
|
|
wd = IWD(True)
|
|
|
|
|
2019-04-20 22:29:05 +02:00
|
|
|
self.validate_connection(wd)
|
2018-10-19 20:39:38 +02:00
|
|
|
|
2022-06-30 20:03:28 +02:00
|
|
|
def test_client_adhoc(self):
|
|
|
|
wd = IWD(True)
|
|
|
|
self.validate_connection(wd, client=True)
|
|
|
|
|
2018-07-17 23:16:06 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
IWD.clear_storage()
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|