From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADD77C433E2 for ; Thu, 17 Sep 2020 18:46:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6741021973 for ; Thu, 17 Sep 2020 18:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600368369; bh=lUbIHmXLMTMgzfrMuB76BK78tkBH1w6cyR+96GYRquY=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-ID:From; b=LOjhxWwoyCrOAih3QIGXxa+SnljFU3SVSAZYXcfGdntMdSk/6suLDsQcXtK4inCKp As5pPP7WRuyAtGCCfxIwtbtePfdk4P2PT6xv3wMmV0KqZFkAI/n6/jp/kyqp+lYlyk 4sI9iCvvqdTpHEXmT3iVT2tHeyImOv6gy6h9qdMQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726427AbgIQSp7 (ORCPT ); Thu, 17 Sep 2020 14:45:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728653AbgIQQvg (ORCPT ); Thu, 17 Sep 2020 12:51:36 -0400 Received: from mail-ot1-x343.google.com (mail-ot1-x343.google.com [IPv6:2607:f8b0:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A13D0C061756 for ; Thu, 17 Sep 2020 09:51:34 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id o8so2545126otl.4 for ; Thu, 17 Sep 2020 09:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=o4EtNq7DyeGyaCTcfrcZu/YzRJzariS8Y96E7qW0PrI=; b=Y+GQfQ39bnkj6VnXa/M03RqeBAiDwLC7zseIDxVADyRcOAHj8N4cLAejLQUP8HSeH1 uo6DqNZgmCRIulGOZwczZruqMPJCQgekDLtD9VsZwrrcTos+rwUcqsFBwSqWklr5HaZ2 KZ5JL+Qb9VLaySf/HwISQUZ0EpezySg8GW1Zg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=o4EtNq7DyeGyaCTcfrcZu/YzRJzariS8Y96E7qW0PrI=; b=VyO3CKU6yU2EzEVb9ZrnToGKq8VgU8g3+JPBNk6Y93vufG5OYMuMbo0H3xNQPMO87+ TpgdA+bh0xdl5Fudp1djJhDdPLMBRC5QG2m81yTVssaFpfJscJjSPh+tmjXU6ylOZFSI VA+iEyhAi+ZO6zXPjWfJ+XJE5nnJheSyUuIgDJs3qwLD62EXnKNJfoBjMkPXcrMdfn2S 7P7yG/s3nofhhcy5nGN/2sc1jnWx7yu4JicQOmn3PNSAAXoWiOYq+o1vkOpH4ndxVJSR m9NnMrSZcKWmClbBq2S1WuhaktL+zGDXJ396opTUa/NAGnomTYHtgGjkRzLN/2Sa/ASp 03AA== X-Gm-Message-State: AOAM532VpFAQkuWhqq8hubbd9vvObdcIDd3poc+l4MoOcsR6uVpp7NNc 8iEYNLeHNkyDjEzw+4x+F8PSCA== X-Google-Smtp-Source: ABdhPJwnUUENSuTgrXD2q07P3VS761z7dRJIFzoT9pAk7/FoabmgyszKCLUmCPxq8cLBTh+aRAiNXg== X-Received: by 2002:a05:6830:1db5:: with SMTP id z21mr21358539oti.144.1600361493923; Thu, 17 Sep 2020 09:51:33 -0700 (PDT) Received: from [192.168.1.112] (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id c12sm204335otm.61.2020.09.17.09.51.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Sep 2020 09:51:33 -0700 (PDT) Subject: Re: [PATCH] selftests/harness: Flush stdout before forking To: Kees Cook Cc: Max Filippov , Michael Ellerman , linux-kselftest@vger.kernel.org, LKML , Shuah Khan References: <20200917041519.3284582-1-mpe@ellerman.id.au> From: Shuah Khan Message-ID: <99f67c84-4dcd-278a-e7b8-e19054818ecf@linuxfoundation.org> Date: Thu, 17 Sep 2020 10:51:32 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 >> 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 >>> --- >>>   tools/testing/selftests/kselftest_harness.h | 5 +++++ >>>   1 file changed, 5 insertions(+) >> >> Tested-by: Max Filippov >> > > 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 thanks, -- Shuah