tests: test_fst_config: Convert FstLauncher to context manager
Using __del__ for any kind of cleanup is not a good idea as it's not guaranteed to be called at any particular time, it's only called whenever the next garbage collect cycle kicks in. Use a context manager instead, which basically removes the need for the try/finally and fixes the reliance on __del__. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
parent
c8e2fc1fd5
commit
fde38cac8a
1 changed files with 52 additions and 53 deletions
|
@ -111,7 +111,10 @@ class FstLauncher:
|
|||
self.reg_ctrl = fst_test_common.HapdRegCtrl()
|
||||
self.test_is_supported()
|
||||
|
||||
def __del__(self):
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
self.cleanup()
|
||||
|
||||
@staticmethod
|
||||
|
@ -303,7 +306,7 @@ def run_test_ap_configuration(apdev, test_params,
|
|||
0 - no errors discovered, an error otherwise. The function is used for
|
||||
simplek "bad configuration" tests."""
|
||||
logdir = test_params['logdir']
|
||||
fst_launcher = FstLauncher(logdir)
|
||||
with FstLauncher(logdir) as fst_launcher:
|
||||
ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_goodconf', 'a',
|
||||
fst_test_common.fst_test_def_chan_a,
|
||||
fst_test_common.fst_test_def_group,
|
||||
|
@ -326,7 +329,7 @@ def run_test_sta_configuration(test_params,
|
|||
the run: 0 - no errors discovered, an error otherwise. The function is used
|
||||
for simple "bad configuration" tests."""
|
||||
logdir = test_params['logdir']
|
||||
fst_launcher = FstLauncher(logdir)
|
||||
with FstLauncher(logdir) as fst_launcher:
|
||||
sta1 = FstLauncherConfigSTA('wlan5',
|
||||
fst_test_common.fst_test_def_group,
|
||||
fst_test_common.fst_test_def_prio_low,
|
||||
|
@ -481,7 +484,7 @@ def test_fst_scan_mb(dev, apdev, test_params):
|
|||
logdir = test_params['logdir']
|
||||
|
||||
# Test valid MB IE in scan results
|
||||
fst_launcher = FstLauncher(logdir)
|
||||
with FstLauncher(logdir) as fst_launcher:
|
||||
ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_11a', 'a',
|
||||
fst_test_common.fst_test_def_chan_a,
|
||||
fst_test_common.fst_test_def_group,
|
||||
|
@ -495,7 +498,7 @@ def test_fst_scan_mb(dev, apdev, test_params):
|
|||
res = fst_launcher.run_hostapd()
|
||||
if res != 0:
|
||||
raise Exception("hostapd didn't start properly")
|
||||
try:
|
||||
|
||||
mbie1 = []
|
||||
flags1 = ''
|
||||
mbie2 = []
|
||||
|
@ -514,8 +517,6 @@ def test_fst_scan_mb(dev, apdev, test_params):
|
|||
mbie2 = parse_ies(vals2['ie'], 0x9e)
|
||||
if 'flags' in vals2:
|
||||
flags2 = vals2['flags']
|
||||
finally:
|
||||
fst_launcher.cleanup()
|
||||
|
||||
if len(mbie1) == 0:
|
||||
raise Exception("No MB IE created by 1st AP")
|
||||
|
@ -527,7 +528,7 @@ def test_fst_scan_nomb(dev, apdev, test_params):
|
|||
logdir = test_params['logdir']
|
||||
|
||||
# Test valid MB IE in scan results
|
||||
fst_launcher = FstLauncher(logdir)
|
||||
with FstLauncher(logdir) as fst_launcher:
|
||||
ap1 = FstLauncherConfigAP(apdev[0]['ifname'], 'fst_11a', 'a',
|
||||
fst_test_common.fst_test_def_chan_a,
|
||||
fst_test_common.fst_test_def_group,
|
||||
|
@ -536,7 +537,7 @@ def test_fst_scan_nomb(dev, apdev, test_params):
|
|||
res = fst_launcher.run_hostapd()
|
||||
if res != 0:
|
||||
raise Exception("Hostapd didn't start properly")
|
||||
try:
|
||||
|
||||
time.sleep(2)
|
||||
mbie1 = []
|
||||
flags1 = ''
|
||||
|
@ -546,8 +547,6 @@ def test_fst_scan_nomb(dev, apdev, test_params):
|
|||
mbie1 = parse_ies(vals1['ie'], 0x9e)
|
||||
if 'flags' in vals1:
|
||||
flags1 = vals1['flags']
|
||||
finally:
|
||||
fst_launcher.cleanup()
|
||||
|
||||
if len(mbie1) != 0:
|
||||
raise Exception("MB IE exists with 1 AP")
|
||||
|
|
Loading…
Reference in a new issue