All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv()
@ 2016-03-25  2:08 Xiao Yang
  2016-03-25  2:08 ` [LTP] [PATCH 2/2] pwritev/pwritev02.c: add specific error for pwritev() Xiao Yang
  2016-03-31 14:13 ` [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv() Cyril Hrubis
  0 siblings, 2 replies; 7+ messages in thread
From: Xiao Yang @ 2016-03-25  2:08 UTC (permalink / raw)
  To: ltp

1) preadv(2) fails when attempts to read into a invalid address
   and set errno to EFAULT.
2) preadv(2) fails if file descriptor is invalid and set errno
   to EBADF.
3) preadv(2) fails if file descriptor is not open for reading
   and set errno to EBADF.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/preadv/preadv02.c | 69 +++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/preadv/preadv02.c b/testcases/kernel/syscalls/preadv/preadv02.c
index 1fcaa3c..40d5f9e 100644
--- a/testcases/kernel/syscalls/preadv/preadv02.c
+++ b/testcases/kernel/syscalls/preadv/preadv02.c
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015 Fujitsu Ltd.
+* Copyright (c) 2016 Fujitsu Ltd.
 * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 *
 * This program is free software; you can redistribute it and/or modify it
@@ -21,14 +21,21 @@
 * 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.
+* 4) preadv(2) fails when attempts to read into a invalid address.
+* 5) preadv(2) fails if file descriptor is invalid.
+* 6) preadv(2) fails if file descriptor is not open for reading.
 *
 * 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.
+* 4) preadv(2) should return -1 and set errno to EFAULT.
+* 5) preadv(2) should return -1 and set errno to EBADF.
+* 6) preadv(2) should return -1 and set errno to EBADF.
 */
 
 #include <errno.h>
+#include <sys/uio.h>
 
 #include "test.h"
 #include "preadv.h"
@@ -36,7 +43,8 @@
 
 #define CHUNK           64
 
