Skip to contentSkip to conversation

selftests/ftrace: Fix ftracetest testcases for dash, etc.

PATCH In review Masami Hiramatsu 8 participants 38 messages May 1, 2020 – May 28, 2020

Subsystems (2)
lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

cover selftests/ftrace: Fix ftracetest testcases for dash, etc.

Hi,

Here are some patches to update ftracetest to fix some issues.
- [1/3] Fix coloring of XFAIL
- [2/3] Fix a testcase not to expect just one event entry
- [3/3] Do not use built-in echo because the behavior is different on dash and bash. (Thanks Liu for reporting!)

Thank you,

---

Masami Hiramatsu (3):
selftests/ftrace: Make XFAIL green color selftests/ftrace: Pick only the first kprobe event to test selftests/ftrace: Use /bin/echo instead of built-in echo

 tools/testing/selftests/ftrace/ftracetest          |    2 +-
 tools/testing/selftests/ftrace/test.d/functions    |    3 +++
 .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
 .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
 .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
 .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
 6 files changed, 12 insertions(+), 5 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/3 selftests/ftrace: Make XFAIL green color

Since XFAIL (Expected Failure) is expected to fail the test, which means that test case works as we expected. IOW, XFAIL is same as PASS. So make it green.

---
 tools/testing/selftests/ftrace/ftracetest |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/ftracetest +1 -1
index 063ecb290a5a..72e837d0dfc1 100755
@@ -273,7 +273,7 @@ eval_result() { # sigval
       return $UNSUPPORTED_RESULT # depends on use case
     ;;
     $XFAIL)
-      prlog "	[${color_red}XFAIL${color_reset}]"
+      prlog "	[${color_green}XFAIL${color_reset}]"
       XFAILED_CASES="$XFAILED_CASES $CASENO"
       return 0
     ;;
maintainer
#2 lore raw

Re: [PATCH 1/3] selftests/ftrace: Make XFAIL green color

Quoted 3 lines · On Fri, 1 May 2020 22:37:41 +0900 Masami Hiramatsu <[email protected]> wrote:

Since XFAIL (Expected Failure) is expected to fail the test, which means that test case works as we expected. IOW, XFAIL is same as PASS. So make it green.

THANK YOU!!!! That's been annoying me for some time ;-)

BIG Acked-by: Steven Rostedt (VMware) <[email protected]>

-- Steve

Quoted 19 lines
---
 tools/testing/selftests/ftrace/ftracetest |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/ftracetest +1 -1
index 063ecb290a5a..72e837d0dfc1 100755
@@ -273,7 +273,7 @@ eval_result() { # sigval
       return $UNSUPPORTED_RESULT # depends on use case
     ;;
     $XFAIL)
-      prlog "	[${color_red}XFAIL${color_reset}]"
+      prlog "	[${color_green}XFAIL${color_reset}]"
       XFAILED_CASES="$XFAILED_CASES $CASENO"
       return 0
     ;;
author maintainer
#3 lore raw

PATCH 2/3 selftests/ftrace: Pick only the first kprobe event to test

In reply to Masami Hiramatsu

Since the kprobe/kprobe_args_type.tc reads out all event logs from the trace buffer, the test can fail if there is another fork event happens.
Use head command to pick only the first kprobe event from the trace buffer to test the argument types.

---
 .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +1 -1
index 1bcb67dcae26..81490ecaaa92 100644
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
   echo 0 > events/kprobes/testprobe/enable
 
   : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
   check_types $ARGS $width
 
   : "Clear event for next loop"
maintainer Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] selftests/ftrace: Pick only the first kprobe event to test

Quoted 16 lines · On Fri, 1 May 2020 22:37:51 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the kprobe/kprobe_args_type.tc reads out all event logs from the trace buffer, the test can fail if there is another fork event happens.
Use head command to pick only the first kprobe event from the trace buffer to test the argument types.

---
 .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +0 -0
index 1bcb67dcae26..81490ecaaa92 100644

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc for width in 64 32 16 8; do · line 44

Quoted 8 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +1 -1
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
   echo 0 > events/kprobes/testprobe/enable
 
   : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
   check_types $ARGS $width
 
   : "Clear event for next loop"

I think I've manually added this exact change to my tests to keep it from failing.

-- Steve

maintainer
#5 lore raw

Re: [PATCH 2/3] selftests/ftrace: Pick only the first kprobe event to test

Quoted 26 lines · Steven Rostedt
Quoted 23 lines · On Fri, 1 May 2020 22:37:51 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the kprobe/kprobe_args_type.tc reads out all event logs from the trace buffer, the test can fail if there is another fork event happens.
Use head command to pick only the first kprobe event from the trace buffer to test the argument types.

---
  .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +1 -1
index 1bcb67dcae26..81490ecaaa92 100644
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
    echo 0 > events/kprobes/testprobe/enable
 
    : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
    check_types $ARGS $width
 
Quoted 7 lines

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc for width in 64 32 16 8; do · line 44

Quoted 1 line
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +0 -0
    : "Clear event for next loop"

I think I've manually added this exact change to my tests to keep it from failing.

Does this conflict with:

Author: Xiao Yang <[email protected]>
Date:   Tue Apr 7 14:34:19 2020 +0800

selftests/ftrace: Check the first record for kprobe_args_type.tc

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/commit/?h=next&id=f0c0d0cf590f71b2213b29a7ded2cde3d0a1a0ba

I went into mainline yesterday in my rc4 pull request.

Exact change it appears.

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +1 -1
index 1bcb67dcae26..81490ecaaa92 100644
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
   echo 0 > events/kprobes/testprobe/enable
 
   : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
   check_types $ARGS $width
 
   : "Clear event for next loop"

thanks,
-- Shuah

maintainer
#6 lore raw

Re: [PATCH 2/3] selftests/ftrace: Pick only the first kprobe event to test

Quoted 40 lines · On Fri, 1 May 2020 09:38:59 -0600 shuah <[email protected]> wrote:
Quoted 26 lines · Steven Rostedt
Quoted 23 lines · On Fri, 1 May 2020 22:37:51 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the kprobe/kprobe_args_type.tc reads out all event logs from the trace buffer, the test can fail if there is another fork event happens.
Use head command to pick only the first kprobe event from the trace buffer to test the argument types.

---
  .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +1 -1
index 1bcb67dcae26..81490ecaaa92 100644
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
    echo 0 > events/kprobes/testprobe/enable
 
    : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
    check_types $ARGS $width
 
Quoted 7 lines

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc for width in 64 32 16 8; do · line 44

Quoted 1 line
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +0 -0
    : "Clear event for next loop"  

I think I've manually added this exact change to my tests to keep it from failing.

Does this conflict with:

