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

Brian Paul brianp at vmware.com
Mon Jun 12 12:22:23 UTC 2017


On 06/12/2017 04:23 AM, Jose Fonseca wrote:
>
> On 07/06/17 21:17, Brian Paul wrote:
>> Windows doesn't immediately flush stdout/stderr after printf().
>> Use setbuf() to disable buffering on Windows.
>
> Hmm, I thought that Windows immediately flushed stderr/stdout when it is
> a TTY, just like Linux.
>
> Most like stdout/stderr is not a TTY.  That is
>
>    isatty(STDOUT_FILENO)
>    isatty(STDERR_FILENO)
>
> returns false.
>
> Are you using a Cygwin shell/terminal? Perhaps that's the issue -- mayve
> it's redirecting stdout/stderr to a pipe behind your back.

Yes, Cygwin.  I see the same problem with any app that writes to 
stderr/stdio (like Mesa demos).


>
> At any rate, it doesn't hurt to disable buffering, to cover all cases,
> so this is
>
> Reviewed-by: Jose Fonseca <jfonseca at vmware.com>
>
> though it might be worth rephrasing the comment, as I don't think
> Windows differs from Linux in this regard.

I'll update the comment.  Thanks.

-Brian

>
> Jose
>
>> 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);
>>
>



More information about the Piglit mailing list