-static int fd;
+static int fd1;
+static int fd2;
 static char buf[CHUNK];
 
 static struct iovec rd_iovec1[] = {
@@ -45,24 +53,33 @@ static struct iovec rd_iovec1[] = {
 
 static struct iovec rd_iovec2[] = {
 	{buf, CHUNK},
+	{(char *)-1, CHUNK},
 };
 
 static struct test_case_t {
+	int des;
 	struct iovec *name;
 	int count;
 	off_t offset;
+	int exp_err;
 } tc[] = {
 	/* test1 */
-	{rd_iovec1, 1, 0},
+	{0, rd_iovec1, 1, 0, EINVAL},
 	/* test2 */
-	{rd_iovec2, -1, 0},
+	{0, rd_iovec2, -1, 0, EINVAL},
 	/* test3 */
-	{rd_iovec2, 1, -1}
+	{0, rd_iovec2, 1, -1, EINVAL},
+	/* test4 */
+	{0, rd_iovec2, 2, 0, EFAULT},
+	/* test5 */
+	{-1, rd_iovec2, 1, 0, EBADF},
+	/* test6 */
+	{0, rd_iovec2, 1, 0, EBADF}
 };
 
-void verify_preadv(struct test_case_t *tc);
-void setup(void);
-void cleanup(void);
+static void verify_preadv(struct test_case_t *tc);
+static void setup(void);
+static void cleanup(void);
 
 char *TCID = "preadv02";
 int TST_TOTAL = ARRAY_SIZE(tc);
@@ -86,23 +103,27 @@ int main(int ac, char **av)
 	tst_exit();
 }
 
-void verify_preadv(struct test_case_t *tc)
+static void verify_preadv(struct test_case_t *tc)
 {
-	TEST(preadv(fd, tc->name, tc->count, tc->offset));
+	TEST(preadv(tc->des, tc->name, tc->count, tc->offset));
 	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "preadv(2) succeed unexpectedly");
+		tst_resm(TFAIL, "preadv() succeeded unexpectedly");
 	} else {
-		if (TEST_ERRNO == EINVAL) {
-			tst_resm(TPASS | TTERRNO, "preadv(2) fails as expected");
+		if (TEST_ERRNO == tc->exp_err) {
+			tst_resm(TPASS | TTERRNO,
+				 "preadv() failed as expected");
 		} else {
-			tst_resm(TFAIL | TTERRNO, "preadv(2) fails unexpectedly,"
-				 " expected errno is EINVAL");
+			tst_resm(TFAIL | TTERRNO,
+				 "preadv() failed unexpectedly, expected"
+				 " errno is %s", tst_strerrno(tc->exp_err));
 		}
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
+	int i;
+
 	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.");
@@ -114,12 +135,22 @@ void setup(void)
 
 	tst_tmpdir();
 
-	fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
+	fd1 = SAFE_OPEN(cleanup, "file1", O_RDWR | O_CREAT, 0644);
+
+	fd2 = SAFE_OPEN(cleanup, "file2", O_WRONLY | O_CREAT, 0644);
+
+	for (i = 0; i < 4; i++)
+		tc[i].des = fd1;
+
+	tc[5].des = fd2;
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
+	if (fd1 > 0 && close(fd1))
+		tst_resm(TWARN | TERRNO, "failed to close file");
+
+	if (fd2 > 0 && close(fd2))
 		tst_resm(TWARN | TERRNO, "failed to close file");
 
 	tst_rmdir();
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH 2/2] pwritev/pwritev02.c: add specific error for pwritev()
  2016-03-25  2:08 [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv() Xiao Yang
@ 2016-03-25  2:08 ` Xiao Yang
  2016-03-31 14:14   ` Cyril Hrubis
  2016-03-31 14:13 ` [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv() Cyril Hrubis
  1 sibling, 1 reply; 7+ messages in thread
From: Xiao Yang @ 2016-03-25  2:08 UTC (permalink / raw)
  To: ltp

1) pwritev(2) fails when attempts to write from a invalid address
   and set errno to EFAULT.
2) pwritev(2) fails if file descriptor is invalid and set errno
   to EBADF.
3) pwritev(2) fails if file descriptor is not open for writing
   and set errno to EBADF.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/pwritev/pwritev02.c | 69 +++++++++++++++++++--------
 1 file changed, 50 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/pwritev/pwritev02.c b/testcases/kernel/syscalls/pwritev/pwritev02.c
index 0c8e436..0e77c5e 100644
--- a/testcases/kernel/syscalls/pwritev/pwritev02.c
+++ b/testcases/kernel/syscalls/pwritev/pwritev02.c
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015 Fujitsu Ltd.
+* Copyright (c) 2016 Fujitsu Ltd.
 * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 *
 * This program is free software; you can redistribute it and/or modify it
@@ -21,14 +21,21 @@
 * 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.
+* 4) pwritev(2) fails when attempts to write from a invalid address
+* 5) pwritev(2) fails if file descriptor is invalid.
+* 6) pwritev(2) fails if file descriptor is not open for writing.
 *
 * 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.
+* 4) pwritev(2) should return -1 and set errno to EFAULT.
+* 5) pwritev(2) should return -1 and set errno to EBADF.
+* 6) pwritev(2) should return -1 and set errno to EBADF.
 */
 
 #include <errno.h>
+#include <sys/uio.h>
 
 #include "test.h"
 #include "pwritev.h"
@@ -36,7 +43,8 @@
 
 #define CHUNK           64
 
-static int fd;
+static int fd1;
+static int fd2;
 static char buf[CHUNK];
 
 static struct iovec wr_iovec1[] = {
@@ -45,24 +53,33 @@ static struct iovec wr_iovec1[] = {
 
 static struct iovec wr_iovec2[] = {
 	{buf, CHUNK},
+	{(char *)-1, CHUNK},
 };
 
 static struct test_case_t {
+	int des;
 	struct iovec *name;
 	int count;
 	off_t offset;
+	int exp_err;
 } tc[] = {
 	/* test1 */
-	{wr_iovec1, 1, 0},
+	{0, wr_iovec1, 1, 0, EINVAL},
 	/* test2 */
-	{wr_iovec2, -1, 0},
+	{0, wr_iovec2, -1, 0, EINVAL},
 	/* test3 */
-	{wr_iovec2, 1, -1}
+	{0, wr_iovec2, 1, -1, EINVAL},
+	/* test4 */
+	{0, wr_iovec2, 2, 0, EFAULT},
+	/* test5 */
+	{-1, wr_iovec2, 1, 0, EBADF},
+	/* test6 */
+	{0, wr_iovec2, 1, 0, EBADF}
 };
 
-void verify_pwritev(struct test_case_t *tc);
-void setup(void);
-void cleanup(void);
+static void verify_pwritev(struct test_case_t *tc);
+static void setup(void);
+static void cleanup(void);
 
 char *TCID = "pwritev02";
 int TST_TOTAL = ARRAY_SIZE(tc);
@@ -86,23 +103,27 @@ int main(int ac, char **av)
 	tst_exit();
 }
 
-void verify_pwritev(struct test_case_t *tc)
+static void verify_pwritev(struct test_case_t *tc)
 {
-	TEST(pwritev(fd, tc->name, tc->count, tc->offset));
+	TEST(pwritev(tc->des, tc->name, tc->count, tc->offset));
 	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "pwritev(2) succeed unexpectedly");
+		tst_resm(TFAIL, "pwritev() succeeded unexpectedly");
 	} else {
-		if (TEST_ERRNO == EINVAL) {
-			tst_resm(TPASS | TTERRNO, "pwritev(2) fails as expected");
+		if (TEST_ERRNO == tc->exp_err) {
+			tst_resm(TPASS | TTERRNO,
+				 "pwritev() failed as expected");
 		} else {
-			tst_resm(TFAIL | TTERRNO, "pwritev(2) fails unexpectedly,"
-				 " expected errno is EINVAL");
+			tst_resm(TFAIL | TTERRNO,
+				 "pwritev() failed unexpectedly, expected"
+				 " errno is %s", tst_strerrno(tc->exp_err));
 		}
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
+	int i;
+
 	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.");
@@ -114,12 +135,22 @@ void setup(void)
 
 	tst_tmpdir();
 
-	fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
+	fd1 = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
+
+	fd2 = SAFE_OPEN(cleanup, "file", O_RDONLY | O_CREAT, 0644);
+
+	for (i = 0; i < 4; i++)
+		tc[i].des = fd1;
+
+	tc[5].des = fd2;
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
+	if (fd1 > 0 && close(fd1))
+		tst_resm(TWARN | TERRNO, "failed to close file");
+
+	if (fd2 > 0 && close(fd2))
 		tst_resm(TWARN | TERRNO, "failed to close file");
 
 	tst_rmdir();
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv()
  2016-03-25  2:08 [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv() Xiao Yang
  2016-03-25  2:08 ` [LTP] [PATCH 2/2] pwritev/pwritev02.c: add specific error for pwritev() Xiao Yang
@ 2016-03-31 14:13 ` Cyril Hrubis
  2016-04-01  5:14   ` [LTP] [PATCH v2 " Xiao Yang
  1 sibling, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2016-03-31 14:13 UTC (permalink / raw)
  To: ltp

Hi!
>  /*
> -* Copyright (c) 2015 Fujitsu Ltd.
> +* Copyright (c) 2016 Fujitsu Ltd.

The 2015 should stay there, you should make it:

Copyright (c) 2015-2016 Fujitsu Ltd.

>  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
>  *
>  * This program is free software; you can redistribute it and/or modify it
> @@ -21,14 +21,21 @@
>  * 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.
> +* 4) preadv(2) fails when attempts to read into a invalid address.
> +* 5) preadv(2) fails if file descriptor is invalid.
> +* 6) preadv(2) fails if file descriptor is not open for reading.
>  *
>  * 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.
> +* 4) preadv(2) should return -1 and set errno to EFAULT.
> +* 5) preadv(2) should return -1 and set errno to EBADF.
> +* 6) preadv(2) should return -1 and set errno to EBADF.
>  */
>  
>  #include <errno.h>
> +#include <sys/uio.h>
>  
>  #include "test.h"
>  #include "preadv.h"
> @@ -36,7 +43,8 @@
>  
>  #define CHUNK           64
>  
> -static int fd;
> +static int fd1;
> +static int fd2;
>  static char buf[CHUNK];
>  
>  static struct iovec rd_iovec1[] = {
> @@ -45,24 +53,33 @@ static struct iovec rd_iovec1[] = {
>  
>  static struct iovec rd_iovec2[] = {
>  	{buf, CHUNK},
> +	{(char *)-1, CHUNK},
>  };
>  
>  static struct test_case_t {
> +	int des;

This should be called fd, calling it des is quite confusing. Also it
should be pointer to int and it should be initialized to &fd1 or &fd2
instead of setting it in the setup().

>  	struct iovec *name;
>  	int count;
>  	off_t offset;
> +	int exp_err;
>  } tc[] = {
>  	/* test1 */
> -	{rd_iovec1, 1, 0},
> +	{0, rd_iovec1, 1, 0, EINVAL},
>  	/* test2 */
> -	{rd_iovec2, -1, 0},
> +	{0, rd_iovec2, -1, 0, EINVAL},
>  	/* test3 */
> -	{rd_iovec2, 1, -1}
> +	{0, rd_iovec2, 1, -1, EINVAL},
> +	/* test4 */
> +	{0, rd_iovec2, 2, 0, EFAULT},
> +	/* test5 */
> +	{-1, rd_iovec2, 1, 0, EBADF},
> +	/* test6 */
> +	{0, rd_iovec2, 1, 0, EBADF}
>  };
>  
> -void verify_preadv(struct test_case_t *tc);
> -void setup(void);
> -void cleanup(void);
> +static void verify_preadv(struct test_case_t *tc);
> +static void setup(void);
> +static void cleanup(void);
>  
>  char *TCID = "preadv02";
>  int TST_TOTAL = ARRAY_SIZE(tc);
> @@ -86,23 +103,27 @@ int main(int ac, char **av)
>  	tst_exit();
>  }
>  
> -void verify_preadv(struct test_case_t *tc)
> +static void verify_preadv(struct test_case_t *tc)
>  {
> -	TEST(preadv(fd, tc->name, tc->count, tc->offset));
> +	TEST(preadv(tc->des, tc->name, tc->count, tc->offset));
>  	if (TEST_RETURN == 0) {
> -		tst_resm(TFAIL, "preadv(2) succeed unexpectedly");
> +		tst_resm(TFAIL, "preadv() succeeded unexpectedly");
>  	} else {
> -		if (TEST_ERRNO == EINVAL) {
> -			tst_resm(TPASS | TTERRNO, "preadv(2) fails as expected");
> +		if (TEST_ERRNO == tc->exp_err) {
> +			tst_resm(TPASS | TTERRNO,
> +				 "preadv() failed as expected");
>  		} else {
> -			tst_resm(TFAIL | TTERRNO, "preadv(2) fails unexpectedly,"
> -				 " expected errno is EINVAL");
> +			tst_resm(TFAIL | TTERRNO,
> +				 "preadv() failed unexpectedly, expected"
> +				 " errno is %s", tst_strerrno(tc->exp_err));
>  		}
>  	}
>  }
>  
> -void setup(void)
> +static void setup(void)
>  {
> +	int i;
> +
>  	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.");
> @@ -114,12 +135,22 @@ void setup(void)
>  
>  	tst_tmpdir();
>  
> -	fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
> +	fd1 = SAFE_OPEN(cleanup, "file1", O_RDWR | O_CREAT, 0644);
> +
> +	fd2 = SAFE_OPEN(cleanup, "file2", O_WRONLY | O_CREAT, 0644);
> +
> +	for (i = 0; i < 4; i++)
> +		tc[i].des = fd1;
> +
> +	tc[5].des = fd2;
>  }
>  
> -void cleanup(void)
> +static void cleanup(void)
>  {
> -	if (fd > 0 && close(fd))
> +	if (fd1 > 0 && close(fd1))
> +		tst_resm(TWARN | TERRNO, "failed to close file");
> +
> +	if (fd2 > 0 && close(fd2))
>  		tst_resm(TWARN | TERRNO, "failed to close file");
>  
>  	tst_rmdir();


Otherwise it looks fine.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH 2/2] pwritev/pwritev02.c: add specific error for pwritev()
  2016-03-25  2:08 ` [LTP] [PATCH 2/2] pwritev/pwritev02.c: add specific error for pwritev() Xiao Yang
@ 2016-03-31 14:14   ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2016-03-31 14:14 UTC (permalink / raw)
  To: ltp

Hi!
The same applies here as well.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 1/2] preadv/preadv02.c: add specific error for preadv()
  2016-03-31 14:13 ` [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv() Cyril Hrubis
@ 2016-04-01  5:14   ` Xiao Yang
  2016-04-01  5:14     ` [LTP] [PATCH v2 2/2] pwritev/pwritev02.c: add specific error for pwritev() Xiao Yang
  0 siblings, 1 reply; 7+ messages in thread
From: Xiao Yang @ 2016-04-01  5:14 UTC (permalink / raw)
  To: ltp

1) preadv(2) fails when attempts to read into a invalid address
   and set errno to EFAULT.
2) preadv(2) fails if file descriptor is invalid and set errno
   to EBADF.
3) preadv(2) fails if file descriptor is not open for reading
   and set errno to EBADF.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/preadv/preadv02.c | 63 ++++++++++++++++++++---------
 1 file changed, 44 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/preadv/preadv02.c b/testcases/kernel/syscalls/preadv/preadv02.c
index 1fcaa3c..e21ffea 100644
--- a/testcases/kernel/syscalls/preadv/preadv02.c
+++ b/testcases/kernel/syscalls/preadv/preadv02.c
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015 Fujitsu Ltd.
+* Copyright (c) 2015-2016 Fujitsu Ltd.
 * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 *
 * This program is free software; you can redistribute it and/or modify it
@@ -21,14 +21,21 @@
 * 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.
+* 4) preadv(2) fails when attempts to read into a invalid address.
+* 5) preadv(2) fails if file descriptor is invalid.
+* 6) preadv(2) fails if file descriptor is not open for reading.
 *
 * 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.
