Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1245155pxk; Fri, 18 Sep 2020 07:35:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5TBbvTJhsMGeBMOSNPIRkuyJrZmJ/6YLq/neXenbR2GzvvYnKEnGVmX/Pz4dA8lmqzE5d X-Received: by 2002:a17:906:88d:: with SMTP id n13mr37141146eje.75.1600439745139; Fri, 18 Sep 2020 07:35:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600439745; cv=none; d=google.com; s=arc-20160816; b=usxiX8MDnMLmXyoEQn16WXX+Lyndp+0yfePEzEL2tSmhRTx206JCR+C8s4l+AI1PBR enfXB+ccNb0oPFjYxZc16K+wUDPDlsRXNMxbOln7bh9NpO/+rD03pvT2RwGELhNCPbhC KtoKmClnPqPE6NFYuqGn437AZZTu/g2XStyCeDnkWY3ZQAXOUrixHbf/xbdbW/dyQ5xT 9k6vziT6qfIoJ88Jwq52nG3m3XRrLu2cc6zUDlp3Q3EyfRMrOwTgGljEwUlkLejJgnjp zn3EWzc3XSWDJbX/IDHSlnIkRnfSR1EF4rkHgV7VJ7hOMhYOaI/HDzQSXWeLd1E5HtOT yG+w== 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=sYJpr/JTfAc7wYRPBb4gv+TaUOt5dcnyH7jSr7tuCpM=; b=csTfEQtyiB0/ax1WZB/ygtHmetctfmTJRQJSQOY8t8Jsp8vxqPtD4k9APz3bNt5bb6 V4dIxak79OkxdTjujbt/gJlQMFbMgDA2PRvXpwgMC3JheG2Q4+eZ1NzdFHpPdUi25Ugg a2UpGPSzdqKY1WJBg8GYRZ5SXXcBOXHpD2kXxky7SpSG8PIcsyiqAIj6CCXhx4f8HePH e5RiLehY6uWn+yyTOTHMVXdgxwnSTVXgp0HU9+tFl/rpKXAEPxjZU2biFHx5Qay2KsbK UPZ7oejfS5lR44d2PKCnnbRh1fO6fXIKWNM58QrlID9r8n27J0dxQX+zhj4eiN+z/6ka nNbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=OizUltZ1; 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 m3si2330275edp.33.2020.09.18.07.35.21; Fri, 18 Sep 2020 07:35:45 -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=OizUltZ1; 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 S1726728AbgIROcR (ORCPT + 99 others); Fri, 18 Sep 2020 10:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbgIROcR (ORCPT ); Fri, 18 Sep 2020 10:32:17 -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 C2A04C0613CF for ; Fri, 18 Sep 2020 07:32:16 -0700 (PDT) Received: by mail-ot1-x343.google.com with SMTP id m12so5587512otr.0 for ; Fri, 18 Sep 2020 07:32:16 -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=sYJpr/JTfAc7wYRPBb4gv+TaUOt5dcnyH7jSr7tuCpM=; b=OizUltZ1LFId+L2XPadEiLoGsJia3Vb4yFpDK5KEcNWLrJW6Aem2AEybtF8cy3U+QY eoMGUf6mI0+wEijASIk6eboEjhmANetheAdBPBnm6rd+VaguUpkAbTzIdq2VelitR6BK syRnG+eDr/eNUK7FH0sWgDhnT/m+Rg3Nl1p4M= 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=sYJpr/JTfAc7wYRPBb4gv+TaUOt5dcnyH7jSr7tuCpM=; b=XeyKv+U/1rFpeJUoSgmheLofwZFjeujLsTxpG6UGvzt+n18UiVLFeFRKUUemjIpGDo HXsuzfllKY2eK4yZkMxUJvCmwBrdDET8/H68hr7Ze8fNkF/6fP9gg31nuSFDG9fVxfoM WZd8sLBKY0RpR+NSwtZW8KFVe2VZVGRSD1HFyEqeLy6HbmWUlhqc5459epaIXHtATplf Y6Ew8dLyKBcTOQcpBaQxK+IvrnerFyhJcE9FtU4S/a6G3CTaC9k+gYTnFZIejaaJ/+5n jFnebA9/LKPOnmLGFY2PcN0vtOeywVgKI/+THJdTowR8nIxKmcM/uy3ZK+eyRK3VLjaL tFbQ== X-Gm-Message-State: AOAM530dQXjWxmdfHOhAQ7QG4VptEvgMe2+HarEjfpD2ZOhC5yvM89tP LuE83x20ObExYWDPfiB/EbQ1dA== X-Received: by 2002:a05:6830:118b:: with SMTP id u11mr23775978otq.261.1600439535424; Fri, 18 Sep 2020 07:32:15 -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 q14sm2347601ota.41.2020.09.18.07.32.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 18 Sep 2020 07:32:14 -0700 (PDT) Subject: Re: [PATCH] selftests/harness: Flush stdout before forking To: Michael Ellerman , Max Filippov Cc: Kees Cook , linux-kselftest@vger.kernel.org, LKML , Shuah Khan References: <20200917041519.3284582-1-mpe@ellerman.id.au> <87o8m3oiv6.fsf@mpe.ellerman.id.au> From: Shuah Khan Message-ID: Date: Fri, 18 Sep 2020 08:32:13 -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: <87o8m3oiv6.fsf@mpe.ellerman.id.au> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/17/20 9:37 PM, Michael Ellerman wrote: > Shuah Khan writes: >> 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 > > It can wait for v5.10 IMHO, but up to you. > Good to know. I will send this for 5.10-rc1 then. thanks, -- Shuah