[LTP] [PATCH] preadv/preadv02.c: add new testcase
Xiao Yang
yangx.jy@cn.fujitsu.com
Tue Dec 29 11:20:30 CET 2015
1) preadv(2) fails if iov_len is invalid and set errno to EINVAL.
2) preadv(2) fails if the vector count is less than zero and set errno to EINVAL.
3) preadv(2) fails if offset is negative and set errno to EINVAL.
Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
runtest/ltplite | 1 +
runtest/stress.part3 | 1 +
runtest/syscalls | 2 +
testcases/kernel/syscalls/.gitignore | 2 +
testcases/kernel/syscalls/preadv/preadv02.c | 126 ++++++++++++++++++++++++++++
5 files changed, 132 insertions(+)
create mode 100644 testcases/kernel/syscalls/preadv/preadv02.c
diff --git a/runtest/ltplite b/runtest/ltplite
index 1aa93e6..e129c66 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -589,6 +589,7 @@ pread02 pread02
pread03 pread03
preadv01 preadv01
+preadv02 preadv02
profil01 profil01
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 87f42ea..0ed71c0 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -499,6 +499,7 @@ pread02 pread02
pread03 pread03
preadv01 preadv01
+preadv02 preadv02
profil01 profil01
diff --git a/runtest/syscalls b/runtest/syscalls
index 7173f22..e940146 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -781,6 +781,8 @@ pread03_64 pread03_64
preadv01 preadv01
preadv01_64 preadv01_64
+preadv02 preadv02
+preadv02_64 preadv02_64
profil01 profil01
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d5f21ef..197f444 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -659,6 +659,8 @@
/pread/pread03_64
/preadv/preadv01
/preadv/preadv01_64
+/preadv/preadv02
+/preadv/preadv02_64
/profil/profil01
/pselect/pselect01
/pselect/pselect01_64
diff --git a/testcases/kernel/syscalls/preadv/preadv02.c b/testcases/kernel/syscalls/preadv/preadv02.c
new file mode 100644
index 0000000..1fcaa3c
--- /dev/null
+++ b/testcases/kernel/syscalls/preadv/preadv02.c
@@ -0,0 +1,126 @@
+/*
+* Copyright (c) 2015 Fujitsu Ltd.
+* Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+*
+* This program is free software; you can redistribute it and/or modify it
+* under the terms of version 2 of the GNU General Public License as
+* published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it would be useful, but
+* WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+*
+* You should have received a copy of the GNU General Public License
+* alone with this program.
+*/
+
+/*
+* Test Name: preadv02
+*
+* Description:
+* 1) preadv(2) fails if iov_len is invalid.
+* 2) preadv(2) fails if the vector count iovcnt is less than zero.
+* 3) preadv(2) fails if offset is negative.
+*
+* Expected Result:
+* 1) preadv(2) should return -1 and set errno to EINVAL.
+* 2) preadv(2) should return -1 and set errno to EINVAL.
+* 3) preadv(2) should return -1 and set errno to EINVAL.
+*/
+
+#include <errno.h>
+
+#include "test.h"
+#include "preadv.h"
+#include "safe_macros.h"
+
+#define CHUNK 64
+
+static int fd;
+static char buf[CHUNK];
+
+static struct iovec rd_iovec1[] = {
+ {buf, -1},
+};
+
+static struct iovec rd_iovec2[] = {
+ {buf, CHUNK},
+};
+
+static struct test_case_t {
+ struct iovec *name;
+ int count;
+ off_t offset;
+} tc[] = {
+ /* test1 */
+ {rd_iovec1, 1, 0},
+ /* test2 */
+ {rd_iovec2, -1, 0},
+ /* test3 */
+ {rd_iovec2, 1, -1}
+};
+
+void verify_preadv(struct test_case_t *tc);
+void setup(void);
+void cleanup(void);
+
+char *TCID = "preadv02";
+int TST_TOTAL = ARRAY_SIZE(tc);
+
+int main(int ac, char **av)
+{
+ int lc;
+ int i;
+
+ tst_parse_opts(ac, av, NULL, NULL);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+ for (i = 0; i < TST_TOTAL; i++)
+ verify_preadv(&tc[i]);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+void verify_preadv(struct test_case_t *tc)
+{
+ TEST(preadv(fd, tc->name, tc->count, tc->offset));
+ if (TEST_RETURN == 0) {
+ tst_resm(TFAIL, "preadv(2) succeed unexpectedly");
+ } else {
+ if (TEST_ERRNO == EINVAL) {
+ tst_resm(TPASS | TTERRNO, "preadv(2) fails as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO, "preadv(2) fails unexpectedly,"
+ " expected errno is EINVAL");
+ }
+ }
+}
+
+void setup(void)
+{
+ if ((tst_kvercmp(2, 6, 30)) < 0) {
+ tst_brkm(TCONF, NULL, "This test can only run on kernels"
+ " that are 2.6.30 or higher.");
+ }
+
+ tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+ TEST_PAUSE;
+
+ tst_tmpdir();
+
+ fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
+}
+
+void cleanup(void)
+{
+ if (fd > 0 && close(fd))
+ tst_resm(TWARN | TERRNO, "failed to close file");
+
+ tst_rmdir();
+}
--
1.8.3.1
More information about the Ltp
mailing list