+* 4) preadv(2) should return -1 and set errno to EFAULT.
+* 5) preadv(2) should return -1 and set errno to EBADF.
+* 6) preadv(2) should return -1 and set errno to EBADF.
 */
 
 #include <errno.h>
+#include <sys/uio.h>
 
 #include "test.h"
 #include "preadv.h"
@@ -36,7 +43,9 @@
 
 #define CHUNK           64
 
-static int fd;
+static int fd1;
+static int fd2;
+static int fd3 = -1;
 static char buf[CHUNK];
 
 static struct iovec rd_iovec1[] = {
@@ -45,24 +54,33 @@ static struct iovec rd_iovec1[] = {
 
 static struct iovec rd_iovec2[] = {
 	{buf, CHUNK},
+	{(char *)-1, CHUNK},
 };
 
 static struct test_case_t {
+	int *fd;
 	struct iovec *name;
 	int count;
 	off_t offset;
+	int exp_err;
 } tc[] = {
 	/* test1 */
-	{rd_iovec1, 1, 0},
+	{&fd1, rd_iovec1, 1, 0, EINVAL},
 	/* test2 */
-	{rd_iovec2, -1, 0},
+	{&fd1, rd_iovec2, -1, 0, EINVAL},
 	/* test3 */
-	{rd_iovec2, 1, -1}
+	{&fd1, rd_iovec2, 1, -1, EINVAL},
+	/* test4 */
+	{&fd1, rd_iovec2, 2, 0, EFAULT},
+	/* test5 */
+	{&fd3, rd_iovec2, 1, 0, EBADF},
+	/* test6 */
+	{&fd2, rd_iovec2, 1, 0, EBADF}
 };
 
-void verify_preadv(struct test_case_t *tc);
-void setup(void);
-void cleanup(void);
+static void verify_preadv(struct test_case_t *tc);
+static void setup(void);
+static void cleanup(void);
 
 char *TCID = "preadv02";
 int TST_TOTAL = ARRAY_SIZE(tc);
@@ -86,22 +104,24 @@ int main(int ac, char **av)
 	tst_exit();
 }
 
-void verify_preadv(struct test_case_t *tc)
+static void verify_preadv(struct test_case_t *tc)
 {
-	TEST(preadv(fd, tc->name, tc->count, tc->offset));
+	TEST(preadv(*tc->fd, tc->name, tc->count, tc->offset));
 	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "preadv(2) succeed unexpectedly");
+		tst_resm(TFAIL, "preadv() succeeded unexpectedly");
 	} else {
-		if (TEST_ERRNO == EINVAL) {
-			tst_resm(TPASS | TTERRNO, "preadv(2) fails as expected");
+		if (TEST_ERRNO == tc->exp_err) {
+			tst_resm(TPASS | TTERRNO,
+				 "preadv() failed as expected");
 		} else {
-			tst_resm(TFAIL | TTERRNO, "preadv(2) fails unexpectedly,"
-				 " expected errno is EINVAL");
+			tst_resm(TFAIL | TTERRNO,
+				 "preadv() failed unexpectedly, expected"
+				 " errno is %s", tst_strerrno(tc->exp_err));
 		}
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
 	if ((tst_kvercmp(2, 6, 30)) < 0) {
 		tst_brkm(TCONF, NULL, "This test can only run on kernels"
@@ -114,12 +134,17 @@ void setup(void)
 
 	tst_tmpdir();
 
-	fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
+	fd1 = SAFE_OPEN(cleanup, "file1", O_RDWR | O_CREAT, 0644);
+
+	fd2 = SAFE_OPEN(cleanup, "file2", O_WRONLY | O_CREAT, 0644);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
+	if (fd1 > 0 && close(fd1))
+		tst_resm(TWARN | TERRNO, "failed to close file");
+
+	if (fd2 > 0 && close(fd2))
 		tst_resm(TWARN | TERRNO, "failed to close file");
 
 	tst_rmdir();
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 2/2] pwritev/pwritev02.c: add specific error for pwritev()
  2016-04-01  5:14   ` [LTP] [PATCH v2 " Xiao Yang
@ 2016-04-01  5:14     ` Xiao Yang
  2016-04-04 16:01       ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Xiao Yang @ 2016-04-01  5:14 UTC (permalink / raw)
  To: ltp

1) pwritev(2) fails when attempts to write from a invalid address
   and set errno to EFAULT.
2) pwritev(2) fails if file descriptor is invalid and set errno
   to EBADF.
3) pwritev(2) fails if file descriptor is not open for writing
   and set errno to EBADF.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/pwritev/pwritev02.c | 63 +++++++++++++++++++--------
 1 file changed, 44 insertions(+), 19 deletions(-)

