syscalls/mount: Big cleanup.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
diff --git a/testcases/kernel/syscalls/mount/mount01.c b/testcases/kernel/syscalls/mount/mount01.c
index 5dfa750..dbe8af6 100644
--- a/testcases/kernel/syscalls/mount/mount01.c
+++ b/testcases/kernel/syscalls/mount/mount01.c
@@ -13,60 +13,17 @@
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- */
-/**************************************************************************
- *
- * TEST IDENTIFIER : mount01
- *
- * EXECUTED BY : root / superuser
- *
- * TEST TITLE : Basic test for mount(2)
- *
- * TEST CASE TOTAL : 1
- *
* AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
*
- * SIGNALS
- * Uses SIGUSR1 to pause before test if option set.
- * (See the parse_opts(3) man page).
- *
* 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.
*
- * Setup:
- * Setup signal handling.
- * Create a mount point.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed (return=-1)
- * Log the errno and Issue a FAIL message.
- * Otherwise, Issue a PASS message.
- *
- * Cleanup:
- * Delete the mount point.
- * Print errno log and/or timing stats if options given
- *
- * USAGE: <for command-line>
- * mount01 [-T type] -D device [-e] [-i n] [-I x] [-p x] [-t]
- * where, -T type : specifies the type of filesystem to
- * be mounted. Default ext2.
- * -D device : device to be mounted.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -p : Pause for SIGUSR1 before starting
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
* RESTRICTIONS
* test must 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 <sys/mount.h>
@@ -82,20 +39,16 @@
char *TCID = "mount01";
int TST_TOTAL = 1;
-#define DEFAULT_FSTYPE "ext2"
#define DIR_MODE S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP
-static char *Fstype;
-
-static char mntpoint[20];
-static char *fstype;
+static char *mntpoint = "mntpoint";
+static char *fstype = "ext2";
static char *device;
-static int Tflag = 0;
static int Dflag = 0;
-static option_t options[] = { /* options supported by mount01 test */
- {"T:", &Tflag, &fstype}, /* -T type of filesystem */
- {"D:", &Dflag, &device}, /* -D device used for mounting */
+static option_t options[] = {
+ {"T:", NULL, &fstype},
+ {"D:", &Dflag, &device},
{NULL, NULL, NULL}
};
@@ -107,29 +60,11 @@
if ((msg = parse_opts(ac, av, options, &help)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- /* Check for mandatory option of the testcase */
if (!Dflag)
tst_brkm(TBROK, NULL,
"you must specify the device used for mounting with the -D "
"option");
- if (Tflag) {
- Fstype = malloc(strlen(fstype) + 1);
- if (Fstype == NULL) {
- tst_brkm(TBROK | TERRNO, NULL,
- "malloc - failed to alloc %zd",
- strlen(fstype));
- }
- strncpy(Fstype, fstype, strlen(fstype) + 1);
- } else {
- Fstype = malloc(strlen(DEFAULT_FSTYPE) + 1);
- if (Fstype == NULL) {
- tst_brkm(TBROK, NULL, "malloc - failed to alloc %zu",
- strlen(DEFAULT_FSTYPE));
- }
- strncpy(Fstype, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE) + 1);
- }
-
if (STD_COPIES != 1) {
tst_resm(TINFO, "-c option has no effect for this testcase - "
"%s doesn't allow running more than one instance "
@@ -143,10 +78,8 @@
tst_count = 0;
- /* Call mount(2) */
- TEST(mount(device, mntpoint, Fstype, 0, NULL));
+ TEST(mount(device, mntpoint, fstype, 0, NULL));
- /* check return code */
if (TEST_RETURN != 0) {
tst_resm(TFAIL | TTERRNO, "mount(2) failed");
} else {
@@ -159,65 +92,33 @@
}
}
- /* cleanup and exit */
cleanup();
-
tst_exit();
}
-/* setup() - performs all ONE TIME setup for this test */
-void setup()
+static void setup(void)
{
-
tst_sig(NOFORK, DEF_HANDLER, cleanup);
- /* Check whether we are root */
- if (geteuid() != 0) {
- if (Fstype != NULL) {
- free(Fstype);
- Fstype = NULL;
- }
- tst_brkm(TBROK, NULL, "Test must be run as root");
- }
+ tst_require_root(NULL);
- /* make a temp directory */
tst_tmpdir();
- /* Unique mount point */
- (void)sprintf(mntpoint, "mnt_%d", getpid());
-
if (mkdir(mntpoint, DIR_MODE) < 0) {
tst_brkm(TBROK | TERRNO, cleanup, "mkdir(%s, %#o) failed",
mntpoint, DIR_MODE);
}
TEST_PAUSE;
-
}
-/*
- *cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- */
-void cleanup()
+static void cleanup(void)
{
- if (Fstype) {
- free(Fstype);
- Fstype = NULL;
- }
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
TEST_CLEANUP;
-
tst_rmdir();
}
-/*
- * issue a help message
- */
-void help()
+static void help(void)
{
printf("-T type : specifies the type of filesystem to be mounted."
" Default ext2. \n");
diff --git a/testcases/kernel/syscalls/mount/mount02.c b/testcases/kernel/syscalls/mount/mount02.c
index b33d3dd..09b9f9e 100644
--- a/testcases/kernel/syscalls/mount/mount02.c
+++ b/testcases/kernel/syscalls/mount/mount02.c
@@ -56,11 +56,10 @@
static void cleanup(void);
static int setup_test(int, int);
-static int cleanup_test(int);
+static void cleanup_test(int);
char *TCID = "mount02";
-#define DEFAULT_FSTYPE "ext2"
#define FSTYPE_LEN 20
#define DIR_MODE (S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP)
#define FILE_MODE (S_IRWXU | S_IRWXG | S_IRWXO)
@@ -75,10 +74,9 @@
static unsigned long Flag;
static int fd;
-static char mntpoint[PATH_MAX];
-static char *fstype;
+static char *mntpoint = "mntpoint";
+static char *fstype = "ext2";
static char *device;
-static int Tflag;
static int Dflag;
static int exp_enos[] = {
@@ -90,7 +88,7 @@
int TST_TOTAL = (sizeof(exp_enos) / sizeof(exp_enos[0])) - 1;
static option_t options[] = {
- {"T:", &Tflag, &fstype},
+ {"T:", NULL, &fstype},
{"D:", &Dflag, &device},
{NULL, NULL, NULL}
};
@@ -109,18 +107,6 @@
tst_brkm(TBROK, NULL, "You must specifiy the device used for "
" mounting with -D option.");
- Type = malloc(FSTYPE_LEN);
- if (Type == NULL)
- tst_brkm(TBROK | TERRNO, NULL, "malloc failed");
-
- if (Tflag == 1) {
- strncpy(Type, fstype,
- (FSTYPE_LEN <
- strlen(fstype)) ? FSTYPE_LEN : strlen(fstype));
- } else {
- strncpy(Type, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE));
- }
-
if (STD_COPIES != 1) {
tst_resm(TINFO, "-c option has no effect for this testcase - "
"%s doesn't allow running more than one instance "
@@ -162,13 +148,11 @@
"error (%d)", exp_enos[i]);
}
- (void)cleanup_test(i);
-
+ cleanup_test(i);
}
}
cleanup();
-
tst_exit();
}
@@ -188,9 +172,7 @@
switch (i) {
case 0:
/* Setup for mount(2) returning errno ENODEV. */
-
- strncpy(Type, "error", 5);
- Fstype = Type;
+ Fstype = "error";
return 0;
case 1:
/* Setup for mount(2) returning errno ENOTBLK. */
@@ -308,34 +290,25 @@
* cleanup_test() - Setup function for test cases based on the error values
* to be returned.
*/
-static int cleanup_test(int i)
+static void cleanup_test(int i)
{
switch (i) {
case 0:
case 5:
case 7:
- if (Tflag) {
- /* Avoid buffer overflow */
- strncpy(Type, fstype,
- (FSTYPE_LEN < strlen(fstype) + 1) ? FSTYPE_LEN :
- strlen(fstype) + 1);
- } else {
- strcpy(Type, "ext2");
- }
- break;
+ Type = fstype;
+ break;
case 3:
close(fd);
/* FALLTHROUGH */
case 2:
- TEST(umount(mntpoint));
- if (TEST_RETURN != 0)
- tst_resm(TWARN | TTERRNO, "umount failed");
- break;
+ if (umount(mntpoint))
+ tst_resm(TWARN | TERRNO, "umount failed");
+ break;
case 12:
close(fd);
- break;
+ break;
}
- return 0;
}
static void setup(void)
@@ -346,8 +319,6 @@
tst_tmpdir();
- (void)sprintf(mntpoint, "mnt_%d", getpid());
-
if (mkdir(mntpoint, DIR_MODE) == -1)
tst_brkm(TBROK | TERRNO, cleanup, "mkdir(%s, %#o) failed",
mntpoint, DIR_MODE);
@@ -359,16 +330,10 @@
static void cleanup(void)
{
- free(Type);
-
TEST_CLEANUP;
-
tst_rmdir();
}
-/*
- * issue a help message
- */
static void help(void)
{
printf("-T type : specifies the type of filesystem to be mounted."
diff --git a/testcases/kernel/syscalls/mount/mount03.c b/testcases/kernel/syscalls/mount/mount03.c
index d3f0733..05cd996 100644
--- a/testcases/kernel/syscalls/mount/mount03.c
+++ b/testcases/kernel/syscalls/mount/mount03.c
@@ -151,7 +151,6 @@
}
cleanup();
-
tst_exit();
}
@@ -373,7 +372,7 @@
return 0;
}
-void setup(void)
+static void setup(void)
{
char path[PATH_MAX];
@@ -398,14 +397,13 @@
TEST_PAUSE;
}
-void cleanup(void)
+static void cleanup(void)
{
TEST_CLEANUP;
-
tst_rmdir();
}
-void help(void)
+static void help(void)
{
printf("-T type : specifies the type of filesystem to be mounted. "
"Default ext2.\n");
diff --git a/testcases/kernel/syscalls/mount/mount04.c b/testcases/kernel/syscalls/mount/mount04.c
index 8d5c945..943dc49 100644
--- a/testcases/kernel/syscalls/mount/mount04.c
+++ b/testcases/kernel/syscalls/mount/mount04.c
@@ -13,62 +13,15 @@
* with this program; if not, write the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- */
-/******************************************************************************
- *
- * TEST IDENTIFIER : mount04
- *
- * EXECUTED BY : root / superuser
- *
- * TEST TITLE : Test for checking EPERM
- *
- * TEST CASE TOTAL : 1
- *
- * AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
- *
- * SIGNALS
- * Uses SIGUSR1 to pause before test if option set.
- * (See the parse_opts(3) man page).
- *
- * DESCRIPTION
+ * DESCRIPTION
* Verify that mount(2) returns -1 and sets errno to EPERM if the user
* is not the super-user.
*
- * Setup:
- * Setup signal handling.
- * Create a mount point.
- * Pause for SIGUSR1 if option specified.
- *
- * Test:
- * Loop if the proper options are given.
- * Execute system call
- * Check return code, if system call failed and errno == EPERM
- * Issue sys call passed with expected return value and errno.
- * Otherwise,
- * Issue sys call failed to produce expected error.
- * Do cleanup for each test.
- *
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Delete the temporary directory(s)/file(s) created.
- *
- * USAGE: <for command-line>
- * mount04 [-T type] -D device [-e] [-i n] [-I x] [-p x] [-t]
- * where, -T type : specifies the type of filesystem to
- * be mounted. Default ext2.
- * -D device : device to be mounted.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -p : Pause for SIGUSR1 before starting
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
* 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 <sys/mount.h>
@@ -85,15 +38,11 @@
char *TCID = "mount04";
-#define DEFAULT_FSTYPE "ext2"
-#define FSTYPE_LEN 20
#define DIR_MODE S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP
-static char *Type;
-static char mntpoint[PATH_MAX];
-static char *fstype;
+static char *mntpoint = "mntpoint";
+static char *fstype = "ext2";
static char *device;
-static int Tflag = 0;
static int Dflag = 0;
static struct test_case_t {
@@ -109,9 +58,9 @@
static int exp_enos[] = { EPERM, 0 };
-static option_t options[] = { /* options supported by mount04 test */
- {"T:", &Tflag, &fstype}, /* -T type of filesystem */
- {"D:", &Dflag, &device}, /* -D device used for mounting */
+static option_t options[] = {
+ {"T:", NULL, &fstype},
+ {"D:", &Dflag, &device},
{NULL, NULL, NULL}
};
@@ -120,33 +69,15 @@
int lc, i;
char *msg;
- if ((msg = parse_opts(ac, av, options, &help)) != NULL) {
+ if ((msg = parse_opts(ac, av, options, &help)) != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- tst_exit();
- }
- /* Check for mandatory option of the testcase */
if (Dflag == 0) {
tst_brkm(TBROK, NULL, "You must specifiy the device used for "
" mounting with -D option.");
tst_exit();
}
- Type = (char *)malloc(FSTYPE_LEN);
- if (!Type) {
- tst_brkm(TBROK, NULL, "malloc - alloc of %d failed",
- FSTYPE_LEN);
- tst_exit();
- }
-
- if (Tflag == 1) {
- strncpy(Type, fstype,
- (FSTYPE_LEN <
- strlen(fstype)) ? FSTYPE_LEN : strlen(fstype));
- } else {
- strncpy(Type, DEFAULT_FSTYPE, strlen(DEFAULT_FSTYPE));
- }
-
if (STD_COPIES != 1) {
tst_resm(TINFO, "-c option has no effect for this testcase - "
"%s doesn't allow running more than one instance "
@@ -162,7 +93,7 @@
for (i = 0; i < TST_TOTAL; ++i) {
- TEST(mount(device, mntpoint, Type, 0, NULL));
+ TEST(mount(device, mntpoint, fstype, 0, NULL));
/* check return code */
if ((TEST_RETURN == -1) &&
@@ -186,30 +117,22 @@
}
TEST_ERROR_LOG(TEST_ERRNO);
-
}
}
- /* cleanup and exit */
cleanup();
-
tst_exit();
}
-/* setup() - performs all ONE TIME setup for this test */
-void setup()
+static void setup(void)
{
char nobody_uid[] = "nobody";
struct passwd *ltpuser;
tst_sig(FORK, DEF_HANDLER, cleanup);
- /* Check whether we are root */
- if (geteuid() != 0) {
- free(Type);
- tst_brkm(TBROK, NULL, "Test must be run as root");
- }
+ tst_require_root(NULL);
ltpuser = getpwnam(nobody_uid);
if (seteuid(ltpuser->pw_uid) == -1) {
@@ -218,10 +141,8 @@
"errno = %d : %s", ltpuser->pw_uid, TEST_ERRNO,
strerror(TEST_ERRNO));
}
- /* make a temp directory */
- tst_tmpdir();
- (void)sprintf(mntpoint, "mnt_%d", getpid());
+ tst_tmpdir();
if (mkdir(mntpoint, DIR_MODE)) {
tst_brkm(TBROK, cleanup, "mkdir(%s, %#o) failed; "
@@ -231,27 +152,14 @@
TEST_EXP_ENOS(exp_enos);
- /* Setup for mount(2) returning errno EACCES. */
-
TEST_PAUSE;
return;
}
-/*
- *cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- */
-void cleanup()
+static void cleanup(void)
{
- free(Type);
-
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
TEST_CLEANUP;
-
tst_rmdir();
/* Set effective user id back to root */
@@ -264,10 +172,7 @@
return;
}
-/*
- * issue a help message
- */
-void help()
+static void help(void)
{
printf("-T type : specifies the type of filesystem to be mounted."
" Default ext2. \n");