Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp388659pxk; Thu, 17 Sep 2020 06:00:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwioysMdaU42sY6oi2n6MHWDtqYcZN0nI98/S9+3qaTIGTOvXQzqhyvwXGvVqr/6SUSVj0c X-Received: by 2002:adf:f34a:: with SMTP id e10mr2480927wrp.91.1600347647411; Thu, 17 Sep 2020 06:00:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600347647; cv=none; d=google.com; s=arc-20160816; b=o3nCLbwPOXw2mzrIyutm5c5urVa+br8sTBmU/sP2V9R/hHZoagyWhLwAwKhtZt1Ml2 JEBdaYSat+AoFVcp48uLFz5d1iHH/8Qer8NZAoKadCGZZossQnm3g7zLCcZ+YgzunVsx /YSpWOOSVcBAdeO8ahQpy0f39g7FEY49NaPcBXLmG8Wgq9jn8y5j82mkIxo5SPOPmGWd kCZE3RCELUdpPywDxMp5q8P0J1yLHTt+qMe5zaEbA07QwnhwjYjCVTkmeVZShNt9dGbi Um9zoWKIYJhVPuJzGHE8+fF16Fkfrg4J+ct9147uG2YsCFd76AhRl1HTpjX4Rv37MIb5 sk8A== 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=v+fNl0lP+nDgkIqWYqUCp9ojQxRjrA9fuGvhmoD3cl4=; b=RSFUbHZ106eSWQyoV4IxEDGtR2qEDyLLkAdkvpW4ec5I2Ublpxm8FwqLaSMNVh+bvm rnEf0oa/7PuJSAYqLaHoAgOaztUd4kISkWIM91hdnGT23LHBrMfjxIrddqj4V7nW7vVP IIkLlPTUeT+i+Alm+MbC5ldbPeaoldLlJbNhR+lSfIfaNXsT5AUC0IRa58+U5m43npky sC8gnvHUEQMP+kS8a8Eo99rvt/ejYfclBtwsyj8ljIS+Q/mZZXdiNgvqErNpTjTtPq+N zrsTB2ouLth3nV002hunRYcCSBz/m1Go/VHG/hRzIn+9X3FJg9DxgFXZEIvcSuRGqfrO DcAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=Xx9BA4CJ; 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 f17si13788980edq.587.2020.09.17.06.00.22; Thu, 17 Sep 2020 06:00:47 -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=Xx9BA4CJ; 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 S1727046AbgIQM7Q (ORCPT + 99 others); Thu, 17 Sep 2020 08:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727138AbgIQM61 (ORCPT ); Thu, 17 Sep 2020 08:58:27 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8BD6C061756 for ; Thu, 17 Sep 2020 05:58:26 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id u126so2301836oif.13 for ; Thu, 17 Sep 2020 05:58:26 -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=v+fNl0lP+nDgkIqWYqUCp9ojQxRjrA9fuGvhmoD3cl4=; b=Xx9BA4CJAQ+/KNh9Oytu6Cp3JJRd7dZPKb0a9lbgdBNsP4TrCuCoM2hv/MeNZDJOt2 MIgdbjC+wvFlCsmnuqIU88Zn/DGSfwCm49nVbgVhm4JGYS3rQqQQ8VztYVsEiBaiVSYt P3rMGajvrLFM8xPLxVdoUq+XX/LyQQsFsonFU= 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=v+fNl0lP+nDgkIqWYqUCp9ojQxRjrA9fuGvhmoD3cl4=; b=GTscZhdFbtzPQtPP4o8QVBgAVtK/C1BJRVU1wgIk4Es0lveSepSdGvG5sv8iOCkUk9 258l8nw1Zq0XTK6boHK3B6RkTz9gPkElsGOjsCMvYd0fy77j4oJOKzSFlv7TE1OZX71t Q8Fxj/4wnLOSCcQIbzLKTZ/yMYWHTPHk+9YW0342oiOGfiEMXwju5mH33UHSWb2NamWR HWPiYfkyIkzGPzCabI9Gcxtx9D+y2psC/x7mZ64hvIXnasjZuvJXGBVJt4dDebJzylBu +MDgD08TEvGNGrzZok3k28sIw4WZtbMuYT7AE7KmQR2mYI4/csdZmPRkPCXMIVwuH4CP GQ7g== X-Gm-Message-State: AOAM533auqtp6dAfzXxghqiI92iHTS85CGFBmxwweujweKiQ9WtxMkKd +BgBEPQqQ/kr07NTFiAzPPN3J6XGNaasdQ== X-Received: by 2002:aca:a88e:: with SMTP id r136mr5904429oie.13.1600347506033; Thu, 17 Sep 2020 05:58:26 -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 h14sm10380230otr.21.2020.09.17.05.58.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Sep 2020 05:58:25 -0700 (PDT) Subject: Re: [PATCH] selftests/harness: Flush stdout before forking To: Max Filippov , Michael Ellerman Cc: Kees Cook , linux-kselftest@vger.kernel.org, LKML , Shuah Khan References: <20200917041519.3284582-1-mpe@ellerman.id.au> From: Shuah Khan Message-ID: Date: Thu, 17 Sep 2020 06:58:23 -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: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 thanks, -- Shuah