3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +01:00

test-runner: start HostapdCLI from test-runner

This gives the benefit of test-runner itself having access to
the CLI, e.g. for getting status information.
This commit is contained in:
James Prestwood 2021-08-12 16:12:30 -07:00 committed by Denis Kenzior
parent c7466cd56a
commit 57933425ca
2 changed files with 43 additions and 3 deletions

View File

@ -42,6 +42,24 @@ class HostapdCLI:
hapd = ctx.hostapd[config]
if not hasattr(self, '_hostapd_restarted'):
self._hostapd_restarted = False
#
# TODO: In theory some type of instance singleton could be created for
# HostapdCLI where test-runner initializes but any subsequent
# call to HostapdCLI (with the same config) returns the same
# object that test-runner has. This would avoid setting these
# variables.
#
if hapd.cli:
self.ifname = hapd.cli.ifname
self.ctrl_sock = hapd.cli.ctrl_sock
self.cmdline = hapd.cli.cmdline
self.interface = hapd.intf
self.config = hapd.config
return
self.interface = hapd.intf
self.config = hapd.config
@ -53,9 +71,6 @@ class HostapdCLI:
self.cmdline = ['hostapd_cli', '-p', self.socket_path, '-i', self.ifname]
if not hasattr(self, '_hostapd_restarted'):
self._hostapd_restarted = False
self.local_ctrl = '/tmp/hostapd_' + str(os.getpid()) + '_' + \
str(ctrl_count)
self.ctrl_sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
@ -244,3 +259,14 @@ class HostapdCLI:
bssid = [x for x in status if x.startswith('bssid')]
bssid = bssid[0].split('=')
return bssid[1]
@property
def frequency(self):
cmd = self.cmdline + ['status']
status = ctx.start_process(cmd, wait=True, need_out=True).out
status = status.split('\n')
frequency = [x for x in status if x.startswith('freq')][0]
frequency = frequency.split('=')[1]
return int(frequency)

View File

@ -428,6 +428,7 @@ class HostapdInstance:
def __init__(self, config, radio):
self.radio = radio
self.config = config
self.cli = None
self.intf = radio.create_interface(self.config, 'hostapd')
self.intf.set_interface_state('up')
@ -494,6 +495,10 @@ class Hostapd:
self.process.wait_for_socket(self.global_ctrl_iface, 30)
def attach_cli(self):
for hapd in self.instances:
hapd.cli = importlib.import_module('hostapd').HostapdCLI(config=hapd.config)
def _rewrite_config(self, config):
'''
Replaces any $ifaceN values with the correct interface
@ -841,6 +846,15 @@ class TestContext(Namespace):
radius_config = settings.get('radius_server', None)
self.hostapd = Hostapd(self, hapd_radios, hapd_configs, radius_config)
self.hostapd.attach_cli()
def get_frequencies(self):
frequencies = []
for hapd in self.hostapd.instances:
frequencies.append(hapd.cli.frequency)
return frequencies
def start_wpas_interfaces(self):
if 'WPA_SUPPLICANT' not in self.hw_config: