From: "André Almeida" <andrealmeid@igalia.com>
To: Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Steven Rostedt <rostedt@goodmis.org>,
Christian Brauner <brauner@kernel.org>,
Kees Cook <kees@kernel.org>, Shuah Khan <shuah@kernel.org>,
willy@infradead.org, mathieu.desnoyers@efficios.com,
David Laight <david.laight.linux@gmail.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
akpm@linux-foundation.org, Yafang Shao <laoar.shao@gmail.com>,
andrii.nakryiko@gmail.com, arnaldo.melo@gmail.com,
Petr Mladek <pmladek@suse.com>
Cc: linux-kernel@vger.kernel.org, kernel-dev@igalia.com,
linux-mm@kvack.org, linux-api@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
"André Almeida" <andrealmeid@igalia.com>
Subject: [PATCH v5 3/6] lib/string_kunit: Add test for copy_task_comm()
Date: Thu, 27 Aug 2026 15:23:02 -0300 [thread overview]
Message-ID: <20260827-tonyk-long_name-v5-3-5fa843782a00@igalia.com> (raw)
In-Reply-To: <20260827-tonyk-long_name-v5-0-5fa843782a00@igalia.com>
Add a new test for copy_task_comm(). Check if a copy from a task_struct
works, and special cases when the size of source and destination buffer
mismatches.
Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
lib/tests/string_kunit.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/lib/tests/string_kunit.c b/lib/tests/string_kunit.c
index 0819ace5b027..27a27ab13254 100644
--- a/lib/tests/string_kunit.c
+++ b/lib/tests/string_kunit.c
@@ -881,6 +881,43 @@ static void string_bench_strrchr(struct kunit *test)
STRING_BENCH_BUF(test, buf, len, strrchr, buf, '\0');
}
+#define TASK_NAME "task_name"
+#define TASK_NAME_LEN 9
+#define TASK_MAX_LEN TASK_COMM_LEN
+#define SMALLER_LEN (TASK_NAME_LEN - 3)
+#define BIGGER_LEN (TASK_MAX_LEN + 3)
+
+static void string_copy_task_comm(struct kunit *test)
+{
+ char str[TASK_MAX_LEN] = TASK_NAME, copy[TASK_MAX_LEN],
+ smaller_buf[SMALLER_LEN], bigger_buf[BIGGER_LEN];
+ static struct task_struct task, *tsk = &task;
+ int len1, len2, i;
+
+ /* set and get task name */
+ set_task_comm(tsk, str);
+ copy_task_comm(copy, tsk, TASK_COMM_LEN);
+
+ len1 = strlen(str);
+ len2 = strlen(copy);
+
+ KUNIT_ASSERT_EQ(test, len1, len2);
+ KUNIT_ASSERT_EQ(test, len2, TASK_NAME_LEN);
+ KUNIT_ASSERT_EQ(test, copy[len2], '\0');
+ KUNIT_ASSERT_TRUE(test, !strcmp(str, copy));
+
+ /* copy to a smaller dst buffer */
+ copy_task_comm(smaller_buf, tsk, sizeof(smaller_buf));
+ KUNIT_ASSERT_TRUE(test, !strncmp(str, smaller_buf, SMALLER_LEN - 1));
+ KUNIT_ASSERT_EQ(test, smaller_buf[SMALLER_LEN - 1], '\0');
+
+ /* copy to a bigger dst buffer */
+ copy_task_comm(bigger_buf, tsk, sizeof(bigger_buf));
+ KUNIT_ASSERT_TRUE(test, !strncmp(str, bigger_buf, TASK_NAME_LEN));
+ for (i = TASK_NAME_LEN; i < BIGGER_LEN; i++)
+ KUNIT_ASSERT_EQ(test, bigger_buf[i], '\0');
+}
+
static struct kunit_case string_test_cases[] = {
KUNIT_CASE(string_test_memset16),
KUNIT_CASE(string_test_memset32),
@@ -910,6 +947,7 @@ static struct kunit_case string_test_cases[] = {
KUNIT_CASE(string_bench_strnlen),
KUNIT_CASE(string_bench_strchr),
KUNIT_CASE(string_bench_strrchr),
+ KUNIT_CASE(string_copy_task_comm),
{}
};
--
2.55.0
next prev parent reply other threads:[~2026-08-27 18:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-27 18:22 [PATCH v5 0/6] sched: Add support for long task name André Almeida
2026-08-27 18:23 ` [PATCH v5 1/6] treewide: Get rid of get_task_comm() André Almeida
2026-08-27 18:40 ` sashiko-bot
2026-08-27 18:23 ` [PATCH v5 2/6] treewide: Replace memcpy(..., current->comm) with copy_task_comm() André Almeida
2026-08-27 18:35 ` sashiko-bot
2026-08-27 18:23 ` André Almeida [this message]
2026-08-27 18:47 ` [PATCH v5 3/6] lib/string_kunit: Add test for copy_task_comm() sashiko-bot
2026-08-27 18:23 ` [PATCH v5 4/6] sched: Extend task command name with TASK_COMM_EXT_LEN André Almeida
2026-08-27 19:05 ` sashiko-bot
2026-08-27 18:23 ` [PATCH v5 5/6] prctl: Add support for long user thread names André Almeida
2026-08-27 19:08 ` sashiko-bot
2026-08-27 18:23 ` [PATCH v5 6/6] selftests: prctl: Add test for long " André Almeida
2026-08-27 19:14 ` sashiko-bot
2026-08-30 21:24 ` kernel test robot
2026-08-30 22:55 ` kernel test robot
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=20260827-tonyk-long_name-v5-3-5fa843782a00@igalia.com \
--to=andrealmeid@igalia.com \
--cc=akpm@linux-foundation.org \
--cc=andrii.nakryiko@gmail.com \
--cc=arnaldo.melo@gmail.com \
--cc=brauner@kernel.org \
--cc=david.laight.linux@gmail.com \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kernel-dev@igalia.com \
--cc=laoar.shao@gmail.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=peterz@infradead.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vincent.guittot@linaro.org \
--cc=willy@infradead.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