All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Eryu Guan <guan@eryu.me>, fstests@vger.kernel.org
Cc: Christoph Hellwig <hch@lst.de>,
	Christian Brauner <christian.brauner@ubuntu.com>
Subject: [PATCH 3/7] idmapped-mounts: split out run_test() function
Date: Fri,  7 May 2021 17:00:56 +0200	[thread overview]
Message-ID: <20210507150100.968659-4-brauner@kernel.org> (raw)
In-Reply-To: <20210507150100.968659-1-brauner@kernel.org>

From: Christian Brauner <christian.brauner@ubuntu.com>

to make it easier to run subsets of tests.

Cc: fstests@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
 src/idmapped-mounts/idmapped-mounts.c | 70 ++++++++++++++++-----------
 1 file changed, 41 insertions(+), 29 deletions(-)

diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c
index 59a3daa8..4d93b721 100644
--- a/src/idmapped-mounts/idmapped-mounts.c
+++ b/src/idmapped-mounts/idmapped-mounts.c
@@ -82,6 +82,8 @@
 
 #define die(format, ...) die_errno(errno, format, ##__VA_ARGS__)
 
+#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
+
 uid_t t_overflowuid = 65534;
 gid_t t_overflowgid = 65534;
 
@@ -8735,7 +8737,7 @@ static const struct option longopts[] = {
 struct t_idmapped_mounts {
 	int (*test)(void);
 	const char *description;
-} t_idmapped_mounts[] = {
+} basic_suite[] = {
 	{ acls,								"posix acls on regular mounts",									},
 	{ create_in_userns,						"create operations in user namespace",								},
 	{ device_node_in_userns,					"device node in user namespace",								},
@@ -8787,9 +8789,44 @@ struct t_idmapped_mounts {
 	{ threaded_idmapped_mount_interactions,				"threaded operations on idmapped mounts",							},
 };
 
+static bool run_test(struct t_idmapped_mounts suite[], size_t suite_size)
+{
+	int i;
+
+	for (i = 0; i < suite_size; i++) {
+		struct t_idmapped_mounts *t = &suite[i];
+		int ret;
+		pid_t pid;
+
+		test_setup();
+
+		pid = fork();
+		if (pid < 0)
+			return false;
+
+		if (pid == 0) {
+			ret = t->test();
+			if (ret) {
+				fprintf(stderr, "failure: %s\n", t->description);
+				exit(EXIT_FAILURE);
+			}
+
+			exit(EXIT_SUCCESS);
+		}
+
+		ret = wait_for_pid(pid);
+		test_cleanup();
+
+		if (ret)
+			return false;
+	}
+
+	return true;
+}
+
 int main(int argc, char *argv[])
 {
-	int i, fret, ret;
+	int fret, ret;
 	int index = 0;
 	bool supported = false;
 
@@ -8876,33 +8913,8 @@ int main(int argc, char *argv[])
 
 	fret = EXIT_FAILURE;
 
-	/* Proper test suite run. */
-	for (i = 0; i < (sizeof(t_idmapped_mounts) / sizeof(t_idmapped_mounts[0])); i++) {
-		struct t_idmapped_mounts *t = &t_idmapped_mounts[i];
-		pid_t pid;
-
-		test_setup();
-
-		pid = fork();
-		if (pid < 0)
-			goto out;
-
-		if (pid == 0) {
-			ret = t->test();
-			if (ret) {
-				fprintf(stderr, "failure: %s\n", t->description);
-				exit(EXIT_FAILURE);
-			}
-
-			exit(EXIT_SUCCESS);
-		}
-
-		ret = wait_for_pid(pid);
-		test_cleanup();
-
-		if (ret)
-			goto out;
-	}
+	if (!run_test(basic_suite, ARRAY_SIZE(basic_suite)))
+		goto out;
 
 	fret = EXIT_SUCCESS;
 
-- 
2.27.0


  parent reply	other threads:[~2021-05-07 15:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-07 15:00 [PATCH 0/7] idmapped mounts: extend testsuite and fixes Christian Brauner
2021-05-07 15:00 ` [PATCH 1/7] idmapped-mounts: remove unused set_cloexec() helper Christian Brauner
2021-05-07 15:00 ` [PATCH 2/7] idmapped-mounts: add missing newline to print_r() Christian Brauner
2021-05-07 15:00 ` Christian Brauner [this message]
2021-05-07 15:00 ` [PATCH 4/7] generic/637: add fscaps regression test Christian Brauner
2021-05-23 15:07   ` Eryu Guan
2021-05-07 15:00 ` [PATCH 5/7] idmapped-mounts: refactor helpers Christian Brauner
2021-05-07 15:00 ` [PATCH 6/7] idmapped-mounts: add nested userns creation helpers Christian Brauner
2021-05-07 15:01 ` [PATCH 7/7] generic/638: add nested user namespace tests Christian Brauner
2021-05-23 15:08 ` [PATCH 0/7] idmapped mounts: extend testsuite and fixes Eryu Guan

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=20210507150100.968659-4-brauner@kernel.org \
    --to=brauner@kernel.org \
    --cc=christian.brauner@ubuntu.com \
    --cc=fstests@vger.kernel.org \
    --cc=guan@eryu.me \
    --cc=hch@lst.de \
    /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.