diff --git a/testcases/kernel/syscalls/pwritev/pwritev02.c b/testcases/kernel/syscalls/pwritev/pwritev02.c
index 0c8e436..6e8b7ea 100644
--- a/testcases/kernel/syscalls/pwritev/pwritev02.c
+++ b/testcases/kernel/syscalls/pwritev/pwritev02.c
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2015 Fujitsu Ltd.
+* Copyright (c) 2015-2016 Fujitsu Ltd.
 * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 *
 * This program is free software; you can redistribute it and/or modify it
@@ -21,14 +21,21 @@
 * 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.
+* 4) pwritev(2) fails when attempts to write from a invalid address
+* 5) pwritev(2) fails if file descriptor is invalid.
+* 6) pwritev(2) fails if file descriptor is not open for writing.
 *
 * 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.
+* 4) pwritev(2) should return -1 and set errno to EFAULT.
+* 5) pwritev(2) should return -1 and set errno to EBADF.
+* 6) pwritev(2) should return -1 and set errno to EBADF.
 */
 
 #include <errno.h>
+#include <sys/uio.h>
 
 #include "test.h"
 #include "pwritev.h"
@@ -36,7 +43,9 @@
 
 #define CHUNK           64
 
-static int fd;
+static int fd1;
+static int fd2;
+static int fd3 = -1;
 static char buf[CHUNK];
 
 static struct iovec wr_iovec1[] = {
@@ -45,24 +54,33 @@ static struct iovec wr_iovec1[] = {
 
 static struct iovec wr_iovec2[] = {
 	{buf, CHUNK},
+	{(char *)-1, CHUNK},
 };
 
 static struct test_case_t {
+	int *fd;
 	struct iovec *name;
 	int count;
 	off_t offset;
+	int exp_err;
 } tc[] = {
 	/* test1 */
-	{wr_iovec1, 1, 0},
+	{&fd1, wr_iovec1, 1, 0, EINVAL},
 	/* test2 */
-	{wr_iovec2, -1, 0},
+	{&fd1, wr_iovec2, -1, 0, EINVAL},
 	/* test3 */
-	{wr_iovec2, 1, -1}
+	{&fd1, wr_iovec2, 1, -1, EINVAL},
+	/* test4 */
+	{&fd1, wr_iovec2, 2, 0, EFAULT},
+	/* test5 */
+	{&fd3, wr_iovec2, 1, 0, EBADF},
+	/* test6 */
+	{&fd2, wr_iovec2, 1, 0, EBADF}
 };
 
-void verify_pwritev(struct test_case_t *tc);
-void setup(void);
-void cleanup(void);
+static void verify_pwritev(struct test_case_t *tc);
+static void setup(void);
+static void cleanup(void);
 
 char *TCID = "pwritev02";
 int TST_TOTAL = ARRAY_SIZE(tc);
@@ -86,22 +104,24 @@ int main(int ac, char **av)
 	tst_exit();
 }
 
-void verify_pwritev(struct test_case_t *tc)
+static void verify_pwritev(struct test_case_t *tc)
 {
-	TEST(pwritev(fd, tc->name, tc->count, tc->offset));
+	TEST(pwritev(*tc->fd, tc->name, tc->count, tc->offset));
 	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "pwritev(2) succeed unexpectedly");
+		tst_resm(TFAIL, "pwritev() succeeded unexpectedly");
 	} else {
-		if (TEST_ERRNO == EINVAL) {
-			tst_resm(TPASS | TTERRNO, "pwritev(2) fails as expected");
+		if (TEST_ERRNO == tc->exp_err) {
+			tst_resm(TPASS | TTERRNO,
+				 "pwritev() failed as expected");
 		} else {
-			tst_resm(TFAIL | TTERRNO, "pwritev(2) fails unexpectedly,"
-				 " expected errno is EINVAL");
+			tst_resm(TFAIL | TTERRNO,
+				 "pwritev() failed unexpectedly, expected"
+				 " errno is %s", tst_strerrno(tc->exp_err));
 		}
 	}
 }
 
