preadv/preadv01.c: add new testcase
PATCH 1/2 preadv/preadv01.c: add new testcase
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.
--- 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
configure.ac +1 -0
@@ -181,5 +181,6 @@ LTP_CHECK_LINUXRANDOM LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE +LTP_CHECK_PREADV AC_OUTPUT
m4/ltp-preadv.m4 new file +23 -0
@@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <[email protected]> +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,,) +])
runtest/ltplite +2 -0
@@ -588,6 +588,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01
runtest/stress.part3 +2 -0
@@ -498,6 +498,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01
runtest/syscalls +3 -0
@@ -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
testcases/kernel/syscalls/.gitignore +2 -0
@@ -657,6 +657,8 @@ /pread/pread02_64 /pread/pread03 /pread/pread03_64 +/preadv/preadv01 +/preadv/preadv01_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64
testcases/kernel/syscalls/preadv/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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
testcases/kernel/syscalls/preadv/preadv.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2015 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]> +* +* 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 */
testcases/kernel/syscalls/preadv/preadv01.c new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 1/2 preadv/preadv01.c: add new testcase
Hi!
Quoted 23 lines
testcases/kernel/syscalls/preadv/Makefile new file +17
-0@@ -0,0 +1,31 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +#
testcases/kernel/syscalls/preadv/Makefile line 27
Quoted 10 lines
testcases/kernel/syscalls/preadv/Makefile new file +10
-0+# + +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.
Quoted 3 lines
testcases/kernel/syscalls/preadv/Makefile new file +3
-0+%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
...
Quoted 83 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +77
-0@@ -0,0 +1,163 @@ +/* +* Copyright (c) 2015 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]> +* +* 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 ;
testcases/kernel/syscalls/preadv/preadv01.c line 87
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +10
-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;
}...
testcases/kernel/syscalls/preadv/preadv01.c line 96
Quoted 9 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +9
-0+{ +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?
testcases/kernel/syscalls/preadv/preadv01.c line 100
Quoted 3 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +3
-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.
testcases/kernel/syscalls/preadv/preadv01.c
Quoted 2 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +2
-0+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.
testcases/kernel/syscalls/preadv/preadv01.c
Quoted 8 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +8
-0+ }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.
testcases/kernel/syscalls/preadv/preadv01.c
Quoted 2 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +2
-0+ }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".
Quoted 16 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +16
-0+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 ;
testcases/kernel/syscalls/preadv/preadv01.c line 138
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +10
-0+ +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");testcases/kernel/syscalls/preadv/preadv01.c line 141
Quoted 3 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +3
-0+} + +void *init_buffers (char content,size_t SIZE )
^
Upper case names are used for macros mainly. Please use lower case here.
testcases/kernel/syscalls/preadv/preadv01.c line 146
Quoted 5 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +5
-0+{ +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.
Quoted 22 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +16
-0+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 (); +}Signature · 5 lines
1.8.3.1 -- Mailing list info: http://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 preadv/preadv01.c: add new testcase
Hi!
Thank you for reply!
-----Original Message-----
From: Cyril Hrubis [mailto:[email protected]]
Sent: Tuesday, November 03, 2015 10:31 PM
To: Yang, Xiao/? ?
Cc: [email protected]
Subject: Re: [LTP] [PATCH 1/2] preadv/preadv01.c: add new testcase
Hi!
Quoted 23 lines
testcases/kernel/syscalls/preadv/Makefile new file +17
-0@@ -0,0 +1,31 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +#
testcases/kernel/syscalls/preadv/Makefile line 27
Quoted 10 lines
testcases/kernel/syscalls/preadv/Makefile new file +10
-0+# + +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.
testcases/kernel/syscalls/preadv/Makefile line 31
Quoted 3 lines
testcases/kernel/syscalls/preadv/Makefile new file +3
-0+%_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.
Quoted 83 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +77
-0@@ -0,0 +1,163 @@ +/* +* Copyright (c) 2015 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]> +* +* 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 ;
testcases/kernel/syscalls/preadv/preadv01.c line 87
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +10
-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;
}...
testcases/kernel/syscalls/preadv/preadv01.c line 96
Quoted 9 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +9
-0+{ +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?
testcases/kernel/syscalls/preadv/preadv01.c line 100
Quoted 3 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +3
-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.
testcases/kernel/syscalls/preadv/preadv01.c
Quoted 2 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +2
-0+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.
testcases/kernel/syscalls/preadv/preadv01.c
Quoted 8 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +8
-0+ }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.
testcases/kernel/syscalls/preadv/preadv01.c
Quoted 2 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +2
-0+ }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.
Quoted 16 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +16
-0+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 ;
testcases/kernel/syscalls/preadv/preadv01.c line 138
Quoted 10 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +10
-0+ +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.
testcases/kernel/syscalls/preadv/preadv01.c line 141
Quoted 3 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +3
-0+} + +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.
testcases/kernel/syscalls/preadv/preadv01.c line 146
Quoted 5 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +5
-0+{ +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.
Quoted 22 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +16
-0+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 (); +}Signature · 5 lines
1.8.3.1 -- Mailing list info: http://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 preadv/preadv01.c: add new testcase
Hi!
Quoted 2 lines
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
Quoted 5 lines
testcases/kernel/syscalls/preadv/Makefile line 27
Quoted 2 lines
testcases/kernel/syscalls/preadv/Makefile new file +2
-0+# FIXME (garrcoop): more messy format strings. +CPPFLAGS += -Wno-errorThis workaround should be needed at all.
Quoted 7 lines
Review
Quoted 3 lines
+%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64
(quoted diff) +2
-0+ +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.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 pwritev/pwritev01.c: add new testcase
In reply to Xiao YangThis 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.
--- 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
configure.ac +1 -0
@@ -182,5 +182,6 @@ LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV +LTP_CHECK_PWRITEV AC_OUTPUT
m4/ltp-pwritev.m4 new file +23 -0
@@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <[email protected]> +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,,) +])
runtest/ltplite +2 -0
@@ -608,6 +608,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03
runtest/stress.part3 +2 -0
@@ -517,6 +517,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03
runtest/syscalls +3 -0
@@ -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
testcases/kernel/syscalls/.gitignore +2 -0
@@ -678,6 +678,8 @@ /pwrite/pwrite02_64 /pwrite/pwrite04 /pwrite/pwrite04_64 +/pwritev/pwritev01 +/pwritev/pwritev01_64 /quotactl/quotactl01 /quotactl/quotactl02 /read/read01
testcases/kernel/syscalls/pwritev/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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
testcases/kernel/syscalls/pwritev/pwritev.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2015 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]> +* +* 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 */
testcases/kernel/syscalls/pwritev/pwritev01.c new file +149 -0
149 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 2/2 pwritev/pwritev01.c: add new testcase
Hi!
Quoted 20 lines
testcases/kernel/syscalls/pwritev/Makefile new file +17
-0@@ -0,0 +1,31 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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. +#
testcases/kernel/syscalls/pwritev/Makefile line 27
Quoted 10 lines
testcases/kernel/syscalls/pwritev/Makefile new file +10
-0+# + +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.
Quoted 3 lines
testcases/kernel/syscalls/pwritev/Makefile new file +3
-0+%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
...
Quoted 84 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +78
-0@@ -0,0 +1,149 @@ +/* +* Copyright (c) 2015 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]> +* +* 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++)
testcases/kernel/syscalls/pwritev/pwritev01.c line 88
Quoted 10 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +10
-0+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.
testcases/kernel/syscalls/pwritev/pwritev01.c line 92
Quoted 3 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +3
-0+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.
testcases/kernel/syscalls/pwritev/pwritev01.c line 94
Quoted 2 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +2
-0+ }else { +l_seek (fd,0 ,SEEK_CUR , test_cases[i].offset_cur);
Here we should really say that pwritev() changed file offset.
testcases/kernel/syscalls/pwritev/pwritev01.c line 102
Quoted 7 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +7
-0+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)
testcases/kernel/syscalls/pwritev/pwritev01.c line 107
Quoted 5 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +5
-0+{ +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.
testcases/kernel/syscalls/pwritev/pwritev01.c line 106
Quoted 1 line
testcases/kernel/syscalls/pwritev/pwritev01.c new file +1
-0+ }else {
There is no need for the else branch since the tst_brkm() would have actually exit the test execution.
testcases/kernel/syscalls/pwritev/pwritev01.c line 111
Quoted 3 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +3
-0+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.
Quoted 11 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +11
-0+ }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 "
testcases/kernel/syscalls/pwritev/pwritev01.c line 132
Quoted 10 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +10
-0+ "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.
Quoted 22 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +16
-0+ 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 (); +}Signature · 5 lines
1.8.3.1 -- Mailing list info: http://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 preadv/preadv01.c: add new testcase
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.
--- 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
configure.ac +1 -0
@@ -181,5 +181,6 @@ LTP_CHECK_LINUXRANDOM LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE +LTP_CHECK_PREADV AC_OUTPUT
m4/ltp-preadv.m4 new file +23 -0
@@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <[email protected]> +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,,) +])
runtest/ltplite +2 -0
@@ -588,6 +588,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01
runtest/stress.part3 +2 -0
@@ -498,6 +498,8 @@ pread01 pread01 pread02 pread02 pread03 pread03 +preadv01 preadv01 + profil01 profil01 pselect01 pselect01
runtest/syscalls +3 -0
@@ -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
testcases/kernel/syscalls/.gitignore +2 -0
@@ -657,6 +657,8 @@ /pread/pread02_64 /pread/pread03 /pread/pread03_64 +/preadv/preadv01 +/preadv/preadv01_64 /profil/profil01 /pselect/pselect01 /pselect/pselect01_64
testcases/kernel/syscalls/preadv/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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
testcases/kernel/syscalls/preadv/preadv.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2015 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]> +* +* 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 */
testcases/kernel/syscalls/preadv/preadv01.c new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/2 pwritev/pwritev01.c: add new testcase
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.
--- 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
configure.ac +1 -0
@@ -182,5 +182,6 @@ LTP_CHECK_IF_LINK LTP_CHECK_KCMP LTP_CHECK_KCMP_TYPE LTP_CHECK_PREADV +LTP_CHECK_PWRITEV AC_OUTPUT
m4/ltp-pwritev.m4 new file +23 -0
@@ -0,0 +1,23 @@ +dnl +dnl Copyright (c) 2015 Fujitsu Ltd. +dnl Author: Xiao Yang <[email protected]> +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,,) +])
runtest/ltplite +2 -0
@@ -608,6 +608,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03
runtest/stress.part3 +2 -0
@@ -517,6 +517,8 @@ pwrite01_64 pwrite01_64 pwrite02_64 pwrite02_64 pwrite04_64 pwrite04_64 +pwritev01 pwritev01 + read01 read01 read02 read02 read03 read03
runtest/syscalls +3 -0
@@ -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
testcases/kernel/syscalls/.gitignore +2 -0
@@ -678,6 +678,8 @@ /pwrite/pwrite02_64 /pwrite/pwrite04 /pwrite/pwrite04_64 +/pwritev/pwritev01 +/pwritev/pwritev01_64 /quotactl/quotactl01 /quotactl/quotactl02 /read/read01
testcases/kernel/syscalls/pwritev/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Xiao Yang <[email protected]> +# +# 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
testcases/kernel/syscalls/pwritev/pwritev.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright (c) 2015 Fujitsu Ltd. +* Author: Xiao Yang <[email protected]> +* +* 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 */
testcases/kernel/syscalls/pwritev/pwritev01.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v2 2/2 pwritev/pwritev01.c: add new testcase
Hi!
testcases/kernel/syscalls/pwritev/pwritev01.c line 50
Quoted 7 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +7
-0+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.
Quoted 16 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +16
-0+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",
testcases/kernel/syscalls/pwritev/pwritev01.c line 104
Quoted 10 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +10
-0+ 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
testcases/kernel/syscalls/pwritev/pwritev01.c line 113
Quoted 8 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +8
-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]);
Changed the %c to $02x (for the same reason as in the preadv()).
Quoted 11 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +11
-0+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 "
testcases/kernel/syscalls/pwritev/pwritev01.c line 134
Quoted 10 lines
testcases/kernel/syscalls/pwritev/pwritev01.c new file +10
-0+ "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.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 preadv/preadv01.c: add new testcase
In reply to Xiao YangHi!
testcases/kernel/syscalls/preadv/preadv01.c line 108
Quoted 3 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +3
-0+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.
testcases/kernel/syscalls/preadv/preadv01.c line 138
Quoted 3 lines
testcases/kernel/syscalls/preadv/preadv01.c new file +3
-0+ 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.
Signature · 2 lines
Cyril Hrubis [email protected]