public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH V2 06/10] syscalls/fsmount: Improve fsmount01 test
Date: Thu, 20 Feb 2020 18:34:39 +0100	[thread overview]
Message-ID: <20200220173439.GC15699@gacrux.arch.suse.de> (raw)
In-Reply-To: <9706f359006ea409d2f85c111d3e001ca6f6d128.1582104018.git.viresh.kumar@linaro.org>

Hi,

> +static struct tcase {
> +	char *name;
> +	unsigned int flags;
> +	unsigned int mount_attrs;
> +} tcases[] = {
> +	{"Flag 0, attr RDONLY", 0, MOUNT_ATTR_RDONLY},
> +	{"Flag 0, attr NOSUID", 0, MOUNT_ATTR_NOSUID},
> +	{"Flag 0, attr NODEV", 0, MOUNT_ATTR_NODEV},
> +	{"Flag 0, attr NOEXEC", 0, MOUNT_ATTR_NOEXEC},
> +	{"Flag 0, attr RELATIME", 0, MOUNT_ATTR_RELATIME},
> +	{"Flag 0, attr NOATIME", 0, MOUNT_ATTR_NOATIME},
> +	{"Flag 0, attr STRICTATIME", 0, MOUNT_ATTR_STRICTATIME},
> +	{"Flag 0, attr NODIRATIME", 0, MOUNT_ATTR_NODIRATIME},
> +	{"Flag CLOEXEC, attr RDONLY", FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY},
> +	{"Flag CLOEXEC, attr NOSUID", FSMOUNT_CLOEXEC, MOUNT_ATTR_NOSUID},
> +	{"Flag CLOEXEC, attr NODEV", FSMOUNT_CLOEXEC, MOUNT_ATTR_NODEV},
> +	{"Flag CLOEXEC, attr NOEXEC", FSMOUNT_CLOEXEC, MOUNT_ATTR_NOEXEC},
> +	{"Flag CLOEXEC, attr RELATIME", FSMOUNT_CLOEXEC, MOUNT_ATTR_RELATIME},
> +	{"Flag CLOEXEC, attr NOATIME", FSMOUNT_CLOEXEC, MOUNT_ATTR_NOATIME},
> +	{"Flag CLOEXEC, attr STRICTATIME", FSMOUNT_CLOEXEC, MOUNT_ATTR_STRICTATIME},
> +	{"Flag CLOEXEC, attr NODIRATIME", FSMOUNT_CLOEXEC, MOUNT_ATTR_NODIRATIME},
> +};
I'd use desc field

#define DESC(x, y) .flags = x, .mount_attrs = y, .desc = #x ", " #y

