Hi Steve,

On Fri, 21 Apr 2017 17:30:29 -0400
Steven Rostedt <rost...@goodmis.org> wrote:

> From: "Steven Rostedt (VMware)" <rost...@goodmis.org>
> 
> The set_ftrace_file lists both functions that are filtered, as well as
> function probes (triggers) that are attached to a function, like traceon or
> stacktrace, etc. The reading of this file is not as trivial as most pseudo
> files are, and there's been various bugs that have appeared in the past
> when there's a mix of probes and functions listed. There's also a difference
> when reading the file using dd with a block size of 1.

Would you know which commit fixed this dd/cat differences on
set_ftrace_filter? When I've run this test on 4.9-stable kernel,
it failed because the result of "dd -bs=1" and "cat" on
set_ftrace_filter were different.

Thank you,

> 
> This test performs the following:
> 
>  o Resets set_ftrace_filter
> 
>  o Makes sure only "#### all functions enabled ####" is listed
> 
>     (All checks uses cat, and dd with bs=1 and bs=100)
> 
>  o Adds a traceon trigger to schedule
> 
>  o Checks if only "#### all function enabled ####" and the trigger is there.
> 
>  o Adds tracing of schedule
> 
>  o Checks if only schedule and the trigger is there
> 
>  o Adds tracing of do_IRQ as well
> 
>  o Checks if only schedule, do_IRQ and the trigger is there
> 
>  o Adds a traceon trigger to do_IRQ
> 
>  o Checks if only schedule, do_IRQ and both triggers are there
> 
>  o Removes tracing of do_IRQ
> 
>  o Checks if only schedule and both triggers are there
> 
>  o Removes tracing of schedule
> 
>  o Checks if only  "#### all functions enabled ####" and both triggers are 
> there
> 
>  o Removes the triggers
> 
>  o Checks if only "#### all functions enabled ####" is there
> 
>  o Adds tracing of schedule
> 
>  o Checks if only schedule is there
> 
>  o Adds tracing of do_IRQ
> 
>  o Checks if only schedule and do_IRQ are there
> 
> Signed-off-by: Steven Rostedt (VMware) <rost...@goodmis.org>
> ---
>  .../ftrace/test.d/ftrace/func_set_ftrace_file.tc   | 132 
> +++++++++++++++++++++
>  1 file changed, 132 insertions(+)
>  create mode 100644 
> tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
> 
> diff --git 
> a/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc 
> b/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
> new file mode 100644
> index 000000000000..113b4d9bc733
> --- /dev/null
> +++ b/tools/testing/selftests/ftrace/test.d/ftrace/func_set_ftrace_file.tc
> @@ -0,0 +1,132 @@
> +#!/bin/sh
> +# description: ftrace - test reading of set_ftrace_filter
> +#
> +# The set_ftrace_filter file of ftrace is used to list functions as well as
> +# triggers (probes) attached to functions. The code to read this file is not
> +# straight forward and has had various bugs in the past. This test is 
> designed
> +# to add functions and triggers to that file in various ways and read that
> +# file in various ways (cat vs dd).
> +#
> +
> +# The triggers are set within the set_ftrace_filter file
> +if [ ! -f set_ftrace_filter ]; then
> +    echo "set_ftrace_filter not found? Is dynamic ftrace not set?"
> +    exit_unsupported
> +fi
> +
> +do_reset() {
> +    reset_tracer
> +    reset_ftrace_filter
> +    disable_events
> +    clear_trace
> +    enable_tracing
> +}
> +
> +fail() { # mesg
> +    do_reset
> +    echo $1
> +    exit $FAIL
> +}
> +
> +do_reset
> +
> +FILTER=set_ftrace_filter
> +FUNC1="schedule"
> +FUNC2="do_IRQ"
> +
> +ALL_FUNCS="#### all functions enabled ####"
> +
> +test_func() {
> +    if ! echo "$1" | grep -q "^$2\$"; then
> +     return 0
> +    fi
> +    echo "$1" | grep -v "^$2\$"
> +    return 1
> +}
> +
> +check_set_ftrace_filter() {
> +    cat=`cat $FILTER`
> +    dd1=`dd if=$FILTER bs=1 | grep -v -e 'records in' -e 'records out' -e 
> 'bytes copied'`
> +    dd100=`dd if=$FILTER bs=100 | grep -v -e 'records in' -e 'records out' 
> -e 'bytes copied'`
> +
> +    echo "Testing '$@'"
> +
> +    while [ $# -gt 0 ]; do
> +     echo "test $1"
> +     if cat=`test_func "$cat" "$1"`; then
> +         return 0
> +     fi
> +     if dd1=`test_func "$dd1" "$1"`; then
> +         return 0
> +     fi
> +     if dd100=`test_func "$dd100" "$1"`; then
> +         return 0
> +     fi
> +     shift
> +    done
> +
> +    if [ -n "$cat" ]; then
> +     return 0
> +    fi
> +    if [ -n "$dd1" ]; then
> +     return 0
> +    fi
> +    if [ -n "$dd100" ]; then
> +     return 0
> +    fi
> +    return 1;
> +}
> +
> +if check_set_ftrace_filter "$ALL_FUNCS"; then
> +    fail "Expected only $ALL_FUNCS"
> +fi
> +
> +echo "$FUNC1:traceoff" > set_ftrace_filter
> +if check_set_ftrace_filter "$ALL_FUNCS" "$FUNC1:traceoff:unlimited"; then
> +    fail "Expected $ALL_FUNCS and $FUNC1:traceoff:unlimited"
> +fi
> +
> +echo "$FUNC1" > set_ftrace_filter
> +if check_set_ftrace_filter "$FUNC1" "$FUNC1:traceoff:unlimited"; then
> +    fail "Expected $FUNC1 and $FUNC1:traceoff:unlimited"
> +fi
> +
> +echo "$FUNC2" >> set_ftrace_filter
> +if check_set_ftrace_filter "$FUNC1" "$FUNC2" "$FUNC1:traceoff:unlimited"; 
> then
> +    fail "Expected $FUNC1 $FUNC2 and $FUNC1:traceoff:unlimited"
> +fi
> +
> +echo "$FUNC2:traceoff" >> set_ftrace_filter
> +if check_set_ftrace_filter "$FUNC1" "$FUNC2" "$FUNC1:traceoff:unlimited" 
> "$FUNC2:traceoff:unlimited"; then
> +    fail "Expected $FUNC1 $FUNC2 $FUNC1:traceoff:unlimited and 
> $FUNC2:traceoff:unlimited"
> +fi
> +
> +echo "$FUNC1" > set_ftrace_filter
> +if check_set_ftrace_filter "$FUNC1" "$FUNC1:traceoff:unlimited" 
> "$FUNC2:traceoff:unlimited"; then
> +    fail "Expected $FUNC1 $FUNC1:traceoff:unlimited and 
> $FUNC2:traceoff:unlimited"
> +fi
> +
> +echo > set_ftrace_filter
> +if check_set_ftrace_filter "$ALL_FUNCS" "$FUNC1:traceoff:unlimited" 
> "$FUNC2:traceoff:unlimited"; then
> +    fail "Expected $ALL_FUNCS $FUNC1:traceoff:unlimited and 
> $FUNC2:traceoff:unlimited"
> +fi
> +
> +reset_ftrace_filter
> +
> +if check_set_ftrace_filter "$ALL_FUNCS"; then
> +    fail "Expected $ALL_FUNCS"
> +fi
> +
> +echo "$FUNC1" > set_ftrace_filter
> +if check_set_ftrace_filter "$FUNC1" ; then
> +    fail "Expected $FUNC1"
> +fi
> +
> +echo "$FUNC2" >> set_ftrace_filter
> +if check_set_ftrace_filter "$FUNC1" "$FUNC2" ; then
> +    fail "Expected $FUNC1 and $FUNC2"
> +fi
> +
> +do_reset
> +
> +exit 0
> -- 
> 2.10.2
> 
> 


-- 
Masami Hiramatsu <mhira...@kernel.org>

Reply via email to