[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b43706b7-4ced-9e00-823a-230a5a5e6345@linuxfoundation.org>
Date: Mon, 14 Aug 2023 14:09:15 -0600
From: Shuah Khan <skhan@...uxfoundation.org>
To: Osama Muhammad <osmtendev@...il.com>, shuah@...nel.org
Cc: linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
Shuah Khan <skhan@...uxfoundation.org>
Subject: Re: [PATCH] selftests: prctl: Add prctl test for PR_GET_NAME
On 8/6/23 09:18, Osama Muhammad wrote:
> 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.
>
So the values should match? Can you elaborate that in the
change log.
> Signed-off-by: Osama Muhammad <osmtendev@...il.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] = {};
Define this and use it. Don't hard-code the size.
MAX_PATH_LEN - look for other such defines.
> + int j;
> +
> + j = snprintf(path, 50, "/proc/self/task/%d/comm", pid);
Here - it makes it easier to maintain.
> + fptr = fopen(path, "r");
> + char name[TASK_COMM_LEN] = {};
> + int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
> + char output[TASK_COMM_LEN] = {};
Code after declarations please. It is easier to read and follow.
> +
> + fscanf(fptr, "%s", output);
Don't you want to check error return here?
> +
> + 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);
> +
No need to for this extra line
> + EXPECT_TRUE(check_name());
> +
> }
>
> TEST_HARNESS_MAIN
thanks,
-- Shuah
Powered by blists - more mailing lists