3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00
iwd/autotests/testScanKnownFreqs/quick_scan_test.py
Andrew Zaborowski c73575585b autotests: Remove del wd at the end function pattern
Don't use del wd to dereference the IWD instance at the end of the function
where it has been defined in the first place as at this point wd is about
to have its reference count decreased anyway (the variable's scope is
ending) so it's pointless (but didn't hurt).

Relying on the __del__ destructor to kill the IWD process in those tests
it has been started in the constructor is a bit of a hack in the first
place, because the destructor is called on garbage collection and even
through CPython does this on the refcount reaching 0, this is not
documented and there's no guideline on when it should happen or if it
should happen at all.  So it could be argued that we should keep the del
wd statemenets to be able to easily replace all of them with a call to a
new method.  But most of them are not placed so that they're guaranteed
to happen on test success or failure.  It would probably be easier to do
this and other housekeeping in a base class and make the tests its
subclasses.  Also some of these tests don't really need to launch iwd
themselves, since IWD now tracks changes in the known network files I
think IWD only really needs to be killed between tests when main.conf
changes.
2019-04-22 18:20:01 -05:00

62 lines
1.6 KiB
Python

#!/usr/bin/python3
import unittest
import sys
import time
sys.path.append('../util')
import iwd
from iwd import IWD
class Test(unittest.TestCase):
dict = {
'ssid_open_1': False,
'ssid_open_2': False,
'ssid_open_3': False,
}
def set_network(self, ssid):
if ssid not in self.dict:
return
self.dict[ssid] = True
def validate_quick_scan(self, wd):
devices = wd.list_devices(1)
device = devices[0]
# Device initiates a passive quick scan and scans only for the known
# frequencies (listed in .known_network.freq file).
condition = 'obj.scanning'
wd.wait_for_object_condition(device, condition)
condition = 'not obj.scanning'
wd.wait_for_object_condition(device, condition)
ordered_networks = device.get_ordered_networks()
for network in ordered_networks:
self.set_network(network.name)
def test_scan(self):
wd = IWD(True)
self.validate_quick_scan(wd)
# Only ssid_open_1 and ssid_open_2 should be discovered.
self.assertEqual(self.dict['ssid_open_1'], True)
self.assertEqual(self.dict['ssid_open_2'], True)
self.assertEqual(self.dict['ssid_open_3'], False)
@classmethod
def setUpClass(cls):
IWD.copy_to_storage('.known_network.freq')
IWD.copy_to_storage('ssid_open_1.open')
IWD.copy_to_storage('ssid_open_2.open')
@classmethod
def tearDownClass(cls):
IWD.clear_storage()
if __name__ == '__main__':
unittest.main(exit=True)