Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1269002pxm; Wed, 23 Feb 2022 22:58:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvTP/77/SQhLU0mB5SwvGR60piGReLWLCulyLa2WeFqyxXelv/KMXldMiecqTY8so8mE25 X-Received: by 2002:a50:9d89:0:b0:410:ff04:5a98 with SMTP id w9-20020a509d89000000b00410ff045a98mr1005593ede.404.1645685932371; Wed, 23 Feb 2022 22:58:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645685932; cv=none; d=google.com; s=arc-20160816; b=1A21a5nJAnx0jm58QSkOIYieycSEKg9PR0Q9fWqQnp8WGlqQ4bD1Bnq29CvAbawkho KrNjrsorw65BSf5BsN/zDgF4jjoPpU0iOpKGiDdGWmMHk4Nf5Nx4vrGAuwcX5rf0DPZc wPtNFhNDViNk/k0jo7z2QZD8MV0KZlKZjuazPfJSyE8LtTiTnAgv/rBQjYN4s1caSMS1 ZZrtbINgou0g4pYJ9b0KU04w+2ESq2ywyPLZYMNz1Bj/gwTTcBua1poUmo5jPdYVITQt EtOEGsoZl74U7BLYG3WJ8l/cPKhglAppdabuSr/+Poa1F2IMyEGOkYNSCXlFMpE0EtZk Vq+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BNrrQeR6NLfEy9loV4cRdfklZCJsQsZ1Ot62w9IVtWc=; b=XYNjI4DuObXB4GtBcxteCUy629/oxXIUwIkBfu9abxeD9R2jyNa7SYx4QZJgU4l7RJ k9szwodQ5E54JITNVbXgY8iRUujOy4vHged2rwP8Hyn4qg0iNHTgQSs6VYkYyD0QBiK/ 8yemubszMmvslPGHPOTYYZv6vSluu260FZQfeu9kvC9FDC9CIjh7mk5G/omup+MB1IY9 TPVqJe1hVHpCmQ+IEhjZkjBh7OVTnxAOUtdj77VBiPLoNzYEOmq8D3/5i9XZI3xjNdQo 1O3V39a5evwQtLvxfhGsw/Tp2sCcJHTrGN/tqzf84xjNQ1tqayUhjm7FlZ7zPLHlYQjG sXQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FC6WwKcl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 25si1137195ejh.573.2022.02.23.22.58.29; Wed, 23 Feb 2022 22:58:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FC6WwKcl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231350AbiBXGqx (ORCPT + 99 others); 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-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: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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