+static struct tcase {
+	char *desc;
+	unsigned int flags;
+	unsigned int mount_attrs;
+} tcases[] = {
+	{DESC(0, MOUNT_ATTR_RDONLY)},
+	{DESC(0, MOUNT_ATTR_NOSUID)},

(avoid copy paste).

> +static void setup(void)
>  {
> -	if (is_mounted)
> -		SAFE_UMOUNT(MNTPOINT);
> +	fsopen_supported_by_kernel();
again, just .setup = fsopen_supported_by_kernel;
>  }

> -static void test_fsmount(void)
> +static void run(unsigned int n)
>  {
> +	struct tcase *tc = &tcases[n];
> +	int sfd, mfd;
> +
>  	TEST(fsopen(tst_device->fs_type, FSOPEN_CLOEXEC));
> -	if (TST_RET < 0)
> -		tst_brk(TBROK | TTERRNO, "fsopen() on %s failed", tst_device->fs_type);
> +	if (TST_RET == -1) {
> +		tst_brk(TBROK | TTERRNO, "fsopen() on %s failed",
> +			tst_device->fs_type);
Again, tst_brk(TBROK) shouldn't be on tcnt = ARRAY_SIZE(tcases),
it skips all following tests after failure (sometimes needed but IMHO not here).

> +	}
>  	sfd = TST_RET;
> -	tst_res(TPASS, "fsopen() on %s", tst_device->fs_type);

>  	TEST(fsconfig(sfd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
> -	if (TST_RET < 0)
> +	if (TST_RET < 0) {
> +		SAFE_CLOSE(sfd);
>  		tst_brk(TBROK | TTERRNO,
>  			"fsconfig() failed to set source to %s", tst_device->dev);
> -	tst_res(TPASS, "fsconfig() set source to %s", tst_device->dev);
> -
> +	}

>  	TEST(fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
> -	if (TST_RET < 0)
> +	if (TST_RET < 0) {
> +		SAFE_CLOSE(sfd);
>  		tst_brk(TBROK | TTERRNO, "fsconfig() created superblock");
As you added more runs of the test (changed .test_all to .test && run =
ARRAY_SIZE(tcases)), you need to change all tst_brk() to tst_res() + return.

I also merged tst_brk(TBROK), I guess TFAIL would be better.

Other than that it looks ok.

I also wonder if it'd be worth to implement in fsmount.h some macros to reduce
code duplicity. e.g. one of similar patterns (just flag is different):

TEST(fsopen(tst_device->fs_type, FLAG));
fd = TST_RET;
if (fd == -1)
		tst_brk(TBROK | TERRNO, "fsopen() failed");

But that's not important.

Kind regards,
Petr

  parent reply	other threads:[~2020-02-20 17:34 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19  9:27 [LTP] [PATCH V2 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
2020-02-19  9:27 ` [LTP] [PATCH V2 01/10] tst_device: Add tst_ismount() helper Viresh Kumar
2020-02-20  5:10   ` Li Wang
2020-02-20  5:20     ` Viresh Kumar
2020-02-20  7:06   ` Li Wang
2020-02-20  7:19     ` Viresh Kumar
2020-02-20  7:52       ` Petr Vorel
2020-02-19  9:27 ` [LTP] [PATCH V2 02/10] lapi/fsmount.h: Add fsopen_supported_by_kernel() Viresh Kumar
2020-02-20  8:01   ` Petr Vorel
2020-02-19  9:27 ` [LTP] [PATCH V2 03/10] lapi/fsmount.h: Include "lapi/fcntl.h" Viresh Kumar
2020-02-19  9:28 ` [LTP] [PATCH V2 04/10] syscalls/fsopen: New tests Viresh Kumar
2020-02-20  5:23   ` Li Wang
2020-02-20  8:51     ` Petr Vorel
2020-02-20 17:04   ` Petr Vorel
2020-02-24  3:18     ` Viresh Kumar
2020-02-24  3:35       ` Yang Xu
2020-02-24  6:27         ` Petr Vorel
2020-02-24 13:08       ` Cyril Hrubis
2020-02-24 15:30         ` Petr Vorel
2020-02-24 15:32           ` Cyril Hrubis
2020-02-24 15:46             ` Petr Vorel
2020-02-19  9:28 ` [LTP] [PATCH V2 05/10] syscalls/fsconfig: " Viresh Kumar
2020-02-20  5:41   ` Li Wang
2020-02-20  5:50     ` Viresh Kumar
2020-02-20 10:09       ` Li Wang
2020-02-21 16:44     ` Petr Vorel
2020-02-19  9:28 ` [LTP] [PATCH V2 06/10] syscalls/fsmount: Improve fsmount01 test Viresh Kumar
2020-02-20  6:34   ` Li Wang
2020-02-20 17:34   ` Petr Vorel [this message]
2020-02-19  9:28 ` [LTP] [PATCH V2 07/10] syscalls/fsmount: Add failure tests Viresh Kumar
2020-02-19  9:28 ` [LTP] [PATCH V2 08/10] syscalls/move_mount: New tests Viresh Kumar
2020-02-19  9:28 ` [LTP] [PATCH V2 09/10] syscalls/fspick: " Viresh Kumar
2020-02-20  7:57   ` Li Wang
2020-02-19  9:28 ` [LTP] [PATCH V2 10/10] syscalls/open_tree: " Viresh Kumar
2020-02-20  7:25   ` Li Wang
2020-02-20  7:35     ` Viresh Kumar

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=20200220173439.GC15699@gacrux.arch.suse.de \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    /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