Author: Xiao Yang <[email protected]>
Date:   Tue Apr 7 14:34:19 2020 +0800
Quoted 7 lines

selftests/ftrace: Check the first record for kprobe_args_type.tc

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/commit/?h=next&id=f0c0d0cf590f71b2213b29a7ded2cde3d0a1a0ba

I went into mainline yesterday in my rc4 pull request.

Exact change it appears.

Ah, then I guess we don't need this patch ;-)

-- Steve

Quoted 21 lines
(quoted diff) +0 -0

a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc index 1bcb67dcae26..81490ecaaa92 100644

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +0 -1
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
    echo 0 > events/kprobes/testprobe/enable
 
    : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) 

arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+ ARGS=grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/' check_types $ARGS $width

: "Clear event for next loop"

thanks,
-- Shuah

maintainer
#7 lore raw

Re: [PATCH 2/3] selftests/ftrace: Pick only the first kprobe event to test

Quoted 45 lines · Steven Rostedt
Quoted 42 lines · On Fri, 1 May 2020 09:38:59 -0600 shuah <[email protected]> wrote:
Quoted 26 lines · Steven Rostedt
Quoted 23 lines · On Fri, 1 May 2020 22:37:51 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the kprobe/kprobe_args_type.tc reads out all event logs from the trace buffer, the test can fail if there is another fork event happens.
Use head command to pick only the first kprobe event from the trace buffer to test the argument types.

---
   .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +1 -1
index 1bcb67dcae26..81490ecaaa92 100644
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
     echo 0 > events/kprobes/testprobe/enable
 
     : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
     check_types $ARGS $width
 
Quoted 7 lines

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc for width in 64 32 16 8; do · line 44

Quoted 1 line
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +0 -0
     : "Clear event for next loop"

I think I've manually added this exact change to my tests to keep it from failing.

Does this conflict with:

Author: Xiao Yang <[email protected]>
Date:   Tue Apr 7 14:34:19 2020 +0800

selftests/ftrace: Check the first record for kprobe_args_type.tc

Quoted 8 lines
Quoted 5 lines

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/commit/?h=next&id=f0c0d0cf590f71b2213b29a7ded2cde3d0a1a0ba

I went into mainline yesterday in my rc4 pull request.

Exact change it appears.

Ah, then I guess we don't need this patch ;-)

I took the first one. Will wait for patch 3 to finalize.

thanks,
-- Shuah

author maintainer
#8 lore raw

Re: [PATCH 2/3] selftests/ftrace: Pick only the first kprobe event to test

In reply to shuah
Quoted 64 lines · On Fri, 1 May 2020 09:38:59 -0600 shuah <[email protected]> wrote:
Quoted 26 lines · Steven Rostedt
Quoted 23 lines · On Fri, 1 May 2020 22:37:51 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the kprobe/kprobe_args_type.tc reads out all event logs from the trace buffer, the test can fail if there is another fork event happens.
Use head command to pick only the first kprobe event from the trace buffer to test the argument types.

---
  .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +1 -1
index 1bcb67dcae26..81490ecaaa92 100644
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
    echo 0 > events/kprobes/testprobe/enable
 
    : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+  ARGS=`grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
    check_types $ARGS $width
 
Quoted 7 lines

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc for width in 64 32 16 8; do · line 44

Quoted 1 line
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +0 -0
    : "Clear event for next loop"

I think I've manually added this exact change to my tests to keep it from failing.

Does this conflict with:

Author: Xiao Yang <[email protected]>
Date:   Tue Apr 7 14:34:19 2020 +0800

selftests/ftrace: Check the first record for kprobe_args_type.tc

https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/commit/?h=next&id=f0c0d0cf590f71b2213b29a7ded2cde3d0a1a0ba

I went into mainline yesterday in my rc4 pull request.

Exact change it appears.

(quoted diff) +0 -0

a/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc b/tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc index 1bcb67dcae26..81490ecaaa92 100644

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_args_type.tc +0 -1
@@ -38,7 +38,7 @@ for width in 64 32 16 8; do
    echo 0 > events/kprobes/testprobe/enable
 
    : "Confirm the arguments is recorded in given types correctly"
-  ARGS=`grep "testprobe" trace | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) 

arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/'`
+ ARGS=grep "testprobe" trace | head -n 1 | sed -e 's/.* arg1=\(.*\) arg2=\(.*\) arg3=\(.*\) arg4=\(.*\)/\1 \2 \3 \4/' check_types $ARGS $width

Quoted 1 line

: "Clear event for next loop"

Oops, yes, please drop this patch.

Thank you,

Quoted 3 lines

thanks,
-- Shuah

Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#9 lore raw

PATCH 3/3 selftests/ftrace: Use /bin/echo instead of built-in echo

In reply to Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

This also fixes some test cases which expects built-in echo command.

---
 tools/testing/selftests/ftrace/test.d/functions    |    3 +++
 .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
 .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
 .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
 4 files changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +3 -0
index 5d4550591ff9..ea59b6ea2c3e 100644
@@ -1,3 +1,6 @@
+# Since the built-in echo has different behavior in POSIX shell (dash) and
+# bash, we forcibly use /bin/echo -E (not interpret backslash escapes).
+alias echo="/bin/echo -E"
 
 clear_trace() { # reset trace output
     echo > trace
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
index ab6bedb25736..b3f70f53ee69 100644
@@ -30,7 +30,7 @@ fi
 
 echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid' > events/ftrace/print/trigger
+echo 'hist:keys=ip' > events/ftrace/print/trigger
 for i in `seq 1 10` ; do echo "hello" > trace_marker; done
 grep 'hitcount: *10$' events/ftrace/print/hist > /dev/null || \
     fail "hist trigger did not trigger correct times on trace_marker"
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc +4 -0
index 18b4d1c2807e..c1625d945f4d 100644
@@ -44,6 +44,10 @@ echo 'latency u64 lat' > synthetic_events
 echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
 echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+
+# We have to use the built-in echo here because waking up pid must be same
+# as echoing pid.
+alias echo=echo
 sleep 1
 echo "hello" > trace_marker
 
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
index dd262d6d0db6..23e52c8d71de 100644
@@ -36,8 +36,8 @@ fi
 echo "Test histogram trace_marker to trace_marker latency histogram trigger"
 
 echo 'latency u64 lat' > synthetic_events
-echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger
+echo 'hist:keys=ip:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
+echo 'hist:keys=ip:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
 echo -n "start" > trace_marker
 echo -n "end" > trace_marker
maintainer
#10 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 32 lines · On Fri, 1 May 2020 22:38:00 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

This also fixes some test cases which expects built-in echo command.

---
 tools/testing/selftests/ftrace/test.d/functions    |    3 +++
 .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
 .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
 .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
 4 files changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +3 -0
index 5d4550591ff9..ea59b6ea2c3e 100644
@@ -1,3 +1,6 @@
+# Since the built-in echo has different behavior in POSIX shell (dash) and
+# bash, we forcibly use /bin/echo -E (not interpret backslash escapes).
+alias echo="/bin/echo -E"
 
 clear_trace() { # reset trace output
     echo > trace
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +0 -0
index ab6bedb25736..b3f70f53ee69 100644

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc fi · line 33

Quoted 5 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
@@ -30,7 +30,7 @@ fi
 
 echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid' > events/ftrace/print/trigger
+echo 'hist:keys=ip' > events/ftrace/print/trigger

This is doing more than just changing the echo being used. It's changing the test being done.

Quoted 23 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +0 -0
 for i in `seq 1 10` ; do echo "hello" > trace_marker; done
 grep 'hitcount: *10$' events/ftrace/print/hist > /dev/null || \
     fail "hist trigger did not trigger correct times on trace_marker"
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc +4 -0
index 18b4d1c2807e..c1625d945f4d 100644
@@ -44,6 +44,10 @@ echo 'latency u64 lat' > synthetic_events
 echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
 echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+
+# We have to use the built-in echo here because waking up pid must be same
+# as echoing pid.
+alias echo=echo
 sleep 1
 echo "hello" > trace_marker
 
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +0 -0
index dd262d6d0db6..23e52c8d71de 100644

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc fi · line 40

Quoted 7 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
@@ -36,8 +36,8 @@ fi
 echo "Test histogram trace_marker to trace_marker latency histogram trigger"
 
 echo 'latency u64 lat' > synthetic_events
-echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger
+echo 'hist:keys=ip:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
+echo 'hist:keys=ip:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger

This too. And it's not explained in the change log why. In fact, these changes look like they belong in a separate patch.

-- Steve

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +0 -0
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
 echo -n "start" > trace_marker
 echo -n "end" > trace_marker
author maintainer
#11 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 36 lines · On Fri, 1 May 2020 10:19:42 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 33 lines · On Fri, 1 May 2020 22:38:00 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

This also fixes some test cases which expects built-in echo command.

---
 tools/testing/selftests/ftrace/test.d/functions    |    3 +++
 .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
 .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
 .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
 4 files changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +3 -0
index 5d4550591ff9..ea59b6ea2c3e 100644
@@ -1,3 +1,6 @@
+# Since the built-in echo has different behavior in POSIX shell (dash) and
+# bash, we forcibly use /bin/echo -E (not interpret backslash escapes).
+alias echo="/bin/echo -E"
 
 clear_trace() { # reset trace output
     echo > trace
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +0 -0
index ab6bedb25736..b3f70f53ee69 100644
@@ -30,7 +30,7 @@ fi
 
Quoted 7 lines

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc fi · line 33

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
 echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid' > events/ftrace/print/trigger
+echo 'hist:keys=ip' > events/ftrace/print/trigger

This is doing more than just changing the echo being used. It's changing the test being done.

Yes, I need Tom's review for this change. As far as I can test, this fixes the test failure. If this isn't acceptable, we can use "alias echo=echo" for this test case.

Thank you,

Quoted 41 lines
Quoted 24 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +0 -0
 for i in `seq 1 10` ; do echo "hello" > trace_marker; done
 grep 'hitcount: *10$' events/ftrace/print/hist > /dev/null || \
     fail "hist trigger did not trigger correct times on trace_marker"
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc +4 -0
index 18b4d1c2807e..c1625d945f4d 100644
@@ -44,6 +44,10 @@ echo 'latency u64 lat' > synthetic_events
 echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
 echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+
+# We have to use the built-in echo here because waking up pid must be same
+# as echoing pid.
+alias echo=echo
 sleep 1
 echo "hello" > trace_marker
 
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +0 -0
index dd262d6d0db6..23e52c8d71de 100644

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc fi · line 40

Quoted 7 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
@@ -36,8 +36,8 @@ fi
 echo "Test histogram trace_marker to trace_marker latency histogram trigger"
 
 echo 'latency u64 lat' > synthetic_events
-echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger
+echo 'hist:keys=ip:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
+echo 'hist:keys=ip:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger

This too. And it's not explained in the change log why. In fact, these changes look like they belong in a separate patch.

-- Steve

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +0 -0
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
 echo -n "start" > trace_marker
 echo -n "end" > trace_marker
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#12 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 14 lines · On Sat, 2 May 2020 12:08:42 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 6 lines
Quoted 6 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +0 -0
index ab6bedb25736..b3f70f53ee69 100644
@@ -30,7 +30,7 @@ fi
 
Quoted 7 lines

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc fi · line 33

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
 echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid' > events/ftrace/print/trigger
+echo 'hist:keys=ip' > events/ftrace/print/trigger  

This is doing more than just changing the echo being used. It's changing the test being done.

Quoted 4 lines

Yes, I need Tom's review for this change. As far as I can test, this fixes the test failure. If this isn't acceptable, we can use "alias echo=echo" for this test case.

I still don't see how changing "keys=common_pid" to "keys=ip" has anything to do with the echo patch. If that is a problem, it should be a different patch with explanation to why "keys=common_pid" is broken.

-- Steve

author maintainer
#13 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 17 lines · On Thu, 7 May 2020 09:12:07 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 14 lines · On Sat, 2 May 2020 12:08:42 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 13 lines

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc fi · line 33

Quoted 10 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
index ab6bedb25736..b3f70f53ee69 100644
@@ -30,7 +30,7 @@ fi
 
 echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid' > events/ftrace/print/trigger
+echo 'hist:keys=ip' > events/ftrace/print/trigger  

This is doing more than just changing the echo being used. It's changing the test being done.

Quoted 8 lines
Quoted 4 lines

Yes, I need Tom's review for this change. As far as I can test, this fixes the test failure. If this isn't acceptable, we can use "alias echo=echo" for this test case.

I still don't see how changing "keys=common_pid" to "keys=ip" has anything to do with the echo patch. If that is a problem, it should be a different patch with explanation to why "keys=common_pid" is broken.

This test case uses a trace_marker event to make a histogram with the common_pid key, and it expects the "echo" command is built-in command so that the pid is same while writing several events to trace_marker. I changed it to "ip" which is always same if trace_marker interface is used.

Thank you,

Quoted 3 lines

-- Steve

Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#14 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 9 lines · On Fri, 8 May 2020 00:50:28 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines

Yes, I need Tom's review for this change. As far as I can test, this fixes the test failure. If this isn't acceptable, we can use "alias echo=echo" for this test case.

I still don't see how changing "keys=common_pid" to "keys=ip" has anything to do with the echo patch. If that is a problem, it should be a different patch with explanation to why "keys=common_pid" is broken.

Quoted 5 lines

This test case uses a trace_marker event to make a histogram with the common_pid key, and it expects the "echo" command is built-in command so that the pid is same while writing several events to trace_marker. I changed it to "ip" which is always same if trace_marker interface is used.

Can you explicitly state that in your change log? It wasn't obvious from what you meant with:

"This also fixes some test cases which expects built-in echo command."

Thanks!

-- Steve

Reviewed-by
#15 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Hi,

Quoted 18 lines · Steven Rostedt
Quoted 9 lines · On Fri, 8 May 2020 00:50:28 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines

Yes, I need Tom's review for this change. As far as I can test, this fixes the test failure. If this isn't acceptable, we can use "alias echo=echo" for this test case.

I still don't see how changing "keys=common_pid" to "keys=ip" has anything to do with the echo patch. If that is a problem, it should be a different patch with explanation to why "keys=common_pid" is broken.

Quoted 5 lines

This test case uses a trace_marker event to make a histogram with the common_pid key, and it expects the "echo" command is built-in command so that the pid is same while writing several events to trace_marker. I changed it to "ip" which is always same if trace_marker interface is used.

Quoted 5 lines

Can you explicitly state that in your change log? It wasn't obvious from what you meant with:

"This also fixes some test cases which expects built-in echo command."

With that change,

Thanks,

Tom

Quoted 4 lines

Thanks!

-- Steve

author maintainer
#16 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 25 lines · Tom

Hi,

Quoted 22 lines · Steven Rostedt
Quoted 9 lines · On Fri, 8 May 2020 00:50:28 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines

Yes, I need Tom's review for this change. As far as I can test, this fixes the test failure. If this isn't acceptable, we can use "alias echo=echo" for this test case.

I still don't see how changing "keys=common_pid" to "keys=ip" has anything to do with the echo patch. If that is a problem, it should be a different patch with explanation to why "keys=common_pid" is broken.

Quoted 5 lines

This test case uses a trace_marker event to make a histogram with the common_pid key, and it expects the "echo" command is built-in command so that the pid is same while writing several events to trace_marker. I changed it to "ip" which is always same if trace_marker interface is used.

Can you explicitly state that in your change log? It wasn't obvious from what you meant with:

"This also fixes some test cases which expects built-in echo command."

OK, will add the description.

Quoted 5 lines
Quoted 1 line

With that change,

Thanks Tom!

Quoted 9 lines

Thanks,

Tom

Quoted 4 lines

Thanks!

-- Steve

Signature · 1 line
Masami Hiramatsu <[email protected]>
#17 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

In reply to Masami Hiramatsu
Quoted 21 lines · Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

This also fixes some test cases which expects built-in echo command.

---
  tools/testing/selftests/ftrace/test.d/functions    |    3 +++
  .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
  .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
  .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
  4 files changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +0 -0
index 5d4550591ff9..ea59b6ea2c3e 100644

tools/testing/selftests/ftrace/test.d/functions line 3

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/functions +3 -0
@@ -1,3 +1,6 @@
+# Since the built-in echo has different behavior in POSIX shell (dash) and
+# bash, we forcibly use /bin/echo -E (not interpret backslash escapes).
+alias echo="/bin/echo -E"

Hi Masami, Steven

It seems that only kprobe_syntax_errors.tc is impacted by the issue currently. Is it necessary for all tests to use /bin/echo and could we just make kprobe_syntax_errors.tc use /bin/echo?

Best Regards,
Xiao Yang

Quoted 51 lines
tools/testing/selftests/ftrace/test.d/functions +0 -0
  clear_trace() { # reset trace output
      echo>  trace
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
index ab6bedb25736..b3f70f53ee69 100644
@@ -30,7 +30,7 @@ fi
 
  echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid'>  events/ftrace/print/trigger
+echo 'hist:keys=ip'>  events/ftrace/print/trigger
  for i in `seq 1 10` ; do echo "hello">  trace_marker; done
  grep 'hitcount: *10$' events/ftrace/print/hist>  /dev/null || \
      fail "hist trigger did not trigger correct times on trace_marker"
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc +4 -0
index 18b4d1c2807e..c1625d945f4d 100644
@@ -44,6 +44,10 @@ echo 'latency u64 lat'>  synthetic_events
  echo 'hist:keys=pid:ts0=common_timestamp.usecs'>  events/sched/sched_waking/trigger
  echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)'>  events/ftrace/print/trigger
  echo 'hist:keys=common_pid,lat:sort=lat'>  events/synthetic/latency/trigger
+
+# We have to use the built-in echo here because waking up pid must be same
+# as echoing pid.
+alias echo=echo
  sleep 1
  echo "hello">  trace_marker
 
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
index dd262d6d0db6..23e52c8d71de 100644
@@ -36,8 +36,8 @@ fi
  echo "Test histogram trace_marker to trace_marker latency histogram trigger"
 
  echo 'latency u64 lat'>  synthetic_events
-echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"'>  events/ftrace/print/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"'>>  events/ftrace/print/trigger
+echo 'hist:keys=ip:ts0=common_timestamp.usecs if buf == "start"'>  events/ftrace/print/trigger
+echo 'hist:keys=ip:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"'>>  events/ftrace/print/trigger
  echo 'hist:keys=common_pid,lat:sort=lat'>  events/synthetic/latency/trigger
  echo -n "start">  trace_marker
  echo -n "end">  trace_marker

.

author maintainer
#18 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 27 lines · On Thu, 7 May 2020 14:45:16 +0800 Xiao Yang <[email protected]> wrote:
Quoted 21 lines · Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

This also fixes some test cases which expects built-in echo command.

---
  tools/testing/selftests/ftrace/test.d/functions    |    3 +++
  .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
  .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
  .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
  4 files changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +0 -0
index 5d4550591ff9..ea59b6ea2c3e 100644

tools/testing/selftests/ftrace/test.d/functions line 3

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/functions +3 -0
@@ -1,3 +1,6 @@
+# Since the built-in echo has different behavior in POSIX shell (dash) and
+# bash, we forcibly use /bin/echo -E (not interpret backslash escapes).
+alias echo="/bin/echo -E"

Hi Masami, Steven

Quoted 3 lines

It seems that only kprobe_syntax_errors.tc is impacted by the issue currently. Is it necessary for all tests to use /bin/echo and could we just make kprobe_syntax_errors.tc use /bin/echo?

Yes, I would like to unify the "echo"'s behavior among the testcases instead of patching each failure in the future.
Or would you have any concern on it?

Thank you,

Quoted 58 lines

Best Regards,
Xiao Yang

Quoted 51 lines
tools/testing/selftests/ftrace/test.d/functions +0 -0
  clear_trace() { # reset trace output
      echo>  trace
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
index ab6bedb25736..b3f70f53ee69 100644
@@ -30,7 +30,7 @@ fi
 
  echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid'>  events/ftrace/print/trigger
+echo 'hist:keys=ip'>  events/ftrace/print/trigger
  for i in `seq 1 10` ; do echo "hello">  trace_marker; done
  grep 'hitcount: *10$' events/ftrace/print/hist>  /dev/null || \
      fail "hist trigger did not trigger correct times on trace_marker"
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc +4 -0
index 18b4d1c2807e..c1625d945f4d 100644
@@ -44,6 +44,10 @@ echo 'latency u64 lat'>  synthetic_events
  echo 'hist:keys=pid:ts0=common_timestamp.usecs'>  events/sched/sched_waking/trigger
  echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)'>  events/ftrace/print/trigger
  echo 'hist:keys=common_pid,lat:sort=lat'>  events/synthetic/latency/trigger
+
+# We have to use the built-in echo here because waking up pid must be same
+# as echoing pid.
+alias echo=echo
  sleep 1
  echo "hello">  trace_marker
 
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
index dd262d6d0db6..23e52c8d71de 100644
@@ -36,8 +36,8 @@ fi
  echo "Test histogram trace_marker to trace_marker latency histogram trigger"
 
  echo 'latency u64 lat'>  synthetic_events
-echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"'>  events/ftrace/print/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"'>>  events/ftrace/print/trigger
+echo 'hist:keys=ip:ts0=common_timestamp.usecs if buf == "start"'>  events/ftrace/print/trigger
+echo 'hist:keys=ip:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"'>>  events/ftrace/print/trigger
  echo 'hist:keys=common_pid,lat:sort=lat'>  events/synthetic/latency/trigger
  echo -n "start">  trace_marker
  echo -n "end">  trace_marker

.

Signature · 1 line
Masami Hiramatsu <[email protected]>
#19 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 30 lines · Masami Hiramatsu
Quoted 27 lines · On Thu, 7 May 2020 14:45:16 +0800 Xiao Yang<[email protected]> wrote:
Quoted 21 lines · Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

This also fixes some test cases which expects built-in echo command.

---
   tools/testing/selftests/ftrace/test.d/functions    |    3 +++
   .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
   .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
   .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
   4 files changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +0 -0
index 5d4550591ff9..ea59b6ea2c3e 100644

tools/testing/selftests/ftrace/test.d/functions line 3

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/functions +3 -0
@@ -1,3 +1,6 @@
+# Since the built-in echo has different behavior in POSIX shell (dash) and
+# bash, we forcibly use /bin/echo -E (not interpret backslash escapes).
+alias echo="/bin/echo -E"

Hi Masami, Steven

Quoted 7 lines
Quoted 3 lines

It seems that only kprobe_syntax_errors.tc is impacted by the issue currently. Is it necessary for all tests to use /bin/echo and could we just make kprobe_syntax_errors.tc use /bin/echo?

Yes, I would like to unify the "echo"'s behavior among the testcases instead of patching each failure in the future.
Or would you have any concern on it?

Hi Masami,

Very sorry for the late reply.

We may not avoid fixing related failures after your change:
1) We have to reuse built-in echo (do alias echo=echo) if we want to test common_pid for histogram.
2) We have to reuse built-in echo if some new tests want to interpret backslash escapes in future.

Is it simple to provide two implementations of echo?(built-in echo and echo command?) and then just apply echo command for kprobe_syntax_errors.tc?

BTW: My suggestion may not be correct.

Best Regards,
Xiao Yang

Quoted 63 lines

Thank you,

Quoted 58 lines

Best Regards,
Xiao Yang

Quoted 51 lines
tools/testing/selftests/ftrace/test.d/functions +0 -0
   clear_trace() { # reset trace output
       echo>   trace
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc +1 -1
index ab6bedb25736..b3f70f53ee69 100644
@@ -30,7 +30,7 @@ fi
 
   echo "Test histogram trace_marker tigger"
 
-echo 'hist:keys=common_pid'>   events/ftrace/print/trigger
+echo 'hist:keys=ip'>   events/ftrace/print/trigger
   for i in `seq 1 10` ; do echo "hello">   trace_marker; done
   grep 'hitcount: *10$' events/ftrace/print/hist>   /dev/null || \
       fail "hist trigger did not trigger correct times on trace_marker"
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc +4 -0
index 18b4d1c2807e..c1625d945f4d 100644
@@ -44,6 +44,10 @@ echo 'latency u64 lat'>   synthetic_events
   echo 'hist:keys=pid:ts0=common_timestamp.usecs'>   events/sched/sched_waking/trigger
   echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)'>   events/ftrace/print/trigger
   echo 'hist:keys=common_pid,lat:sort=lat'>   events/synthetic/latency/trigger
+
+# We have to use the built-in echo here because waking up pid must be same
+# as echoing pid.
+alias echo=echo
   sleep 1
   echo "hello">   trace_marker
 
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
index dd262d6d0db6..23e52c8d71de 100644
@@ -36,8 +36,8 @@ fi
   echo "Test histogram trace_marker to trace_marker latency histogram trigger"
 
   echo 'latency u64 lat'>   synthetic_events
-echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"'>   events/ftrace/print/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"'>>   events/ftrace/print/trigger
+echo 'hist:keys=ip:ts0=common_timestamp.usecs if buf == "start"'>   events/ftrace/print/trigger
+echo 'hist:keys=ip:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"'>>   events/ftrace/print/trigger
   echo 'hist:keys=common_pid,lat:sort=lat'>   events/synthetic/latency/trigger
   echo -n "start">   trace_marker
   echo -n "end">   trace_marker

.

author maintainer
#20 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 40 lines · On Mon, 11 May 2020 15:22:25 +0800 Xiao Yang <[email protected]> wrote:
Quoted 30 lines · Masami Hiramatsu
Quoted 27 lines · On Thu, 7 May 2020 14:45:16 +0800 Xiao Yang<[email protected]> wrote:
Quoted 21 lines · Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

This also fixes some test cases which expects built-in echo command.

---
   tools/testing/selftests/ftrace/test.d/functions    |    3 +++
   .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
   .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
   .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
   4 files changed, 10 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +0 -0
index 5d4550591ff9..ea59b6ea2c3e 100644

tools/testing/selftests/ftrace/test.d/functions line 3

Quoted 3 lines
tools/testing/selftests/ftrace/test.d/functions +3 -0
@@ -1,3 +1,6 @@
+# Since the built-in echo has different behavior in POSIX shell (dash) and
+# bash, we forcibly use /bin/echo -E (not interpret backslash escapes).
+alias echo="/bin/echo -E"

Hi Masami, Steven

Quoted 7 lines
Quoted 3 lines

It seems that only kprobe_syntax_errors.tc is impacted by the issue currently. Is it necessary for all tests to use /bin/echo and could we just make kprobe_syntax_errors.tc use /bin/echo?

Yes, I would like to unify the "echo"'s behavior among the testcases instead of patching each failure in the future.
Or would you have any concern on it?

Hi Masami,

Quoted 7 lines

Very sorry for the late reply.

We may not avoid fixing related failures after your change:
1) We have to reuse built-in echo (do alias echo=echo) if we want to test common_pid for histogram.
2) We have to reuse built-in echo if some new tests want to interpret backslash escapes in future.

1) yes, that's what I need to do for avoiding "pid" key histogram (but I think we should have better way to test it)
2) No, in that case you should use "/bin/echo -e" explicitly. dash's built-in echo doesn't support it.

Quoted 2 lines

Is it simple to provide two implementations of echo?(built-in echo and echo command?) and then just apply echo command for kprobe_syntax_errors.tc?

Hmm, OK, there might be another reason we reconsider this patch.

- Alisasing echo (this patch) can avoid dash related issues but this also makes "echo" running in another process implicitly.

- Using /bin/echo for backslash explicitly will be missed unless user runs it on dash, but it will keep "echo" in same process.

So both have pros/cons, but your idea will be locally effected. OK, I'll retry it.

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
#21 lore raw

RE: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

From: Masami Hiramatsu

Quoted 1 line

Sent: 11 May 2020 10:28

...

Quoted 14 lines
Quoted 5 lines

We may not avoid fixing related failures after your change:
1) We have to reuse built-in echo (do alias echo=echo) if we want to test common_pid for histogram.
2) We have to reuse built-in echo if some new tests want to interpret backslash escapes in future.

1) yes, that's what I need to do for avoiding "pid" key histogram (but I think we should have better way to test it)
2) No, in that case you should use "/bin/echo -e" explicitly. dash's built-in echo doesn't support it.

Quoted 2 lines

Is it simple to provide two implementations of echo?(built-in echo and echo command?) and then just apply echo command for kprobe_syntax_errors.tc?

Quoted 7 lines

Hmm, OK, there might be another reason we reconsider this patch.

- Alisasing echo (this patch) can avoid dash related issues but this also makes "echo" running in another process implicitly.

- Using /bin/echo for backslash explicitly will be missed unless user runs it on dash, but it will keep "echo" in same process.

Why not change to use printf - probably a builtin in both shells?

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author maintainer
#22 lore raw

PATCH 1/1 selftests/ftrace: Use /bin/echo for backslash included command

In reply to Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, kprobe_syntax_errors.tc can fail on dash which interpret backslash escape automatically.

To fix this issue, we explicitly use /bin/echo -E (not interpret backslash escapes) if the command string can include backslash.

---
 tools/testing/selftests/ftrace/test.d/functions    |    8 +++++---
 .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc   |    4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +5 -3
index 61a3c7e2634d..69708830026f 100644
@@ -119,12 +119,14 @@ yield() {
     ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
 }
 
+# Since probe event command may include backslash, explicitly use /bin/echo -E
+# to NOT interpret it.
 ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
-    pos=$(echo -n "${2%^*}" | wc -c) # error position
-    command=$(echo "$2" | tr -d ^)
+    pos=$(/bin/echo -En "${2%^*}" | wc -c) # error position
+    command=$(/bin/echo -E "$2" | tr -d ^)
     echo "Test command: $command"
     echo > error_log
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! /bin/echo -E "$command" >> "$3" ) 2> /dev/null
     grep "$1: error:" -A 3 error_log
     N=$(tail -n 1 error_log | wc -c)
     # "  Command: " and "^\n" => 13
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +3 -1
index ef1e9bafb098..4cfcf9440a1a 100644
@@ -91,7 +91,9 @@ esac
 if grep -q "Create/append/" README && grep -q "imm-value" README; then
 echo 'p:kprobes/testevent _do_fork' > kprobe_events
 check_error '^r:kprobes/testevent do_exit'	# DIFF_PROBE_TYPE
-echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
+
+# Explicitly use /bin/echo -E to not interpret \1
+/bin/echo -E 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
 check_error 'p:kprobes/testevent _do_fork ^bcd=\1'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"'	# DIFF_ARG_TYPE
#23 lore raw

Re: [PATCH] selftests/ftrace: Use /bin/echo for backslash included command

Quoted 2 lines · Masami Hiramatsu

To fix this issue, we explicitly use /bin/echo -E (not interpret backslash escapes) if the command string can include backslash.

Please use printf instead.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
author maintainer
#24 lore raw

PATCH v2 1/1 selftests/ftrace: Use printf for backslash included command

Since the built-in echo has different behavior in POSIX shell (dash) and bash, kprobe_syntax_errors.tc can fail on dash which interpret backslash escape automatically.

To fix this issue, we explicitly use printf "%s" (not interpret backslash escapes) if the command string can include backslash.

---
 tools/testing/selftests/ftrace/test.d/functions    |    8 +++++---
 .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc   |    4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +5 -3
index 61a3c7e2634d..697c77ef2e2b 100644
@@ -119,12 +119,14 @@ yield() {
     ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
 }
 
+# Since probe event command may include backslash, explicitly use printf "%s"
+# to NOT interpret it.
 ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
-    pos=$(echo -n "${2%^*}" | wc -c) # error position
-    command=$(echo "$2" | tr -d ^)
+    pos=$(printf "%s" "${2%^*}" | wc -c) # error position
+    command=$(printf "%s" "$2" | tr -d ^)
     echo "Test command: $command"
     echo > error_log
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null
     grep "$1: error:" -A 3 error_log
     N=$(tail -n 1 error_log | wc -c)
     # "  Command: " and "^\n" => 13
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +3 -1
index ef1e9bafb098..eb0f4ab4e070 100644
@@ -91,7 +91,9 @@ esac
 if grep -q "Create/append/" README && grep -q "imm-value" README; then
 echo 'p:kprobes/testevent _do_fork' > kprobe_events
 check_error '^r:kprobes/testevent do_exit'	# DIFF_PROBE_TYPE
-echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
+
+# Explicitly use printf "%s" to not interpret \1
+printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
 check_error 'p:kprobes/testevent _do_fork ^bcd=\1'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"'	# DIFF_ARG_TYPE
author maintainer
#25 lore raw

Re: [PATCH v2] selftests/ftrace: Use printf for backslash included command

Hi Andreas and David,

OK, what about this fix?

Quoted 53 lines · On Mon, 11 May 2020 22:36:27 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the built-in echo has different behavior in POSIX shell (dash) and bash, kprobe_syntax_errors.tc can fail on dash which interpret backslash escape automatically.

To fix this issue, we explicitly use printf "%s" (not interpret backslash escapes) if the command string can include backslash.

---
 tools/testing/selftests/ftrace/test.d/functions    |    8 +++++---
 .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc   |    4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +5 -3
index 61a3c7e2634d..697c77ef2e2b 100644
@@ -119,12 +119,14 @@ yield() {
     ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
 }
 
+# Since probe event command may include backslash, explicitly use printf "%s"
+# to NOT interpret it.
 ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
-    pos=$(echo -n "${2%^*}" | wc -c) # error position
-    command=$(echo "$2" | tr -d ^)
+    pos=$(printf "%s" "${2%^*}" | wc -c) # error position
+    command=$(printf "%s" "$2" | tr -d ^)
     echo "Test command: $command"
     echo > error_log
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null
     grep "$1: error:" -A 3 error_log
     N=$(tail -n 1 error_log | wc -c)
     # "  Command: " and "^\n" => 13
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +3 -1
index ef1e9bafb098..eb0f4ab4e070 100644
@@ -91,7 +91,9 @@ esac
 if grep -q "Create/append/" README && grep -q "imm-value" README; then
 echo 'p:kprobes/testevent _do_fork' > kprobe_events
 check_error '^r:kprobes/testevent do_exit'	# DIFF_PROBE_TYPE
-echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
+
+# Explicitly use printf "%s" to not interpret \1
+printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
 check_error 'p:kprobes/testevent _do_fork ^bcd=\1'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"'	# DIFF_ARG_TYPE
Signature · 1 line
Masami Hiramatsu <[email protected]>
#26 lore raw

RE: [PATCH v2] selftests/ftrace: Use printf for backslash included command

From: Masami Hiramatsu

Quoted 5 lines

Sent: 11 May 2020 14:38

Hi Andreas and David,

OK, what about this fix?

No idea what it is trying to do or why.
Just a way of avoiding the differences between SYSV and BSD /bin/echo.

IIRC Posix allows both behaviours (and probably others).

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

author maintainer
#27 lore raw

Re: [PATCH v2] selftests/ftrace: Use printf for backslash included command

Quoted 11 lines · On Mon, 11 May 2020 13:46:35 +0000 David Laight <[email protected]> wrote:

From: Masami Hiramatsu

Quoted 5 lines

Sent: 11 May 2020 14:38

Hi Andreas and David,

OK, what about this fix?

No idea what it is trying to do or why.
Just a way of avoiding the differences between SYSV and BSD /bin/echo.

IIRC Posix allows both behaviours (and probably others).

Ah, I got it. That's why POSIX said "the results are implementation-defined."

https://pubs.opengroup.org/onlinepubs/009695399/utilities/echo.html

Thank you!

Signature · 1 line
Masami Hiramatsu <[email protected]>
#28 lore raw

RE: [PATCH v2] selftests/ftrace: Use printf for backslash included command

In reply to Masami Hiramatsu
Quoted 2 lines

tools/testing/selftests/ftrace/test.d/functions yield() { · line 126

Quoted 2 lines
tools/testing/selftests/ftrace/test.d/functions +2 -0
+    pos=$(printf "%s" "${2%^*}" | wc -c) # error position
+    command=$(printf "%s" "$2" | tr -d ^)

You may want to put all the $(...) inside "" to avoid field splitting (not relevant to a shell assignment with modern shells) and filename globbing.

Quoted 4 lines

tools/testing/selftests/ftrace/test.d/functions yield() { · line 129

Quoted 4 lines

echo "Test command: $command"
echo > error_log

tools/testing/selftests/ftrace/test.d/functions +1 -1
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null

WTF is the (! for ??
The (...) is a subshell.
And ! inverts the exit status.
Neither is needed at all.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

maintainer
#29 lore raw

Re: [PATCH v2] selftests/ftrace: Use printf for backslash included command

Quoted 9 lines · On Mon, 11 May 2020 14:59:20 +0000 David Laight <[email protected]> wrote:
Quoted 4 lines

tools/testing/selftests/ftrace/test.d/functions yield() { · line 129

Quoted 4 lines

echo "Test command: $command"
echo > error_log

tools/testing/selftests/ftrace/test.d/functions +1 -1
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null  

WTF is the (! for ??
The (...) is a subshell. And ! inverts the exit status. Neither is needed at all.

This is done because the scripts are run with '-e' and will exit the script on any error.

This particular test is examining errors in the error log. The command being written into $3 is going to fail, and return an exit code. The "(! ..)" is needed, otherwise that failure will exit out the script.

-- Steve

#30 lore raw

Re: [PATCH v2] selftests/ftrace: Use printf for backslash included command

In reply to Masami Hiramatsu

tools/testing/selftests/ftrace/test.d/functions yield() { · line 129

Quoted 2 lines · Masami Hiramatsu
tools/testing/selftests/ftrace/test.d/functions +1 -1
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null

printf %s does not print a newline, you need printf '%s\n' for that.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
author maintainer
#31 lore raw

Re: [PATCH v2] selftests/ftrace: Use printf for backslash included command

Quoted 6 lines · On Mon, 11 May 2020 15:42:10 +0200 Andreas Schwab <[email protected]> wrote:

tools/testing/selftests/ftrace/test.d/functions yield() { · line 129

Quoted 2 lines · Masami Hiramatsu
tools/testing/selftests/ftrace/test.d/functions +1 -1
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null

printf %s does not print a newline, you need printf '%s\n' for that.

Actually, ftrace doesn't need newline for single command. The reason why we had used echo instead of "echo -n" here, is just for short typing :)

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#32 lore raw

Re: [PATCH v2] selftests/ftrace: Use printf for backslash included command

In reply to Masami Hiramatsu

Hi Shuah,

Could you pick this to kselftest-next?

Thank you,

Quoted 53 lines · On Mon, 11 May 2020 22:36:27 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the built-in echo has different behavior in POSIX shell (dash) and bash, kprobe_syntax_errors.tc can fail on dash which interpret backslash escape automatically.

To fix this issue, we explicitly use printf "%s" (not interpret backslash escapes) if the command string can include backslash.

---
 tools/testing/selftests/ftrace/test.d/functions    |    8 +++++---
 .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc   |    4 +++-
 2 files changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +5 -3
index 61a3c7e2634d..697c77ef2e2b 100644
@@ -119,12 +119,14 @@ yield() {
     ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
 }
 
+# Since probe event command may include backslash, explicitly use printf "%s"
+# to NOT interpret it.
 ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
-    pos=$(echo -n "${2%^*}" | wc -c) # error position
-    command=$(echo "$2" | tr -d ^)
+    pos=$(printf "%s" "${2%^*}" | wc -c) # error position
+    command=$(printf "%s" "$2" | tr -d ^)
     echo "Test command: $command"
     echo > error_log
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null
     grep "$1: error:" -A 3 error_log
     N=$(tail -n 1 error_log | wc -c)
     # "  Command: " and "^\n" => 13
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +3 -1
index ef1e9bafb098..eb0f4ab4e070 100644
@@ -91,7 +91,9 @@ esac
 if grep -q "Create/append/" README && grep -q "imm-value" README; then
 echo 'p:kprobes/testevent _do_fork' > kprobe_events
 check_error '^r:kprobes/testevent do_exit'	# DIFF_PROBE_TYPE
-echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
+
+# Explicitly use printf "%s" to not interpret \1
+printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
 check_error 'p:kprobes/testevent _do_fork ^bcd=\1'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8'	# DIFF_ARG_TYPE
 check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"'	# DIFF_ARG_TYPE
Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#33 lore raw

Re: [PATCH v2] selftests/ftrace: Use printf for backslash included command

Quoted 54 lines · Masami Hiramatsu

Hi Shuah,

Could you pick this to kselftest-next?

Thank you,

Quoted 45 lines · On Mon, 11 May 2020 22:36:27 +0900 Masami Hiramatsu <[email protected]> wrote:

Since the built-in echo has different behavior in POSIX shell (dash) and bash, kprobe_syntax_errors.tc can fail on dash which interpret backslash escape automatically.

To fix this issue, we explicitly use printf "%s" (not interpret backslash escapes) if the command string can include backslash.

---
  tools/testing/selftests/ftrace/test.d/functions    |    8 +++++---
  .../ftrace/test.d/kprobe/kprobe_syntax_errors.tc   |    4 +++-
  2 files changed, 8 insertions(+), 4 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +5 -3
index 61a3c7e2634d..697c77ef2e2b 100644
@@ -119,12 +119,14 @@ yield() {
      ping $LOCALHOST -c 1 || sleep .001 || usleep 1 || sleep 1
  }
 
+# Since probe event command may include backslash, explicitly use printf "%s"
+# to NOT interpret it.
  ftrace_errlog_check() { # err-prefix command-with-error-pos-by-^ command-file
-    pos=$(echo -n "${2%^*}" | wc -c) # error position
-    command=$(echo "$2" | tr -d ^)
+    pos=$(printf "%s" "${2%^*}" | wc -c) # error position
+    command=$(printf "%s" "$2" | tr -d ^)
      echo "Test command: $command"
      echo > error_log
-    (! echo "$command" >> "$3" ) 2> /dev/null
+    (! printf "%s" "$command" >> "$3" ) 2> /dev/null
      grep "$1: error:" -A 3 error_log
      N=$(tail -n 1 error_log | wc -c)
      # "  Command: " and "^\n" => 13
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +0 -0
index ef1e9bafb098..eb0f4ab4e070 100644
@@ -91,7 +91,9 @@ esac
  if grep -q "Create/append/" README && grep -q "imm-value" README; then
  echo 'p:kprobes/testevent _do_fork' > kprobe_events
  check_error '^r:kprobes/testevent do_exit'	# DIFF_PROBE_TYPE
Quoted 10 lines

tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc esac · line 99

Quoted 8 lines
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +3 -1
-echo 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
+
+# Explicitly use printf "%s" to not interpret \1
+printf "%s" 'p:kprobes/testevent _do_fork abcd=\1' > kprobe_events
  check_error 'p:kprobes/testevent _do_fork ^bcd=\1'	# DIFF_ARG_TYPE
  check_error 'p:kprobes/testevent _do_fork ^abcd=\1:u8'	# DIFF_ARG_TYPE
  check_error 'p:kprobes/testevent _do_fork ^abcd=\"foo"'	# DIFF_ARG_TYPE

Applied to

git.kernel.org/pub/scm/linux/kernel/git/shuah/linux kselftest.git/ next branch for Linux 5.8-rc1

thanks,
-- Shuah

#34 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

In reply to Masami Hiramatsu
Quoted 3 lines · Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

How about using printf instead (at least where it matters)?

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
author maintainer
#35 lore raw

Re: [PATCH 3/3] selftests/ftrace: Use /bin/echo instead of built-in echo

Quoted 7 lines · On Thu, 07 May 2020 11:22:28 +0200 Andreas Schwab <[email protected]> wrote:
Quoted 3 lines · Masami Hiramatsu

Since the built-in echo has different behavior in POSIX shell (dash) and bash, we forcibly use /bin/echo -E (not interpret backslash escapes) by default.

How about using printf instead (at least where it matters)?

Hmm, I think replacing all echos with printf in the testcase might be much harder than this...

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
maintainer
#36 lore raw
In reply to Masami Hiramatsu

[ FYI, Shuah responds better from her linuxfoundation.org email ]

Shuah,

Feel free to take the first two patches of this series (I acked one, and reviewed the other).

The last patch I had some issues with, and is still under discussion.

Thanks!

-- Steve

Quoted 28 lines · On Fri, 1 May 2020 22:37:31 +0900 Masami Hiramatsu <[email protected]> wrote:

Hi,

Here are some patches to update ftracetest to fix some issues.
- [1/3] Fix coloring of XFAIL
- [2/3] Fix a testcase not to expect just one event entry
- [3/3] Do not use built-in echo because the behavior is different on dash and bash. (Thanks Liu for reporting!)

Thank you,

---

Masami Hiramatsu (3):
selftests/ftrace: Make XFAIL green color selftests/ftrace: Pick only the first kprobe event to test selftests/ftrace: Use /bin/echo instead of built-in echo

 tools/testing/selftests/ftrace/ftracetest          |    2 +-
 tools/testing/selftests/ftrace/test.d/functions    |    3 +++
 .../ftrace/test.d/kprobe/kprobe_args_type.tc       |    2 +-
 .../test.d/trigger/trigger-trace-marker-hist.tc    |    2 +-
 .../trigger-trace-marker-synthetic-kernel.tc       |    4 ++++
 .../trigger/trigger-trace-marker-synthetic.tc      |    4 ++--
 6 files changed, 12 insertions(+), 5 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

maintainer
#37 lore raw
Quoted 5 lines · Steven Rostedt

[ FYI, Shuah responds better from her linuxfoundation.org email ]

Shuah,

Quoted 9 lines

Feel free to take the first two patches of this series (I acked one, and reviewed the other).

The last patch I had some issues with, and is still under discussion.

Thanks!

-- Steve

Will apply the first two.

thanks,
-- Shuah