[PATCH 0/2] kunit: tool: Create missing build directories and parents
From: Pavee Zheng via B4 Relay
Date: Fri Dec 04 2026 - 20:17:28 EST
This 2-patch series fixes two build-directory creation issues in kunit.py
and kunit_kernel.py:
1. run_handler(), config_handler(), and LinuxSourceTree.build_config()
use os.mkdir(), which fails with FileNotFoundError when any parent
directory does not yet exist (for example with nested --build_dir
paths or a not-yet-created KBUILD_OUTPUT directory). Patch 1 switches
them to os.makedirs(..., exist_ok=True) while keeping run_handler()'s
existing fail-fast behavior for empty --build_dir=.
2. build_handler() does not create build_dir before tree_from_args()
copies the default .kunitconfig into build_dir, so running
kunit.py build on a clean checkout or with a missing build directory
fails with FileNotFoundError before configuring or building. Patch 2
creates non-empty build_dir with os.makedirs(..., exist_ok=True)
before calling tree_from_args() in build_handler().
Verification:
- python3 tools/testing/kunit/kunit_tool_test.py: 96/96 tests pass on
Patch 1 alone and 96/96 tests pass on Patch 1+2 (up from 94 on
shuah/kunit; tested on Python 3.9.6 and Python 3.11.2).
- End-to-end arm64 build and QEMU boot (Linux aarch64 container, GCC
12.2.0, QEMU 7.2.22, Python 3.11.2):
- Clean-tree kunit.py build --arch=arm64 creates .kunit and builds
.kunit/arch/arm64/boot/Image.gz cleanly.
- Fresh nested KBUILD_OUTPUT=ci/arm64 kunit.py config --arch=arm64
creates ci/arm64/.kunit/.config with CONFIG_KUNIT=y, and a second
config run preserves a customized .kunitconfig while regenerating
.config.
- Fresh nested KBUILD_OUTPUT=/tmp/kunit-run-out/arm64 kunit.py run
--arch=arm64 --kunitconfig=lib/kunit builds and boots QEMU cleanly
(Ran 95 tests: passed: 89, skipped: 6, failed: 0, crashed: 0).
- Isolated CLI reproducer matrix (stub make stopping at olddefconfig)
verified across shuah/kunit, Patch 1, and Patch 2 covering build,
KBUILD_OUTPUT=out config, KBUILD_OUTPUT=out/sub run,
run --build_dir=nested/dir, build --build_dir=nested/dir, fail-fast
run --build_dir=, and exec --build_dir=missing/dir (no dirs created).
- scripts/checkpatch.pl --strict: 0 errors, 0 warnings, 0 checks on
each patch and on the full series.
- Limitations: mypy and pytype are unavailable in the local host and
container environments, and UML execution was not run.
An AI coding assistant helped refine the code, tests, commit messages,
and cover letter, and ran the checks above.
---
Pavee Zheng (2):
kunit: tool: Create missing parent directories for build_dir
kunit: tool: Create missing build directory before build
tools/testing/kunit/kunit.py | 11 ++++++-----
tools/testing/kunit/kunit_kernel.py | 4 ++--
tools/testing/kunit/kunit_tool_test.py | 35 +++++++++++++++++++++++++++++++---
3 files changed, 40 insertions(+), 10 deletions(-)
---
base-commit: 79cffdf134300a8c0e95e26224691263477b5f15
change-id: 20261205-patch-kunit-build-dir-71cfccf32b5c
Best regards,
--
Pavee Zheng <pavee.zheng@xxxxxxxxx>