diff mbox series

[v2,1/6] idmapped-mounts: prepare for additional tests

Message ID 20210731165834.479633-2-brauner@kernel.org (mailing list archive)
State New, archived
Headers show
Series Extend idmapped mount testsuite | expand

Commit Message

Christian Brauner July 31, 2021, 4:58 p.m. UTC
From: Christian Brauner <christian.brauner@ubuntu.com>

- Use sequential option numbering for option parsing since we're only
  using longopts anyway and to easier correlate test parsing in the
  switch with the options specified in longopts.
- Introduce an explicit command line switch to runs the basic test
  suite. This prepares for the introduction of additional command line
  switches to run tests.
- Update help output.
- Use die() when logging test failure.

Cc: fstests@vger.kernel.org
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
/* v2 */
new patch
---
 src/idmapped-mounts/idmapped-mounts.c | 44 +++++++++++++++------------
 tests/generic/633                     |  3 +-
 2 files changed, 27 insertions(+), 20 deletions(-)

Comments

Christoph Hellwig Aug. 10, 2021, 8:15 a.m. UTC | #1
On Sat, Jul 31, 2021 at 06:58:29PM +0200, Christian Brauner wrote:
> From: Christian Brauner <christian.brauner@ubuntu.com>
> 
> - Use sequential option numbering for option parsing since we're only
>   using longopts anyway and to easier correlate test parsing in the
>   switch with the options specified in longopts.

These sequential options are rally weird.  Why not use getopt_long_only?

>
> - Introduce an explicit command line switch to runs the basic test
>   suite. This prepares for the introduction of additional command line
>   switches to run tests.
> - Update help output.
> - Use die() when logging test failure.

Each of these changes really should be a separate patch.
Christian Brauner Aug. 10, 2021, 2:03 p.m. UTC | #2
On Tue, Aug 10, 2021 at 10:15:49AM +0200, Christoph Hellwig wrote:
> On Sat, Jul 31, 2021 at 06:58:29PM +0200, Christian Brauner wrote:
> > From: Christian Brauner <christian.brauner@ubuntu.com>
> > 
> > - Use sequential option numbering for option parsing since we're only
> >   using longopts anyway and to easier correlate test parsing in the
> >   switch with the options specified in longopts.
> 
> These sequential options are rally weird.  Why not use getopt_long_only?

Good point! Let me see if I can make that work.

> 
> >
> > - Introduce an explicit command line switch to runs the basic test
> >   suite. This prepares for the introduction of additional command line
> >   switches to run tests.
> > - Update help output.
> > - Use die() when logging test failure.
> 
> Each of these changes really should be a separate patch.

Ok, will split this up.

Thanks for the reviews, much appreciated!
Christian
diff mbox series

Patch

diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c
index 2c212131..c8635362 100644
--- a/src/idmapped-mounts/idmapped-mounts.c
+++ b/src/idmapped-mounts/idmapped-mounts.c
@@ -8717,19 +8717,24 @@  static void usage(void)
 	fprintf(stderr, "    Run idmapped mount tests\n\n");
 
 	fprintf(stderr, "Arguments:\n");
-	fprintf(stderr, "-d --device        Device used in the tests\n");
-	fprintf(stderr, "-m --mountpoint    Mountpoint of device\n");
+	fprintf(stderr, "--device        Device used in the tests\n");
+	fprintf(stderr, "--fstype        Filesystem type used in the tests\n");
+	fprintf(stderr, "--help          Print help\n");
+	fprintf(stderr, "--mountpoint    Mountpoint of device\n");
+	fprintf(stderr, "--supported     Test whether idmapped mounts are supported on this filesystem\n");
+	fprintf(stderr, "--test-core     Run core idmapped mount testsuite\n");
 
 	_exit(EXIT_SUCCESS);
 }
 
 static const struct option longopts[] = {
-	{"device",	required_argument,	0,	'd'},
-	{"fstype",	required_argument,	0,	'f'},
-	{"mountpoint",	required_argument,	0,	'm'},
-	{"supported",	no_argument,		0,	's'},
-	{"help",	no_argument,		0,	'h'},
-	{NULL,		0,			0,	0  },
+	{"device",	required_argument,	0,	1},
+	{"fstype",	required_argument,	0,	2},
+	{"mountpoint",	required_argument,	0,	3},
+	{"supported",	no_argument,		0,	4},
+	{"help",	no_argument,		0,	5},
+	{"test-core",	no_argument,		0,	6},
+	{NULL,		0,			0,	0},
 };
 
 struct t_idmapped_mounts {
@@ -8804,10 +8809,8 @@  static bool run_test(struct t_idmapped_mounts suite[], size_t suite_size)
 
 		if (pid == 0) {
 			ret = t->test();
-			if (ret) {
-				fprintf(stderr, "failure: %s\n", t->description);
-				exit(EXIT_FAILURE);
-			}
+			if (ret)
+				die("failure: %s", t->description);
 
 			exit(EXIT_SUCCESS);
 		}
@@ -8826,23 +8829,26 @@  int main(int argc, char *argv[])
 {
 	int fret, ret;
 	int index = 0;
-	bool supported = false;
+	bool supported = false, test_core = false;
 
 	while ((ret = getopt_long(argc, argv, "", longopts, &index)) != -1) {
 		switch (ret) {
-		case 'd':
+		case 1:
 			t_device = optarg;
 			break;
-		case 'f':
+		case 2:
 			t_fstype = optarg;
 			break;
-		case 'm':
+		case 3:
 			t_mountpoint = optarg;
 			break;
-		case 's':
+		case 4:
 			supported = true;
 			break;
-		case 'h':
+		case 6:
+			test_core = true;
+			break;
+		case 5:
 			/* fallthrough */
 		default:
 			usage();
@@ -8911,7 +8917,7 @@  int main(int argc, char *argv[])
 
 	fret = EXIT_FAILURE;
 
-	if (!run_test(basic_suite, ARRAY_SIZE(basic_suite)))
+	if (test_core && !run_test(basic_suite, ARRAY_SIZE(basic_suite)))
 		goto out;
 
 	fret = EXIT_SUCCESS;
diff --git a/tests/generic/633 b/tests/generic/633
index 6be8a69e..67501177 100755
--- a/tests/generic/633
+++ b/tests/generic/633
@@ -20,7 +20,8 @@  _require_test
 
 echo "Silence is golden"
 
-$here/src/idmapped-mounts/idmapped-mounts --device "$TEST_DEV" --mount "$TEST_DIR" --fstype "$FSTYP"
+$here/src/idmapped-mounts/idmapped-mounts --test-core --device "$TEST_DEV" \
+	--mount "$TEST_DIR" --fstype "$FSTYP"
 
 status=$?
 exit