Linux kbuild/kconfig development
 help / color / mirror / Atom feed
* [PATCH] clang-tools: Import os for broken pipe handling
@ 2026-09-23 14:22 houtinghang
  2026-09-25 22:34 ` Nathan Chancellor
  0 siblings, 1 reply; 5+ messages in thread
From: houtinghang @ 2026-09-23 14:22 UTC (permalink / raw)
  To: Nathan Chancellor, Nicolas Schier
  Cc: llvm, linux-kbuild, linux-kernel, Nick Desaulniers, Bill Wendling,
	Justin Stitt

The BrokenPipeError handler in run-clang-tools.py calls os.open() and
os.dup2() without importing os. When the analysis pool raises this
exception, the handler raises NameError instead of redirecting stdout
and exiting with status 1.

Import os and add a regression test that injects BrokenPipeError from
Pool.map(), then checks the redirection and exit status.

Fixes: 87c7ee67deb7 ("scripts: handle BrokenPipeError for python scripts")
Assisted-by: LLM
Signed-off-by: houtinghang <ue081723@gmail.com>
---
Testing: python scripts/clang-tools/run-clang-tools_test.py -v
The test fails before the import with NameError and passes after it.
Tested with Python 3.13 on Windows using exception injection; no complete
kernel build or real clang-tidy pipeline test was performed.

AI disclosure: Codex found the missing import, wrote the fix and test,
ran the test, reviewed the diff, and drafted this message in response to
a request to find, fix, review and submit a Linux kernel bug.

 scripts/clang-tools/run-clang-tools.py      |  1 +
 scripts/clang-tools/run-clang-tools_test.py | 41 +++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 scripts/clang-tools/run-clang-tools_test.py

diff --git a/scripts/clang-tools/run-clang-tools.py b/scripts/clang-tools/run-clang-tools.py
index e78be82..79d58b3 100755
--- a/scripts/clang-tools/run-clang-tools.py
+++ b/scripts/clang-tools/run-clang-tools.py
@@ -12,6 +12,7 @@ compile_commands.json.
 import argparse
 import json
 import multiprocessing
+import os
 import subprocess
 import sys
 
diff --git a/scripts/clang-tools/run-clang-tools_test.py b/scripts/clang-tools/run-clang-tools_test.py
new file mode 100644
index 0000000..207b866
--- /dev/null
+++ b/scripts/clang-tools/run-clang-tools_test.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+
+"""Tests for run-clang-tools.py."""
+
+import importlib.util
+import os
+from pathlib import Path
+import unittest
+from unittest import mock
+
+
+spec = importlib.util.spec_from_file_location(
+    "run_clang_tools", Path(__file__).with_name("run-clang-tools.py"))
+run_clang_tools = importlib.util.module_from_spec(spec)
+spec.loader.exec_module(run_clang_tools)
+
+
+class TestRunClangTools(unittest.TestCase):
+    def test_broken_pipe_redirects_stdout_and_exits(self):
+        args = mock.Mock(path="compile_commands.json")
+        with mock.patch.object(run_clang_tools, "parse_arguments", return_value=args), \
+             mock.patch("builtins.open", mock.mock_open(read_data="[]")), \
+             mock.patch.object(run_clang_tools.multiprocessing, "Lock"), \
+             mock.patch.object(run_clang_tools.multiprocessing, "Pool") as pool, \
+             mock.patch("os.open", return_value=42) as open_devnull, \
+             mock.patch("os.dup2") as dup2, \
+             mock.patch.object(run_clang_tools.sys, "stdout") as stdout:
+            pool.return_value.__enter__.return_value.map.side_effect = BrokenPipeError
+            stdout.fileno.return_value = 1
+
+            with self.assertRaises(SystemExit) as raised:
+                run_clang_tools.main()
+
+            self.assertEqual(raised.exception.code, 1)
+            open_devnull.assert_called_once_with(os.devnull, os.O_WRONLY)
+            dup2.assert_called_once_with(42, 1)
+
+
+if __name__ == "__main__":
+    unittest.main()

base-commit: fe2ec83746e501645709761605c2464a44fd2929
-- 
2.52.0.windows.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] clang-tools: Import os for broken pipe handling
  2026-09-23 14:22 [PATCH] clang-tools: Import os for broken pipe handling houtinghang
@ 2026-09-25 22:34 ` Nathan Chancellor
  2026-09-26  0:52   ` 14侯廷翰
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2026-09-25 22:34 UTC (permalink / raw)
  To: houtinghang
  Cc: Nathan Chancellor, Nicolas Schier, llvm, linux-kbuild,
	linux-kernel, Nick Desaulniers, Bill Wendling, Justin Stitt

On 2026-09-23 22:22 +0800, houtinghang wrote:
> The BrokenPipeError handler in run-clang-tools.py calls os.open() and
> os.dup2() without importing os. When the analysis pool raises this
> exception, the handler raises NameError instead of redirecting stdout
> and exiting with status 1.
> 
> Import os and add a regression test that injects BrokenPipeError from
> Pool.map(), then checks the redirection and exit status.
> 
> Fixes: 87c7ee67deb7 ("scripts: handle BrokenPipeError for python scripts")
> Assisted-by: LLM
> Signed-off-by: houtinghang <ue081723@gmail.com>
> ---
> Testing: python scripts/clang-tools/run-clang-tools_test.py -v
> The test fails before the import with NameError and passes after it.
> Tested with Python 3.13 on Windows using exception injection; no complete
> kernel build or real clang-tidy pipeline test was performed.
> 
> AI disclosure: Codex found the missing import, wrote the fix and test,
> ran the test, reviewed the diff, and drafted this message in response to
> a request to find, fix, review and submit a Linux kernel bug.
> 
>  scripts/clang-tools/run-clang-tools.py      |  1 +
>  scripts/clang-tools/run-clang-tools_test.py | 41 +++++++++++++++++++++
>  2 files changed, 42 insertions(+)
>  create mode 100644 scripts/clang-tools/run-clang-tools_test.py
> 
> diff --git a/scripts/clang-tools/run-clang-tools.py b/scripts/clang-tools/run-clang-tools.py
> index e78be82..79d58b3 100755
> --- a/scripts/clang-tools/run-clang-tools.py
> +++ b/scripts/clang-tools/run-clang-tools.py
> @@ -12,6 +12,7 @@ compile_commands.json.
>  import argparse
>  import json
>  import multiprocessing
> +import os
>  import subprocess
>  import sys
>  
> diff --git a/scripts/clang-tools/run-clang-tools_test.py b/scripts/clang-tools/run-clang-tools_test.py

The change to run-clang-tools.py is obviously correct but I am not sure
this test really adds much other than noise. Please drop it and resend
with an adjusted commit message. Additionally, please adjust your name
in the signoff to be a "known identity" per the Documentation.

-- 
Cheers,
Nathan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] clang-tools: Import os for broken pipe handling
  2026-09-25 22:34 ` Nathan Chancellor
