Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp896277pxk; Thu, 17 Sep 2020 20:39:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxH2qDZBIh/z698tid7B/8J2vdso8uFf/vpAaXrDMM2GiFlDjs9bMN59TJiU8RudKtGVWeX X-Received: by 2002:a17:906:4f8d:: with SMTP id o13mr33085946eju.20.1600400350147; Thu, 17 Sep 2020 20:39:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600400350; cv=none; d=google.com; s=arc-20160816; b=EC5cQsNX+YopZLVET1gslE8MVTi0Ckp+udt+sNUx7fYc4dkowW6DSUU9hhY3PBdeJ1 L13ItWsYSot0/GrPz/QxrOdrtCSXbQrJhYFVBobxCgXv7ANAAB5VMTRhN3duo+eKL5CY mXNgmjvvM/vovtuQrUI1gZRfQ55KYP73NYdDb+FtDwcHtyYrklJppmDlycvE+JWDKz9Y iClMdXZ/fZOHQPZAnWrJkfSnzadJh4SHzfEnK+L5p2DVOcBRkWAd+OwP45gv2suvr2Dv 1FTkITjfIMx6FI6mWBnosLTej75mMUoGB1rcvWuOIZZmgQgleX0H6e/XFSVo7NcJgj+Z Q2NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=wHpGbFlGpqOBo3S6ZU0nTgwxTbS57LAlUSTyElmc63o=; b=pD7QW7ckGd8ops/YXPEG5al8GsdKO2C1a+iYjnQfQ8Eb8zzsqCTlxA5GnWe/fvxDTJ zyvtmFXiPjLPhCwk0OsFiryCFupvyk5CJvfZvGsYeGE2zGY4sBWESS0S8hDpj3FMkOgq 5niZ3SQJE1FPFlTv+kWKC3RaYWkdQBMObbqxtfRJPYisEhZ+PMtKbgwGdMW4hW1VXdWm AqGZ5uvJtFcBvV3LC7WEpw2gbsP+UiAI5fO0BH1xcGdCXGcC1s+ROEQ8fgkK1UtxzZCJ R43EWQgm6yYIKKp6lz1UBNztwpcM8U46RVMBOehLuOxOzMmVzNVnabTapeOZOcJHwcNT MnlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b="d/6/w5s6"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dr18si1171341ejc.702.2020.09.17.20.38.46; Thu, 17 Sep 2020 20:39:10 -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=@ellerman.id.au header.s=201909 header.b="d/6/w5s6"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbgIRDhl (ORCPT + 99 others); Thu, 17 Sep 2020 23:37:41 -0400 Received: from ozlabs.org ([203.11.71.1]:45173 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726260AbgIRDhl (ORCPT ); Thu, 17 Sep 2020 23:37:41 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4Bt0035J9Yz9sRR; Fri, 18 Sep 2020 13:37:39 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1600400259; bh=f+WI+4Y5FqCAKO5vI/9vI4pfQazkTL/VYPrdXvYY8fc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=d/6/w5s6c9CO1f97Mol+q4eV4zfmEBkZqG2s4JuhiDKVhnNJWc5BrI+ZbKp2yPZXm rLb+teRkc65mrjjFi+LJg8GF0cteV4C/iDp1HzFSLeUK/dNWZ3umckQ0LclSP5GfeG waXRmi+DsFeLUFM7gpHcWFKIe9HGtH6ZDQe9EAnZM07N5jAVZCuKaHCqI8KjRYysWi yVQZJJEDSU7s3+hfcQvRZdbs+BJ0EtylUCIAncVEyAzhORUMv9qVlvP2du5Im7ucvi TlSUp4EMTrAqCyJPK066nR0sZ0PVZ+VvAODpl4clbLW+MKNT7nn8a0aWOfx6Rk0ZOW b2AGwACZctcDw== From: Michael Ellerman To: Shuah Khan , Max Filippov Cc: Kees Cook , linux-kselftest@vger.kernel.org, LKML , Shuah Khan Subject: Re: [PATCH] selftests/harness: Flush stdout before forking In-Reply-To: References: <20200917041519.3284582-1-mpe@ellerman.id.au> Date: Fri, 18 Sep 2020 13:37:33 +1000 Message-ID: <87o8m3oiv6.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. cheers