From patchwork Tue Oct 16 17:02:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_D=C3=ADaz?= X-Patchwork-Id: 10643905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93F6317D2 for ; Tue, 16 Oct 2018 17:02:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 687C32A632 for ; Tue, 16 Oct 2018 17:02:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B1C62A634; Tue, 16 Oct 2018 17:02:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E67702A632 for ; Tue, 16 Oct 2018 17:02:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727211AbeJQAyP (ORCPT ); Tue, 16 Oct 2018 20:54:15 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:46501 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727163AbeJQAyP (ORCPT ); Tue, 16 Oct 2018 20:54:15 -0400 Received: by mail-yw1-f66.google.com with SMTP id j202-v6so9184449ywa.13 for ; Tue, 16 Oct 2018 10:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RaPTae517Y+bNpef4yQIvFQgsgdIAhxr/JzYA1ji4RE=; b=fmAZyL/XuhaSR2b0tAZm1ewvTSsWICZRbQWOkl85bVnbDxw0cff6TSdw54wgOcAnXN +Ey7/unYVeqNSTZBIbHYGaTypTyXZnx+cPl2seqtb4KxIrsMdSa+FC/nBV8tQnKqn52F TYm2LhLxClitrtIVeThsNkRG8m4w/kX28dl4c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=RaPTae517Y+bNpef4yQIvFQgsgdIAhxr/JzYA1ji4RE=; b=uEVHGuvEJYYpNhaXll4/w9bBzAFRbbWZToCYW4fXyUHPPAEh9EDlnmI7dP7S8OYl05 WAn28QmIikFSj9vHgzrVZls/B77kGTEjNfrZ+jqufueQxkRdPpEETfzzg8r6/edWeLXG ygH4ZTBP51L5EYIRROZSh7EVP3yqNxp34DDO8DOn2lpMp+A56mU8nlGcMHfyuuy/uxR2 zwQK2WhIL/6wBmYZNY0qEwfUaWNbm/N1C4ZqUGdrNBdW4q/OL9lzJbUa3bhjYppTHluc 9bHADoggLEzZsgbbDhvbSkZpd1wE2Fa3H3/C6KVafnCrRiy3dQytzZ4qX1zKxXIXQMGo /q6Q== X-Gm-Message-State: ABuFfoj/clvjBDXOF4UBk2JfS5rlhllb0qBZu4jbqaufSQBlu6bRf2mZ RMx/oeBzyUsXM5TDwGcRWi/xeNz0xjMIARSz X-Google-Smtp-Source: ACcGV63Owz/bC1n1lNE4SmpSEXBNZ8/AnuA0FhxlN61PoEKxSUUBapLfckn1EmpfHJWWGdJimbgE4A== X-Received: by 2002:a0d:fe07:: with SMTP id o7-v6mr9730237ywf.379.1539709374895; Tue, 16 Oct 2018 10:02:54 -0700 (PDT) Received: from alago.cortijodelrio.net (CableLink-187-161-144-121.PCs.InterCable.net. [187.161.144.121]) by smtp.googlemail.com with ESMTPSA id r8-v6sm5049384ywa.56.2018.10.16.10.02.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Oct 2018 10:02:53 -0700 (PDT) From: =?utf-8?q?Daniel_D=C3=ADaz?= To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: =?utf-8?q?Daniel_D=C3=ADaz?= , Steven Rostedt , Ingo Molnar , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] selftests/ftrace: Use colored output when available Date: Tue, 16 Oct 2018 12:02:20 -0500 Message-Id: <20181016170220.31156-1-daniel.diaz@linaro.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If test is being directly executed (with stdout opened on the terminal) and the terminal capabilities indicate enough colors, then use the existing scheme of green, red, and blue to show when tests pass, fail or end in a different way. When running the tests redirecting the stdout, for instance, to a file, then colors are not shown, thus producing a more readable output. Signed-off-by: Daniel Díaz Acked-by: Masami Hiramatsu Acked-by: Steven Rostedt (VMware) --- tools/testing/selftests/ftrace/ftracetest | 29 +++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest index 4946b2edfcff..d987bbec675f 100755 --- a/tools/testing/selftests/ftrace/ftracetest +++ b/tools/testing/selftests/ftrace/ftracetest @@ -152,6 +152,21 @@ else date > $LOG_FILE fi +# Define text colors +# Check available colors on the terminal, if any +ncolors=`tput colors 2>/dev/null` +color_reset= +color_red= +color_green= +color_blue= +# If stdout exists and number of colors is eight or more, use them +if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then + color_reset="\e[0m" + color_red="\e[31m" + color_green="\e[32m" + color_blue="\e[34m" +fi + prlog() { # messages [ -z "$LOG_FILE" ] && echo -e "$@" || echo -e "$@" | tee -a $LOG_FILE } @@ -195,37 +210,37 @@ test_on_instance() { # testfile eval_result() { # sigval case $1 in $PASS) - prlog " [\e[32mPASS\e[30m]" + prlog " [${color_green}PASS${color_reset}]" PASSED_CASES="$PASSED_CASES $CASENO" return 0 ;; $FAIL) - prlog " [\e[31mFAIL\e[30m]" + prlog " [${color_red}FAIL${color_reset}]" FAILED_CASES="$FAILED_CASES $CASENO" return 1 # this is a bug. ;; $UNRESOLVED) - prlog " [\e[34mUNRESOLVED\e[30m]" + prlog " [${color_blue}UNRESOLVED${color_reset}]" UNRESOLVED_CASES="$UNRESOLVED_CASES $CASENO" return 1 # this is a kind of bug.. something happened. ;; $UNTESTED) - prlog " [\e[34mUNTESTED\e[30m]" + prlog " [${color_blue}UNTESTED${color_reset}]" UNTESTED_CASES="$UNTESTED_CASES $CASENO" return 0 ;; $UNSUPPORTED) - prlog " [\e[34mUNSUPPORTED\e[30m]" + prlog " [${color_blue}UNSUPPORTED${color_reset}]" UNSUPPORTED_CASES="$UNSUPPORTED_CASES $CASENO" return $UNSUPPORTED_RESULT # depends on use case ;; $XFAIL) - prlog " [\e[31mXFAIL\e[30m]" + prlog " [${color_red}XFAIL${color_reset}]" XFAILED_CASES="$XFAILED_CASES $CASENO" return 0 ;; *) - prlog " [\e[34mUNDEFINED\e[30m]" + prlog " [${color_blue}UNDEFINED${color_reset}]" UNDEFINED_CASES="$UNDEFINED_CASES $CASENO" return 1 # this must be a test bug ;;