Linux Kernel Selftest development
 help / color / mirror / Atom feed
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,
	ivan.orlov0322@gmail.com, Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests: prctl: Add new prctl test for PR_SET_NAME
Date: Tue, 6 Jun 2023 13:39:30 -0600	[thread overview]
Message-ID: <1514ff05-9049-25d7-77cb-04db04e441b0@linuxfoundation.org> (raw)
In-Reply-To: <20230606175515.12855-1-osmtendev@gmail.com>

On 6/6/23 11:55, Osama Muhammad wrote:
> This patch will add the new test, which covers the prctl call
> PR_SET_NAME command. The test tries to give a name using the PR_SET_NAME
> call and then confirm it that it changed correctly by using  PR_GET_NAME.
> It also tries to rename it with empty name.In the test PR_GET_NAME is
> tested by passing null pointer to it and check its behaviour.
> 
> Signed-off-by: Osama Muhammad <osmtendev@gmail.com>
> ---
>   tools/testing/selftests/prctl/Makefile        |  2 +-
>   .../selftests/prctl/set-process-name.c        | 61 +++++++++++++++++++
>   2 files changed, 62 insertions(+), 1 deletion(-)
>   create mode 100644 tools/testing/selftests/prctl/set-process-name.c
> 
> diff --git a/tools/testing/selftests/prctl/Makefile b/tools/testing/selftests/prctl/Makefile
> index c058b81ee..cfc35d29f 100644
> --- a/tools/testing/selftests/prctl/Makefile
> +++ b/tools/testing/selftests/prctl/Makefile
> @@ -5,7 +5,7 @@ ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)
>   
>   ifeq ($(ARCH),x86)
>   TEST_PROGS := disable-tsc-ctxt-sw-stress-test disable-tsc-on-off-stress-test \
> -		disable-tsc-test set-anon-vma-name-test
> +		disable-tsc-test set-anon-vma-name-test set-process-name
>   all: $(TEST_PROGS)
>   
>   include ../lib.mk
> diff --git a/tools/testing/selftests/prctl/set-process-name.c b/tools/testing/selftests/prctl/set-process-name.c
> new file mode 100644
> index 000000000..12c5ed9a5
> --- /dev/null
> +++ b/tools/testing/selftests/prctl/set-process-name.c
> @@ -0,0 +1,61 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * This test covers the PR_SET_NAME functionality of prctl calls
> + */
> +
> +#include <errno.h>
> +#include <sys/prctl.h>
> +#include <string.h>
> +
> +#include "../kselftest_harness.h"
> +
> +#define CHANGE_NAME "changename"
> +#define EMPTY_NAME ""
> +
> +int set_name(char *name)
> +{
> +	int res;
> +
> +	res = prctl(PR_SET_NAME, name, NULL, NULL, NULL);
> +
> +	if (res < 0)
> +		return -errno;
> +	return res;
> +}
> +
> +int check_is_name_correct(char *check_name)
> +{
> +	char name[16];

Use TASK_COMM_LEN here instead of 16.

> +	int res;
> +
> +	res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
> +
> +	if (res < 0)
> +		return -errno;
> +
> +	return !strcmp(name, check_name);
> +}
> +
> +int check_null_pointer(char *check_name)
> +{
> +	char *name = NULL;
> +	int res;
> +
> +	res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
> +
> +	return res;
> +}
> +
> +TEST(rename_process) {
> +
> +	EXPECT_GE(set_name(CHANGE_NAME), 0);
> +	EXPECT_TRUE(check_is_name_correct(CHANGE_NAME));
> +
> +	EXPECT_GE(set_name(EMPTY_NAME), 0);
> +	EXPECT_TRUE(check_is_name_correct(EMPTY_NAME));
> +
> +	EXPECT_GE(set_name(CHANGE_NAME), 0);
> +	EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);
> +}
> +
> +TEST_HARNESS_MAIN

Otherwise looks good.

thanks,
-- Shuah

      reply	other threads:[~2023-06-06 19:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06 17:55 [PATCH] selftests: prctl: Add new prctl test for PR_SET_NAME Osama Muhammad
2023-06-06 19:39 ` Shuah Khan [this message]

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=1514ff05-9049-25d7-77cb-04db04e441b0@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=ivan.orlov0322@gmail.com \
    --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