commit 57933425ca3b1542dfd555f37e41af0fe21e15b6
parent c7466cd56a82e405ef9c3be32d81a53a624fded2
Author: James Prestwood <prestwoj@gmail.com>
Date: Thu, 12 Aug 2021 16:12:30 -0700
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.
Diffstat:
2 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py
@@ -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)
diff --git a/tools/test-runner b/tools/test-runner
@@ -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: