All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shuah Khan <skhan@linuxfoundation.org>
To: Kees Cook <keescook@chromium.org>
Cc: Max Filippov <jcmvbkbc@gmail.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	linux-kselftest@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH] selftests/harness: Flush stdout before forking
Date: Thu, 17 Sep 2020 10:51:32 -0600	[thread overview]
Message-ID: <99f67c84-4dcd-278a-e7b8-e19054818ecf@linuxfoundation.org> (raw)
In-Reply-To: <e24df908-c50d-59ef-563c-9db24c819248@linuxfoundation.org>

On 9/17/20 6:58 AM, Shuah Khan wrote:
> On 9/16/20 10:53 PM, Max Filippov wrote:
>> On Wed, Sep 16, 2020 at 9:16 PM Michael Ellerman <mpe@ellerman.id.au> 
>> wrote:
>>>
>>> The test harness forks() a child to run each test. Both the parent and
>>> the child print to stdout using libc functions. That can lead to
>>> duplicated (or more) output if the libc buffers are not flushed before
>>> forking.
>>>
>>> It's generally not seen when running programs directly, because stdout
>>> will usually be line buffered when it's pointing to a terminal.
>>>
>>> This was noticed when running the seccomp_bpf test, eg:
>>>
>>>    $ ./seccomp_bpf | tee test.log
>>>    $ grep -c "TAP version 13" test.log
>>>    2
>>>
>>> But we only expect the TAP header to appear once.
>>>
>>> It can be exacerbated using stdbuf to increase the buffer size:
>>>
>>>    $ stdbuf -o 1MB ./seccomp_bpf > test.log
>>>    $ grep -c "TAP version 13" test.log
>>>    13
>>>
>>> The fix is simple, we just flush stdout & stderr before fork. Usually
>>> stderr is unbuffered, but that can be changed, so flush it as well
>>> just to be safe.
>>>
>>> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>>> ---
>>>   tools/testing/selftests/kselftest_harness.h | 5 +++++
>>>   1 file changed, 5 insertions(+)
>>
>> Tested-by: Max Filippov <jcmvbkbc@gmail.com>
>>
> 
> Thank you both. Applying to linux-kselftest fixes for 5.9-rc7
> 

Kees,

I haven't pulled this in yet. If you want to take this through seccomp
tree for dependencies:

Acked-by: Shuah Khan <skhan@linuxfoundation.org>

thanks,
-- Shuah


  reply	other threads:[~2020-09-17 16:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17  4:15 [PATCH] selftests/harness: Flush stdout before forking Michael Ellerman
2020-09-17  4:53 ` Max Filippov
2020-09-17 12:58   ` Shuah Khan
2020-09-17 16:51     ` Shuah Khan [this message]
2020-09-17 22:06       ` Kees Cook
2020-09-18  3:37     ` Michael Ellerman
2020-09-18 14:32       ` Shuah Khan
2020-09-17 22:07 ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=99f67c84-4dcd-278a-e7b8-e19054818ecf@linuxfoundation.org \
    --to=skhan@linuxfoundation.org \
    --cc=jcmvbkbc@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mpe@ellerman.id.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.