diff mbox series

[2/3] test-runner: set up environment with --start

Message ID 20220719181647.452178-2-prestwoj@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series [1/3] test-runner: allow infinite process wait | expand

Checks

Context Check Description
tedd_an/pre-ci_am fail error: patch failed: tools/run-tests:1011 error: tools/run-tests: patch does not apply error: patch failed: tools/runner.py:197 error: tools/runner.py: patch does not apply hint: Use 'git am --show-current-patch' to see the failed patch

Commit Message

James Prestwood July 19, 2022, 6:16 p.m. UTC
The --start option was directly passed to the kernel init parameter,
preventing any environment setup from happening.

Intead always use 'run-tests' as the init process but detect --start
and execute that binary/script once inside the environment. This also
starts dbus, and sets the right dbus address for any processes started
by the --start script.
---
 tools/run-tests | 12 +++++++++++-
 tools/runner.py | 24 ++++++++++++++----------
 2 files changed, 25 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/tools/run-tests b/tools/run-tests
index 565847df..f59c71fe 100755
--- a/tools/run-tests
+++ b/tools/run-tests
@@ -1011,5 +1011,15 @@  runner = Runner()
 
 atexit.register(exit_vm)
 runner.prepare_environment()
-run_tests(runner.args)
+
+if runner.args.start:
+	ctx = TestContext(runner.args)
+	ctx.start_dbus()
+	os.chdir(runner.args.testhome)
+	os.environ['DBUS_SYSTEM_BUS_ADDRESS'] = ctx.dbus_address
+
+	subprocess.run([runner.args.start])
+else:
+	run_tests(runner.args)
+
 runner.cleanup_environment()
diff --git a/tools/runner.py b/tools/runner.py
index d39b560f..cf904412 100644
--- a/tools/runner.py
+++ b/tools/runner.py
@@ -197,14 +197,6 @@  class Runner:
 			else:
 				args.testhome = os.getcwd()
 
-		if args.start is None:
-			if os.path.exists('run-tests'):
-				args.start = os.path.abspath('run-tests')
-			elif os.path.exists('tools/run-tests'):
-				args.start = os.path.abspath('tools/run-tests')
-			else:
-				raise Exception("Cannot locate run-tests binary")
-
 		# If no runner is specified but we have a kernel image assume
 		# if the kernel is executable its UML, otherwise qemu
 		if not args.runner:
@@ -231,6 +223,16 @@  class RunnerAbstract:
 	def __init__(self, args):
 		self.args = args
 
+		if len(sys.argv) <= 1:
+			return
+
+		if os.path.exists('run-tests'):
+			self.init = os.path.abspath('run-tests')
+		elif os.path.exists('tools/run-tests'):
+			self.init = os.path.abspath('tools/run-tests')
+		else:
+			raise Exception("Cannot locate run-tests binary")
+
 	def start(self):
 		print("Starting %s" % self.name)
 		os.execlpe(self.cmdline[0], *self.cmdline, self.env)
@@ -279,6 +281,8 @@  class RunnerAbstract:
 
 		fcntl.ioctl(STDIN_FILENO, TIOCSTTY, 1)
 
+		os.system('ip link set dev lo up')
+
 	def cleanup_environment(self):
 		rmtree('/tmp/iwd')
 		rmtree('/tmp/certs')
@@ -413,7 +417,7 @@  class QemuRunner(RunnerAbstract):
 				rootflags=trans=virtio \
 				acpi=off pci=noacpi %s ro \
 				mac80211_hwsim.radios=0 init=%s %s' %
-						(kern_log, args.start, args.to_cmd()),
+						(kern_log, self.init, args.to_cmd()),
 		]
 
 		# Add two ethernet devices for testing EAD
@@ -516,7 +520,7 @@  class UmlRunner(RunnerAbstract):
 
 		cmd = [args.kernel, 'rootfstype=hostfs', 'ro', 'mem=256M', 'mac80211_hwsim.radios=0',
 				'time-travel=inf-cpu', 'eth0=mcast', 'eth1=mcast',
-				'%s '% kern_log, 'init=%s' % args.start]
+				'%s' % kern_log, 'init=%s' % self.init]
 		cmd.extend(args.to_cmd().split(' '))
 
 		self.cmdline = cmd