public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests: prctl: Add prctl test for PR_GET_NAME
@ 2023-08-06 15:18 Osama Muhammad
  2023-08-14 20:09 ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Osama Muhammad @ 2023-08-06 15:18 UTC (permalink / raw)
  To: shuah; +Cc: linux-kernel, linux-kselftest, Osama Muhammad

This patch covers the testing of PR_GET_NAME by
reading it's value from proc/self/task/pid/comm
and matching it by the value returned by  PR_GET_NAME.

Signed-off-by: Osama Muhammad <osmtendev@gmail.com>
---
 .../selftests/prctl/set-process-name.c        | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c
index 3bc5e0e09..41f4b105d 100644
--- a/tools/testing/selftests/prctl/set-process-name.c
+++ b/tools/testing/selftests/prctl/set-process-name.c
@@ -47,6 +47,28 @@ int check_null_pointer(char *check_name)
 	return res;
 }
 
+int check_name(void)
+{
+
+	int pid;
+
+	pid = getpid();
+	FILE *fptr;
+	char path[50] = {};
+	int j;
+
+	j = snprintf(path, 50, "/proc/self/task/%d/comm", pid);
+	fptr = fopen(path, "r");
+	char name[TASK_COMM_LEN] = {};
+	int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
+	char output[TASK_COMM_LEN] = {};
+
+	fscanf(fptr, "%s", output);
+
+	return !strcmp(output, name);
+
+}
+
 TEST(rename_process) {
 
 	EXPECT_GE(set_name(CHANGE_NAME), 0);
@@ -57,6 +79,9 @@ TEST(rename_process) {
 
 	EXPECT_GE(set_name(CHANGE_NAME), 0);
 	EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);
+
+	EXPECT_TRUE(check_name());
+
 }
 
 TEST_HARNESS_MAIN
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread
* [PATCH] selftests: prctl: Add prctl test for PR_GET_NAME
@ 2023-08-05 22:41 Osama Muhammad
  0 siblings, 0 replies; 3+ messages in thread
From: Osama Muhammad @ 2023-08-05 22:41 UTC (permalink / raw)
  To: =shuah; +Cc: linux-kernel, linux-kselftest, Osama Muhammad

This patch covers the testing of PR_GET_NAME by
reading it's value from proc/self/task/pid/comm
and matching it by the value returned by  PR_GET_NAME.

Signed-off-by: Osama Muhammad <osmtendev@gmail.com>
---
 .../selftests/prctl/set-process-name.c        | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c
index 3bc5e0e09..41f4b105d 100644
--- a/tools/testing/selftests/prctl/set-process-name.c
+++ b/tools/testing/selftests/prctl/set-process-name.c
@@ -47,6 +47,28 @@ int check_null_pointer(char *check_name)
 	return res;
 }
 
+int check_name(void)
+{
+
+	int pid;
+
+	pid = getpid();
+	FILE *fptr;
+	char path[50] = {};
+	int j;
+
+	j = snprintf(path, 50, "/proc/self/task/%d/comm", pid);
+	fptr = fopen(path, "r");
+	char name[TASK_COMM_LEN] = {};
+	int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
+	char output[TASK_COMM_LEN] = {};
+
+	fscanf(fptr, "%s", output);
+
+	return !strcmp(output, name);
+
+}
+
 TEST(rename_process) {
 
 	EXPECT_GE(set_name(CHANGE_NAME), 0);
@@ -57,6 +79,9 @@ TEST(rename_process) {
 
 	EXPECT_GE(set_name(CHANGE_NAME), 0);
 	EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);
+
+	EXPECT_TRUE(check_name());
+
 }
 
 TEST_HARNESS_MAIN
-- 
2.34.1


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

end of thread, other threads:[~2023-08-14 20:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-06 15:18 [PATCH] selftests: prctl: Add prctl test for PR_GET_NAME Osama Muhammad
2023-08-14 20:09 ` Shuah Khan
  -- strict thread matches above, loose matches on Subject: below --
2023-08-05 22:41 Osama Muhammad

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