* [PATCH 0/2] kunit: tool: Create missing build directories and parents
@ 2026-12-05 1:17 ` Pavee Zheng via B4 Relay
0 siblings, 0 replies; 6+ messages in thread
From: Pavee Zheng @ 2026-12-05 1:17 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, Shuah Khan, Ryota Sakamoto, linux-kselftest, kunit-dev,
linux-kernel, Pavee Zheng
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@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 0/2] kunit: tool: Create missing build directories and parents
@ 2026-12-05 1:17 ` Pavee Zheng via B4 Relay
0 siblings, 0 replies; 6+ messages in thread
From: Pavee Zheng via B4 Relay @ 2026-12-05 1:17 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, Shuah Khan, Ryota Sakamoto, linux-kselftest, kunit-dev,
linux-kernel, Pavee Zheng
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@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] kunit: tool: Create missing parent directories for build_dir
2026-12-05 1:17 ` Pavee Zheng via B4 Relay
@ 2026-12-05 1:17 ` Pavee Zheng via B4 Relay
-1 siblings, 0 replies; 6+ messages in thread
From: Pavee Zheng @ 2026-12-05 1:17 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, Shuah Khan, Ryota Sakamoto, linux-kselftest, kunit-dev,
linux-kernel, Pavee Zheng
run_handler(), config_handler(), and LinuxSourceTree.build_config() use
os.mkdir() to create build_dir, which fails with FileNotFoundError when
any parent directory does not yet exist. This breaks nested --build_dir
paths (such as --build_dir=out/arm64) as well as KBUILD_OUTPUT when the
target directory has not been created yet, because kunit.py appends
.kunit to KBUILD_OUTPUT.
Replace the os.path.exists() check and os.mkdir() call with
os.makedirs(..., exist_ok=True) in run_handler(), config_handler(), and
LinuxSourceTree.build_config() so missing parent directories are created
automatically.
Update test_run_builddir_from_env to use a non-existent temporary
KBUILD_OUTPUT directory instead of /tmp, and add unit tests for nested
build_dir creation in KUnitMainTest and LinuxSourceTreeTest.
Fixes: 6ebf5866f2e8 ("kunit: tool: add Python wrappers for running KUnit tests")
Fixes: 5c7a4741431b ("kunit: respect KBUILD_OUTPUT env variable by default")
Signed-off-by: Pavee Zheng <pavee.zheng@gmail.com>
---
tools/testing/kunit/kunit.py | 8 +++-----
tools/testing/kunit/kunit_kernel.py | 4 ++--
tools/testing/kunit/kunit_tool_test.py | 35 +++++++++++++++++++++++++++++++---
3 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 6db09144d7cf..5070a831e4e8 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -523,8 +523,7 @@ def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree
def run_handler(cli_args: argparse.Namespace) -> None:
- if not os.path.exists(cli_args.build_dir):
- os.mkdir(cli_args.build_dir)
+ os.makedirs(cli_args.build_dir, exist_ok=True)
linux = tree_from_args(cli_args)
request = KunitRequest(build_dir=cli_args.build_dir,
@@ -550,9 +549,8 @@ def run_handler(cli_args: argparse.Namespace) -> None:
def config_handler(cli_args: argparse.Namespace) -> None:
- if cli_args.build_dir and (
- not os.path.exists(cli_args.build_dir)):
- os.mkdir(cli_args.build_dir)
+ if cli_args.build_dir:
+ os.makedirs(cli_args.build_dir, exist_ok=True)
linux = tree_from_args(cli_args)
request = KunitConfigRequest(build_dir=cli_args.build_dir,
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 58557c47d85f..5294786442fe 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -295,8 +295,8 @@ class LinuxSourceTree:
def build_config(self, build_dir: str, make_options: Optional[List[str]]) -> bool:
kconfig_path = get_kconfig_path(build_dir)
- if build_dir and not os.path.exists(build_dir):
- os.mkdir(build_dir)
+ if build_dir:
+ os.makedirs(build_dir, exist_ok=True)
try:
self._kconfig = self._ops.make_arch_config(self._kconfig)
self._kconfig.write_to_file(kconfig_path)
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 11b8f6dc88ae..95809cdec7d2 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -647,6 +647,18 @@ class LinuxSourceTreeTest(unittest.TestCase):
self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
mock_build_config.assert_called_once_with(build_dir, [])
+ def test_build_config_creates_nested_builddir(self):
+ with tempfile.TemporaryDirectory('') as tmpdir:
+ build_dir = os.path.join(tmpdir, 'nested', 'arm64')
+ tree = kunit_kernel.LinuxSourceTree(build_dir, kunitconfig_paths=[os.devnull])
+ tree._ops = kunit_kernel.LinuxSourceTreeOperations('none', None)
+ with mock.patch.object(tree._ops, 'make_olddefconfig') as mock_olddefconfig:
+ self.assertTrue(tree.build_config(build_dir, make_options=[]))
+ mock_olddefconfig.assert_called_once_with(build_dir, [])
+ self.assertTrue(os.path.isdir(build_dir))
+ self.assertTrue(os.path.isfile(kunit_kernel.get_kconfig_path(build_dir)))
+ self.assertTrue(os.path.isfile(kunit_kernel.get_old_kunitconfig_path(build_dir)))
+
# TODO: add more test cases.
@@ -870,15 +882,32 @@ class KUnitMainTest(unittest.TestCase):
args=None, build_dir=build_dir, filter_glob='', filter='', filter_action=None, timeout=300)
self.print_mock.assert_any_call(StrContains('Testing complete.'))
- @mock.patch.dict(os.environ, {'KBUILD_OUTPUT': '/tmp'})
def test_run_builddir_from_env(self):
- build_dir = '/tmp/.kunit'
- kunit.main(['run'])
+ with tempfile.TemporaryDirectory() as tmpdir:
+ output = os.path.join(tmpdir, 'build')
+ build_dir = os.path.join(output, '.kunit')
+ with mock.patch.dict(os.environ, {'KBUILD_OUTPUT': output}):
+ kunit.main(['run'])
+ self.assertTrue(os.path.isdir(build_dir))
self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
self.linux_source_mock.run_kernel.assert_called_once_with(
args=None, build_dir=build_dir, filter_glob='', filter='', filter_action=None, timeout=300)
self.print_mock.assert_any_call(StrContains('Testing complete.'))
+ def test_commands_create_nested_builddir(self):
+ def init_linux(build_dir, **kwargs):
+ self.assertTrue(os.path.isdir(build_dir))
+ return self.linux_source_mock
+
+ self.mock_linux_init.side_effect = init_linux
+ with tempfile.TemporaryDirectory() as tmpdir:
+ for command in ('config', 'run'):
+ with self.subTest(command=command):
+ self.mock_linux_init.reset_mock()
+ build_dir = os.path.join(tmpdir, command, 'arm64')
+ kunit.main([command, '--build_dir', build_dir])
+ self.mock_linux_init.assert_called_once()
+
@mock.patch.dict(os.environ, {'KBUILD_OUTPUT': '/tmp'})
def test_run_builddir_override(self):
build_dir = '.kunit'
--
Git-157)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 1/2] kunit: tool: Create missing parent directories for build_dir
@ 2026-12-05 1:17 ` Pavee Zheng via B4 Relay
0 siblings, 0 replies; 6+ messages in thread
From: Pavee Zheng via B4 Relay @ 2026-12-05 1:17 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, Shuah Khan, Ryota Sakamoto, linux-kselftest, kunit-dev,
linux-kernel, Pavee Zheng
From: Pavee Zheng <pavee.zheng@gmail.com>
run_handler(), config_handler(), and LinuxSourceTree.build_config() use
os.mkdir() to create build_dir, which fails with FileNotFoundError when
any parent directory does not yet exist. This breaks nested --build_dir
paths (such as --build_dir=out/arm64) as well as KBUILD_OUTPUT when the
target directory has not been created yet, because kunit.py appends
.kunit to KBUILD_OUTPUT.
Replace the os.path.exists() check and os.mkdir() call with
os.makedirs(..., exist_ok=True) in run_handler(), config_handler(), and
LinuxSourceTree.build_config() so missing parent directories are created
automatically.
Update test_run_builddir_from_env to use a non-existent temporary
KBUILD_OUTPUT directory instead of /tmp, and add unit tests for nested
build_dir creation in KUnitMainTest and LinuxSourceTreeTest.
Fixes: 6ebf5866f2e8 ("kunit: tool: add Python wrappers for running KUnit tests")
Fixes: 5c7a4741431b ("kunit: respect KBUILD_OUTPUT env variable by default")
Signed-off-by: Pavee Zheng <pavee.zheng@gmail.com>
---
tools/testing/kunit/kunit.py | 8 +++-----
tools/testing/kunit/kunit_kernel.py | 4 ++--
tools/testing/kunit/kunit_tool_test.py | 35 +++++++++++++++++++++++++++++++---
3 files changed, 37 insertions(+), 10 deletions(-)
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 6db09144d7cf..5070a831e4e8 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -523,8 +523,7 @@ def tree_from_args(cli_args: argparse.Namespace) -> kunit_kernel.LinuxSourceTree
def run_handler(cli_args: argparse.Namespace) -> None:
- if not os.path.exists(cli_args.build_dir):
- os.mkdir(cli_args.build_dir)
+ os.makedirs(cli_args.build_dir, exist_ok=True)
linux = tree_from_args(cli_args)
request = KunitRequest(build_dir=cli_args.build_dir,
@@ -550,9 +549,8 @@ def run_handler(cli_args: argparse.Namespace) -> None:
def config_handler(cli_args: argparse.Namespace) -> None:
- if cli_args.build_dir and (
- not os.path.exists(cli_args.build_dir)):
- os.mkdir(cli_args.build_dir)
+ if cli_args.build_dir:
+ os.makedirs(cli_args.build_dir, exist_ok=True)
linux = tree_from_args(cli_args)
request = KunitConfigRequest(build_dir=cli_args.build_dir,
diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py
index 58557c47d85f..5294786442fe 100644
--- a/tools/testing/kunit/kunit_kernel.py
+++ b/tools/testing/kunit/kunit_kernel.py
@@ -295,8 +295,8 @@ class LinuxSourceTree:
def build_config(self, build_dir: str, make_options: Optional[List[str]]) -> bool:
kconfig_path = get_kconfig_path(build_dir)
- if build_dir and not os.path.exists(build_dir):
- os.mkdir(build_dir)
+ if build_dir:
+ os.makedirs(build_dir, exist_ok=True)
try:
self._kconfig = self._ops.make_arch_config(self._kconfig)
self._kconfig.write_to_file(kconfig_path)
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 11b8f6dc88ae..95809cdec7d2 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -647,6 +647,18 @@ class LinuxSourceTreeTest(unittest.TestCase):
self.assertTrue(tree.build_reconfig(build_dir, make_options=[]))
mock_build_config.assert_called_once_with(build_dir, [])
+ def test_build_config_creates_nested_builddir(self):
+ with tempfile.TemporaryDirectory('') as tmpdir:
+ build_dir = os.path.join(tmpdir, 'nested', 'arm64')
+ tree = kunit_kernel.LinuxSourceTree(build_dir, kunitconfig_paths=[os.devnull])
+ tree._ops = kunit_kernel.LinuxSourceTreeOperations('none', None)
+ with mock.patch.object(tree._ops, 'make_olddefconfig') as mock_olddefconfig:
+ self.assertTrue(tree.build_config(build_dir, make_options=[]))
+ mock_olddefconfig.assert_called_once_with(build_dir, [])
+ self.assertTrue(os.path.isdir(build_dir))
+ self.assertTrue(os.path.isfile(kunit_kernel.get_kconfig_path(build_dir)))
+ self.assertTrue(os.path.isfile(kunit_kernel.get_old_kunitconfig_path(build_dir)))
+
# TODO: add more test cases.
@@ -870,15 +882,32 @@ class KUnitMainTest(unittest.TestCase):
args=None, build_dir=build_dir, filter_glob='', filter='', filter_action=None, timeout=300)
self.print_mock.assert_any_call(StrContains('Testing complete.'))
- @mock.patch.dict(os.environ, {'KBUILD_OUTPUT': '/tmp'})
def test_run_builddir_from_env(self):
- build_dir = '/tmp/.kunit'
- kunit.main(['run'])
+ with tempfile.TemporaryDirectory() as tmpdir:
+ output = os.path.join(tmpdir, 'build')
+ build_dir = os.path.join(output, '.kunit')
+ with mock.patch.dict(os.environ, {'KBUILD_OUTPUT': output}):
+ kunit.main(['run'])
+ self.assertTrue(os.path.isdir(build_dir))
self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)
self.linux_source_mock.run_kernel.assert_called_once_with(
args=None, build_dir=build_dir, filter_glob='', filter='', filter_action=None, timeout=300)
self.print_mock.assert_any_call(StrContains('Testing complete.'))
+ def test_commands_create_nested_builddir(self):
+ def init_linux(build_dir, **kwargs):
+ self.assertTrue(os.path.isdir(build_dir))
+ return self.linux_source_mock
+
+ self.mock_linux_init.side_effect = init_linux
+ with tempfile.TemporaryDirectory() as tmpdir:
+ for command in ('config', 'run'):
+ with self.subTest(command=command):
+ self.mock_linux_init.reset_mock()
+ build_dir = os.path.join(tmpdir, command, 'arm64')
+ kunit.main([command, '--build_dir', build_dir])
+ self.mock_linux_init.assert_called_once()
+
@mock.patch.dict(os.environ, {'KBUILD_OUTPUT': '/tmp'})
def test_run_builddir_override(self):
build_dir = '.kunit'
--
Git-157)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] kunit: tool: Create missing build directory before build
2026-12-05 1:17 ` Pavee Zheng via B4 Relay
@ 2026-12-05 1:17 ` Pavee Zheng via B4 Relay
-1 siblings, 0 replies; 6+ messages in thread
From: Pavee Zheng @ 2026-12-05 1:17 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, Shuah Khan, Ryota Sakamoto, linux-kselftest, kunit-dev,
linux-kernel, Pavee Zheng
Commit 1ee2ba89bea8 ("kunit: tool: make `build` subcommand also
reconfigure if needed") made kunit.py build run configuration before
building, so it can be used standalone without first running
kunit.py config. However, unlike run_handler() and config_handler(),
build_handler() does not create build_dir before calling
tree_from_args(). Because LinuxSourceTree.__init__() copies the default
.kunitconfig into build_dir when no --kunitconfig is given, running
kunit.py build on a clean checkout or with a non-existent build
directory fails with FileNotFoundError before configuring or building
the kernel.
Create cli_args.build_dir with os.makedirs(..., exist_ok=True) when
non-empty in build_handler() before calling tree_from_args(), matching
config_handler(). Extend test_commands_create_nested_builddir to cover
the build subcommand.
Fixes: 1ee2ba89bea8 ("kunit: tool: make `build` subcommand also reconfigure if needed")
Signed-off-by: Pavee Zheng <pavee.zheng@gmail.com>
---
tools/testing/kunit/kunit.py | 3 +++
tools/testing/kunit/kunit_tool_test.py | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 5070a831e4e8..312e184f1a52 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -564,6 +564,9 @@ def config_handler(cli_args: argparse.Namespace) -> None:
def build_handler(cli_args: argparse.Namespace) -> None:
+ if cli_args.build_dir:
+ os.makedirs(cli_args.build_dir, exist_ok=True)
+
linux = tree_from_args(cli_args)
request = KunitBuildRequest(build_dir=cli_args.build_dir,
make_options=cli_args.make_options,
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 95809cdec7d2..921907c5771a 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -901,7 +901,7 @@ class KUnitMainTest(unittest.TestCase):
self.mock_linux_init.side_effect = init_linux
with tempfile.TemporaryDirectory() as tmpdir:
- for command in ('config', 'run'):
+ for command in ('config', 'build', 'run'):
with self.subTest(command=command):
self.mock_linux_init.reset_mock()
build_dir = os.path.join(tmpdir, command, 'arm64')
--
Git-157)
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] kunit: tool: Create missing build directory before build
@ 2026-12-05 1:17 ` Pavee Zheng via B4 Relay
0 siblings, 0 replies; 6+ messages in thread
From: Pavee Zheng via B4 Relay @ 2026-12-05 1:17 UTC (permalink / raw)
To: Brendan Higgins, David Gow
Cc: Rae Moar, Shuah Khan, Ryota Sakamoto, linux-kselftest, kunit-dev,
linux-kernel, Pavee Zheng
From: Pavee Zheng <pavee.zheng@gmail.com>
Commit 1ee2ba89bea8 ("kunit: tool: make `build` subcommand also
reconfigure if needed") made kunit.py build run configuration before
building, so it can be used standalone without first running
kunit.py config. However, unlike run_handler() and config_handler(),
build_handler() does not create build_dir before calling
tree_from_args(). Because LinuxSourceTree.__init__() copies the default
.kunitconfig into build_dir when no --kunitconfig is given, running
kunit.py build on a clean checkout or with a non-existent build
directory fails with FileNotFoundError before configuring or building
the kernel.
Create cli_args.build_dir with os.makedirs(..., exist_ok=True) when
non-empty in build_handler() before calling tree_from_args(), matching
config_handler(). Extend test_commands_create_nested_builddir to cover
the build subcommand.
Fixes: 1ee2ba89bea8 ("kunit: tool: make `build` subcommand also reconfigure if needed")
Signed-off-by: Pavee Zheng <pavee.zheng@gmail.com>
---
tools/testing/kunit/kunit.py | 3 +++
tools/testing/kunit/kunit_tool_test.py | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 5070a831e4e8..312e184f1a52 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -564,6 +564,9 @@ def config_handler(cli_args: argparse.Namespace) -> None:
def build_handler(cli_args: argparse.Namespace) -> None:
+ if cli_args.build_dir:
+ os.makedirs(cli_args.build_dir, exist_ok=True)
+
linux = tree_from_args(cli_args)
request = KunitBuildRequest(build_dir=cli_args.build_dir,
make_options=cli_args.make_options,
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 95809cdec7d2..921907c5771a 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -901,7 +901,7 @@ class KUnitMainTest(unittest.TestCase):
self.mock_linux_init.side_effect = init_linux
with tempfile.TemporaryDirectory() as tmpdir:
- for command in ('config', 'run'):
+ for command in ('config', 'build', 'run'):
with self.subTest(command=command):
self.mock_linux_init.reset_mock()
build_dir = os.path.join(tmpdir, command, 'arm64')
--
Git-157)
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-05 1:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 1:17 [PATCH 0/2] kunit: tool: Create missing build directories and parents Pavee Zheng
2026-12-05 1:17 ` Pavee Zheng via B4 Relay
2026-12-05 1:17 ` [PATCH 1/2] kunit: tool: Create missing parent directories for build_dir Pavee Zheng
2026-12-05 1:17 ` Pavee Zheng via B4 Relay
2026-12-05 1:17 ` [PATCH 2/2] kunit: tool: Create missing build directory before build Pavee Zheng
2026-12-05 1:17 ` Pavee Zheng via B4 Relay
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.