selftests/ftrace: Use printf instead of echo in kprobe syntax error tests
PATCH v2 1/1 selftests/ftrace: Use printf instead of echo in kprobe syntax error tests
Test cases which use echo to write strings containing backslashes fail with some shells, as echo's treatment of backslashes in strings varies between shell implementations. Use printf instead, as it should behave consistently across different shells. This requires adjustments to the strings to escape \ and % characters. ftrace_errlog_check() must also re-escape these characters after processing them to remove ^ characters.
---
Changes in v2:
- Escape backslashes for a couple of additional tests
.../testing/selftests/ftrace/test.d/functions | 6 +++--- .../test.d/kprobe/kprobe_syntax_errors.tc | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +3 -3
@@ -114,11 +114,11 @@ yield() { } 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 "${2%^*}" | wc -c) # error position + command=$(printf "$2" | sed -e 's/\^//g' -e 's/%/%%/g' -e 's/\\/\\\\/g') echo "Test command: $command" echo > error_log - (! echo "$command" >> "$3" ) 2> /dev/null + (! printf "$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 +10 -10
@@ -37,14 +37,14 @@ fi check_error 'p vfs_read ^$none_var' # BAD_VAR -check_error 'p vfs_read ^%none_reg' # BAD_REG_NAME +check_error 'p vfs_read ^%%none_reg' # BAD_REG_NAME check_error 'p vfs_read ^@12345678abcde' # BAD_MEM_ADDR check_error 'p vfs_read ^@+10' # FILE_ON_KPROBE grep -q "imm-value" README && \ -check_error 'p vfs_read arg1=\^x' # BAD_IMM +check_error 'p vfs_read arg1=\\^x' # BAD_IMM grep -q "imm-string" README && \ -check_error 'p vfs_read arg1=\"abcd^' # IMMSTR_NO_CLOSE +check_error 'p vfs_read arg1=\\"abcd^' # IMMSTR_NO_CLOSE check_error 'p vfs_read ^+0@0)' # DEREF_NEED_BRACE check_error 'p vfs_read ^+0ab1(@0)' # BAD_DEREF_OFFS
@@ -80,7 +80,7 @@ check_error 'p vfs_read arg1=^' # NO_ARG_BODY # instruction boundary check is valid on x86 (at this moment) case $(uname -m) in x86_64|i[3456]86) - echo 'p vfs_read' > kprobe_events + printf 'p vfs_read' > kprobe_events if grep -q FTRACE ../kprobes/list ; then check_error 'p ^vfs_read+3' # BAD_INSN_BNDRY (only if function-tracer is enabled) fi
@@ -89,13 +89,13 @@ esac # multiprobe errors if grep -q "Create/append/" README && grep -q "imm-value" README; then -echo 'p:kprobes/testevent _do_fork' > kprobe_events +printf '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 -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 -check_error '^p:kprobes/testevent _do_fork abcd=\1' # SAME_PROBE +printf '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 +check_error '^p:kprobes/testevent _do_fork abcd=\\1' # SAME_PROBE fi exit 0
Signature · 1 line
2.25.0
Quoted 9 lines · Seth Forshee
Test cases which use echo to write strings containing backslashes fail with some shells, as echo's treatment of backslashes in strings varies between shell implementations. Use printf instead, as it should behave consistently across different shells. This requires adjustments to the strings to escape \ and % characters.
ftrace_errlog_check()must also re-escape these characters after processing them to remove ^ characters.Signed-off-by Seth Forshee <[email protected]>
Ping. Someone just asked me about this patch, and I noticed that it hasn't been applied or received any feedback.
Quoted 81 lines
---
Changes in v2:
- Escape backslashes for a couple of additional tests.../testing/selftests/ftrace/test.d/functions | 6 +++--- .../test.d/kprobe/kprobe_syntax_errors.tc | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-)tools/testing/selftests/ftrace/test.d/functions +3
-3@@ -114,11 +114,11 @@ yield() { } 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 "${2%^*}" | wc -c) # error position + command=$(printf "$2" | sed -e 's/\^//g' -e 's/%/%%/g' -e 's/\\/\\\\/g') echo "Test command: $command" echo > error_log - (! echo "$command" >> "$3" ) 2> /dev/null + (! printf "$command" >> "$3" ) 2> /dev/null grep "$1: error:" -A 3 error_log N=$(tail -n 1 error_log | wc -c) # " Command: " and "^\n" => 13tools/testing/selftests/ftrace/test.d/kprobe/kprobe_syntax_errors.tc +10
-10@@ -37,14 +37,14 @@ fi check_error 'p vfs_read ^$none_var' # BAD_VAR -check_error 'p vfs_read ^%none_reg' # BAD_REG_NAME +check_error 'p vfs_read ^%%none_reg' # BAD_REG_NAME check_error 'p vfs_read ^@12345678abcde' # BAD_MEM_ADDR check_error 'p vfs_read ^@+10' # FILE_ON_KPROBE grep -q "imm-value" README && \ -check_error 'p vfs_read arg1=\^x' # BAD_IMM +check_error 'p vfs_read arg1=\\^x' # BAD_IMM grep -q "imm-string" README && \ -check_error 'p vfs_read arg1=\"abcd^' # IMMSTR_NO_CLOSE +check_error 'p vfs_read arg1=\\"abcd^' # IMMSTR_NO_CLOSE check_error 'p vfs_read ^+0@0)' # DEREF_NEED_BRACE check_error 'p vfs_read ^+0ab1(@0)' # BAD_DEREF_OFFS@@ -80,7 +80,7 @@ check_error 'p vfs_read arg1=^' # NO_ARG_BODY # instruction boundary check is valid on x86 (at this moment) case $(uname -m) in x86_64|i[3456]86) - echo 'p vfs_read' > kprobe_events + printf 'p vfs_read' > kprobe_events if grep -q FTRACE ../kprobes/list ; then check_error 'p ^vfs_read+3' # BAD_INSN_BNDRY (only if function-tracer is enabled) fi@@ -89,13 +89,13 @@ esac # multiprobe errors if grep -q "Create/append/" README && grep -q "imm-value" README; then -echo 'p:kprobes/testevent _do_fork' > kprobe_events +printf '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 -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 -check_error '^p:kprobes/testevent _do_fork abcd=\1' # SAME_PROBE +printf '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 +check_error '^p:kprobes/testevent _do_fork abcd=\\1' # SAME_PROBE fi exit 0Signature · 1 line
2.25.0
Shuah Khan
maintainerQuoted 9 lines · Seth Forshee
Quoted 8 lines · Seth Forshee
Test cases which use echo to write strings containing backslashes fail with some shells, as echo's treatment of backslashes in strings varies between shell implementations. Use printf instead, as it should behave consistently across different shells. This requires adjustments to the strings to escape \ and % characters.
ftrace_errlog_check()must also re-escape these characters after processing them to remove ^ characters.
Quoted 5 lines
Quoted 1 line
Signed-off-by Seth Forshee <[email protected]>Ping. Someone just asked me about this patch, and I noticed that it hasn't been applied or received any feedback.
I pulled in this patch from Masami:
selftests/ftrace: Use printf for backslash included command
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/commit/?h=next&id=8e923a2168afd221ea26e3d9716f21e9578b5c4d
Looks like a duplicate.
Seth,
Is your patch still needed?
+ Steve and Masami
thanks,
-- Shuah
Quoted 18 lines · Shuah Khan
Quoted 9 lines · Seth Forshee
Quoted 8 lines · Seth Forshee
Test cases which use echo to write strings containing backslashes fail with some shells, as echo's treatment of backslashes in strings varies between shell implementations. Use printf instead, as it should behave consistently across different shells. This requires adjustments to the strings to escape \ and % characters.
ftrace_errlog_check()must also re-escape these characters after processing them to remove ^ characters.Quoted 5 lines
Quoted 1 line
Signed-off-by Seth Forshee <[email protected]>Ping. Someone just asked me about this patch, and I noticed that it hasn't been applied or received any feedback.
I pulled in this patch from Masami:
Quoted 7 lines
selftests/ftrace: Use printf for backslash included command
https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git/commit/?h=next&id=8e923a2168afd221ea26e3d9716f21e9578b5c4dLooks like a duplicate.
Seth,
Is your patch still needed?
Nope, Masami's patch seems to fix the issues addressed by my patch. Thanks!