syscalls/preadv02.c: add specific error
PATCH 1/3 syscalls/preadv02.c: add specific error
1) preadv(2) fails when fd refers to a directory and set errno to EISDIR.
2) preadv(2) fails if fd is associated with a pipe and set errno to ESPIPE.
--- testcases/kernel/syscalls/preadv/preadv02.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/preadv/preadv02.c +21 -1
@@ -24,6 +24,8 @@* 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. +* 7) preadv(2) fails when fd refers to a directory. +* 8) preadv(2) fails if fd is associated with a pipe. * * Expected Result: * 1) preadv(2) should return -1 and set errno to EINVAL.
@@ -32,6 +34,8 @@* 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. +* 7) preadv(2) should return -1 and set errno to EISDIR. +* 8) preadv(2) should return -1 and set errno to ESPIPE. */ #include <sys/uio.h>
@@ -43,6 +47,9 @@static int fd1;static int fd2;static int fd3 =-1 ; +static int fd4; +static int fd5[2 ]; +static char buf[CHUNK ];static struct iovec rd_iovec1[] = {
@@ -66,7 +73,9 @@ static struct tcase { {&fd1, rd_iovec2, 1, -1, EINVAL}, {&fd1, rd_iovec2, 2, 0, EFAULT}, {&fd3, rd_iovec2, 1, 0, EBADF}, - {&fd2, rd_iovec2, 1, 0, EBADF} + {&fd2, rd_iovec2, 1, 0, EBADF}, + {&fd4, rd_iovec2, 1, 0, EISDIR}, + {&fd5[0], rd_iovec2, 1, 0, ESPIPE} };static void verify_preadv (unsigned int n)
@@ -93,6 +102,8 @@ static void setup(void) { fd1 =SAFE_OPEN ("file1" ,O_RDWR |O_CREAT ,0644 ); fd2 =SAFE_OPEN ("file2" ,O_WRONLY |O_CREAT ,0644 ); + fd4 =SAFE_OPEN ("." ,O_RDONLY ); +SAFE_PIPE (fd5); }static void cleanup (void )
@@ -102,6 +113,15 @@ static void cleanup(void)if (fd2 >0 &&close (fd2))tst_res (TWARN |TERRNO ,"failed to close file" ); + +if (fd4 >0 &&close (fd4)) +tst_res (TWARN |TERRNO ,"failed to close file" ); + +if (fd5[0 ] >0 &&close (fd5[0 ])) +tst_res (TWARN |TERRNO ,"failed to close file" ); + +if (fd5[1 ] >0 &&close (fd5[1 ])) +tst_res (TWARN |TERRNO ,"failed to close file" ); }static struct tst_test test = {
Signature · 1 line
1.8.3.1
PATCH 2/3 syscalls/pwritev01: convert to new test API
--- testcases/kernel/syscalls/pwritev/pwritev.h | 2 +- testcases/kernel/syscalls/pwritev/pwritev01.c | 89 +++++++++------------------ 2 files changed, 31 insertions(+), 60 deletions(-)
testcases/kernel/syscalls/pwritev/pwritev.h +1 -1
@@ -24,7 +24,7 @@#if !defined(HAVE_PWRITEV )int pwritev (int fd,const struct iovec *iov,int iovcnt,off_t offset) { -return ltp_syscall (__NR_pwritev, fd, iov, iovcnt, offset); +return tst_syscall (__NR_pwritev, fd, iov, iovcnt, offset); }#endif
testcases/kernel/syscalls/pwritev/pwritev01.c +30 -59
146 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/3 syscalls/pwritev01: convert to new test API
Hi!
testcases/kernel/syscalls/pwritev/pwritev01.c static struct iovec wr_iovec[] = { · line 64
Quoted 4 lines
testcases/kernel/syscalls/pwritev/pwritev01.c +1
-1TEST (pwritev (fd, wr_iovec, tc->count, tc->offset));if (TEST_RETURN <0 ) { -tst_resm (TFAIL |TTERRNO ,"Pwritev(2) failed" ); +tst_res (TFAIL |TERRNO ,"pwritev() failed" );
^
I've changed this back to TTERRNO since we use the TEST() macro here.
And also merged this patch with the next one to avoid failures when the fallback from pwritev.h is used with the new macro in the old library and pushed. Thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 3/3 syscalls/pwritev02.c: add specific error && convert to new test API
In reply to Xiao Yang1) pwritev(2) fails if fd is associated with a pipe and set errno to ESPIPE.
--- testcases/kernel/syscalls/pwritev/pwritev02.c | 107 ++++++++++---------------- 1 file changed, 41 insertions(+), 66 deletions(-)
testcases/kernel/syscalls/pwritev/pwritev02.c +41 -66
@@ -24,6 +24,7 @@* 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. +* 7) pwritev(2) fails if fd is associated with a pipe. * * Expected Result: * 1) pwritev(2) should return -1 and set errno to EINVAL.
@@ -32,20 +33,20 @@* 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. +* 7) pwritev(2) should return -1 and set errno to ESPIPE. */ -#include <errno.h> #include <sys/uio.h> - -#include "test.h" +#include "tst_test.h" #include "pwritev.h" -#include "safe_macros.h" #define CHUNK 64static int fd1;static int fd2;static int fd3 =-1 ; +static int fd4[2 ]; +static char buf[CHUNK ];static struct iovec wr_iovec1[] = {
@@ -57,95 +58,69 @@ static struct iovec wr_iovec2[] = { {(char *)-1, CHUNK}, }; -static struct test_case_t { +static struct tcase {int *fd;struct iovec *name;int count;off_t offset;int exp_err; -} tc[] = { -/* test1 */ +} tcases[] = { {&fd1, wr_iovec1,1 ,0 ,EINVAL }, -/* test2 */ {&fd1, wr_iovec2,-1 ,0 ,EINVAL }, -/* test3 */ {&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 } + {&fd2, wr_iovec2,1 ,0 ,EBADF }, + {&fd4[1 ], wr_iovec2,1 ,0 ,ESPIPE } }; -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); - -int main (int ac,char **av) +static void verify_pwritev (unsigned int n) { -int lc; -int i; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); +struct tcase *tc = &tcases[n]; -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; -for (i =0 ; i <TST_TOTAL ; i++) -verify_pwritev (&tc[i]); - } - -cleanup (); -tst_exit (); -} - -static void verify_pwritev (struct test_case_t *tc) -{TEST (pwritev (*tc->fd, tc->name, tc->count, tc->offset));if (TEST_RETURN ==0 ) { -tst_resm (TFAIL ,"pwritev() succeeded unexpectedly" ); - }else { -if (TEST_ERRNO == tc->exp_err) { -tst_resm (TPASS |TTERRNO , -"pwritev() failed as expected" ); - }else { -tst_resm (TFAIL |TTERRNO , -"pwritev() failed unexpectedly, expected" -" errno is %s" ,tst_strerrno (tc->exp_err)); - } +tst_res (TFAIL ,"pwritev() succeeded unexpectedly" ); +return ; } -} -static 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." ); +if (TEST_ERRNO == tc->exp_err) { +tst_res (TPASS |TTERRNO ,"pwritev() failed as expected" ); +return ; } -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -tst_tmpdir (); - - fd1 =SAFE_OPEN (cleanup,"file" ,O_RDWR |O_CREAT ,0644 ); +tst_res (TFAIL |TTERRNO ,"pwritev() failed unexpectedly, expected %s" , +tst_strerrno (tc->exp_err)); +} - fd2 =SAFE_OPEN (cleanup,"file" ,O_RDONLY |O_CREAT ,0644 ); +static void setup (void ) +{ + fd1 =SAFE_OPEN ("file" ,O_RDWR |O_CREAT ,0644 ); + fd2 =SAFE_OPEN ("file" ,O_RDONLY |O_CREAT ,0644 ); +SAFE_PIPE (fd4); }static void cleanup (void ) {if (fd1 >0 &&close (fd1)) -tst_resm (TWARN |TERRNO ,"failed to close file" ); +tst_res (TWARN |TERRNO ,"failed to close file" );if (fd2 >0 &&close (fd2)) -tst_resm (TWARN |TERRNO ,"failed to close file" ); +tst_res (TWARN |TERRNO ,"failed to close file" ); + +if (fd4[0 ] >0 &&close (fd4[0 ])) +tst_res (TWARN |TERRNO ,"failed to close file" ); -tst_rmdir (); +if (fd4[1 ] >0 &&close (fd4[1 ])) +tst_res (TWARN |TERRNO ,"failed to close file" ); } + +static struct tst_test test = { + .tid ="pwritev02" , + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_pwritev, + .min_kver ="2.6.30" , + .needs_tmpdir =1 , +};
Signature · 1 line
1.8.3.1