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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5F1AC433F5 for ; Thu, 24 Feb 2022 06:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbiBXGqw (ORCPT ); Thu, 24 Feb 2022 01:46:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231350AbiBXGqv (ORCPT ); Thu, 24 Feb 2022 01:46:51 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6328F26A3B1 for ; Wed, 23 Feb 2022 22:46:22 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id v5-20020a17090ac90500b001bc40b548f9so4901354pjt.0 for ; Wed, 23 Feb 2022 22:46:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=BNrrQeR6NLfEy9loV4cRdfklZCJsQsZ1Ot62w9IVtWc=; b=FC6WwKcl8bcpZH6rSRW+egDrnBFtM3/+Wz8W+smEyyK8YkHUvCqHkLVFsbIzKgtIkZ rpJQYoPf92HL8Ol2sa/r8myerAxpRTYyvXhTy3eMvROo9vuXKaMmnwMwAwIW0RqdRIhC sCT8nHeSsD0KGOEbF+WJ88qUpgbSAyDK377p0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=BNrrQeR6NLfEy9loV4cRdfklZCJsQsZ1Ot62w9IVtWc=; b=LFoplC1IwVldk9ymfmBMBqXlD3ykq/NydPFMweL8Rq4XlTmlE6nW0wvKqVaVlLwK3w oVSwkg4YUbzakLLzRzdPeW84hZ3UsqSBE2WSci+Ff7UMz+pG0+1hLzPA61E/Bz2Jdsjc bvQrNNGM/pISvjgmxP2CH9LgNom3eZsUknPwm9X3RLrsZE8oGdsdLxuO4jjFvqlPNGTH HLSYReqHpDvZP0ObV9GwYTzCIXX5HBUpDt97UrwAe5jSCYwJklO/WH6Yfsnx90rTher2 ImTwkY0cReICbHQQ78+Tpjz/QHF6Cq1uhN2yH5L4134gDrI27UnqpsMRstN66KK0EW6X YYkg== X-Gm-Message-State: AOAM530n7XL9kivZiyVmlL32TUGAC7M8wmO5N0eIHjbz5Kf6kiPmta3w ksAqdT5V5n+gLm92teb9yhKT6Q== X-Google-Smtp-Source: ABdhPJxPMmxj82io+/WpZ92rz6mdpLfWg+7yYFn+HEFTUTwqoTzzIKGNd9B5t41jrbqTU+7RMRhLuA== X-Received: by 2002:a17:90a:ab89:b0:1bc:71a7:f93a with SMTP id n9-20020a17090aab8900b001bc71a7f93amr1341755pjq.111.1645685181936; Wed, 23 Feb 2022 22:46:21 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f7sm1866845pfc.0.2022.02.23.22.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 22:46:21 -0800 (PST) Date: Wed, 23 Feb 2022 22:46:21 -0800 From: Kees Cook To: David Gow Cc: Brendan Higgins , "open list:KERNEL SELFTEST FRAMEWORK" , KUnit Development , Linux Kernel Mailing List , linux-hardening@vger.kernel.org Subject: Re: [PATCH] kunit: tool: Do not colorize output when redirected Message-ID: <202202232245.BD69919F@keescook> References: <20220224055350.1854078-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org On Thu, Feb 24, 2022 at 02:43:53PM +0800, David Gow wrote: > On Thu, Feb 24, 2022 at 1:53 PM Kees Cook wrote: > > > > Filling log files with color codes makes diffs and other comparisons > > difficult. Only emit vt100 codes when the stdout is a TTY. > > > > Cc: Brendan Higgins > > Cc: linux-kselftest@vger.kernel.org > > Cc: kunit-dev@googlegroups.com > > Signed-off-by: Kees Cook > > --- > > Ah, you can tell a tool has "made it" when people are redirecting its output! Heheh. Indeed! I have some more patches coming where I put a diff of output in the commit log. ;) > This works fine here. > > Reviewed-by: David Gow Thanks! -Kees > > Thanks, > -- David > > > tools/testing/kunit/kunit_parser.py | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py > > index 05ff334761dd..807ed2bd6832 100644 > > --- a/tools/testing/kunit/kunit_parser.py > > +++ b/tools/testing/kunit/kunit_parser.py > > @@ -11,6 +11,7 @@ > > > > from __future__ import annotations > > import re > > +import sys > > > > import datetime > > from enum import Enum, auto > > @@ -503,14 +504,20 @@ RESET = '\033[0;0m' > > > > def red(text: str) -> str: > > """Returns inputted string with red color code.""" > > + if not sys.stdout.isatty(): > > + return text > > return '\033[1;31m' + text + RESET > > > > def yellow(text: str) -> str: > > """Returns inputted string with yellow color code.""" > > + if not sys.stdout.isatty(): > > + return text > > return '\033[1;33m' + text + RESET > > > > def green(text: str) -> str: > > """Returns inputted string with green color code.""" > > + if not sys.stdout.isatty(): > > + return text > > return '\033[1;32m' + text + RESET > > > > ANSI_LEN = len(red('')) > > -- > > 2.30.2 > > > > -- > > You received this message because you are subscribed to the Google Groups "KUnit Development" group. > > To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@googlegroups.com. > > To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20220224055350.1854078-1-keescook%40chromium.org. -- Kees Cook