Skip to contentSkip to conversation

tst_test: Handle device mkfs/mount int the library

PATCH New Cyril Hrubis 2 participants 6 messages Feb 14, 2017 – Mar 1, 2017 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 tst_test: Handle device mkfs/mount int the library

This commit adds functionality to format and then mount the test device to the test library which:

* Saves a few setup steps in most of the testcases that use test device

* The device is umounted in the test library process now -> it will be umounted even if the test process has segfaulted.

+ docs

---
 doc/test-writing-guidelines.txt | 14 ++++++++++++--
 include/tst_test.h              | 18 +++++++++++++++++-
 lib/newlib_tests/tst_device.c   |  4 ++--
 lib/tst_test.c                  | 39 +++++++++++++++++++++++++++++++++++++--
 4 files changed, 68 insertions(+), 7 deletions(-)
doc/test-writing-guidelines.txt +12 -2
index a33efb1..4256427 100644
@@ -911,8 +911,18 @@ structure is initialized with a path to a test device and default filesystem
 to be used.
 
 You can also request minimal device size in megabytes by setting
-'.device_min_size' in the 'struct tst_test' structure. The device is
-guaranteed to have at least the requested size then.
+'.dev_min_size' the device is guaranteed to have at least the requested size
+then.
+
+If '.format_device' flag is set the device is formatted with a filesystem as
+well. You can use '.dev_fs_type' to override the default filesystem type if
+needed and pass additional options to mkfs via '.dev_fs_opts' and
+'.dev_extra_opt' pointers.
+
+If '.mount_device' is set, the device is mounted at '.mntpoint' which is used
+to pass a directory name that will be created and used as mount destination.
+You can pass additional flags and data to the mount command via '.mnt_flags'
+and '.mnt_data' pointers.
 
 [source,c]
 -------------------------------------------------------------------------------
include/tst_test.h +17 -1
index 1ed39db..b196a7d 100644
@@ -117,8 +117,24 @@ struct tst_test {
 	int forks_child:1;
 	int needs_device:1;
 	int needs_checkpoints:1;
+	int format_device:1;
+	int mount_device:1;
 
-	unsigned int device_min_size;
+	/* Minimal device size in bytes */
+	unsigned int dev_min_size;
+
+	/* Device filesystem type override NULL == default */
+	const char *dev_fs_type;
+
+	/* Options passed to SAFE_MKFS() when format_device is set */
+	struct tst_dev_opts *dev_opts;
+	const char *const *dev_fs_opts;
+	const char *dev_extra_opt;
+
+	/* Device mount options, used if mount_device is set */
+	const char *mntpoint;
+	unsigned int mnt_flags;
+	void *mnt_data;
 
 	/* override default timeout per test run */
 	unsigned int timeout;
lib/newlib_tests/tst_device.c +2 -2
index 72c2033..9bcdce1 100644
@@ -37,7 +37,7 @@ static void do_test(void)
 	SAFE_IOCTL(fd, BLKGETSIZE64, &ltp_dev_size);
 	SAFE_CLOSE(fd);
 
-	if (ltp_dev_size/1024/1024 == 160)
+	if (ltp_dev_size/1024/1024 == 300)
 		tst_res(TPASS, "Got expected device size");
 	else
 		tst_res(TFAIL, "Got unexpected device size");
@@ -47,6 +47,6 @@ static struct tst_test test = {
 	.tid = "tst_device",
 	.needs_tmpdir = 1,
 	.needs_device = 1,
-	.device_min_size = 160,
+	.dev_min_size = 300,
 	.test_all = do_test,
 };
lib/tst_test.c +37 -2
index f19f763..f87d9a9 100644
@@ -40,6 +40,7 @@ struct tst_test *tst_test;
 static int iterations = 1;
 static float duration = -1;
 static pid_t main_pid, lib_pid;
+static int device_mounted;
 
 struct results {
 	int passed;
@@ -644,6 +645,14 @@ static void do_setup(int argc, char *argv[])
 	if (tst_test->min_kver)
 		check_kver();
 
+	if (tst_test->format_device)
+		tst_test->needs_device = 1;
+
+	if (tst_test->mount_device) {
+		tst_test->needs_device = 1;
+		tst_test->format_device = 1;
+	}
+
 	parse_opts(argc, argv);
 
 	setup_ipc();
@@ -652,13 +661,36 @@ static void do_setup(int argc, char *argv[])
 		tst_tmpdir();
 
 	if (tst_test->needs_device) {
-		tdev.dev = tst_acquire_device_(NULL, tst_test->device_min_size);
-		tdev.fs_type = tst_dev_fs_type();
+		tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size);
 
 		if (!tdev.dev)
 			tst_brk(TCONF, "Failed to acquire device");
 
 		tst_device = &tdev;
+
+		if (tst_test->dev_fs_type)
+			tdev.fs_type = tst_test->dev_fs_type;
+		else
+			tdev.fs_type = tst_dev_fs_type();
+
+		if (tst_test->format_device) {
+			SAFE_MKFS(tdev.dev, tdev.fs_type,
+			          tst_test->dev_fs_opts,
+				  tst_test->dev_extra_opt);
+		}
+
+		if (tst_test->mount_device) {
+
+			if (!tst_test->mntpoint) {
+				tst_brk(TBROK,
+					"tst_test->mntpoint must be set!");
+			}
+
+			SAFE_MKDIR(tst_test->mntpoint, 0777);
+			SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
+				   tst_test->mnt_flags, tst_test->mnt_data);
+			device_mounted = 1;
+		}
 	}
 
 	if (tst_test->resource_files)