-void setup(void)
+static void setup(void)
 {
 	if ((tst_kvercmp(2, 6, 30)) < 0) {
 		tst_brkm(TCONF, NULL, "This test can only run on kernels"
@@ -114,12 +134,17 @@ void setup(void)
 
 	tst_tmpdir();
 
-	fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
+	fd1 = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644);
+
+	fd2 = SAFE_OPEN(cleanup, "file", O_RDONLY | O_CREAT, 0644);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
+	if (fd1 > 0 && close(fd1))
+		tst_resm(TWARN | TERRNO, "failed to close file");
+
+	if (fd2 > 0 && close(fd2))
 		tst_resm(TWARN | TERRNO, "failed to close file");
 
 	tst_rmdir();
-- 
1.8.3.1




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2 2/2] pwritev/pwritev02.c: add specific error for pwritev()
  2016-04-01  5:14     ` [LTP] [PATCH v2 2/2] pwritev/pwritev02.c: add specific error for pwritev() Xiao Yang
@ 2016-04-04 16:01       ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2016-04-04 16:01 UTC (permalink / raw)
  To: ltp

Hi!
Both patches pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-04-04 16:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-25  2:08 [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv() Xiao Yang
2016-03-25  2:08 ` [LTP] [PATCH 2/2] pwritev/pwritev02.c: add specific error for pwritev() Xiao Yang
2016-03-31 14:14   ` Cyril Hrubis
2016-03-31 14:13 ` [LTP] [PATCH 1/2] preadv/preadv02.c: add specific error for preadv() Cyril Hrubis
2016-04-01  5:14   ` [LTP] [PATCH v2 " Xiao Yang
2016-04-01  5:14     ` [LTP] [PATCH v2 2/2] pwritev/pwritev02.c: add specific error for pwritev() Xiao Yang
2016-04-04 16:01       ` Cyril Hrubis

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.