@ 2026-09-26  0:52   ` 14侯廷翰
  2026-09-29 19:59     ` Nathan Chancellor
  0 siblings, 1 reply; 5+ messages in thread
From: 14侯廷翰 @ 2026-09-26  0:52 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nicolas Schier, llvm, linux-kbuild, linux-kernel,
	Nick Desaulniers, Bill Wendling, Justin Stitt

From: Ting-Han Hou <ue081723@gmail.com>

The BrokenPipeError handler in run-clang-tools.py calls os.open() and
os.dup2() without importing os. If this handler is reached, it raises
NameError instead of redirecting stdout and exiting with status 1.

Import os so the handler can work as intended.

Fixes: 87c7ee67deb7 ("scripts: handle BrokenPipeError for python scripts")
Assisted-by: LLM
Signed-off-by: Ting-Han Hou <ue081723@gmail.com>
---
 scripts/clang-tools/run-clang-tools.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/clang-tools/run-clang-tools.py
b/scripts/clang-tools/run-clang-tools.py
index e78be82..79d58b3 100755
--- a/scripts/clang-tools/run-clang-tools.py
+++ b/scripts/clang-tools/run-clang-tools.py
@@ -12,6 +12,7 @@ compile_commands.json.
 import argparse
 import json
 import multiprocessing
+import os
 import subprocess
 import sys


