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=ham 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 B8B91C43461 for ; Thu, 17 Sep 2020 12:59:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FF08206CA for ; Thu, 17 Sep 2020 12:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600347541; bh=AmfKKecA45gbPkNMoLmcbmdvKE728KmeBwZz952aCgw=; h=Subject:To:Cc:References:From:Date:In-Reply-To:List-ID:From; b=SgIubAls9U8X5tRXKsm9MzxonMnz9wtiuv55rct12U530tLvggXL4WEQuWHqozXNJ 9lQmevLDMcK0GHxzHre8cLgZzkc1TqbEeVJLBMy9xp3va28DwwXrF18/ZwTdxDpgX4 wSx2xN01ZLSdqDq+mjtcX9YhcU27QKOfMXsXt6kc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727038AbgIQM66 (ORCPT ); Thu, 17 Sep 2020 08:58:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727229AbgIQM61 (ORCPT ); Thu, 17 Sep 2020 08:58:27 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEFADC061788 for ; Thu, 17 Sep 2020 05:58:26 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id 185so2320581oie.11 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=Gne3pel7igPoXmfvul73ybaeR876QHxqPLdBOmeiD7LxEP+vHUKmQGSzEHLg7Jgcd1 bVMyLksfZeuzzfBZTPrt9XcSmiAE0QyFt0OmEYGGBD1b+rbI4rUSRkltlS+/jtG2g0qp ++FnwcT+LjI9tz9F2M5pl3LY2wvIFJMQung/vtz0o8t7iMcJ4wzQV+1qUaPX+OG8Vfgb SRtlUZizQYxsokeVzw8tj1cR4v/qLMyvTK8su/dOigek9vl1nKCZGTTbzoH0wGpdiBwG NlVNzPe8L/p5XipdtiF77ZP/CoFHpudfRc/GQVFEZPbZrryUZPBySz29fMXFoNsuHt9G KMGg== X-Gm-Message-State: AOAM531JfSYtm83Ls/zjEkkirTUVGFEWMVvLy72iBc3jxJ3Bi+68euh4 +cFmpUzAA7LR2vNZktjQad5oKQ== X-Google-Smtp-Source: ABdhPJxJ+hJC5NgrepAXypYOwEjQMM4lNMMM27TkWxWgD7WozscsKqRmtHl4Tv93I1l3RzjjxNAuQw== 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-kselftest@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