From: Cihan Karadag <cihan.cihan@gmail.com>
To: Andy Whitcroft <apw@canonical.com>, Joe Perches <joe@perches.com>,
Dwaipayan Ray <dwaipayanray1@gmail.com>,
Lukas Bulwahn <lukas.bulwahn@gmail.com>,
Jonathan Corbet <corbet@lwn.net>
Cc: Cihan Karadag <cihan.cihan@gmail.com>,
Shuah Khan <skhan@linuxfoundation.org>,
linux-kernel@vger.kernel.org, workflows@vger.kernel.org,
linux-doc@vger.kernel.org
Subject: [PATCH] checkpatch: warn about possible missing gitignore coverage in selftests
Date: Mon, 27 Jul 2026 23:24:41 -0600 [thread overview]
Message-ID: <20260728052442.626076-1-cihan.cihan@gmail.com> (raw)
Per selftests documentation [1], every generated test binary must be
added to gitignore to prevent leaving untracked files in the kernel
tree.
This is an easy mistake to make when adding a new test. In fact, a
search of selftests history turns up dozens of standalone follow-up
patches with titles like "add missing gitignore for <binary>", each
needed only because the original patch adding a new test
didn't also update gitignore.
Add a SELFTESTS_GITIGNORE check that warns about gitignore coverage
whenever a patch adds a new file under tools/testing/selftests/, the
same way FILE_PATH_CHANGES warns about MAINTAINERS on any added,
moved, or deleted file.
The warning fires once per patch via a $reported_selftests_gitignore
guard, even when a patch adds several new files under
tools/testing/selftests/ at once, mirroring
$reported_maintainer_file's per patch dedup for FILE_PATH_CHANGES.
Link: https://docs.kernel.org/dev-tools/kselftest.html#contributing-new-tests-details [1]
Signed-off-by: Cihan Karadag <cihan.cihan@gmail.com>
---
Documentation/dev-tools/checkpatch.rst | 7 +++++++
scripts/checkpatch.pl | 10 ++++++++++
2 files changed, 17 insertions(+)
diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index 6139a08c34cd8..9201d1cda0d44 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -1293,6 +1293,13 @@ Others
**PRINTF_0XDECIMAL**
Prefixing 0x with decimal output is defective and should be corrected.
+ **SELFTESTS_GITIGNORE**
+ Warn that, if the new file(s) added under tools/testing/selftests/
+ generate any test objects, those objects need to be added to
+ .gitignore.
+
+ See: https://www.kernel.org/doc/html/latest/dev-tools/kselftest.html
+
**SPDX_LICENSE_TAG**
The source file is missing or has an improper SPDX identifier tag.
The Linux kernel requires the precise SPDX identifier in all source files,
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2b7a42bbdd94f..a4ead4677e3c6 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2701,6 +2701,7 @@ sub process {
my $commit_log_long_line = 0;
my $commit_log_has_diff = 0;
my $reported_maintainer_file = 0;
+ my $reported_selftests_gitignore = 0;
my $non_utf8_charset = 0;
my $last_git_commit_id_linenr = -1;
@@ -3492,6 +3493,15 @@ sub process {
"added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
}
+# Check for new files added under kselftests
+ if (!$reported_selftests_gitignore && !$in_commit_log &&
+ ($line =~ /^new file mode\s*\d+\s*$/) &&
+ ($realfile =~ m@^tools/testing/selftests/@)) {
+ $reported_selftests_gitignore = 1;
+ WARN("SELFTESTS_GITIGNORE",
+ "Added file(s) under tools/testing/selftests/, if they generate any test objects make sure they are added to .gitignore. See: Documentation/dev-tools/kselftest.rst\n");
+ }
+
# Check for adding new DT bindings not in schema format
if (!$in_commit_log &&
($line =~ /^new file mode\s*\d+\s*$/) &&
--
2.54.0
next reply other threads:[~2026-07-28 5:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-28 5:24 Cihan Karadag [this message]
2026-07-28 14:31 ` [PATCH] checkpatch: warn about possible missing gitignore coverage in selftests Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260728052442.626076-1-cihan.cihan@gmail.com \
--to=cihan.cihan@gmail.com \
--cc=apw@canonical.com \
--cc=corbet@lwn.net \
--cc=dwaipayanray1@gmail.com \
--cc=joe@perches.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=workflows@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox