public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] syscalls/umount01: Cleanup && Convert to new API
@ 2016-11-03 10:55 Guangwen Feng
  2016-11-03 10:55 ` [LTP] [PATCH 2/3] syscalls/umount02: " Guangwen Feng
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Guangwen Feng @ 2016-11-03 10:55 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/umount/umount01.c | 104 +++++++++-------------------
 1 file changed, 34 insertions(+), 70 deletions(-)

diff --git a/testcases/kernel/syscalls/umount/umount01.c b/testcases/kernel/syscalls/umount/umount01.c
index 4597651..a8da4f4 100644
--- a/testcases/kernel/syscalls/umount/umount01.c
+++ b/testcases/kernel/syscalls/umount/umount01.c
@@ -22,92 +22,56 @@
 
 #include <errno.h>
 #include <sys/mount.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "test.h"
+#include "tst_test.h"
 
-static void setup(void);
-static void cleanup(void);
+#define MNTPOINT	"mntpoint"
 
-char *TCID = "umount01";
-int TST_TOTAL = 1;
+static int mount_flag;
 
-#define DEFAULT_FSTYPE	"ext2"
-#define DIR_MODE	S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH
-
-static const char *mntpoint = "mntpoint";
-static const char *fs_type;
-static const char *device;
-
-int main(int ac, char **av)
+static void verify_umount(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 (mount_flag != 1) {
+		SAFE_MOUNT(tst_device->dev, MNTPOINT,
+			tst_device->fs_type, 0, NULL);
+		mount_flag = 1;
+	}
 
-		if (TEST_RETURN != 0) {
-			tst_brkm(TBROK, cleanup, "mount(2) Failed errno = %d :"
-				 "%s ", TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			TEST(umount(mntpoint));
+	TEST(umount(MNTPOINT));
 
-			if (TEST_RETURN != 0 && TEST_ERRNO == EBUSY) {
-				tst_resm(TINFO, "umount() failed with EBUSY "
-				         "possibly some daemon (gvfsd-trash) "
-				         "is probing newly mounted dirs");
-			}
+	if (TEST_RETURN != 0 && TEST_ERRNO == EBUSY) {
+		tst_res(TINFO, "umount() Failed with EBUSY "
+			"possibly some daemon (gvfsd-trash) "
+			"is probing newly mounted dirs");
+	}
 
-			if (TEST_RETURN != 0) {
-				tst_brkm(TFAIL, NULL, "umount(2) Failed while "
-					 " unmounting %s errno = %d : %s",
-					 mntpoint, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TPASS, "umount(2) Passed ");
-			}
-		}
+	if (TEST_RETURN != 0) {
+		tst_res(TFAIL | TTERRNO, "umount() Failed");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "umount() Passed");
+	mount_flag = 0;
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
 
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	if (mkdir(mntpoint, DIR_MODE) < 0) {
-		tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) failed; "
-			 "errno = %d: %s", mntpoint, DIR_MODE, errno,
-			 strerror(errno));
-	}
-
-	TEST_PAUSE;
+	SAFE_MKDIR(MNTPOINT, 0775);
 }
 
 static void cleanup(void)
 {
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)
+		tst_umount(MNTPOINT);
 }
+
+static struct tst_test test = {
+	.tid = "umount01",
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.needs_device = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_umount,
+};
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 2/3] syscalls/umount02: Cleanup && Convert to new API
  2016-11-03 10:55 [LTP] [PATCH 1/3] syscalls/umount01: Cleanup && Convert to new API Guangwen Feng
@ 2016-11-03 10:55 ` Guangwen Feng
  2016-11-08  9:58   ` Cyril Hrubis
  2016-11-03 10:55 ` [LTP] [PATCH 3/3] syscalls/umount03: " Guangwen Feng
  2016-11-08  9:58 ` [LTP] [PATCH 1/3] syscalls/umount01: " Cyril Hrubis
  2 siblings, 1 reply; 6+ messages in thread
From: Guangwen Feng @ 2016-11-03 10:55 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/umount/umount02.c | 128 ++++++++++------------------
 1 file changed, 43 insertions(+), 85 deletions(-)

diff --git a/testcases/kernel/syscalls/umount/umount02.c b/testcases/kernel/syscalls/umount/umount02.c
index 7d469fd..7ff125a 100644
--- a/testcases/kernel/syscalls/umount/umount02.c
+++ b/testcases/kernel/syscalls/umount/umount02.c
@@ -29,119 +29,77 @@
  *****************************************************************************/
 
 #include <errno.h>
+#include <string.h>
 #include <sys/mount.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/fcntl.h>
-#include <pwd.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "umount02";
-
-#define DIR_MODE	S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH
-#define FILE_MODE	S_IRWXU | S_IRWXG | S_IRWXO
-#define MNTPOINT        "mntpoint"
+#define MNTPOINT	"mntpoint"
 
 static char long_path[PATH_MAX + 2];
 static int mount_flag;
 static int fd;
 
-static const char *device;
-
-static struct test_case_t {
-	char *err_desc;
-	char *mntpoint;
+static struct tcase {
+	const char *err_desc;
+	const char *mntpoint;
 	int exp_errno;
-	char *exp_retval;
-} testcases[] = {
-	{"Already mounted/busy", MNTPOINT, EBUSY, "EBUSY"},
-	{"Invalid address space", NULL, EFAULT, "EFAULT"},
-	{"Directory not found", "nonexistent", ENOENT, "ENOENT"},
-	{"Invalid  device", "./", EINVAL, "EINVAL"},
-	{"Pathname too long", long_path, ENAMETOOLONG, "ENAMETOOLONG"}
+} tcases[] = {
+	{"Already mounted/busy", MNTPOINT, EBUSY},
+	{"Invalid address space", NULL, EFAULT},
+	{"Directory not found", "nonexistent", ENOENT},
+	{"Invalid  device", "./", EINVAL},
+	{"Pathname too long", long_path, ENAMETOOLONG}
 };
 
-int TST_TOTAL = ARRAY_SIZE(testcases);
-
-int main(int ac, char **av)
+static void verify_umount(unsigned int n)
 {
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
+	struct tcase *tc = &tcases[n];
 
-	setup();
+	TEST(umount(tc->mntpoint));
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-			TEST(umount(testcases[i].mntpoint));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "umount() succeeds unexpectedly");
+		return;
+	}
 
-			if ((TEST_RETURN == -1) &&
-			    (TEST_ERRNO == testcases[i].exp_errno)) {
-				tst_resm(TPASS, "umount(2) expected failure; "
-					 "Got errno - %s : %s",
-					 testcases[i].exp_retval,
-					 testcases[i].err_desc);
-			} else {
-				tst_resm(TFAIL, "umount(2) failed to produce "
-					 "expected error; %d, errno:%s got %d",
-					 testcases[i].exp_errno,
-					 testcases[i].exp_retval, TEST_ERRNO);
-			}
-		}
+	if (tc->exp_errno != TEST_ERRNO) {
+		tst_res(TFAIL | TTERRNO, "umount() should fail with %s",
+			tst_strerrno(tc->exp_errno));
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS | TTERRNO, "umount() fails as expected: %s",
+		tc->err_desc);
 }
 
 static void setup(void)
 {
-	const char *fs_type;
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
 	memset(long_path, 'a', PATH_MAX + 1);
 
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	if (mount(device, MNTPOINT, fs_type, 0, NULL))
-		tst_brkm(TBROK | TERRNO, cleanup, "mount() failed");
+	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;
 
-	fd = SAFE_OPEN(cleanup, MNTPOINT "/file", O_CREAT | O_RDWR);
-
-	TEST_PAUSE;
+	fd = SAFE_CREAT(MNTPOINT "/file", 0777);
 }
 
 static void cleanup(void)
 {
 	if (fd > 0 && close(fd))
-		tst_resm(TWARN | TERRNO, "Failed to close file");
-
-	if (mount_flag && tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "umount() failed");
-
-	if (device)
-		tst_release_device(device);
+		tst_res(TWARN | TERRNO, "Failed to close file");
 
-	tst_rmdir();
+	if (mount_flag)
+		tst_umount(MNTPOINT);
 }
+
+static struct tst_test test = {
+	.tid = "umount02",
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.needs_device = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_umount,
+};
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 3/3] syscalls/umount03: Cleanup && Convert to new API
  2016-11-03 10:55 [LTP] [PATCH 1/3] syscalls/umount01: Cleanup && Convert to new API Guangwen Feng
  2016-11-03 10:55 ` [LTP] [PATCH 2/3] syscalls/umount02: " Guangwen Feng
