Rewrite fs stream testing suite
cover Rewrite fs stream testing suite
All tests are now using the new LTP API. The stream05 has been deleted because I think it was a bit messy and it didn't have a proper testing focus. I replaced it with a new test that is just verifying that fd returned by fileno() can be used for basic operations on fd.
---
Andrea Cervesato (6):
Add safe macros for stream testing suite
fs: rewrite stream01 test using new API
fs: rewrite stream02 test using new API
fs: rewrite stream03 test using new API
fs: rewrite stream04 test using new API
fs: rewrite stream05 test using new API
include/safe_stdio_fn.h | 18 ++ include/tst_safe_stdio.h | 18 ++ lib/safe_stdio.c | 87 +++++++++ testcases/kernel/fs/stream/stream01.c | 153 +++++----------- testcases/kernel/fs/stream/stream02.c | 133 +++----------- testcases/kernel/fs/stream/stream03.c | 326 ++++++---------------------------- testcases/kernel/fs/stream/stream04.c | 147 +++++---------- testcases/kernel/fs/stream/stream05.c | 256 +++++--------------------- 8 files changed, 332 insertions(+), 806 deletions(-)
---
base-commit: c47ab95d5fe077133e598ac7762387450a87cb2b
change-id: 20260120-stream_refactoring-4b5a6e9d0ad7
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 1/6 Add safe macros for stream testing suite
From: Andrea Cervesato <[email protected]>
Introduce the following SAFE_* macros for stream file testing:
- SAFE_FREAD
- SAFE_FWRITE
- SAFE_FREOPEN
- SAFE_FSEEK
- SAFE_FTELL
- SAFE_FILENO
--- include/safe_stdio_fn.h | 18 ++++++++++ include/tst_safe_stdio.h | 18 ++++++++++ lib/safe_stdio.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+)
include/safe_stdio_fn.h +18 -0
@@ -32,4 +32,22 @@ int safe_asprintf(const char *file, const int lineno, void (cleanup_fn)(void),FILE *safe_popen (const char *file,const int lineno,void (cleanup_fn )(void ),const char *command,const char *type); +size_t safe_fread (const char *file,const int lineno,void (cleanup_fn )(void ), +void *ptr,size_t size,size_t n,FILE *stream); + +size_t safe_fwrite (const char *file,const int lineno,void (cleanup_fn )(void ), +const void *ptr,size_t size,size_t n,FILE *stream); + +FILE *safe_freopen (const char *file,const int lineno,void (cleanup_fn )(void ), +const char *path,const char *mode,FILE *stream); + +int safe_fseek (const char *file,const int lineno,void (cleanup_fn )(void ), +FILE *f,long offset,int whence); + +long safe_ftell (const char *file,const int lineno,void (cleanup_fn )(void ), +FILE *f); + +int safe_fileno (const char *file,const int lineno,void (cleanup_fn )(void ), +FILE *stream); +#endif /* SAFE_STDIO_FN_H__ */
include/tst_safe_stdio.h +18 -0
@@ -21,4 +21,22 @@#define SAFE_POPEN (command, type) \ safe_popen(__FILE__, __LINE__, NULL, command, type) +#define SAFE_FREAD (ptr, size, n, stream) \ + safe_fread(__FILE__, __LINE__, NULL, ptr, size, n, stream) + +#define SAFE_FWRITE (ptr, size, n, stream) \ + safe_fwrite(__FILE__, __LINE__, NULL, ptr, size, n, stream) + +#define SAFE_FREOPEN (path, mode, stream) \ + safe_freopen(__FILE__, __LINE__, NULL, path, mode, stream) + +#define SAFE_FSEEK (f, offset, whence) \ + safe_fseek(__FILE__, __LINE__, NULL, f, offset, whence) + +#define SAFE_FTELL (f) \ + safe_ftell(__FILE__, __LINE__, NULL, f) + +#define SAFE_FILENO (f) \ + safe_fileno(__FILE__, __LINE__, NULL, f) +#endif /* TST_SAFE_STDIO_H__ */
lib/safe_stdio.c +87 -0
90 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] Add safe macros for stream testing suite
Hi!
Quoted 31 lines
Introduce the following SAFE_* macros for stream file testing:
-
SAFE_FREAD
-SAFE_FWRITE
-SAFE_FREOPEN
-SAFE_FSEEK
-SAFE_FTELL
-SAFE_FILENOSigned-off-by Andrea Cervesato <[email protected]>--- include/safe_stdio_fn.h | 18 ++++++++++ include/tst_safe_stdio.h | 18 ++++++++++ lib/safe_stdio.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+)include/safe_stdio_fn.h +7
-0@@ -32,4 +32,22 @@ int safe_asprintf(const char *file, const int lineno, void (cleanup_fn)(void),FILE *safe_popen (const char *file,const int lineno,void (cleanup_fn )(void ),const char *command,const char *type); +size_t safe_fread (const char *file,const int lineno,void (cleanup_fn )(void ), +void *ptr,size_t size,size_t n,FILE *stream); + +size_t safe_fwrite (const char *file,const int lineno,void (cleanup_fn )(void ), +const void *ptr,size_t size,size_t n,FILE *stream); + +FILE *safe_freopen(const char *file, const int lineno, void (cleanup_fn)(void),
include/safe_stdio_fn.h int safe_asprintf(const char *file, const int lineno, void (cleanup_fn)(void), · line 51
Quoted 10 lines
include/safe_stdio_fn.h +10
-0+ const char *path, const char *mode, FILE *stream); + +int safe_fseek (const char *file,const int lineno,void (cleanup_fn )(void ), +FILE *f,long offset,int whence); + +long safe_ftell (const char *file,const int lineno,void (cleanup_fn )(void ), +FILE *f); + +int safe_fileno (const char *file,const int lineno,void (cleanup_fn )(void ), +FILE *stream);
Newly added safe macros shouldn't add the cleanup_fn parameter, that is kept only in the legacy macros that are stil used in the old library tests.
Otherwise: Reviewed-by: Cyril Hrubis <[email protected]>
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] Add safe macros for stream testing suite
Hi!
Quoted 4 lines
Newly added safe macros shouldn't add the
cleanup_fnparameter, that is kept only in the legacy macros that are stil used in the old library tests.
The problem is that I don't know how to approach it, since the header is correct, but we also have tso_safe_stdio.h and there's a mix of old implementations/new implementations mixing together into tst_kernel.c.
I'm a bit puzzled. The point would be to move evrything in the new API, including the core library.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] Add safe macros for stream testing suite
Hi!
Quoted 7 lines
Quoted 3 lines
Newly added safe macros shouldn't add the
cleanup_fnparameter, that is kept only in the legacy macros that are stil used in the old library tests.The problem is that I don't know how to approach it, since the header is correct, but we also have
tso_safe_stdio.hand there's a mix of old implementations/new implementations mixing together intotst_kernel.c.
Just do not add the cleanup_fn parameter to the new functions 1added there. That's all I ask for here.
Quoted 2 lines
I'm a bit puzzled. The point would be to move evrything in the new API, including the core library.
Well we can't until there are old tests using the old library left.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] Add safe macros for stream testing suite
Quoted 3 lines
Just do not add the
cleanup_fnparameter to the new functions 1added there. That's all I ask for here.
But their implementations inside safe_stdio.c requires the old test.h header. Should I move them somewhere else?
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] Add safe macros for stream testing suite
Hi!
Quoted 6 lines
Quoted 3 lines
Just do not add the
cleanup_fnparameter to the new functions 1added there. That's all I ask for here.But their implementations inside
safe_stdio.crequires the oldtest.hheader. Should I move them somewhere else?
Just pass NULL to the tst_resm() and tst_brkm().
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 1/6] Add safe macros for stream testing suite
In reply to Cyril HrubisQuoted 2 lines
Otherwise: Reviewed-by: Cyril Hrubis <[email protected]>
Just one thing about the tag: be aware that b4 trailers -u -S command that updates all tags trailers inside commit messages will use Otherwise: as a tag (lol).
The best way is to keep trailers in a new line.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/6 fs: rewrite stream01 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream01.c | 153 ++++++++++------------------------ 1 file changed, 46 insertions(+), 107 deletions(-)
testcases/kernel/fs/stream/stream01.c +46 -107
@@ -1,127 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* +* Copyright (c) International Business Machines Corp., 2002 +* ported from SPIE section2/filesuite/stream1.c, by Airong Zhang * -* Copyright (c) International Business Machines Corp., 2002 -* -* 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. +* Copyright (c) 2026 Andrea Cervesato <[email protected]> +*/ + +/*\ +* Verify that `freopen()` substitutes the named file in place of stream. * -* 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. +* [Algorithm] * -* 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 +* - fopen() a stream +* - fwrite() something inside it +* - perform freopen() creating a new stream pointing to the first one +* - fwrite() data inside the new stream +* - check that second write to stream went to the file specified by freopen() */ -/* ported from SPIE section2/filesuite/stream1.c, by Airong Zhang */ +#include "tst_test.h" +#include "tst_safe_stdio.h" -/*====================================================================== -=================== TESTPLAN SEGMENT =================== ->KEYS: < freopen() ->WHAT: < 1) check that freopen substitutes the named file in place of stream. ->HOW: < 1) open a stream, write something to it, perform freopen and -< write some more. Check that second write to stream went to -< the file specified by freopen. ->BUGS: < -======================================================================*/ +#define FILENAME1 "ltp_file1.txt" +#define FILENAME2 "ltp_file2.txt" -#include <stdio.h> -#include <errno.h> -#include "test.h" - -char *TCID ="stream01" ; -int TST_TOTAL =1 ; -int local_flag; +static void read_file (const char *file) +{ +char buf[2 ]; +FILE *stream; -#define PASSED 1 -#define FAILED 0 +memset (buf,0 ,sizeof (buf)); -/* XXX: add setup and cleanup. */ + stream =SAFE_FOPEN (file,"r" ); +SAFE_FREAD (buf,1 ,1 , stream); +SAFE_FCLOSE (stream); -char progname[] ="stream01()" ; -char tempfile1[40 ] ="" ; -char tempfile2[40 ] ="" ; +TST_EXP_EXPR ((buf[0 ] =='a' ) && (buf[1 ] ==0 ), +"%s file contains the correct data" , file); +} -/*--------------------------------------------------------------------*/ -int main (int ac,char *av[]) +static void run (void ) {FILE *stream; -char buf[10 ]; -int i; -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - local_flag =PASSED ; -tst_tmpdir (); -for (lc =0 ;TEST_LOOPING (lc); lc++) { +tst_res (TINFO ,"Write %s file" ,FILENAME1 ); + stream =SAFE_FOPEN (FILENAME1 ,"a+" ); +SAFE_FWRITE ("a" ,1 ,1 , stream); -sprintf (tempfile1,"stream011.%d" ,getpid ()); -sprintf (tempfile2,"stream012.%d" ,getpid ()); -/*--------------------------------------------------------------------*/ -//block0: -if ((stream =fopen (tempfile1,"a+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) a+ failed: %s" , - tempfile1, -strerror (errno)); - } -fwrite ("a" ,1 ,1 , stream); -if ((stream =freopen (tempfile2,"a+" , stream)) ==NULL ) { -tst_brkm (TFAIL |TERRNO ,NULL ,"freopen(%s) a+ failed" , - tempfile2); - } -fwrite ("a" ,1 ,1 , stream); -fclose (stream); +tst_res (TINFO ,"Write %s file streaming into %s file" ,FILENAME2 ,FILENAME1 ); + stream =SAFE_FREOPEN (FILENAME2 ,"a+" , stream); +SAFE_FWRITE ("a" ,1 ,1 , stream); -/* now check that a single "a" is in each file */ -if ((stream =fopen (tempfile1,"r" )) ==NULL ) { -tst_brkm (TFAIL |TERRNO ,NULL ,"fopen(%s) r failed" , - tempfile1); - }else { -for (i =0 ; i <10 ; i++) - buf[i] =0 ; -fread (buf,1 ,1 , stream); -if ((buf[0 ] !='a' ) || (buf[1 ] !=0 )) { -tst_resm (TFAIL ,"bad contents in %s" , - tempfile1); - local_flag =FAILED ; - } -fclose (stream); - } -if ((stream =fopen (tempfile2,"r" )) ==NULL ) { -tst_brkm (TFAIL |TERRNO ,NULL ,"fopen(%s) r failed" , - tempfile2); - }else { -for (i =0 ; i <10 ; i++) - buf[i] =0 ; -fread (buf,1 ,1 , stream); -if ((buf[0 ] !='a' ) || (buf[1 ] !=0 )) { -tst_resm (TFAIL ,"bad contents in %s" , - tempfile2); - local_flag =FAILED ; - } -fclose (stream); - } -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed." ); - }else { -tst_resm (TFAIL ,"Test failed." ); - } +SAFE_FCLOSE (stream); - local_flag =PASSED ; +read_file (FILENAME1 ); +read_file (FILENAME2 ); -/*--------------------------------------------------------------------*/ -unlink (tempfile1); -unlink (tempfile2); - - }/* end for */ -tst_rmdir (); -tst_exit (); +SAFE_UNLINK (FILENAME1 ); +SAFE_UNLINK (FILENAME2 ); } + +static struct tst_test test = { + .test_all = run, + .needs_tmpdir =1 , +};
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/6] fs: rewrite stream01 test using new API
Hi!
Quoted 5 lines
testcases/kernel/fs/stream/stream01.c +2
-3-char *TCID ="stream01" ; -int TST_TOTAL =1 ; -int local_flag; +static void read_file (const char *file) +{
testcases/kernel/fs/stream/stream01.c line 35
Quoted 10 lines
testcases/kernel/fs/stream/stream01.c +5
-3+char buf[2 ]; +FILE *stream; -#define PASSED 1 -#define FAILED 0 +memset (buf,0 ,sizeof (buf)); -/* XXX: add setup and cleanup. */ + stream =SAFE_FOPEN (file,"r" ); +SAFE_FREAD (buf,1 ,1 , stream);
Here we read at most 1 character from the stream.
testcases/kernel/fs/stream/stream01.c line 38
Quoted 6 lines
testcases/kernel/fs/stream/stream01.c +2
-3+SAFE_FCLOSE (stream); -char progname[] ="stream01()" ; -char tempfile1[40 ] ="" ; -char tempfile2[40 ] ="" ; + TST_EXP_EXPR((buf[0] == 'a') && (buf[1] == 0),
^
Hence this is always true
testcases/kernel/fs/stream/stream01.c line 39
Quoted 1 line
testcases/kernel/fs/stream/stream01.c +1
-0+ "%s file contains the correct data", file);
If we wanted to assert that the file has a single characted written into it we need to let the fread() read the whole buffer:
SAFE_FREAD(buf, 2, 1, stream);
With that there is at least chance that the buf[1] may be overwritten with some data.
Or we can check the size returned from fread(), if it was 1 there was a single characted in the file. But again, we have to pass buffer that is at least 2 bytes long.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 3/6 fs: rewrite stream02 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream02.c | 133 ++++++++-------------------------- 1 file changed, 29 insertions(+), 104 deletions(-)
testcases/kernel/fs/stream/stream02.c +29 -104
@@ -1,119 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* +* Copyright (c) International Business Machines Corp., 2002 +* ported from SPIE section2/filesuite/stream2.c, by Airong Zhang * -* Copyright (c) International Business Machines Corp., 2002 -* -* 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 +* Copyright (c) 2026 Andrea Cervesato <[email protected]> */ -/* ported from SPIE section2/filesuite/stream2.c, by Airong Zhang */ - -/*====================================================================== -=================== TESTPLAN SEGMENT =================== ->KEYS: < fseek() mknod() fopen() ->WHAT: < 1) ->HOW: < 1) ->BUGS: < -======================================================================*/ - -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "test.h" -char *TCID ="stream02" ; -int TST_TOTAL =1 ; -int local_flag; +/*\ +* Verify that it's possible to `fopen()` a file that has been created by +* `mknod()` using different modes. +*/ -#define PASSED 1 -#define FAILED 0 +#include "tst_test.h" +#include "tst_safe_stdio.h" -char progname[] ="stream02()" ; -char tempfile1[40 ] ="" ; +#define FILENAME "ltp_file_node" -/* XXX: add cleanup + setup. */ +static const char *const modes[] = { +"r+" , +"w+" , +"a+" , +}; -/*--------------------------------------------------------------------*/ -int main (int ac,char *av[]) +static void run (void ) {FILE *stream; -int fd; -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - local_flag =PASSED ; -tst_tmpdir (); +SAFE_MKNOD (FILENAME , (S_IFIFO |0666 ),0 ); -for (lc =0 ;TEST_LOOPING (lc); lc++) { +for (size_t i =0 ; i <ARRAY_SIZE (modes); i++) { + stream =SAFE_FOPEN (FILENAME , modes[i]); +SAFE_FCLOSE (stream); -sprintf (tempfile1,"stream1.%d" ,getpid ()); -/*--------------------------------------------------------------------*/ -//block0: -if (mknod (tempfile1, (S_IFIFO |0666 ),0 ) !=0 ) { -tst_resm (TFAIL ,"mknod failed in block0: %s" , -strerror (errno)); - local_flag =FAILED ; - goto block1; - } -if ((stream =fopen (tempfile1,"w+" )) ==NULL ) { -tst_resm (TFAIL ,"fopen(%s) w+ failed for pipe file: %s" , - tempfile1,strerror (errno)); - local_flag =FAILED ; - }else { -fclose (stream); - } -if ((stream =fopen (tempfile1,"a+" )) ==NULL ) { -tst_resm (TFAIL ,"fopen(%s) a+ failed: %s" , tempfile1, -strerror (errno)); - local_flag =FAILED ; - }else { -fclose (stream); -unlink (tempfile1); - } -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block0." ); - }else { -tst_resm (TFAIL ,"Test failed in block0." ); - } - local_flag =PASSED ; +tst_res (TPASS ,"Opened file using '%s' mode" , modes[i]); + } -/*--------------------------------------------------------------------*/ -block1: -if ((fd =open ("/dev/tty" ,O_WRONLY )) >=0 ) { -close (fd); -if ((stream =fopen ("/dev/tty" ,"w" )) ==NULL ) { -tst_resm (TFAIL |TERRNO , -"fopen(/dev/tty) write failed" ); - local_flag =FAILED ; - }else { -fclose (stream); - } - } -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block1." ); - }else { -tst_resm (TFAIL ,"Test failed in block1." ); - } - -/*--------------------------------------------------------------------*/ - }/* end for */ -tst_rmdir (); -tst_exit (); +SAFE_UNLINK (FILENAME ); } + +static struct tst_test test = { + .test_all = run, + .needs_tmpdir =1 , +};
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 3/6] fs: rewrite stream02 test using new API
Hi!
testcases/kernel/fs/stream/stream02.c line 32
Quoted 2 lines
testcases/kernel/fs/stream/stream02.c +2
-0+for (size_t i =0 ; i <ARRAY_SIZE (modes); i++) { + stream =SAFE_FOPEN (FILENAME , modes[i]);
This will TBROK instead of TFAIL if the open fails.
Maybe we need:
#define TST_EXP_PASS_PTR_NULL(SCALL, ...) \ TST_EXP_PASS_PTR_(SCALL, #SCALL, NULL, ##__VA_ARGS__)
So that we can use that as:
TST_EXP_PASS_PTR_NULL(fopen(FILENAME, modes[i]); if (TST_PASS) SAFE_FCLOSE(TST_RET_PTR);
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 4/6 fs: rewrite stream03 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream03.c | 326 ++++++---------------------------- 1 file changed, 50 insertions(+), 276 deletions(-)
testcases/kernel/fs/stream/stream03.c +50 -276
@@ -1,297 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* +* Copyright (c) International Business Machines Corp., 2002 +* ported from SPIE, section2/filesuite/stream3.c, by Airong Zhang * -* Copyright (c) International Business Machines Corp., 2002 -* -* 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 +* Copyright (c) 2026 Andrea Cervesato <[email protected]> */ -/* ported from SPIE, section2/filesuite/stream3.c, by Airong Zhang */ - -/*====================================================================== -=================== TESTPLAN SEGMENT =================== ->KEYS: < fseek() ftell() ->WHAT: < 1) Ensure ftell reports the correct current byte offset. ->HOW: < 1) Open a file, write to it, reposition the file pointer and -check it. ->BUGS: < -======================================================================*/ -#define _XOPEN_SOURCE 500 -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <inttypes.h> -#include "test.h" +/*\ +* Verify that `ftell()` reports the correct current byte offset after +* moving it. +*/ -char *TCID ="stream03" ; -int TST_TOTAL =1 ; -int local_flag; +#include "tst_test.h" +#include "tst_rand_data.h" +#include "tst_safe_stdio.h" -#define PASSED 1 -#define FAILED 0 +#define FILENAME "ltp_file" +#define DATASIZE 30 +#define BUFFSIZE 10 -char progname[] ="stream03()" ; -char tempfile1[40 ] ="" ; +static char *data; +static char *buff; -int main (int ac,char *av[]) +static void run (void ) {FILE *stream; -char buf[30 ]; -char *junk ="abcdefghijklmnopqrstuvwxyz" ; -long pos; -off_t opos; -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); - - local_flag =PASSED ; -tst_tmpdir (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - -sprintf (tempfile1,"stream03.%d" ,getpid ()); -/*--------------------------------------------------------------------*/ -//block0: - -if ((stream =fopen (tempfile1,"a+" )) ==NULL ) { -tst_brkm (TBROK ,NULL ,"fopen(%s) a+ failed: %s" , - tempfile1, -strerror (errno)); - } - -/* make sure offset of zero at start */ - pos =ftell (stream); - -if (pos !=0 ) { -tst_resm (TFAIL ,"file pointer descrepancy 1" ); - local_flag =FAILED ; - } - -/* write something and check */ -if (fwrite (junk,sizeof (*junk),strlen (junk), stream) ==0 ) { -tst_brkm (TFAIL ,NULL ,"fwrite failed: %s" , -strerror (errno)); - } - - pos =ftell (stream); - -if (pos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 2 (pos=%li)" , -strlen (junk), pos); - local_flag =FAILED ; - } - -/* rewind and check */ -rewind (stream); - pos =ftell (stream); - -if (pos !=0 ) { -tst_resm (TFAIL , -"file pointer descrepancy 3 (pos=%li, wanted pos=0)" , - pos); - local_flag =FAILED ; - } - -/* seek from current position and then check */ -if (fseek (stream,strlen (junk),1 ) !=0 ) { -tst_brkm (TFAIL ,NULL ,"fseek failed: %s" , -strerror (errno)); - } - - pos =ftell (stream); - -if (pos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 4 (pos=%li)" , -strlen (junk), pos); - local_flag =FAILED ; - } - -/* seek from end of file and then check */ -if (fseek (stream,0 ,2 ) !=0 ) { -tst_brkm (TFAIL ,NULL ,"fseek failed: %s" , -strerror (errno)); - } - - pos =ftell (stream); - -if (pos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 5 (pos=%li)" , -strlen (junk), pos); - local_flag =FAILED ; - } - -/* rewind with seek and then check */ -if (fseek (stream,0 ,0 ) !=0 ) { -tst_brkm (TFAIL ,NULL ,"fseek failed: %s" , -strerror (errno)); - } - pos =ftell (stream); +memset (buff,0 ,BUFFSIZE ); -if (pos !=0 ) { -tst_resm (TFAIL , -"file pointer descrepancy 6 (pos=%li, wanted pos=0)" , - pos); - local_flag =FAILED ; - } + stream =SAFE_FOPEN (FILENAME ,"a+" ); +TST_EXP_EQ_LI (SAFE_FTELL (stream),0 ); -/* read till EOF, do getc and then check ftell */ -while (fgets (buf,sizeof (buf), stream)) ; - pos =ftell (stream); -getc (stream); - pos =ftell (stream); +SAFE_FWRITE (data,1 ,DATASIZE , stream); +TST_EXP_EQ_LI (SAFE_FTELL (stream),DATASIZE ); -if (pos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 7 (pos=%li)" , -strlen (junk), pos); - local_flag =FAILED ; - } +rewind (stream); +TST_EXP_EQ_LI (SAFE_FTELL (stream),SEEK_SET ); -fclose (stream); +SAFE_FSEEK (stream,10 ,SEEK_CUR ); +TST_EXP_EQ_LI (SAFE_FTELL (stream),10 ); -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block0." ); - }else { -tst_resm (TFAIL ,"Test failed in block0." ); - } +SAFE_FSEEK (stream,0 ,SEEK_END ); +TST_EXP_EQ_LI (SAFE_FTELL (stream),DATASIZE ); - local_flag =PASSED ; +SAFE_FSEEK (stream,0 ,SEEK_SET ); +TST_EXP_EQ_LI (SAFE_FTELL (stream),0 ); -unlink (tempfile1); -/*--------------------------------------------------------------------*/ -//block1: -if ((stream =fopen (tempfile1,"a+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) a+ failed: %s" , - tempfile1, -strerror (errno)); - } +while (fgets (buff,BUFFSIZE , stream)) + ; +TST_EXP_EQ_LI (SAFE_FTELL (stream),DATASIZE ); -/* make sure offset of zero at start */ - opos =ftello (stream); - -if (opos !=0 ) { -tst_resm (TFAIL , -"file pointer descrepancy 1 (opos=%" PRId64 -", wanted opos=0)" , (int64_t ) opos); - local_flag =FAILED ; - } - -/* write something and check */ -if (fwrite (junk,sizeof (*junk),strlen (junk), stream) ==0 ) { -tst_brkm (TFAIL ,NULL ,"fwrite failed: %s" , -strerror (errno)); - } - - opos =ftello (stream); - -if (opos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 2 (opos=%" - PRId64")" ,strlen (junk), (int64_t ) opos); - local_flag =FAILED ; - } - -/* rewind and check */ -rewind (stream); - opos =ftello (stream); - -if (opos !=0 ) { -tst_resm (TFAIL , -"file pointer descrepancy 3 (opos=%" PRId64 -", wanted opos=0)" , (int64_t ) opos); - local_flag =FAILED ; - } - -/* seek from current position and then check */ -if (fseeko (stream,strlen (junk),1 ) !=0 ) { -tst_brkm (TFAIL ,NULL ,"fseeko failed: %s" , -strerror (errno)); - } - - opos =ftello (stream); - -if (opos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 4 (opos=%" - PRId64")" ,strlen (junk), (int64_t ) opos); - local_flag =FAILED ; - } - -/* seek from end of file and then check */ -if (fseeko (stream,0 ,2 ) !=0 ) { -tst_brkm (TFAIL ,NULL ,"fseeko failed: %s" , -strerror (errno)); - } - - opos =ftello (stream); - -if (opos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 5 (opos=%" - PRId64")" ,strlen (junk), (int64_t ) opos); - local_flag =FAILED ; - } - -/* rewind with seek and then check */ -if (fseeko (stream,0 ,0 ) !=0 ) { -tst_brkm (TFAIL ,NULL ,"fseeko failed: %s" , -strerror (errno)); - } - - opos =ftello (stream); - -if (opos !=0 ) { -tst_resm (TFAIL , -"file pointer descrepancy 6 (opos=%" PRId64 -", wanted opos=0)" , (int64_t ) opos); - local_flag =FAILED ; - } - -/* read till EOF, do getc and then check ftello */ -while (fgets (buf,sizeof (buf), stream)) ; - - opos =ftello (stream); -getc (stream); - opos =ftello (stream); - -if (opos !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk)=%zi: file pointer descrepancy 7 (opos=%li)" , -strlen (junk), opos); - local_flag =FAILED ; - } - -fclose (stream); - -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block1." ); - }else { -tst_resm (TFAIL ,"Test failed in block1." ); - } - -unlink (tempfile1); - } +SAFE_FCLOSE (stream); +SAFE_UNLINK (FILENAME ); +} -tst_rmdir (); -tst_exit (); +static void setup (void ) +{ +memcpy (data, tst_rand_data,DATASIZE ); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_tmpdir =1 , + .bufs = (struct tst_buffers []) { + {&data, .size =DATASIZE }, + {&buff, .size =BUFFSIZE }, + {}, + }, +};
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 4/6] fs: rewrite stream03 test using new API
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 5/6 fs: rewrite stream04 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream04.c | 147 +++++++++------------------------- 1 file changed, 40 insertions(+), 107 deletions(-)
testcases/kernel/fs/stream/stream04.c +40 -107
@@ -1,124 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* +* Copyright (c) International Business Machines Corp., 2002 +* ported from SPIE, section2/filesuite/stream4.c, by Airong Zhang * -* Copyright (c) International Business Machines Corp., 2002 -* -* 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 +* Copyright (c) 2026 Andrea Cervesato <[email protected]> */ -/* Ported from SPIE, section2/iosuite/stream4.c, by Airong Zhang */ - -/*====================================================================== -=================== TESTPLAN SEGMENT =================== ->KEYS: < fwrite() fread() ->WHAT: < 1) Ensure fwrite appends data to stream. -< 2) Ensure fread and fwrite return values are valid. ->HOW: < 1) Open a file, write to it, and then check it. -< 2) Fwrite a know quanity, check return value. -< Fread a know quanity, check return value. ->BUGS: < -======================================================================*/ - -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include "test.h" - -char *TCID ="stream04" ; -int TST_TOTAL =1 ; -int local_flag; +/*\ +* Ensure that `fwrite()` is appending data to stream and `fread()` +* `fwrite()` are returning the right data. +*/ -#define PASSED 1 -#define FAILED 0 +#include "tst_test.h" +#include "tst_safe_stdio.h" -char progname[] ="stream04()" ; -char tempfile1[40 ] ="" ; -long ftell (); +#define FILENAME "ltp_file" +#define DATA "abcdefghijklmnopqrstuvwxyz" +#define DATASIZE sizeof(DATA) -/* XXX: add setup and cleanup */ +static char *data; +static char *buff; -/*--------------------------------------------------------------------*/ -int main (int ac,char *av[]) +static void run (void ) {FILE *stream; -char *junk ="abcdefghijklmnopqrstuvwxyz" ; -char *inbuf; -int ret; -int lc; +memset (buff,0 ,DATASIZE ); -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); -tst_tmpdir (); -for (lc =0 ;TEST_LOOPING (lc); lc++) { + stream =SAFE_FOPEN (FILENAME ,"a+" ); +TST_EXP_EQ_LI (fwrite (data,1 ,DATASIZE , stream),DATASIZE ); +SAFE_FCLOSE (stream); - local_flag =PASSED ; + stream =SAFE_FOPEN (FILENAME ,"r+" ); +TST_EXP_EQ_LI (fread (buff,1 ,DATASIZE , stream),DATASIZE ); +SAFE_FCLOSE (stream); -sprintf (tempfile1,"stream04.%d" ,getpid ()); -/*--------------------------------------------------------------------*/ -//block0: -if ((stream =fopen (tempfile1,"a+" )) ==NULL ) { -tst_brkm (TFAIL |TERRNO , tst_rmdir,"fopen(%s) a+ failed" , - tempfile1); - } -/* write something and check */ -if ((ret = -fwrite (junk,sizeof (*junk),strlen (junk), stream)) ==0 ) { -tst_brkm (TFAIL , tst_rmdir,"fwrite failed: %s" , -strerror (errno)); - } +SAFE_UNLINK (FILENAME ); -if ((size_t ) ret !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk) = %zi != return value from fwrite = %zi" , -strlen (junk), ret); - local_flag =FAILED ; - } +TST_EXP_EQ_STRN (data, buff,DATASIZE ); +} -fclose (stream); -if ((stream =fopen (tempfile1,"r+" )) ==NULL ) { -tst_brkm (TFAIL , tst_rmdir,"fopen(%s) r+ failed: %s" , tempfile1, -strerror (errno)); - } -if ((inbuf =malloc (strlen (junk))) ==0 ) { -tst_brkm (TBROK , tst_rmdir,"test failed because of malloc: %s" , -strerror (errno)); - } -if ((ret = -fread (inbuf,sizeof (*junk),strlen (junk), stream)) ==0 ) { -tst_brkm (TFAIL , tst_rmdir,"fread failed: %s" , -strerror (errno)); - } -if ((size_t ) ret !=strlen (junk)) { -tst_resm (TFAIL , -"strlen(junk) = %zi != return value from fread = %zi" , -strlen (junk), ret); - local_flag =FAILED ; - } -fclose (stream); -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed." ); - }else { -tst_resm (TFAIL ,"Test failed." ); - } -/*--------------------------------------------------------------------*/ -unlink (tempfile1); - }/* end for */ -tst_rmdir (); -tst_exit (); +static void setup (void ) +{ +memcpy (data,DATA ,DATASIZE ); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_tmpdir =1 , + .bufs = (struct tst_buffers []) { + {&data, .size =DATASIZE }, + {&buff, .size =DATASIZE }, + {}, + }, +};
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 5/6] fs: rewrite stream04 test using new API
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 6/6 fs: rewrite stream05 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream05.c | 256 ++++++---------------------------- 1 file changed, 44 insertions(+), 212 deletions(-)
testcases/kernel/fs/stream/stream05.c +44 -212
@@ -1,230 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* -* Copyright (c) International Business Machines Corp., 2002 -* -* 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 +* Copyright (c) 2026 Andrea Cervesato <[email protected]> */ -/* ported from SPIE, section2/filesuite/stream.c, by Airong Zhang */ - -/*====================================================================== -=================== TESTPLAN SEGMENT =================== ->KEYS: < ferror() feof() clearerr() fileno() ->WHAT: < 1) check that ferror returns zero -< 2) check fileno returns valid file descriptor -< 3) check that feof returns zero (nonzero) appropriately -< 4) check that clearerr resets EOF indicator. ->HOW: < 1) open a stream and immediately execute ferror -< 2) use the file des returned from fileno to read a file -< written with stream - compare actual vs expected. -< 3) open stream and ensure feof returns zero, read to end of -< file and ensure feof returns non-zero. -< 4) after 3) above use clearerr and then use feof to ensure -< clearerr worked ->BUGS: < -======================================================================*/ - -#include <unistd.h> -#include <stdio.h> -#include <errno.h> -#include "test.h" +/*\ +* Verify that it's possible to read/write on a file descriptor returned by +* `fileno()` and to close it, leaving `fclose()` to raise EBADF error. +*/ -char *TCID ="stream05" ; -int TST_TOTAL =1 ; -int local_flag; +#include "tst_test.h" +#include "tst_safe_stdio.h" +#include "tst_rand_data.h" -#define PASSED 1 -#define FAILED 0 +#define FILENAME "ltp_file" +#define DATASIZE 3 +#define BUFFSIZE (2 * DATASIZE) -char progname[] ="stream05()" ; -char tempfile[40 ] ="" ; +static char *data; +static char *buff; -/*--------------------------------------------------------------------*/ -int main (int ac,char *av[]) +static void run (void ) { +int fd;FILE *stream; -char buf[10 ]; -int nr, fd; - -int lc; - -/* -* parse standard options -*/ -tst_parse_opts (ac, av,NULL ,NULL ); -tst_tmpdir (); - local_flag =PASSED ; - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - local_flag =PASSED ; - -sprintf (tempfile,"stream05.%d" ,getpid ()); -/*--------------------------------------------------------------------*/ -//block0: -if ((stream =fopen (tempfile,"a+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) a+ failed: %s" , - tempfile, -strerror (errno)); - } -fprintf (stream,"a" ); -fclose (stream); - -if ((stream =fopen (tempfile,"r+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) r+ failed: %s" , - tempfile, -strerror (errno)); - } - -/* check that ferror returns zero */ -if (ferror (stream) !=0 ) { -tst_resm (TFAIL ,"ferror did not return zero: %s" , -strerror (errno)); - local_flag =FAILED ; - } - -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block0." ); - }else { -tst_resm (TFAIL ,"Test failed in block0." ); - } - - local_flag =PASSED ; -/*--------------------------------------------------------------------*/ -//block1: +memset (buff,0 ,BUFFSIZE ); -/* check that fileno returns valid file descriptor */ - fd =fileno (stream); -if ((nr =read (fd, buf,1 )) <0 ) { -tst_brkm (TFAIL ,NULL ,"read failed: %s" , -strerror (errno)); - } -if (nr !=1 ) { -tst_resm (TFAIL ,"read did not read right number" ); - local_flag =FAILED ; - } -if (buf[0 ] !='a' ) { -tst_resm (TFAIL ,"read returned bad values" ); - local_flag =FAILED ; - } -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block1." ); - }else { -tst_resm (TFAIL ,"Test failed in block1." ); - } + stream =SAFE_FOPEN (FILENAME ,"a+" ); +SAFE_FWRITE (data,1 ,DATASIZE , stream); - local_flag =PASSED ; -/*--------------------------------------------------------------------*/ -//block2: + fd =TST_EXP_FD (SAFE_FILENO (stream)); +SAFE_WRITE (SAFE_WRITE_ALL , fd, data,DATASIZE ); -/* read to EOF and ensure feof returns non-zero */ -fclose (stream); +fsync (fd); +SAFE_FSEEK (stream,0 ,SEEK_SET ); +SAFE_READ (1 , fd, buff,BUFFSIZE ); -if ((stream =fopen (tempfile,"r+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) r+ failed: %s" , - tempfile, -strerror (errno)); - } -if (feof (stream) !=0 ) { -tst_resm (TFAIL , -"feof returned non-zero when it should not: %s" , -strerror (errno)); - local_flag =FAILED ; - } -fread (buf,1 ,2 , stream);/* read to EOF */ -if (feof (stream) ==0 ) { -tst_resm (TFAIL , -"feof returned zero when it should not: %s" , -strerror (errno)); - local_flag =FAILED ; - } +TST_EXP_EQ_STRN (data, buff,DATASIZE ); +TST_EXP_EQ_STRN (data, buff +3 ,DATASIZE ); -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block2." ); - }else { -tst_resm (TFAIL ,"Test failed in block2." ); - } +SAFE_CLOSE (fd); +TST_EXP_FAIL (fclose (stream),EBADF ); - local_flag =PASSED ; -/*--------------------------------------------------------------------*/ -//block3: -/* ensure clearerr works */ -clearerr (stream); -if (feof (stream) !=0 ) { -tst_resm (TFAIL ,"clearerr failed: %s" ,strerror (errno)); - local_flag =FAILED ; - } -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block3." ); - }else { -tst_resm (TFAIL ,"Test failed in block3." ); - } - - local_flag =PASSED ; -/*--------------------------------------------------------------------*/ -//block4: - -/* test fopen "b" flags -- should be allowed but ignored */ - (void )fclose (stream); - -if ((stream =fopen (tempfile,"rb" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) rb failed: %s" , - tempfile, -strerror (errno)); - } - (void )fclose (stream); - -if ((stream =fopen (tempfile,"wb" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) wb failed: %s" , - tempfile, -strerror (errno)); - } - (void )fclose (stream); - -if ((stream =fopen (tempfile,"ab" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) ab failed: %s" , - tempfile, -strerror (errno)); - } - (void )fclose (stream); - -if ((stream =fopen (tempfile,"rb+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) rb+ failed: %s" , - tempfile, -strerror (errno)); - } - (void )fclose (stream); - -if ((stream =fopen (tempfile,"wb+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) wb+ failed: %s" , - tempfile, -strerror (errno)); - } - (void )fclose (stream); - -if ((stream =fopen (tempfile,"ab+" )) ==NULL ) { -tst_brkm (TFAIL ,NULL ,"fopen(%s) ab+ failed: %s" , - tempfile, -strerror (errno)); - } - (void )fclose (stream); +SAFE_UNLINK (FILENAME ); +} -tst_resm (TPASS ,"Test passed in block4." ); -/*--------------------------------------------------------------------*/ -unlink (tempfile); - }/* end for */ -tst_rmdir (); -tst_exit (); +static void setup (void ) +{ +memcpy (data, tst_rand_data,DATASIZE ); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_tmpdir =1 , + .bufs = (struct tst_buffers []) { + {&data, .size =DATASIZE }, + {&buff, .size =BUFFSIZE }, + {}, + }, +};
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 6/6] fs: rewrite stream05 test using new API
Hi!
Quoted 4 lines
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2002
Shouldn't this copyright stay?
Quoted 16 lines
- * 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+ * Copyright (c) 2026 Andrea Cervesato <[email protected]> */
...
testcases/kernel/fs/stream/stream05.c line 30
Quoted 2 lines
testcases/kernel/fs/stream/stream05.c +2
-0+ stream =SAFE_FOPEN (FILENAME ,"a+" ); +SAFE_FWRITE (data,1 ,DATASIZE , stream);
Shouldn't this be SAFE_FFLUSH(stream) here?
The previous test closed and opened the stream before, which explicitly flushed the buffers.
testcases/kernel/fs/stream/stream05.c line 32
Quoted 4 lines
testcases/kernel/fs/stream/stream05.c +1
-3- local_flag =PASSED ; -/*--------------------------------------------------------------------*/ -//block2: + fd =TST_EXP_FD (SAFE_FILENO (stream));
This is wrong, either we use SAFE_MACRO or TST_EXP macro. Using both of them like this does not make any sense since the SAFE_FILENO() does not return on a failure.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp