test-runner: allow infinite process wait
PATCH 1/3 test-runner: allow infinite process wait
subprocess.Popen's wait() method was overwritten to be non-blocking but in certain circumstances you do want to wait forever. Fix this to allow timeout=None, which calls the parent wait() method directly.
--- tools/utils.py | 4 ++++ 1 file changed, 4 insertions(+)
tools/utils.py +4 -0
@@ -246,6 +246,10 @@ class Process(subprocess.Popen): # Override wait() so it can do so non-blocking def wait(self, timeout=10): + if timeout == None: + super().wait() + return + Namespace.non_block_wait(self.__wait, timeout, 1) self._cleanup()
Signature · 1 line
2.34.1
PATCH 2/3 test-runner: set up environment with --start
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(-)
tools/run-tests +11 -1
@@ -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()
tools/runner.py +14 -10
@@ -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
Signature · 1 line
2.34.1
PATCH 3/3 test-runner: automatically find PCI passthrough config
In reply to James PrestwoodWhen PCI adapters are properly configured they should exist in the vfio-pci system tree. It is assumed any devices configured as such are used for test-runner.
This removes the need for a hw.conf file to be supplied, but still is required for USB adapters. Because of this the --hw option was updated to allow no value, or a file path.
--- tools/runner.py | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-)
tools/runner.py +32 -10
@@ -115,6 +115,9 @@ class RunnerCoreArgParse(ArgumentParser): help='Writes PASS/FAIL to results file') self.add_argument('--hw', '-w', type=str, + nargs='?', + const=True, + action='store', help='Use physical adapters for tests (passthrough)') self.add_argument('--testhome', help=SUPPRESS) self.add_argument('--monitor-parent', help=SUPPRESS)
@@ -381,18 +384,18 @@ class QemuRunner(RunnerAbstract): self._prepare_outfiles() if args.hw: - hw_conf = ConfigParser() - hw_conf.read(args.hw) + if os.path.isfile(args.hw): + hw_conf = ConfigParser() + hw_conf.read(args.hw) - if hw_conf.has_section('USBAdapters'): - # The actual key name of the adapter - # doesn't matter since all we need is the - # bus/address. This gets named by the kernel - # anyways once in the VM. - usb_adapters = [v for v in hw_conf['USBAdapters'].values()] + if hw_conf.has_section('USBAdapters'): + # The actual key name of the adapter + # doesn't matter since all we need is the + # bus/address. This gets named by the kernel + # anyways once in the VM. + usb_adapters = [v for v in hw_conf['USBAdapters'].values()] - if hw_conf.has_section('PCIAdapters'): - pci_adapters = [v for v in hw_conf['PCIAdapters'].values()] + pci_adapters = self._find_pci_adapters() kern_log = "ignore_loglevel" if "kernel" in args.verbose else "quiet"
@@ -472,6 +475,25 @@ class QemuRunner(RunnerAbstract): self.cmdline = qemu_cmdline + def _find_pci_adapters(self): + adapters = [] + + try: + files = os.listdir('/sys/module/vfio_pci/drivers/pci:vfio-pci') + except: + return None + + for bus_addr in files: + if not bus_addr.startswith('0000:'): + continue + + adapters.append(bus_addr.replace('0000:', '')) + + if len(adapters) == 0: + return None + + return adapters + def prepare_environment(self): mounts = [ MountInfo('debugfs', 'debugfs', '/sys/kernel/debug', '', 0) ]
Signature · 1 line
2.34.1