@@ -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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -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__)
@@ -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");
+
+}
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. 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(+)