* [LTP] [PATCH] readlinkat/readlinkat02.c: add new errno testes
@ 2014-04-08 10:41 Zeng Linggang
2014-05-07 10:52 ` chrubis
0 siblings, 1 reply; 2+ messages in thread
From: Zeng Linggang @ 2014-04-08 10:41 UTC (permalink / raw)
To: ltp-list
Add EINVAL and ENOTDIR errno testes for readlinkat(2)
Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
runtest/syscalls | 1 +
testcases/kernel/syscalls/.gitignore | 1 +
.../kernel/syscalls/readlinkat/readlinkat02.c | 127 +++++++++++++++++++++
3 files changed, 129 insertions(+)
create mode 100644 testcases/kernel/syscalls/readlinkat/readlinkat02.c
diff --git a/runtest/syscalls b/runtest/syscalls
index fb3e59f..93ec2ea 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -817,6 +817,7 @@ readlink04 readlink04
#readlinkat test cases
readlinkat01 readlinkat01
+readlinkat02 readlinkat02
readv01 readv01
readv02 readv02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d5c7bac..24e1707 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -668,6 +668,7 @@
/readlink/readlink03
/readlink/readlink04
/readlinkat/readlinkat01
+/readlinkat/readlinkat02
/readv/readv01
/readv/readv02
/readv/readv03
diff --git a/testcases/kernel/syscalls/readlinkat/readlinkat02.c b/testcases/kernel/syscalls/readlinkat/readlinkat02.c
new file mode 100644
index 0000000..c720601
--- /dev/null
+++ b/testcases/kernel/syscalls/readlinkat/readlinkat02.c
@@ -0,0 +1,127 @@
+/*
+ * 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. bufsiz is 0, EINVAL should be returned.
+ * 2. The named file is not a symbolic link, EINVAL should be returned.
+ * 3. The component of the path prefix is not a directory, ENOTDIR should be
+ * returned.
+ * 4. pathname is relative and dirfd is a file descriptor referring to a file
+ * other than a directory, ENOTDIR should be returned.
+ */
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "linux_syscall_numbers.h"
+
+#define TEST_FILE "test_file"
+#define SYMLINK_FILE "symlink_file"
+#define BUFF_SIZE 256
+
+static int file_fd, dir_fd;
+
+static struct test_case_t {
+ int *dirfd;
+ const char *pathname;
+ size_t bufsiz;
+ int exp_errno;
+} test_cases[] = {
+ {&dir_fd, SYMLINK_FILE, 0, EINVAL},
+ {&dir_fd, TEST_FILE, BUFF_SIZE, EINVAL},
+ {&file_fd, SYMLINK_FILE, BUFF_SIZE, ENOTDIR},
+ {&dir_fd, "test_file/test_file", BUFF_SIZE, ENOTDIR},
+};
+
+char *TCID = "readlinkat02";
+int TST_TOTAL = ARRAY_SIZE(test_cases);
+static int exp_enos[] = { EINVAL, ENOTDIR, 0 };
+static void setup(void);
+static void cleanup(void);
+static void readlinkat_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++)
+ readlinkat_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();
+
+ dir_fd = SAFE_OPEN(cleanup, "./", O_RDONLY);
+
+ file_fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0644);
+
+ SAFE_SYMLINK(cleanup, TEST_FILE, SYMLINK_FILE);
+}
+
+static void readlinkat_verify(const struct test_case_t *test)
+{
+ char buf[BUFF_SIZE];
+ TEST(readlinkat(*test->dirfd, test->pathname, buf, test->bufsiz));
+
+ if (TEST_RETURN != -1) {
+ tst_resm(TFAIL, "readlinkat succeeded unexpectedly");
+ return;
+ }
+
+ if (TEST_ERRNO == test->exp_errno) {
+ tst_resm(TPASS | TTERRNO, "readlinkat failed as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO,
+ "readlinkat failed unexpectedly; expected: %d - %s",
+ test->exp_errno, strerror(test->exp_errno));
+ }
+}
+
+static void cleanup(void)
+{
+ TEST_CLEANUP;
+
+ tst_rmdir();
+}
--
1.8.4.2
------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH] readlinkat/readlinkat02.c: add new errno testes
2014-04-08 10:41 [LTP] [PATCH] readlinkat/readlinkat02.c: add new errno testes Zeng Linggang
@ 2014-05-07 10:52 ` chrubis
0 siblings, 0 replies; 2+ messages in thread
From: chrubis @ 2014-05-07 10:52 UTC (permalink / raw)
To: Zeng Linggang; +Cc: ltp-list
Hi!
> Add EINVAL and ENOTDIR errno testes for readlinkat(2)
>
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
I've added configure check for readlinkat and lapi/readlinkat.h and
included it in the testcase and pushed, thanks.
(I've also cleaned up readlinkat01 testcase)
--
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] 2+ messages in thread
end of thread, other threads:[~2014-05-07 10:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-08 10:41 [LTP] [PATCH] readlinkat/readlinkat02.c: add new errno testes Zeng Linggang
2014-05-07 10:52 ` chrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox