* [LTP] [PATCH] readdir/readdir03.c: add new error number testes
@ 2014-04-01 11:12 Zeng Linggang
2014-05-05 16:32 ` chrubis
0 siblings, 1 reply; 5+ messages in thread
From: Zeng Linggang @ 2014-04-01 11:12 UTC (permalink / raw)
To: ltp-list
Add ENOENT and ENOTDIR error number testes for readdir(2)
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
runtest/ltplite | 1 +
runtest/stress.part3 | 1 +
runtest/syscalls | 1 +
testcases/kernel/syscalls/.gitignore | 1 +
testcases/kernel/syscalls/readdir/readdir03.c | 151 ++++++++++++++++++++++++++
5 files changed, 155 insertions(+)
create mode 100644 testcases/kernel/syscalls/readdir/readdir03.c
diff --git a/runtest/ltplite b/runtest/ltplite
index ebe171e..bfa32bb 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -610,6 +610,7 @@ read04 read04
readdir01 readdir01
readdir02 readdir02
+readdir03 readdir03
readlink01A symlink01 -T readlink01
readlink01 readlink01
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index b21e44b..a052240 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -520,6 +520,7 @@ read04 read04
readdir01 readdir01
readdir02 readdir02
+readdir03 readdir03
readlink01A symlink01 -T readlink01
readlink01 readlink01
diff --git a/runtest/syscalls b/runtest/syscalls
index fb3e59f..a398083 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -808,6 +808,7 @@ readahead02 readahead02
readdir01 readdir01
readdir02 readdir02
+readdir03 readdir03
readlink01A symlink01 -T readlink01
readlink01 readlink01
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d5c7bac..b73ac7f 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -662,6 +662,7 @@
/readahead/readahead02
/readdir/readdir01
/readdir/readdir02
+/readdir/readdir03
/readlink/creat_slink
/readlink/readlink01
/readlink/readlink02
diff --git a/testcases/kernel/syscalls/readdir/readdir03.c b/testcases/kernel/syscalls/readdir/readdir03.c
new file mode 100644
index 0000000..ab6cd54
--- /dev/null
+++ b/testcases/kernel/syscalls/readdir/readdir03.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ *
+ * 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 Library 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-1307, USA.
+ *
+ */
+/*
+ * Test Description:
+ * Verify that,
+ * 1. Creat a directory and open it, then delete the directory, ENOENT would
+ * return.
+ * 2. File descriptor does not refer to a directory, ENOTDIR would return.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <limits.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+
+char *TCID = "readdir03";
+
+#if !defined __x86_64__
+
+#define TEST_DIR "test_dir"
+#define TEST_FILE "test_file"
+#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
+ S_IXGRP|S_IROTH|S_IXOTH)
+
+struct old_linux_dirent {
+ long d_ino;
+ off_t d_off;
+ unsigned short d_reclen;
+ char d_name[NAME_MAX+1];
+};
+
+static unsigned int del_dir_fd, file_fd;
+static struct old_linux_dirent dirp;
+static void setup(void);
+static void cleanup(void);
+
+static struct test_case_t {
+ unsigned int *fd;
+ struct old_linux_dirent *dirp;
+ unsigned int count;
+ int exp_errno;
+} test_cases[] = {
+ {&del_dir_fd, &dirp, sizeof(struct old_linux_dirent), ENOENT},
+ {&file_fd, &dirp, sizeof(struct old_linux_dirent), ENOTDIR},
+};
+
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+static int exp_enos[] = { ENOENT, ENOTDIR, 0 };
+static void readdir_verify(const struct test_case_t *);
+
+int main(int argc, char **argv)
+{
+ int i, lc;
+ char *msg;
+
+ msg = parse_opts(argc, argv, NULL, NULL);
+ if (msg != NULL)
+ tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+ for (i = 0; i < TST_TOTAL; i++)
+ readdir_verify(&test_cases[i]);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+static void setup(void)
+{
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ TEST_EXP_ENOS(exp_enos);
+
+ TEST_PAUSE;
+
+ tst_tmpdir();
+
+ SAFE_MKDIR(cleanup, TEST_DIR, DIR_MODE);
+ del_dir_fd = SAFE_OPEN(cleanup, TEST_DIR, O_RDONLY | O_DIRECTORY);
+ if (rmdir(TEST_DIR) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "rmdir failed");
+
+ file_fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0777);
+}
+
+static void readdir_verify(const struct test_case_t *test)
+{
+ TEST(syscall(__NR_readdir, *test->fd, test->dirp, test->count));
+
+ if (TEST_RETURN != -1) {
+ tst_resm(TFAIL, "readdir() succeeded unexpectedly");
+ return;
+ }
+
+ if (TEST_ERRNO == test->exp_errno) {
+ tst_resm(TPASS | TTERRNO, "readdir() failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "readdir() failed unexpectedly; expected: %d - %s",
+ test->exp_errno, strerror(test->exp_errno));
+ }
+}
+
+static void cleanup(void)
+{
+ TEST_CLEANUP;
+
+ tst_rmdir();
+}
+
+#else
+
+int TST_TOTAL = 1;
+
+int main(void)
+{
+ tst_brkm(TCONF, NULL, "test is not available on __x86_64__");
+}
+
+#endif /* if !defined __x86_64__ */
--
1.8.4.2
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [LTP] [PATCH] readdir/readdir03.c: add new error number testes
2014-04-01 11:12 [LTP] [PATCH] readdir/readdir03.c: add new error number testes Zeng Linggang
@ 2014-05-05 16:32 ` chrubis
[not found] ` <1399373430.3177.55.camel@G08JYZSD130126>
0 siblings, 1 reply; 5+ messages in thread
From: chrubis @ 2014-05-05 16:32 UTC (permalink / raw)
To: Zeng Linggang; +Cc: ltp-list
Hi!
> --- /dev/null
> +++ b/testcases/kernel/syscalls/readdir/readdir03.c
> @@ -0,0 +1,151 @@
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> + *
> + * 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 Library 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-1307, USA.
> + *
> + */
> +/*
> + * Test Description:
> + * Verify that,
> + * 1. Creat a directory and open it, then delete the directory, ENOENT would
> + * return.
> + * 2. File descriptor does not refer to a directory, ENOTDIR would return.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <errno.h>
> +#include <limits.h>
> +#include <dirent.h>
> +#include <unistd.h>
> +#include <sys/syscall.h>
> +#include "test.h"
> +#include "usctest.h"
> +#include "safe_macros.h"
> +
> +char *TCID = "readdir03";
> +
> +#if !defined __x86_64__
Why is the test disabled on x86_64? What about other 64 bit
architectures?
> +#define TEST_DIR "test_dir"
> +#define TEST_FILE "test_file"
> +#define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
> + S_IXGRP|S_IROTH|S_IXOTH)
> +
> +struct old_linux_dirent {
> + long d_ino;
> + off_t d_off;
> + unsigned short d_reclen;
> + char d_name[NAME_MAX+1];
> +};
> +
> +static unsigned int del_dir_fd, file_fd;
> +static struct old_linux_dirent dirp;
> +static void setup(void);
> +static void cleanup(void);
> +
> +static struct test_case_t {
> + unsigned int *fd;
> + struct old_linux_dirent *dirp;
> + unsigned int count;
> + int exp_errno;
> +} test_cases[] = {
> + {&del_dir_fd, &dirp, sizeof(struct old_linux_dirent), ENOENT},
> + {&file_fd, &dirp, sizeof(struct old_linux_dirent), ENOTDIR},
> +};
> +
> +int TST_TOTAL = ARRAY_SIZE(test_cases);
> +static int exp_enos[] = { ENOENT, ENOTDIR, 0 };
> +static void readdir_verify(const struct test_case_t *);
> +
> +int main(int argc, char **argv)
> +{
> + int i, lc;
> + char *msg;
> +
> + msg = parse_opts(argc, argv, NULL, NULL);
> + if (msg != NULL)
> + tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> + setup();
> +
> + for (lc = 0; TEST_LOOPING(lc); lc++) {
> + tst_count = 0;
> + for (i = 0; i < TST_TOTAL; i++)
> + readdir_verify(&test_cases[i]);
> + }
> +
> + cleanup();
> + tst_exit();
> +}
> +
> +static void setup(void)
> +{
> + tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> + TEST_EXP_ENOS(exp_enos);
> +
> + TEST_PAUSE;
> +
> + tst_tmpdir();
> +
> + SAFE_MKDIR(cleanup, TEST_DIR, DIR_MODE);
> + del_dir_fd = SAFE_OPEN(cleanup, TEST_DIR, O_RDONLY | O_DIRECTORY);
> + if (rmdir(TEST_DIR) == -1)
> + tst_brkm(TBROK | TERRNO, cleanup, "rmdir failed");
> +
> + file_fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0777);
> +}
> +
> +static void readdir_verify(const struct test_case_t *test)
> +{
> + TEST(syscall(__NR_readdir, *test->fd, test->dirp, test->count));
So you are using raw readdir() syscall (man 2 readdir) instead of the
glibc readdir() (man 3 readdir).
Are you aware that the rest of the readdir testcases use the glibc
readdir()?
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
• 3 signs your SCM is hindering your productivity
• Requirements for releasing software faster
• Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-07 12:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01 11:12 [LTP] [PATCH] readdir/readdir03.c: add new error number testes Zeng Linggang
2014-05-05 16:32 ` chrubis
[not found] ` <1399373430.3177.55.camel@G08JYZSD130126>
2014-05-06 11:00 ` chrubis
[not found] ` <1399427555.2397.8.camel@G08JYZSD130126>
2014-05-07 9:09 ` chrubis
[not found] ` <1399459901.2397.18.camel@G08JYZSD130126>
2014-05-07 12:58 ` [LTP] [PATCH v2 2/2] readdir/readdir21.c: " chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox