linux-next: manual merge of the kunit-next tree with the kunit-fixes tree
Subsystems (2)
Mark Brown
maintainerHi all,
[I note that Shuah is the only contact listed for the KUnit trees, is that right?]
Today's linux-next merge of the kunit-next tree got a conflict in:
tools/testing/kunit/kunit_tool_test.py
between commit:
40804c4974b8d ("kunit: tool: copy caller args in run_kernel to prevent mutation")
from the kunit-fixes tree and commit:
7e331b560a76d ("kunit: tool: skip stty when stdin is not a tty")
from the kunit-next tree.
I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.
[Sorry, forgot to diff - it's a simple add/add.]
David Gow
maintainerLe 03/03/2026 à 10:00 PM, Mark Brown a écrit :
Quoted 19 lines
Hi all,
[I note that Shuah is the only contact listed for the KUnit trees, is that right?]
Today's linux-next merge of the kunit-next tree got a conflict in:
tools/testing/kunit/kunit_tool_test.pybetween commit:
40804c4974b8d("kunit: tool: copy caller args inrun_kernelto prevent mutation")from the kunit-fixes tree and commit:
7e331b560a76d("kunit: tool: skip stty when stdin is not a tty")from the kunit-next tree.
Quoted 8 lines
I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.
[Sorry, forgot to diff - it's a simple add/add.]
Thanks, Mark. Shuah is definitely the right contact, given the KUnit branches live in the kselftest trees, but I won't object to being CCed as well. :-)
Shuah: I suspect the simplest resolution here is just to rebase the kunit branch on top of kunit-fixes. But it wouldn't be a problem if you wanted to shunt the stty fix into kunit-fixes instead (though that'd still require a rebase for the SIGINT handling patch).
Cheers,
-- David
Quoted 27 lines · David Gow
Le 03/03/2026 à 10:00 PM, Mark Brown a écrit :
Quoted 26 lines
Hi all,
[I note that Shuah is the only contact listed for the KUnit trees, is that right?]
Today's linux-next merge of the kunit-next tree got a conflict in:
tools/testing/kunit/kunit_tool_test.pybetween commit:
40804c4974b8d("kunit: tool: copy caller args inrun_kernelto prevent mutation")from the kunit-fixes tree and commit:
7e331b560a76d("kunit: tool: skip stty when stdin is not a tty")from the kunit-next tree.
I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts.
Quoted 7 lines
Quoted 1 line
[Sorry, forgot to diff - it's a simple add/add.]
Thanks, Mark. Shuah is definitely the right contact, given the KUnit branches live in the kselftest trees, but I won't object to being CCed as well. :-)
Shuah: I suspect the simplest resolution here is just to rebase the kunit branch on top of kunit-fixes. But it wouldn't be a problem if you wanted to shunt the stty fix into kunit-fixes instead (though that'd still require a rebase for the SIGINT handling patch).
Apologies - this got buried in my inbox.
Mark, Can you send me the diff for the fix you put in..
thanks,
-- Shuah
Mark Brown
maintainerQuoted 3 lines · Shuah Khan
Apologies - this got buried in my inbox.
Mark, Can you send me the diff for the fix you put in..
commit b0fac824fa7047bc4e71e2f40d005f40ca03b3e5
Merge: e12aa2398ae4 fa2c3ed5f079
Author: Mark Brown <[email protected]>
Date: Tue Mar 31 13:54:54 2026 +0100
Merge branch 'kunit' of https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
# Conflicts:
# tools/testing/kunit/kunit_tool_test.py
tools/testing/kunit/kunit_kernel.py +0 -0
@@@ -345,11 -346,15 +346,17 @@@ class LinuxSourceTree return False return self.validate_config(build_dir) + def _restore_terminal_if_tty(self) -> None: + # stty requires a controlling terminal; skip headless runs. + if sys.stdin is None or not sys.stdin.isatty(): + return + subprocess.call(['stty', 'sane']) + def run_kernel(self, args: Optional[List[str]]=None, build_dir: str='', filter_glob: str='', filter: str='', filter_action: Optional[str]=None, timeout: Optional[int]=None) -> Iterator[str]: - if not args: - args = [] + # Copy to avoid mutating the caller-supplied list. exec_tests() reuses + # the same args across repeated run_kernel() calls (e.g. --run_isolated), + # so appending to the original would accumulate stale flags on each call. + args = list(args) if args else [] if filter_glob: args.append('kunit.filter_glob=' + filter_glob) if filter:
tools/testing/kunit/kunit_tool_test.py +0 -0
@@@ -503,32 -503,48 +503,74 @@@ class LinuxSourceTreeTest(unittest.Test with open(kunit_kernel.get_outfile_path(build_dir), 'rt') as outfile: self.assertEqual(outfile.read(), 'hi\nbye\n', msg='Missing some output') + def test_run_kernel_args_not_mutated(self): + """Verify run_kernel() copies args so callers can reuse them.""" + start_calls = [] + + def fake_start(start_args, unused_build_dir): + start_calls.append(list(start_args)) + return subprocess.Popen(['printf', 'KTAP version 1\n'], + text=True, stdout=subprocess.PIPE) + + with tempfile.TemporaryDirectory('') as build_dir: + tree = kunit_kernel.LinuxSourceTree(build_dir, + kunitconfig_paths=[os.devnull]) + with mock.patch.object(tree._ops, 'start', side_effect=fake_start), \ + mock.patch.object(kunit_kernel.subprocess, 'call'): + kernel_args = ['mem=1G'] + for _ in tree.run_kernel(args=kernel_args, build_dir=build_dir, + filter_glob='suite.test1'): + pass + for _ in tree.run_kernel(args=kernel_args, build_dir=build_dir, + filter_glob='suite.test2'): + pass + self.assertEqual(kernel_args, ['mem=1G'], + 'run_kernel() should not modify caller args') + self.assertIn('kunit.filter_glob=suite.test1', start_calls[0]) + self.assertIn('kunit.filter_glob=suite.test2', start_calls[1]) + + def test_run_kernel_skips_terminal_reset_without_tty(self): + def fake_start(unused_args, unused_build_dir): + return subprocess.Popen(['printf', 'KTAP version 1\n'], + text=True, stdout=subprocess.PIPE) + + non_tty_stdin = mock.Mock() + non_tty_stdin.isatty.return_value = False + + with tempfile.TemporaryDirectory('') as build_dir: + tree = kunit_kernel.LinuxSourceTree(build_dir, kunitconfig_paths=[os.devnull]) + with mock.patch.object(tree._ops, 'start', side_effect=fake_start), \ + mock.patch.object(kunit_kernel.sys, 'stdin', non_tty_stdin), \ + mock.patch.object(kunit_kernel.subprocess, 'call') as mock_call: + for _ in tree.run_kernel(build_dir=build_dir): + pass + + mock_call.assert_not_called() + + def test_signal_handler_skips_terminal_reset_without_tty(self): + non_tty_stdin = mock.Mock() + non_tty_stdin.isatty.return_value = False + tree = kunit_kernel.LinuxSourceTree('', kunitconfig_paths=[os.devnull]) + + with mock.patch.object(kunit_kernel.sys, 'stdin', non_tty_stdin), \ + mock.patch.object(kunit_kernel.subprocess, 'call') as mock_call, \ + mock.patch.object(kunit_kernel.logging, 'error') as mock_error: + tree.signal_handler(signal.SIGINT, None) + mock_error.assert_called_once() + mock_call.assert_not_called() + + def test_signal_handler_resets_terminal_with_tty(self): + tty_stdin = mock.Mock() + tty_stdin.isatty.return_value = True + tree = kunit_kernel.LinuxSourceTree('', kunitconfig_paths=[os.devnull]) + + with mock.patch.object(kunit_kernel.sys, 'stdin', tty_stdin), \ + mock.patch.object(kunit_kernel.subprocess, 'call') as mock_call, \ + mock.patch.object(kunit_kernel.logging, 'error') as mock_error: + tree.signal_handler(signal.SIGINT, None) + mock_error.assert_called_once() + mock_call.assert_called_once_with(['stty', 'sane']) + def test_build_reconfig_no_config(self): with tempfile.TemporaryDirectory('') as build_dir: with open(kunit_kernel.get_kunitconfig_path(build_dir), 'w') as f: