lapi/syscalls: Add syscall numbers for pwritev2()
PATCH 1/3 lapi/syscalls: Add syscall numbers for pwritev2()
--- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 13 files changed, 13 insertions(+)
include/lapi/syscalls/aarch64.in +1 -0
@@ -263,4 +263,5 @@ execveat 281 mlock2 284 copy_file_range 285 preadv2 286 +pwritev2 287 _sysctl 1078
include/lapi/syscalls/arm.in +1 -0
@@ -347,4 +347,5 @@ membarrier (__NR_SYSCALL_BASE+389) mlock2 (__NR_SYSCALL_BASE+390) copy_file_range (__NR_SYSCALL_BASE+391) preadv2 (__NR_SYSCALL_BASE+392) +pwritev2 (__NR_SYSCALL_BASE+393) statx (__NR_SYSCALL_BASE+397)
include/lapi/syscalls/hppa.in +1 -0
@@ -24,3 +24,4 @@ execveat 342 mlock2 345 copy_file_range 346 preadv2 347 +pwritev2 348
include/lapi/syscalls/i386.in +1 -0
@@ -345,4 +345,5 @@ membarrier 375 mlock2 376 copy_file_range 377 preadv2 378 +pwritev2 379 statx 383
include/lapi/syscalls/ia64.in +1 -0
@@ -303,3 +303,4 @@ execveat 1342 mlock2 1346 copy_file_range 1347 preadv2 1348 +pwritev2 1349
include/lapi/syscalls/powerpc.in +1 -0
@@ -352,4 +352,5 @@ execveat 362 mlock2 378 copy_file_range 379 preadv2 380 +pwritev2 381 statx 383
include/lapi/syscalls/powerpc64.in +1 -0
@@ -352,4 +352,5 @@ execveat 362 mlock2 378 copy_file_range 379 preadv2 380 +pwritev2 381 statx 383
include/lapi/syscalls/s390.in +1 -0
@@ -336,3 +336,4 @@ execveat 354 mlock2 374 copy_file_range 375 preadv2 376 +pwritev2 377
include/lapi/syscalls/s390x.in +1 -0
@@ -335,3 +335,4 @@ execveat 354 mlock2 374 copy_file_range 375 preadv2 376 +pwritev2 377
include/lapi/syscalls/sh.in +1 -0
@@ -368,3 +368,4 @@ execveat 387 mlock2 390 copy_file_range 391 preadv2 392 +pwritev2 393
include/lapi/syscalls/sparc.in +1 -0
@@ -341,3 +341,4 @@ execveat 350 mlock2 356 copy_file_range 357 preadv2 358 +pwritev2 359
include/lapi/syscalls/sparc64.in +1 -0
@@ -317,3 +317,4 @@ execveat 350 mlock2 356 copy_file_range 357 preadv2 358 +pwritev2 359
include/lapi/syscalls/x86_64.in +1 -0
@@ -312,4 +312,5 @@ membarrier 324 mlock2 325 copy_file_range 326 preadv2 327 +pwritev2 328 statx 332
Signature · 1 line
1.8.3.1
PATCH 2/3 syscalls/pwritev201: Add new testcase
Check the basic functionality of the pwritev2().
--- configure.ac | 1 + include/lapi/pwritev2.h | 26 +++++ m4/ltp-pwritev2.m4 | 9 ++ runtest/syscalls | 3 + testcases/kernel/syscalls/pwritev2/.gitignore | 2 + testcases/kernel/syscalls/pwritev2/Makefile | 13 +++ testcases/kernel/syscalls/pwritev2/pwritev201.c | 120 ++++++++++++++++++++++++ 7 files changed, 174 insertions(+) create mode 100644 include/lapi/pwritev2.h create mode 100644 m4/ltp-pwritev2.m4 create mode 100644 testcases/kernel/syscalls/pwritev2/.gitignore create mode 100644 testcases/kernel/syscalls/pwritev2/Makefile create mode 100644 testcases/kernel/syscalls/pwritev2/pwritev201.c
configure.ac +1 -0
@@ -219,6 +219,7 @@ LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV LTP_CHECK_PWRITEV LTP_CHECK_PREADV2 +LTP_CHECK_PWRITEV2 LTP_CHECK_EPOLL_PWAIT LTP_CHECK_KEYUTILS_SUPPORT LTP_CHECK_SYNC_ADD_AND_FETCH
include/lapi/pwritev2.h new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Jinhui Huang <[email protected]> +*/ + +#ifndef PWRITEV2_H +#define PWRITEV2_H + +#include "config.h" +#include "lapi/syscalls.h" + +#if !defined(HAVE_PWRITEV2 ) + +/* LO_HI_LONG taken from glibc */ +# define LO_HI_LONG (val) (long) (val), (long) (((uint64_t) (val)) >> 32) + +ssize_t pwritev2 (int fd,const struct iovec *iov,int iovcnt,off_t offset, +int flags) +{ +return tst_syscall (__NR_pwritev2, fd, iov, iovcnt, +LO_HI_LONG (offset), flags); +} +#endif + +#endif /* PWRITEV2_H */
m4/ltp-pwritev2.m4 new file +9 -0
@@ -0,0 +1,9 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +dnl Author: Jinhui Huang <[email protected]> + +dnl LTP_CHECK_PWRITEV2 +dnl ---------------------------- +AC_DEFUN([LTP_CHECK_PWRITEV2],[ +AC_CHECK_FUNCS(pwritev2,,) +])
runtest/syscalls +3 -0
@@ -907,6 +907,9 @@ pwritev02_64 pwritev02_64 pwritev03 pwritev03 pwritev03_64 pwritev03_64 +pwritev201 pwritev201 +pwritev201_64 pwritev201_64 + quotactl01 quotactl01 quotactl02 quotactl02 quotactl03 quotactl03
testcases/kernel/syscalls/pwritev2/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/pwritev201 +/pwritev201_64
testcases/kernel/syscalls/pwritev2/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Jinhui Huang <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(abs_srcdir)/../utils/newer_64.mk + +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/3 syscalls/pwritev201: Add new testcase
Hi Jinhui,
Quoted 143 lines · Jinhui huang
Check the basic functionality of the
pwritev2().Signed-off-by Jinhui huang <[email protected]>--- configure.ac | 1 + include/lapi/pwritev2.h | 26 +++++ m4/ltp-pwritev2.m4 | 9 ++ runtest/syscalls | 3 + testcases/kernel/syscalls/pwritev2/.gitignore | 2 + testcases/kernel/syscalls/pwritev2/Makefile | 13 +++ testcases/kernel/syscalls/pwritev2/pwritev201.c | 120 ++++++++++++++++++++++++ 7 files changed, 174 insertions(+) create mode 100644 include/lapi/pwritev2.h create mode 100644 m4/ltp-pwritev2.m4 create mode 100644 testcases/kernel/syscalls/pwritev2/.gitignore create mode 100644 testcases/kernel/syscalls/pwritev2/Makefile create mode 100644 testcases/kernel/syscalls/pwritev2/pwritev201.cconfigure.ac +1
-0@@ -219,6 +219,7 @@ LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV LTP_CHECK_PWRITEV LTP_CHECK_PREADV2 +LTP_CHECK_PWRITEV2 LTP_CHECK_EPOLL_PWAIT LTP_CHECK_KEYUTILS_SUPPORT LTP_CHECK_SYNC_ADD_AND_FETCHinclude/lapi/pwritev2.h new file +26
-0@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Jinhui Huang <[email protected]> +*/ + +#ifndef PWRITEV2_H +#define PWRITEV2_H + +#include "config.h" +#include "lapi/syscalls.h" + +#if !defined(HAVE_PWRITEV2 ) + +/* LO_HI_LONG taken from glibc */ +# define LO_HI_LONG (val) (long) (val), (long) (((uint64_t) (val)) >> 32) + +ssize_t pwritev2 (int fd,const struct iovec *iov,int iovcnt,off_t offset, +int flags) +{ +return tst_syscall (__NR_pwritev2, fd, iov, iovcnt, +LO_HI_LONG (offset), flags); +} +#endif + +#endif /* PWRITEV2_H */ m4/ltp-pwritev2.m4 new file +9
-0@@ -0,0 +1,9 @@ +dnl SPDX-License-Identifier: GPL-2.0-or-later +dnl Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +dnl Author: Jinhui Huang <[email protected]> + +dnl LTP_CHECK_PWRITEV2 +dnl ---------------------------- +AC_DEFUN([LTP_CHECK_PWRITEV2],[ +AC_CHECK_FUNCS(pwritev2,,) +])runtest/syscalls +3
-0@@ -907,6 +907,9 @@ pwritev02_64 pwritev02_64 pwritev03 pwritev03 pwritev03_64 pwritev03_64 +pwritev201 pwritev201 +pwritev201_64 pwritev201_64 + quotactl01 quotactl01 quotactl02 quotactl02 quotactl03 quotactl03testcases/kernel/syscalls/pwritev2/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +/pwritev201 +/pwritev201_64testcases/kernel/syscalls/pwritev2/Makefile new file +13
-0@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Jinhui Huang <[email protected]> + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(abs_srcdir)/../utils/newer_64.mk + +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/syscalls/pwritev2/pwritev201.c new file +19
-0@@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Jinhui Huang <[email protected]> +*/ +/* +* Description: +* Testcase to check the basic functionality of the pwritev2(2). +* 1) If the file offset argument is not -1, pwritev2() should succeed +* in writing the expected content of data and the file offset is +* not changed after writing. +* 2) If the file offset argument is -1, pwritev2() should succeed in +* writing the expected content of data and the current file offset +* is used and changed after writing. +*/ + +#define _GNU_SOURCE +#include <string.h> +#include <sys/uio.h>
testcases/kernel/syscalls/pwritev2/pwritev201.c line 29
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +10
-0+ +#include "tst_test.h" +#include "lapi/pwritev2.h" +#include "tst_safe_prw.h" + +#define CHUNK 64 + +static int fd; +static char initbuf[CHUNK *2 ]; +static char preadbuf[CHUNK ];
It is enough to declare preadbuf[CHUNK] as local variable.
Quoted 17 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +17
-0+static char buf[CHUNK ]; + +static struct iovec wr_iovec[] = { + {buf,CHUNK }, + {NULL ,0 }, +}; + +static struct tcase { +off_t seek_off; +int count; +off_t write_off; +ssize_t size; +off_t exp_off; +} tcases[] = { + {0 ,1 ,0 ,CHUNK ,0 }, + {CHUNK ,2 ,0 ,CHUNK ,CHUNK }, + {0 ,1 ,CHUNK *3 /2 ,CHUNK ,0 },
testcases/kernel/syscalls/pwritev2/pwritev201.c line 56
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +10
-0+ {0, 1, -1, CHUNK, CHUNK}, + {0, 2, -1, CHUNK, CHUNK}, + {CHUNK, 1, -1, CHUNK, CHUNK * 2}, +}; + +static void verify_pwritev2 (unsigned int n) +{ +int i; +struct tcase *tc = &tcases[n]; +off_t read_off =0 ;
Perhaps, we should initialize preadbuf before running each test.
testcases/kernel/syscalls/pwritev2/pwritev201.c line 66
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +10
-0+ +SAFE_PWRITE (1 , fd, initbuf,sizeof (initbuf),0 ); + +SAFE_LSEEK (fd, tc->seek_off,SEEK_SET ); + +TEST (pwritev2 (fd, wr_iovec, tc->count, tc->write_off,0 )); +if (TST_RET <0 ) { +tst_res (TFAIL |TTERRNO ,"pwritev() failed" ); +return ; + }
Typo? pwritev2() is correct.
Quoted 7 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +7
-0+ +if (TST_RET != tc->size) { +tst_res (TFAIL ,"pwritev2() wrote %li bytes, expected %zi" , +TST_RET , tc->size); +return ; + } +
testcases/kernel/syscalls/pwritev2/pwritev201.c line 83
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +10
-0+if (SAFE_LSEEK (fd,0 ,SEEK_CUR ) != tc->exp_off) { +tst_res (TFAIL ,"pwritev2() had changed file offset" ); +return ; + } +if (tc->write_off !=-1 ) + read_off = tc->write_off; +else + read_off = tc->seek_off; + +SAFE_PREAD (1 , fd, preadbuf, tc->size, read_off);
How about calling SAFE_PREAD() directly? as below:
-------------------------------------------------------
if (tc->write_off != -1)SAFE_PREAD(1, fd, preadbuf, tc->size, write_off); elseSAFE_PREAD(1, fd, preadbuf, tc->size, seek_off);
-------------------------------------------------------
Best Regards,
Xiao Yang
Quoted 37 lines
testcases/kernel/syscalls/pwritev2/pwritev201.c new file +37
-0+ +for (i =0 ; i < tc->size; i++) { +if (preadbuf[i] !=0x61 ) +break ; + } + +if (i != tc->size) { +tst_res (TFAIL ,"buffer wrong at %i have %02x expected 61" , + i, preadbuf[i]); +return ; + } + +tst_res (TPASS ,"pwritev2() wrote %zi bytes successfully " +"with content 'a' expectedly " , tc->size); +} + +static void setup (void ) +{ +memset (buf,0x61 ,CHUNK ); +memset (initbuf,0 ,CHUNK *2 ); + + fd =SAFE_OPEN ("file" ,O_RDWR |O_CREAT ,0644 ); +} + +static void cleanup (void ) +{ +if (fd >0 ) +SAFE_CLOSE (fd); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_pwritev2, + .needs_tmpdir =1 , +};
PATCH 3/3 syscalls/pwitev202: Add new testcase
In reply to Jinhui huangCheck various errnos for the pwitev202().
--- runtest/syscalls | 2 + testcases/kernel/syscalls/pwritev2/.gitignore | 2 + testcases/kernel/syscalls/pwritev2/pwritev202.c | 117 ++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 testcases/kernel/syscalls/pwritev2/pwritev202.c
runtest/syscalls +2 -0
@@ -909,6 +909,8 @@ pwritev03_64 pwritev03_64 pwritev201 pwritev201 pwritev201_64 pwritev201_64 +pwritev202 pwritev202 +pwritev202_64 pwritev202_64 quotactl01 quotactl01 quotactl02 quotactl02
testcases/kernel/syscalls/pwritev2/.gitignore +2 -0
@@ -1,2 +1,4 @@ /pwritev201 /pwritev201_64 +/pwritev202 +/pwritev202_64
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +117 -0
117 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 3/3 syscalls/pwitev202: Add new testcase
Hi Jinhui,
Quoted 1 line · Jinhui huang
Check various errnos for the
pwitev202().
Typo? pwitev2() seems proper.
Quoted 40 lines
Signed-off-by Jinhui huang <[email protected]>--- runtest/syscalls | 2 + testcases/kernel/syscalls/pwritev2/.gitignore | 2 + testcases/kernel/syscalls/pwritev2/pwritev202.c | 117 ++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 testcases/kernel/syscalls/pwritev2/pwritev202.cruntest/syscalls +2
-0@@ -909,6 +909,8 @@ pwritev03_64 pwritev03_64 pwritev201 pwritev201 pwritev201_64 pwritev201_64 +pwritev202 pwritev202 +pwritev202_64 pwritev202_64 quotactl01 quotactl01 quotactl02 quotactl02testcases/kernel/syscalls/pwritev2/.gitignore +2
-0@@ -1,2 +1,4 @@ /pwritev201 /pwritev201_64 +/pwritev202 +/pwritev202_64testcases/kernel/syscalls/pwritev2/pwritev202.c new file +4
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Jinhui Huang <[email protected]>
testcases/kernel/syscalls/pwritev2/pwritev202.c line 14
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +10
-0+*/ +/* +* Description: +* Check various errnos for pwritev2(2). +* 1) pwritev2() fails and sets errno to EINVAL if iov_len is invalid. +* 2) pwritev2() fails and sets errno to EINVAL if the vector count iovcnt is +* less than zero. +* 3) pwritev2() fails and sets errno to EOPNOTSUPP if flag is invalid. +* 4) pwritev2() fails and sets errno to EFAULT when attempts to read into a +* invalid address.
Typo? Invalid address is actually used to test write instead of read.
testcases/kernel/syscalls/pwritev2/pwritev202.c line 17
Quoted 3 lines
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +3
-0+* 5) pwritev2() fails and sets errno to EBADF if file descriptor is invalid. +* 6) pwritev2() fails and sets errno to EBADF if file descriptor is not open +* for reading.
Typo? fd2 is actually opened with O_RDONLY.
Best Regards,
Xiao Yang
Quoted 100 lines
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +100
-0+* 7) pwritev2() fails and sets errno to ESPIPE if fd is associated with a pipe. +*/ + +#define _GNU_SOURCE +#include <sys/uio.h> +#include <unistd.h> + +#include "tst_test.h" +#include "lapi/pwritev2.h" + +#define CHUNK 64 + +static int fd1; +static int fd2; +static int fd3 =-1 ; +static int fd4[2 ]; + +static char buf[CHUNK ]; + +static struct iovec wr_iovec1[] = { + {buf,-1 }, +}; + +static struct iovec wr_iovec2[] = { + {buf,CHUNK }, +}; + +static struct iovec wr_iovec3[] = { + {NULL ,CHUNK }, +}; + +static struct tcase { +int *fd; +struct iovec *name; +int count; +off_t offset; +int flag; +int exp_err; +} tcases[] = { + {&fd1, wr_iovec1,1 ,0 ,0 ,EINVAL }, + {&fd1, wr_iovec2,-1 ,0 ,0 ,EINVAL }, + {&fd1, wr_iovec2,1 ,1 ,-1 ,EOPNOTSUPP }, + {&fd1, wr_iovec3,1 ,0 ,0 ,EFAULT }, + {&fd3, wr_iovec2,1 ,0 ,0 ,EBADF }, + {&fd2, wr_iovec2,1 ,0 ,0 ,EBADF }, + {&fd4[0 ], wr_iovec2,1 ,0 ,0 ,ESPIPE }, +}; + +static void verify_pwritev2 (unsigned int n) +{ +struct tcase *tc = &tcases[n]; + +TEST (pwritev2 (*tc->fd, tc->name, tc->count, tc->offset, tc->flag)); + +if (TST_RET ==0 ) { +tst_res (TFAIL ,"pwritev2() succeeded unexpectedly" ); +return ; + } + +if (TST_ERR == tc->exp_err) { +tst_res (TPASS |TTERRNO ,"pwritev2() failed as expected" ); +return ; + } + +tst_res (TFAIL |TTERRNO ,"pwritev2() failed unexpectedly, expected %s" , +tst_strerrno (tc->exp_err)); +} + +static void setup (void ) +{ + fd1 =SAFE_OPEN ("file1" ,O_RDWR |O_CREAT ,0644 ); +SAFE_FTRUNCATE (fd1,getpagesize ()); + fd2 =SAFE_OPEN ("file2" ,O_RDONLY |O_CREAT ,0644 ); +SAFE_PIPE (fd4); + + wr_iovec3[0 ].iov_base =tst_get_bad_addr (NULL ); +} + +static void cleanup (void ) +{ +if (fd1 >0 ) +SAFE_CLOSE (fd1); + +if (fd2 >0 ) +SAFE_CLOSE (fd2); + +if (fd4[0 ] >0 ) +SAFE_CLOSE (fd4[0 ]); + +if (fd4[1 ] >0 ) +SAFE_CLOSE (fd4[1 ]); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_pwritev2, + .needs_tmpdir =1 , +};
PATCH 3/3 syscalls/pwitev202: Add new testcase
Hi Xiao,
Thanks for your suggestion, I will update the patchset.
Thanks,
Jinhui Huang
Quoted 167 lines · Xiao Yang
Hi Jinhui,
Quoted 1 line · Jinhui huang
Check various errnos for the
pwitev202().Typo?
pwitev2()seems proper.Quoted 40 lines
Signed-off-by Jinhui huang <[email protected]>--- runtest/syscalls | 2 + testcases/kernel/syscalls/pwritev2/.gitignore | 2 + testcases/kernel/syscalls/pwritev2/pwritev202.c | 117 ++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 testcases/kernel/syscalls/pwritev2/pwritev202.cruntest/syscalls +2
-0@@ -909,6 +909,8 @@ pwritev03_64 pwritev03_64 pwritev201 pwritev201 pwritev201_64 pwritev201_64 +pwritev202 pwritev202 +pwritev202_64 pwritev202_64 quotactl01 quotactl01 quotactl02 quotactl02testcases/kernel/syscalls/pwritev2/.gitignore +2
-0@@ -1,2 +1,4 @@ /pwritev201 /pwritev201_64 +/pwritev202 +/pwritev202_64testcases/kernel/syscalls/pwritev2/pwritev202.c new file +4
-0@@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +* Author: Jinhui Huang <[email protected]> testcases/kernel/syscalls/pwritev2/pwritev202.c line 14
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +10
-0+*/ +/* +* Description: +* Check various errnos for pwritev2(2). +* 1) pwritev2() fails and sets errno to EINVAL if iov_len is invalid. +* 2) pwritev2() fails and sets errno to EINVAL if the vector count iovcnt is +* less than zero. +* 3) pwritev2() fails and sets errno to EOPNOTSUPP if flag is invalid. +* 4) pwritev2() fails and sets errno to EFAULT when attempts to read into a +* invalid address. Typo? Invalid address is actually used to test write instead of read.
testcases/kernel/syscalls/pwritev2/pwritev202.c line 17
Quoted 3 lines
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +3
-0+* 5) pwritev2() fails and sets errno to EBADF if file descriptor is invalid. +* 6) pwritev2() fails and sets errno to EBADF if file descriptor is not open +* for reading. Typo? fd2 is actually opened with
O_RDONLY.Best Regards,
Xiao YangQuoted 90 lines
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +90
-0+* 7) pwritev2() fails and sets errno to ESPIPE if fd is associated with a pipe. +*/ + +#define _GNU_SOURCE +#include <sys/uio.h> +#include <unistd.h> + +#include "tst_test.h" +#include "lapi/pwritev2.h" + +#define CHUNK 64 + +static int fd1; +static int fd2; +static int fd3 =-1 ; +static int fd4[2 ]; + +static char buf[CHUNK ]; + +static struct iovec wr_iovec1[] = { + {buf,-1 }, +}; + +static struct iovec wr_iovec2[] = { + {buf,CHUNK }, +}; + +static struct iovec wr_iovec3[] = { + {NULL ,CHUNK }, +}; + +static struct tcase { +int *fd; +struct iovec *name; +int count; +off_t offset; +int flag; +int exp_err; +} tcases[] = { + {&fd1, wr_iovec1,1 ,0 ,0 ,EINVAL }, + {&fd1, wr_iovec2,-1 ,0 ,0 ,EINVAL }, + {&fd1, wr_iovec2,1 ,1 ,-1 ,EOPNOTSUPP }, + {&fd1, wr_iovec3,1 ,0 ,0 ,EFAULT }, + {&fd3, wr_iovec2,1 ,0 ,0 ,EBADF }, + {&fd2, wr_iovec2,1 ,0 ,0 ,EBADF }, + {&fd4[0 ], wr_iovec2,1 ,0 ,0 ,ESPIPE }, +}; + +static void verify_pwritev2 (unsigned int n) +{ +struct tcase *tc = &tcases[n]; + +TEST (pwritev2 (*tc->fd, tc->name, tc->count, tc->offset, tc->flag)); + +if (TST_RET ==0 ) { +tst_res (TFAIL ,"pwritev2() succeeded unexpectedly" ); +return ; + } + +if (TST_ERR == tc->exp_err) { +tst_res (TPASS |TTERRNO ,"pwritev2() failed as expected" ); +return ; + } + +tst_res (TFAIL |TTERRNO ,"pwritev2() failed unexpectedly, expected %s" , +tst_strerrno (tc->exp_err)); +} + +static void setup (void ) +{ + fd1 =SAFE_OPEN ("file1" ,O_RDWR |O_CREAT ,0644 ); +SAFE_FTRUNCATE (fd1,getpagesize ()); + fd2 =SAFE_OPEN ("file2" ,O_RDONLY |O_CREAT ,0644 ); +SAFE_PIPE (fd4); + + wr_iovec3[0 ].iov_base =tst_get_bad_addr (NULL ); +} + +static void cleanup (void ) +{ +if (fd1 >0 ) +SAFE_CLOSE (fd1); + +if (fd2 >0 ) +SAFE_CLOSE (fd2); + +if (fd4[0 ] >0 ) +SAFE_CLOSE (fd4[0 ]); + +if (fd4[1 ] >0 )testcases/kernel/syscalls/pwritev2/pwritev202.c line 117
Quoted 10 lines
testcases/kernel/syscalls/pwritev2/pwritev202.c new file +10
-0+SAFE_CLOSE (fd4[1 ]); +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .setup = setup, + .cleanup = cleanup, + .test = verify_pwritev2, + .needs_tmpdir =1 , +};.