base-commit: fe2ec83746e501645709761605c2464a44fd2929
-- 
2.52.0.windows.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] clang-tools: Import os for broken pipe handling
  2026-09-26  0:52   ` 14侯廷翰
@ 2026-09-29 19:59     ` Nathan Chancellor
  2026-09-30  7:58       ` Ting-Han Hou
  0 siblings, 1 reply; 5+ messages in thread
From: Nathan Chancellor @ 2026-09-29 19:59 UTC (permalink / raw)
  To: 14侯廷翰
  Cc: Nathan Chancellor, Nicolas Schier, llvm, linux-kbuild,
	linux-kernel, Nick Desaulniers, Bill Wendling, Justin Stitt

On 2026-09-26 08:52 +0800, 14侯廷翰 wrote:
> From: Ting-Han Hou <ue081723@gmail.com>
> 
> The BrokenPipeError handler in run-clang-tools.py calls os.open() and
> os.dup2() without importing os. If this handler is reached, it raises
> NameError instead of redirecting stdout and exiting with status 1.
> 
> Import os so the handler can work as intended.
> 
> Fixes: 87c7ee67deb7 ("scripts: handle BrokenPipeError for python scripts")
> Assisted-by: LLM
> Signed-off-by: Ting-Han Hou <ue081723@gmail.com>
> ---
>  scripts/clang-tools/run-clang-tools.py | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/scripts/clang-tools/run-clang-tools.py
> b/scripts/clang-tools/run-clang-tools.py

Your patch is mangled, so it cannot be applied (maybe you send it with a
different client from your v1?). Please resend properly.

-- 
Cheers,
Nathan


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] clang-tools: Import os for broken pipe handling
  2026-09-29 19:59     ` Nathan Chancellor
@ 2026-09-30  7:58       ` Ting-Han Hou
  0 siblings, 0 replies; 5+ messages in thread
From: Ting-Han Hou @ 2026-09-30  7:58 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: Nicolas Schier, llvm, linux-kbuild, linux-kernel,
	Nick Desaulniers, Bill Wendling, Justin Stitt

From: Ting-Han Hou <ue081723@gmail.com>
Date: Sat, 26 Sep 2026 08:52:24 +0800
Subject: [PATCH] clang-tools: Import os for broken pipe handling

The BrokenPipeError handler in run-clang-tools.py calls os.open() and
os.dup2() without importing os. If this handler is reached, it raises
NameError instead of redirecting stdout and exiting with status 1.

Import os so the handler can work as intended.

Fixes: 87c7ee67deb7 ("scripts: handle BrokenPipeError for python scripts")
Assisted-by: LLM
Signed-off-by: Ting-Han Hou <ue081723@gmail.com>
---
Hi Nathan,

Sorry about the formatting issue. The diff header was wrapped in my
previous email. Here is the corrected patch; the code change is
unchanged.

Thanks,
Ting-Han

 scripts/clang-tools/run-clang-tools.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/clang-tools/run-clang-tools.py
b/scripts/clang-tools/run-clang-tools.py
index e78be82..79d58b3 100755
--- a/scripts/clang-tools/run-clang-tools.py
+++ b/scripts/clang-tools/run-clang-tools.py
@@ -12,6 +12,7 @@ compile_commands.json.
 import argparse
 import json
 import multiprocessing
+import os
 import subprocess
 import sys


base-commit: fe2ec83746e501645709761605c2464a44fd2929
-- 
2.52.0.windows.1


On Tue, 29 Sep 2026 21:59:52 +0200, Nathan Chancellor <nathan@kernel.org> wrote:
> On 2026-09-26 08:52 +0800, 14侯廷翰 wrote:
> > From: Ting-Han Hou <ue081723@gmail.com>
> >
> > The BrokenPipeError handler in run-clang-tools.py calls os.open() and
> > os.dup2() without importing os. If this handler is reached, it raises
> > NameError instead of redirecting stdout and exiting with status 1.
> >
> > Import os so the handler can work as intended.
> >
> > Fixes: 87c7ee67deb7 ("scripts: handle BrokenPipeError for python scripts")
> > Assisted-by: LLM
> > Signed-off-by: Ting-Han Hou <ue081723@gmail.com>
> > ---
> >  scripts/clang-tools/run-clang-tools.py | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/scripts/clang-tools/run-clang-tools.py
> > b/scripts/clang-tools/run-clang-tools.py
>
> Your patch is mangled, so it cannot be applied (maybe you send it with a
> different client from your v1?). Please resend properly.
>
> --
> Cheers,
> Nathan

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-30  7:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 14:22 [PATCH] clang-tools: Import os for broken pipe handling houtinghang
2026-09-25 22:34 ` Nathan Chancellor
2026-09-26  0:52   ` 14侯廷翰
2026-09-29 19:59     ` Nathan Chancellor
2026-09-30  7:58       ` Ting-Han Hou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox