From: Steven Rostedt <rostedt@goodmis.org>
To: "Daniel Díaz" <daniel.diaz@linaro.org>
Cc: shuah@kernel.org, linux-kselftest@vger.kernel.org,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org (open list),
Masami Hiramatsu <mhiramat@kernel.org>
Subject: Re: [PATCH] selftests/ftrace: Use colored output when available
Date: Tue, 16 Oct 2018 13:09:56 -0400 [thread overview]
Message-ID: <20181016130956.2be3b984@gandalf.local.home> (raw)
In-Reply-To: <20181016170220.31156-1-daniel.diaz@linaro.org>
Masami,
Does this fix the issues you reported?
-- Steve
On Tue, 16 Oct 2018 12:02:20 -0500
Daniel Díaz <daniel.diaz@linaro.org> wrote:
> 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 <daniel.diaz@linaro.org>
> ---
> 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
> ;;
next prev parent reply other threads:[~2018-10-16 17:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-16 17:02 [PATCH] selftests/ftrace: Use colored output when available Daniel Díaz
2018-10-16 17:09 ` Steven Rostedt [this message]
2018-10-17 1:03 ` Masami Hiramatsu
2018-10-17 3:33 ` [PATCH] selftests/ftrace: Strip escape sequences for log file Masami Hiramatsu
2018-10-17 20:45 ` Steven Rostedt
2018-10-17 23:02 ` Shuah Khan
2018-10-16 17:43 ` [PATCH] selftests/ftrace: Use colored output when available Shuah Khan
2018-10-16 18:20 ` Daniel Díaz
2018-10-16 18:34 ` Steven Rostedt
2018-10-17 15:19 ` Shuah Khan
2018-10-17 20:41 ` Steven Rostedt
2018-10-17 23:01 ` Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181016130956.2be3b984@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=daniel.diaz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).