Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp144152pxk; Wed, 16 Sep 2020 21:57:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHWkmhmYk7I00msMN9wWnmI1cATkWrXdt/uddrhvMHTtGMN9Dmq1/EDRJIdzruyA9K9Aoz X-Received: by 2002:a17:906:3495:: with SMTP id g21mr28179926ejb.121.1600318659390; Wed, 16 Sep 2020 21:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600318659; cv=none; d=google.com; s=arc-20160816; b=i0XzSxN30gR+PJtmo9v0FZmy0hBK63CObrEKE0yLqrbmf1n1c0r0ZJmCTwveScOIVY 4Si0fHL6wMeMWr9iKzlDhU6ctADBW712Qr+5xBJ5CWjCgU2pSmVKRrhz8nK1icawHk0A IslUDpPpYdfnpi0nZAQ8085x2c+8DW23Wp1IQgVImaN0G8KXmxVZDKmmwSzOcYqFbs0+ LoedtLx+aHiWjuzCdT+78KHk0c7xPw5H0TmT+E8ohSKUJjICuyxirdPAFZxbMTm528dT IJywCxfuan7L+3RPrshk+jlSDpfp/+3l0M1bNMb7niCFDtug3gG3dk+CW+HcHdIq8BBm jorA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=wNz+JDmGulPqE8+DTCTJLtF5IeVLMfodqV1In4Cvwrk=; b=Bf4tvWwDvC4QbPnGPATjm+4YAWCJ0F+zEhMg0WOxwpFbtHaciS8/FEkqwkRYCJDl/8 1NRm9ghbEAY5zd6btN6l8uV7XTroaeCHo3J3bpslP+axd7Kx4uPI/qeA3UL/UXkZsyHw Y9fN6N/RrR/0fgjd/m6B9PrCL7Xgv1NpFhCjGPQ6BmF0aLuNn2rTSXYHwL4Y2aKPG7Qv 2QMlS43/GWECfCWDnhiPPnSiLMydfNfhvv0M+P7KCEU+FxHfLJU6HBodzgrXzZQtnJCr Oemmuw0iVlMK1OPYgsuietMMVtyhafmr7J7cQSc5waa6cUcbgHuemsKe2lbHyQBWNKCz OYCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cWkfh3O1; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn20si15263069ejc.196.2020.09.16.21.57.14; Wed, 16 Sep 2020 21:57:39 -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=@gmail.com header.s=20161025 header.b=cWkfh3O1; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726171AbgIQExZ (ORCPT + 99 others); Thu, 17 Sep 2020 00:53:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726126AbgIQExY (ORCPT ); Thu, 17 Sep 2020 00:53:24 -0400 Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF0AAC06174A; Wed, 16 Sep 2020 21:53:23 -0700 (PDT) Received: by mail-ed1-x544.google.com with SMTP id n13so1006884edo.10; Wed, 16 Sep 2020 21:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wNz+JDmGulPqE8+DTCTJLtF5IeVLMfodqV1In4Cvwrk=; b=cWkfh3O1pmoPFlb9+Bpb4H2BQ3nv+Kv6cCuPpr5pvvxnkuPYWuFpt0GTlzBKd+32sf CPUKpm93fQwhnsl+h+GyVV7AHWEVD+4cy6dsBdVlcA8g0eCBR7gaImP84mgamWkRY0+V hbXnWKpA+iaIVbISSAFrmwOj8iUcQKw5QTt6oEzWg2laRshTUJ5x+rSxt8JYGHhusJk9 TgPnnupskVfvEYOjpJDGzL6wEIKeLIhlAwRjgqoULK9OJbAwavothw6ngfiEBRJnfrtz m+4UQceeSdEUAM/d1mnYjYwHZ1tYxv3veSDaly4idJcynIXSisTtlDKu05Xx6VqTUi29 2eDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wNz+JDmGulPqE8+DTCTJLtF5IeVLMfodqV1In4Cvwrk=; b=toLEs/U3DYywK0RuyxUsjUJs7D91mDmYIyNhwt8UiLE/IXTpyWZl9rXOYzKuSE9C2G +Kl0cI0jLq1w0Hs3p0WDInEPvzFexNwr1nGINc1AnLAD7RC36uCygen9RYsVP1ViRrIX 53OekzKAfXySIkgiDKghTOJcR6Tp7B8oqB/oGIhR1WQD5db+hIdGCe9jyZfKtIIEH3fN q/Yx+TF/wzuD4tY3Rlr2vdkVPHWriJGO8ONi2fTFq+SG64PlLhz2iJ6iMPg7uVjTEW+Q HQDYvUysw4Gr1IHRdD6DkX/7JpfQudx5E3uzkLs6Y0kn4TL8A8SH9jF7H/RsgDiENsLJ Perg== X-Gm-Message-State: AOAM5327RGLdONscTYEICSttMegr78uONf0U1y2zBjvHRNVJT02UoQaE 1dhN0z/vQx4KOv+eMBL9J0RZcwzvKkSwd5mKAKM= X-Received: by 2002:a05:6402:1353:: with SMTP id y19mr31405733edw.71.1600318402672; Wed, 16 Sep 2020 21:53:22 -0700 (PDT) MIME-Version: 1.0 References: <20200917041519.3284582-1-mpe@ellerman.id.au> In-Reply-To: <20200917041519.3284582-1-mpe@ellerman.id.au> From: Max Filippov Date: Wed, 16 Sep 2020 21:53:11 -0700 Message-ID: Subject: Re: [PATCH] selftests/harness: Flush stdout before forking To: Michael Ellerman Cc: Kees Cook , linux-kselftest@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- Thanks. -- Max