* [LTP] [PATCH 2/3] syscalls: Make use of format_device/mount_device flags
2017-02-14 15:26 [LTP] [PATCH 1/3] tst_test: Handle device mkfs/mount int the library Cyril Hrubis
@ 2017-02-14 15:26 ` Cyril Hrubis
2017-02-14 15:26 ` [LTP] [PATCH 3/3] ioctl04: Add BLKROSET/BLKROGET test Cyril Hrubis
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2017-02-14 15:26 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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(-)
diff --git a/testcases/kernel/syscalls/access/access04.c b/testcases/kernel/syscalls/access/access04.c
index f43c38c..820aab6 100644
--- a/testcases/kernel/syscalls/access/access04.c
+++ b/testcases/kernel/syscalls/access/access04.c
@@ -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,
};
diff --git a/testcases/kernel/syscalls/creat/creat06.c b/testcases/kernel/syscalls/creat/creat06.c
index 73913cd..db0850a 100644
--- a/testcases/kernel/syscalls/creat/creat06.c
+++ b/testcases/kernel/syscalls/creat/creat06.c
@@ -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,
};
diff --git a/testcases/kernel/syscalls/quotactl/quotactl01.c b/testcases/kernel/syscalls/quotactl/quotactl01.c
index e6baa2e..a994e95 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl01.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl01.c
@@ -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
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c
index d3bd946..f7ae78b 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.c
@@ -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");
diff --git a/testcases/kernel/syscalls/umount/umount01.c b/testcases/kernel/syscalls/umount/umount01.c
index a8da4f4..3b5aeb9 100644
--- a/testcases/kernel/syscalls/umount/umount01.c
+++ b/testcases/kernel/syscalls/umount/umount01.c
@@ -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,
diff --git a/testcases/kernel/syscalls/umount/umount02.c b/testcases/kernel/syscalls/umount/umount02.c
index ecfad1b..690ba5f 100644
--- a/testcases/kernel/syscalls/umount/umount02.c
+++ b/testcases/kernel/syscalls/umount/umount02.c
@@ -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,
diff --git a/testcases/kernel/syscalls/umount/umount03.c b/testcases/kernel/syscalls/umount/umount03.c
index 4b13240..c1bcb05 100644
--- a/testcases/kernel/syscalls/umount/umount03.c
+++ b/testcases/kernel/syscalls/umount/umount03.c
@@ -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,
--
2.10.2
^ permalink raw reply related [flat|nested] 6+ messages in thread* [LTP] [PATCH 3/3] ioctl04: Add BLKROSET/BLKROGET test.
2017-02-14 15:26 [LTP] [PATCH 1/3] tst_test: Handle device mkfs/mount int the library Cyril Hrubis
2017-02-14 15:26 ` [LTP] [PATCH 2/3] syscalls: Make use of format_device/mount_device flags Cyril Hrubis
@ 2017-02-14 15:26 ` Cyril Hrubis
2017-02-14 15:28 ` [LTP] [PATCH 1/3] tst_test: Handle device mkfs/mount int the library Cyril Hrubis
2017-02-21 11:27 ` Jan Stancek
3 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2017-02-14 15:26 UTC (permalink / raw)
To: ltp
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
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
diff --git a/runtest/syscalls b/runtest/syscalls
index dc03c4c..1ef6161 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -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
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 91dccef..4c645f6 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -384,6 +384,7 @@
/ioctl/ioctl01
/ioctl/ioctl02
/ioctl/ioctl03
+/ioctl/ioctl04
/ioperm/ioperm01
/ioperm/ioperm02
/iopl/iopl01
diff --git a/testcases/kernel/syscalls/ioctl/ioctl04.c b/testcases/kernel/syscalls/ioctl/ioctl04.c
new file mode 100644
index 0000000..d3de368
--- /dev/null
+++ b/testcases/kernel/syscalls/ioctl/ioctl04.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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/>.
+ */
+/*
+ * Basic test for the BLKROSET and BLKROGET ioctls.
+ *
+ * - Set the device read only, read the value back.
+ * - Try to mount the device read write, expect failure.
+ * - Try to mount the device read only, expect success.
+ */
+
+#include <errno.h>
+#include <sys/mount.h>
+#include <linux/fs.h>
+#include "tst_test.h"
+
+static int fd;
+
+static void verify_ioctl(void)
+{
+ int ro = 1;
+
+ SAFE_IOCTL(fd, BLKROGET, &ro);
+
+ if (ro == 0)
+ tst_res(TPASS, "BLKROGET returned 0");
+ else
+ tst_res(TFAIL, "BLKROGET returned %i", ro);
+
+ ro = 1;
+ SAFE_IOCTL(fd, BLKROSET, &ro);
+
+ ro = 0;
+ SAFE_IOCTL(fd, BLKROGET, &ro);
+
+ if (ro == 0)
+ tst_res(TFAIL, "BLKROGET returned 0");
+ else
+ tst_res(TPASS, "BLKROGET returned %i", ro);
+
+ TEST(mount(tst_device->dev, "mntpoint", tst_device->fs_type, 0, NULL));
+
+ if (TEST_RETURN != -1) {
+ tst_res(TFAIL, "Mounting RO device RW succeeded");
+ tst_umount("mntpoint");
+ goto next;
+ }
+
+ if (TEST_ERRNO == EACCES) {
+ tst_res(TPASS | TERRNO, "Mounting RO device RW failed");
+ goto next;
+ }
+
+ tst_res(TFAIL | TERRNO,
+ "Mounting RO device RW failed unexpectedly expected EACCES");
+
+next:
+ TEST(mount(tst_device->dev, "mntpoint", tst_device->fs_type, MS_RDONLY, NULL));
+
+ if (TEST_RETURN == 0) {
+ tst_res(TPASS, "Mounting RO device RO works");
+ tst_umount("mntpoint");
+ } else {
+ tst_res(TFAIL | TTERRNO, "Mounting RO device RO failed");
+ }
+
+ ro = 0;
+ SAFE_IOCTL(fd, BLKROSET, &ro);
+}
+
+static void setup(void)
+{
+ SAFE_MKDIR("mntpoint", 0777);
+ fd = SAFE_OPEN(tst_device->dev, O_RDONLY);
+}
+
+static void cleanup(void)
+{
+ if (fd > 0)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .tid = "ioctl04",
+ .needs_tmpdir = 1,
+ .needs_device = 1,
+ .format_device = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = verify_ioctl,
+};
--
2.10.2
^ permalink raw reply related [flat|nested] 6+ messages in thread