[Piglit] [PATCH] util: fix Windows stdout/stderr buffering

Neha Bhende bhenden at vmware.com
Thu Jun 8 20:24:11 UTC 2017


Looks good to me.


Reviewed-by: Neha Bhende<bhenden at vmware.com>


Regards,

Neha

________________________________
From: Brian Paul <brianp at vmware.com>
Sent: Wednesday, June 7, 2017 1:17:19 PM
To: piglit at lists.freedesktop.org
Cc: Charmaine Lee; Neha Bhende; Brian Paul
Subject: [PATCH] util: fix Windows stdout/stderr buffering

Windows doesn't immediately flush stdout/stderr after printf().
Use setbuf() to disable buffering on Windows.

Refactor the init code a bit to avoid calling setbuf() from some
arbitrary place otherwise.
---
 tests/util/piglit-framework-gl.h |  2 +-
 tests/util/piglit-util.c         | 24 +++++++++++++++++++++++-
 tests/util/piglit-util.h         |  2 +-
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/tests/util/piglit-framework-gl.h b/tests/util/piglit-framework-gl.h
index 992f28a..970fd55 100644
--- a/tests/util/piglit-framework-gl.h
+++ b/tests/util/piglit-framework-gl.h
@@ -271,7 +271,7 @@ piglit_gl_test_run(int argc, char *argv[],
         {                                                                    \
                 struct piglit_gl_test_config config;                         \
                                                                              \
-                piglit_disable_error_message_boxes();                        \
+                piglit_general_init();                                       \
                                                                              \
                 piglit_gl_test_config_init(&config);                         \
                                                                              \
diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
index 6b34c46..15a178b 100644
--- a/tests/util/piglit-util.c
+++ b/tests/util/piglit-util.c
@@ -317,7 +317,7 @@ piglit_report_subtest_result(enum piglit_result result, const char *format, ...)
 }


-void
+static void
 piglit_disable_error_message_boxes(void)
 {
         /* When Windows' error message boxes are disabled for this process (as
@@ -354,6 +354,28 @@ piglit_disable_error_message_boxes(void)
 }


+static void
+piglit_set_line_buffering(void)
+{
+       /* Windows doesn't immediately flush stdout/stderr after printf
+        * calls as we see on Linux.  To get immediate flushing, we disable
+        * buffering here.
+        */
+#ifdef _WIN32
+       setbuf(stdout, NULL);
+       setbuf(stderr, NULL);
+#endif
+}
+
+
+void
+piglit_general_init(void)
+{
+       piglit_disable_error_message_boxes();
+       piglit_set_line_buffering();
+}
+
+
 void
 piglit_set_rlimit(unsigned long lim)
 {
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index b30ae07..ad00817 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -414,7 +414,7 @@ void piglit_set_timeout(double seconds, enum piglit_result timeout_result);
 void piglit_report_subtest_result(enum piglit_result result,
                                   const char *format, ...) PRINTFLIKE(2, 3);

-void piglit_disable_error_message_boxes(void);
+void piglit_general_init(void);

 extern void piglit_set_rlimit(unsigned long lim);

--
1.9.1

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/piglit/attachments/20170608/69a53051/attachment.html>


More information about the Piglit mailing list