| #!/bin/sh |
| # SPDX-License-Identifier: GPL-2.0 |
| # 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 |