diotest: cleanup & fix
PATCH 1/3 diotest: cleanup & fix
This patch is mostly about fixing coding style mistakes in diotest*.c to make the code more readable. Headers were also updated.
Useless function arguments were removed Useless "removed" tests like:
tst_resm(TPASS, "removed")
were removed.
Added O_DIRECT in fcntl.h and check
that O_DIRECT is supported by the file system
--- include/lapi/fcntl.h | 4 + testcases/kernel/io/direct_io/diotest1.c | 84 +++++----- testcases/kernel/io/direct_io/diotest2.c | 121 ++++++++------- testcases/kernel/io/direct_io/diotest3.c | 118 +++++++------- testcases/kernel/io/direct_io/diotest4.c | 189 ++++++++++++----------- testcases/kernel/io/direct_io/diotest5.c | 141 ++++++++--------- testcases/kernel/io/direct_io/diotest6.c | 66 ++++---- testcases/kernel/io/direct_io/diotest_routines.c | 68 ++++---- testcases/kernel/io/direct_io/diotest_routines.h | 40 +++-- 9 files changed, 435 insertions(+), 396 deletions(-)
include/lapi/fcntl.h +4 -0
@@ -59,6 +59,10 @@# define O_NOATIME 01000000#endif +#ifndef O_DIRECT +# define O_DIRECT 00040000 +#endif +#ifndef O_PATH # define O_PATH 010000000#endif
testcases/kernel/io/direct_io/diotest1.c +39 -45
151 lines not on this page · raw message
testcases/kernel/io/direct_io/diotest2.c +62 -59
242 lines not on this page · raw message
testcases/kernel/io/direct_io/diotest3.c +62 -56
244 lines not on this page · raw message
testcases/kernel/io/direct_io/diotest4.c +96 -93
414 lines not on this page · raw message
testcases/kernel/io/direct_io/diotest5.c +71 -70
296 lines not on this page · raw message
testcases/kernel/io/direct_io/diotest6.c +35 -31
170 lines not on this page · raw message
testcases/kernel/io/direct_io/diotest_routines.c +35 -33
153 lines not on this page · raw message
testcases/kernel/io/direct_io/diotest_routines.h +31 -9
@@ -1,12 +1,34 @@ -struct iovec ; -extern void fillbuf (char *buf,int count,char value); -extern void vfillbuf (struct iovec *iv,int vcnt,char value); -extern int filecmp (char *f1,char *f2); -extern int bufcmp (char *b1,char *b2,int bsize); -extern int vbufcmp (struct iovec *iv1,struct iovec *iv2,int vcnt); +/* +* Copyright (c) International Business Machines Corp., 2002 +* 04/30/2002 Narasimha Sharoff [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; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ -extern int forkchldrn (int **pidlst,int numchld,int action,int (*chldfunc)()); -extern int waitchldrn (int **pidlst,int numchld); -extern int killchldrn (int **pidlst,int numchld,int sig); +#ifndef DIOTEST_ROUTINES_H +#define DIOTEST_ROUTINES_H +#include "lapi/fcntl.h" +void fillbuf (char *buf,int count,char value); +void vfillbuf (struct iovec *iv,int vcnt,char value); +int filecmp (char *f1,char *f2); +int bufcmp (char *b1,char *b2,int bsize); +int vbufcmp (struct iovec *iv1,struct iovec *iv2,int vcnt); +int forkchldrn (int **pidlst,int numchld,int action,int (*chldfunc)()); +int waitchldrn (int **pidlst,int numchld); +int killchldrn (int **pidlst,int numchld,int sig); + +#endif /* DIOTEST_ROUTINES_H */
Signature · 1 line
2.1.4
PATCH 2/3 diotest4.c: Fixed filesystem
Test 3 & 14 were failing for BTRFS
so add TCONF for BTRFS
--- testcases/kernel/io/direct_io/diotest4.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
testcases/kernel/io/direct_io/diotest4.c +6 -7
@@ -68,7 +68,7 @@char *TCID ="diotest4" ;int TST_TOTAL =17 ; -int NO_NFS =1 ; +static long fs_type;#define BUFSIZE 4096#define TRUE 1
@@ -269,12 +269,12 @@ int main(int argc, char *argv[])lseek (fd, offset,SEEK_SET );if (write (fd, buf2,4096 ) ==-1 )tst_resm (TFAIL ,"can't write to file %d" , ret); -if (NO_NFS ) { +if (fs_type !=TST_NFS_MAGIC && fs_type !=TST_BTRFS_MAGIC ) { ret =runtest_f (fd, buf2, offset, count,EINVAL ,"odd count" );testcheck_end (ret, &failed, &fail_count,"Odd count of read and write" ); }else -tst_resm (TCONF ,"NFS support odd count IO" ); +tst_resm (TCONF ,"filesystem supports odd count IO" ); total++;/* Test-4: Read beyond the file size */
@@ -447,13 +447,13 @@ int main(int argc, char *argv[])tst_brkm (TBROK , cleanup,"can't open %s: %s" , filename,strerror (errno)); } -if (NO_NFS ) { +if (fs_type !=TST_NFS_MAGIC && fs_type !=TST_BTRFS_MAGIC ) { ret =runtest_f (fd, buf2 +1 , offset, count,EINVAL ," nonaligned buf" );testcheck_end (ret, &failed, &fail_count,"read, write with non-aligned buffer" ); }else -tst_resm (TCONF ,"NFS support read, write with non-aligned buffer" ); +tst_resm (TCONF ,"filesystem supports read, write with non-aligned buffer" );close (fd); total++;
@@ -573,8 +573,7 @@ static void setup(void)close (fd1); -if (tst_fs_type (cleanup,"." ) ==TST_NFS_MAGIC ) -NO_NFS =0 ; + fs_type =tst_fs_type (cleanup,"." ); }static void cleanup (void )
Signature · 1 line
2.1.4
PATCH 3/3 diotest5.c: replaced iovec
In reply to Cedric HnydaReplaced iovec pointers by normal buffers.
iovec were passed instead of expected buffers.
--- testcases/kernel/io/direct_io/diotest5.c | 54 +++++++++----------------------- 1 file changed, 14 insertions(+), 40 deletions(-)
testcases/kernel/io/direct_io/diotest5.c +14 -40
@@ -84,49 +84,30 @@ static void prg_usage(void);static int runtest (int fd_r,int fd_w,int iter,off64_t offset) {int i, bufsize =BUFSIZE ; -struct iovec *iov1, *iov2, *iovp;/* Allocate for buffers and data pointers */ - iov1 = (struct iovec *)valloc (sizeof (struct iovec ) * nvector); -if (iov1 ==NULL ) { -tst_resm (TFAIL ,"valloc() buf1 failed: %s" ,strerror (errno)); -return (-1 ); - } +char *buf1, *buf2; - iov2 = (struct iovec *)valloc (sizeof (struct iovec ) * nvector); -if (iov2 ==NULL ) { -tst_resm (TFAIL ,"valloc buf2 failed: %s" ,strerror (errno)); -return (-1 ); - } -for (i =0 , iovp = iov1; i < nvector; iovp++, i++) { - iovp->iov_base =valloc (bufsize); -if (iovp->iov_base ==NULL ) { -tst_resm (TFAIL ,"valloc for iovp->iov_base: %s" , -strerror (errno)); -return (-1 ); - } - iovp->iov_len = bufsize; - } -for (i =0 , iovp = iov2; i < nvector; iovp++, i++) { - iovp->iov_base =valloc (bufsize); -if (iovp->iov_base ==NULL ) { -tst_resm (TFAIL ,"valloc, iov2 for iovp->iov_base: %s" , -strerror (errno)); -return (-1 ); - } - iovp->iov_len = bufsize; + buf1 =valloc (bufsize); + buf2 =valloc (bufsize); + +if (!buf1 || !buf2) { +tst_resm (TBROK |TERRNO ,"valloc() failed" ); +free (buf1); +free (buf2); +return -1 ; }/* Test */ for (i =0 ; i < iter; i++) { -vfillbuf (iov1, nvector, i); -vfillbuf (iov2, nvector, i +1 ); +fillbuf (buf1, bufsize, i); +fillbuf (buf2, bufsize, i +1 );if (lseek (fd_w, offset,SEEK_SET ) <0 ) {tst_resm (TFAIL ,"lseek before writev failed: %s" ,strerror (errno));return (-1 ); } -if (writev (fd_w, iov1, nvector) <0 ) { +if (write (fd_w, buf1, bufsize) <0 ) {tst_resm (TFAIL ,"writev failed: %s" ,strerror (errno));return (-1 ); }
@@ -135,23 +116,16 @@ static int runtest(int fd_r, int fd_w, int iter, off64_t offset) strerror(errno));return (-1 ); } -if (readv (fd_r, iov2, nvector) <0 ) { +if (read (fd_r, buf2, bufsize) <0 ) {tst_resm (TFAIL ,"readv failed: %s" ,strerror (errno));return (-1 ); } -if (vbufcmp (iov1, iov2, nvector) !=0 ) { +if (bufcmp (buf1, buf2, bufsize) !=0 ) {tst_resm (TFAIL ,"readv/writev comparision failed" );return (-1 ); } } -/* Cleanup */ -for (i =0 , iovp = iov1; i < nvector; iovp++, i++) -free (iovp->iov_base); -for (i =0 , iovp = iov2; i < nvector; iovp++, i++) -free (iovp->iov_base); -free (iov1); -free (iov2);return 0 ; }
Signature · 1 line
2.1.4
PATCH 3/3 diotest5.c: replaced iovec
----- Original Message -----
Quoted 7 lines
From: "Cedric Hnyda" <[email protected]>
To: [email protected]
Sent: Thursday, 29 October, 2015 5:55:58 PM
Subject: [LTP] [PATCH 3/3]diotest5.c: replaced iovecReplaced iovec pointers by normal buffers.
iovec were passed instead of expected buffers.
What is the problem with iovecs here?
Isn't readv/writev meant to be used in this test?
* DESCRIPTION
* The programs test buffered and direct IO with vector arrays using
* readv() and writev() calls.
Regards,
Jan
Quoted 108 lines
Signed-off-by Cedric Hnyda <[email protected]>--- testcases/kernel/io/direct_io/diotest5.c | 54 +++++++++----------------------- 1 file changed, 14 insertions(+), 40 deletions(-)testcases/kernel/io/direct_io/diotest5.c +14
-41@@ -84,49 +84,30 @@ static void prg_usage(void);static int runtest (int fd_r,int fd_w,int iter,off64_t offset) {int i, bufsize =BUFSIZE ; -struct iovec *iov1, *iov2, *iovp;/* Allocate for buffers and data pointers */ - iov1 = (struct iovec *)valloc (sizeof (struct iovec ) * nvector); -if (iov1 ==NULL ) { -tst_resm (TFAIL ,"valloc() buf1 failed: %s" ,strerror (errno)); -return (-1 ); - } +char *buf1, *buf2; - iov2 = (struct iovec *)valloc (sizeof (struct iovec ) * nvector); -if (iov2 ==NULL ) { -tst_resm (TFAIL ,"valloc buf2 failed: %s" ,strerror (errno)); -return (-1 ); - } -for (i =0 , iovp = iov1; i < nvector; iovp++, i++) { - iovp->iov_base =valloc (bufsize); -if (iovp->iov_base ==NULL ) { -tst_resm (TFAIL ,"valloc for iovp->iov_base: %s" , -strerror (errno)); -return (-1 ); - } - iovp->iov_len = bufsize; - } -for (i =0 , iovp = iov2; i < nvector; iovp++, i++) { - iovp->iov_base =valloc (bufsize); -if (iovp->iov_base ==NULL ) { -tst_resm (TFAIL ,"valloc, iov2 for iovp->iov_base: %s" , -strerror (errno)); -return (-1 ); - } - iovp->iov_len = bufsize; + buf1 =valloc (bufsize); + buf2 =valloc (bufsize); + +if (!buf1 || !buf2) { +tst_resm (TBROK |TERRNO ,"valloc() failed" ); +free (buf1); +free (buf2); +return -1 ; }/* Test */ for (i =0 ; i < iter; i++) { -vfillbuf (iov1, nvector, i); -vfillbuf (iov2, nvector, i +1 ); +fillbuf (buf1, bufsize, i); +fillbuf (buf2, bufsize, i +1 );if (lseek (fd_w, offset,SEEK_SET ) <0 ) {tst_resm (TFAIL ,"lseek before writev failed: %s" ,strerror (errno));return (-1 ); } -if (writev (fd_w, iov1, nvector) <0 ) { +if (write (fd_w, buf1, bufsize) <0 ) {tst_resm (TFAIL ,"writev failed: %s" ,strerror (errno));return (-1 ); }@@ -135,23 +116,16 @@ static int runtest(int fd_r, int fd_w, int iter, off64_t offset) strerror(errno));return (-1 ); } -if (readv (fd_r, iov2, nvector) <0 ) { +if (read (fd_r, buf2, bufsize) <0 ) {tst_resm (TFAIL ,"readv failed: %s" ,strerror (errno));return (-1 ); } -if (vbufcmp (iov1, iov2, nvector) !=0 ) { +if (bufcmp (buf1, buf2, bufsize) !=0 ) {tst_resm (TFAIL ,"readv/writev comparision failed" );return (-1 ); } } -/* Cleanup */ -for (i =0 , iovp = iov1; i < nvector; iovp++, i++) -free (iovp->iov_base); -for (i =0 , iovp = iov2; i < nvector; iovp++, i++) -free (iovp->iov_base); -free (iov1); -free (iov2);return 0 ; } --2.1.4
--
Mailing list info: http://lists.linux.it/listinfo/ltp
PATCH 3/3 diotest5.c: replaced iovec
Quoted 6 lines · Jan Stancek
What is the problem with iovecs here?
Isn't readv/writev meant to be used in this test?* DESCRIPTION
* The programs test buffered and direct IO with vector arrays using
*readv()andwritev()calls.
My bad. You are right it is indeed irrelevant.
I misread something.
Best,
Cedric
Signature · 1 line
Cedric Hnyda
PATCH 1/3 diotest: cleanup & fix
In reply to Cedric HnydaHi!
Quoted 31 lines
testcases/kernel/io/direct_io/diotest1.c +5
-5+static void fail_clean (int fd1,int fd2,char *infile,char *outfile) {close (fd1);close (fd2);@@ -98,7 +93,8 @@ int main(int argc, char *argv[])while ((i =getopt (argc, argv,"b:n:i:o:" )) !=-1 ) {switch (i) {case 'b' : -if ((bufsize =atoi (optarg)) <=0 ) { + bufsize =atoi (optarg); +if (bufsize <=0 ) {fprintf (stderr,"bufsize must be > 0\n" );prg_usage (); }@@ -109,7 +105,8 @@ int main(int argc, char *argv[]) }break ;case 'n' : -if ((numblks =atoi (optarg)) <=0 ) { + numblks =atoi (optarg); +if (numblks <=0 ) {fprintf (stderr,"numblks must be > 0\n" );prg_usage (); }@@ -126,21 +123,25 @@ int main(int argc, char *argv[]) }/* Test for filesystem support of O_DIRECT */ -if ((fd =open (infile,O_DIRECT |O_RDWR |O_CREAT ,0666 )) <0 ) { - tst_brkm(TCONF, - NULL,
testcases/kernel/io/direct_io/diotest1.c int main(int argc, char *argv[]) · line 131
Quoted 10 lines
testcases/kernel/io/direct_io/diotest1.c +6
-4- "O_DIRECT is not supported by this filesystem."); - }else { -close (fd); - } + fd =open (infile,O_DIRECT |O_RDWR |O_CREAT ,0666 ); +if (fd <0 && errno ==EINVAL ) +tst_brkm (TCONF ,NULL , +"O_DIRECT is not supported by this filesystem. %s" , +strerror (errno)); +else if (fd <0 )
Well LKML coding style preffers to have curly braces if the statement spans across multiple lines, even if it's one function call. Not that this is a big problem, we have quite a lot of code that does not reflect that.
testcases/kernel/io/direct_io/diotest1.c int main(int argc, char *argv[]) · line 141
Quoted 11 lines
testcases/kernel/io/direct_io/diotest1.c +5
-1+tst_brkm (TBROK ,NULL ,"Couldn't open test file %s: %s" , + infile,strerror (errno)); +close (fd);/* Open files */ -if ((fd1 =open (infile,O_DIRECT |O_RDWR |O_CREAT ,0666 )) <0 ) { + fd1 =open (infile,O_DIRECT |O_RDWR |O_CREAT ,0666 ); +if (fd1 <0 ) {tst_brkm (TFAIL ,NULL ,"open infile failed: %s" ,strerror (errno)); }
Can you pretty please change all the open statements into to SAFE_OPEN()?
You would have to convert the fail_clean() into cleanup() without any parameters (make fd1, fd2 global...) in this case but that shouldn't be that hard...
Otherwise the changes looks good.
Signature · 2 lines
Cyril Hrubis [email protected]