[PATCH v6 6/6] selftests: prctl: Add test for long thread names
From: André Almeida
Date: Thu Sep 10 2026 - 13:14:15 EST
Add tests for the new interface to set and get long thread names. The
kernel should accept the LONG_NAME and returning it accordingly. For the
old PR_GET_NAME interface, the kernel should truncate the name up to 16
chars. /proc/<task>/comm should return the same string ad PR_GET_NAME.
While here, fix the check_is_name_correct() logic. It currently returns 1
for success, or a negative number for error. EXPECT_TRUE() evaluates any
non-zero value as true, so the error will be evaluated as a success. Make
the logic more robust and straightforward by returning the results of
strcmp() and expecting zero as success.
Signed-off-by: André Almeida <andrealmeid@xxxxxxxxxx>
---
Changes in v5:
- fix check_is_name_correct() return logic
---
tools/testing/selftests/prctl/set-process-name.c | 53 +++++++++++++++++++++---
1 file changed, 48 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c
index 3f7b146d36df..27a0dbbce4db 100644
--- a/tools/testing/selftests/prctl/set-process-name.c
+++ b/tools/testing/selftests/prctl/set-process-name.c
@@ -9,9 +9,17 @@
#include "kselftest_harness.h"
+#ifndef PR_SET_EXT_NAME
+# define PR_SET_EXT_NAME 17
+# define PR_GET_EXT_NAME 18
+#endif
+
#define CHANGE_NAME "changename"
+#define LONG_NAME "change_to_very_long_extended_name"
+#define LONG_NAME_CAP "change_to_very_"
#define EMPTY_NAME ""
#define TASK_COMM_LEN 16
+#define TASK_COMM_EXT_LEN 64
#define MAX_PATH_LEN 50
int set_name(char *name)
@@ -25,6 +33,20 @@ int set_name(char *name)
return res;
}
+int set_ext_name(char *name)
+{
+ int res;
+
+ res = prctl(PR_SET_EXT_NAME, name, NULL, NULL, NULL);
+
+ if (res < 0)
+ return -errno;
+ return res;
+}
+
+/*
+ * Return 0 if strings match
+ */
int check_is_name_correct(char *check_name)
{
char name[TASK_COMM_LEN];
@@ -35,7 +57,23 @@ int check_is_name_correct(char *check_name)
if (res < 0)
return -errno;
- return !strcmp(name, check_name);
+ return strcmp(name, check_name);
+}
+
+/*
+ * Return 0 if strings match
+ */
+int check_is_ext_name_correct(char *check_name)
+{
+ char name[TASK_COMM_EXT_LEN];
+ int res;
+
+ res = prctl(PR_GET_EXT_NAME, name, NULL, NULL, NULL);
+
+ if (res < 0)
+ return -errno;
+
+ return strcmp(name, check_name);
}
int check_null_pointer(char *check_name)
@@ -56,8 +94,8 @@ int check_name(void)
pid = getpid();
FILE *fptr = NULL;
char path[MAX_PATH_LEN] = {};
- char name[TASK_COMM_LEN] = {};
- char output[TASK_COMM_LEN] = {};
+ char name[TASK_COMM_EXT_LEN] = {};
+ char output[TASK_COMM_EXT_LEN] = {};
int j;
j = snprintf(path, MAX_PATH_LEN, "/proc/self/task/%d/comm", pid);
@@ -80,10 +118,15 @@ int check_name(void)
TEST(rename_process) {
EXPECT_GE(set_name(CHANGE_NAME), 0);
- EXPECT_TRUE(check_is_name_correct(CHANGE_NAME));
+ EXPECT_FALSE(check_is_name_correct(CHANGE_NAME));
+
+ EXPECT_GE(set_ext_name(LONG_NAME), 0);
+ EXPECT_FALSE(check_is_ext_name_correct(LONG_NAME));
+ EXPECT_FALSE(check_is_name_correct(LONG_NAME_CAP));
+ EXPECT_TRUE(check_name());
EXPECT_GE(set_name(EMPTY_NAME), 0);
- EXPECT_TRUE(check_is_name_correct(EMPTY_NAME));
+ EXPECT_FALSE(check_is_name_correct(EMPTY_NAME));
EXPECT_GE(set_name(CHANGE_NAME), 0);
EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);
--
2.55.0