Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kunit: respect KBUILD_OUTPUT env variable by default

Currently, kunit.py ignores the KBUILD_OUTPUT env variable and always
defaults to .kunit in the working directory. This behavior is inconsistent
with standard Kbuild behavior, where KBUILD_OUTPUT defines the build
artifact location.

This patch modifies kunit.py to respect KBUILD_OUTPUT if set. A .kunit
subdirectory is created inside KBUILD_OUTPUT to avoid polluting the build
directory.

Link: https://lore.kernel.org/r/20260106-kunit-kbuild_output-v2-1-582281797343@gmail.com
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Ryota Sakamoto <sakamo.ryota@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Ryota Sakamoto and committed by
Shuah Khan
5c7a4741 a7a81655

+25 -1
+6 -1
tools/testing/kunit/kunit.py
··· 323 323 return ncpu 324 324 raise RuntimeError("os.cpu_count() returned None") 325 325 326 + def get_default_build_dir() -> str: 327 + if 'KBUILD_OUTPUT' in os.environ: 328 + return os.path.join(os.environ['KBUILD_OUTPUT'], '.kunit') 329 + return '.kunit' 330 + 326 331 def add_common_opts(parser: argparse.ArgumentParser) -> None: 327 332 parser.add_argument('--build_dir', 328 333 help='As in the make command, it specifies the build ' 329 334 'directory.', 330 - type=str, default='.kunit', metavar='DIR') 335 + type=str, default=get_default_build_dir(), metavar='DIR') 331 336 parser.add_argument('--make_options', 332 337 help='X=Y make option, can be repeated.', 333 338 action='append', metavar='X=Y')
+19
tools/testing/kunit/kunit_tool_test.py
··· 601 601 all_passed_log = file.readlines() 602 602 603 603 self.print_mock = mock.patch('kunit_printer.Printer.print').start() 604 + mock.patch.dict(os.environ, clear=True).start() 604 605 self.addCleanup(mock.patch.stopall) 605 606 606 607 self.mock_linux_init = mock.patch.object(kunit_kernel, 'LinuxSourceTree').start() ··· 717 716 self.print_mock.assert_any_call(StrContains('Testing complete.')) 718 717 719 718 def test_run_builddir(self): 719 + build_dir = '.kunit' 720 + kunit.main(['run', '--build_dir=.kunit']) 721 + self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1) 722 + self.linux_source_mock.run_kernel.assert_called_once_with( 723 + args=None, build_dir=build_dir, filter_glob='', filter='', filter_action=None, timeout=300) 724 + self.print_mock.assert_any_call(StrContains('Testing complete.')) 725 + 726 + @mock.patch.dict(os.environ, {'KBUILD_OUTPUT': '/tmp'}) 727 + def test_run_builddir_from_env(self): 728 + build_dir = '/tmp/.kunit' 729 + kunit.main(['run']) 730 + self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1) 731 + self.linux_source_mock.run_kernel.assert_called_once_with( 732 + args=None, build_dir=build_dir, filter_glob='', filter='', filter_action=None, timeout=300) 733 + self.print_mock.assert_any_call(StrContains('Testing complete.')) 734 + 735 + @mock.patch.dict(os.environ, {'KBUILD_OUTPUT': '/tmp'}) 736 + def test_run_builddir_override(self): 720 737 build_dir = '.kunit' 721 738 kunit.main(['run', '--build_dir=.kunit']) 722 739 self.assertEqual(self.linux_source_mock.build_reconfig.call_count, 1)