All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Eryu Guan <guaneryu@gmail.com>, Zorro Lang <zlang@redhat.com>,
	fstests <fstests@vger.kernel.org>
Cc: Christian Brauner <brauner@kernel.org>,
	Dave Chinner <david@fromorbit.com>,
	Amir Goldstein <amir73il@gmail.com>,
	Christoph Hellwig <hch@lst.de>, Jan Kara <jack@suse.cz>,
	"Darrick J. Wong" <djwong@kernel.org>
Subject: [PATCH 08/11] utils: add struct test_suite
Date: Thu, 28 Apr 2022 17:15:56 +0200	[thread overview]
Message-ID: <20220428151559.947144-9-brauner@kernel.org> (raw)
In-Reply-To: <20220428151559.947144-1-brauner@kernel.org>

Provide a convenient wrapper struct which provides the tests and the
number of tests. The struct can be kept local to each source file so we
are sure that the tests and number of tests is correct.

In vfstest.c we provide a run_suite() function which expects a struct
test_suite and runs the tests provided by that suite.

Cc: Dave Chinner <david@fromorbit.com>
Cc: Amir Goldstein <amir73il@gmail.com>
Cc: Eryu Guan <guaneryu@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Zorro Lang <zlang@redhat.com>
Cc: "Darrick J. Wong" <djwong@kernel.org>
Cc: fstests <fstests@vger.kernel.org>
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
---
 src/vfs/utils.h   |  5 +++++
 src/vfs/vfstest.c | 54 +++++++++++++++++++++++++++++++++++------------
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/src/vfs/utils.h b/src/vfs/utils.h
index 3f7cf911..a13efabb 100644
--- a/src/vfs/utils.h
+++ b/src/vfs/utils.h
@@ -198,6 +198,11 @@ struct test_struct {
 	const char *description;
 };
 
