Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp130109pxk; Wed, 16 Sep 2020 21:24:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmopHiEpIuSfAu7SypzPG7m3mcYgJAYS/VdkTHU1wj1pFfri/DWVp+W4LGyHr8DREBaPdP X-Received: by 2002:aa7:dac5:: with SMTP id x5mr26834843eds.72.1600316661002; Wed, 16 Sep 2020 21:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600316660; cv=none; d=google.com; s=arc-20160816; b=JAHxpuxuhSQLUU6uAXFTaGhtzdKyrgWjQbn+l/pxFyQjn9YOTjQqxrd5fHfMkO9/Oe PCV80mG7uTtadZ3bew9hB+BKg40h99TV1UZuy+XTuBrx1uHsQ8YbloennXZmWWqmskhB jpFsThjgkm40VecjLUe1dfxF9KrQOV253/WuC9Lb9hqM2m6iPe66C3lY2ZKTg/dRzesP a5VUoRilpMitsL9Pb47Q7+Y31fxQ2aSqn0iZtlEJVkbaUkJRkGrLc0gjVdfLlljv0ntp SgjNRE1XUZMM4cllqxN+3Pg8Hr4o5S6P2iN6wwWW7n+BrkstqoP+7lq802ak4GbcvkP2 T21w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=pUZsBwy7/8m+WER1C0+eKgH93iXeT6qrAPgP13FwW+k=; b=US7SAzZuaP3Jh7NtIrdIORGf6xu81RJed5J0KqwXX3Q3H5MDhwFwiE5OqhZi6BmxxY neJgmbI3UcLsUQVlVbonEY0lsr2ZP+V0vODL68ndS/FZuYs+kSu8NvnqZ6tfushHDo/6 +2K4wFpgPJBF7RfLABwIv0kie/ky4MVAJBXF4JLl/+L//tJCs/q/mnaCM0+7LkTqPjsa kUgPbBFfPk+ljWmVq4H+kHxPa0r7vvkuPTL7Pc+6qVaQkS4deIjkHrAt3NQLnT49umjh Ro+PmG+RHYf/gSPNQcq8kjc+NZ6Ws8LEB8T+X0ho5hbNJhJir/U6Yp7H+Y5GXueFjve/ t+4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=dnMJXdBQ; 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 i5si13122142ejs.267.2020.09.16.21.23.57; Wed, 16 Sep 2020 21:24:20 -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=dnMJXdBQ; 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 S1726135AbgIQEW7 (ORCPT + 99 others); Thu, 17 Sep 2020 00:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725858AbgIQEW7 (ORCPT ); Thu, 17 Sep 2020 00:22:59 -0400 Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71889C06174A; Wed, 16 Sep 2020 21:16:16 -0700 (PDT) Received: by ozlabs.org (Postfix, from userid 1034) id 4BsNtv1s87z9sSn; Thu, 17 Sep 2020 14:15:59 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1600316167; bh=E4XTRIY2Yg5zL9/EFXMuDBdNiIOZtiHl+cuCUmjJXGw=; h=From:To:Cc:Subject:Date:From; b=dnMJXdBQiQhKQ4LlvkTFq7q1SWmi7Eb4zYRGEE9QQcaZauuZnnT20J4dFS2U/Fzi+ GZL3ChfHLiOflz3xxaPzo4gxvBDzXYh6+HeaSkYEh7IsF5//BOq438Rc0DwZufsa8X s8mn7sZfXaMhyNEqA9re1rC/d8sEycbRwpOI2TFRMFPLBYZ/ij34H/KB5+vKps8Ph0 Yrxqzr5ki4lWVaA/vjkdj0eao/gTxUmZVdKw5aD8nv5GJhkl65Q8MtVQW//x/n/bS6 cNE9Ew0z9EL18ZIAj0GG5K4MxRkLjshyC5B5bNJdEhsmcbuIErvZbstSHE+BgFPAmT 4ywo/8iLBpXUA== From: Michael Ellerman To: keescook@chromium.org Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, jcmvbkbc@gmail.com Subject: [PATCH] selftests/harness: Flush stdout before forking Date: Thu, 17 Sep 2020 14:15:19 +1000 Message-Id: <20200917041519.3284582-1-mpe@ellerman.id.au> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 4f78e4805633..f19804df244c 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -971,6 +971,11 @@ void __run_test(struct __fixture_metadata *f, ksft_print_msg(" RUN %s%s%s.%s ...\n", f->name, variant->name[0] ? "." : "", variant->name, t->name); + + /* Make sure output buffers are flushed before fork */ + fflush(stdout); + fflush(stderr); + t->pid = fork(); if (t->pid < 0) { ksft_print_msg("ERROR SPAWNING TEST CHILD\n"); -- 2.25.1