From: Shuah Khan <skhan@linuxfoundation.org>
To: Osama Muhammad <osmtendev@gmail.com>, shuah@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests: prctl: Add prctl test for PR_GET_NAME
Date: Mon, 14 Aug 2023 14:09:15 -0600 [thread overview]
Message-ID: <b43706b7-4ced-9e00-823a-230a5a5e6345@linuxfoundation.org> (raw)
In-Reply-To: <20230806151810.9958-1-osmtendev@gmail.com>
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@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] = {};
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
next prev parent reply other threads:[~2023-08-14 20:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-06 15:18 [PATCH] selftests: prctl: Add prctl test for PR_GET_NAME Osama Muhammad
2023-08-14 20:09 ` Shuah Khan [this message]
-- strict thread matches above, loose matches on Subject: below --
2023-08-05 22:41 Osama Muhammad
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=b43706b7-4ced-9e00-823a-230a5a5e6345@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=osmtendev@gmail.com \
--cc=shuah@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