+struct test_suite {
+	size_t nr_tests;
+	const struct test_struct *tests;
+};
+
 typedef enum idmap_type_t {
 	ID_TYPE_UID,
 	ID_TYPE_GID
diff --git a/src/vfs/vfstest.c b/src/vfs/vfstest.c
index f6c8c194..e8025e81 100644
--- a/src/vfs/vfstest.c
+++ b/src/vfs/vfstest.c
@@ -13204,7 +13204,7 @@ static const struct option longopts[] = {
 	{NULL,					0,			0,	  0},
 };
 
-struct test_struct basic_suite[] = {
+static const struct test_struct t_basic[] = {
 	{ acls,								true,	"posix acls on regular mounts",									},
 	{ create_in_userns,						true,	"create operations in user namespace",								},
 	{ device_node_in_userns,					true,	"device node in user namespace",								},
@@ -13256,15 +13256,30 @@ struct test_struct basic_suite[] = {
 	{ threaded_idmapped_mount_interactions,				true,	"threaded operations on idmapped mounts",							},
 };
 
-struct test_struct fscaps_in_ancestor_userns[] = {
+static const struct test_suite s_basic = {
+	.tests = t_basic,
+	.nr_tests = ARRAY_SIZE(t_basic),
+};
+
+static const struct test_struct t_fscaps_in_ancestor_userns[] = {
 	{ fscaps_idmapped_mounts_in_userns_valid_in_ancestor_userns,	true,	"fscaps on idmapped mounts in user namespace writing fscap valid in ancestor userns",		},
 };
 
-struct test_struct t_nested_userns[] = {
+static const struct test_suite s_fscaps_in_ancestor_userns = {
+	.tests = t_fscaps_in_ancestor_userns,
+	.nr_tests = ARRAY_SIZE(t_fscaps_in_ancestor_userns),
+};
+
+static const struct test_struct t_nested_userns[] = {
 	{ nested_userns,						true,	"test that nested user namespaces behave correctly when attached to idmapped mounts",		},
 };
 
-struct test_struct t_btrfs[] = {
+static const struct test_suite s_nested_userns = {
+	.tests = t_nested_userns,
+	.nr_tests = ARRAY_SIZE(t_nested_userns),
+};
+
+static const struct test_struct t_btrfs[] = {
 	{ btrfs_subvolumes_fsids_mapped,				true,	"test subvolumes with mapped fsids",								},
 	{ btrfs_subvolumes_fsids_mapped_userns,				true, 	"test subvolumes with mapped fsids inside user namespace",					},
 	{ btrfs_subvolumes_fsids_mapped_user_subvol_rm_allowed,		true, 	"test subvolume deletion with user_subvol_rm_allowed mount option",				},
@@ -13289,11 +13304,21 @@ struct test_struct t_btrfs[] = {
 	{ btrfs_subvolume_lookup_user,					true, 	"test unprivileged subvolume lookup",								},
 };
 
+static const struct test_suite s_btrfs = {
+	.tests = t_btrfs,
+	.nr_tests = ARRAY_SIZE(t_btrfs),
+};
+
 /* Test for commit 968219708108 ("fs: handle circular mappings correctly"). */
-struct test_struct t_setattr_fix_968219708108[] = {
+static const struct test_struct t_setattr_fix_968219708108[] = {
 	{ setattr_fix_968219708108,					true,	"test that setattr works correctly",								},
 };
 
+static const struct test_suite s_setattr_fix_968219708108 = {
+	.tests = t_setattr_fix_968219708108,
+	.nr_tests = ARRAY_SIZE(t_setattr_fix_968219708108),
+};
+
 static bool run_test(struct vfstest_info *info, const struct test_struct suite[], size_t suite_size)
 {
 	int i;
@@ -13336,6 +13361,12 @@ static bool run_test(struct vfstest_info *info, const struct test_struct suite[]
 	return true;
 }
 
+static inline bool run_suite(struct vfstest_info *info,
+			     const struct test_suite *suite)
+{
+	return run_test(info, suite->tests, suite->nr_tests);
+}
+
 static bool fs_allow_idmap(const struct vfstest_info *info)
 {
 	int ret;
@@ -13460,24 +13491,21 @@ int main(int argc, char *argv[])
 
 	fret = EXIT_FAILURE;
 
-	if (test_core && !run_test(&info, basic_suite, ARRAY_SIZE(basic_suite)))
+	if (test_core && !run_suite(&info, &s_basic))
 		goto out;
 
 	if (test_fscaps_regression &&
-	    !run_test(&info, fscaps_in_ancestor_userns,
-		      ARRAY_SIZE(fscaps_in_ancestor_userns)))
+	    !run_suite(&info, &s_fscaps_in_ancestor_userns))
 		goto out;
 
-	if (test_nested_userns &&
-	    !run_test(&info, t_nested_userns, ARRAY_SIZE(t_nested_userns)))
+	if (test_nested_userns && !run_suite(&info, &s_nested_userns))
 		goto out;
 
-	if (test_btrfs && !run_test(&info, t_btrfs, ARRAY_SIZE(t_btrfs)))
+	if (test_btrfs && !run_suite(&info, &s_btrfs))
 		goto out;
 
 	if (test_setattr_fix_968219708108 &&
-	    !run_test(&info, t_setattr_fix_968219708108,
-		      ARRAY_SIZE(t_setattr_fix_968219708108)))
+	    !run_suite(&info, &s_setattr_fix_968219708108))
 		goto out;
 
 	fret = EXIT_SUCCESS;
-- 
2.32.0


  parent reply	other threads:[~2022-04-28 15:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 15:15 [PATCH 00/11] rename & split tests Christian Brauner
2022-04-28 15:15 ` [PATCH 01/11] src: rename idmapped-mounts folder Christian Brauner
2022-04-28 15:15 ` [PATCH 02/11] src/vfs: rename idmapped-mounts.c file Christian Brauner
2022-04-28 15:15 ` [PATCH 03/11] vfstest: rename struct t_idmapped_mounts Christian Brauner
2022-04-28 15:15 ` [PATCH 04/11] utils: add missing global.h include Christian Brauner
2022-04-28 15:15 ` [PATCH 06/11] utils: move helpers into utils Christian Brauner
2022-04-28 15:15 ` [PATCH 07/11] missing: move sys_execveat() to missing.h Christian Brauner
2022-04-28 15:15 ` Christian Brauner [this message]
2022-04-28 15:15 ` [PATCH 11/11] vfstest: split out remaining idmapped mount tests Christian Brauner
2022-04-29 15:20 ` [PATCH 00/11] rename & split tests Christoph Hellwig
2022-05-01 11:46 ` Zorro Lang
2022-05-07 12:01   ` Christian Brauner
2022-05-07 12:03   ` Christian Brauner
2022-05-07 12:50     ` Zorro Lang
2022-05-07 15:43       ` Christian Brauner

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=20220428151559.947144-9-brauner@kernel.org \
    --to=brauner@kernel.org \
    --cc=amir73il@gmail.com \
    --cc=david@fromorbit.com \
    --cc=djwong@kernel.org \
    --cc=fstests@vger.kernel.org \
    --cc=guaneryu@gmail.com \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=zlang@redhat.com \
    /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.