remove old tst_flush()
PATCH v3 1/3 remove old tst_flush()
The old tst_flush() was renamed to tst_old_flush(), and tst_flush() was removed from tstapicmd.c.
Present calls to tst_flush() were changed to tst_old_flush().
--- doc/man3/tst_res.3 | 6 +++--- include/old/test.h | 6 +++--- lib/tests/trerrno.c | 2 +- lib/tst_res.c | 8 ++++---- testcases/kernel/controllers/cgroup_xattr/cgroup_xattr.c | 4 ++-- testcases/kernel/syscalls/epoll/epoll-ltp.c | 4 ++-- testcases/kernel/syscalls/fork/fork07.c | 2 +- testcases/kernel/syscalls/ipc/shmctl/shmctl01.c | 2 +- testcases/kernel/syscalls/modify_ldt/modify_ldt02.c | 2 +- tools/apicmds/ltpapicmd.c | 4 ---- 10 files changed, 18 insertions(+), 22 deletions(-)
doc/man3/tst_res.3 +3 -3
@@ -39,7 +39,7 @@ tst_resm_hexd \- Print result message, including specified buffer in hexadecimal .sp tst_brkm \- Print result message and break remaining test cases .sp -tst_flush \- Print any messages pending because of CONDENSE mode, and flush output stream +tst_old_flush \- Print any messages pending because of CONDENSE mode, and flush output stream .sp tst_exit \- Exit test with a meaningful exit value .sp
@@ -56,7 +56,7 @@ char *\fItmesg, [arg ...]\fR) \fBvoid tst_brkm(int \fIttype\fB, void (*\fIfunc\fB)(), char *\fItmesg, [arg ...]\fR) .P -\fBvoid tst_flush() +\fBvoid tst_old_flush() .P \fBvoid tst_exit() .P
@@ -180,7 +180,7 @@ after all results have been printed. If \fBtst_brk()\fR is called with a first reported result. \fBtst_brk()\fR takes the \fIfname\fR argument whereas \fBtst_brkm()\fR does not. .P -\fBtst_flush()\fR is used to print any results pending because of +\fBtst_old_flush()\fR is used to print any results pending because of \fBCONDENSE\fR or \fBNOPASS\fR modes (described below), and flushes the output stream. .P
include/old/test.h +3 -3
@@ -102,7 +102,7 @@#ifdef UCLINUX # define FORK_OR_VFORK tst_vfork# define MAP_PRIVATE_EXCEPT_UCLINUX 0 -/* tst_flush() + vfork() */ +/* tst_old_flush() + vfork() */ pid_t tst_vfork (void );#else # define FORK_OR_VFORK tst_fork
@@ -176,10 +176,10 @@ void tst_brkm_(const char *file, const int lineno, int ttype,void tst_require_root (void ); void tst_exit(void) LTP_ATTRIBUTE_NORETURN; -void tst_flush (void ); +void tst_old_flush (void );/* -* tst_flush() + fork +* tst_old_flush() + fork * NOTE: tst_fork() will reset T_exitval to 0 for child process. */ pid_t tst_fork (void );
lib/tests/trerrno.c +1 -1
@@ -57,7 +57,7 @@ int main(void)TEST_ERRNO =EPERM ;TEST_RETURN =EINVAL ;tst_resm (TINFO |TRERRNO ,"test" ); -tst_flush (); +tst_old_flush ();/* restore stdout */ TEST (dup2 (stdout_fd,fileno (stdout)));
lib/tst_res.c +4 -4
@@ -245,7 +245,7 @@ static void tst_condense(int tnum, int ttype, const char *tmesg) Buffered = TRUE; } -void tst_flush (void ) +void tst_old_flush (void ) {NO_NEWLIB_ASSERT ("Unknown" ,0 );
@@ -399,7 +399,7 @@ void tst_exit(void)pthread_mutex_lock (&tmutex); -tst_flush (); +tst_old_flush (); T_exitval &= ~TINFO ;
@@ -415,7 +415,7 @@ pid_t tst_fork(void)NO_NEWLIB_ASSERT ("Unknown" ,0 ); -tst_flush (); +tst_old_flush (); child =fork ();if (child ==0 )
@@ -460,7 +460,7 @@ pid_t tst_vfork(void) {NO_NEWLIB_ASSERT ("Unknown" ,0 ); -tst_flush (); +tst_old_flush ();return vfork (); }
testcases/kernel/controllers/cgroup_xattr/cgroup_xattr.c +2 -2
@@ -219,10 +219,10 @@ static void cleanup(void)/* * Kernels 3.7 can crash while unmounting cgroups with xattr, -* call tst_flush() to make sure all buffered data written +* call tst_old_flush() to make sure all buffered data written * before it happens */ -tst_flush (); +tst_old_flush ();int i;for (i =0 ; i < odir_num; ++i) {
testcases/kernel/syscalls/epoll/epoll-ltp.c +2 -2
@@ -142,7 +142,7 @@ do { \pid_t kid_pid; \int kid_status; \ \ -tst_flush (); \ +tst_old_flush (); \ kid_pid =FORK_OR_VFORK (); \if (kid_pid ==0 ) {
@@ -176,7 +176,7 @@ do { \pid_t kid_pid; \int kid_status; \ \ -tst_flush (); \ +tst_old_flush (); \ kid_pid =FORK_OR_VFORK (); \if (kid_pid ==0 ) {/* Run the function */ \return fn (epoll_fd); \
testcases/kernel/syscalls/fork/fork07.c +1 -1
@@ -110,7 +110,7 @@ int main(int ac, char **av)/* fork off the children */ tst_resm (TINFO ,"Forking %d children" , Nforks); -tst_flush (); +tst_old_flush ();for (forks =0 ; forks < Nforks; forks++) { pid1 =fork ();if (pid1 ==0 ) {
testcases/kernel/syscalls/ipc/shmctl/shmctl01.c +1 -1
@@ -228,7 +228,7 @@ void stat_setup(void)*/ set_shared =set_shmat (); -tst_flush (); +tst_old_flush ();for (stat_i =0 ; stat_i <N_ATTACH ; stat_i++) { pid =FORK_OR_VFORK ();if (pid ==-1 )
testcases/kernel/syscalls/modify_ldt/modify_ldt02.c +1 -1
@@ -140,7 +140,7 @@ int main(int ac, char **av)tst_brkm (TINFO , cleanup,"Creation of segment failed" ); } -tst_flush (); +tst_old_flush ();if ((pid =FORK_OR_VFORK ()) ==0 ) { val =read_segment (0 );exit (1 );
tools/apicmds/ltpapicmd.c +0 -4
@@ -34,8 +34,6 @@* break remaining test cases * tst_res - Print result message, including file contents * tst_resm - Print result message -* tst_flush - Print any messages pending because of CONDENSE mode, -* and flush output stream * tst_exit - Exit test with a meaningful exit value * * These are the minimum set of functions or commands required to
@@ -332,8 +330,6 @@ int main(int argc, char *argv[])apicmd_resm (argc, argv); }else if (strcmp (cmd_name,"tst_exit" ) ==0 ) {tst_exit (); - }else if (strcmp (cmd_name,"tst_flush" ) ==0 ) { -tst_flush (); }else if (strcmp (cmd_name,"tst_ncpus" ) ==0 ) {printf ("%li\n" ,tst_ncpus ()); }else if (strcmp (cmd_name,"tst_ncpus_conf" ) ==0 ) {
Signature · 1 line
2.13.6
PATCH v3 2/3 Add new tst_flush() library function
Add a new library function to flush stderr and stdout streams:
void tst_flush(void)
This function flushes stderr and stdout streams. In case of an error, the test is aborted with TBROK and an error message is printed.
--- doc/test-writing-guidelines.txt | 8 ++++++++ include/tst_test.h | 3 +++ lib/tst_test.c | 15 +++++++++++++++ 3 files changed, 26 insertions(+)
doc/test-writing-guidelines.txt +8 -0
@@ -465,6 +465,14 @@ Allows for setting timeout per test iteration dymanically in the test setup(), the timeout is specified in seconds. There are a few testcases whose runtime can vary arbitrarily, these can disable timeouts by setting it to -1. +[source,c] +------------------------------------------------------------------------------ +void tst_flush(void); +------------------------------------------------------------------------------- + +Flush stderr and stdout streams, handling errors appropriately. +You should not use fflush() for stderr or stdout. + 2.2.3 Test temporary directory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
include/tst_test.h +3 -0
@@ -70,6 +70,9 @@ void tst_brk_(const char *file, const int lineno, int ttype,#define tst_brk (ttype, arg_fmt, ...) \ tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) +/* flush stderr and stdout */ +void tst_flush (void ); +pid_t safe_fork (const char *filename,unsigned int lineno);#define SAFE_FORK () \ safe_fork(__FILE__, __LINE__)
lib/tst_test.c +15 -0
@@ -1085,3 +1085,18 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)do_exit (ret); } + + +void tst_flush (void ) +{ +int rval; + + rval =fflush (stderr); +if (rval !=0 ) +tst_brk (TBROK |TERRNO ,"fflush(stderr) failed" ); + + rval =fflush (stderr); +if (rval !=0 ) +tst_brk (TBROK |TERRNO ,"fflush(stdout) failed" ); + +}
Signature · 1 line
2.13.6
PATCH v3 2/3 Add new tst_flush() library function
Hi!
I've changed the documentation to explain better why this call is needed and pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 3/3 safe_fork() should use tst_flush() instead of fflush()
In reply to Michael Moesesafe_fork() should not use fflush(stdout). This commit makes use of the the newly added tst_flush(), which flushes, in fact, both stdout and stderr.
In addition, tests output their results to stderr, so flushing stdout here is simply wrong.
--- lib/tst_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/tst_test.c +1 -1
@@ -380,7 +380,7 @@ pid_t safe_fork(const char *filename, unsigned int lineno)if (!tst_test->forks_child)tst_brk (TBROK ,"test.forks_child must be set!" ); -fflush (stdout); +tst_flush (); pid =fork ();if (pid <0 )
Signature · 1 line
2.13.6
PATCH v3 3/3 safe_fork() should use tst_flush() instead of fflush()
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v3 1/3 remove old tst_flush()
In reply to Michael MoeseHi!
I've amended the patch with a change that removes the tst_flush from the .gitingore as well and pushe, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]