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 7FB69C433FE for ; Thu, 24 Feb 2022 06:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbiBXGqx (ORCPT ); Thu, 24 Feb 2022 01:46:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbiBXGqv (ORCPT ); Thu, 24 Feb 2022 01:46:51 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EE8D26A3A2 for ; Wed, 23 Feb 2022 22:46:22 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id m13-20020a17090aab0d00b001bbe267d4d1so5151635pjq.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=NFVrwnwZiYoe82HSk3tXQBNf1YJ00ucBxDLSvS5nSQJcH6WT+pG3HO7H5N/nf+wi09 Jv0EbWjfZBb2qEQeIdQjDC2vQZXUims27DSLIhnJ5KcVbXDKa9a+p75clOOV5UWEsUPB OSPJEkUK8FCczO0Igej85/9qxO3etkv8Eie6nvqBTRhFQwS6szZKou+2bWLpoeTWRmz/ /pzmMJ6pihyEO5MQ27QateLDs+jMCf6WzR7NhmxfpktpmPIlzSox+ZYQgzq8fmhlCCDp K4mC65GHVLMjpWCJ8IC0g9Qg9L1EL+sRSq8VblxBaQijd1f3P/fQSuJtuqI+NS5LkA+Y 1vlA== X-Gm-Message-State: AOAM531ICxOirJ2WIAu/r80iDYNh0v1hSkx7WDGP6UNkmYAzEwULYOJQ 4DvEwZGuy2gG2R5BGLX7SjpP0A== 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-kernel@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