diff mbox series

[2/3] test-runner: allow hwsim in namespaces

Message ID 20230504215247.581443-2-prestwoj@gmail.com (mailing list archive)
State New
Headers show
Series [1/3] hwsim: remove 'optimization' sending to only known MACs | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood May 4, 2023, 9:52 p.m. UTC
Starts the hwsim daemon per-namespace rather than only in the
root namespace.
---
 tools/run-tests | 16 ++++++++--------
 tools/utils.py  | 13 ++++++++++++-
 2 files changed, 20 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/tools/run-tests b/tools/run-tests
index 32c09723..ef316666 100755
--- a/tools/run-tests
+++ b/tools/run-tests
@@ -319,6 +319,7 @@  class TestContext(Namespace):
 		self.namespaces = []
 		self._last_mem_available = 0
 		self._mem_chart = BarChart()
+		self.register_hwsim = False;
 
 	def start_dbus_monitor(self):
 		if not Process.is_verbose('dbus-monitor'):
@@ -329,18 +330,16 @@  class TestContext(Namespace):
 	def start_haveged(self):
 		self.start_process(['haveged', '-F'])
 
+	def start_hwsim(self):
+		self.register_hwsim = self.hw_config['SETUP'].get('hwsim_medium', 'no') in ['no', '0', 'false']
+
+		super().start_hwsim(self.register_hwsim)
+
 	def create_radios(self):
 		setup = self.hw_config['SETUP']
 		nradios = int(setup['num_radios'])
 		args = ['hwsim']
 
-		if self.hw_config['SETUP'].get('hwsim_medium', 'no') in ['no', '0', 'false']:
-			# register hwsim as medium
-			args.extend(['--no-register'])
-
-		proc = self.start_process(args)
-		proc.wait_for_service(self, 'net.connman.hwsim', 20)
-
 		for i in range(nradios):
 			name = 'rad%u' % i
 
@@ -524,7 +523,7 @@  class TestContext(Namespace):
 			# Remove radios from 'root' namespace
 			self.radios = list(set(self.radios) - set(radios))
 
-			self.namespaces.append(Namespace(self.args, key, radios))
+			self.namespaces.append(Namespace(self.args, key, radios, self.register_hwsim))
 
 	def get_namespace(self, ns):
 		for n in self.namespaces:
@@ -865,6 +864,7 @@  def pre_test(ctx, test, copied):
 	ctx.start_dbus()
 	ctx.start_haveged()
 	ctx.start_dbus_monitor()
+	ctx.start_hwsim()
 	ctx.start_radios()
 	ctx.create_namespaces()
 	ctx.start_hostapd()
diff --git a/tools/utils.py b/tools/utils.py
index a07c3183..d2e1c33b 100644
--- a/tools/utils.py
+++ b/tools/utils.py
@@ -320,7 +320,7 @@  busconfig.dtd\">
 '''
 
 class Namespace:
-	def __init__(self, args, name, radios):
+	def __init__(self, args, name, radios, hwsim_register=False):
 		self.dbus_address = None
 		self.name = name
 		self.radios = radios
@@ -331,6 +331,7 @@  class Namespace:
 			r.set_namespace(self)
 
 		self.start_dbus()
+		self.start_hwsim(register=hwsim_register)
 
 	def reset(self):
 		self._bus = None
@@ -458,6 +459,16 @@  class Namespace:
 
 		return proc
 
+	def start_hwsim(self, register=False):
+		args = ['hwsim']
+
+		if register:
+			# register hwsim as medium
+			args.extend(['--no-register'])
+
+		proc = self.start_process(args)
+		proc.wait_for_service(self, 'net.connman.hwsim', 20)
+
 	@staticmethod
 	def non_block_wait(func, timeout, *args, exception=True):
 		'''