@@ -678,6 +710,9 @@ static void do_test_setup(void)
 
 static void do_cleanup(void)
 {
+	if (device_mounted)
+		tst_umount(tst_test->mntpoint);
+
 	if (tst_test->needs_device && tdev.dev)
 		tst_release_device(tdev.dev);
 
Signature · 1 line
2.10.2
#1 lore raw

PATCH 1/3 tst_test: Handle device mkfs/mount int the library

Hi!

include/tst_test.h struct tst_test { · line 123

Quoted 1 line
include/tst_test.h +1 -0
+	/* Minimal device size in bytes */

^
This should be megabytes I will fix it in my tree

Quoted 14 lines
include/tst_test.h +14 -0
+	unsigned int dev_min_size;
+
+	/* Device filesystem type override NULL == default */
+	const char *dev_fs_type;
+
+	/* Options passed to SAFE_MKFS() when format_device is set */
+	struct tst_dev_opts *dev_opts;
+	const char *const *dev_fs_opts;
+	const char *dev_extra_opt;
+
+	/* Device mount options, used if mount_device is set */
+	const char *mntpoint;
+	unsigned int mnt_flags;
+	void *mnt_data;
Signature · 2 lines
Cyril Hrubis
[email protected]
#2 lore raw

PATCH 2/3 syscalls: Make use of format_device/mount_device flags

In reply to Cyril Hrubis
---
 testcases/kernel/syscalls/access/access04.c     | 18 +++---------------
 testcases/kernel/syscalls/creat/creat06.c       | 20 +++-----------------
 testcases/kernel/syscalls/quotactl/quotactl01.c | 19 ++++---------------
 testcases/kernel/syscalls/quotactl/quotactl02.c | 20 ++++----------------
 testcases/kernel/syscalls/umount/umount01.c     |  4 +---
 testcases/kernel/syscalls/umount/umount02.c     |  3 +--
 testcases/kernel/syscalls/umount/umount03.c     |  3 +--
 7 files changed, 17 insertions(+), 70 deletions(-)
testcases/kernel/syscalls/access/access04.c +3 -15
index f43c38c..820aab6 100644
@@ -54,7 +54,6 @@
 
 static uid_t uid;
 static char longpathname[PATH_MAX + 2];
-int mount_flag;
 
 static struct tcase {
 	const char *pathname;
@@ -119,18 +118,6 @@ static void setup(void)
 
 	SAFE_SYMLINK(SNAME1, SNAME2);
 	SAFE_SYMLINK(SNAME2, SNAME1);
-
-	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
-	SAFE_MKDIR(MNT_POINT, 0755);
-	SAFE_MOUNT(tst_device->dev, MNT_POINT, tst_device->fs_type,
-		MS_RDONLY, NULL);
-	mount_flag = 1;
-}
-
-static void cleanup(void)
-{
-	if (mount_flag)
-		tst_umount(MNT_POINT);
 }
 
 static struct tst_test test = {
@@ -138,9 +125,10 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.needs_tmpdir = 1,
 	.needs_root = 1,
-	.needs_device = 1,
 	.forks_child = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.mnt_flags = MS_RDONLY,
 	.setup = setup,
-	.cleanup = cleanup,
 	.test = verify_access,
 };
testcases/kernel/syscalls/creat/creat06.c +3 -17
index 73913cd..db0850a 100644
@@ -71,7 +71,6 @@
 #define	MODE2		0666
 
 static void setup(void);
-static void cleanup(void);
 static void test6_setup(void);
 static void test6_cleanup(void);
 #if !defined(UCLINUX)
@@ -80,7 +79,6 @@ static void bad_addr_setup(int);
 
 static struct passwd *ltpuser;
 static char long_name[PATH_MAX+2];
-static int mount_flag;
 
 static struct test_case_t {
 	char *fname;
@@ -140,13 +138,6 @@ static void setup(void)
 
 	SAFE_SYMLINK(TEST7_FILE, "test_file_eloop2");
 	SAFE_SYMLINK("test_file_eloop2", TEST7_FILE);
-
-	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
-
-	SAFE_MKDIR("mntpoint", 0777);
-	SAFE_MOUNT(tst_device->dev, "mntpoint", tst_device->fs_type,
-	           MS_RDONLY, NULL);
-	mount_flag = 1;
 }
 
 #if !defined(UCLINUX)
@@ -170,19 +161,14 @@ static void test6_cleanup(void)
 	SAFE_SETEUID(0);
 }
 
-static void cleanup(void)
-{
-	if (mount_flag)
-		tst_umount("mntpoint");
-}
-
 static struct tst_test test = {
 	.tid = "creat06",
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_creat,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
-	.needs_device = 1,
-	.cleanup = cleanup,
+	.mount_device = 1,
+	.mntpoint = "mntpoint",
+	.mnt_flags = MS_RDONLY,
 	.setup = setup,
 };
testcases/kernel/syscalls/quotactl/quotactl01.c +4 -15
index e6baa2e..a994e95 100644
@@ -78,7 +78,6 @@
 
 # define MNTPOINT	"mntpoint"
 
-static int mount_flag;
 static int32_t fmt_id = FMTID;
 static int test_id;
 static struct dqblk set_dq = {
@@ -163,12 +162,6 @@ static void setup(void)
 	const char *const cmd[] = {"quotacheck", "-ug", MNTPOINT, NULL};
 	int ret;
 
-	SAFE_MKDIR(MNTPOINT, 0755);
-
-	SAFE_MKFS(tst_device->dev, "ext4", NULL, NULL);
-
-	SAFE_MOUNT(tst_device->dev, MNTPOINT, "ext4", 0, "usrquota,grpquota");
-	mount_flag = 1;
 
 	ret = tst_run_cmd(cmd, NULL, NULL, 1);
 	switch (ret) {
@@ -189,12 +182,6 @@ static void setup(void)
 		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
 }
 
-static void cleanup(void)
-{
-	if (mount_flag && tst_umount(MNTPOINT) < 0)
-		tst_res(TWARN | TERRNO, "umount(2) failed");
-}
-
 static void verify_quota(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
@@ -225,9 +212,11 @@ static struct tst_test test = {
 	.needs_root = 1,
 	.test = verify_quota,
 	.tcnt = ARRAY_SIZE(tcases),
-	.needs_device = 1,
+	.mount_device = 1,
+	.dev_fs_type = "ext4",
+	.mntpoint = MNTPOINT,
+	.mnt_data = "usrquota,grpquota",
 	.setup = setup,
-	.cleanup = cleanup
 };
 
 #else
testcases/kernel/syscalls/quotactl/quotactl02.c +4 -16
index d3bd946..f7ae78b 100644
@@ -47,7 +47,6 @@ static void check_qon(char *);
 static void check_qlim(char *);
 
 static int test_id;
-static int mount_flag;
 static struct fs_disk_quota set_dquota = {
 	.d_rtb_softlimit = 1000,
 	.d_fieldmask = FS_DQ_RTBSOFT
@@ -138,22 +137,9 @@ static void check_qlim(char *desp)
 
 static void setup(void)
 {
-	SAFE_MKDIR(mntpoint, 0755);
-
-	SAFE_MKFS(tst_device->dev, "xfs", NULL, NULL);
-
-	SAFE_MOUNT(tst_device->dev, mntpoint, "xfs", 0, "usrquota");
-	mount_flag = 1;
-
 	test_id = geteuid();
 }
 
-static void cleanup(void)
-{
-	if (mount_flag && tst_umount(mntpoint) < 0)
-		tst_res(TWARN | TERRNO, "umount() failed");
-}
-
 static void verify_quota(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
@@ -173,9 +159,11 @@ static struct tst_test test = {
 	.needs_root = 1,
 	.test = verify_quota,
 	.tcnt = ARRAY_SIZE(tcases),
-	.needs_device = 1,
+	.mount_device = 1,
+	.dev_fs_type = "xfs",
+	.mntpoint = mntpoint,
+	.mnt_data = "usrquota",
 	.setup = setup,
-	.cleanup = cleanup
 };
 #else
 	TST_TEST_TCONF("This system didn't support quota or xfs quota");
testcases/kernel/syscalls/umount/umount01.c +1 -3
index a8da4f4..3b5aeb9 100644
@@ -55,8 +55,6 @@ static void verify_umount(void)
 
 static void setup(void)
 {
-	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
-
 	SAFE_MKDIR(MNTPOINT, 0775);
 }
 
@@ -70,7 +68,7 @@ static struct tst_test test = {
 	.tid = "umount01",
 	.needs_root = 1,
 	.needs_tmpdir = 1,
-	.needs_device = 1,
+	.format_device = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_umount,
testcases/kernel/syscalls/umount/umount02.c +1 -2
index ecfad1b..690ba5f 100644
@@ -76,7 +76,6 @@ static void setup(void)
 {
 	memset(long_path, 'a', PATH_MAX + 1);
 
-	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
 	SAFE_MKDIR(MNTPOINT, 0775);
 	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
 	mount_flag = 1;
@@ -98,7 +97,7 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.needs_root = 1,
 	.needs_tmpdir = 1,
-	.needs_device = 1,
+	.format_device = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = verify_umount,
testcases/kernel/syscalls/umount/umount03.c +1 -2
index 4b13240..c1bcb05 100644
@@ -52,7 +52,6 @@ static void setup(void)
 {
 	struct passwd *pw;
 
-	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
 	SAFE_MKDIR(MNTPOINT, 0775);
 	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
 	mount_flag = 1;
@@ -74,7 +73,7 @@ static struct tst_test test = {
 	.tid = "umount03",
 	.needs_root = 1,
 	.needs_tmpdir = 1,
-	.needs_device = 1,
+	.format_device = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_umount,
Signature · 1 line
2.10.2
#3 lore raw

PATCH 3/3 ioctl04: Add BLKROSET/BLKROGET test.

In reply to Cyril Hrubis
---
 runtest/syscalls                          |   1 +
 testcases/kernel/syscalls/.gitignore      |   1 +
 testcases/kernel/syscalls/ioctl/ioctl04.c | 104 ++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+)
 create mode 100644 testcases/kernel/syscalls/ioctl/ioctl04.c
runtest/syscalls +1 -0
index dc03c4c..1ef6161 100644
@@ -452,6 +452,7 @@ getxattr03 getxattr03
 # Introducing ioctl tests for all /dev/tty* devices
 ioctl01_02   test_ioctl
 ioctl03      ioctl03
+ioctl04      ioctl04
 
 inotify_init1_01 inotify_init1_01
 inotify_init1_02 inotify_init1_02
testcases/kernel/syscalls/.gitignore +1 -0
index 91dccef..4c645f6 100644
@@ -384,6 +384,7 @@
 /ioctl/ioctl01
 /ioctl/ioctl02
 /ioctl/ioctl03
+/ioctl/ioctl04
 /ioperm/ioperm01
 /ioperm/ioperm02
 /iopl/iopl01
testcases/kernel/syscalls/ioctl/ioctl04.c new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
2.10.2
#4 lore raw

PATCH 1/3 tst_test: Handle device mkfs/mount int the library

In reply to Cyril Hrubis

----- Original Message -----

Quoted 8 lines

From: "Cyril Hrubis" <[email protected]>
To: [email protected]
Sent: Tuesday, 14 February, 2017 4:26:37 PM
Subject: [LTP] [PATCH 1/3] tst_test: Handle device mkfs/mount int the library

This commit adds functionality to format and then mount the test device to the test library which:

Quoted 8 lines

* Saves a few setup steps in most of the testcases that use test device

* The device is umounted in the test library process now -> it will be umounted even if the test process has segfaulted.

+ docs

Series looks good to me. One issue I ran into is that quotactl01 fails on RHEL5.6/6.0, but that doesn't seem to be related to your patch:

# ./quotactl01 
tst_device.c:120: INFO: Found free device '/dev/loop0'
tst_mkfs.c:79: INFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
mke2fs 1.41.12 (17-May-2010)
tst_test.c:847: INFO: Timeout per run is 0h 05m 00s
quotacheck: Mountpoint (or device) /tmp/quoyk2cuB/mntpoint not found or has no quota enabled.
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.
quotactl01.c:179: FAIL: user quotafile didn't exist: ENOENT

RHEL6.0 man-page says:
ext2
grpquota|noquota|quota|usrquota
These options are accepted but ignored.
ext4
quota, noquota, grpquota, usrquota and [no]bh are backwardly compatible with ext3 or ext2.

Regards,
Jan

#5 lore raw

PATCH 1/3 tst_test: Handle device mkfs/mount int the library

Hi!

Quoted 1 line

Series looks good to me.

Pushed with two more fcntl() tests.

Quoted 4 lines

One issue I ran into is that
quotactl01 fails on RHEL5.6/6.0, but that doesn't seem to be related to your patch:

Quoted 8 lines
# ./quotactl01 
tst_device.c:120: INFO: Found free device '/dev/loop0'
tst_mkfs.c:79: INFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
mke2fs 1.41.12 (17-May-2010)
tst_test.c:847: INFO: Timeout per run is 0h 05m 00s
quotacheck: Mountpoint (or device) /tmp/quoyk2cuB/mntpoint not found or has no quota enabled.
quotacheck: Cannot find filesystem to check or filesystem not mounted with quota option.
quotactl01.c:179: FAIL: user quotafile didn't exist: ENOENT

Strange, that looks like the options are accepted but ignored for ext4 as well.

Signature · 2 lines
Cyril Hrubis
[email protected]