* [LTP] [PATCH 1/2] mkdir/mkdir03.c: cleanup
@ 2014-01-20 9:34 Zeng Linggang
2014-01-20 9:41 ` [LTP] [PATCH 2/2] mkdir/mkdir03.c: add new error number tests Zeng Linggang
0 siblings, 1 reply; 6+ messages in thread
From: Zeng Linggang @ 2014-01-20 9:34 UTC (permalink / raw)
To: ltp-list
Fix FSF address
Make use of SAFE_MACROS()
Some cleanup
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
testcases/kernel/syscalls/mkdir/mkdir03.c | 283 +++++++-----------------------
1 file changed, 65 insertions(+), 218 deletions(-)
diff --git a/testcases/kernel/syscalls/mkdir/mkdir03.c b/testcases/kernel/syscalls/mkdir/mkdir03.c
index 9243299..3aabe1c 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir03.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir03.c
@@ -1,6 +1,6 @@
/*
- *
* Copyright (c) International Business Machines Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
*
* 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
@@ -13,54 +13,13 @@
* 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1303 USA
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
/*
- * NAME
- * mkdir03
- *
* DESCRIPTION
* check mkdir() with various error conditions that should produce
* EFAULT, ENAMETOOLONG, EEXIST, ENOENT and ENOTDIR
- *
- * ALGORITHM
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * Test:
- * Loop if the proper options are given.
- * Loop through the test cases
- * call the test case specific setup routine if necessary
- * call mkdir() using the TEST macro
- * if the call succeeds
- * print a FAIL message and continue
- * Log the errno value
- * if the errno is expected
- * issue a PASS message
- * else
- * issue a FAIL message
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Delete the temporary directory created.
- * USAGE
- * mkdir03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * None.
- *
*/
#include <errno.h>
@@ -70,234 +29,122 @@
#include <fcntl.h>
#include "test.h"
#include "usctest.h"
+#include "safe_macros.h"
-void setup();
-void cleanup();
-void setup1();
-void setup2();
-void setup3();
-void setup4();
-void setup5();
+static void setup(int ac, char **av);
+static void bad_addr_setup(int);
+static void mkdir_verify(int);
+static void cleanup(void);
-#define PERMS 0777
-#define PERMS2 0277
-
-#define NAMELEN 50
+#define TST_EEXIST "tst_eexist"
+#define TST_ENOENT "tst_enoent/tst"
+#define TST_ENOTDIR "tst_enotdir/tst"
+#define MODE 0777
char *TCID = "mkdir03";
-int fileHandle, fileHandle2 = 0;
-
-char tstdir3[NAMELEN];
-char tstdir4[NAMELEN];
-char tstdir5[NAMELEN];
-char long_dir[] =
- "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
+static char long_dir[PATH_MAX+2];
+static int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, 0 };
-int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, 0 };
-
-char *bad_addr = 0;
-
-struct test_case_t {
- char *dir;
- int perms;
- int error;
+static struct test_case_t {
+ char *pathname;
+ int mode;
+ int exp_errno;
void (*setupfunc) ();
} TC[] = {
#if !defined(UCLINUX)
- /* try to create a directory with an illegal name/address */
- {
- (void *)-1, PERMS, EFAULT, NULL},
+ {NULL, MODE, EFAULT, bad_addr_setup},
#endif
- /* try to create a directory using a name that is too long */
- {
- long_dir, PERMS2, ENAMETOOLONG, NULL},
- /* try to create a directory with the same name as an existing file */
- {
- tstdir3, PERMS, EEXIST, setup3},
- /* try to create a directory under a directory that doesn't exist */
- {
- tstdir4, PERMS, ENOENT, setup4},
- /*
- * try to create a directory under a path with a non-directory
- * component
- */
- {
- tstdir5, PERMS, ENOTDIR, setup5}
+ {long_dir, MODE, ENAMETOOLONG, NULL},
+ {TST_EEXIST, MODE, EEXIST, NULL},
+ {TST_ENOENT, MODE, ENOENT, NULL},
+ {TST_ENOTDIR, MODE, ENOTDIR, NULL},
};
-int TST_TOTAL = sizeof(TC) / sizeof(TC[0]);
+int TST_TOTAL = ARRAY_SIZE(TC);
int main(int ac, char **av)
{
int lc;
- char *msg;
int i;
- /*
- * parse standard options
- */
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
- tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- }
-
- /*
- * perform global setup for test
- */
- setup();
-
- /* set the expected errnos... */
- TEST_EXP_ENOS(exp_enos);
+ setup(ac, av);
- /*
- * check looping state if -i option given
- */
for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
- /* loop through the test cases */
- for (i = 0; i < TST_TOTAL; i++) {
-
- /* perform test specific setup if necessary */
- if (TC[i].setupfunc != NULL) {
- (*TC[i].setupfunc) ();
- }
-
- TEST(mkdir(TC[i].dir, TC[i].perms));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded unexpectedly");
- continue;
- }
-
- TEST_ERROR_LOG(TEST_ERRNO);
-
- if (TEST_ERRNO == TC[i].error) {
- tst_resm(TPASS, "expected failure - "
- "errno = %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL, "unexpected error - %d : %s - "
- "expected %d", TEST_ERRNO,
- strerror(TEST_ERRNO), TC[i].error);
- }
- }
+ for (i = 0; i < TST_TOTAL; i++)
+
+ mkdir_verify(i);
}
- /*
- * cleanup and exit
- */
cleanup();
-
tst_exit();
}
-/*
- * setup3() - performs all ONE TIME setup for this test case 3.
- */
-void setup3()
+static void setup(int ac, char **av)
{
- char tstfile3[NAMELEN];
+ char *msg;
+ struct stat statbuf;
- /* Initialize the test directory name and file name */
- sprintf(tstfile3, "tst.%d", getpid());
- sprintf(tstdir3, "%s", tstfile3);
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- /* create a file */
- if ((fileHandle = creat(tstfile3, PERMS)) == -1) {
- tst_brkm(TBROK, cleanup, "file creation failed is setup3");
- }
-}
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
-/*
- * setup4() - performs all ONE TIME setup for this test case 4.
- */
-void setup4()
-{
- char tstdir[NAMELEN];
- struct stat statbuf;
+ TEST_PAUSE;
- /* Initialize the test directory name */
- sprintf(tstdir, "tstdir4.%d", getpid());
- sprintf(tstdir4, "%s/tst", tstdir);
-/*
- sprintf(tstdir4, "%s/tst", tstdir4);
+ tst_tmpdir();
+
+ memset(long_dir, 'a', PATH_MAX+1);
- This fails with EACCES ^^^^^^^
- add this as testcase?
+ SAFE_TOUCH(cleanup, TST_EEXIST, MODE, NULL);
-*/
+ SAFE_TOUCH(cleanup, "tst_enotdir", MODE, NULL);
- /* make sure tstdir4 does not exist */
- if (stat(tstdir4, &statbuf) != -1) {
+ if (stat(TST_ENOENT, &statbuf) != -1)
tst_brkm(TBROK, cleanup, "directory exists - test #4");
- }
+ TEST_EXP_ENOS(exp_enos);
}
-/*
- * setup5() - performs all ONE TIME setup for this test case 5.
- */
-void setup5()
+#if !defined(UCLINUX)
+static void bad_addr_setup(int i)
{
- char tstfile5[NAMELEN];
-
- /* Initialize the test directories name and file name */
- sprintf(tstfile5, "tstfile5.%d", getpid());
- sprintf(tstdir5, "%s/tst", tstfile5);
-
- /* create a file */
- if ((fileHandle2 = creat(tstfile5, PERMS)) == -1) {
- tst_brkm(TBROK, cleanup, "creat a file failed");
- }
+ TC[i].pathname = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
}
+#endif
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup()
+static void mkdir_verify(int i)
{
+ if (TC[i].setupfunc != NULL)
+ TC[i].setupfunc(i);
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ TEST(mkdir(TC[i].pathname, TC[i].mode));
- TEST_PAUSE;
+ if (TEST_RETURN != -1) {
+ tst_resm(TFAIL, "mkdir() returned %ld, expected -1, errno=%d",
+ TEST_RETURN, TC[i].exp_errno);
+ return;
+ }
- /* Create a temporary directory and make it current. */
- tst_tmpdir();
+ TEST_ERROR_LOG(TEST_ERRNO);
-#if !defined(UCLINUX)
- bad_addr = mmap(0, 1, PROT_NONE,
- MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
- if (bad_addr == MAP_FAILED) {
- tst_brkm(TBROK, cleanup, "mmap failed");
+ if (TEST_ERRNO == TC[i].exp_errno) {
+ tst_resm(TPASS | TTERRNO, "mkdir() failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "mkdir() failed unexpectedly; expected: %d - %s",
+ TC[i].exp_errno, strerror(TC[i].exp_errno));
}
- TC[0].dir = bad_addr;
-#endif
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
- close(fileHandle);
- close(fileHandle2);
-
TEST_CLEANUP;
- /*
- * Remove the temporary directory.
- */
tst_rmdir();
-
- /*
- * Exit with return code appropriate for results.
- */
-
}
--
1.8.4.2
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/2] mkdir/mkdir03.c: add new error number tests
2014-01-20 9:34 [LTP] [PATCH 1/2] mkdir/mkdir03.c: cleanup Zeng Linggang
@ 2014-01-20 9:41 ` Zeng Linggang
2014-02-18 15:18 ` [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup Zeng Linggang
0 siblings, 1 reply; 6+ messages in thread
From: Zeng Linggang @ 2014-01-20 9:41 UTC (permalink / raw)
To: ltp-list
Add ELOOP, EROFS error number tests fof mkdir(2)
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
runtest/ltplite | 2 +-
runtest/stress.part3 | 2 +-
runtest/syscalls | 2 +-
testcases/kernel/syscalls/mkdir/mkdir03.c | 58 +++++++++++++++++++++++++++++--
4 files changed, 58 insertions(+), 6 deletions(-)
diff --git a/runtest/ltplite b/runtest/ltplite
index 4b5300d..edc67e8 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -415,7 +415,7 @@ mlockall03 mlockall03
mkdir01 mkdir01
mkdir02 mkdir02
-mkdir03 mkdir03
+mkdir03 mkdir03 -D DEVICE -T DEVICE_FS_TYPE
mkdir04 mkdir04
mkdir05 mkdir05
mkdir05A symlink01 -T mkdir05
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index bb4807c..66ad4c6 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -348,7 +348,7 @@ mlockall03 mlockall03
mkdir01 mkdir01
mkdir02 mkdir02
-mkdir03 mkdir03
+mkdir03 mkdir03 -D DEVICE -T DEVICE_FS_TYPE
mkdir04 mkdir04
mkdir05 mkdir05
mkdir05A symlink01 -T mkdir05
diff --git a/runtest/syscalls b/runtest/syscalls
index afa7976..bebf2b5 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -530,7 +530,7 @@ mlockall03 mlockall03
mkdir01 mkdir01
mkdir02 mkdir02
-mkdir03 mkdir03
+mkdir03 mkdir03 -D DEVICE -T DEVICE_FS_TYPE
mkdir04 mkdir04
mkdir05 mkdir05
mkdir05A symlink01 -T mkdir05
diff --git a/testcases/kernel/syscalls/mkdir/mkdir03.c b/testcases/kernel/syscalls/mkdir/mkdir03.c
index 3aabe1c..b983f79 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir03.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir03.c
@@ -19,7 +19,7 @@
/*
* DESCRIPTION
* check mkdir() with various error conditions that should produce
- * EFAULT, ENAMETOOLONG, EEXIST, ENOENT and ENOTDIR
+ * EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, ELOOP and EROFS
*/
#include <errno.h>
@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
+#include <sys/mount.h>
#include "test.h"
#include "usctest.h"
#include "safe_macros.h"
@@ -35,16 +36,32 @@ static void setup(int ac, char **av);
static void bad_addr_setup(int);
static void mkdir_verify(int);
static void cleanup(void);
+static void help(void);
#define TST_EEXIST "tst_eexist"
#define TST_ENOENT "tst_enoent/tst"
#define TST_ENOTDIR "tst_enotdir/tst"
+#define TST_EROFS "mntpoint/tst_erofs"
#define MODE 0777
+#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
+ S_IXGRP|S_IROTH|S_IXOTH)
char *TCID = "mkdir03";
static char long_dir[PATH_MAX+2];
-static int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, 0 };
+static char loop_dir[PATH_MAX];
+static char *fstype = "ext2";
+static char *device;
+static int dflag;
+static int mount_flag;
+
+static option_t options[] = {
+ {"T:", NULL, &fstype},
+ {"D:", &dflag, &device},
+ {NULL, NULL, NULL}
+};
+static int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR,
+ ELOOP, EROFS, 0 };
static struct test_case_t {
char *pathname;
@@ -59,6 +76,8 @@ static struct test_case_t {
{TST_EEXIST, MODE, EEXIST, NULL},
{TST_ENOENT, MODE, ENOENT, NULL},
{TST_ENOTDIR, MODE, ENOTDIR, NULL},
+ {loop_dir, MODE, ELOOP, NULL},
+ {TST_EROFS, MODE, EROFS, NULL},
};
int TST_TOTAL = ARRAY_SIZE(TC);
@@ -87,11 +106,18 @@ static void setup(int ac, char **av)
{
char *msg;
struct stat statbuf;
+ int i;
- msg = parse_opts(ac, av, NULL, NULL);
+ msg = parse_opts(ac, av, options, help);
if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ if (!dflag) {
+ tst_brkm(TBROK, NULL,
+ "you must specify the device used for mounting with "
+ "-D option");
+ }
+
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_PAUSE;
@@ -107,6 +133,20 @@ static void setup(int ac, char **av)
if (stat(TST_ENOENT, &statbuf) != -1)
tst_brkm(TBROK, cleanup, "directory exists - test #4");
+ SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
+ SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
+ strcpy(loop_dir, ".");
+ for (i = 0; i < 43; i++)
+ strcat(loop_dir, "/test_eloop");
+
+ tst_mkfs(NULL, device, fstype, NULL);
+ SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
+ if (mount(device, "mntpoint", fstype, MS_RDONLY, NULL) < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "mount device:%s failed", device);
+ }
+ mount_flag = 1;
+
TEST_EXP_ENOS(exp_enos);
}
@@ -146,5 +186,17 @@ static void cleanup(void)
{
TEST_CLEANUP;
+ if (mount_flag && umount("mntpoint") < 0) {
+ tst_brkm(TBROK | TERRNO, NULL,
+ "umount device:%s failed", device);
+ }
+
tst_rmdir();
}
+
+static void help(void)
+{
+ printf("-T type : specifies the type of filesystem to be mounted. "
+ "Default ext2.\n");
+ printf("-D device : device used for mounting.\n");
+}
--
1.8.4.2
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup
2014-01-20 9:41 ` [LTP] [PATCH 2/2] mkdir/mkdir03.c: add new error number tests Zeng Linggang
@ 2014-02-18 15:18 ` Zeng Linggang
2014-02-18 15:21 ` [LTP] [PATCH v2 2/2] mkdir/mkdir03.c: add new error number tests Zeng Linggang
2014-02-19 9:34 ` [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup Wanlong Gao
0 siblings, 2 replies; 6+ messages in thread
From: Zeng Linggang @ 2014-02-18 15:18 UTC (permalink / raw)
To: ltp-list
Fix FSF address
Make use of SAFE_MACROS()
Some cleanup
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
testcases/kernel/syscalls/mkdir/mkdir03.c | 283 +++++++-----------------------
1 file changed, 61 insertions(+), 222 deletions(-)
diff --git a/testcases/kernel/syscalls/mkdir/mkdir03.c b/testcases/kernel/syscalls/mkdir/mkdir03.c
index 9243299..f0f444f 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir03.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir03.c
@@ -1,6 +1,6 @@
/*
- *
* Copyright (c) International Business Machines Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
*
* 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
@@ -13,54 +13,13 @@
* 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1303 USA
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
/*
- * NAME
- * mkdir03
- *
* DESCRIPTION
* check mkdir() with various error conditions that should produce
* EFAULT, ENAMETOOLONG, EEXIST, ENOENT and ENOTDIR
- *
- * ALGORITHM
- * Setup:
- * Setup signal handling.
- * Pause for SIGUSR1 if option specified.
- * Create temporary directory.
- *
- * Test:
- * Loop if the proper options are given.
- * Loop through the test cases
- * call the test case specific setup routine if necessary
- * call mkdir() using the TEST macro
- * if the call succeeds
- * print a FAIL message and continue
- * Log the errno value
- * if the errno is expected
- * issue a PASS message
- * else
- * issue a FAIL message
- * Cleanup:
- * Print errno log and/or timing stats if options given
- * Delete the temporary directory created.
- * USAGE
- * mkdir03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -e : Turn on errno logging.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * None.
- *
*/
#include <errno.h>
@@ -70,234 +29,114 @@
#include <fcntl.h>
#include "test.h"
#include "usctest.h"
+#include "safe_macros.h"
-void setup();
-void cleanup();
-void setup1();
-void setup2();
-void setup3();
-void setup4();
-void setup5();
+static void setup(void);
+struct test_case_t;
+static void mkdir_verify(struct test_case_t *tc);
+static void bad_addr_setup(struct test_case_t *tc);
+static void cleanup(void);
-#define PERMS 0777
-#define PERMS2 0277
-
-#define NAMELEN 50
+#define TST_EEXIST "tst_eexist"
+#define TST_ENOENT "tst_enoent/tst"
+#define TST_ENOTDIR "tst_enotdir/tst"
+#define MODE 0777
char *TCID = "mkdir03";
-int fileHandle, fileHandle2 = 0;
-
-char tstdir3[NAMELEN];
-char tstdir4[NAMELEN];
-char tstdir5[NAMELEN];
-char long_dir[] =
- "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
+static char long_dir[PATH_MAX+2];
+static int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, 0 };
-int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, 0 };
-
-char *bad_addr = 0;
-
-struct test_case_t {
- char *dir;
- int perms;
- int error;
- void (*setupfunc) ();
+static struct test_case_t {
+ char *pathname;
+ int mode;
+ int exp_errno;
+ void (*setupfunc) (struct test_case_t *tc);
} TC[] = {
#if !defined(UCLINUX)
- /* try to create a directory with an illegal name/address */
- {
- (void *)-1, PERMS, EFAULT, NULL},
+ {NULL, MODE, EFAULT, bad_addr_setup},
#endif
- /* try to create a directory using a name that is too long */
- {
- long_dir, PERMS2, ENAMETOOLONG, NULL},
- /* try to create a directory with the same name as an existing file */
- {
- tstdir3, PERMS, EEXIST, setup3},
- /* try to create a directory under a directory that doesn't exist */
- {
- tstdir4, PERMS, ENOENT, setup4},
- /*
- * try to create a directory under a path with a non-directory
- * component
- */
- {
- tstdir5, PERMS, ENOTDIR, setup5}
+ {long_dir, MODE, ENAMETOOLONG, NULL},
+ {TST_EEXIST, MODE, EEXIST, NULL},
+ {TST_ENOENT, MODE, ENOENT, NULL},
+ {TST_ENOTDIR, MODE, ENOTDIR, NULL},
};
-int TST_TOTAL = sizeof(TC) / sizeof(TC[0]);
+int TST_TOTAL = ARRAY_SIZE(TC);
int main(int ac, char **av)
{
- int lc;
+ int i, lc;
char *msg;
- int i;
- /*
- * parse standard options
- */
- if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+ msg = parse_opts(ac, av, NULL, NULL);
+ if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
- }
- /*
- * perform global setup for test
- */
setup();
- /* set the expected errnos... */
- TEST_EXP_ENOS(exp_enos);
-
- /*
- * check looping state if -i option given
- */
for (lc = 0; TEST_LOOPING(lc); lc++) {
-
tst_count = 0;
-
- /* loop through the test cases */
- for (i = 0; i < TST_TOTAL; i++) {
-
- /* perform test specific setup if necessary */
- if (TC[i].setupfunc != NULL) {
- (*TC[i].setupfunc) ();
- }
-
- TEST(mkdir(TC[i].dir, TC[i].perms));
-
- if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "call succeeded unexpectedly");
- continue;
- }
-
- TEST_ERROR_LOG(TEST_ERRNO);
-
- if (TEST_ERRNO == TC[i].error) {
- tst_resm(TPASS, "expected failure - "
- "errno = %d : %s", TEST_ERRNO,
- strerror(TEST_ERRNO));
- } else {
- tst_resm(TFAIL, "unexpected error - %d : %s - "
- "expected %d", TEST_ERRNO,
- strerror(TEST_ERRNO), TC[i].error);
- }
- }
+ for (i = 0; i < TST_TOTAL; i++)
+ mkdir_verify(&TC[i]);
}
- /*
- * cleanup and exit
- */
cleanup();
-
tst_exit();
}
-/*
- * setup3() - performs all ONE TIME setup for this test case 3.
- */
-void setup3()
+static void setup(void)
{
- char tstfile3[NAMELEN];
-
- /* Initialize the test directory name and file name */
- sprintf(tstfile3, "tst.%d", getpid());
- sprintf(tstdir3, "%s", tstfile3);
-
- /* create a file */
- if ((fileHandle = creat(tstfile3, PERMS)) == -1) {
- tst_brkm(TBROK, cleanup, "file creation failed is setup3");
- }
-}
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
-/*
- * setup4() - performs all ONE TIME setup for this test case 4.
- */
-void setup4()
-{
- char tstdir[NAMELEN];
- struct stat statbuf;
+ TEST_EXP_ENOS(exp_enos);
- /* Initialize the test directory name */
- sprintf(tstdir, "tstdir4.%d", getpid());
- sprintf(tstdir4, "%s/tst", tstdir);
-/*
- sprintf(tstdir4, "%s/tst", tstdir4);
+ TEST_PAUSE;
- This fails with EACCES ^^^^^^^
- add this as testcase?
+ tst_tmpdir();
-*/
+ memset(long_dir, 'a', PATH_MAX+1);
- /* make sure tstdir4 does not exist */
- if (stat(tstdir4, &statbuf) != -1) {
- tst_brkm(TBROK, cleanup, "directory exists - test #4");
- }
+ SAFE_TOUCH(cleanup, TST_EEXIST, MODE, NULL);
+ SAFE_TOUCH(cleanup, "tst_enotdir", MODE, NULL);
}
-/*
- * setup5() - performs all ONE TIME setup for this test case 5.
- */
-void setup5()
+#if !defined(UCLINUX)
+static void bad_addr_setup(struct test_case_t *tc)
{
- char tstfile5[NAMELEN];
-
- /* Initialize the test directories name and file name */
- sprintf(tstfile5, "tstfile5.%d", getpid());
- sprintf(tstdir5, "%s/tst", tstfile5);
-
- /* create a file */
- if ((fileHandle2 = creat(tstfile5, PERMS)) == -1) {
- tst_brkm(TBROK, cleanup, "creat a file failed");
- }
+ tc->pathname = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
}
+#endif
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup()
+static void mkdir_verify(struct test_case_t *tc)
{
+ if (tc->setupfunc != NULL)
+ tc->setupfunc(tc);
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ TEST(mkdir(tc->pathname, tc->mode));
- TEST_PAUSE;
+ if (TEST_RETURN != -1) {
+ tst_resm(TFAIL, "mkdir() returned %ld, expected -1, errno=%d",
+ TEST_RETURN, tc->exp_errno);
+ return;
+ }
- /* Create a temporary directory and make it current. */
- tst_tmpdir();
+ TEST_ERROR_LOG(TEST_ERRNO);
-#if !defined(UCLINUX)
- bad_addr = mmap(0, 1, PROT_NONE,
- MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
- if (bad_addr == MAP_FAILED) {
- tst_brkm(TBROK, cleanup, "mmap failed");
+ if (TEST_ERRNO == tc->exp_errno) {
+ tst_resm(TPASS | TTERRNO, "mkdir() failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "mkdir() failed unexpectedly; expected: %d - %s",
+ tc->exp_errno, strerror(tc->exp_errno));
}
- TC[0].dir = bad_addr;
-#endif
}
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- * completion or premature exit.
- */
-void cleanup()
+static void cleanup(void)
{
- /*
- * print timing stats if that option was specified.
- * print errno log if that option was specified.
- */
- close(fileHandle);
- close(fileHandle2);
-
TEST_CLEANUP;
- /*
- * Remove the temporary directory.
- */
tst_rmdir();
-
- /*
- * Exit with return code appropriate for results.
- */
-
}
--
1.8.4.2
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2 2/2] mkdir/mkdir03.c: add new error number tests
2014-02-18 15:18 ` [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup Zeng Linggang
@ 2014-02-18 15:21 ` Zeng Linggang
2014-02-19 9:34 ` Wanlong Gao
2014-02-19 9:34 ` [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup Wanlong Gao
1 sibling, 1 reply; 6+ messages in thread
From: Zeng Linggang @ 2014-02-18 15:21 UTC (permalink / raw)
To: ltp-list
Add ELOOP, EROFS error number tests fof mkdir(2)
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
testcases/kernel/syscalls/mkdir/mkdir03.c | 61 +++++++++++++++++++++++++++++--
1 file changed, 58 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/syscalls/mkdir/mkdir03.c b/testcases/kernel/syscalls/mkdir/mkdir03.c
index f0f444f..8058fcf 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir03.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir03.c
@@ -19,7 +19,7 @@
/*
* DESCRIPTION
* check mkdir() with various error conditions that should produce
- * EFAULT, ENAMETOOLONG, EEXIST, ENOENT and ENOTDIR
+ * EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, ELOOP and EROFS
*/
#include <errno.h>
@@ -27,6 +27,8 @@
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
+#include <sys/mount.h>
+
#include "test.h"
#include "usctest.h"
#include "safe_macros.h"
@@ -36,16 +38,34 @@ struct test_case_t;
static void mkdir_verify(struct test_case_t *tc);
static void bad_addr_setup(struct test_case_t *tc);
static void cleanup(void);
+static void help(void);
#define TST_EEXIST "tst_eexist"
#define TST_ENOENT "tst_enoent/tst"
#define TST_ENOTDIR "tst_enotdir/tst"
#define MODE 0777
+#define MNT_POINT "mntpoint"
+#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
+ S_IXGRP|S_IROTH|S_IXOTH)
+#define TST_EROFS "mntpoint/tst_erofs"
+
char *TCID = "mkdir03";
static char long_dir[PATH_MAX+2];
-static int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT, ENOTDIR, 0 };
+static char loop_dir[PATH_MAX] = ".";
+static char *fstype = "ext2";
+static char *device;
+static int mount_flag;
+
+static option_t options[] = {
+ {"T:", NULL, &fstype},
+ {"D:", NULL, &device},
+ {NULL, NULL, NULL}
+};
+
+static int exp_enos[] = { EFAULT, ENAMETOOLONG, EEXIST, ENOENT,
+ ENOTDIR, ELOOP, EROFS, 0 };
static struct test_case_t {
char *pathname;
@@ -60,6 +80,8 @@ static struct test_case_t {
{TST_EEXIST, MODE, EEXIST, NULL},
{TST_ENOENT, MODE, ENOENT, NULL},
{TST_ENOTDIR, MODE, ENOTDIR, NULL},
+ {loop_dir, MODE, ELOOP, NULL},
+ {TST_EROFS, MODE, EROFS, NULL},
};
int TST_TOTAL = ARRAY_SIZE(TC);
@@ -69,10 +91,16 @@ int main(int ac, char **av)
int i, lc;
char *msg;
- msg = parse_opts(ac, av, NULL, NULL);
+ msg = parse_opts(ac, av, options, help);
if (msg != NULL)
tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+ if (!device) {
+ tst_brkm(TBROK, NULL,
+ "you must specify the device used for mounting with "
+ "-D option");
+ }
+
setup();
for (lc = 0; TEST_LOOPING(lc); lc++) {
@@ -87,6 +115,10 @@ int main(int ac, char **av)
static void setup(void)
{
+ int i;
+
+ tst_require_root(NULL);
+
tst_sig(NOFORK, DEF_HANDLER, cleanup);
TEST_EXP_ENOS(exp_enos);
@@ -100,6 +132,19 @@ static void setup(void)
SAFE_TOUCH(cleanup, TST_EEXIST, MODE, NULL);
SAFE_TOUCH(cleanup, "tst_enotdir", MODE, NULL);
+
+ SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE);
+ SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop");
+ for (i = 0; i < 43; i++)
+ strcat(loop_dir, "/test_eloop");
+
+ tst_mkfs(NULL, device, fstype, NULL);
+ SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE);
+ if (mount(device, MNT_POINT, fstype, MS_RDONLY, NULL) < 0) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "mount device:%s failed", device);
+ }
+ mount_flag = 1;
}
#if !defined(UCLINUX)
@@ -138,5 +183,15 @@ static void cleanup(void)
{
TEST_CLEANUP;
+ if (mount_flag && umount(MNT_POINT) < 0)
+ tst_resm(TWARN | TERRNO, "umount device:%s failed", device);
+
tst_rmdir();
}
+
+static void help(void)
+{
+ printf("-T type : specifies the type of filesystem to be mounted. "
+ "Default ext2.\n");
+ printf("-D device : device used for mounting.\n");
+}
--
1.8.4.2
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup
2014-02-18 15:18 ` [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup Zeng Linggang
2014-02-18 15:21 ` [LTP] [PATCH v2 2/2] mkdir/mkdir03.c: add new error number tests Zeng Linggang
@ 2014-02-19 9:34 ` Wanlong Gao
1 sibling, 0 replies; 6+ messages in thread
From: Wanlong Gao @ 2014-02-19 9:34 UTC (permalink / raw)
To: Zeng Linggang; +Cc: ltp-list
On 02/18/2014 11:18 PM, Zeng Linggang wrote:
> Fix FSF address
> Make use of SAFE_MACROS()
> Some cleanup
>
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> ---
> testcases/kernel/syscalls/mkdir/mkdir03.c | 283 +++++++-----------------------
> 1 file changed, 61 insertions(+), 222 deletions(-)
Applied, thank you.
Wanlong Gao
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [LTP] [PATCH v2 2/2] mkdir/mkdir03.c: add new error number tests
2014-02-18 15:21 ` [LTP] [PATCH v2 2/2] mkdir/mkdir03.c: add new error number tests Zeng Linggang
@ 2014-02-19 9:34 ` Wanlong Gao
0 siblings, 0 replies; 6+ messages in thread
From: Wanlong Gao @ 2014-02-19 9:34 UTC (permalink / raw)
To: Zeng Linggang; +Cc: ltp-list
On 02/18/2014 11:21 PM, Zeng Linggang wrote:
> Add ELOOP, EROFS error number tests fof mkdir(2)
>
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> ---
> testcases/kernel/syscalls/mkdir/mkdir03.c | 61 +++++++++++++++++++++++++++++--
> 1 file changed, 58 insertions(+), 3 deletions(-)
Applied, thank you.
Wanlong Gao
------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-02-19 9:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-20 9:34 [LTP] [PATCH 1/2] mkdir/mkdir03.c: cleanup Zeng Linggang
2014-01-20 9:41 ` [LTP] [PATCH 2/2] mkdir/mkdir03.c: add new error number tests Zeng Linggang
2014-02-18 15:18 ` [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup Zeng Linggang
2014-02-18 15:21 ` [LTP] [PATCH v2 2/2] mkdir/mkdir03.c: add new error number tests Zeng Linggang
2014-02-19 9:34 ` Wanlong Gao
2014-02-19 9:34 ` [LTP] [PATCH v2 1/2] mkdir/mkdir03.c: cleanup Wanlong Gao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.