* [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase @ 2015-11-03 22:57 Xiao Yang 2015-11-03 14:30 ` Cyril Hrubis 2015-11-03 22:57 ` [LTP] [PATCH 2/2] pwritev/pwritev01.c: " Xiao Yang 0 siblings, 2 replies; 10+ messages in thread From: Xiao Yang @ 2015-11-03 22:57 UTC (permalink / raw) To: ltp This testcase can check the basic functionality of the preadv(2). Preadv(2) should succeed to read the expected content of data and after reading the file, the file offset is not changed. Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- configure.ac | 1 + m4/ltp-preadv.m4 | 23 ++++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 3 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/preadv/Makefile | 31 ++++++ testcases/kernel/syscalls/preadv/preadv.h | 31 ++++++ testcases/kernel/syscalls/preadv/preadv01.c | 163 ++++++++++++++++++++++++++++ 9 files changed, 258 insertions(+) create mode 100644 m4/ltp-preadv.m4 create mode 100644 testcases/kernel/syscalls/preadv/Makefile create mode 100644 testcases/kernel/syscalls/preadv/preadv.h create mode 100644 testcases/kernel/syscalls/preadv/preadv01.c diff --git a/configure.ac b/configure.ac index cc89273..609de8f 100644 --- a/configure.ac +++ b/configure.ac @@ -181,5 +181,6 @@ LTP_CHECK_LINUXRANDOM LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE +LTP_CHECK_PREADV AC_OUTPUT diff --git a/m4/ltp-preadv.m4 b/m4/ltp-preadv.m4 new file mode 100644 index 0000000..2046902 --- /dev/null +++ b/m4/ltp-preadv.m4 @@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <yangx.jy@cn.fujitsu.com> +dnl +dnl This program is free software; you can redistribute it and/or modify it +dnl under the terms of version 2 of the GNU General Public License as +dnl published by the Free Software Foundation. +dnl +dnl This program is distributed in the hope that it would be useful, but +dnl WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +dnl +dnl You should have received a copy of the GNU General Public License +dnl alone with this program. +dnl + +dnl +dnl LTP_CHECK_PREADV +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_PREADV],[ +AC_CHECK_FUNCS(preadv,,) +]) diff --git a/runtest/ltplite b/runtest/ltplite index aaa5c73..9f02c7d 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -588,6 +588,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 63505ec..f30dc9c 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -498,6 +498,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01 diff --git a/runtest/syscalls b/runtest/syscalls index 958f66e..5eb5034 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -779,6 +779,9 @@ pread02_64 pread02_64 pread03 pread03 pread03_64 pread03_64 +preadv01 preadv01 +preadv01_64 preadv01_64 + profil01 profil01 process_vm_readv01 process_vm01 -r diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 6e4894a..2b4a8d9 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -657,6 +657,8 @@ /pread/pread02_64 /pread/pread03 /pread/pread03_64 +/preadv/preadv01 +/preadv/preadv01_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64 diff --git a/testcases/kernel/syscalls/preadv/Makefile b/testcases/kernel/syscalls/preadv/Makefile new file mode 100644 index 0000000..ac9a969 --- /dev/null +++ b/testcases/kernel/syscalls/preadv/Makefile @@ -0,0 +1,31 @@ +# +# 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 the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(abs_srcdir)/../utils/newer_64.mk + +# FIXME (garrcoop): more messy format strings. +CPPFLAGS += -Wno-error + +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/preadv/preadv.h b/testcases/kernel/syscalls/preadv/preadv.h new file mode 100644 index 0000000..d9243f6 --- /dev/null +++ b/testcases/kernel/syscalls/preadv/preadv.h @@ -0,0 +1,31 @@ +/* +* 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. +*/ + +#ifndef PREADV_H +#define PREADV_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#if !defined(HAVE_PREADV) +int preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) +{ + return ltp_syscall(__NR_preadv, fd, iov, iovcnt, offset); +} +#endif + +#endif /* RREADV_H */ diff --git a/testcases/kernel/syscalls/preadv/preadv01.c b/testcases/kernel/syscalls/preadv/preadv01.c new file mode 100644 index 0000000..bb9dca3 --- /dev/null +++ b/testcases/kernel/syscalls/preadv/preadv01.c @@ -0,0 +1,163 @@ +/* +* 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: preadv01 +* +* Test Description: +* Testcase to check the basic functionality of the preadv(2). +* Preadv(2) should succeed to read the expected content of data +* and after reading the file, the file offset is not changed. +*/ + +#include <errno.h> + +#include "test.h" +#include "preadv.h" +#include "safe_macros.h" + +#define CHUNK 64 + +static int fd; + +static void *s1; +static void *s2; +static char buf[CHUNK]; + +static struct iovec rd_iovec[] = { + {buf, CHUNK}, + {NULL, 0}, +}; + +static struct test_case_t { + off_t offset_cur; + int count; + off_t offset; + int byte; + char content; +} test_cases[] = { + {CHUNK, 0, 0, 0, 0x00}, + {CHUNK/2, 1, 0, CHUNK, 0x42}, + {CHUNK/4, 2, 0, CHUNK, 0x42}, + {CHUNK/8, 1, CHUNK*3/2, CHUNK/2, 0x41}, +}; + +void verify_preadv(int); +void setup(void); +void *init_buffers(char, size_t); +void l_seek(int, off_t, int, off_t); +void cleanup(void); + +char *TCID = "preadv01"; +int TST_TOTAL = ARRAY_SIZE(test_cases); + +int main(int ac, char **av) +{ + int lc; + int tc; + + tst_parse_opts(ac, av, NULL, NULL); + + setup(); + + for (lc = 0; TEST_LOOPING(lc); lc++) { + tst_count = 0; + + for (tc = 0; tc < TST_TOTAL; tc++) + verify_preadv(tc); + } + + cleanup(); + tst_exit(); +} + +void verify_preadv(int i) +{ + int c; + int fail = 0; + char *vec; + + vec = rd_iovec[0].iov_base; + + l_seek(fd, test_cases[i].offset_cur, SEEK_SET, + test_cases[i].offset_cur); + + TEST(preadv(fd, rd_iovec, test_cases[i].count, test_cases[i].offset)); + + if (test_cases[i].byte != TEST_RETURN) { + tst_resm(TFAIL, "preadv failed reading %d bytes ", + test_cases[i].byte); + } else { + for (c = 0; c < test_cases[i].byte; c++) { + if (vec[c] != test_cases[i].content) + fail++; + } + if (fail) { + tst_resm(TFAIL, "Wrong buffer content"); + } else { + l_seek(fd, 0, SEEK_CUR, test_cases[i].offset_cur); + + tst_resm(TPASS, "preadv passed reading %d bytes ", + test_cases[i].byte); + } + } +} + +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 and higher"); + } + + tst_sig(NOFORK, DEF_HANDLER, cleanup); + + TEST_PAUSE; + + tst_tmpdir(); + + s1 = init_buffers(0x42, CHUNK); + s2 = init_buffers(0x41, CHUNK); + + fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); + + SAFE_WRITE(cleanup, 1, fd, s1, CHUNK); + SAFE_WRITE(cleanup, 1, fd, s2, CHUNK); +} + +void *init_buffers(char content, size_t SIZE) +{ + void *s; + + s = SAFE_MALLOC(cleanup, SIZE); + (void)memset(s, content, SIZE); + + return s; +} + +void l_seek(int fdes, off_t offset, int whence, off_t checkoff) +{ + if (SAFE_LSEEK(cleanup, fdes, offset, whence) != checkoff) + tst_brkm(TBROK | TERRNO, cleanup, "lseek() on file failed"); +} + +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] 10+ messages in thread
* [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase 2015-11-03 22:57 [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase Xiao Yang @ 2015-11-03 14:30 ` Cyril Hrubis 2015-11-04 6:33 ` yangx.jy 2015-11-03 22:57 ` [LTP] [PATCH 2/2] pwritev/pwritev01.c: " Xiao Yang 1 sibling, 1 reply; 10+ messages in thread From: Cyril Hrubis @ 2015-11-03 14:30 UTC (permalink / raw) To: ltp Hi! > diff --git a/testcases/kernel/syscalls/preadv/Makefile b/testcases/kernel/syscalls/preadv/Makefile > new file mode 100644 > index 0000000..ac9a969 > --- /dev/null > +++ b/testcases/kernel/syscalls/preadv/Makefile > @@ -0,0 +1,31 @@ > +# > +# 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 the GNU General Public License as published by > +# the Free Software Foundation; either version 2 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See > +# the GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. > +# > +# > + > +top_srcdir ?= ../../../.. > + > +include $(top_srcdir)/include/mk/testcases.mk > + > +include $(abs_srcdir)/../utils/newer_64.mk > + > +# FIXME (garrcoop): more messy format strings. > +CPPFLAGS += -Wno-error This workaround should be needed at all. > +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 > + > +include $(top_srcdir)/include/mk/generic_leaf_target.mk ... > diff --git a/testcases/kernel/syscalls/preadv/preadv01.c b/testcases/kernel/syscalls/preadv/preadv01.c > new file mode 100644 > index 0000000..bb9dca3 > --- /dev/null > +++ b/testcases/kernel/syscalls/preadv/preadv01.c > @@ -0,0 +1,163 @@ > +/* > +* 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: preadv01 > +* > +* Test Description: > +* Testcase to check the basic functionality of the preadv(2). > +* Preadv(2) should succeed to read the expected content of data > +* and after reading the file, the file offset is not changed. > +*/ > + > +#include <errno.h> > + > +#include "test.h" > +#include "preadv.h" > +#include "safe_macros.h" > + > +#define CHUNK 64 > + > +static int fd; > + > +static void *s1; > +static void *s2; > +static char buf[CHUNK]; > + > +static struct iovec rd_iovec[] = { > + {buf, CHUNK}, > + {NULL, 0}, > +}; > + > +static struct test_case_t { > + off_t offset_cur; > + int count; > + off_t offset; > + int byte; > + char content; > +} test_cases[] = { > + {CHUNK, 0, 0, 0, 0x00}, > + {CHUNK/2, 1, 0, CHUNK, 0x42}, > + {CHUNK/4, 2, 0, CHUNK, 0x42}, > + {CHUNK/8, 1, CHUNK*3/2, CHUNK/2, 0x41}, > +}; > + > +void verify_preadv(int); > +void setup(void); > +void *init_buffers(char, size_t); > +void l_seek(int, off_t, int, off_t); > +void cleanup(void); > + > +char *TCID = "preadv01"; > +int TST_TOTAL = ARRAY_SIZE(test_cases); > + > +int main(int ac, char **av) > +{ > + int lc; > + int tc; > + > + tst_parse_opts(ac, av, NULL, NULL); > + > + setup(); > + > + for (lc = 0; TEST_LOOPING(lc); lc++) { > + tst_count = 0; > + > + for (tc = 0; tc < TST_TOTAL; tc++) > + verify_preadv(tc); > + } > + > + cleanup(); > + tst_exit(); > +} > + > +void verify_preadv(int i) It would be a bit easier if you passed a pointer to the testcase here instead of the integer. That way we could just do: void verify_preadv(struct tcase *tc) ... if (TEST_RETURN < 0) { tst_resm(TFAIL | TTERRNO, "preadv() failed"); return; } if (TEST_RETURN != tc->size) { tst_resm(TFAIL, "preadv() read %li bytes, expected %i", TEST_RETURN, tc->size); return; } for (i = 0; i < tc->size; i++) { if (vec[i] != tc->content) break; } if (i < tc->size) { tst_resm(TFAIL, "Buffer wrong at %i have %02x expected %02x", i, vec[i], tc->content); return; } ... > +{ > + int c; > + int fail = 0; > + char *vec; > + > + vec = rd_iovec[0].iov_base; > + > + l_seek(fd, test_cases[i].offset_cur, SEEK_SET, > + test_cases[i].offset_cur); Why do you set different file offset here? What is the motivation? Why cannot we instead check that after every pread() the file offset is simply set to 0? > + TEST(preadv(fd, rd_iovec, test_cases[i].count, test_cases[i].offset)); > + > + if (test_cases[i].byte != TEST_RETURN) { ^ This should be named size. Naming it byte is quite confusing since it's actually not a single byte but number of bytes. > + tst_resm(TFAIL, "preadv failed reading %d bytes ", > + test_cases[i].byte); You should test the separate case that preadv() returned -1 and print errno in that case. And in the case that preadv() read less than expected number of bytes you should print both actual and expected value. > + } else { > + for (c = 0; c < test_cases[i].byte; c++) { > + if (vec[c] != test_cases[i].content) > + fail++; > + } > + > + if (fail) { > + tst_resm(TFAIL, "Wrong buffer content"); It would be a bit better to actually write at least first place in the buffer with unexpected value and what was expected instead here. > + } else { > + l_seek(fd, 0, SEEK_CUR, test_cases[i].offset_cur); And here you check that the offset wasn't changed. That is fine, but it would be far better to actually call the SAFE_LSEEK() here and issue better error message when the resulting offset is unexpected. I.e. "pread() has changed file offset" instead of cryptic "lseek() on file failed". > + tst_resm(TPASS, "preadv passed reading %d bytes ", > + test_cases[i].byte); > + } > + } > +} > + > +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 and higher"); > + } > + > + tst_sig(NOFORK, DEF_HANDLER, cleanup); > + > + TEST_PAUSE; > + > + tst_tmpdir(); > + > + s1 = init_buffers(0x42, CHUNK); > + s2 = init_buffers(0x41, CHUNK); > + > + fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); > + > + SAFE_WRITE(cleanup, 1, fd, s1, CHUNK); > + SAFE_WRITE(cleanup, 1, fd, s2, CHUNK); You are not freeing the s1 and s2 here. Also there is no reason to make them global variables if they are used only in the setup(). Moreover 64 bytes is small enough to be declared as an array on the stack. You can do just: char s1[CHUNK]; char s2[CHUNK]; memset(s1, 0x42, sizeof(s1)); memset(s2, 0x41, sizeof(s2)); fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); SAFE_WRITE(cleanup, 1, fd, s1, sizeof(s1)); SAFE_WRITE(cleanup, 1, fd, s2, sizeof(s2)); Or we can do even better. We allready have tst_fill_file(), if we add a flag to the function that would allow us to choose between trunc and append mode we could just do: int ret; ret = tst_fill_file("file", 0x42, CHUNK, 1, TST_TRUNC); ret |= tst_fill_file("file", 0x41, CHUNK, 1, TST_APPEND); if (ret) tst_brkm(TBROK | TERRNO, "Failed to write test file"); > +} > + > +void *init_buffers(char content, size_t SIZE) ^ Upper case names are used for macros mainly. Please use lower case here. > +{ > + void *s; > + > + s = SAFE_MALLOC(cleanup, SIZE); > + (void)memset(s, content, SIZE); Why do you cast the result from memset() to (void)? It shouldn't be needed at all. > + return s; > +} > + > +void l_seek(int fdes, off_t offset, int whence, off_t checkoff) > +{ > + if (SAFE_LSEEK(cleanup, fdes, offset, whence) != checkoff) > + tst_brkm(TBROK | TERRNO, cleanup, "lseek() on file failed"); > +} > + > +void cleanup(void) > +{ > + if (fd > 0 && close(fd)) > + tst_resm(TWARN | TERRNO, "Failed to close file"); > + > + tst_rmdir(); > +} > -- > 1.8.3.1 > > > -- > Mailing list info: http://lists.linux.it/listinfo/ltp -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase 2015-11-03 14:30 ` Cyril Hrubis @ 2015-11-04 6:33 ` yangx.jy 2015-11-04 11:51 ` Cyril Hrubis 0 siblings, 1 reply; 10+ messages in thread From: yangx.jy @ 2015-11-04 6:33 UTC (permalink / raw) To: ltp Hi! Thank you for reply! -----Original Message----- From: Cyril Hrubis [mailto:chrubis@suse.cz] Sent: Tuesday, November 03, 2015 10:31 PM To: Yang, Xiao/? ? Cc: ltp@lists.linux.it Subject: Re: [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase Hi! > diff --git a/testcases/kernel/syscalls/preadv/Makefile b/testcases/kernel/syscalls/preadv/Makefile > new file mode 100644 > index 0000000..ac9a969 > --- /dev/null > +++ b/testcases/kernel/syscalls/preadv/Makefile > @@ -0,0 +1,31 @@ > +# > +# 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 the GNU General Public License as published by > +# the Free Software Foundation; either version 2 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See > +# the GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. > +# > +# > + > +top_srcdir ?= ../../../.. > + > +include $(top_srcdir)/include/mk/testcases.mk > + > +include $(abs_srcdir)/../utils/newer_64.mk > + > +# FIXME (garrcoop): more messy format strings. > +CPPFLAGS += -Wno-error This workaround should be needed at all. > +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 > + > +include $(top_srcdir)/include/mk/generic_leaf_target.mk ... Do you mean that this workaround can be removed ? I will remove it. > diff --git a/testcases/kernel/syscalls/preadv/preadv01.c b/testcases/kernel/syscalls/preadv/preadv01.c > new file mode 100644 > index 0000000..bb9dca3 > --- /dev/null > +++ b/testcases/kernel/syscalls/preadv/preadv01.c > @@ -0,0 +1,163 @@ > +/* > +* 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: preadv01 > +* > +* Test Description: > +* Testcase to check the basic functionality of the preadv(2). > +* Preadv(2) should succeed to read the expected content of data > +* and after reading the file, the file offset is not changed. > +*/ > + > +#include <errno.h> > + > +#include "test.h" > +#include "preadv.h" > +#include "safe_macros.h" > + > +#define CHUNK 64 > + > +static int fd; > + > +static void *s1; > +static void *s2; > +static char buf[CHUNK]; > + > +static struct iovec rd_iovec[] = { > + {buf, CHUNK}, > + {NULL, 0}, > +}; > + > +static struct test_case_t { > + off_t offset_cur; > + int count; > + off_t offset; > + int byte; > + char content; > +} test_cases[] = { > + {CHUNK, 0, 0, 0, 0x00}, > + {CHUNK/2, 1, 0, CHUNK, 0x42}, > + {CHUNK/4, 2, 0, CHUNK, 0x42}, > + {CHUNK/8, 1, CHUNK*3/2, CHUNK/2, 0x41}, > +}; > + > +void verify_preadv(int); > +void setup(void); > +void *init_buffers(char, size_t); > +void l_seek(int, off_t, int, off_t); > +void cleanup(void); > + > +char *TCID = "preadv01"; > +int TST_TOTAL = ARRAY_SIZE(test_cases); > + > +int main(int ac, char **av) > +{ > + int lc; > + int tc; > + > + tst_parse_opts(ac, av, NULL, NULL); > + > + setup(); > + > + for (lc = 0; TEST_LOOPING(lc); lc++) { > + tst_count = 0; > + > + for (tc = 0; tc < TST_TOTAL; tc++) > + verify_preadv(tc); > + } > + > + cleanup(); > + tst_exit(); > +} > + > +void verify_preadv(int i) It would be a bit easier if you passed a pointer to the testcase here instead of the integer. That way we could just do: void verify_preadv(struct tcase *tc) ... if (TEST_RETURN < 0) { tst_resm(TFAIL | TTERRNO, "preadv() failed"); return; } if (TEST_RETURN != tc->size) { tst_resm(TFAIL, "preadv() read %li bytes, expected %i", TEST_RETURN, tc->size); return; } for (i = 0; i < tc->size; i++) { if (vec[i] != tc->content) break; } if (i < tc->size) { tst_resm(TFAIL, "Buffer wrong at %i have %02x expected %02x", i, vec[i], tc->content); return; } ... > +{ > + int c; > + int fail = 0; > + char *vec; > + > + vec = rd_iovec[0].iov_base; > + > + l_seek(fd, test_cases[i].offset_cur, SEEK_SET, > + test_cases[i].offset_cur); Why do you set different file offset here? What is the motivation? Why cannot we instead check that after every pread() the file offset is simply set to 0? > + TEST(preadv(fd, rd_iovec, test_cases[i].count, test_cases[i].offset)); > + > + if (test_cases[i].byte != TEST_RETURN) { ^ This should be named size. Naming it byte is quite confusing since it's actually not a single byte but number of bytes. > + tst_resm(TFAIL, "preadv failed reading %d bytes ", > + test_cases[i].byte); You should test the separate case that preadv() returned -1 and print errno in that case. And in the case that preadv() read less than expected number of bytes you should print both actual and expected value. > + } else { > + for (c = 0; c < test_cases[i].byte; c++) { > + if (vec[c] != test_cases[i].content) > + fail++; > + } > + > + if (fail) { > + tst_resm(TFAIL, "Wrong buffer content"); It would be a bit better to actually write at least first place in the buffer with unexpected value and what was expected instead here. > + } else { > + l_seek(fd, 0, SEEK_CUR, test_cases[i].offset_cur); And here you check that the offset wasn't changed. That is fine, but it would be far better to actually call the SAFE_LSEEK() here and issue better error message when the resulting offset is unexpected. I.e. "pread() has changed file offset" instead of cryptic "lseek() on file failed". Thanks for your all suggestions about the function of verify_preadv. I will rewrite this function. > + tst_resm(TPASS, "preadv passed reading %d bytes ", > + test_cases[i].byte); > + } > + } > +} > + > +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 and higher"); > + } > + > + tst_sig(NOFORK, DEF_HANDLER, cleanup); > + > + TEST_PAUSE; > + > + tst_tmpdir(); > + > + s1 = init_buffers(0x42, CHUNK); > + s2 = init_buffers(0x41, CHUNK); > + > + fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); > + > + SAFE_WRITE(cleanup, 1, fd, s1, CHUNK); > + SAFE_WRITE(cleanup, 1, fd, s2, CHUNK); You are not freeing the s1 and s2 here. Also there is no reason to make them global variables if they are used only in the setup(). Moreover 64 bytes is small enough to be declared as an array on the stack. You can do just: char s1[CHUNK]; char s2[CHUNK]; memset(s1, 0x42, sizeof(s1)); memset(s2, 0x41, sizeof(s2)); fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); SAFE_WRITE(cleanup, 1, fd, s1, sizeof(s1)); SAFE_WRITE(cleanup, 1, fd, s2, sizeof(s2)); Or we can do even better. We allready have tst_fill_file(), if we add a flag to the function that would allow us to choose between trunc and append mode we could just do: int ret; ret = tst_fill_file("file", 0x42, CHUNK, 1, TST_TRUNC); ret |= tst_fill_file("file", 0x41, CHUNK, 1, TST_APPEND); if (ret) tst_brkm(TBROK | TERRNO, "Failed to write test file"); Thanks for your suggestion. I will take your suggestion. > +} > + > +void *init_buffers(char content, size_t SIZE) ^ Upper case names are used for macros mainly. Please use lower case here. You are right, i will use lower case. > +{ > + void *s; > + > + s = SAFE_MALLOC(cleanup, SIZE); > + (void)memset(s, content, SIZE); Why do you cast the result from memset() to (void)? It shouldn't be needed at all. OK?I understand. > + return s; > +} > + > +void l_seek(int fdes, off_t offset, int whence, off_t checkoff) > +{ > + if (SAFE_LSEEK(cleanup, fdes, offset, whence) != checkoff) > + tst_brkm(TBROK | TERRNO, cleanup, "lseek() on file failed"); > +} > + > +void cleanup(void) > +{ > + if (fd > 0 && close(fd)) > + tst_resm(TWARN | TERRNO, "Failed to close file"); > + > + tst_rmdir(); > +} > -- > 1.8.3.1 > > > -- > Mailing list info: http://lists.linux.it/listinfo/ltp -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase 2015-11-04 6:33 ` yangx.jy @ 2015-11-04 11:51 ` Cyril Hrubis 0 siblings, 0 replies; 10+ messages in thread From: Cyril Hrubis @ 2015-11-04 11:51 UTC (permalink / raw) To: ltp Hi! > Hi! > Thank you for reply! Can you pretty please set you email cliend to prefix quoted text in the reply? https://en.wikipedia.org/wiki/Posting_style#Quoted_line_prefix > > +# FIXME (garrcoop): more messy format strings. > > +CPPFLAGS += -Wno-error > > This workaround should be needed at all. > > > +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 > > + > > +include $(top_srcdir)/include/mk/generic_leaf_target.mk > > ... > > Do you mean that this workaround can be removed ? I will remove it. LTP is not build with -Werror hence there is absolutely no need to add -Wno-error to CPPFLAGS. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH 2/2] pwritev/pwritev01.c: add new testcase 2015-11-03 22:57 [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase Xiao Yang 2015-11-03 14:30 ` Cyril Hrubis @ 2015-11-03 22:57 ` Xiao Yang 2015-11-03 14:46 ` Cyril Hrubis 1 sibling, 1 reply; 10+ messages in thread From: Xiao Yang @ 2015-11-03 22:57 UTC (permalink / raw) To: ltp This testcase can check the basic functionality of the pwritev(2). Pwritev(2) should succeed to write the expected content of data and after writing the file, the file offset is not changed. Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- configure.ac | 1 + m4/ltp-pwritev.m4 | 23 ++++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 3 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/pwritev/Makefile | 31 ++++++ testcases/kernel/syscalls/pwritev/pwritev.h | 31 ++++++ testcases/kernel/syscalls/pwritev/pwritev01.c | 149 ++++++++++++++++++++++++++ 9 files changed, 244 insertions(+) create mode 100644 m4/ltp-pwritev.m4 create mode 100644 testcases/kernel/syscalls/pwritev/Makefile create mode 100644 testcases/kernel/syscalls/pwritev/pwritev.h create mode 100644 testcases/kernel/syscalls/pwritev/pwritev01.c diff --git a/configure.ac b/configure.ac index 609de8f..cc50397 100644 --- a/configure.ac +++ b/configure.ac @@ -182,5 +182,6 @@ LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV +LTP_CHECK_PWRITEV AC_OUTPUT diff --git a/m4/ltp-pwritev.m4 b/m4/ltp-pwritev.m4 new file mode 100644 index 0000000..6565332 --- /dev/null +++ b/m4/ltp-pwritev.m4 @@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <yangx.jy@cn.fujitsu.com> +dnl +dnl This program is free software; you can redistribute it and/or modify it +dnl under the terms of version 2 of the GNU General Public License as +dnl published by the Free Software Foundation. +dnl +dnl This program is distributed in the hope that it would be useful, but +dnl WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +dnl +dnl You should have received a copy of the GNU General Public License +dnl alone with this program. +dnl + +dnl +dnl LTP_CHECK_PWRITEV +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_PWRITEV],[ +AC_CHECK_FUNCS(pwritev,,) +]) diff --git a/runtest/ltplite b/runtest/ltplite index 9f02c7d..076007a 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -608,6 +608,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index f30dc9c..ecb032d 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -517,6 +517,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03 diff --git a/runtest/syscalls b/runtest/syscalls index 5eb5034..9e977e4 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -813,6 +813,9 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 +pwritev01_64 pwritev01_64 + quotactl01 quotactl01 quotactl02 quotactl02 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 2b4a8d9..25e0e46 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -678,6 +678,8 @@ /pwrite/pwrite02_64 /pwrite/pwrite04 /pwrite/pwrite04_64 +/pwritev/pwritev01 +/pwritev/pwritev01_64 /quotactl/quotactl01 /quotactl/quotactl02 /read/read01 diff --git a/testcases/kernel/syscalls/pwritev/Makefile b/testcases/kernel/syscalls/pwritev/Makefile new file mode 100644 index 0000000..ac9a969 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev/Makefile @@ -0,0 +1,31 @@ +# +# 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 the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# +# + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(abs_srcdir)/../utils/newer_64.mk + +# FIXME (garrcoop): more messy format strings. +CPPFLAGS += -Wno-error + +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/pwritev/pwritev.h b/testcases/kernel/syscalls/pwritev/pwritev.h new file mode 100644 index 0000000..ae9d999 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev/pwritev.h @@ -0,0 +1,31 @@ +/* +* 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. +*/ + +#ifndef PWRITEV_H +#define PWRITEV_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#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); +} +#endif + +#endif /* PWRITEV_H */ diff --git a/testcases/kernel/syscalls/pwritev/pwritev01.c b/testcases/kernel/syscalls/pwritev/pwritev01.c new file mode 100644 index 0000000..ce75552 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev/pwritev01.c @@ -0,0 +1,149 @@ +/* +* 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: pwritev01 +* +* Test Description: +* Testcase to check the basic functionality of the pwritev(2). +* pwritev(2) should succeed to write the expected content of data +* and after writing the file, the file offset is not changed. +*/ + +#include <errno.h> + +#include "test.h" +#include "pwritev.h" +#include "safe_macros.h" + +#define CHUNK 64 + +static char buf[CHUNK]; + +static char preadbuf[CHUNK*2]; + +static struct iovec wr_iovec[] = { + {buf, CHUNK}, + {NULL, 0}, +}; + +static struct test_case_t { + off_t offset_cur; + int count; + off_t offset; + int byte; +} test_cases[] = { + {CHUNK, 0, 0, 0}, + {CHUNK/2, 1, 0, CHUNK}, + {CHUNK/4, 1, CHUNK, CHUNK}, + {CHUNK/8, 2, 0, CHUNK}, +}; + +static int fd; + +void verify_pwritev(int); +void check_file_contents(int, char *, int, off_t, char *); +void setup(void); +void l_seek(int, off_t, int, off_t); +void cleanup(void); + +char *TCID = "pwritev01"; +int TST_TOTAL = ARRAY_SIZE(test_cases); + +int main(int ac, char **av) +{ + int lc; + int tc; + + tst_parse_opts(ac, av, NULL, NULL); + + setup(); + + for (lc = 0; TEST_LOOPING(lc); lc++) { + tst_count = 0; + + for (tc = 0; tc < TST_TOTAL; tc++) + verify_pwritev(tc); + } + cleanup(); + tst_exit(); +} + +void verify_pwritev(int i) +{ + l_seek(fd, test_cases[i].offset_cur, SEEK_SET, + test_cases[i].offset_cur); + + TEST(pwritev(fd, wr_iovec, test_cases[i].count, test_cases[i].offset)); + if (test_cases[i].byte != TEST_RETURN) { + tst_resm(TFAIL, "pwritev failed unexpectedly"); + } else { + l_seek(fd, 0, SEEK_CUR, test_cases[i].offset_cur); + + check_file_contents(fd, preadbuf, test_cases[i].byte, + test_cases[i].offset, buf); + } +} + +void check_file_contents(int fdes1, char *pread_buf, int pread_byte, + off_t pread_offset, char *iov_buf) +{ + if (SAFE_PREAD(cleanup, 1, fdes1, preadbuf, pread_byte, + pread_offset) != pread_byte) { + tst_brkm(TBROK | TERRNO, cleanup, + "pread failed reading %d bytes ", pread_byte); + } else { + if (memcmp(iov_buf, pread_buf, pread_byte) != 0) { + tst_resm(TFAIL, "pwritev failed reading %d bytes ", + pread_byte); + } else { + tst_resm(TPASS, "pwritev passed reading %d bytes ", + pread_byte); + } + } +} + +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 and higher"); + } + + tst_sig(NOFORK, DEF_HANDLER, cleanup); + + TEST_PAUSE; + + tst_tmpdir(); + + (void)memset(&buf, 0x42, CHUNK); + + fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); +} + +void l_seek(int fdes, off_t offset, int whence, off_t checkoff) +{ + if (SAFE_LSEEK(cleanup, fdes, offset, whence) != checkoff) + tst_brkm(TBROK | TERRNO, cleanup, "lseek() on file failed"); +} + +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] 10+ messages in thread
* [LTP] [PATCH 2/2] pwritev/pwritev01.c: add new testcase 2015-11-03 22:57 ` [LTP] [PATCH 2/2] pwritev/pwritev01.c: " Xiao Yang @ 2015-11-03 14:46 ` Cyril Hrubis 2015-12-03 11:31 ` [LTP] [PATCH v2 1/2] preadv/preadv01.c: " Xiao Yang 0 siblings, 1 reply; 10+ messages in thread From: Cyril Hrubis @ 2015-11-03 14:46 UTC (permalink / raw) To: ltp Hi! > --- /dev/null > +++ b/testcases/kernel/syscalls/pwritev/Makefile > @@ -0,0 +1,31 @@ > +# > +# 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 the GNU General Public License as published by > +# the Free Software Foundation; either version 2 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See > +# the GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. > +# > +# > + > +top_srcdir ?= ../../../.. > + > +include $(top_srcdir)/include/mk/testcases.mk > + > +include $(abs_srcdir)/../utils/newer_64.mk > + > +# FIXME (garrcoop): more messy format strings. > +CPPFLAGS += -Wno-error Here as well. > +%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 > + > +include $(top_srcdir)/include/mk/generic_leaf_target.mk ... > diff --git a/testcases/kernel/syscalls/pwritev/pwritev01.c b/testcases/kernel/syscalls/pwritev/pwritev01.c > new file mode 100644 > index 0000000..ce75552 > --- /dev/null > +++ b/testcases/kernel/syscalls/pwritev/pwritev01.c > @@ -0,0 +1,149 @@ > +/* > +* 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: pwritev01 > +* > +* Test Description: > +* Testcase to check the basic functionality of the pwritev(2). > +* pwritev(2) should succeed to write the expected content of data > +* and after writing the file, the file offset is not changed. > +*/ > + > +#include <errno.h> > + > +#include "test.h" > +#include "pwritev.h" > +#include "safe_macros.h" > + > +#define CHUNK 64 > + > +static char buf[CHUNK]; > + > +static char preadbuf[CHUNK*2]; > + > +static struct iovec wr_iovec[] = { > + {buf, CHUNK}, > + {NULL, 0}, > +}; > + > +static struct test_case_t { > + off_t offset_cur; > + int count; > + off_t offset; > + int byte; > +} test_cases[] = { > + {CHUNK, 0, 0, 0}, > + {CHUNK/2, 1, 0, CHUNK}, > + {CHUNK/4, 1, CHUNK, CHUNK}, > + {CHUNK/8, 2, 0, CHUNK}, > +}; > + > +static int fd; > + > +void verify_pwritev(int); > +void check_file_contents(int, char *, int, off_t, char *); > +void setup(void); > +void l_seek(int, off_t, int, off_t); > +void cleanup(void); > + > +char *TCID = "pwritev01"; > +int TST_TOTAL = ARRAY_SIZE(test_cases); > + > +int main(int ac, char **av) > +{ > + int lc; > + int tc; > + > + tst_parse_opts(ac, av, NULL, NULL); > + > + setup(); > + > + for (lc = 0; TEST_LOOPING(lc); lc++) { > + tst_count = 0; > + > + for (tc = 0; tc < TST_TOTAL; tc++) > + verify_pwritev(tc); > + } > + cleanup(); > + tst_exit(); > +} > + > +void verify_pwritev(int i) > +{ > + l_seek(fd, test_cases[i].offset_cur, SEEK_SET, > + test_cases[i].offset_cur); So you are changing the file offset in order to trick pwritev() to write to a differnt part of the file. Ok, then, it's the same for preadv I guess. But you really shouldn't do wrappers to SAFE_LSEEK() and name it l_seek(). At least call it do_seek() so it does not look like a library function. > + TEST(pwritev(fd, wr_iovec, test_cases[i].count, test_cases[i].offset)); > + if (test_cases[i].byte != TEST_RETURN) { > + tst_resm(TFAIL, "pwritev failed unexpectedly"); Here again, differentiate between failure and partial write. > + } else { > + l_seek(fd, 0, SEEK_CUR, test_cases[i].offset_cur); Here we should really say that pwritev() changed file offset. > + check_file_contents(fd, preadbuf, test_cases[i].byte, > + test_cases[i].offset, buf); > + } > +} > + > +void check_file_contents(int fdes1, char *pread_buf, int pread_byte, > + off_t pread_offset, char *iov_buf) Again byte does mean something different than size. Also there is absolutely no nedd to pass the buffer to the function if you aren't using it in the caller. So the function should have parameters named as: void check_file_content(int fd, int size, off_t off, char *iov_buf) > +{ > + if (SAFE_PREAD(cleanup, 1, fdes1, preadbuf, pread_byte, > + pread_offset) != pread_byte) { > + tst_brkm(TBROK | TERRNO, cleanup, > + "pread failed reading %d bytes ", pread_byte); The SAFE_PREAD() has len_strict parameter. If that is set to non-zero the call will exit the test unless exactly requested number of bytes was read. Hence it cannot fail here at all. > + } else { There is no need for the else branch since the tst_brkm() would have actually exit the test execution. > + if (memcmp(iov_buf, pread_buf, pread_byte) != 0) { > + tst_resm(TFAIL, "pwritev failed reading %d bytes ", > + pread_byte); Again, please be more specific on what have failed. In this case you should at least say that the buffer had unexpected value and ideally print first place when it was wrong. > + } else { > + tst_resm(TPASS, "pwritev passed reading %d bytes ", > + pread_byte); > + } > + } > +} > + > +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 and higher"); > + } > + > + tst_sig(NOFORK, DEF_HANDLER, cleanup); > + > + TEST_PAUSE; > + > + tst_tmpdir(); > + > + (void)memset(&buf, 0x42, CHUNK); Drop the (void) here. > + fd = SAFE_OPEN(cleanup, "file", O_RDWR | O_CREAT, 0644); > +} > + > +void l_seek(int fdes, off_t offset, int whence, off_t checkoff) > +{ > + if (SAFE_LSEEK(cleanup, fdes, offset, whence) != checkoff) > + tst_brkm(TBROK | TERRNO, cleanup, "lseek() on file failed"); > +} > + > +void cleanup(void) > +{ > + if (fd > 0 && close(fd)) > + tst_resm(TWARN | TERRNO, "Failed to close file"); > + > + tst_rmdir(); > +} > -- > 1.8.3.1 > > > -- > Mailing list info: http://lists.linux.it/listinfo/ltp -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v2 1/2] preadv/preadv01.c: add new testcase 2015-11-03 14:46 ` Cyril Hrubis @ 2015-12-03 11:31 ` Xiao Yang 2015-12-03 11:31 ` [LTP] [PATCH v2 2/2] pwritev/pwritev01.c: " Xiao Yang 2015-12-15 14:40 ` [LTP] [PATCH v2 1/2] preadv/preadv01.c: " Cyril Hrubis 0 siblings, 2 replies; 10+ messages in thread From: Xiao Yang @ 2015-12-03 11:31 UTC (permalink / raw) To: ltp Test preadv(2) with some basic functions. Preadv(2) should succeed to read the expected content of data and the file offset is not changed after reading the file. Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- configure.ac | 1 + m4/ltp-preadv.m4 | 23 +++++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 3 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/preadv/Makefile | 28 ++++++ testcases/kernel/syscalls/preadv/preadv.h | 31 ++++++ testcases/kernel/syscalls/preadv/preadv01.c | 150 ++++++++++++++++++++++++++++ 9 files changed, 242 insertions(+) create mode 100644 m4/ltp-preadv.m4 create mode 100644 testcases/kernel/syscalls/preadv/Makefile create mode 100644 testcases/kernel/syscalls/preadv/preadv.h create mode 100644 testcases/kernel/syscalls/preadv/preadv01.c diff --git a/configure.ac b/configure.ac index cc89273..609de8f 100644 --- a/configure.ac +++ b/configure.ac @@ -181,5 +181,6 @@ LTP_CHECK_LINUXRANDOM LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE +LTP_CHECK_PREADV AC_OUTPUT diff --git a/m4/ltp-preadv.m4 b/m4/ltp-preadv.m4 new file mode 100644 index 0000000..2046902 --- /dev/null +++ b/m4/ltp-preadv.m4 @@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <yangx.jy@cn.fujitsu.com> +dnl +dnl This program is free software; you can redistribute it and/or modify it +dnl under the terms of version 2 of the GNU General Public License as +dnl published by the Free Software Foundation. +dnl +dnl This program is distributed in the hope that it would be useful, but +dnl WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +dnl +dnl You should have received a copy of the GNU General Public License +dnl alone with this program. +dnl + +dnl +dnl LTP_CHECK_PREADV +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_PREADV],[ +AC_CHECK_FUNCS(preadv,,) +]) diff --git a/runtest/ltplite b/runtest/ltplite index f2c9dcf..4eb4233 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -588,6 +588,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 36bb16f..0718fbc 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -498,6 +498,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01 diff --git a/runtest/syscalls b/runtest/syscalls index 9c69eea..099dfa7 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -779,6 +779,9 @@ pread02_64 pread02_64 pread03 pread03 pread03_64 pread03_64 +preadv01 preadv01 +preadv01_64 preadv01_64 + profil01 profil01 process_vm_readv01 process_vm01 -r diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index bf515cc..38e36fb 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -657,6 +657,8 @@ /pread/pread02_64 /pread/pread03 /pread/pread03_64 +/preadv/preadv01 +/preadv/preadv01_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64 diff --git a/testcases/kernel/syscalls/preadv/Makefile b/testcases/kernel/syscalls/preadv/Makefile new file mode 100644 index 0000000..764c956 --- /dev/null +++ b/testcases/kernel/syscalls/preadv/Makefile @@ -0,0 +1,28 @@ +# +# 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 the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# +# + +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/preadv/preadv.h b/testcases/kernel/syscalls/preadv/preadv.h new file mode 100644 index 0000000..d9243f6 --- /dev/null +++ b/testcases/kernel/syscalls/preadv/preadv.h @@ -0,0 +1,31 @@ +/* +* 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. +*/ + +#ifndef PREADV_H +#define PREADV_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#if !defined(HAVE_PREADV) +int preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) +{ + return ltp_syscall(__NR_preadv, fd, iov, iovcnt, offset); +} +#endif + +#endif /* RREADV_H */ diff --git a/testcases/kernel/syscalls/preadv/preadv01.c b/testcases/kernel/syscalls/preadv/preadv01.c new file mode 100644 index 0000000..3f1a798 --- /dev/null +++ b/testcases/kernel/syscalls/preadv/preadv01.c @@ -0,0 +1,150 @@ +/* +* 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: preadv01 +* +* Test Description: +* Testcase to check the basic functionality of the preadv(2). +* Preadv(2) should succeed to read the expected content of data +* and after reading the file, the file offset is not changed. +*/ + +#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_iovec[] = { + {buf, CHUNK}, + {NULL, 0}, +}; + +static struct test_case_t { + int count; + off_t offset; + ssize_t size; +} tc[] = { + {1, 0, CHUNK}, + {2, 0, CHUNK}, + {1, CHUNK*3/2, CHUNK/2}, +}; + +void verify_preadv(struct test_case_t *tc); +void setup(void); +void cleanup(void); + +char *TCID = "preadv01"; +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) +{ + int i; + char *vec; + + vec = rd_iovec[0].iov_base; + memset(vec, 0x00, CHUNK); + + SAFE_LSEEK(cleanup, fd, 0, SEEK_SET); + + TEST(preadv(fd, rd_iovec, tc->count, tc->offset)); + if (TEST_RETURN < 0) { + tst_resm(TFAIL | TTERRNO, "Preadv(2) failed"); + return; + } + + if (TEST_RETURN != tc->size) { + tst_resm(TFAIL, "Preadv(2) read %li bytes, expected %li", + TEST_RETURN, tc->size); + return; + } + + for (i = 0; i < tc->size; i++) { + if (vec[i] != 0x61) + break; + } + + if (i < tc->size) { + tst_resm(TFAIL, "Buffer wrong at %i have %c expected a", + i, vec[i]); + return; + } + + if (SAFE_LSEEK(cleanup, fd, 0, SEEK_CUR) != 0) { + tst_resm(TFAIL, "Preadv(2) has changed file offset"); + return; + } + + tst_resm(TPASS, "Preadv(2) read %li bytes successfully " + "with content 'a' expectedly", tc->size); +} + +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 and higher"); + } + + tst_sig(NOFORK, DEF_HANDLER, cleanup); + + TEST_PAUSE; + + tst_tmpdir(); + + int ret; + + ret = tst_fill_file("file", 0x61, CHUNK, 2); + if (ret) + tst_brkm(TBROK | TERRNO, cleanup, "Failed to fill test file"); + + fd = SAFE_OPEN(cleanup, "file", O_RDWR, 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] 10+ messages in thread
* [LTP] [PATCH v2 2/2] pwritev/pwritev01.c: add new testcase 2015-12-03 11:31 ` [LTP] [PATCH v2 1/2] preadv/preadv01.c: " Xiao Yang @ 2015-12-03 11:31 ` Xiao Yang 2015-12-15 16:36 ` Cyril Hrubis 2015-12-15 14:40 ` [LTP] [PATCH v2 1/2] preadv/preadv01.c: " Cyril Hrubis 1 sibling, 1 reply; 10+ messages in thread From: Xiao Yang @ 2015-12-03 11:31 UTC (permalink / raw) To: ltp Test pwritev(2) with some basic functions. Pwritev(2) should succeed to write the expected content of data and the file offset is not changed after writing the file. Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> --- configure.ac | 1 + m4/ltp-pwritev.m4 | 23 ++++ runtest/ltplite | 2 + runtest/stress.part3 | 2 + runtest/syscalls | 3 + testcases/kernel/syscalls/.gitignore | 2 + testcases/kernel/syscalls/pwritev/Makefile | 28 +++++ testcases/kernel/syscalls/pwritev/pwritev.h | 31 ++++++ testcases/kernel/syscalls/pwritev/pwritev01.c | 146 ++++++++++++++++++++++++++ 9 files changed, 238 insertions(+) create mode 100644 m4/ltp-pwritev.m4 create mode 100644 testcases/kernel/syscalls/pwritev/Makefile create mode 100644 testcases/kernel/syscalls/pwritev/pwritev.h create mode 100644 testcases/kernel/syscalls/pwritev/pwritev01.c diff --git a/configure.ac b/configure.ac index 609de8f..cc50397 100644 --- a/configure.ac +++ b/configure.ac @@ -182,5 +182,6 @@ LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV +LTP_CHECK_PWRITEV AC_OUTPUT diff --git a/m4/ltp-pwritev.m4 b/m4/ltp-pwritev.m4 new file mode 100644 index 0000000..6565332 --- /dev/null +++ b/m4/ltp-pwritev.m4 @@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <yangx.jy@cn.fujitsu.com> +dnl +dnl This program is free software; you can redistribute it and/or modify it +dnl under the terms of version 2 of the GNU General Public License as +dnl published by the Free Software Foundation. +dnl +dnl This program is distributed in the hope that it would be useful, but +dnl WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +dnl +dnl You should have received a copy of the GNU General Public License +dnl alone with this program. +dnl + +dnl +dnl LTP_CHECK_PWRITEV +dnl ---------------------------- +dnl +AC_DEFUN([LTP_CHECK_PWRITEV],[ +AC_CHECK_FUNCS(pwritev,,) +]) diff --git a/runtest/ltplite b/runtest/ltplite index 4eb4233..1aa93e6 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -608,6 +608,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 0718fbc..87f42ea 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -517,6 +517,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03 diff --git a/runtest/syscalls b/runtest/syscalls index 099dfa7..69b0c8f 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -813,6 +813,9 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 +pwritev01_64 pwritev01_64 + quotactl01 quotactl01 quotactl02 quotactl02 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index 38e36fb..6b7de17 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -678,6 +678,8 @@ /pwrite/pwrite02_64 /pwrite/pwrite04 /pwrite/pwrite04_64 +/pwritev/pwritev01 +/pwritev/pwritev01_64 /quotactl/quotactl01 /quotactl/quotactl02 /read/read01 diff --git a/testcases/kernel/syscalls/pwritev/Makefile b/testcases/kernel/syscalls/pwritev/Makefile new file mode 100644 index 0000000..764c956 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev/Makefile @@ -0,0 +1,28 @@ +# +# 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 the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. +# +# + +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/pwritev/pwritev.h b/testcases/kernel/syscalls/pwritev/pwritev.h new file mode 100644 index 0000000..ae9d999 --- /dev/null +++ b/testcases/kernel/syscalls/pwritev/pwritev.h @@ -0,0 +1,31 @@ +/* +* 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. +*/ + +#ifndef PWRITEV_H +#define PWRITEV_H + +#include <sys/types.h> +#include "config.h" +#include "linux_syscall_numbers.h" + +#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); +} +#endif + +#endif /* PWRITEV_H */ diff --git a/testcases/kernel/syscalls/pwritev/pwritev01.c b/testcases/kernel/syscalls/pwritev/pwritev01.c new file mode 100644 index 0000000..6a82e8e --- /dev/null +++ b/testcases/kernel/syscalls/pwritev/pwritev01.c @@ -0,0 +1,146 @@ +/* +* 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: pwritev01 +* +* Test Description: +* Testcase to check the basic functionality of the pwritev(2). +* pwritev(2) should succeed to write the expected content of data +* and after writing the file, the file offset is not changed. +*/ + +#include <errno.h> + +#include "test.h" +#include "pwritev.h" +#include "safe_macros.h" + +#define CHUNK 64 + +static char buf[CHUNK]; +static char initbuf[CHUNK]; +static char preadbuf[CHUNK]; +static int fd; + +static struct iovec wr_iovec[] = { + {buf, CHUNK}, + {NULL, 0}, +}; + +static struct test_case_t { + int count; + off_t offset; + ssize_t size; +} tc[] = { + {1, 0, CHUNK}, + {2, 0, CHUNK}, +}; + +void verify_pwritev(struct test_case_t *); +void setup(void); +void cleanup(void); + +char *TCID = "pwritev01"; +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) +{ + int i; + + SAFE_PWRITE(cleanup, 1, fd, initbuf, tc->size, 0); + + SAFE_LSEEK(cleanup, fd, 0, SEEK_SET); + + TEST(pwritev(fd, wr_iovec, tc->count, tc->offset)); + if (TEST_RETURN < 0) { + tst_resm(TFAIL | TTERRNO, "Pwritev(2) failed"); + return; + } + + if (TEST_RETURN != tc->size) { + tst_resm(TFAIL, "Pwritev(2) write %li bytes, expected %li", + TEST_RETURN, tc->size); + return; + } + + if (SAFE_LSEEK(cleanup, fd, 0, SEEK_CUR) != 0) { + tst_resm(TFAIL, "Pwritev(2) has changed file offset"); + return; + } + + SAFE_PREAD(cleanup, 1, fd, preadbuf, tc->size, 0); + + for (i = 0; i < tc->size; i++) { + if (preadbuf[i] != 0x61) + break; + } + + if (i != tc->size) { + tst_resm(TFAIL, "Buffer wrong at %i have %c expected a", + i, preadbuf[i]); + return; + } + + tst_resm(TPASS, "Pwritev(2) write %li bytes successfully " + "with content 'a' expectedly ", tc->size); +} + +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 and higher"); + } + + tst_sig(NOFORK, DEF_HANDLER, cleanup); + + TEST_PAUSE; + + tst_tmpdir(); + + memset(&initbuf, 0x00, CHUNK); + memset(&buf, 0x61, CHUNK); + + 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] 10+ messages in thread
* [LTP] [PATCH v2 2/2] pwritev/pwritev01.c: add new testcase 2015-12-03 11:31 ` [LTP] [PATCH v2 2/2] pwritev/pwritev01.c: " Xiao Yang @ 2015-12-15 16:36 ` Cyril Hrubis 0 siblings, 0 replies; 10+ messages in thread From: Cyril Hrubis @ 2015-12-15 16:36 UTC (permalink / raw) To: ltp Hi! > +static struct test_case_t { > + int count; > + off_t offset; > + ssize_t size; > +} tc[] = { > + {1, 0, CHUNK}, > + {2, 0, CHUNK}, I've added a test with non-zero offset here. > +void verify_pwritev(struct test_case_t *tc) > +{ > + int i; > + > + SAFE_PWRITE(cleanup, 1, fd, initbuf, tc->size, 0); > + > + SAFE_LSEEK(cleanup, fd, 0, SEEK_SET); > + > + TEST(pwritev(fd, wr_iovec, tc->count, tc->offset)); > + if (TEST_RETURN < 0) { > + tst_resm(TFAIL | TTERRNO, "Pwritev(2) failed"); > + return; > + } > + > + if (TEST_RETURN != tc->size) { > + tst_resm(TFAIL, "Pwritev(2) write %li bytes, expected %li", > + TEST_RETURN, tc->size); > + return; > + } > + > + if (SAFE_LSEEK(cleanup, fd, 0, SEEK_CUR) != 0) { > + tst_resm(TFAIL, "Pwritev(2) has changed file offset"); > + return; > + } > + > + SAFE_PREAD(cleanup, 1, fd, preadbuf, tc->size, 0); Fixed it here to read from tc->offset > + for (i = 0; i < tc->size; i++) { > + if (preadbuf[i] != 0x61) > + break; > + } > + > + if (i != tc->size) { > + tst_resm(TFAIL, "Buffer wrong at %i have %c expected a", > + i, preadbuf[i]); Changed the %c to $02x (for the same reason as in the preadv()). > + return; > + } > + > + tst_resm(TPASS, "Pwritev(2) write %li bytes successfully " > + "with content 'a' expectedly ", tc->size); > +} > + > +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 and higher"); > + } > + > + tst_sig(NOFORK, DEF_HANDLER, cleanup); > + > + TEST_PAUSE; > + > + tst_tmpdir(); > + > + memset(&initbuf, 0x00, CHUNK); And removed the memset() here since global variables are initialized to zero automatically. And pushed the test, thanks. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v2 1/2] preadv/preadv01.c: add new testcase 2015-12-03 11:31 ` [LTP] [PATCH v2 1/2] preadv/preadv01.c: " Xiao Yang 2015-12-03 11:31 ` [LTP] [PATCH v2 2/2] pwritev/pwritev01.c: " Xiao Yang @ 2015-12-15 14:40 ` Cyril Hrubis 1 sibling, 0 replies; 10+ messages in thread From: Cyril Hrubis @ 2015-12-15 14:40 UTC (permalink / raw) To: ltp Hi! > + if (i < tc->size) { > + tst_resm(TFAIL, "Buffer wrong at %i have %c expected a", > + i, vec[i]); I've changed the %c to %x since more than half of the char values are non-printable ones and will probably mess up terminal. > + ret = tst_fill_file("file", 0x61, CHUNK, 2); > + if (ret) > + tst_brkm(TBROK | TERRNO, cleanup, "Failed to fill test file"); Change to single tst_fill_file() is not a good one. Since that way we cannot say that the offset parameter for the syscall is working as expected. So I changed this part to go with memset() and SAFE_WRITE() and pushed, thanks. -- Cyril Hrubis chrubis@suse.cz ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2015-12-15 16:36 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2015-11-03 22:57 [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase Xiao Yang 2015-11-03 14:30 ` Cyril Hrubis 2015-11-04 6:33 ` yangx.jy 2015-11-04 11:51 ` Cyril Hrubis 2015-11-03 22:57 ` [LTP] [PATCH 2/2] pwritev/pwritev01.c: " Xiao Yang 2015-11-03 14:46 ` Cyril Hrubis 2015-12-03 11:31 ` [LTP] [PATCH v2 1/2] preadv/preadv01.c: " Xiao Yang 2015-12-03 11:31 ` [LTP] [PATCH v2 2/2] pwritev/pwritev01.c: " Xiao Yang 2015-12-15 16:36 ` Cyril Hrubis 2015-12-15 14:40 ` [LTP] [PATCH v2 1/2] preadv/preadv01.c: " Cyril Hrubis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox