Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp630208pxk; Thu, 17 Sep 2020 11:47:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7SIkVleB1dExZrJuXOQCg2j7hZzRoWiUAISzqeX1GhMKoi8zLzGnLAytuaM8HTM1NgfK8 X-Received: by 2002:aa7:da16:: with SMTP id r22mr35405371eds.132.1600368457721; Thu, 17 Sep 2020 11:47:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600368457; cv=none; d=google.com; s=arc-20160816; b=MX9JLJzvwSeHNYIkAYCKgPxVJ3HUhQsiTq1lATm7NnKNO7bTcrmepMHWsVapT44ma5 3OhkndM2UPvehNxXHenyt4FsubCBvwufmXWe26Ny7WjrzUW99WyVzFTfCpHTymoLc0Ng 2sjPWIBk0XIlOHP8rF312BcdfB67wnSk3xQwY92rUJ4IYliTCJ3hmPt2LFFO9ToZGP4M MEZbCq7DAKLoQeeCpBx/oumEtJOChtI6HsYZ2/vxnlsXQT17/RFeihK0vtAhMDFX5sKw ijNwc2/Kly32/wxd6JljdOkxUF7Q8Hp3rdvz2P2eIi5hGkHjv98DGYiqXNzpO2OirUgQ fxcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=o4EtNq7DyeGyaCTcfrcZu/YzRJzariS8Y96E7qW0PrI=; b=UEmVU1RbQ1F1Ci5V24K3MdcFfFByJRwrQAn2qvRnbfjplOy/AQ5wdNfyolPL6qUbG0 B9LMwnPgA+iIF6mqj1o6S+sAN48T8TsSV9C4bujhI7S1Dz5fWkulN1CZ+b98VLjyS5HC T9brorKoBlm70LFxUuLbEDvLljZR12OXy1bwALfRTwe+dcZIC5eE1rIjIyAqtFRhdcjI msm4MaJb+FU8psnZBfy+KNwTbwJtiD8Fcs4IusN6aRTjrV3Iu5MtnqdQqO8IBLzPaKMb 32D/G2vvB3zVHMmelSZyLtoH3si+2l//lk9Wm/xvG4+Vow37qzoL3GDXsPKLa7FCpKEc j9zQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=Y+GQfQ39; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ng5si518589ejb.532.2020.09.17.11.47.14; Thu, 17 Sep 2020 11:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=Y+GQfQ39; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726457AbgIQSpx (ORCPT + 99 others); Thu, 17 Sep 2020 14:45:53 -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-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