* [LTP] [PATCH] Add tst_flush() library function
@ 2018-03-08 10:57 Michael Moese
2018-03-08 15:14 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Michael Moese @ 2018-03-08 10:57 UTC (permalink / raw)
To: ltp
Add a 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.
Signed-off-by: Michael Moese <mmoese@suse.de>
---
doc/test-writing-guidelines.txt | 8 ++++++++
include/tst_test.h | 3 +++
lib/tst_test.c | 15 +++++++++++++++
3 files changed, 26 insertions(+)
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index 739b295b8..4c60cd66b 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/include/tst_test.h b/include/tst_test.h
index af97b8983..54ff306d9 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -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__)
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 2cf35ed66..9b4f43828 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -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");
+
+}
--
2.13.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [LTP] [PATCH] Add tst_flush() library function
2018-03-08 10:57 [LTP] [PATCH] Add tst_flush() library function Michael Moese
@ 2018-03-08 15:14 ` Cyril Hrubis
2018-03-09 8:06 ` Michael Moese
0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2018-03-08 15:14 UTC (permalink / raw)
To: ltp
Hi!
I've tried to apply this but found out that there is tst_flush() in the
old library and because of that the code does not even compile.
So we have to rename the tst_flush() in the old library to something as
tst_old_flush() and also remove it from the ltpapicmd.c since there are
no shell tests that call that command (ltpapicmd.c should hopefully die
some day soon). Should I do that or will you send another patch? :-)
Also we should make use of the tst_flush() in the safe_fork() so that we
finally flush the right stream in the new test library...
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH] Add tst_flush() library function
2018-03-08 15:14 ` Cyril Hrubis
@ 2018-03-09 8:06 ` Michael Moese
0 siblings, 0 replies; 3+ messages in thread
From: Michael Moese @ 2018-03-09 8:06 UTC (permalink / raw)
To: ltp
Hi,
Now that you tell me that, I can see this as well. Of course I did a local
build test, but the issue did not show up at first.
I will send more patches, changing safe_fork() and the old library.
Michael
On Thu, Mar 08, 2018 at 04:14:03PM +0100, Cyril Hrubis wrote:
> Hi!
> I've tried to apply this but found out that there is tst_flush() in the
> old library and because of that the code does not even compile.
>
> So we have to rename the tst_flush() in the old library to something as
> tst_old_flush() and also remove it from the ltpapicmd.c since there are
> no shell tests that call that command (ltpapicmd.c should hopefully die
> some day soon). Should I do that or will you send another patch? :-)
>
> Also we should make use of the tst_flush() in the safe_fork() so that we
> finally flush the right stream in the new test library...
>
> --
> Cyril Hrubis
> chrubis@suse.cz
--
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-03-09 8:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-08 10:57 [LTP] [PATCH] Add tst_flush() library function Michael Moese
2018-03-08 15:14 ` Cyril Hrubis
2018-03-09 8:06 ` Michael Moese
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.