Skip to contentSkip to conversation

Refactor mount01 test using new LTP API

PATCH Superseded Andrea Cervesato 3 participants 4 messages Feb 9, 2024 – Feb 13, 2024

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Refactor mount01 test using new LTP API

From: Andrea Cervesato <[email protected]>

---
 testcases/kernel/syscalls/mount/mount01.c | 117 +++++++---------------
 1 file changed, 35 insertions(+), 82 deletions(-)
testcases/kernel/syscalls/mount/mount01.c +35 -82
index 1d902ba89..ceb9bd075 100644
@@ -1,99 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
+ *               Nirmala Devi Dhanasekar <[email protected]>
+ * Copyright (C) 2023 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+/*\
+ * [Description]
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- *    AUTHOR		: Nirmala Devi Dhanasekar <[email protected]>
- *
- *    DESCRIPTION
- *	This is a Phase I test for the mount(2) system call.
- *	It is intended to provide a limited exposure of the system call.
+ * Basic test that checks `mount` syscall works on multiple filesystems.
  */
 
-#include <errno.h>
+#include "tst_test.h"
 #include <sys/mount.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "test.h"
-#include "safe_macros.h"
-
-static void setup(void);
-static void cleanup(void);
 
-char *TCID = "mount01";
-int TST_TOTAL = 1;
-
-#define DIR_MODE (S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP)
 #define MNTPOINT "mntpoint"
 
-static const char *device;
-static const char *fs_type;
-
-int main(int ac, char **av)
+static void cleanup(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(mount(device, MNTPOINT, fs_type, 0, NULL));
-
-		if (TEST_RETURN != 0) {
-			tst_resm(TFAIL | TTERRNO, "mount(2) failed");
-		} else {
-			tst_resm(TPASS, "mount(2) passed ");
-			TEST(tst_umount(MNTPOINT));
-			if (TEST_RETURN != 0) {
-				tst_brkm(TBROK | TTERRNO, cleanup,
-					 "umount(2) failed");
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	if (tst_is_mounted(MNTPOINT))
+		SAFE_UMOUNT(MNTPOINT);
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
+	TST_EXP_PASS(mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL));
 
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
+	if (tst_is_mounted(MNTPOINT)) {
+		tst_res(TPASS, "folder has been mounted");
 
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	TEST_PAUSE;
+		SAFE_UMOUNT(MNTPOINT);
+	} else {
+		tst_res(TFAIL, "folder has not been mounted");
+	}
 }
 
-static void cleanup(void)
-{
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.format_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.skip_filesystems = (const char *const []){
+		"exfat",
+		"vfat",
+		"ntfs",
+		NULL
+	},
+};
Signature · 5 lines
2.35.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Andrea,

...

testcases/kernel/syscalls/mount/mount01.c line 42

Quoted 3 lines
testcases/kernel/syscalls/mount/mount01.c +3 -0
+	.test_all = run,
+	.needs_root = 1,
+	.needs_tmpdir = 1,

Also this is redundant due .all_filesystems = 1.

testcases/kernel/syscalls/mount/mount01.c line 49

Quoted 7 lines
testcases/kernel/syscalls/mount/mount01.c +7 -0
+	.format_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.skip_filesystems = (const char *const []){
+		"exfat",
+		"vfat",
+		"ntfs",

Skip only ntfs, which is problamatic on fuse (ntfs-3g). vfat and exfat are OK and deserved to be tested.

Merged also with Martin's RBT.
Thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 1 line · Petr Vorel

Merged also with Martin's RBT.

Please do *NOT* add patch review tags which I didn't send myself. Thank you.

Signature · 11 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi Martin,

Quoted 4 lines · Petr Vorel
Quoted 1 line

Merged also with Martin's RBT.

Please do *NOT* add patch review tags which I didn't send myself. Thank you.

I'm sorry, I will not do in the future.

The reason I added it was that you obviously spent time reviewing previous version and I did not want you to credit your work, but I agree this is not a approach.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp