* [LTP] [PATCH] preadv/preadv02.c: add new testcase
@ 2015-12-29 10:20 Xiao Yang
2015-12-29 10:20 ` [LTP] [PATCH] pwritev/pwritev02.c: " Xiao Yang
0 siblings, 1 reply; 4+ messages in thread
From: Xiao Yang @ 2015-12-29 10:20 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 4+ messages in thread* [LTP] [PATCH] pwritev/pwritev02.c: add new testcase
2015-12-29 10:20 [LTP] [PATCH] preadv/preadv02.c: add new testcase Xiao Yang
@ 2015-12-29 10:20 ` Xiao Yang
2016-01-26 16:38 ` Cyril Hrubis
0 siblings, 1 reply; 4+ messages in thread
From: Xiao Yang @ 2015-12-29 10:20 UTC (permalink / raw)
To: ltp
1) pwritev(2) fails if iov_len is invalid and set errno to EINVAL.
2) pwritev(2) fails if the vector count is less than zero set errno to EINVAL.
3) pwritev(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/pwritev/pwritev02.c | 126 ++++++++++++++++++++++++++
5 files changed, 132 insertions(+)
create mode 100644 testcases/kernel/syscalls/pwritev/pwritev02.c
diff --git a/runtest/ltplite b/runtest/ltplite
index 1aa93e6..5356cf3 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -609,6 +609,7 @@ pwrite02_64 pwrite02_64
pwrite04_64 pwrite04_64
pwritev01 pwritev01
+pwritev02 pwritev02
read01 read01
read02 read02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 87f42ea..68bacff 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -518,6 +518,7 @@ pwrite02_64 pwrite02_64
pwrite04_64 pwrite04_64
pwritev01 pwritev01
+pwritev02 pwritev02
read01 read01
read02 read02
diff --git a/runtest/syscalls b/runtest/syscalls
index 7173f22..9158f39 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -815,6 +815,8 @@ pwrite04_64 pwrite04_64
pwritev01 pwritev01
pwritev01_64 pwritev01_64
+pwritev02 pwritev02
+pwritev02_64 pwritev02_64
quotactl01 quotactl01
quotactl02 quotactl02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d5f21ef..423ad55 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -680,6 +680,8 @@
/pwrite/pwrite04_64
/pwritev/pwritev01
/pwritev/pwritev01_64
+/pwritev/pwritev02
+/pwritev/pwritev02_64
/quotactl/quotactl01
/quotactl/quotactl02
/read/read01
diff --git a/testcases/kernel/syscalls/pwritev/pwritev02.c b/testcases/kernel/syscalls/pwritev/pwritev02.c
new file mode 100644
index 0000000..0c8e436
--- /dev/null
+++ b/testcases/kernel/syscalls/pwritev/pwritev02.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: pwritev02
+*
+* Description:
+* 1) pwritev(2) fails if iov_len is invalid.
+* 2) pwritev(2) fails if the vector count iovcnt is less than zero.
+* 3) pwritev(2) fails if offset is negative.
+*
+* Expected Result:
+* 1) pwritev(2) should return -1 and set errno to EINVAL.
+* 2) pwritev(2) should return -1 and set errno to EINVAL.
+* 3) pwritev(2) should return -1 and set errno to EINVAL.
+*/
+
+#include <errno.h>
+
+#include "test.h"
+#include "pwritev.h"
+#include "safe_macros.h"
+
+#define CHUNK 64
+
+static int fd;
+static char buf[CHUNK];
+
+static struct iovec wr_iovec1[] = {
+ {buf, -1},
+};
+
+static struct iovec wr_iovec2[] = {
+ {buf, CHUNK},
+};
+
+static struct test_case_t {
+ struct iovec *name;
+ int count;
+ off_t offset;
+} tc[] = {
+ /* test1 */
+ {wr_iovec1, 1, 0},
+ /* test2 */
+ {wr_iovec2, -1, 0},
+ /* test3 */
+ {wr_iovec2, 1, -1}
+};
+
+void verify_pwritev(struct test_case_t *tc);
+void setup(void);
+void cleanup(void);
+
+char *TCID = "pwritev02";
+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_pwritev(&tc[i]);
+ }
+
+ cleanup();
+ tst_exit();
+}
+
+void verify_pwritev(struct test_case_t *tc)
+{
+ TEST(pwritev(fd, tc->name, tc->count, tc->offset));
+ if (TEST_RETURN == 0) {
+ tst_resm(TFAIL, "pwritev(2) succeed unexpectedly");
+ } else {
+ if (TEST_ERRNO == EINVAL) {
+ tst_resm(TPASS | TTERRNO, "pwritev(2) fails as expected");
+ } else {
+ tst_resm(TFAIL | TTERRNO, "pwritev(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
^ permalink raw reply related [flat|nested] 4+ messages in thread* [LTP] [PATCH] pwritev/pwritev02.c: add new testcase
2015-12-29 10:20 ` [LTP] [PATCH] pwritev/pwritev02.c: " Xiao Yang
@ 2016-01-26 16:38 ` Cyril Hrubis
2016-01-27 2:53 ` Xiao Yang
0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2016-01-26 16:38 UTC (permalink / raw)
To: ltp
Hi!
Both pushed, thanks.
BTW: both preadv() and pwritev() can also fail with errors specified for
read() and write(), so we should, get EBADFD if fd is invalid or not
open for reading/writing for read/write, etc.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 4+ messages in thread* [LTP] [PATCH] pwritev/pwritev02.c: add new testcase
2016-01-26 16:38 ` Cyril Hrubis
@ 2016-01-27 2:53 ` Xiao Yang
0 siblings, 0 replies; 4+ messages in thread
From: Xiao Yang @ 2016-01-27 2:53 UTC (permalink / raw)
To: ltp
? 2016/01/27 0:38, Cyril Hrubis ??:
> Hi!
> Both pushed, thanks.
>
> BTW: both preadv() and pwritev() can also fail with errors specified for
> read() and write(), so we should, get EBADFD if fd is invalid or not
> open for reading/writing for read/write, etc.
Thanks for your suggestion. I will send patches to test other errors.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-01-27 2:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-29 10:20 [LTP] [PATCH] preadv/preadv02.c: add new testcase Xiao Yang
2015-12-29 10:20 ` [LTP] [PATCH] pwritev/pwritev02.c: " Xiao Yang
2016-01-26 16:38 ` Cyril Hrubis
2016-01-27 2:53 ` Xiao Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox