Rewrite fs stream testing suite
v2 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.
---
Changes in v2:
- add SAFE_FFLUSH() macro
- remove cleanup_fn from SAFE_* macros
- stream01: use a double buffer to write data inside file
- stream02: check if stream is NULL after fopen()
- stream05: use SAFE_FFLUSH()
- stream05: don't overengineer SAFE_FILENO() with TST_EXP_FD()
- Link to v1: https://lore.kernel.org/r/[email protected]
---
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 | 21 +++ include/tst_safe_stdio.h | 21 +++ lib/safe_stdio.c | 101 +++++++++++ testcases/kernel/fs/stream/stream01.c | 155 +++++----------- testcases/kernel/fs/stream/stream02.c | 136 ++++---------- testcases/kernel/fs/stream/stream03.c | 326 ++++++---------------------------- testcases/kernel/fs/stream/stream04.c | 147 +++++---------- testcases/kernel/fs/stream/stream05.c | 258 +++++---------------------- 8 files changed, 362 insertions(+), 803 deletions(-)
---
base-commit: 23ea0f0f8064f68bbf4d5c5f4f037ef18a5848d8
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 v2 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
- SAFE_FFLUSH
--- include/safe_stdio_fn.h | 21 ++++++++++ include/tst_safe_stdio.h | 21 ++++++++++ lib/safe_stdio.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+)
include/safe_stdio_fn.h +21 -0
@@ -32,4 +32,25 @@ 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 *ptr,size_t size,size_t n,FILE *stream); + +size_t safe_fwrite (const char *file,const int lineno, +const void *ptr,size_t size,size_t n,FILE *stream); + +FILE *safe_freopen (const char *file,const int lineno, +const char *path,const char *mode,FILE *stream); + +int safe_fseek (const char *file,const int lineno, +FILE *f,long offset,int whence); + +long safe_ftell (const char *file,const int lineno, +FILE *f); + +int safe_fileno (const char *file,const int lineno, +FILE *stream); + +int safe_fflush (const char *file,const int lineno, +FILE *stream); +#endif /* SAFE_STDIO_FN_H__ */
include/tst_safe_stdio.h +21 -0
@@ -21,4 +21,25 @@#define SAFE_POPEN (command, type) \ safe_popen(__FILE__, __LINE__, NULL, command, type) +#define SAFE_FREAD (ptr, size, n, stream) \ + safe_fread(__FILE__, __LINE__, ptr, size, n, stream) + +#define SAFE_FWRITE (ptr, size, n, stream) \ + safe_fwrite(__FILE__, __LINE__, ptr, size, n, stream) + +#define SAFE_FREOPEN (path, mode, stream) \ + safe_freopen(__FILE__, __LINE__, path, mode, stream) + +#define SAFE_FSEEK (f, offset, whence) \ + safe_fseek(__FILE__, __LINE__, f, offset, whence) + +#define SAFE_FTELL (f) \ + safe_ftell(__FILE__, __LINE__, f) + +#define SAFE_FILENO (f) \ + safe_fileno(__FILE__, __LINE__, f) + +#define SAFE_FFLUSH (f) \ + safe_fflush(__FILE__, __LINE__, f) +#endif /* TST_SAFE_STDIO_H__ */
lib/safe_stdio.c +101 -0
104 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/6 fs: rewrite stream01 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream01.c | 155 +++++++++++----------------------- 1 file changed, 49 insertions(+), 106 deletions(-)
testcases/kernel/fs/stream/stream01.c +49 -106
@@ -1,127 +1,70 @@ +// 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" +static char *buff_file1 ="abc" ; +static char *buff_file2 ="def" ; -char *TCID ="stream01" ; -int TST_TOTAL =1 ; -int local_flag; +static void read_file (const char *file,const char *str,size_t n) +{ +char buf[n]; +FILE *stream; +size_t len; -#define PASSED 1 -#define FAILED 0 +memset (buf,0 ,sizeof (buf)); -/* XXX: add setup and cleanup. */ + stream =SAFE_FOPEN (file,"r" ); + len =SAFE_FREAD (buf, n, n, stream); +SAFE_FCLOSE (stream); -char progname[] ="stream01()" ; -char tempfile1[40 ] ="" ; -char tempfile2[40 ] ="" ; +TST_EXP_EXPR (len == n,"Read the entire %s file buffer" , file); +TST_EXP_EQ_STRN (buf, str, len); +} -/*--------------------------------------------------------------------*/ -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 (buff_file1,strlen (buff_file1),3 , 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 (buff_file2,strlen (buff_file2),3 , 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 , buff_file1,3 ); +read_file (FILENAME2 , buff_file2,3 ); -/*--------------------------------------------------------------------*/ -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 v2 2/6] fs: rewrite stream01 test using new API
Hi!
testcases/kernel/fs/stream/stream01.c line 39
Quoted 13 lines
testcases/kernel/fs/stream/stream01.c +8
-3+static void read_file (const char *file,const char *str,size_t n) +{ +char buf[n]; +FILE *stream; +size_t len; -#define PASSED 1 -#define FAILED 0 +memset (buf,0 ,sizeof (buf)); -/* XXX: add setup and cleanup. */ + stream =SAFE_FOPEN (file,"r" ); + len =SAFE_FREAD (buf, n, n, stream);
Huh, we pass buffer of size n but ask it to read n * n bytes? That does not seem to be right.
Also the buffer must always be bigger than n to allow the fread() to read more bytes that we wrote, in a case that the file was written into intcorrectly. So we need something like:
char buf[128]; ... len = SAFE_FREAD(buf, 1, sizeof(buf), stream);
Quoted 39 lines
testcases/kernel/fs/stream/stream01.c +8
-25+SAFE_FCLOSE (stream); -char progname[] ="stream01()" ; -char tempfile1[40 ] ="" ; -char tempfile2[40 ] ="" ; +TST_EXP_EXPR (len == n,"Read the entire %s file buffer" , file); +TST_EXP_EQ_STRN (buf, str, len); +} -/*--------------------------------------------------------------------*/ -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 (buff_file1,strlen (buff_file1),3 , 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)); - }
testcases/kernel/fs/stream/stream01.c line 56
Quoted 10 lines
testcases/kernel/fs/stream/stream01.c +3
-7-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 (buff_file2,strlen (buff_file2),3 , stream);
And here as well we ask to write strlen(buff_fiel2) * 3 bytes but the buff_file2 is only 3 characters.
Quoted 28 lines
testcases/kernel/fs/stream/stream01.c +10
-8+SAFE_FCLOSE (stream); - local_flag =PASSED ; +read_file (FILENAME1 , buff_file1,3 ); +read_file (FILENAME2 , buff_file2,3 ); -/*--------------------------------------------------------------------*/ -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 · 6 lines
-- 2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] Add safe macros for stream testing suite
In reply to Andrea CervesatoHi Andrea,
our agent completed the review of the patch.
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
--- Reply to [PATCH 1/6] ---
Review
Quoted 12 lines · Andrea Cervesato
Add safe macros for stream testing suite
(quoted diff) +10
-0+size_t safe_fread(const char *file, const int lineno, + void *ptr, size_t size, size_t n, FILE *stream) +{ + size_t ret; + + ret = fread(ptr, size, n, stream); + if (ret != n) { + tst_brkm_(file, lineno, TBROK, NULL, + "fread(%p, %lu, %lu, %p) read %lu bytes", + ptr, size, n, stream, ret);
%lu is wrong for size_t on ILP32; use %zu. Also, ret is an item count, not bytes — the message is misleading. Same issue in safe_fwrite.
Use TBROK | TERRNO here and in safe_fwrite; errno is set on actual I/O errors, not just EOF.
Review
Quoted 2 lines
(quoted diff) +2
-0+FILE *safe_freopen(const char *file, const int lineno, + const char *path, const char *mode, FILE *stream)
Continuation-line alignment is inconsistent with the declaration in safe_stdio_fn.h. Same applies to safe_fseek, safe_ftell. Align to the opening parenthesis using tabs+spaces as in the header.
--- Reply to [PATCH 2/6] ---
Quoted 1 line · Andrea Cervesato
fs: rewrite stream01 test using new API
Commit body is missing. Explain why the conversion is done (e.g. "Old API is deprecated; convert to new tst_test.h-based API."). Same applies to patches 3/6–6/6.
testcases/kernel/fs/stream/stream01.c line 39
Quoted 5 lines
testcases/kernel/fs/stream/stream01.c +5
-0+static void read_file (const char *file,const char *str,size_t n) +{ +char buf[n]; + ... + len =SAFE_FREAD (buf, n, n, stream);
fread(buf, n, n) attempts to read n*n bytes into a n-byte VLA — buffer overflow. Change to SAFE_FREAD(buf, 1, n, stream).
testcases/kernel/fs/stream/stream01.c line 52
Quoted 1 line
testcases/kernel/fs/stream/stream01.c +1
-0+SAFE_FWRITE (buff_file1,strlen (buff_file1),3 , stream);
fwrite("abc", 3, 3) reads 9 bytes from a 3-byte literal — out-of-bounds read. Change to SAFE_FWRITE(buff_file1, 1, strlen(buff_file1), stream).
--- Reply to [PATCH 3/6] ---
Review
Quoted 7 lines · Andrea Cervesato
fs: rewrite stream02 test using new API
(quoted diff) +5
-0+ stream = SAFE_FOPEN(FILENAME, modes[i]); + if (!stream) { + tst_res(TFAIL, "fopen(%s) returned NULL pointer", modes[i]); + return; + }
SAFE_FOPEN never returns NULL — it calls tst_brk(TBROK) on failure. Remove the dead null check.
--- Reply to [PATCH 4/6] ---
Review
Quoted 4 lines · Andrea Cervesato
fs: rewrite stream03 test using new API
(quoted diff) +2
-0+ rewind(stream); + TST_EXP_EQ_LI(SAFE_FTELL(stream), SEEK_SET);
SEEK_SET is a seek-direction constant (value 0), not a file position. Use 0 as the expected value to avoid confusion.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/6 fs: rewrite stream02 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream02.c | 136 +++++++++------------------------- 1 file changed, 33 insertions(+), 103 deletions(-)
testcases/kernel/fs/stream/stream02.c +33 -103
@@ -1,119 +1,49 @@ +// 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 (); -for (lc =0 ;TEST_LOOPING (lc); lc++) { +SAFE_MKNOD (FILENAME , (S_IFIFO |0666 ),0 ); -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; +for (size_t i =0 ; i <ARRAY_SIZE (modes); i++) { + stream =SAFE_FOPEN (FILENAME , modes[i]); +if (!stream) { +tst_res (TFAIL ,"fopen(%s) returned NULL pointer" , modes[i]); +return ; } -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 ; -/*--------------------------------------------------------------------*/ -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." ); - } +SAFE_FCLOSE (stream); + +tst_res (TPASS ,"Opened file using '%s' mode" , modes[i]); + } -/*--------------------------------------------------------------------*/ - }/* 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 v2 3/6] fs: rewrite stream02 test using new API
Hi!
No change from v2?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 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
PATCH v2 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
PATCH v2 6/6 fs: rewrite stream05 test using new API
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
--- testcases/kernel/fs/stream/stream05.c | 258 +++++++--------------------------- 1 file changed, 47 insertions(+), 211 deletions(-)
testcases/kernel/fs/stream/stream05.c +47 -211
@@ -1,230 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* +* Copyright (c) International Business Machines Corp., 2002 +* ported from SPIE section2/filesuite/stream.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/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 ; +memset (buff,0 ,BUFFSIZE ); -/*--------------------------------------------------------------------*/ -//block1: + stream =SAFE_FOPEN (FILENAME ,"a+" ); +SAFE_FWRITE (data,1 ,DATASIZE , stream); +SAFE_FFLUSH (stream); -/* 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." ); - } + fd =SAFE_FILENO (stream); +SAFE_WRITE (SAFE_WRITE_ALL , fd, data,DATASIZE ); - local_flag =PASSED ; -/*--------------------------------------------------------------------*/ -//block2: +fsync (fd); +SAFE_FSEEK (stream,0 ,SEEK_SET ); +SAFE_READ (1 , fd, buff,BUFFSIZE ); -/* read to EOF and ensure feof returns non-zero */ -fclose (stream); +TST_EXP_EQ_STRN (data, buff,DATASIZE ); +TST_EXP_EQ_STRN (data, buff +3 ,DATASIZE ); -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 ; - } +SAFE_CLOSE (fd); +TST_EXP_FAIL (fclose (stream),EBADF ); -if (local_flag ==PASSED ) { -tst_resm (TPASS ,"Test passed in block2." ); - }else { -tst_resm (TFAIL ,"Test failed in block2." ); - } - - 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 v2 6/6] fs: rewrite stream05 test using new API
Hi!
testcases/kernel/fs/stream/stream05.c line 39
Quoted 1 line
testcases/kernel/fs/stream/stream05.c +1
-0+fsync (fd);
This should really be SAFE_FSYNC(fd);
testcases/kernel/fs/stream/stream05.c line 41
Quoted 2 lines
testcases/kernel/fs/stream/stream05.c +2
-0+SAFE_FSEEK (stream,0 ,SEEK_SET ); +SAFE_READ (1 , fd, buff,BUFFSIZE );
Otherwise the rest looks fine.
With that fixed:
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp