[PATCH] selftests/ftrace: Make the coloring POSIX compliant

From: Juerg Haefliger
Date: Wed Feb 20 2019 - 11:13:44 EST


echo -e and \e are not POSIX. Depending on what /bin/sh is, we can get
incorrect output like:
$ -e -n [1] Basic trace file check
$ -e [PASS]

Fix that by using \033 instead of \e and printf.

Signed-off-by: Juerg Haefliger <juergh@xxxxxxxxxxxxx>
---
tools/testing/selftests/ftrace/ftracetest | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest
index fc755e1b50f1..f200898e3e2c 100755
--- a/tools/testing/selftests/ftrace/ftracetest
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -161,10 +161,10 @@ color_green=
color_blue=
# If stdout exists and number of colors is eight or more, use them
if [ -t 1 -a "$ncolors" -ge 8 ]; then
- color_reset="\e[0m"
- color_red="\e[31m"
- color_green="\e[32m"
- color_blue="\e[34m"
+ color_reset="\033[0m"
+ color_red="\033[31m"
+ color_green="\033[32m"
+ color_blue="\033[34m"
fi

strip_esc() {
@@ -173,8 +173,13 @@ strip_esc() {
}

prlog() { # messages
- echo -e "$@"
- [ "$LOG_FILE" ] && echo -e "$@" | strip_esc >> $LOG_FILE
+ newline="\n"
+ if [ "$1" = "-n" ] ; then
+ newline=
+ shift
+ fi
+ printf "$@$newline"
+ [ "$LOG_FILE" ] && printf "$@$newline" | strip_esc >> $LOG_FILE
}
catlog() { #file
cat $1
--
2.19.1