state_change_test.py (3359B)
1 #!/usr/bin/python3 2 3 import unittest 4 import sys 5 6 sys.path.append('../util') 7 from iwd import IWD, SharedCodeAgent, DeviceState 8 from iwd import DeviceProvisioning 9 from wpas import Wpas 10 from hostapd import HostapdCLI 11 from hwsim import Hwsim 12 from config import ctx 13 from time import time 14 import os 15 16 class Test(unittest.TestCase): 17 def auto_connect(self): 18 IWD.copy_to_storage('ssidCCMP.psk') 19 self.device.autoconnect = True 20 21 condition = 'obj.state == DeviceState.connected' 22 self.wd.wait_for_object_condition(self.device, condition) 23 24 def test_configurator_stops_on_disconnect(self): 25 self.auto_connect() 26 27 self.device.dpp_start_configurator() 28 29 self.device.disconnect() 30 31 condition = 'obj.state == DeviceState.disconnected' 32 self.wd.wait_for_object_condition(self.device, condition) 33 34 self.assertEqual(self.device._device_provisioning.started, False) 35 36 def test_enrollee_stops_on_connect(self): 37 # Scan to get a list of networks 38 self.device.scan() 39 self.wd.wait_for_object_condition(self.device, 'obj.scanning == True') 40 self.wd.wait_for_object_condition(self.device, 'obj.scanning == False') 41 42 self.device.dpp_start_enrollee() 43 44 network = self.device.get_ordered_network("ssidCCMP") 45 network.network_object.connect() 46 47 condition = 'obj.state == DeviceState.connected' 48 self.wd.wait_for_object_condition(self.device, condition) 49 50 self.assertEqual(self.device._device_provisioning.started, False) 51 52 def test_enrollee_disconnects_automatically(self): 53 self.auto_connect() 54 55 self.device.dpp_start_enrollee() 56 57 condition = 'obj.state == DeviceState.disconnected' 58 self.wd.wait_for_object_condition(self.device, condition) 59 60 def test_enrollee_autoconnect_stays_on(self): 61 # Put in an autoconnecting state, no saved profile though 62 self.device.autoconnect = True 63 64 self.device.dpp_start_enrollee() 65 66 # DPP should set autoconnect false, but then re-enable after it stops 67 self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False") 68 self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True") 69 70 # Stop DPP 71 self.device.dpp_stop() 72 self.wd.wait_for_object_condition(self.device, "obj.autoconnect == True") 73 74 def test_enrollee_autoconnect_stays_off(self): 75 # Autoconnect should be off by default 76 77 self.device.dpp_start_enrollee() 78 79 # DPP should set autoconnect false, but stay off after it stops 80 self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False") 81 self.wd.wait_for_object_condition(self.device._device_provisioning, "obj.started == True") 82 83 # Stop DPP 84 self.device.dpp_stop() 85 self.wd.wait_for_object_condition(self.device, "obj.autoconnect == False") 86 87 def setUp(self): 88 self.wd = IWD(True) 89 self.device = self.wd.list_devices(1)[0] 90 91 def tearDown(self): 92 self.wd.stop() 93 self.wd = None 94 95 @classmethod 96 def setUpClass(cls): 97 hapd = HostapdCLI(config="hostapd.conf") 98 hapd.reload() 99 100 hapd.wait_for_event("AP-ENABLED") 101 102 @classmethod 103 def tearDownClass(cls): 104 pass 105 106 if __name__ == '__main__': 107 unittest.main(exit=True)