test: take extra mkosi options from TEST_MKOSI_ARGS

Add a TEST_MKOSI_ARGS environment variable whose contents are appended
to the mkosi invocation launching the test image, without affecting the
image build. This lets the environment adapt how tests are run, e.g.
pass --format=directory --output-dir=... to boot the test container
from a directory format output in environments that cannot dissect disk
images, such as unprivileged containers, where loop devices and udev
are not available.

Signed-off-by: Paul Meyer <katexochen0@gmail.com>
This commit is contained in:
Paul Meyer
2026-08-27 10:00:30 +02:00
parent 3904661440
commit 5d8191da48
2 changed files with 16 additions and 0 deletions
+9
View File
@@ -120,6 +120,15 @@ rerun the test.
`TEST_NO_KVM=1`: Disable qemu KVM auto-detection (may be necessary when you're
trying to run the *vanilla* qemu and have both qemu and qemu-kvm installed)
`TEST_MKOSI_ARGS=options`: Extra options (split like a shell command line)
passed to the `mkosi` invocation that launches the test image, without
affecting the image build. Only the `--option=value` syntax is accepted. For example,
`TEST_MKOSI_ARGS="--format=directory --output-dir=build/mkosi.output.dir"`
boots the test container from a directory format output (which has to be built
beforehand, into a separate output directory), allowing boot mode tests to run
in environments that can't dissect disk images, such as unprivileged
containers, where loop devices and udev are not available.
`TEST_MATCH_SUBTEST=subtest`: If the test makes use of `run_subtests` use this
variable to provide a POSIX extended regex to run only subtests matching the
expression.
@@ -670,6 +670,12 @@ def main() -> None:
'''
)
# Extra mkosi options for this invocation only. Each has to use the '--option=value' syntax.
test_mkosi_args = shlex.split(os.getenv('TEST_MKOSI_ARGS', ''))
for arg in test_mkosi_args:
if not re.fullmatch('--[^=]+=.*', arg):
sys.exit(f"TEST_MKOSI_ARGS must contain only '--option=value' mkosi options, got: {arg}")
cmd = [
args.mkosi,
'--directory', os.fspath(args.mkosi_dir),
@@ -713,6 +719,7 @@ def main() -> None:
),
'--credential', f"journal.storage={'persistent' if sys.stdin.isatty() else args.storage}",
*(['--runtime-build-sources=no', '--register=no'] if not sys.stdin.isatty() else []),
*test_mkosi_args,
'vm' if vm else 'boot',
*(
[