* [LTP] [PATCH 1/3] lapi/syscalls: Add syscall numbers for pwritev2() @ 2019-02-15 8:11 Jinhui huang 2019-02-15 8:11 ` [LTP] [PATCH 2/3] syscalls/pwritev201: Add new testcase Jinhui huang 2019-02-15 8:11 ` [LTP] [PATCH 3/3] syscalls/pwitev202: " Jinhui huang 0 siblings, 2 replies; 6+ messages in thread From: Jinhui huang @ 2019-02-15 8:11 UTC (permalink / raw) To: ltp Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com> --- 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(+) diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in index bf04895..7ce1485 100644 --- a/include/lapi/syscalls/aarch64.in +++ b/include/lapi/syscalls/aarch64.in @@ -263,4 +263,5 @@ execveat 281 mlock2 284 copy_file_range 285 preadv2 286 +pwritev2 287 _sysctl 1078 diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in index e720b08..22c76d4 100644 --- a/include/lapi/syscalls/arm.in +++ b/include/lapi/syscalls/arm.in @@ -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) diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in index 182d393..a0dd230 100644 --- a/include/lapi/syscalls/hppa.in +++ b/include/lapi/syscalls/hppa.in @@ -24,3 +24,4 @@ execveat 342 mlock2 345 copy_file_range 346 preadv2 347 +pwritev2 348 diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in index 2fb0188..7e485ae 100644 --- a/include/lapi/syscalls/i386.in +++ b/include/lapi/syscalls/i386.in @@ -345,4 +345,5 @@ membarrier 375 mlock2 376 copy_file_range 377 preadv2 378 +pwritev2 379 statx 383 diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in index 081c9ed..7c9a0ea 100644 --- a/include/lapi/syscalls/ia64.in +++ b/include/lapi/syscalls/ia64.in @@ -303,3 +303,4 @@ execveat 1342 mlock2 1346 copy_file_range 1347 preadv2 1348 +pwritev2 1349 diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in index d16f9f9..fc1f899 100644 --- a/include/lapi/syscalls/powerpc.in +++ b/include/lapi/syscalls/powerpc.in @@ -352,4 +352,5 @@ execveat 362 mlock2 378 copy_file_range 379 preadv2 380 +pwritev2 381 statx 383 diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in index d16f9f9..fc1f899 100644 --- a/include/lapi/syscalls/powerpc64.in +++ b/include/lapi/syscalls/powerpc64.in @@ -352,4 +352,5 @@ execveat 362 mlock2 378 copy_file_range 379 preadv2 380 +pwritev2 381 statx 383 diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in index 4019438..6d0c895 100644 --- a/include/lapi/syscalls/s390.in +++ b/include/lapi/syscalls/s390.in @@ -336,3 +336,4 @@ execveat 354 mlock2 374 copy_file_range 375 preadv2 376 +pwritev2 377 diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in index e156b09..8105b55 100644 --- a/include/lapi/syscalls/s390x.in +++ b/include/lapi/syscalls/s390x.in @@ -335,3 +335,4 @@ execveat 354 mlock2 374 copy_file_range 375 preadv2 376 +pwritev2 377 diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in index 8520bb1..a942fb5 100644 --- a/include/lapi/syscalls/sh.in +++ b/include/lapi/syscalls/sh.in @@ -368,3 +368,4 @@ execveat 387 mlock2 390 copy_file_range 391 preadv2 392 +pwritev2 393 diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in index b7bb135..20a21a9 100644 --- a/include/lapi/syscalls/sparc.in +++ b/include/lapi/syscalls/sparc.in @@ -341,3 +341,4 @@ execveat 350 mlock2 356 copy_file_range 357 preadv2 358 +pwritev2 359 diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in index a211df8..36ab394 100644 --- a/include/lapi/syscalls/sparc64.in +++ b/include/lapi/syscalls/sparc64.in @@ -317,3 +317,4 @@ execveat 350 mlock2 356 copy_file_range 357 preadv2 358 +pwritev2 359 diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in index dae5769..6aa9d12 100644 --- a/include/lapi/syscalls/x86_64.in +++ b/include/lapi/syscalls/x86_64.in @@ -312,4 +312,5 @@ membarrier 324 mlock2 325 copy_file_range 326 preadv2 327 +pwritev2 328 statx 332 -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/3] syscalls/pwritev201: Add new testcase 2019-02-15 8:11 [LTP] [PATCH 1/3] lapi/syscalls: Add syscall numbers for pwritev2() Jinhui huang @ 2019-02-15 8:11 ` Jinhui huang 2019-02-28 7:22 ` Xiao Yang 2019-02-15 8:11 ` [LTP] [PATCH 3/3] syscalls/pwitev202: " Jinhui huang 1 sibling, 1 reply; 6+ messages in thread From: Jinhui huang @ 2019-02-15 8:11 UTC (permalink / raw) To: ltp Check the basic functionality of the pwritev2(). Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com> --- 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 diff --git a/configure.ac b/configure.ac index caea344..c5f3d4e 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/include/lapi/pwritev2.h b/include/lapi/pwritev2.h new file mode 100644 index 0000000..305e48e --- /dev/null +++ b/include/lapi/pwritev2.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> + */ + +#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 */ diff --git a/m4/ltp-pwritev2.m4 b/m4/ltp-pwritev2.m4 new file mode 100644 index 0000000..38148ac --- /dev/null +++ b/m4/ltp-pwritev2.m4 @@ -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 <huangjh.jy@cn.fujitsu.com> + +dnl LTP_CHECK_PWRITEV2 +dnl ---------------------------- +AC_DEFUN([LTP_CHECK_PWRITEV2],[ +AC_CHECK_FUNCS(pwritev2,,) +]) diff --git a/runtest/syscalls b/runtest/syscalls index 668c87c..04f5269 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -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 diff --git a/testcases/kernel/syscalls/pwritev2/.gitignore b/testcases/kernel/syscalls/pwritev2/.gitignore new file mode 100644 index 0000000..46270c3 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev2/.gitignore @@ -0,0 +1,2 @@ +/pwritev201 +/pwritev201_64 diff --git a/testcases/kernel/syscalls/pwritev2/Makefile b/testcases/kernel/syscalls/pwritev2/Makefile new file mode 100644 index 0000000..89756d0 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev2/Makefile @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. +# Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> + +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 diff --git a/testcases/kernel/syscalls/pwritev2/pwritev201.c b/testcases/kernel/syscalls/pwritev2/pwritev201.c new file mode 100644 index 0000000..34067c1 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev2/pwritev201.c @@ -0,0 +1,120 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> + */ +/* + * 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> + +#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]; +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}, + {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; + + 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; + } + + if (TST_RET != tc->size) { + tst_res(TFAIL, "pwritev2() wrote %li bytes, expected %zi", + TST_RET, tc->size); + return; + } + + 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); + + 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, +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/3] syscalls/pwritev201: Add new testcase 2019-02-15 8:11 ` [LTP] [PATCH 2/3] syscalls/pwritev201: Add new testcase Jinhui huang @ 2019-02-28 7:22 ` Xiao Yang 0 siblings, 0 replies; 6+ messages in thread From: Xiao Yang @ 2019-02-28 7:22 UTC (permalink / raw) To: ltp Hi Jinhui, On 2019/02/15 16:11, Jinhui huang wrote: > Check the basic functionality of the pwritev2(). > > Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com> > --- > 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 > > diff --git a/configure.ac b/configure.ac > index caea344..c5f3d4e 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -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 > diff --git a/include/lapi/pwritev2.h b/include/lapi/pwritev2.h > new file mode 100644 > index 0000000..305e48e > --- /dev/null > +++ b/include/lapi/pwritev2.h > @@ -0,0 +1,26 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > + * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> > + */ > + > +#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 */ > diff --git a/m4/ltp-pwritev2.m4 b/m4/ltp-pwritev2.m4 > new file mode 100644 > index 0000000..38148ac > --- /dev/null > +++ b/m4/ltp-pwritev2.m4 > @@ -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 <huangjh.jy@cn.fujitsu.com> > + > +dnl LTP_CHECK_PWRITEV2 > +dnl ---------------------------- > +AC_DEFUN([LTP_CHECK_PWRITEV2],[ > +AC_CHECK_FUNCS(pwritev2,,) > +]) > diff --git a/runtest/syscalls b/runtest/syscalls > index 668c87c..04f5269 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -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 > diff --git a/testcases/kernel/syscalls/pwritev2/.gitignore b/testcases/kernel/syscalls/pwritev2/.gitignore > new file mode 100644 > index 0000000..46270c3 > --- /dev/null > +++ b/testcases/kernel/syscalls/pwritev2/.gitignore > @@ -0,0 +1,2 @@ > +/pwritev201 > +/pwritev201_64 > diff --git a/testcases/kernel/syscalls/pwritev2/Makefile b/testcases/kernel/syscalls/pwritev2/Makefile > new file mode 100644 > index 0000000..89756d0 > --- /dev/null > +++ b/testcases/kernel/syscalls/pwritev2/Makefile > @@ -0,0 +1,13 @@ > +# SPDX-License-Identifier: GPL-2.0-or-later > +# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > +# Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> > + > +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 > diff --git a/testcases/kernel/syscalls/pwritev2/pwritev201.c b/testcases/kernel/syscalls/pwritev2/pwritev201.c > new file mode 100644 > index 0000000..34067c1 > --- /dev/null > +++ b/testcases/kernel/syscalls/pwritev2/pwritev201.c > @@ -0,0 +1,120 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > + * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> > + */ > +/* > + * 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> > + > +#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. > +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}, > + {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. > + > + 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. > + > + if (TST_RET != tc->size) { > + tst_res(TFAIL, "pwritev2() wrote %li bytes, expected %zi", > + TST_RET, tc->size); > + return; > + } > + > + 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); else SAFE_PREAD(1, fd, preadbuf, tc->size, seek_off); ------------------------------------------------------- Best Regards, Xiao Yang > + > + 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, > +}; ^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 3/3] syscalls/pwitev202: Add new testcase 2019-02-15 8:11 [LTP] [PATCH 1/3] lapi/syscalls: Add syscall numbers for pwritev2() Jinhui huang 2019-02-15 8:11 ` [LTP] [PATCH 2/3] syscalls/pwritev201: Add new testcase Jinhui huang @ 2019-02-15 8:11 ` Jinhui huang 2019-02-28 7:22 ` Xiao Yang 1 sibling, 1 reply; 6+ messages in thread From: Jinhui huang @ 2019-02-15 8:11 UTC (permalink / raw) To: ltp Check various errnos for the pwitev202(). Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com> --- 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 diff --git a/runtest/syscalls b/runtest/syscalls index 04f5269..27cc1dc 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -909,6 +909,8 @@ pwritev03_64 pwritev03_64 pwritev201 pwritev201 pwritev201_64 pwritev201_64 +pwritev202 pwritev202 +pwritev202_64 pwritev202_64 quotactl01 quotactl01 quotactl02 quotactl02 diff --git a/testcases/kernel/syscalls/pwritev2/.gitignore b/testcases/kernel/syscalls/pwritev2/.gitignore index 46270c3..40030d9 100644 --- a/testcases/kernel/syscalls/pwritev2/.gitignore +++ b/testcases/kernel/syscalls/pwritev2/.gitignore @@ -1,2 +1,4 @@ /pwritev201 /pwritev201_64 +/pwritev202 +/pwritev202_64 diff --git a/testcases/kernel/syscalls/pwritev2/pwritev202.c b/testcases/kernel/syscalls/pwritev2/pwritev202.c new file mode 100644 index 0000000..d0f8868 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev2/pwritev202.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. + * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> + */ +/* + * 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. + * 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. + * 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, +}; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 3/3] syscalls/pwitev202: Add new testcase 2019-02-15 8:11 ` [LTP] [PATCH 3/3] syscalls/pwitev202: " Jinhui huang @ 2019-02-28 7:22 ` Xiao Yang 2019-03-01 7:13 ` jinhui huang 0 siblings, 1 reply; 6+ messages in thread From: Xiao Yang @ 2019-02-28 7:22 UTC (permalink / raw) To: ltp Hi Jinhui, On 2019/02/15 16:11, Jinhui huang wrote: > Check various errnos for the pwitev202(). Typo? pwitev2() seems proper. > Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com> > --- > 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 > > diff --git a/runtest/syscalls b/runtest/syscalls > index 04f5269..27cc1dc 100644 > --- a/runtest/syscalls > +++ b/runtest/syscalls > @@ -909,6 +909,8 @@ pwritev03_64 pwritev03_64 > > pwritev201 pwritev201 > pwritev201_64 pwritev201_64 > +pwritev202 pwritev202 > +pwritev202_64 pwritev202_64 > > quotactl01 quotactl01 > quotactl02 quotactl02 > diff --git a/testcases/kernel/syscalls/pwritev2/.gitignore b/testcases/kernel/syscalls/pwritev2/.gitignore > index 46270c3..40030d9 100644 > --- a/testcases/kernel/syscalls/pwritev2/.gitignore > +++ b/testcases/kernel/syscalls/pwritev2/.gitignore > @@ -1,2 +1,4 @@ > /pwritev201 > /pwritev201_64 > +/pwritev202 > +/pwritev202_64 > diff --git a/testcases/kernel/syscalls/pwritev2/pwritev202.c b/testcases/kernel/syscalls/pwritev2/pwritev202.c > new file mode 100644 > index 0000000..d0f8868 > --- /dev/null > +++ b/testcases/kernel/syscalls/pwritev2/pwritev202.c > @@ -0,0 +1,117 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. > + * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> > + */ > +/* > + * 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. > + * 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 > + * 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, > +}; ^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 3/3] syscalls/pwitev202: Add new testcase 2019-02-28 7:22 ` Xiao Yang @ 2019-03-01 7:13 ` jinhui huang 0 siblings, 0 replies; 6+ messages in thread From: jinhui huang @ 2019-03-01 7:13 UTC (permalink / raw) To: ltp Hi Xiao, Thanks for your suggestion, I will update the patchset. Thanks, Jinhui Huang On 2019/02/28 15:22, Xiao Yang wrote: > Hi Jinhui, > > On 2019/02/15 16:11, Jinhui huang wrote: >> Check various errnos for the pwitev202(). > Typo? pwitev2() seems proper. > >> Signed-off-by: Jinhui huang <huangjh.jy@cn.fujitsu.com> >> --- >> 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 >> >> diff --git a/runtest/syscalls b/runtest/syscalls >> index 04f5269..27cc1dc 100644 >> --- a/runtest/syscalls >> +++ b/runtest/syscalls >> @@ -909,6 +909,8 @@ pwritev03_64 pwritev03_64 >> >> pwritev201 pwritev201 >> pwritev201_64 pwritev201_64 >> +pwritev202 pwritev202 >> +pwritev202_64 pwritev202_64 >> >> quotactl01 quotactl01 >> quotactl02 quotactl02 >> diff --git a/testcases/kernel/syscalls/pwritev2/.gitignore b/testcases/kernel/syscalls/pwritev2/.gitignore >> index 46270c3..40030d9 100644 >> --- a/testcases/kernel/syscalls/pwritev2/.gitignore >> +++ b/testcases/kernel/syscalls/pwritev2/.gitignore >> @@ -1,2 +1,4 @@ >> /pwritev201 >> /pwritev201_64 >> +/pwritev202 >> +/pwritev202_64 >> diff --git a/testcases/kernel/syscalls/pwritev2/pwritev202.c b/testcases/kernel/syscalls/pwritev2/pwritev202.c >> new file mode 100644 >> index 0000000..d0f8868 >> --- /dev/null >> +++ b/testcases/kernel/syscalls/pwritev2/pwritev202.c >> @@ -0,0 +1,117 @@ >> +// SPDX-License-Identifier: GPL-2.0-or-later >> +/* >> + * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. >> + * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com> >> + */ >> +/* >> + * 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. > >> + * 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 >> + * 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, >> +}; > . > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-03-01 7:13 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-02-15 8:11 [LTP] [PATCH 1/3] lapi/syscalls: Add syscall numbers for pwritev2() Jinhui huang 2019-02-15 8:11 ` [LTP] [PATCH 2/3] syscalls/pwritev201: Add new testcase Jinhui huang 2019-02-28 7:22 ` Xiao Yang 2019-02-15 8:11 ` [LTP] [PATCH 3/3] syscalls/pwitev202: " Jinhui huang 2019-02-28 7:22 ` Xiao Yang 2019-03-01 7:13 ` jinhui huang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox