Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43bb45da authored by Steven Rostedt (VMware)'s avatar Steven Rostedt (VMware)
Browse files

selftests: ftrace: Add a selftest to test event enable/disable func trigger



This adds a test to enable and disable trace events via the function
triggers. It tests enabling and disabling the sched:sched_switch event via
the the event_enable and event_disable function triggers attached to the
schedule() kernel function.

The test does the following:

 o disable all events

 o disables or enables the sched_switch event

 o writes schedule:event_enable/disable:sched:sched_switch into set_ftrace_filter

 o 5 times it checks to make sure:

    . Writes 0/1 into the sched_switch/enable

    . Checks that the sched_switch/enable goes back to 1/0

 o Resets the events

 o writes schedule:event_enable/disable:sched:sched_switch:3 into set_ftrace_filter

 o Does a loop of 3 to see that sched_switch/enable file gets updated

 o Makes sure the sched_switch/enable stops getting updated

Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 8e5e19c1
Loading
Loading
Loading
Loading
+113 −0
Original line number Original line Diff line number Diff line
#!/bin/sh
# description: ftrace - test for function event triggers
#
# Ftrace allows to add triggers to functions, such as enabling or disabling
# tracing, enabling or disabling trace events, or recording a stack trace
# within the ring buffer.
#
# This test is designed to test event triggers
#

# 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_ftrace_filter
    reset_tracer
    disable_events
    clear_trace
    enable_tracing
}

fail() { # mesg
    do_reset
    echo $1
    exit $FAIL
}

SLEEP_TIME=".1"

do_reset

echo "Testing function probes with events:"

EVENT="sched:sched_switch"
EVENT_ENABLE="events/sched/sched_switch/enable"

cnt_trace() {
    grep -v '^#' trace | wc -l
}

test_event_enabled() {
    val=$1

    e=`cat $EVENT_ENABLE`
    if [ "$e" != $val ]; then
	echo "Expected $val but found $e"
	exit -1
    fi
}

run_enable_disable() {
    enable=$1			# enable
    Enable=$2			# Enable
    check_disable=$3		# 0
    check_enable_star=$4	# 1*
    check_disable_star=$5	# 0*

    cnt=`cnt_trace`
    if [ $cnt -ne 0 ]; then
	fail "Found junk in trace file"
    fi

    echo "$Enable event all the time"

    echo $check_disable > $EVENT_ENABLE
    sleep $SLEEP_TIME

    test_event_enabled $check_disable

    echo "schedule:${enable}_event:$EVENT" > set_ftrace_filter

    echo " make sure it works 5 times"

    for i in `seq 5`; do
	sleep $SLEEP_TIME
	echo "  test $i"
	test_event_enabled $check_enable_star

	echo $check_disable > $EVENT_ENABLE
    done
    sleep $SLEEP_TIME
    echo " make sure it's still works"
    test_event_enabled $check_enable_star

    reset_ftrace_filter

    echo " make sure it only works 3 times"

    echo $check_disable > $EVENT_ENABLE
    sleep $SLEEP_TIME

    echo "schedule:${enable}_event:$EVENT:3" > set_ftrace_filter

    for i in `seq 3`; do
	sleep $SLEEP_TIME
	echo "  test $i"
	test_event_enabled $check_enable_star

	echo $check_disable > $EVENT_ENABLE
    done

    sleep $SLEEP_TIME
    echo " make sure it stop working"
    test_event_enabled $check_disable_star

    do_reset
}

run_enable_disable enable Enable 0 "1*" "0*"
run_enable_disable disable Disable 1 "0*" "1*"