All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 4/6] Rewrite mountns04 test using new LTP API
Date: Tue,  1 Mar 2022 10:15:15 +0100	[thread overview]
Message-ID: <20220301091517.11142-5-andrea.cervesato@suse.de> (raw)
In-Reply-To: <20220301091517.11142-1-andrea.cervesato@suse.de>

Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.de>
---
 .../kernel/containers/mountns/mountns04.c     | 109 ++++++++----------
 1 file changed, 46 insertions(+), 63 deletions(-)

diff --git a/testcases/kernel/containers/mountns/mountns04.c b/testcases/kernel/containers/mountns/mountns04.c
index 1f022a683..044c90aa7 100644
--- a/testcases/kernel/containers/mountns/mountns04.c
+++ b/testcases/kernel/containers/mountns/mountns04.c
@@ -1,89 +1,72 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: mountns04.c
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
  * Tests an unbindable mount: unbindable mount is an unbindable
  * private mount.
- * Description:
- * 1. Creates directories "A", "B" and files "A/A", "B/B"
- * 2. Unshares mount namespace and makes it private (so mounts/umounts
- *    have no effect on a real system)
- * 3. Bind mounts directory "A" to "A"
- * 4. Makes directory directory "A" unbindable
- * 5. Tries to bind mount unbindable "A" to "B":
- *    - if it fails, test passes
- *    - if it passes, test fails
- ***********************************************************************/
+ *
+ * [Algorithm]
+ *
+ * . Creates directories "A", "B" and files "A/A", "B/B"
+ * . Unshares mount namespace and makes it private (so mounts/umounts have no
+ *   effect on a real system)
+ * . Bind mounts directory "A" to "A"
+ * . Makes directory "A" unbindable
+ * . Tries to bind mount unbindable "A" to "B":
+ * .. if it fails, test passes
+ * .. if it passes, test fails
+ */
 
-#define _GNU_SOURCE
 #include <sys/wait.h>
 #include <sys/mount.h>
-#include <stdio.h>
-#include <errno.h>
-#include "mountns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID	= "mountns04";
-int TST_TOTAL	= 1;
-
-#if defined(MS_SHARED) && defined(MS_PRIVATE) \
-    && defined(MS_REC) && defined(MS_UNBINDABLE)
+#include "mountns.h"
+#include "tst_test.h"
 
-static void test(void)
+static void run(void)
 {
 	/* unshares the mount ns */
-	if (unshare(CLONE_NEWNS) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
+	SAFE_UNSHARE(CLONE_NEWNS);
+
 	/* makes sure mounts/umounts have no effect on a real system */
-	SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL);
+	SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
 
 	/* bind mounts DIRA to itself */
-	SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL);
+	SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
+
 	/* makes mount DIRA unbindable */
-	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_UNBINDABLE, NULL);
+	SAFE_MOUNT("none", DIRA, "none", MS_UNBINDABLE, NULL);
 
 	/* tries to bind mount unbindable DIRA to DIRB which should fail */
 	if (mount(DIRA, DIRB, "none", MS_BIND, NULL) == -1) {
-		tst_resm(TPASS, "unbindable mount passed");
+		tst_res(TPASS, "unbindable mount passed");
 	} else {
-		SAFE_UMOUNT(cleanup, DIRB);
-		tst_resm(TFAIL, "unbindable mount faled");
+		SAFE_UMOUNT(DIRB);
+		tst_res(TFAIL, "unbindable mount faled");
 	}
 
-	SAFE_UMOUNT(cleanup, DIRA);
+	SAFE_UMOUNT(DIRA);
 }
 
-int main(int argc, char *argv[])
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
+	check_newns();
+	create_folders();
 }
 
-#else
-int main(void)
+static void cleanup(void)
 {
-	tst_brkm(TCONF, NULL, "needed mountflags are not defined");
+	umount_folders();
 }
-#endif
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
-- 
2.35.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2022-03-01  9:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01  9:15 [LTP] [PATCH v3 0/6] Rewrite mountns testing suite Andrea Cervesato
2022-03-01  9:15 ` [LTP] [PATCH v3 1/6] Rewrite mountns01 test using new LTP API Andrea Cervesato
2022-03-01 14:35   ` Cyril Hrubis
2022-03-01 15:18     ` Cyril Hrubis
2022-03-01  9:15 ` [LTP] [PATCH v3 2/6] Rewrite mountns02 " Andrea Cervesato
2022-03-01  9:15 ` [LTP] [PATCH v3 3/6] Rewrite mountns03 " Andrea Cervesato
2022-03-01  9:15 ` Andrea Cervesato [this message]
2022-03-01  9:15 ` [LTP] [PATCH v3 5/6] Removed obsolete mountns_helper.h Andrea Cervesato
2022-03-01  9:15 ` [LTP] [PATCH v3 6/6] Removed libclone usage from mountns testing suite Andrea Cervesato

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=20220301091517.11142-5-andrea.cervesato@suse.de \
    --to=andrea.cervesato@suse.de \
    --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 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.