@ 2016-11-03 10:55 ` Guangwen Feng
  2016-11-08  9:59   ` Cyril Hrubis
  2016-11-08  9:58 ` [LTP] [PATCH 1/3] syscalls/umount01: " Cyril Hrubis
  2 siblings, 1 reply; 6+ messages in thread
From: Guangwen Feng @ 2016-11-03 10:55 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/umount/umount03.c | 105 +++++++++-------------------
 1 file changed, 32 insertions(+), 73 deletions(-)

diff --git a/testcases/kernel/syscalls/umount/umount03.c b/testcases/kernel/syscalls/umount/umount03.c
index 322005e..1ade141 100644
--- a/testcases/kernel/syscalls/umount/umount03.c
+++ b/testcases/kernel/syscalls/umount/umount03.c
@@ -20,107 +20,66 @@
  *	is not the super-user.
  *
  * RESTRICTIONS
- *	test must be run with the -D option
  *	test doesn't support -c option to run it in parallel, as mount
  *	syscall is not supposed to run in parallel.
  */
 
 #include <errno.h>
+#include <pwd.h>
 #include <sys/mount.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/fcntl.h>
-#include <sys/wait.h>
-#include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include <unistd.h>
+#include "tst_test.h"
 
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "umount03";
-
-#define FSTYPE_LEN	20
-#define DIR_MODE	S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH
 #define MNTPOINT	"mntpoint"
 
-static const char *device;
 static int mount_flag;
 
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_umount(void)
 {
-	int lc;
+	TEST(umount(MNTPOINT));
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(umount(MNTPOINT));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "umout() didn't fail (ret=%ld)",
-				 TEST_RETURN);
-			continue;
-		}
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "umount() succeeds unexpectedly");
+		return;
+	}
 
-		if (TEST_ERRNO == EPERM) {
-			tst_resm(TPASS | TTERRNO, "umount() failed with EPERM");
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-			         "umount() did not fail with EPERM(%d)", EPERM);
-		}
+	if (EPERM != TEST_ERRNO) {
+		tst_res(TFAIL | TTERRNO, "umount() should fail with EPERM");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS | TTERRNO, "umount() fails as expected");
 }
 
 static void setup(void)
 {
-	const char *fs_type;
-	struct passwd *ltpuser;
+	struct passwd *pw;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	ltpuser = SAFE_GETPWNAM(NULL, "nobody");
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	if (mount(device, MNTPOINT, fs_type, 0, NULL))
-		tst_brkm(TBROK | TERRNO, cleanup, "mount() failed");
+	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;
 
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-	TEST_PAUSE;
+	pw = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(pw->pw_uid);
 }
 
 static void cleanup(void)
 {
 	if (seteuid(0))
-		tst_resm(TWARN | TERRNO, "seteuid(0) failed");
-
-	if (mount_flag && tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "umount() failed");
+		tst_res(TWARN | TERRNO, "seteuid(0) Failed");
 
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)
+		tst_umount(MNTPOINT);
 }
+
+static struct tst_test test = {
+	.tid = "umount03",
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.needs_device = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_umount,
+};
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 1/3] syscalls/umount01: Cleanup && Convert to new API
  2016-11-03 10:55 [LTP] [PATCH 1/3] syscalls/umount01: Cleanup && Convert to new API Guangwen Feng
  2016-11-03 10:55 ` [LTP] [PATCH 2/3] syscalls/umount02: " Guangwen Feng
  2016-11-03 10:55 ` [LTP] [PATCH 3/3] syscalls/umount03: " Guangwen Feng
@ 2016-11-08  9:58 ` Cyril Hrubis
  2 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2016-11-08  9:58 UTC (permalink / raw)
  To: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 2/3] syscalls/umount02: Cleanup && Convert to new API
  2016-11-03 10:55 ` [LTP] [PATCH 2/3] syscalls/umount02: " Guangwen Feng
@ 2016-11-08  9:58   ` Cyril Hrubis
  0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2016-11-08  9:58 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor typo fix, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 3/3] syscalls/umount03: Cleanup && Convert to new API
  2016-11-03 10:55 ` [LTP] [PATCH 3/3] syscalls/umount03: " Guangwen Feng
@ 2016-11-08  9:59   ` Cyril Hrubis
  0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2016-11-08  9:59 UTC (permalink / raw)
  To: ltp

