Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1881814pxm; Thu, 24 Feb 2022 11:11:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJ33d5iTG0Vb5iVVLCUkz7YZLJQAva4gV3fsmFeubdZJRQR7wfJiRvF149MyC5xL4cOHmE X-Received: by 2002:a63:515d:0:b0:373:8aca:7a40 with SMTP id r29-20020a63515d000000b003738aca7a40mr3315198pgl.284.1645729859753; Thu, 24 Feb 2022 11:10:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645729859; cv=none; d=google.com; s=arc-20160816; b=IMVw/4OyAOyae/NzVNL/Whf5rj4xb5hJliSiu7gYduA2KpwbQw1zEK3wERxzr3VLjB DF6xrjrdQy60jMrl0L6WQxQzLE3DiYO+V0A5cHZgfn/nmqb3br270eIXxyd0Oz8Zpium yNPCqsT5V/LIlsxVRGViPZogSwyIP1fuQgHJJ8NLnqOFlxIniQ83cRz1zjh2juM+Ud5y tiusGdFLunQ0Q7pCIr1u4TwEBjXZOlKkR7ID8AeU18mHctDsb1t1727qPAKPARfTOvXL 9Ot2+R01G6vjAUfBaspjpBkfRWNekQB80eG0Z5qZ/9kUrDgBrn9hKo7X01u2sirpWASI 7J1Q== 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=A9fzDXY9Pawtti5sitNYgs0Fy4usPU844voMfn3IdBw=; b=wK1/eWj7AKvv/f5sXdb19tnXqPC/HcAxVVtrWbsKQ4t/+/6O3B8cTTTgL8AECVkU88 pe5HzGn1Rqet2v3wK67q6eqYRqpiLGdDlSo4ld1lnel7oI805BV+OS8S0aujxml50wXg MkxtpEnUUCc9t/fQU68NFu3b7Fk/d0x2QUMI8eRwfzetNMUfLiUjnDb5R08eU1caOoUc VxxZTQLY7uDLmcfUVrxhrtRZTms6UmD337pUuYcXqIRKbp3+2Gv4wa90Ut7WYuH7i5TV HGZyLQIJXvduSwrsQsRbAIlm+IzjwMCqF//zgUWWeYENuYeY1+LiKH7f5Ynz2bekFtXK S2sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=dl6HDEGV; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dw5-20020a17090b094500b001bc8ef5a111si5727285pjb.93.2022.02.24.11.10.43; Thu, 24 Feb 2022 11:10:59 -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=@google.com header.s=20210112 header.b=dl6HDEGV; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232791AbiBXS25 (ORCPT + 99 others); Thu, 24 Feb 2022 13:28:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbiBXS24 (ORCPT ); Thu, 24 Feb 2022 13:28:56 -0500 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 614A312B76F for ; Thu, 24 Feb 2022 10:28:25 -0800 (PST) Received: by mail-ed1-x530.google.com with SMTP id w3so4080931edu.8 for ; Thu, 24 Feb 2022 10:28:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A9fzDXY9Pawtti5sitNYgs0Fy4usPU844voMfn3IdBw=; b=dl6HDEGVlT4NNXS+IICLIyWUeJ4CPNtZVqt7karefHOT34m9SGbvzOBZnY4TRymU+P TkWhXBb6+tkuw3h4utWmhoNw6f+PwulSb7gpb+/NZejGPPxjEbaBMwIoyyP5tVnqrnQI NU8gttIl16ZIr9mhL9cMEXK7E0Q9RK3aACepd+i0T6ECmKr1Ko8jaU6MhGwU4USSGPfq z779HAe3Cr+BgKDZ8/CCe0NULpEw0jkPfilJrpWc4A+0mBtl4Dx5QXt15277Bov3kmLJ xxFcHR9V4DDznD/q4rB8pCa4mUrLkNRhFtkVse/rJeEVYV0SEw/kkggDHdHJ7xCbHjRr tYIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A9fzDXY9Pawtti5sitNYgs0Fy4usPU844voMfn3IdBw=; b=XnE+iKupJQa5ZVsFF7OU9bShF6cT3MazuA1h+61W3c5c+pvCpFcYYZAc4QdEG0xlV7 e3ynyzxAa5xAaC8iJIK1PboACWhvgr1yEnGcsA7b3TZqbbEfv8nY4Q5Ky8pApFSJCf/g Az7oU/dKRnB40imBAuMKsevO+T506XXjHc6/HatlkkGygANYYoNVDY4kHpcnrijDZsEn +04YqX/JrUxsActEaVVTiylKEJgXorP7HKbOeUuEJ4WxjTRMD55M+ySvR00ur1lsDk6O SQWcaRJdqSr61AAvsKizs4m3tXUI8nhYkvanmTsF8lt1BCJkuYDLBo/jTahdIq0z4t54 CfOw== X-Gm-Message-State: AOAM531eUiQBxFJIToYcJmilGxAPId/GCVQvT5OTS1bWgUKQKVo7fAuL O2v8q2AfE2Kror7Il4lILcHnSkhc5HC4JDUkGrgMaA== X-Received: by 2002:aa7:d592:0:b0:410:b9f9:90f2 with SMTP id r18-20020aa7d592000000b00410b9f990f2mr3543452edq.327.1645727303752; Thu, 24 Feb 2022 10:28:23 -0800 (PST) MIME-Version: 1.0 References: <20220224055350.1854078-1-keescook@chromium.org> In-Reply-To: <20220224055350.1854078-1-keescook@chromium.org> From: Daniel Latypov Date: Thu, 24 Feb 2022 10:28:12 -0800 Message-ID: Subject: Re: [PATCH] kunit: tool: Do not colorize output when redirected To: Kees Cook Cc: Brendan Higgins , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, David Gow , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Wed, Feb 23, 2022 at 9: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 > --- > 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 I'd been thinking about doing this for a while. I'd just gotten used to removing them via sed, or ending pipes with less -R. I totally agree it's for the best that colors be turned off by default when piping. My hesitation was whether we'd want to introduce a flag like grep et al have. I.e. --color=auto/always/etc. Pros: * consistency with grep, maybe less surprise * allows wrappers around kunit.py to redirect output and still show color * this is very niche and I know it. But I happen to own such a wrapper :) Cons: * an extra flag that's very niche * I'm likely the only person to have ever used `kunit.py run | ... | less -R` * the logic to check for coloring becomes more complicated, need to add a helper I'm fine if we just stick with this simpler approach or do it later. My aforementioned wrapper only redirects stdout when necessary anyways. > 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.