All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Shivam Chaudhary <cvam0000@gmail.com>
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH v3] selftests: tmpfs: Add kselftest support to tmpfs
Date: Mon, 28 Oct 2024 21:02:36 -0600	[thread overview]
Message-ID: <17008f4e-e5c4-459b-8a50-7b9fbb426a70@linuxfoundation.org> (raw)
In-Reply-To: <20241028185756.111832-1-cvam0000@gmail.com>

On 10/28/24 12:57, Shivam Chaudhary wrote:
> Add kselftest support for openat, linkat, unshare, mount tests

You are combining a few too many changes in this patch. As such
this patch doesn't add support for the above tests. Instead it
changes the reporting to use ksft_* framework.

> 
> - Replace direct error handling with
>   'ksft_test_result_*' , 'ksft_print_msg' macros for better
>   reporting.
> 

That
> - Add `ksft_print_header()` and `ksft_set_plan()`
>   to structure test outputs more effectively.
> 
> - Improve the test flow by adding more detailed pass/fail
>    reporting for unshare, mounting, file opening, and linking
>    operations.
> 
> - Skip the test if it's not run as root, providing an
>    appropriate Warning.

Make this a separate patch and the very first patch in the series.

> 
>    Test logs:
> 
> Before change:
> 
> - Without root
>   error: unshare, errno 1
> 
> - With root
>   No, output
> 
> After change:
> 
> - Without root
>   TAP version 13
>   1..1
>    ok 1 # SKIP This test needs root to run
> 
> - With root
>   TAP version 13
> 1..1
>    unshare(): Creat new mount namespace: Success.
>    mount(): Root filesystem private mount: Success
>    mount(): Mounting tmpfs on /tmp: Success
>    openat(): Open first temporary file: Success
>    linkat(): Linking the temporary file: Success
>    openat(): Opening the second temporary file: Success
>    ok 1 Test : Success
>    Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> Signed-off-by: Shivam Chaudhary <cvam0000@gmail.com>
> ---
> 
> Notes:
> 		Changes in v3:
> 				- Remove extra ksft_set_plan()
> 				- Remove function for unshare()
> 				- Fix the comment style
> 
> 		link to v2: https://lore.kernel.org/all/20241026191621.2860376-1-cvam0000@gmail.com/
> 
> 		Changes in v2:
> 				- Make the commit message more clear.
> 
> 		link to v1: https://lore.kernel.org/all/20241024200228.1075840-1-cvam0000@gmail.com/T/#u
> 
>   .../selftests/tmpfs/bug-link-o-tmpfile.c      | 69 +++++++++++++++----
>   1 file changed, 57 insertions(+), 12 deletions(-)
> 
> diff --git a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
> index b5c3ddb90942..9ca1245784d9 100644
> --- a/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
> +++ b/tools/testing/selftests/tmpfs/bug-link-o-tmpfile.c
> @@ -23,45 +23,90 @@
>   #include <sys/mount.h>
>   #include <unistd.h>
>   
> +#include "../kselftest.h"
> +
> +
>   int main(void)
>   {
>   	int fd;
>   
> +	/* Setting up kselftest framework */
> +	ksft_print_header();
> +	ksft_set_plan(1);
> +
> +	/* Check if test is run as root */
> +	if (geteuid()) {
> +		ksft_test_result_skip("This test needs root to run!\n");
> +		return 1;

This should be SKIP - simply use KSFT_SKIP

> +	}
> +
> +
>   	if (unshare(CLONE_NEWNS) == -1) {
>   		if (errno == ENOSYS || errno == EPERM) {
> -			fprintf(stderr, "error: unshare, errno %d\n", errno);
> -			return 4;
> +			ksft_test_result_fail("unshare() error: unshare, errno %d\n", errno);

This isn't a failure - it just means that unsaher() might not be supported.
Since root check is already done, EPERM won't be returned here.

> +			return 1;

Okay this wrong. This changes the return value fro 4 to 1 - SKIP becomes fail.
Use KSFT_SKIP


>   		}
> -		fprintf(stderr, "error: unshare, errno %d\n", errno);
> -		return 1;
> +		else{
> +			fprintf(stderr, "unshare() error: unshare, errno %d\n", errno);
> +			ksft_test_result_fail("unshare() error: unshare, errno %d\n", errno);
> +			return 1;
> +
> +		}
> +	}
> +	
> +	else {
> +		ksft_print_msg("unshare(): Creat new mount namespace: Success.\n");
> +
>   	}
> -	if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) == -1) {
> -		fprintf(stderr, "error: mount '/', errno %d\n", errno);
> +
> +
> +
> +	if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL) == -1) {
> +		ksft_test_result_fail("mount() error: Root filesystem private mount: Fail %d\n", errno);
>   		return 1;
> +	} else {
> +		ksft_print_msg("mount(): Root filesystem private mount: Success\n");
>   	}
>   
> +
>   	/* Our heroes: 1 root inode, 1 O_TMPFILE inode, 1 permanent inode. */
>   	if (mount(NULL, "/tmp", "tmpfs", 0, "nr_inodes=3") == -1) {
> -		fprintf(stderr, "error: mount tmpfs, errno %d\n", errno);
> +		ksft_test_result_fail("mount() error: Mounting tmpfs on /tmp: Fail %d\n", errno);
>   		return 1;
> +	} else {
> +		ksft_print_msg("mount(): Mounting tmpfs on /tmp: Success\n");
>   	}
>   
> -	fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);
> +
> +	fd = openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600);
>   	if (fd == -1) {
> -		fprintf(stderr, "error: open 1, errno %d\n", errno);
> +		ksft_test_result_fail("openat() error: Open first temporary file: Fail %d\n", errno);
>   		return 1;
> +	} else {
> +		ksft_print_msg("openat(): Open first temporary file: Success\n");
>   	}
> +
> +
>   	if (linkat(fd, "", AT_FDCWD, "/tmp/1", AT_EMPTY_PATH) == -1) {
> -		fprintf(stderr, "error: linkat, errno %d\n", errno);
> +		ksft_test_result_fail("linkat() error: Linking the temporary file: Fail %d\n", errno);
> +		/* Ensure fd is closed on failure */
> +		close(fd);
>   		return 1;
> +	} else {
> +		ksft_print_msg("linkat(): Linking the temporary file: Success\n");
>   	}
>   	close(fd);
>   
> -	fd = openat(AT_FDCWD, "/tmp", O_WRONLY|O_TMPFILE, 0600);
> +
> +	fd = openat(AT_FDCWD, "/tmp", O_WRONLY | O_TMPFILE, 0600);
>   	if (fd == -1) {
> -		fprintf(stderr, "error: open 2, errno %d\n", errno);
> +		ksft_test_result_fail("openat() error: Opening the second temporary file: Fail %d\n", errno);
>   		return 1;
> +	} else {
> +		ksft_print_msg("openat(): Opening the second temporary file: Success\n");
>   	}
>   
> +    ksft_test_result_pass("Test : Success\n");
> +	ksft_exit_pass();
>   	return 0;
>   }


Fix these and split the patches. It makes it easier to review.

thanks,
-- Shuah

      reply	other threads:[~2024-10-29  3:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-28 18:57 [PATCH v3] selftests: tmpfs: Add kselftest support to tmpfs Shivam Chaudhary
2024-10-29  3:02 ` 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=17008f4e-e5c4-459b-8a50-7b9fbb426a70@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=cvam0000@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.