Hi!
> ---
>  testcases/kernel/syscalls/umount/umount03.c | 105 +++++++++-------------------
>  1 file changed, 32 insertions(+), 73 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/umount/umount03.c b/testcases/kernel/syscalls/umount/umount03.c
> index 322005e..1ade141 100644
> --- a/testcases/kernel/syscalls/umount/umount03.c
> +++ b/testcases/kernel/syscalls/umount/umount03.c
> @@ -20,107 +20,66 @@
>   *	is not the super-user.
>   *
>   * RESTRICTIONS
> - *	test must be run with the -D option
>   *	test doesn't support -c option to run it in parallel, as mount
>   *	syscall is not supposed to run in parallel.
>   */

I've removed the whole RESTRICTIONS part of the comment since the -c
option has been removed long time ago anyway.

Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-11-08  9:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-03 10:55 [LTP] [PATCH 1/3] syscalls/umount01: Cleanup && Convert to new API Guangwen Feng
2016-11-03 10:55 ` [LTP] [PATCH 2/3] syscalls/umount02: " Guangwen Feng
2016-11-08  9:58   ` Cyril Hrubis
2016-11-03 10:55 ` [LTP] [PATCH 3/3] syscalls/umount03: " Guangwen Feng
2016-11-08  9:59   ` Cyril Hrubis
2016-11-08  9:58 ` [LTP] [PATCH 1/3] syscalls/umount01: " Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox