selftests/ftrace: Strip escape sequences for log file
diff mbox series

Message ID 153974720272.17748.17439079576533415951.stgit@devbox
State New
Headers show
Series
  • selftests/ftrace: Strip escape sequences for log file
Related show

Commit Message

Masami Hiramatsu Oct. 17, 2018, 3:33 a.m. UTC
Strip escape sequences from the stream to the ftracetest
summary log file. Note that all test-case results are
dumped raw in each file.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 tools/testing/selftests/ftrace/ftracetest |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Steven Rostedt Oct. 17, 2018, 8:45 p.m. UTC | #1
On Wed, 17 Oct 2018 12:33:23 +0900
Masami Hiramatsu <mhiramat@kernel.org> wrote:

> Strip escape sequences from the stream to the ftracetest
> summary log file. Note that all test-case results are
> dumped raw in each file.
> 

Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

Shuah,

Please take this one too.

Thanks!

-- Steve
shuah Oct. 17, 2018, 11:02 p.m. UTC | #2
On 10/17/2018 02:45 PM, Steven Rostedt wrote:
> On Wed, 17 Oct 2018 12:33:23 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 
>> Strip escape sequences from the stream to the ftracetest
>> summary log file. Note that all test-case results are
>> dumped raw in each file.
>>
> 
> Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
> 
> Shuah,
> 
> Please take this one too.
> 

Yup. Applied to linux-kselftest for 4.20-rc1.

thanks,
-- Shuah

Patch
diff mbox series

diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest
index d987bbec675f..75244db70331 100755
--- a/tools/testing/selftests/ftrace/ftracetest
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -167,11 +167,18 @@  if [ -t 1 -a "$ncolors" -a "$ncolors" -ge 8 ]; then
   color_blue="\e[34m"
 fi
 
+strip_esc() {
+  # busybox sed implementation doesn't accept "\x1B", so use [:cntrl:] instead.
+  sed -E "s/[[:cntrl:]]\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
+}
+
 prlog() { # messages
-  [ -z "$LOG_FILE" ] && echo -e "$@" || echo -e "$@" | tee -a $LOG_FILE
+  echo -e "$@"
+  [ "$LOG_FILE" ] && echo -e "$@" | strip_esc >> $LOG_FILE
 }
 catlog() { #file
-  [ -z "$LOG_FILE" ] && cat $1 || cat $1 | tee -a $LOG_FILE
+  cat $1
+  [ "$LOG_FILE" ] && cat $1 | strip_esc >> $LOG_FILE
 }
 prlog "=== Ftrace unit tests ==="